Three weeks ago the only secrets in my cluster were the ones I could invent on the spot. A password I typed into kubectl create secret without writing it down anywhere, and a vague memory of which app it belonged to. Nobody was going to rebuild that cluster anyway.

Then two services arrived that I could not fake. The finances instance talks to a bank, so it needs a private key, an API token and a session that has to survive a restart. The developer portal creates GitHub repositories, so it holds a personal token that can push code. Those are not passwords I can regenerate at dinner, and the rest of my setup assumes git describes the cluster. Everything except these two.

The lazy option was a private repository with the values in clear. I have done that before and it survives exactly as long as the repository stays private, which is a setting and not a promise. It also does not survive deleting the line later, because git remembers. So the rule I wrote down is about plaintext, not about visibility.

sops encrypts values, not files

I had assumed the whole file came out unreadable. You get the same YAML, same keys, same indentation, and only the values become blobs:

stringData:
  POSTGRES_USER: ENC[AES256_GCM,data:6jd7zBA+fX+g,iv:JlRm7w2Wtr...,type:str]
  GITHUB_TOKEN: ENC[AES256_GCM,data:UVLlFPnlNxAHZUC7x...,type:str]

That is on purpose. apiVersion, kind, name and namespace have to stay readable, because whatever consumes the file needs to recognise a Secret before it can decrypt anything inside it. What gets encrypted is decided once, at the repository root:

creation_rules:
  - path_regex: apps/.*\.sops\.yaml$
    encrypted_regex: ^(data|stringData)$

I ended up liking the diff more than the encryption. When I rotate a password, the commit shows me the line I touched and nothing about the value, so the history answers “when did this change” and refuses to answer “what is it”.

One habit fell out of that: read a key, never the file.

sops -d apps/backstage/secret.sops.yaml | sed -n '7p;10p'

A whole secret printed to a terminal lives in scrollback, and scrollback ends up in screenshots.

A terminal showing the same secret twice: the encrypted file with ENC blobs, then sops decrypting two specific keys, then the public age key derived from the private one

The same file three ways: what git stores, what sops returns when you ask for two keys, and the check that proves the local key is the right one.

one identity per machine, one line of text

SOPS on its own is a format. It needs something holding a key, and I picked age because it is one binary and one line of text. age-keygen -o ~/.config/sops/age/keys.txt writes a comment, the public key and a single AGE-SECRET-KEY-1... line. There is no keyring, no daemon and nothing in /etc to keep in sync. PGP does the same job, and I did not find a reason to carry it around.

The repository only ever holds the public half:

    age:
      - age1r0puxn970c7tpt20dqhx8w86h867y0nf8x0upjwujy7u5qayq9tq3djjpx
      - age1w33zek5846mupklux00mgqzreydnvhqurnfl79t4x537k8m3a9yqx0f4f8

Two recipients: the cluster and my laptop. The sentence I wrote in my decision record about this was wrong. I said the private key never enters the cluster. It has to, because something inside has to decrypt, or ArgoCD renders a Secret full of ciphertext and you get to debug a database that cannot start. What stays out of the cluster is the idea that its copy is the only copy.

The first version of my .sops.yaml also claimed the canonical key lived in my Ansible vault, which it never did. It lived in the cluster and in one container on another machine, and I had written a comment describing a backup I had never made. I fixed the comment and left the backup pending, which I know is the wrong order of operations.

Adding a machine is three commands:

age-keygen -o ~/.config/sops/age/keys.txt
age-keygen -y ~/.config/sops/age/keys.txt      # prints the public half, which is what you paste
for f in apps/*/secret*.sops.yaml; do sops updatekeys -y "$f"; done

Nothing gets restarted, because adding a recipient does not remove the old one. Afterwards I check four things: both recipients in the footer, the old key still decrypting, ArgoCD still Synced with the same set of keys in the Secret, and the credential working once. The last one is the only one that proves the value came through the re-encryption intact, so it is the one I do not skip.

the piece that lives inside argocd

Diagram: an age identity on a laptop pushes an encrypted file to git, the ArgoCD repo server pulls it and decrypts it with KSOPS and its own shared key, producing a plain Kubernetes Secret that a pod consumes as environment variables or files

Ciphertext travels through git. Plaintext exists only after the repo server decrypts it, inside the cluster.

ArgoCD will not read these files on its own. The repo server needs KSOPS next to it and a kustomize that is allowed to execute it, so its values grow an init container that drops both binaries into an emptyDir:

initContainers:
  - name: install-ksops
    image: harbor.example.com/tools/ksops:v4.5.1
    command: ["/usr/local/bin/ksops", "install", "--with-kustomize", "/custom-tools"]

env:
  - name: SOPS_AGE_KEY_FILE
    value: /home/argocd/.config/sops/age/keys.txt

And two flags, which I missed for longer than I want to admit:

configs:
  cm:
    kustomize.buildOptions: "--enable-alpha-plugins --enable-exec"

Without them kustomize looks at the exec function and skips it. No warning, no error, nothing in the sync log. The app goes green, the pod starts, and the password it reads is the string ENC[AES256_GCM,...].

The mount path cost me another round. The KSOPS docs mount the key at /.config/sops/age, and the repo server runs as a non-root user, so that path is not yours to create. /home/argocd/.config/sops/age works.

Each app then points at its encrypted file from the generator list:

generators:
  - ksops-generator.yaml

and the generator is a small krm function that names the files:

apiVersion: viaduct.ai/v1
kind: ksops
metadata:
  name: backstage-secrets-generator
  annotations:
    config.kubernetes.io/function: |
      exec:
        path: ksops
files:
  - secret.sops.yaml

The sops-age Secret those binaries read is the one piece of this that is not declarative. It exists because its contents cannot be in git, and it was created by hand. I dislike that, and it is what I would fix first if I ever had to hand this cluster to someone else.

the failure that explains the whole design

My first attempt put secret.sops.yaml under resources:. ArgoCD synced, reported Healthy, and PostgreSQL died on startup with:

FATAL: identifier too long

It was trying to create a role named ENC[AES256_GCM,data:6jd7zBA+fX+g,iv:...], because the cluster had received the file instead of its contents. A generator produces objects during the build. A resource is an object you apply. I had read both sentences before, several times, and it took a dead database for the difference to stick. The comment sitting above the generators: list in my kustomization is there because I wrote it the minute I understood it, in the tone of someone explaining it to their past self.

The second one wasted an evening:

no identity matched any of the recipients

I read that as “the file is broken”. It means “I did not find a key it could use”. In my case SOPS_AGE_KEY_FILE pointed at a path that did not exist in the shell I had just opened, and because the message talks about recipients I spent the first half hour staring at the repository. The check that settles it is deriving the public key from the private one:

age-keygen -y ~/.config/sops/age/keys.txt

If that does not match the recipient in .sops.yaml, the key on disk is not the key you think it is. Everything I had been checking in the repository was fine.

a secret in git is not a secret in a pod

The GitHub token taught me something I thought I already knew. The portal kept failing with a scope error and I kept looking at the repository’s Actions secrets, editing them, and getting the same error back. The portal does not read Actions secrets. It reads a Kubernetes Secret that ArgoCD rebuilds on every sync. Two stores that look like one problem, and I was fixing the wrong one.

Once you see that, the kubectl patch trap makes sense. It works, for about a minute. Then the next reconcile writes the file over it and the value vanishes without a message. The file is the copy that survives. Every secret change I make goes through it now, including the ones that would take ten seconds with kubectl.

what this does not fix

A key on a laptop is the whole set of secrets. Two machines, two full copies, one of them in a backpack. Fine for me. Not fine the moment there is a third person, and the answer at that point is not a bigger SOPS file.

Rotation is still manual. sops rotate gives you a new data key, which is not the same as a new credential. The credential lives in whichever console issued it, and SOPS has no opinion about that.

Encrypting in git says nothing about etcd, or about anyone with kubectl exec, and it says nothing about logs. The plaintext exists inside the cluster in every form the pod needs, and it will end up in a log line the day someone debugs the wrong thing. The old ciphertext also stays in history forever, so if a value leaks, rotating the value is the fix. Rewriting history just breaks everyone’s clone.

What I took away

The encryption took an afternoon, and most of that afternoon was not encryption. It was kustomize indirection, mount paths and a green sync that lied to me.

The part that stayed with me is smaller than a lesson. The one tidy line in my decision record, the one about the private key never entering the cluster, is the only sentence in the whole document that is simply false, because a repo server that decrypts at sync time holds a key. I would rather have it corrected than have it read well. What I want is the weaker claim that the cluster’s copy is never the only copy, and once I said it that way the design followed: two identities, a list of recipients, an updatekeys that only ever adds.

Something similar happens with the files themselves. A Secret in a cluster is a blob I look at once and forget. A Secret in git is four lines I read in a pull request, with a name, a namespace and a history, and I keep noticing things in it that I would never have noticed in kubectl describe.

If you want more than my version of it: SOPS, age and KSOPS. My manifests are in a private repository, but the decision behind them is ADR 016 in the platform baseline, “where the secrets live”. If you have done this at work, I would like to know where it stopped working for you.