Repository navigation
salt-minion: StatefulSet with a unique ID and keypair per replica - #36
Merged
Merged
Conversation
…plica With replicas > 1 the Deployment made every pod register as the same minion (same agent.minion.id) using the same keypair. - Deployment -> StatefulSet. agent.minion.idPrefix names the StatefulSet, so pod N is minion <idPrefix>-N. - replicas > 1 rejects agent.minion.id and the single static privateKeyB64/publicKeyB64 pair. - keySecretName holds <pod>.pem/<pod>.pub pairs when replicas > 1; each pod mounts only its own pair (items + subPathExpr). - The keygen Job generates one pair per replica, only adds missing pairs on scale-up, and its Role gains patch. - Tests and docs updated; replicas: 1 behaves as before. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
saifuddinrangwala
force-pushed
the
feat/minion-statefulset
branch
from
November 25, 2026 13:39
52a26d6 to
fa89a73
Compare
The keygen Job looked up each pod's key with
jsonpath={.data['<pod>.pem']}. kubectl needs the dots in a key name
escaped, so the lookup silently returned nothing, every pair looked
missing, and a scale-up regenerated the keys of every existing pod. That
breaks the master's trust in all existing minions.
Read the Secret's key map once as JSON and check each key by name.
Found by scaling 3 -> 4 on a real cluster; a fake kubectl in the earlier
test had hidden it. Add a regression test on the script.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
saltext.kubernetes requires salt>=3006. pip does not treat the onedir Salt as satisfying that, so it downloaded a different salt from the index (3008.4 built from the sdist) and installed it over the onedir 3008.5. That removed the /opt/saltstack/salt/salt-minion launcher and left /usr/bin/salt-minion as a dangling symlink, so the container failed with "exec: salt-minion: not found". Constrain salt to the installed version for the extension installs, so pip only adds the extensions and their other dependencies. The version is read from `salt-pip list --format=freeze`; `pip freeze` prints the onedir Salt as a file:// URL. Applies to both the kubernetes and vcf images. Verified for both: salt stays at 3008.5, salt-minion runs, the extensions import, salt-call works. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Hadolint DL4006 flags a pipe in a RUN without pipefail. Write `salt-pip list --format=freeze` to a file and grep the file instead, which also makes a salt-pip failure stop the build rather than being masked by the pipe. Both images rebuilt and re-verified (salt stays 3008.5, salt-minion runs, extensions import). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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
With
agent.replicas > 1the chart rendered aDeploymentwhose pods all got the sameagent.minion.idand mounted the same key Secret. So every replica registered as one and the same minion with one keypair, and the master saw a single identity that several pods kept displacing. Without an explicit id the pod ids differed, but every pod still presented the same key.Change
Deploymentbecomes aStatefulSet(templates/statefulset.yaml). Newagent.minion.idPrefixnames the StatefulSet, so podNis minion<idPrefix>-N(e.g.external-minion-0,-1, ...). No image change is needed: the entrypoints already fall back to the pod name, and the chart now also setsPOD_NAME.With
agent.replicas > 1the chart rejectsagent.minion.idand a single staticprivateKeyB64/publicKeyB64pair, because both describe one identity.With
replicas > 1,keySecretNamepoints at a Secret holding one pair per pod, as<pod>.pemand<pod>.pub. Each pod mounts only its own pair (itemsplussubPathExpr: $(POD_NAME)) and never sees the others'.The keygen Job generates one keypair per replica. It is idempotent: it never regenerates existing pairs, and on scale-up it adds only the missing ones (via
kubectl patch, so the Role gainspatch). Withreplicas > 1it is named<release>-keygen-<replicas>so each scale step gets a fresh Job, since Job specs are immutable.replicas: 1is unchanged: same Secret layout, andagent.minion.idstill works.Minion images (both
kubernetesandvcf): keep the onedir Salt when installing extensions.saltext.kubernetesrequiressalt>=3006, and pip does not treat the onedir Salt as satisfying it. It downloaded a differentsaltfrom the index (3008.4, built from the sdist) and installed it over the onedir 3008.5, which removed the/opt/saltstack/salt/salt-minionlauncher and left/usr/bin/salt-miniondangling, so containers failed withexec: salt-minion: not found. The extension step now constrainssaltto the installed version (read withsalt-pip list --format=freeze;pip freezeprints the onedir Salt as afile://URL), so pip only adds the extensions and their other dependencies. It is included here because the chart cannot be run end to end without a working minion image.Testing
Rebased onto
mainafter Fix minion PKI preparation and security defaults #34 merged, and re-tested on the merged templates.helm lintpasses for 1 and 3 replicas, andhelm templaterenders what I expect (StatefulSet name, per-poditems,subPathExpr, Job name and pod list).helm unittest: 44 of 44 pass, including the existing suites and new ones for the identity, per-pod mounts, guards and keygen naming.Installed on a real cluster (3 replicas,
idPrefix: ext-minion,allowSelfGeneratedKey):ext-minion-N.pemand.pub);ext-minion-0to-2, spread across different nodes, with the minion ID equal to the pod name;itemsplussubPathExprmount works.Scale-up test found a bug, now fixed (
a940030). Scaling from 3 to 4 regenerated the keys of every pod, not just the new one, which would break trust for all existing minions. The keygen script looked keys up withjsonpath={.data['<pod>.pem']}, and kubectl needs the dots in a key name escaped, so the lookup silently returned nothing. It now reads the Secret's key map once as JSON. After the fix, scaling from 4 to 5 added onlyext-minion-4and left the 8 existing entries byte-identical. A regression test covers the script.Images: both fixed images were built (amd64, Salt 3008.5). In each, the installed Salt stays 3008.5,
salt-minion --versionworks,saltext.kubernetesandsaltext.vaultimport, andsalt-call --local test.pingreturnsTrue.With the fixed image, all 5 minion pods run. Each pod's
minion.pubandminion.pemmatch its own entries in the Secret, the 5 public keys are all different, and a pod's PKI directory contains only its own pair. A master showsext-minion-0toext-minion-4as 5 separate unaccepted keys.Not tested:
Notes
helm upgrade, since a Deployment cannot be converted to a StatefulSet in place.get/liston Secrets. Only the container filesystem is isolated.helm unittestyet, so these tests don't run automatically (same gap as noted on Fix minion PKI preparation and security defaults #34).🤖 Generated with Claude Code