Metadata-Version: 2.4
Name: dbrij-secrets
Version: 0.1.0
Summary: Dbrij Secrets for Python: load an environment's secrets with a machine token and open them on your own server.
Author: Dbrij
License-Expression: MIT
Project-URL: Homepage, https://secrets.dbrij.com
Project-URL: Documentation, https://dbrij.com/products/secrets/docs
Keywords: secrets,env,configuration,end-to-end-encryption,dbrij
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Security :: Cryptography
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: cryptography>=41
Dynamic: license-file

# dbrij-secrets

Load your app's secrets from Dbrij Secrets with a machine token, and open them on your own server. Dbrij stores only what it cannot open.

```bash
pip install dbrij-secrets
```

```python
from dbrij_secrets import DbrijSecrets

# Reads DBRIJ_SECRETS_TOKEN and DBRIJ_SECRETS_ENV from the environment.
secrets = DbrijSecrets(environment="production")
secrets.load()

database_url = secrets.get("DATABASE_URL")
secrets.inject_env()  # or put every value into os.environ
```

- `refresh()` asks with the last ETag, so an unchanged environment costs one small request.
- If Dbrij cannot be reached, the last good copy is served for `fail_soft_seconds` (one hour by default; `0` turns it off, as `failSoftMs: 0` does in Node). A refusal is never hidden.
- `watch(on_change, every_seconds=30)` asks again every 30 seconds in a background thread (it polls; the Node and Go SDKs follow a stream) and calls you when values change. It returns a `threading.Event`; set it to stop.
- A machine with write access can `set()` and `delete()`; values are sealed here first.
- A login key (`dbsk_...`) in `DBRIJ_SECRETS_KEY` logs in with the identity the machine already has: GitHub Actions (give the job `permissions: id-token: write`), Dbrij Source CI, AWS, Google Cloud, Azure or Kubernetes. Dbrij says which, and the SDK fetches the proof itself.

Only the first two parts of the token are ever sent to Dbrij. Requires Python 3.9 or newer and the `cryptography` package.

## Key management

Use a Dbrij Secrets Key management key with the same machine token, once the key's page gives this machine the operations it needs. The key never leaves Dbrij.

```python
ciphertext = secrets.keys.encrypt(KEY_ID, "a customer BVN", context={"table": "customers"})["ciphertext"]
bvn = secrets.keys.decrypt_text(KEY_ID, ciphertext, context={"table": "customers"})

# Larger than 4 KB: a data key from Dbrij, AES 256 GCM on this server.
sealed = secrets.keys.encrypt_large(KEY_ID, big_text)
back = secrets.keys.decrypt_large_text(KEY_ID, sealed)

signature = secrets.keys.sign(SIGNING_KEY_ID, manifest)["signature"]
ok = secrets.keys.verify(SIGNING_KEY_ID, manifest, signature)
```

Also `data_key`, `reencrypt`, `mac`, `verify_mac` and `public_key`. Decrypting needs the same `context` the value was encrypted with. Envelopes from `encrypt_large` open in the Node and Go SDKs too.

## Tests

```bash
python -m unittest discover -s tests
```

`tests/fixture.json` is written by the Node SDK (`node packages/secrets/scripts/python-fixture.mjs`), so the tests prove the two open each other's work.
