Security hardening: DB credential separation & Kubernetes SecurityContext#10
Merged
Security hardening: DB credential separation & Kubernetes SecurityContext#10
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Eliminates hardcoded database credentials from source code, configuration defaults, and Kubernetes ConfigMaps. Adds pod-level security hardening across all Kubernetes deployments.
This is a breaking change —
IMG_DATABASE_URLis removed and replaced by individualIMG_DB_*variables. Existing deployments must setIMG_DB_USERandIMG_DB_PASSWORDenvironment variables before upgrading.Breaking Changes
IMG_DATABASE_URLenvironment variable is removedIMG_DB_USERandIMG_DB_PASSWORDare now required — no defaults are provided to prevent accidental credential leakagePOSTGRES_PASSWORDto be set in the host environment (or a.envfile)What Changed
Credential separation (config.py)
database_urlfield (with hardcodedpostgres:postgresdefault) with individual typed fields:db_user,db_password,db_host,db_port,db_namedatabase_urlis now a@computed_fieldproperty that assembles the connection string with proper password URL-encoding viaurllib.parse.quote_plusDocker Compose (docker-compose.yml)
${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD})Kubernetes Secrets (secret.yaml, 01a-secret.yaml)
Secretresources forIMG_DB_USER/IMG_DB_PASSWORDIMG_DATABASE_URL(with embedded credentials) from both ConfigMapsConfigMapandSecretviaenvFromsecretKeyRefSecurityContext (k8s + minikube deployments)
runAsNonRoot: true,runAsUser: 999,runAsGroup: 999,allowPrivilegeEscalation: false,readOnlyRootFilesystem: truerunAsNonRoot: true,runAsUser: 70,fsGroup: 70,allowPrivilegeEscalation: false,readOnlyRootFilesystem: trueemptyDirvolumes for tmp (both pods) and/var/run/postgresql(postgres) to support read-only root filesystemDockerfile fix
COPY pyproject.tomlandpip install --no-deps .soimportlib.metadata.version()works at runtime (pre-existing bug)Documentation updates
Files Changed
1.3.0→2.0.0)Testing
ruff check— all passedmypy src/— cleanpytest— 101 tests passedVersion Bump
MAJOR (
1.3.0→2.0.0) — removal ofIMG_DATABASE_URLand requiredIMG_DB_USER/IMG_DB_PASSWORDwith no defaults is a breaking configuration change.