feat: add shared PostgreSQL deployment for platform services#659
feat: add shared PostgreSQL deployment for platform services#659maskarb wants to merge 5 commits intoambient-code:mainfrom
Conversation
Add a shared PostgreSQL instance that can be used by multiple platform services (Unleash, Langfuse, etc.). Base configuration: - Uses postgres:16 image with init scripts for database creation - Credentials use db.* key format (db.host, db.port, db.name, db.user, db.password) - ConfigMap with init scripts creates service databases on first startup Kind overlay: - Inherits base postgres:16 image and init scripts - Includes dev credentials with default values - Smaller PVC (1Gi) for local development Local-dev overlay (CRC/OpenShift): - Patches to RHEL PostgreSQL image (registry.redhat.io/rhel10/postgresql-16) - Uses POSTGRESQL_* env vars for RHEL compatibility Production overlay: - Patches to RHEL PostgreSQL image - Credentials managed separately (not in repo) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Local-dev deployments should use the example secret template or provide credentials externally. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
- Convert RHEL patches from strategic merge to JSON patches to ensure proper replacement instead of merging (fixes double volumeMount issue) - Remove init-scripts volume in RHEL overlays (not used by RHEL image) - Use shell expansion in probes for dynamic username ($POSTGRES_USER for base, $POSTGRESQL_USER for RHEL overlays) - Change service targetPort from integer to named port reference - Add input validation to init script to prevent SQL injection Addresses review comments from PR ambient-code#659. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Claude Code ReviewSummaryThis PR adds a shared PostgreSQL instance deployed via Kustomize overlays (base + kind/local-dev/production), supporting platform services like Unleash and Langfuse. The overall structure is sound and mirrors the existing Minio deployment pattern. The previous automated review was marked "outdated" — this is a fresh pass against the current diff. The main concerns are: missing SecurityContext (project security standard), the RHEL overlay silently drops database initialization without a fallback, duplicate patch files between overlays, and a misleading comment about SQL parameterization. Issues by Severity🚫 Blocker IssuesNone — safe to continue as a draft. 🔴 Critical Issues1. RHEL overlays drop init-scripts without a replacement initialization path
Options to fix:
2. No SecurityContext on the Pod or container The project security standard (CLAUDE.md) requires # Missing from spec.template.spec (pod level):
securityContext:
runAsNonRoot: true
fsGroup: 999 # postgres group in upstream image
# Missing from containers[0] (container level):
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]The upstream 🟡 Major Issues3.
Fix: Add a 4. Duplicate JSON patch files (DRY violation)
Consider moving the patch to 5. Floating image tag in base
🔵 Minor Issues6. Misleading comment on init script SQL injection prevention # Uses parameterized queries to avoid SQL injection
...
psql -c "CREATE DATABASE $db_name"This is not a parameterized query — it is string interpolation with regex pre-validation. The regex validation ( 7. No NetworkPolicy for PostgreSQL PostgreSQL is reachable from any pod in the namespace. Given this is a shared multi-service database, a NetworkPolicy restricting ingress to only the services that need it (Unleash, Langfuse, etc.) would be a meaningful security improvement. 8. Production overlay specifies no PVC storage class or size override The base requests 9. command: ["/bin/sh", "-c", "pg_isready -U \"$POSTGRES_USER\""]This works, but pg_isready -U "$POSTGRES_USER" && psql -U "$POSTGRES_USER" -c "SELECT 1" -d unleashPositive Highlights
RecommendationsPriority order before promoting from draft:
🔍 View AI decision process (logs available for 90 days) 📋 View memory system files loaded (click to expand)What Amber Loaded for Code ReviewAmber automatically loaded these repository standards from the memory system:
Impact: This review used your repository's specific code quality standards, security patterns, and best practices from the memory system (PRs #359, #360) - not just generic code review guidelines. |
Base PostgreSQL deployment no longer creates databases. Database creation is now handled per-environment: - kind: uses init-scripts ConfigMap with /docker-entrypoint-initdb.d/ - production/local-dev: uses init containers in individual services (e.g., Unleash init container creates its own database) This allows each service to manage its own database creation without coupling to PostgreSQL base manifests. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Claude Code ReviewSummaryThis PR adds a shared PostgreSQL deployment via Kustomize overlays (base + kind/local-dev/production) for platform services like Unleash and Langfuse. The overlay structure cleanly mirrors the existing Minio pattern. However, there is a critical blocker in the production overlay where component images were accidentally redirected to a personal registry, plus several correctness and security issues. Issues by Severity🚫 Blocker Issues1. Production overlay redirects ALL component images to a personal registry
# Every :latest-tagged image now pulls from a personal registry:
- name: quay.io/ambient_code/vteam_backend:latest
newName: quay.io/mskarbek/vteam_backend # ← should be quay.io/ambient_code/vteam_backend
- name: quay.io/ambient_code/vteam_claude_runner:latest
newName: quay.io/mskarbek/vteam_claude_runner # ← same
- name: quay.io/ambient_code/vteam_frontend:latest
newName: quay.io/mskarbek/vteam_frontend # ← same
- name: quay.io/ambient_code/vteam_operator:latest
newName: quay.io/mskarbek/vteam_operator # ← same
- name: quay.io/ambient_code/vteam_state_sync:latest
newName: quay.io/mskarbek/vteam_state_sync # ← sameThe base kustomization uses This must be reverted to 🔴 Critical Issues2. No SecurityContext on PostgreSQL pod or container The project security standard (CLAUDE.md) requires # Missing from spec.template.spec:
securityContext:
runAsNonRoot: true
fsGroup: 999 # postgres user group in upstream image (26 in RHEL image)
# Missing from containers[0]:
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]The upstream 3. RHEL overlays silently drop database initialization The kind overlay mounts init scripts at Result: on local-dev (CRC) and production deployments, the Fix options:
🟡 Major Issues4. The Fix: add a note in 5. Duplicate JSON patch files — will drift
6. Floating image tag in base image: postgres:16 # ← floating — pulls different patch versions over timePin to a specific patch version for reproducible builds, e.g. 🔵 Minor Issues7. Misleading SQL injection comment # Uses parameterized queries to avoid SQL injection
...
psql -c "CREATE DATABASE $db_name"This is not a parameterized query — it's string interpolation with regex pre-validation. The validation is effective and the approach is safe, but the comment is technically incorrect and could mislead future editors. Replace with: 8. No NetworkPolicy for PostgreSQL PostgreSQL is reachable from any pod in the namespace. As a shared multi-service database, a NetworkPolicy restricting ingress to only the services that need it (Unleash, Langfuse) would meaningfully limit blast radius. 9. Production PVC has no storage class or size override The base requests 10. The base sets Positive Highlights
RecommendationsPriority order before merge:
Review generated by Claude Code (claude-sonnet-4-6) against repository patterns in CLAUDE.md and 🔍 View AI decision process (logs available for 90 days) 📋 View memory system files loaded (click to expand)What Amber Loaded for Code ReviewAmber automatically loaded these repository standards from the memory system:
Impact: This review used your repository's specific code quality standards, security patterns, and best practices from the memory system (PRs #359, #360) - not just generic code review guidelines. |
Convert patchesStrategicMerge and patchesJson6902 to unified patches syntax to eliminate deprecation warnings. Also add PostgreSQL credentials and init-scripts to e2e overlay (was missing). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Claude Code ReviewSummaryThis PR adds a shared PostgreSQL deployment for platform services (Unleash, Langfuse, etc.) using a Kustomize overlay architecture. It correctly distinguishes between upstream Issues by Severity🚫 Blocker IssuesNone — PR is in DRAFT, but the following criticals should be resolved before promoting. 🔴 Critical Issues1. Missing
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: false # PostgreSQL needs temp writes
capabilities:
drop: ["ALL"]PostgreSQL runs on port 5432 (> 1024, no 2. No NetworkPolicy restricting database access The Suggested policy allowing only labeled consumers: apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: postgresql-allow-consumers
spec:
podSelector:
matchLabels:
app: postgresql
ingress:
- from:
- podSelector:
matchLabels:
db-consumer: postgresql
ports:
- port: 54323. Production/local-dev have no database initialization path The base deployment comment says "production uses init containers per service", but no init containers exist anywhere in this PR. The 🟡 Major Issues4. Identical files duplicated across Three files are byte-for-byte identical between the two overlays:
This creates a maintenance burden — a change to the init script requires updating two files. Consider a shared 5. Unversioned base image tag
6. The PR description explicitly lists Langfuse as a use case. The init script has it commented out: # create_db_if_not_exists "langfuse"If Langfuse is a real consumer, this should either be uncommented or the PR description should clarify it will be added later. As written, this is incomplete for the stated goal. 7. No The PVC relies on the cluster's default StorageClass. Production OpenShift clusters often have multiple storage classes (e.g., standard, encrypted, replicated). Without an explicit 🔵 Minor Issues8. Weak dev credentials
9. Resource limits may be insufficient for production
10. The comment block in the ...but doesn't actually provide the 11. The base spec sets Positive Highlights
Recommendations
Review generated by Claude Code (claude-sonnet-4-6) against ambient-code/platform@postgres-deployment 🔍 View AI decision process (logs available for 90 days) 📋 View memory system files loaded (click to expand)What Amber Loaded for Code ReviewAmber automatically loaded these repository standards from the memory system:
Impact: This review used your repository's specific code quality standards, security patterns, and best practices from the memory system (PRs #359, #360) - not just generic code review guidelines. |
Add a shared PostgreSQL instance that can be used by multiple platform services (Unleash, Langfuse, etc.).
Base configuration:
Kind overlay:
Local-dev overlay (CRC/OpenShift):
Production overlay: