Skip to main content

Rewrite of package which uses a direct config file for the database connection.

Developer notes

The most significant change is that users no longer need to specify a section of a config file to locate a database connection. The former form, -d | --drsConfig prod:~someone/somewhere/somefile is no longer needed. Clients now siimply specify a section name: -d | --drsConfig prod, for example.

The name of the section is free-form.

Critical information is now given in to environment variables:

BDRC_DB_CONFIG

The path to the database configuration file can be given using ~ notation to designate a user.

BDRC_DB_PASSWORD

this is the password to the database named in the section given in the drsConfig parameter.

Development

pyproject.toml

python -m build --wheel bdist_wheel

Deployment

twine upload --verbose  -r testpypi dist/bdrc_db_lib-x.MM.mm-py3-none-any.whl

Installation

pyPI.org bdrc-db-lib2

Implementation

The architecture lends itself to a Docker Secrets + KMS Decryption Scheme. The interested user can refer to Buda-base/ao-workflows

Steps (Thanks to Perplexity)

  1. Encrypt password (One-Time, secure workstation)

# AWS KMS example (use AWS CLI)
aws kms encrypt \
--key-id arn:aws:kms:us-east-1:123456789012:key/1234abcd-12ab-34cd \
--plaintext "mypassword123" \
--output text \
--query CiphertextBlob | base64 > encrypted_db_pass.b64
  1. Docker Secret (Encrypted Blob)

    Add the encrypted blob into the docker image. “But wait,” I hear you say, won’t a hacker have access to the encrypted image?” “Yes, but only until the Docker container is started. The encrypted blob is removed at Docker startup. (See Step 3)

# docker-compose.yml
version: '3.8'
services:
app:
   image: myapp:latest
   secrets:
      - db_password
   environment:
      DB_PASSWORD_FILE: /run/secrets/db_password

secrets:
db_password:
   file: ./encrypted_db_pass.b64
   external: false  # Don't commit
  1. Decrypt at Runtime (Entry script)

    This decrypts the password blob at runtime, and then removes the blob from the container’s file system The only hacker access would be if they could inspect the running container (or has injected code into some open source library that grants access to the Docker inspector)

#!/usr/bin/env python3
import boto3
import base64
import os
import sys

kms = boto3.client('kms')
encrypted_pass = base64.b64decode(open('/run/secrets/db_password').read())
decrypted_pass = kms.decrypt(CiphertextBlob=encrypted_pass)['Plaintext'].decode()

os.environ['DB_PASSWORD'] = decrypted_pass
os.unlink('/run/secrets/db_password')  # Wipe secret file

# Start app
exec(sys.argv[1])

Changelog

version

Commit

Comments

2.0.1

Initial

2.0.2

2.0.2

401b6b0a

Move Models out

Breaks support for older clients

2.0.5

10cc6000

Complete refactoring

2.0.7

a55af435

un-hardwire ‘dev’.

Read parameters for echo and dev from environment

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

bdrc_db_lib2-2.0.7-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file bdrc_db_lib2-2.0.7-py3-none-any.whl.

File metadata

  • Download URL: bdrc_db_lib2-2.0.7-py3-none-any.whl
  • Upload date:
  • Size: 17.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for bdrc_db_lib2-2.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 c79bca8dce4e92c676a3365135909644b09306510b1c4d25842407a70df81ef9
MD5 5145977c5674cd1d9e78ddc2813b01ee
BLAKE2b-256 95b7fd6d74abcefbeb5e707620f5302d15f4bbc7f35d560db74a5d389269880d

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.0.7 This release

1 file

2.0.6

1 file

2.0.5

1 file

2.0.4

1 file

2.0.3a0

1 file

2.0.2

1 file

2.0.1

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page