Repository navigation
Deliver tenant secrets to apps on staging and production - #109
Merged
Merged
Conversation
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
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.
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
envFromfor 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-fetchand nothing else. The listener is HTTPS 443 withcertificateArn; the chart refuses to render without one unlessplaintextListeneris set. The public edge is untouched.The cells call it.
profile.secretFetchBrokeris on for staging and prod. The cell helmfile picks the broker address in this order:crossCluster.coreApiwhen the environment names it (dev-public, unchanged).<emulator.endpoint>/_aws/elasticloadbalancing/<DNSName>, with the DNSName exported asLOOPZERO_CORE_API_ALB_DNS_NAMEbymonitoring-addresses.sh core-api. The platform task reads it after the core sync and before the cells.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 setsremoteRef.decodingStrategy: Base64.Broker tokens.
task staging:platformrunsbootstrap-aws-clusters.sh broker-tokensafterplatform:verify, which runsloopzero-ops seed broker. The seed reuses tokens already issued, so a redeploy does not rotate them. It used to reach cells only throughk3d-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.gotmplsays 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.yamlstill 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 refuseshttp://; 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 afterplatform:verify; thebroker-tokensphase.cd infra/tests && GOWORK=off go test ./charts ./unit ./scriptspasses. 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:platformran from this branch (e48345c) on the staging host, under the platform lock:loopzero-api-secret-fetchgot 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/healthgot the ALB's empty 404.loopzero-brokeris Valid and Ready on cell-0 and cell-1, callinghttps://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).es-app-probe-secretwent fromSecretSyncedErrortoSecretSyncedand 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. WithdecodingStrategy: Base64patched 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 imagedevelop-befa481, whose renderer adds noenvFromto 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