Agent Mesh
Go a2aa2a-protocolagent-meshagentic-aiinferencemcpmeshmesh-networknetwork-securitynetworking-aip2p-network
fix(security): source control-plane DB credentials from a k8s Secret
Antonio Ojeacc16d1bdd2ad
diff --git a/.github/k8s/sam-control-plane-template.yaml b/.github/k8s/sam-control-plane-template.yamlindex 552b6ead..7793f819 100644--- a/.github/k8s/sam-control-plane-template.yaml+++ b/.github/k8s/sam-control-plane-template.yaml@@ -52,7 +52,10 @@ spec:- name: POSTGRES_USERvalue: sam- name: POSTGRES_PASSWORD- value: sam-secret-password+ valueFrom:+ secretKeyRef:+ name: sam-control-plane-secret-${ENV_NAME}+ key: db-password- name: PGDATAvalue: /var/lib/postgresql/data/pgdataports:@@ -99,6 +102,11 @@ spec:name: sam-control-plane-secret-${ENV_NAME}key: admin-tokenoptional: true+ - name: SAM_DB_DSN+ valueFrom:+ secretKeyRef:+ name: sam-control-plane-secret-${ENV_NAME}+ key: db-dsnports:- containerPort: 8080protocol: TCP@@ -120,7 +128,6 @@ spec:args:- "--bind-address=0.0.0.0:8080"- "--db-driver=postgres"- - "--db-dsn=postgres://sam:sam-secret-password@sam-db-${ENV_NAME}:5432/sam_mesh?sslmode=disable"- "--issuer=https://auth.sam-mesh.dev,https://container.googleapis.com/v1/projects/${GCP_PROJECT_ID}/locations/${CLUSTER_REGION}/clusters/${CLUSTER_NAME}"- "--allowed-audiences=sam-mesh-audience,sam-control-plane-audience"- "--auto-approve-enrollment"diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yamlindex 100aa573..05f189a4 100644--- a/.github/workflows/deploy.yaml+++ b/.github/workflows/deploy.yaml@@ -314,11 +314,15 @@ jobs:export ENV_NAME="${VAR_ENV_NAME}"export NAMESPACE="sam-${ENV_NAME}"if ! kubectl get secret sam-control-plane-secret-${ENV_NAME} -n ${NAMESPACE} >/dev/null 2>&1; then- echo "Generating a new random 32-byte hex key for admin-token..."+ echo "Generating new random secrets for admin-token and the DB..."ADMIN_TOKEN=$(openssl rand -hex 32)+ DB_PASSWORD=$(openssl rand -hex 32)+ DB_DSN="postgres://sam:${DB_PASSWORD}@sam-db-${ENV_NAME}:5432/sam_mesh?sslmode=disable"kubectl create secret generic sam-control-plane-secret-${ENV_NAME} \--namespace=${NAMESPACE} \- --from-literal=admin-token="${ADMIN_TOKEN}"+ --from-literal=admin-token="${ADMIN_TOKEN}" \+ --from-literal=db-password="${DB_PASSWORD}" \+ --from-literal=db-dsn="${DB_DSN}"elseecho "sam-control-plane-secret-${ENV_NAME} already exists in namespace ${NAMESPACE}. Skipping generation."fi