feat(compose): x-orcinus-env-from-secret — load an existing Secret as env vars - #10
Merged
Conversation
… env vars
There was no compose-native way to read a Secret that already exists in the
cluster. x-orcinus-secret sounds like it, but it does the opposite: it creates
a Secret from values written in the compose file. Referencing one made by
`orcinus secret create` meant either mounting it as a file through compose's
`external: true`, which only fits a single value, or dropping the whole
workload down to a raw manifest and losing the orcinus ownership labels with it.
services:
app:
image: myapp:1.0
x-orcinus-env-from-secret: app-secret # or [app-secret, extra]
Every key in the Secret becomes an env var under its own name, via envFrom.
Nothing is generated for the Secret — it is expected to exist at deploy time.
Applied alongside imagePullSecrets, before Rollout conversion, so StatefulSets
and Argo Rollouts carry it too. The reference is appended after any env_file
ConfigMap, so a key present in both resolves to the Secret's value, which is
the reason to name a Secret in the first place.
Also documents the file-mount route, which turned out to work but was written
down nowhere: compose `secrets:` with `external: true` mounts an existing
Secret, with the sharp edges that the map key must equal the Secret's name (a
`name:` field is ignored) and the Secret needs a data key of that same name.
The fork warns "External secrets ... not currently supported - ignoring" while
doing it correctly; the warning is wrong.
`orcinus secret create` now ends by naming the key to reference it with, and
the secrets skill card says how to consume a secret rather than only how to
make one.
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.
Problem
There was no compose-native way to consume a Secret that already exists in the cluster.
x-orcinus-secretreads like it should do this, but it does the opposite — it creates a Secret from values written in the compose file. So referencing one made byorcinus secret createleft two options, both bad:secrets:+external: true— mounts it as a file, and only really fits a Secret holding a single value (details below)envFrom.secretRef— which passes through untouched and therefore gets no orcinus labels, so it disappears fromorcinus lsand from--prunescopeChange
Every key in the Secret becomes an env var under its own name. Nothing is generated for the Secret — it must exist at deploy time.
Applied next to
applyImagePullSecrets, before Rollout conversion, so StatefulSets and Argo Rollouts inherit it (covered by a test). The reference is appended after anyenv_fileConfigMap, so a key in both resolves to the Secret's value — which is the point of naming a Secret.Docs
While answering "how do I attach
app-secret?" it turned out the file-mount route works but was documented nowhere —COMPOSE.mdonly mentionedfile:. Now written down, including two sharp edges found by testing:secrets:map must equal the Secret's name in the cluster — aname:field is silently ignoredtarget:renames the file, not the key.orcinus secret create app-secret --from-literal DB_PASS=xthen mounting it leaves the pod stuck on the missing keyAlso worth flagging for reviewers: the fork logs
level=warning msg="External secrets app-secret is not currently supported - ignoring"while wiring it up correctly. The warning is wrong; it is not from this PR, and I left it alone.Discoverability, since the original confusion was "I made the secret, now what":
orcinus secret createnow ends with— load it into a service with \x-orcinus-env-from-secret: ``secretsskill card said how to make a secret but never how to consume one; it now covers both, and warns thatx-orcinus-secretis not the way to reference an existing oneTests
Four cases: scalar form, list form (order preserved), ordering after an
env_fileConfigMap, and inheritance by StatefulSet + Rollout. Full suite 137 passing.