Sealing a secret into a GitOps values file, and the three ways it quietly fails
A sealed secret is the one thing in a GitOps repository that nobody can read back to check. When it is wrong, it commits cleanly, passes review, syncs, and then fails in the cluster. This post explains the three usual causes and how EnvMap avoids them.
Sealed Secrets is how a lot of teams keep secrets in a GitOps repository. A controller in the cluster holds a private key. Anyone with the matching public certificate can encrypt a value with kubeseal, commit the result, and only that cluster can turn it back into a Kubernetes Secret.
It works well. It also has a property that makes mistakes expensive: the ciphertext cannot be checked by reading it. A reviewer sees a long base64 string either way. So the mistakes below all get through review and show up later, in the cluster, as a Secret that never appears.
The scope is part of the encryption#
By default a sealed value is bound to one namespace and one secret name. Sealed Secrets calls this the strict scope. The name and namespace are mixed into the encryption, so a value sealed for payments/payments-api-secret cannot be opened as payments/payments-secret, or in another namespace. That is deliberate: it stops someone copying a sealed value into a Secret they control.
There are two wider scopes. namespace-wide lets the name change within the namespace, and cluster-wide lets both change. They are opt-in, chosen with kubeseal --scope, and the sealed object is marked with the wider scope. A cluster-wide value can be opened by anyone who can create a SealedSecret in that cluster, which is why strict is the default.
Three ways it fails without telling you#
1. Sealed against the wrong name#
The values file says secretName: payments-api-secret. Somebody seals with --name payments-api because that is the service's name. The blob commits, Argo CD or Flux syncs it, and the controller cannot decrypt it, because the name it was sealed for is not the name it is used under. The application then starts without its Secret.
This is the commonest one, because the name lives in one file and the command is typed somewhere else.
2. Sealed with another cluster's certificate#
Each cluster's controller has its own key pair. A value sealed with the staging certificate cannot be opened by production. With three clusters and three certificates on a laptop, picking the wrong --cert is easy, and nothing in the output tells you.
3. A newline nobody typed#
echo "s3cret" | kubeseal --raw --namespace payments --name payments-api-secret \
--cert prod.pem --from-file=/dev/stdinecho adds a newline, so the sealed value is s3cret followed by a newline. It decrypts fine and the password is wrong. Use printf '%s', which adds nothing. This one is especially unpleasant because everything about the Secret looks right except the one byte you cannot see.
How EnvMap seals a value#
EnvMap opens a values file in a window that edits the text, and it has a seal a value panel beside it. The panel is built around those three failures:
- The scope comes from the file. EnvMap reads the file's
namespaceand thesecretNameit declares (or<name>-secretwhen it declares none). The panel names that scope before you type anything, for example into payments/payments-api-secret. Sealing uses--scope strictagainst exactly that pair, so the blob is written where it can be opened. - The certificate is the serving cluster's. Each environment is served by one cluster, and the certificate is the one stored for that cluster, or fetched from its sealed-secrets controller. You do not choose a certificate, so you cannot choose the wrong one.
- The value goes in exactly as typed. It is handed to
kubesealon its standard input, with nothing added to it. - You seal a key and a value, never a selection. Selecting text in the file and pressing "encrypt" is the obvious gesture, and it would get the scope wrong, because the caret says nothing about which Secret the value belongs to.
- Rotation is the same gesture. The keys already sealed in the file are offered by name, and choosing one replaces its value.
Two things it deliberately does not do:
- It never keeps the plaintext. The value goes to the EnvMap server and to
kubeseal, and nowhere else. It is not stored, not echoed back, and the audit log records the key's name and scope, never the value. - It does not seal while you have unsaved edits in the text, because sealing rewrites the file on disk and would throw those edits away. It says so instead.
Then the change is an ordinary commit: you review the diff, write a message, and push with your own name. A push to a production environment asks for the environment's name to be typed first.
Doing it by hand, safely#
Without EnvMap, the same discipline is three habits:
- Read the namespace and name from the file you are writing into, not from memory. If your chart builds the name, render it (
helm template) and read it from the output. - Keep one certificate per cluster with the cluster's name in the file name, and fetch it from the controller when in doubt:
kubeseal --fetch-cert --controller-namespace kube-system --controller-name sealed-secrets-controller. Your controller's namespace and name depend on how it was installed. - Pipe the value from
printf '%s', never from a bareecho.
Try it#
The values window and the seal panel are documented in GitOps repos, and the demo shows the screens with pretend data. EnvMap runs on one machine with Docker Compose:
curl -fsSLO \
https://raw.githubusercontent.com/ammar-hassoun/envmap/main/deploy/compose/compose.yaml
docker compose up -dIf you seal secrets another way and have hit a failure this post does not cover, tell us about it.
EnvMap home · Docs · GitHub