Decrypts SOPS files in the JSON, binary, dotenv and INI formats with age identities.
A SOPS JSON file is a JSON document with the encrypted values and the sops
metadata. The binary format is what sops encrypt --input-type binary
writes: a JSON file with only one value, data. A dotenv file has one
NAME=value line for each value, and sops_ lines for the metadata. An INI
file has its metadata in a [sops] section. The steps:
- Decrypt one of the
sops.ageentries to get the 32-byte data key. - Walk the values in file order. Decrypt each encrypted value with
AES-256-GCM. The additional data is the path of keys to the value, for
example
"db:password:". The items of a list share the path of the list. - Decrypt
sops.macwithsops.lastmodifiedas the additional data, and compare it with the SHA-512 of the values from step 2.
The unencrypted_suffix, encrypted_suffix, unencrypted_regex,
encrypted_regex, unencrypted_comment_regex, encrypted_comment_regex
and mac_only_encrypted settings work as in SOPS. SOPS uses Go regular
expressions. This module compiles them as PCRE, which gives the same result
for usual patterns. A JSON file has no comments, so a comment rule applies
to all its values the same way.
The MAC does not include comments. With a comment rule, a changed comment
can change which values are encrypted. The MAC check still finds a changed
value, but with mac_only_encrypted it does not find a new clear-text value.
Not supported: YAML files, and key groups (Shamir). Other key types in the file (PGP, KMS) are ignored.
Summary
Functions
Decrypts the contents of a SOPS binary-format file.
Decrypts a SOPS dotenv file to a map of names to values.
Decrypts a SOPS INI file to a map of section names to maps of keys to values.
Decrypts a SOPS JSON file to the terms that JSON.decode/1 gives.
Types
Functions
@spec decrypt(binary(), AgeEx.identity() | [AgeEx.identity()]) :: {:ok, binary()} | {:error, error()}
Decrypts the contents of a SOPS binary-format file.
@spec decrypt_dotenv(binary(), AgeEx.identity() | [AgeEx.identity()]) :: {:ok, %{required(String.t()) => term()}} | {:error, error()}
Decrypts a SOPS dotenv file to a map of names to values.
The file must be UTF-8. As in SOPS, \n in a value is a newline, and quotes
are part of the value. Comments are not in the result. A value that SOPS
stored with a type other than a string, for example after
sops encrypt --input-type json --output-type dotenv, comes back with that
type, as in decrypt_json/2.
@spec decrypt_ini(binary(), AgeEx.identity() | [AgeEx.identity()]) :: {:ok, %{required(String.t()) => %{required(String.t()) => term()}}} | {:error, error()}
Decrypts a SOPS INI file to a map of section names to maps of keys to values.
The file must be UTF-8. The result has a "DEFAULT" section, which holds
the keys before the first section header, as in sops decrypt. The values
are strings, with the same exception as in decrypt_dotenv/2. Comments are
not in the result. A duplicate section or key is refused.
SOPS keeps the comment above a key after that key, so the comment rules apply it to the next key. A comment above a section header applies to the first key of that section.
@spec decrypt_json(binary(), AgeEx.identity() | [AgeEx.identity()]) :: {:ok, map()} | {:error, error()}
Decrypts a SOPS JSON file to the terms that JSON.decode/1 gives.
SOPS keeps all JSON numbers as 64-bit floats. A number with no fraction part
comes back as an integer, and other numbers as floats. A binary-format file
gives %{"data" => contents}.