Skip to content

Deliver tenant secrets to apps on staging and production - #109

Merged
paulohenriquevn merged 5 commits into
developfrom
workspace
Nov 25, 2026
Merged

paulohenriquevn merged 5 commits into
developfrom
workspace

Conversation

@paulohenriquevn

@paulohenriquevn paulohenriquevn commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the delivery of tenant secrets to apps on staging and production (#108), and pins the staging dashboard to develop-95bfb98 (getloopscale/console#546).

What changes

The app mounts its secrets. The renderer added envFrom for the app's user-secrets Secret only when the app's configuration listed secret names. A theokit app lists none, so External Secrets wrote the Secret and the process never read it. The container now mounts the environment's Secret and then the app's (the app's value wins on a shared key), both optional unless the app declares secrets.

Core publishes the broker on an internal ALB. The loopzero-api chart gets secretFetchLoadBalancer (off by default): a NodePort Service and an Ingress for the AWS Load Balancer Controller, scheme: internal, instance targets, forwarding /internal/v1/secret-fetch and nothing else. The listener is HTTPS 443 with certificateArn; the chart refuses to render without one unless plaintextListener is set. The public edge is untouched.

The cells call it. profile.secretFetchBroker is on for staging and prod. The cell helmfile picks the broker address in this order:

  • crossCluster.coreApi when the environment names it (dev-public, unchanged).
  • On the emulator: <emulator.endpoint>/_aws/elasticloadbalancing/<DNSName>, with the DNSName exported as LOOPZERO_CORE_API_ALB_DNS_NAME by monitoring-addresses.sh core-api. The platform task reads it after the core sync and before the cells.
  • Elsewhere: LOOPZERO_CORE_API_INTERNAL_URL, required.

The chart's guard against http:// outside dev-public stays.

The secret holds its value. The broker answers plaintext_b64, and the External Secrets webhook provider writes it as is, so the app's Secret held the value's base64 text. Each tenant ExternalSecret now sets remoteRef.decodingStrategy: Base64.

Broker tokens. task staging:platform runs bootstrap-aws-clusters.sh broker-tokens after platform:verify, which runs loopzero-ops seed broker. The seed reuses tokens already issued, so a redeploy does not rotate them. It used to reach cells only through k3d-loopzero-<cell> contexts; LOOPZERO_CELL_CONTEXT_PREFIX (set empty on staging) replaces that prefix.

Staging divergence

Staging's ALB listener is HTTP 80. The emulator's ALB has no socket a pod can reach, so the cells call it through the emulator's HTTPS endpoint, whose CA their External Secrets already trust. The bearer token crosses the network inside TLS, and only the emulator's hop to the target on the same host is plain HTTP. The comment in values/staging/loopzero-api.yaml.gotmpl says so.

Production prerequisite (not created here)

Production now refuses to render until two values exist, and this PR creates neither:

  • LOOPZERO_CORE_API_INTERNAL_CERTIFICATE_ARN: an ACM certificate for the internal name, read by the core render.
  • LOOPZERO_CORE_API_INTERNAL_URL: https://<that name>, a private DNS record pointing at the ALB, read by the cell render.

environments/prod.yaml still describes the DigitalOcean layout (awsLoadBalancerController: false), so an ALB Ingress there has no controller until production moves to the AWS profile. Production also needs the broker seed in its deploy path; this PR wires it for staging only.

Tests

Each new test failed before the change it covers:

  • api/internal/manifests: TestAppContainerMountsUndeclaredUserSecretsOptionally.
  • api/internal/k8s/secretsync: TestExternalSecretDecodesTheBrokersBase64Answer.
  • cmd/loopzero-ops/internal/seed: TestBrokerSeed_WritesThroughTheCellContextsTheEnvironmentNames.
  • infra/tests/charts/secret_fetch_broker_test.go: staging store URL through the emulator ALB over HTTPS; staging and prod refuse to render without their address; prod refuses http://; the core Ingress is internal and forwards only the secret-fetch prefix; prod core refuses without a certificate and serves HTTPS 443 with one. The dev-public tests (k3d host address, no ALB) passed before and after.
  • infra/tests/unit: monitoring-addresses.sh core-api; the platform task reads the ALB between the core and cell syncs and seeds tokens after platform:verify; the broker-tokens phase.

cd infra/tests && GOWORK=off go test ./charts ./unit ./scripts passes. So does shellcheck on the two changed scripts, and the gates helmfile-context-parity, loopzero-external-secrets-chart-sanity, loopzero-api-openbao-approle-envfrom, security-context, silent-surface and english-only.

Verified on staging

task staging:platform ran from this branch (e48345c) on the staging host, under the platform lock:

  • Core's Ingress loopzero-api-secret-fetch got an internal ALB. Through the emulator, a POST under /internal/v1/secret-fetch/ reached the API (its JSON 404, before the tokens existed), while /api/v1/health got the ALB's empty 404.
  • loopzero-broker is Valid and Ready on cell-0 and cell-1, calling https://172.29.0.1:9597/_aws/elasticloadbalancing/<ALB>/internal/v1/secret-fetch/....
  • seed broker: PASS — broker tokens seeded on core and 2 cell(s): cell-0, cell-1 (2 new).
  • The probe app's es-app-probe-secret went from SecretSyncedError to SecretSynced and Ready. The synced value's SHA-256 matched the expected one only after a second base64 decode, which is how the decoding fix above was found. With decodingStrategy: Base64 patched onto that one ExternalSecret by hand, its SHA-256 prefix matches.

Not verified yet: the probe app still answers {"present":false}. Staging runs the API image develop-befa481, whose renderer adds no envFrom to an app that declares no secrets, and whose ExternalSecrets lack the decoding strategy. Both fixes ship in the API image that develop builds after this merge. Once it is deployed, redeploy the probe app and set its secret again to check the whole path.

Refs #108

getloopscale/console merge 95bfb985 published loopzero-dashboard
develop-95bfb98, which fixes console issues #530 and #539 to #545.
Staging runs the console from this pin, so the fixes reach staging only
once it moves.

Refs getloopscale/console#546
The renderer added envFrom for the app's user-secrets Secret only when
the app's configuration listed secret names. A theokit app lists none,
so a secret set with `loopscale secret set` was written into the
namespace by External Secrets and never read by the process.

The container now mounts the environment's Secret and then the app's,
so the app's value wins on a shared key. Both are optional unless the
app declares secrets, in which case its own Secret stays required.

Refs #108
`loopzero-ops seed broker` wrote each cell's token through the k3d
context k3d-loopzero-<cell>. Staging's kubeconfig names its EKS
contexts after the cell id, so the seed could not write a token there.

LOOPZERO_CELL_CONTEXT_PREFIX, when set (empty included), replaces the
k3d prefix. Unset keeps the k3d names dev-public uses.

Refs #108
Staging and prod never installed the secret-fetch broker store on the
cells, and the API ran without broker tokens, so an ExternalSecret for
a tenant secret could never sync.

Core now publishes the API through an internal ALB that forwards
/internal/v1/secret-fetch alone, made by the AWS Load Balancer
Controller from an Ingress in the loopzero-api chart. Production
serves it over HTTPS with the ACM certificate the environment names
and refuses to render without one. Staging uses an HTTP listener
because its cells reach the ALB only through the emulator's HTTPS
endpoint.

The cells' broker store calls that ALB: through the emulator on
staging, where the platform task reads its DNSName after the core
sync, and at LOOPZERO_CORE_API_INTERNAL_URL in production, which is
required. dev-public keeps crossCluster.coreApi. After the API is
verified, the platform task seeds one broker token per cell; tokens
already issued are reused.

Refs #108
The secret-fetch broker answers {"plaintext_b64": ...} and the External
Secrets webhook provider writes what the result jsonPath selects as is,
so the app's Secret held the base64 text of the value. Measured on
staging: the synced Secret's SHA-256 matched the value only after a
second base64 decode.

Each tenant ExternalSecret now sets remoteRef.decodingStrategy Base64.
The comments that said ESO decodes the answer by itself are corrected.

Refs #108
@paulohenriquevn
paulohenriquevn merged commit eaa9baf into develop Nov 25, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant