Safely transferring code secrets
Project description
Safely transferring code secrets
(very much a work in progress)
- Introduction
- Assumptions
- Requirements
- Use cases
- Developer machine
- add a key/value pair
- list secrets
- create a .env file
- export a secret to another user
- explore
- Server
Seeqret: Safely transferring code secrets
(very much a work in progress)
Introduction
How do you communicate the set of secrets (passwords, API keys, etc.) that your code needs to run? You can't just write them in the code, because that would expose them to anyone who can read the code. You can't just send them in an email, because that would expose them to anyone who can read your email. You can't just write them on a sticky note, because that would expose them to anyone who can read your sticky note.
Prior art...
There are many ways to store and use secrets, e.g.:
-
Environment variables: It is popular, in e.g. kubernetes and javascript, to read secrets from environment variables. For development these are stored in .env files that are not checked into git/svn. These files contain the secrets in plain-text. Transferring secrets to a new server/devloper is a manual process where you create a new file and somehow get access to the secrets.
-
Key vaults: E.g. Secureden or HashiCorp Vault (can be self hosted). These are usually expensive or complex to set up - or both. Key vaults usually have an API that you can use to get the secrets (setting this up is also expensive/complex/both).
-
Secret management services: These are hosted key vaults, e.g. AWS Secrets Manager, Google Secret manager, Azure Key Vault, or hosted HashiCorp Vault. There is always an associated api to read the secrets. This can incur significant costs for large numbers of secrets and/or high usage.
-
Encrypted files: This is usually a key/value file (.json/.yaml), where only the values are encrypted (e.g. SOPS. Every developer must have the same key to be able to use the file, but the file can be stored in git/svn.
Seeqret
Seeqret stores "passwords", encrypted, in a sqlite database. On windows this database is stored in an encrypted folder and permissions are removed from anyone but the developer.
A cli, seeqret, is provided to add/remove/edit/etc. the key/value pairs.
When transferring secrets to another developer they are first encrypted with a public/private key-pair, thus ensuring encryption both at rest and in transit.
An api is provided for use in Python (seeqret.get("key")). This api can do 7000+ fetches/sec on my machine, and
is faster than a fixed record file format.
Please read and understand the docstring in __init__.py before using!
Assumptions
We make the following assumptions:
- https is secure
- the encryption algorithms are secure
- encrypted directories (Windows) are secure (
seeqretwill use the following receipe when setting up its data directory):attrib +I %1 icacls %1 /grant %USERDOMAIN%\%USERNAME%:(F) /T icacls %1 /inheritance:r cipher /e %1
- encrypted private directories (Ubuntu) are secure.
0600(read/write by owner only) directories (linux) are safe provided the user is not compromised.
The following requirments and use-cases have guided the devlopment
Requirements
- different users/systems should have access to different subsets of the secrets.
- the secrets should not exist in plain-text when they are not used (e.g. a database password is only used when logging into the database - it shouldn't exist in memory outside of this process1).
- a subset of secrets needs to be shared with new developers in a secure way.
- there should be a command line utility (
seeqret) toseeqret add key <key> <value>: set a secretseeqret get <key>: get a secretseeqret export <user> <keys..>export a subset of the secrets for transmission (e.g. by email) to a new developerseeqret import <keys..>import keys received by e.g. email
- and a library/API to
seeqret.get(key): get a secret (this should be a fast O(1) operation)
- the secrets should be easy to update2.
- it should be possible to backup the secrets.
- (bonus): the secrets should be easy to rotate3.
- (bonus): the secrets should be auditable4.
Use cases
- Starting from scratch: How do you set up the secrets system?
- Inviting users: How do you invite users and how do you communicate the secrets to them?
- Adding a secret: How do you communicate a new secret to the users?
- Updating a secret: How do you communicate an update to a secret?
- New user: How does a new user get access to the secrets?
- Backup: How do you backup the secrets and what is needed to restore the backup?
- Developer leaves: How do you revoke access to the secrets for a developer that leaves?
Installation and usage
You must have at least Python 3.10+ to run seeqret!
Developer machine
To install the vault under c:\home (the directory must not be on a network drive or inside a version controlled directory):
pip install seeqret
seeqret init c:\home --email <your-email>
seeqret users
Your identity defaults to username@hostname (e.g. bjorn@mypc), so the same
username on two machines (each with its own key pair) stays distinct. Commands
that take a username (export --to, load --from-user, slack link, ...)
accept the bare username as long as it only matches one user; if it is
ambiguous you'll be asked to use the full user@host form.
add a key/value pair
seeqret add key KEY secret --app=myapp --env=dev
list secrets
List all dev secrets that start with POSTGRES_:
seeqret list -f :dev:POSTGRES_*
See the filter docs for more info (https://thebjorn.github.io/seeqret/filter-strings/).
create a .env file
❱ seeqret add key FOO bar --env dev
Adding a new key: FOO, value: bar, app: *, env: dev
❱ cat env.template
# all FOO* keys from the dev environment
:dev:FOO*
❱ seeqret env
FOO="bar"
Created .env file with 1 secrets
❱ cat .env
FOO="bar"
export a secret to another user
first ask for the users personal info
Have the other user run
❱ seeqret owner
┏━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ # ┃ username ┃ email ┃ publickey ┃
┡━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ 1 │ bjorn@mypc │ bp@norsktest.no │ MBiGKmtpckXspJkmijIPXd8GrIAgAdLOoM4pZNOyDzw= │
└───┴────────────┴─────────────────┴──────────────────────────────────────────────┘
and send the information to you (you should directly verify the public key).
They can also run seeqret introduction, which prints a ready-to-paste
seeqret add user ... command containing the same information.
add the user
Add the other user as a known person to your vault:
❱ seeqret add user -h
Usage: seeqret add user [OPTIONS]
Add a new user to the vault from a public key.
Options:
--username TEXT Username to record
--email TEXT Email for the user
--pubkey TEXT Public key for the user
-h, --help Show this message and exit.
❱ seeqret add user --username bjorn@mypc --email bp@norsktest.no --pubkey MBiGKmtpckXspJkmijIPXd8GrIAgAdLOoM4pZNOyDzw=
...
export the keys you want to send
❱ seeqret export --to bjorn -f :dev:FOO
{
"from": {
"email": "bp@norsktest.no",
"pubkey": "MBiGKmtpckXspJkmijIPXd8GrIAgAdLOoM4pZNOyDzw=",
"username": "bjorn@mypc"
},
"secrets": [
{
"app": "*",
"env": "dev",
"key": "FOO",
"type": "str",
"value": "W4Fuverw5Mw//ccvYVm40ysVdSxQ4ZwpNTkBuyXtPvtmIQLkd2cl9veG+w=="
}
],
"signature": "0e34f5934979a9deb02ab0c584b39a4d128188df36ec61a0d591ffd9e4e65f70",
"to": {
"email": "bp@norsktest.no",
"pubkey": "MBiGKmtpckXspJkmijIPXd8GrIAgAdLOoM4pZNOyDzw=",
"username": "bjorn@mypc"
},
"version": 1
}
Note that --to bjorn found the user bjorn@mypc: a bare username resolves
to the matching user@host user as long as there is exactly one match. If
you know bjorn on more than one machine, seeqret will refuse to guess and
list the candidates instead.
The other user can load this file with
> seeqret load -f message.json
NOTE: only the intended recipient can decrypt/load the file.
shortcut for transferring secrets
There command serializer makes it convenient to send a "few" secrets e.g. in chat:
❱ seeqret export --to bjorn -f :dev:FOO -s command
seeqret load -ubjorn@mypc -scommand -v1::84efd:*:dev:FOO:str:jsPI3HbN7zLNpogELFbOYZaFR4wFGs2+f6m6ZJCQ2ey88fovih5ZHzIESg==
the recipient only has to copy and paste the command into their terminal to import the secret.
NOTE: only the intended recipient can import the secret with this command line.
explore
List all commands:
> seeqret info
cli
add Add a new secret.
key Add a new NAME -> VALUE mapping.
text Add a new multi-line secret with key NAME, eg recovery codes.
user Add a new user to the vault from a public key.
backup Backup the vault to an encrypted HTML file.
edit Edit a secret or user in the vault.
value Update secrets matching FILTER to the new VALUE.
env Read filters from env.template and export values from the vault to an .env file.
export Export the vault TO a user (use `seeqret load` to import)
get Get the value of a secret (specified by FILTER).
importenv Import secrets from a .env file.
info List hierarchical command structure.
init Initialize a new vault in DIR
introduction Print an introduction to the vault.
list List the contents of the vault
load Save exported secrets to local vault.
owner List the owner of the vault
public-key Show the admin's public key.
push Push secrets from the vault to external systems.
vercel Push secrets matching FILTER to the linked Vercel project.
receive Receive and import encrypted secrets from a transport.
rm Remove a secret or user from the vault.
key Remove a secret from the vault specified by FILTER.
send Send encrypted secrets to a user via file or Slack.
serializers List available serializers.
server Server commands.
init Initialize a server vault
setenv Set global environment variables from secrets matching FILTER.
slack Slack-based secret exchange transport.
doctor Preflight health check for the Slack exchange transport.
link Bind a local user to a Slack handle after fingerprint confirmation.
login OAuth login to Slack and pick an exchange channel.
logout Wipe all Slack configuration from the vault.
status Show Slack login / channel / last-seen state.
upgrade Upgrade the database to the latest version
users List the users in the vault
whoami Display the current user and their role in the vault.
To get information on any command add the -h flag, e.g.:
> seeqret export -h
Usage: seeqret export [OPTIONS]
Export the vault TO a user (use `seeqret load` to import)
Example:
seeqret export --to u1 --to u2 --f :app1::FOO* --f :app1::BAR* --s command
This will export all secrets starting with FOO or BAR from app1 to users u1
and u2.
Options:
--to TEXT User(s) to export to (can be used multiple times) the
user(s) must exist in the vault. [required]
-f, --filter TEXT A seeqret filter string (can be used multiple times)
-s, --serializer TEXT Name of serializer to use (`seeqret serializers` to
list). [default: json-crypt]
-o, --out TEXT Output file (default: stdout).
-w, --windows Export to windows format.
-l, --linux Export to linux format.
-h, --help Show this message and exit.
Server
TBD
seeqret server init
...
-
This is a defense-in-depth measure (in case the sanitizer fails to remove the secret from any traceback/logs/etc.) ↩
-
Updating means manually changing the secret (both in the storage and the service it protects), e.g. when a password expires/is compromised/a devloper leaves/etc. ↩
-
Rotation is the process of periodically updating a secret. Ideally this is an automatic process that e.g. changes both the secret storage and the service it protects. ↩
-
Auditing means checking who has access to the secrets, which secrets were accessed, and when. ↩
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file seeqret-0.4.4.tar.gz.
File metadata
- Download URL: seeqret-0.4.4.tar.gz
- Upload date:
- Size: 84.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6043014a6549328d787ac2b0736e840cdd8548a49ce9fb308f0c44d8d2895cba
|
|
| MD5 |
60dc04c3bb7e0610ec9dd31431bb6712
|
|
| BLAKE2b-256 |
355960726dfa450b7ae179fedc40118aa53af6e226566e7dce6ba6043b1842bf
|
File details
Details for the file seeqret-0.4.4-py3-none-any.whl.
File metadata
- Download URL: seeqret-0.4.4-py3-none-any.whl
- Upload date:
- Size: 106.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f7faf6e088ac957ae4d454a5ad0856655e2a6b9021e47106798011b64186ea7
|
|
| MD5 |
51ef58415b00929ed374d032a8488759
|
|
| BLAKE2b-256 |
7fe93637466268873b54a13f10ed1329ea969f9105c4478eb081579cb0a0c765
|