Skip to main content

A simple tool for encrypting (only) the secrets inside text files

Project description

PyPI PyPI - Downloads

Mask in situ

Mask in situ makes it easy to encrypt only specific sections of files (for example, secrets such as password in configuration files).

The intended use is to allow config files to be shared in a partially-encrypted form, so that secrets are protected but the overall structure of the file, and the value of non-sensitive options are visible.

Installation

You can install with pip install mask-in-situ, and then use the mis command (e.g., mis generate-key).

Alternatively, you can use the Docker image: docker run jamesscottbrown/mask-in-situ "mis generate-key".

You can pass an environment key, and mount a directory as a volume, e.g.,

export CONFIG_KEY="THIS_IS_A_KEY"
docker run --user $(id -u):$(id -g) -v $(pwd):/config -e CONFIG_KEY="$CONFIG_KEY" jamesscottbrown/mask-in-situ "mis decrypt-dir -e CONFIG_KEY /config/masked /config/unmasked"

Usage

If you have a config file that contains secrets, indicate the values to be encrypted by enclosing them in %MASK{..}, then run the encrypt command providing the name of the input and output files as arguments. You can then recover the original file using the decrypt command.

The encrypt-dir and decrypt-dir commands act in the same way as encrypt and decrypt, but rather than transforming single files they transform every file in a directory (descending recursively into subdirectories).

You can generate a key using the generate-key subcommand.

You can provide the name of an environment variable containing the key as an option; if you do not, you will be prompted for the key interactively.

Alternatives

Listing an alternative tool below is not an endorsement: it means I am aware that the tool exists, not that I have evaluated it.

Encrypt part of config file

By default, SOPS encrypts every value (but not hhe keys) in a YAML/JSON file, but it can optionally encrypt only specific values.

However, it works only for YAMl/JSON files (not arbitrary text files).

Encrypt the whole file

A significant number of tools have bene developed to handle the encryption of single files; many of these support integration with Git.

(git-nerps, git-blur, git-easy-crypt)

As the whole file is encrypted, checking or editing a non-sensitive part of the file requires decrypting it.

Manually remove the secrets

The original file could be edited to manually replace the secrets with placeholders, and the secrets could be stored separately in a passwword manager or encrypted file.

When a file containing plaintext secrets is required, they can be manually retrieved and re-added.

However, this requires manual effort. In particular, whenever any change is made, it must be manually made to both the file containing the placeholders, and any versions containing plaintext secrets.

Automatically fetch secrets from a vault

An alternative is not store secrets in any config files, and instead load them from a centralised store provided by a system like:

This provides advantages like auditing and the ability to more easily rotate credentials, but requires additional infrastructure.

Tool-specific approaches

These typically involving extracting secrets from a config to a separate encrypted file that is then imported.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mask-in-situ-0.1.2.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

mask_in_situ-0.1.2-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file mask-in-situ-0.1.2.tar.gz.

File metadata

  • Download URL: mask-in-situ-0.1.2.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for mask-in-situ-0.1.2.tar.gz
Algorithm Hash digest
SHA256 895259805b2355c8b04be43b06684eec2548f119dae9f9884756fa7124c71ea0
MD5 edfa0a5c94c0d6d5b0b37ffec384a76d
BLAKE2b-256 c7f7954ff8d834356321470f077c1ca3129b9c5e218d5570d4526496ecca4299

See more details on using hashes here.

File details

Details for the file mask_in_situ-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: mask_in_situ-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for mask_in_situ-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cf39f29e632041770d0aba86811986ac486b9140eff98465a09a5f6116752526
MD5 9c596f6e31622b03b7117651ee57a2d1
BLAKE2b-256 3a7c3570e84583b98a9e801aa61b037b0708029daf94f4caf0016bb3d39d7d0e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page