EnvMap GitHub

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#

bash
echo "s3cret" | kubeseal --raw --namespace payments --name payments-api-secret \
  --cert prod.pem --from-file=/dev/stdin

echo 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:

Two things it deliberately does not do:

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:

  1. 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.
  2. 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.
  3. Pipe the value from printf '%s', never from a bare echo.

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:

bash
curl -fsSLO \
  https://raw.githubusercontent.com/ammar-hassoun/envmap/main/deploy/compose/compose.yaml
docker compose up -d

If you seal secrets another way and have hit a failure this post does not cover, tell us about it.

EnvMap home · Docs · GitHub