From 98dbc31121ca5a4dd593bed2a44bd013145c1e5f Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 23 Nov 2026 15:28:31 +0500 Subject: [PATCH] stand: deploy persistent SpiceDB using Terraform-managed Vault credentials --- clusters/stand/30-platform/kustomization.yaml | 1 + .../spicedb/stand/kustomization.yaml | 4 + infrastructure/spicedb/stand/spicedb.yaml | 147 ++++++++++++++++++ 3 files changed, 152 insertions(+) create mode 100644 infrastructure/spicedb/stand/kustomization.yaml create mode 100644 infrastructure/spicedb/stand/spicedb.yaml diff --git a/clusters/stand/30-platform/kustomization.yaml b/clusters/stand/30-platform/kustomization.yaml index a375cd7..9c0c15a 100644 --- a/clusters/stand/30-platform/kustomization.yaml +++ b/clusters/stand/30-platform/kustomization.yaml @@ -3,3 +3,4 @@ kind: Kustomization resources: - ../../../infrastructure/zitadel/contour-template - ../../../infrastructure/camunda/contour-template + - ../../../infrastructure/spicedb/stand diff --git a/infrastructure/spicedb/stand/kustomization.yaml b/infrastructure/spicedb/stand/kustomization.yaml new file mode 100644 index 0000000..0ed8ebf --- /dev/null +++ b/infrastructure/spicedb/stand/kustomization.yaml @@ -0,0 +1,4 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - spicedb.yaml diff --git a/infrastructure/spicedb/stand/spicedb.yaml b/infrastructure/spicedb/stand/spicedb.yaml new file mode 100644 index 0000000..f0d9b4e --- /dev/null +++ b/infrastructure/spicedb/stand/spicedb.yaml @@ -0,0 +1,147 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: spicedb + labels: + istio-injection: disabled +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: spicedb-vault + namespace: spicedb +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: spicedb + namespace: spicedb +spec: + replicas: 1 + selector: + matchLabels: + app: spicedb + template: + metadata: + labels: + app: spicedb + annotations: + vault.hashicorp.com/agent-inject: 'true' + vault.hashicorp.com/agent-init-first: 'true' + vault.hashicorp.com/agent-pre-populate-only: 'true' + vault.hashicorp.com/agent-requests-cpu: 25m + vault.hashicorp.com/auth-path: auth/kubernetes + vault.hashicorp.com/role: spicedb + vault.hashicorp.com/agent-inject-secret-spicedb-db: secrets/data/apps/spicedb/postgres + vault.hashicorp.com/agent-inject-template-spicedb-db: '{{- with secret "secrets/data/apps/spicedb/postgres" + -}} + + SPICEDB_DATASTORE_CONN_URI=''postgres://{{ index .Data.data "username" }}:{{ + index .Data.data "password" }}@{{ index .Data.data "host" }}:{{ index .Data.data + "port" }}/{{ index .Data.data "database" }}?sslmode=disable'' + + {{- end -}}' + vault.hashicorp.com/agent-inject-secret-spicedb-auth: secrets/data/apps/spicedb/auth + vault.hashicorp.com/agent-inject-template-spicedb-auth: '{{- with secret "secrets/data/apps/spicedb/auth" + -}} + + SPICEDB_GRPC_PRESHARED_KEY=''{{ index .Data.data "preshared_key" }}'' + + {{- end -}}' + spec: + serviceAccountName: spicedb-vault + initContainers: + - name: vault-runtime + image: hashicorp/vault:1.21.2 + command: + - /bin/sh + - -ec + args: + - cp /bin/busybox /lib/ld-musl-x86_64.so.1 /vault-runtime/ + resources: + requests: + cpu: 25m + memory: 16Mi + volumeMounts: + - name: vault-runtime + mountPath: /vault-runtime + - name: spicedb-migrate + image: authzed/spicedb:v1.54.0 + command: &id001 + - /vault-runtime/ld-musl-x86_64.so.1 + - /vault-runtime/busybox + - sh + - -ec + args: + - 'set -a + + . /vault/secrets/spicedb-db + + . /vault/secrets/spicedb-auth + + set +a + + exec spicedb datastore migrate head --datastore-engine postgres + + ' + volumeMounts: &id003 + - name: vault-runtime + mountPath: /vault-runtime + readOnly: true + resources: &id002 + requests: + cpu: 100m + memory: 256Mi + containers: + - name: spicedb + image: authzed/spicedb:v1.54.0 + command: *id001 + args: + - 'set -a + + . /vault/secrets/spicedb-db + + . /vault/secrets/spicedb-auth + + set +a + + exec spicedb serve --datastore-engine postgres --http-enabled --datastore-conn-pool-read-max-open + 10 --datastore-conn-pool-read-min-open 1 --datastore-conn-pool-write-max-open + 5 --datastore-conn-pool-write-min-open 1 + + ' + ports: + - name: grpc + containerPort: 50051 + - name: http + containerPort: 8443 + resources: *id002 + volumeMounts: *id003 + startupProbe: + grpc: + port: 50051 + periodSeconds: 5 + failureThreshold: 60 + readinessProbe: + grpc: + port: 50051 + periodSeconds: 5 + volumes: + - name: vault-runtime + emptyDir: {} +--- +apiVersion: v1 +kind: Service +metadata: + name: spicedb + namespace: spicedb +spec: + selector: + app: spicedb + ports: + - name: grpc + port: 50051 + targetPort: grpc + - name: http + port: 8443 + targetPort: http