Skip to main content

A tool for keeping secrets during software builds and deployments

Project description

SECTOOL

A tool for keeping secrets during software builds and deployments.

Challenge

The secrets like API keys or passwords should be used during run time and provided by execution environment. The simple solution is keeping them as environment variables. But values of the variables are usually kept as plain text inside files like Dockerfile or docker-compose.yml which is not secure.

Way to solve

The tool solves the issue, it allows you to keep secrets in an encrypted file and inject the values during software builds.

How it works?

  1. You create an .ini file where in section secrets you keep all your secrets.
  2. Encrypt the file. Later you can use the file (or files if you need different secrets for different environments).
  3. Run sectool by specifying the file and your deployment config file. The tool reads your deployment config, injects the corresponding values and print the result to stdout.
  4. Here is the step when Linux magic begins, the stdout can be piped to your building or deployment tool, also xargs can help.

Examples

First of all, install sectool:

python3 -m pip install sectool

And develop a shell code that calls sectool:

# The function has three arguments 
# * path to encrypted file keeping secrets
# * password for decrypting the file
# * path to file where we need to merge variables
merge() {
read -r -d '' script <<-"----EOF"
import os
from sectool import process
process(os.environ['SEC_FILE'], os.environ['PASS'], os.environ['TMPL_FILE'])
----EOF
SEC_FILE="$1" PASS="$2" TMPL_FILE="$3" python3 -c "$script"
}

Inject to Dockerfile and build a Docker image:

echo -n "Enter your password: "
read PASSWORD
merge "secrets.dat" $PASSWORD "Dockerfile" | docker build -t tulip -f - .

Inject to docker-compose.yml and build all images mentioned there:

echo -n "Enter your password: "
read PASSWORD
merge "secrets.dat" $PASSWORD "docker-compose.yml" | docker-compose -f - build

Inject to AWS Task Definition:

echo -n "Enter your password: "
read PASSWORD
merge "secrets.dat" $PASSWORD "my-aws-task-def.json" | xargs -0 aws ecs register-task-definition --region eu-west-1 --cli-input-json

How do I encrypt .ini file?

Easy. You need openssl, the software is very popular and included in almost popular Linux/Unix distributions.

How do I encrypt file?

openssl enc -aes128 -pbkdf2 -in secrets.ini -out secrets.dat

Don't forget password that the tool will ask! If you forget it, you won't be able to get access to your secrets.

How do I decrypt to check if everything okay?

openssl enc -aes128 -pbkdf2 -d -in secrets.dat -pass pass:<password>

How do I mention secret variables in my, for instance, Dockerfile?

Just use a name of the variable in double curly brackets {{api_key}}

Example of .ini file:

[secrets]
api_key = AGTDBLWLB5BGG7NNVHV

Example of Dockerfile:

FROM ubuntu:20.04
USER wheel

ENV API_KEY={{api_key}}

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

sectool-0.0.17.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sectool-0.0.17-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file sectool-0.0.17.tar.gz.

File metadata

  • Download URL: sectool-0.0.17.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.5.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for sectool-0.0.17.tar.gz
Algorithm Hash digest
SHA256 29cdc7b67a5a00d4a294b8da0871a23275958ca84384082588356f465cbf804d
MD5 7c4908d05b4ac4bb575b70d81abc8641
BLAKE2b-256 62c6a2cbaea1f93c42fe1ecfc966fa130f3e4a9d65a8d1ef3dae9790c1055a45

See more details on using hashes here.

File details

Details for the file sectool-0.0.17-py3-none-any.whl.

File metadata

  • Download URL: sectool-0.0.17-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.5.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for sectool-0.0.17-py3-none-any.whl
Algorithm Hash digest
SHA256 f95b4b64dd265b5c840628eb8fc90b294ede9a5dad8335a0e776b1a89f866367
MD5 85a1ae4c840c9223c1b80869ec409c34
BLAKE2b-256 9cffc849df327e191c96707c71e1773185f6f0e30c35c3aa09ded92e4d7d2e13

See more details on using hashes here.

Supported by

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