From 569f77df5d2cdb39d004c54d7488bf7fa0791717 Mon Sep 17 00:00:00 2001 From: Saifuddin Rangwala Date: Wed, 25 Nov 2026 11:11:09 +0530 Subject: [PATCH 01/10] Add Salt master cluster mode and StatefulSet to salt-master chart; pin Salt 3008.5 - salt-master chart: replace the Deployment with a StatefulSet and add agent.replicas and agent.cluster.* (cluster_id, cluster_peers, cluster_pki_dir, cluster_secret, cluster_pool_port). storageMode is "isolated" (Salt 3008 cluster_isolated_filesystem, per-pod PVCs) or "shared" (one ReadWriteMany claim). The chart generates and keeps a cluster_secret unless one is supplied. - master image entrypoint renders the cluster config from SALT_CLUSTER_* and resolves peer DNS names to IPs; unresolvable peers are skipped. - Pin Salt to 3008.5 in the master and minion Dockerfiles, chart defaults, CI script and docs. Co-Authored-By: Claude Sonnet 5.5 --- docs/building.md | 2 +- docs/kubernetes-compliance-guide.md | 4 +- helm/salt-master/CHANGELOG.md | 15 ++ helm/salt-master/Chart.yaml | 11 +- helm/salt-master/README.md | 24 +++- helm/salt-master/templates/NOTES.txt | 13 +- helm/salt-master/templates/_helpers.tpl | 37 ++++- .../salt-master/templates/cluster-secret.yaml | 19 +++ helm/salt-master/templates/job-cache-pvc.yaml | 20 --- .../templates/master-keygen-job.yaml | 2 +- .../templates/service-headless.yaml | 5 + .../{deployment.yaml => statefulset.yaml} | 132 ++++++++++++++++-- helm/salt-master/values.yaml | 48 ++++++- helm/salt-minion/CHANGELOG.md | 3 + scripts/ci.sh | 2 +- src/master/CHANGELOG.md | 6 + src/master/Dockerfile | 2 +- src/master/README.md | 8 +- src/master/entrypoint.sh | 62 ++++++++ src/minion/README.md | 8 +- src/minion/kubernetes/Dockerfile | 2 +- src/minion/vcf/Dockerfile | 2 +- 22 files changed, 367 insertions(+), 60 deletions(-) create mode 100644 helm/salt-master/templates/cluster-secret.yaml delete mode 100644 helm/salt-master/templates/job-cache-pvc.yaml rename helm/salt-master/templates/{deployment.yaml => statefulset.yaml} (55%) diff --git a/docs/building.md b/docs/building.md index 3c7961c..1f383cf 100644 --- a/docs/building.md +++ b/docs/building.md @@ -19,7 +19,7 @@ build directly from this repo with that image's own directory as the build context: ```bash -docker build -t salt-master:3008.2 docker/salt-master +docker build -t salt-master:3008.5 docker/salt-master docker build -t salt-minion-vcf:0.1.0 salt-minion-vcf docker build -t salt-minion-kubernetes:0.1.0 salt-minion-kubernetes ``` diff --git a/docs/kubernetes-compliance-guide.md b/docs/kubernetes-compliance-guide.md index f97b063..1c25a14 100644 --- a/docs/kubernetes-compliance-guide.md +++ b/docs/kubernetes-compliance-guide.md @@ -29,11 +29,11 @@ context. ### 1a. salt-master ```bash -docker build -t salt-master:3008.2 docker/salt-master +docker build -t salt-master:3008.5 docker/salt-master ``` Override `SALT_VERSION` to pin a different Salt release (defaults to -`3008.2` — see [`docker/salt-master/CHANGELOG.md`](../docker/salt-master/CHANGELOG.md)): +`3008.5` — see [`docker/salt-master/CHANGELOG.md`](../docker/salt-master/CHANGELOG.md)): ```bash docker build --build-arg SALT_VERSION=3007.1 -t salt-master:3007.1 docker/salt-master diff --git a/helm/salt-master/CHANGELOG.md b/helm/salt-master/CHANGELOG.md index a5fb8f9..0ce4043 100644 --- a/helm/salt-master/CHANGELOG.md +++ b/helm/salt-master/CHANGELOG.md @@ -4,6 +4,21 @@ Records what each `salt-master-chart/vX.Y.Z` release tag (see [`docs/releasing.md`](../docs/releasing.md)) defaults to. The chart's own version is independent of the image version it happens to default to — check here, not the tag number. +## salt-master-chart/v1.1.0 +- New `agent.cluster.*`: Salt master cluster mode (`cluster_id`, `cluster_peers`, + `cluster_pki_dir`, `cluster_secret`, `cluster_pool_port`). `agent.cluster.storageMode` + is `isolated` (default; Salt 3008 `cluster_isolated_filesystem`, one PVC per pod, no + shared storage) or `shared` (one ReadWriteMany claim for pki/cache/file_roots/pillar_roots). + In cluster mode each master keeps its own keypair, so `agent.masterKeySecretName` and the + master-keygen Job are not used, and `trustedMinions` writes into `cluster_pki_dir`. + The chart creates (and keeps across upgrades) a random `cluster_secret` Secret unless + `agent.cluster.secretName` is set. +- New `agent.replicas` (default `1`) and `templates/statefulset.yaml`; the leftover + `templates/deployment.yaml` and standalone `templates/job-cache-pvc.yaml` are removed + (the job cache is a `volumeClaimTemplate`). The headless Service gains the + `cluster-pool` port when cluster mode is on. +- Default image tag `3008.2` -> `3008.5`. + ## salt-master-chart/v1.0.0 **Breaking - requires a fresh install, not `helm upgrade`, from any prior release:** - `kind: Deployment` → `kind: StatefulSet` (`templates/deployment.yaml` removed, replaced diff --git a/helm/salt-master/Chart.yaml b/helm/salt-master/Chart.yaml index d20a111..5556b7e 100644 --- a/helm/salt-master/Chart.yaml +++ b/helm/salt-master/Chart.yaml @@ -1,12 +1,13 @@ apiVersion: v2 name: salt-master description: >- - Installs a Salt master as a Kubernetes Deployment. Exposes the master - via a flat Service and optionally per‑ordinal Services for external - minion access. Supports trusted‑minion integration with the - salt‑key‑operator side‑car. Does not provide multi‑master scaling. + Installs a Salt master as a Kubernetes StatefulSet. Supports Salt master + cluster mode (cluster_id/cluster_peers, isolated or shared storage) as well + as classic multi-master with a shared keypair. Exposes the masters via a flat + Service and a headless Service for per-ordinal DNS. Supports trusted-minion + integration with the salt-key-operator side-car. type: application -version: 1.0.0 +version: 1.1.0 appVersion: "1.0.0" keywords: - salt diff --git a/helm/salt-master/README.md b/helm/salt-master/README.md index ed99ee6..453e62b 100644 --- a/helm/salt-master/README.md +++ b/helm/salt-master/README.md @@ -54,8 +54,11 @@ The following table lists the most commonly overridden values. See | --- | --- | --- | | `namespace` | Namespace for all chart resources. | `salt-master` | | `agent.image.repository` | Salt master image repository. | `salt-master` | -| `agent.image.tag` | Salt master image tag. | `3007.1` | +| `agent.image.tag` | Salt master image tag. | `3008.5` | | `agent.replicas` | Number of master replicas (active-active - see below). | `1` | +| `agent.cluster.enabled` | Salt master cluster mode (see "Master cluster" below). | `false` | +| `agent.cluster.storageMode` | `isolated` (per-pod PVCs, Salt 3008+) or `shared` (one RWX claim). | `isolated` | +| `agent.cluster.secretName` | Existing Secret with key `cluster-secret`. Empty = chart generates one. | `""` | | `agent.masterKeySecretName` | Existing Secret with the master's keypair (`private-key-b64`/`public-key-b64`). **Required** when `agent.replicas > 1`. | `""` | | `agent.autoAccept` | Auto-accept new minion keys instead of requiring `salt-key -a`/a `SaltMinionKey`. Leave `false` for a production master. | `false` | | `agent.masterId` | Sets `id:` on the master itself. Empty uses the pod hostname. Need not be unique across replicas. | `""` | @@ -68,6 +71,25 @@ The following table lists the most commonly overridden values. See | `service.perOrdinal.enabled` | One Service per replica ordinal - needed for **external** minions to hold independent connections to every replica (see "Active-active" below). | `false` | | `service.perOrdinal.type` | `ClusterIP`, `NodePort`, or `LoadBalancer` for each per-ordinal Service. | `ClusterIP` | +## Master cluster + +With `agent.cluster.enabled=true` the masters form a +[Salt master cluster](https://docs.saltproject.io/en/latest/topics/tutorials/master-cluster.html): +minions see one cluster identity, so point them at the flat `salt-master` Service and +any replica can serve any minion (unlike the classic multi-master mode above). + +```bash +helm install salt-master . --set agent.cluster.enabled=true --set agent.replicas=3 +kubectl -n salt-master exec salt-master-0 -c salt-master -- salt-run cluster.members +``` + +- `isolated` (default): each pod keeps `cluster_pki_dir` and `cachedir` on its own PVC + and peers sync in-band. `file_roots`/`pillar_roots` changes must be propagated with + `salt-run cluster.sync_roots`. +- `shared`: set `agent.cluster.sharedStorage.existingClaim` to a ReadWriteMany PVC. +- Each master has its own keypair; `agent.masterKeySecretName` is ignored. Do not expose + the `cluster-pool` port outside the cluster. + ## External access Everything defaults to `ClusterIP` - nothing is reachable from outside the diff --git a/helm/salt-master/templates/NOTES.txt b/helm/salt-master/templates/NOTES.txt index 27fb9b0..f4e7d04 100644 --- a/helm/salt-master/templates/NOTES.txt +++ b/helm/salt-master/templates/NOTES.txt @@ -4,14 +4,21 @@ Check the workload: kubectl -n {{ .Values.namespace }} get pods -l app=salt-master +{{- if .Values.agent.cluster.enabled }} +Salt master cluster "{{ include "salt-master.clusterId" . }}" ({{ .Values.agent.replicas }} replicas, {{ .Values.agent.cluster.storageMode }} storage). +Point minions at the flat Service (salt-master.{{ .Values.namespace }}.svc), not at individual pods. Verify: + + kubectl -n {{ .Values.namespace }} exec salt-master-0 -c salt-master -- salt-run cluster.members +{{- end }} + Check the Salt Master logs: - kubectl -n {{ .Values.namespace }} logs deployment/salt-master \ + kubectl -n {{ .Values.namespace }} logs statefulset/salt-master \ --container salt-master List known minion keys: - kubectl -n {{ .Values.namespace }} exec deployment/salt-master \ + kubectl -n {{ .Values.namespace }} exec statefulset/salt-master \ --container salt-master \ -- salt-key -L @@ -47,7 +54,7 @@ salt-key-operator integration is disabled. Accept a pending minion manually: - kubectl -n {{ .Values.namespace }} exec deployment/salt-master \ + kubectl -n {{ .Values.namespace }} exec statefulset/salt-master \ --container salt-master \ -- salt-key -a '' diff --git a/helm/salt-master/templates/_helpers.tpl b/helm/salt-master/templates/_helpers.tpl index 5ece1a8..4da4c12 100644 --- a/helm/salt-master/templates/_helpers.tpl +++ b/helm/salt-master/templates/_helpers.tpl @@ -26,4 +26,39 @@ app.kubernetes.io/managed-by: {{ .Release.Service }} {{- define "salt-master.selectorLabels" -}} app.kubernetes.io/name: {{ include "salt-master.name" . }} app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} \ No newline at end of file +{{- end -}} + +{{- define "salt-master.clusterId" -}} +{{- .Values.agent.cluster.id | default .Release.Name -}} +{{- end -}} + +{{- define "salt-master.clusterSecretName" -}} +{{- .Values.agent.cluster.secretName | default (printf "%s-cluster-secret" .Release.Name) -}} +{{- end -}} + +{{/* Directory holding the accepted minion keys: cluster_pki_dir in cluster mode. */}} +{{- define "salt-master.keysDir" -}} +{{- if .Values.agent.cluster.enabled -}}/etc/salt/pki/cluster{{- else -}}/etc/salt/pki/master{{- end -}} +{{- end -}} + +{{/* Comma-separated per-ordinal FQDNs of every replica (peers; self is dropped by the entrypoint). */}} +{{- define "salt-master.clusterPeers" -}} +{{- $peers := list -}} +{{- range $i := until (int .Values.agent.replicas) -}} +{{- $peers = append $peers (printf "salt-master-%d.salt-master-headless.%s.svc.%s" $i $.Values.namespace $.Values.agent.cluster.clusterDomain) -}} +{{- end -}} +{{- join "," $peers -}} +{{- end -}} + +{{- define "salt-master.validate" -}} +{{- $c := .Values.agent.cluster -}} +{{- if and $c.enabled (not (has $c.storageMode (list "isolated" "shared"))) -}} +{{- fail "agent.cluster.storageMode must be 'isolated' or 'shared'." -}} +{{- end -}} +{{- if and $c.enabled (eq $c.storageMode "shared") (not $c.sharedStorage.existingClaim) -}} +{{- fail "agent.cluster.sharedStorage.existingClaim (a ReadWriteMany PVC) is required when agent.cluster.storageMode=shared." -}} +{{- end -}} +{{- if and (gt (int .Values.agent.replicas) 1) (not $c.enabled) (not .Values.agent.masterKeySecretName) -}} +{{- fail "agent.masterKeySecretName is required when agent.replicas > 1 and agent.cluster.enabled is false (every replica must share one keypair)." -}} +{{- end -}} +{{- end -}} diff --git a/helm/salt-master/templates/cluster-secret.yaml b/helm/salt-master/templates/cluster-secret.yaml new file mode 100644 index 0000000..ce8fc83 --- /dev/null +++ b/helm/salt-master/templates/cluster-secret.yaml @@ -0,0 +1,19 @@ +{{- if and .Values.agent.cluster.enabled (not .Values.agent.cluster.secretName) }} +{{- /* Generated once, then reused: rotating cluster_secret on every upgrade would lock peers out. */ -}} +{{- $name := include "salt-master.clusterSecretName" . -}} +{{- $existing := lookup "v1" "Secret" .Values.namespace $name -}} +apiVersion: v1 +kind: Secret +metadata: + name: {{ $name }} + namespace: {{ .Values.namespace }} + labels: + app.kubernetes.io/name: salt-master + app.kubernetes.io/managed-by: {{ .Release.Service }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} + annotations: + helm.sh/resource-policy: keep +type: Opaque +data: + cluster-secret: {{ if $existing }}{{ index $existing.data "cluster-secret" }}{{ else }}{{ randAlphaNum 48 | b64enc }}{{ end }} +{{- end }} diff --git a/helm/salt-master/templates/job-cache-pvc.yaml b/helm/salt-master/templates/job-cache-pvc.yaml deleted file mode 100644 index 1976d7c..0000000 --- a/helm/salt-master/templates/job-cache-pvc.yaml +++ /dev/null @@ -1,20 +0,0 @@ -{{- if .Values.agent.jobCache.persistence.enabled }} -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: {{ include "salt-master.fullname" . }}-job-cache - namespace: {{ .Values.namespace }} - labels: - app.kubernetes.io/name: salt-master - app.kubernetes.io/managed-by: {{ .Release.Service }} - helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} -spec: - accessModes: - - {{ .Values.agent.jobCache.persistence.accessMode }} - {{- with .Values.agent.jobCache.persistence.storageClassName }} - storageClassName: {{ . }} - {{- end }} - resources: - requests: - storage: {{ .Values.agent.jobCache.persistence.size }} -{{- end }} diff --git a/helm/salt-master/templates/master-keygen-job.yaml b/helm/salt-master/templates/master-keygen-job.yaml index fc7085f..8b11618 100644 --- a/helm/salt-master/templates/master-keygen-job.yaml +++ b/helm/salt-master/templates/master-keygen-job.yaml @@ -1,6 +1,6 @@ {{- $masterKeySecret := .Values.agent.masterKeySecretName | default (printf "%s-master-keys" .Release.Name) -}} {{- $existingMasterKeySecret := lookup "v1" "Secret" .Values.namespace $masterKeySecret -}} -{{- if not $existingMasterKeySecret }} +{{- if and (not .Values.agent.cluster.enabled) (not $existingMasterKeySecret) }} apiVersion: batch/v1 kind: Job metadata: diff --git a/helm/salt-master/templates/service-headless.yaml b/helm/salt-master/templates/service-headless.yaml index ffc87ca..52fe4e6 100644 --- a/helm/salt-master/templates/service-headless.yaml +++ b/helm/salt-master/templates/service-headless.yaml @@ -28,3 +28,8 @@ spec: - name: ret port: 4506 targetPort: ret +{{- if .Values.agent.cluster.enabled }} + - name: cluster-pool + port: {{ .Values.agent.cluster.poolPort }} + targetPort: cluster-pool +{{- end }} diff --git a/helm/salt-master/templates/deployment.yaml b/helm/salt-master/templates/statefulset.yaml similarity index 55% rename from helm/salt-master/templates/deployment.yaml rename to helm/salt-master/templates/statefulset.yaml index 8d48438..aae3773 100644 --- a/helm/salt-master/templates/deployment.yaml +++ b/helm/salt-master/templates/statefulset.yaml @@ -1,5 +1,10 @@ +{{- include "salt-master.validate" . -}} +{{- $cluster := .Values.agent.cluster -}} +{{- $isolated := and $cluster.enabled (eq $cluster.storageMode "isolated") -}} +{{- $shared := and $cluster.enabled (eq $cluster.storageMode "shared") -}} +{{- $keysDir := include "salt-master.keysDir" . -}} apiVersion: apps/v1 -kind: Deployment +kind: StatefulSet metadata: name: salt-master namespace: {{ .Values.namespace }} @@ -9,6 +14,11 @@ metadata: app.kubernetes.io/managed-by: {{ .Release.Service }} helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} spec: + serviceName: salt-master-headless + replicas: {{ .Values.agent.replicas }} + # Masters don't depend on each other's start order: cluster peers join + # dynamically, and classic multi-master replicas are fully independent. + podManagementPolicy: Parallel selector: matchLabels: app: salt-master @@ -25,9 +35,12 @@ spec: {{- end }} securityContext: {{- toYaml .Values.agent.podSecurityContext | nindent 8 }} + {{- if not $cluster.enabled }} # Kubernetes Secret volumes are read-only. Salt needs its PKI # directory to be writable so it can secure the directory and create # minions_pre, minions_rejected and minions_denied. + # (Classic mode only: in cluster mode every master generates and keeps + # its own keypair on its persistent state volume.) initContainers: - name: prepare-master-keys image: {{ .Values.agent.image.repository }}:{{ .Values.agent.image.tag }} @@ -66,6 +79,7 @@ spec: - CHOWN - FOWNER - DAC_OVERRIDE + {{- end }} containers: - name: salt-master @@ -76,23 +90,80 @@ spec: value: {{ .Values.agent.autoAccept | quote }} - name: SALT_PRESENCE_EVENTS value: {{ .Values.agent.presenceEvents | quote }} + {{- with .Values.agent.masterId }} + - name: SALT_MASTER_ID + value: {{ . | quote }} + {{- end }} + {{- if $cluster.enabled }} + - name: SALT_CLUSTER_ID + value: {{ include "salt-master.clusterId" . | quote }} + - name: SALT_CLUSTER_PEERS + value: {{ include "salt-master.clusterPeers" . | quote }} + - name: SALT_CLUSTER_PKI_DIR + value: {{ $keysDir | quote }} + - name: SALT_CLUSTER_POOL_PORT + value: {{ $cluster.poolPort | quote }} + - name: SALT_CLUSTER_ISOLATED_FILESYSTEM + value: {{ $isolated | quote }} + - name: SALT_CLUSTER_SECRET + valueFrom: + secretKeyRef: + name: {{ include "salt-master.clusterSecretName" . }} + key: cluster-secret + {{- end }} ports: - name: publish containerPort: 4505 - name: ret containerPort: 4506 + {{- if $cluster.enabled }} + - name: cluster-pool + containerPort: {{ $cluster.poolPort }} + {{- end }} volumeMounts: + {{- if $cluster.enabled }} + - name: state + mountPath: /etc/salt/pki/master + subPath: master-pki + {{- if $isolated }} + - name: state + mountPath: {{ $keysDir }} + subPath: cluster-pki + - name: state + mountPath: /var/cache/salt/master + subPath: cache + {{- end }} + {{- if $shared }} + - name: shared + mountPath: {{ $keysDir }} + subPath: cluster-pki + - name: shared + mountPath: /var/cache/salt/master + subPath: cache + - name: shared + mountPath: /srv/salt + subPath: file-roots + - name: shared + mountPath: /srv/pillar + subPath: pillar-roots + {{- end }} + {{- else }} - name: master-keys mountPath: /etc/salt/pki/master + {{- if .Values.agent.jobCache.persistence.enabled }} + - name: job-cache + mountPath: /var/cache/salt/master/jobs + {{- end }} + {{- end }} {{- if .Values.agent.trustedMinions.enabled }} # These are writable directories populated by the # trusted-minions-sync sidecar. - name: trusted-minions-live - mountPath: /etc/salt/pki/master/minions + mountPath: {{ $keysDir }}/minions - name: trusted-minions-pre - mountPath: /etc/salt/pki/master/minions_pre + mountPath: {{ $keysDir }}/minions_pre - name: trusted-minions-rejected - mountPath: /etc/salt/pki/master/minions_rejected + mountPath: {{ $keysDir }}/minions_rejected {{- end }} securityContext: {{- toYaml .Values.agent.containerSecurityContext | nindent 12 }} @@ -114,15 +185,15 @@ spec: [ -e "$f" ] || continue b="$(basename "$f")" - cp -f "$f" "/etc/salt/pki/master/minions/$b" + cp -f "$f" "{{ $keysDir }}/minions/$b" # An accepted key must not also remain pending or rejected. rm -f \ - "/etc/salt/pki/master/minions_pre/$b" \ - "/etc/salt/pki/master/minions_rejected/$b" + "{{ $keysDir }}/minions_pre/$b" \ + "{{ $keysDir }}/minions_rejected/$b" done - for f in /etc/salt/pki/master/minions/*; do + for f in {{ $keysDir }}/minions/*; do [ -e "$f" ] || continue b="$(basename "$f")" @@ -139,11 +210,11 @@ spec: mountPath: /var/run/salt-key-operator/trusted-minions readOnly: true - name: trusted-minions-live - mountPath: /etc/salt/pki/master/minions + mountPath: {{ $keysDir }}/minions - name: trusted-minions-pre - mountPath: /etc/salt/pki/master/minions_pre + mountPath: {{ $keysDir }}/minions_pre - name: trusted-minions-rejected - mountPath: /etc/salt/pki/master/minions_rejected + mountPath: {{ $keysDir }}/minions_rejected securityContext: {{- toYaml .Values.agent.containerSecurityContext | nindent 12 }} resources: @@ -156,6 +227,7 @@ spec: {{- end }} volumes: + {{- if not $cluster.enabled }} # The generated/existing Secret is mounted separately and copied # into a writable emptyDir by prepare-master-keys. - name: master-keys-source @@ -163,7 +235,12 @@ spec: secretName: {{ .Values.agent.masterKeySecretName | default (printf "%s-master-keys" .Release.Name) }} - name: master-keys emptyDir: {} - + {{- end }} + {{- if $shared }} + - name: shared + persistentVolumeClaim: + claimName: {{ $cluster.sharedStorage.existingClaim }} + {{- end }} {{- if .Values.agent.trustedMinions.enabled }} - name: trusted-minions-src configMap: @@ -174,4 +251,33 @@ spec: emptyDir: {} - name: trusted-minions-rejected emptyDir: {} - {{- end }} \ No newline at end of file + {{- end }} + + {{- if or $cluster.enabled .Values.agent.jobCache.persistence.enabled }} + volumeClaimTemplates: + {{- if $cluster.enabled }} + - metadata: + name: state + spec: + accessModes: + - {{ $cluster.persistence.accessMode }} + {{- with $cluster.persistence.storageClassName }} + storageClassName: {{ . }} + {{- end }} + resources: + requests: + storage: {{ $cluster.persistence.size }} + {{- else }} + - metadata: + name: job-cache + spec: + accessModes: + - {{ .Values.agent.jobCache.persistence.accessMode }} + {{- with .Values.agent.jobCache.persistence.storageClassName }} + storageClassName: {{ . }} + {{- end }} + resources: + requests: + storage: {{ .Values.agent.jobCache.persistence.size }} + {{- end }} + {{- end }} diff --git a/helm/salt-master/values.yaml b/helm/salt-master/values.yaml index 21bb379..6a42742 100644 --- a/helm/salt-master/values.yaml +++ b/helm/salt-master/values.yaml @@ -12,7 +12,7 @@ agent: # scripts/push-image-to-nodes.sh --role=master, or set repository to the # GHCR path to pull instead. repository: salt-master - tag: "3008.2" + tag: "3008.5" pullPolicy: IfNotPresent # 1 (default) = simplest possible setup: single master, single Service @@ -30,6 +30,52 @@ agent: # otherwise) - every replica must share the identical keypair. + replicas: 1 + + # Salt master cluster (Salt 3007+; the isolated-filesystem mode below needs + # 3008+). Distinct from the classic multi-master mode described above: all + # masters present ONE cluster identity to minions, so a plain Service in + # front of the StatefulSet (service.type/service.gateway) is the intended + # minion endpoint - any replica can serve any minion, and jobs/events are + # routed between peers. Each master keeps its OWN master keypair; the + # cluster-wide keypair and the accepted minion keys live in cluster_pki_dir. + # See https://docs.saltproject.io/en/latest/topics/tutorials/master-cluster.html + # + # When enabled: masterKeySecretName is not used (no shared master keypair), + # jobCache.persistence is ignored (the state volume below holds the cache), + # and trustedMinions writes into /minions instead. + cluster: + enabled: false + # cluster_id. Defaults to the release name. + id: "" + clusterDomain: cluster.local + # cluster_pool_port: peer-to-peer RPC between masters (headless Service + # and container port are added automatically). Must be reachable between + # pods; never expose it outside the cluster. + poolPort: 4520 + # Secret holding key 'cluster-secret' (cluster_secret: authenticates + # masters joining the cluster). Empty = the chart creates + # -cluster-secret with a random value on first install and + # keeps it across upgrades. + secretName: "" + # isolated: Salt 3008+ cluster_isolated_filesystem - every pod keeps its + # own cluster_pki_dir/cachedir on its own PVC and peers sync in-band. + # No shared storage required. file_roots/pillar_roots then have to be + # propagated with `salt-run cluster.sync_roots`. + # shared: all pods mount one ReadWriteMany claim (NFS, CephFS, ...) for + # cluster_pki_dir, cachedir, file_roots and pillar_roots. + storageMode: isolated + # Per-pod volume (volumeClaimTemplates): the master's own keypair, and in + # isolated mode also cluster_pki_dir and the cachedir. + persistence: + storageClassName: "" + accessMode: ReadWriteOnce + size: 5Gi + # storageMode=shared only: an EXISTING ReadWriteMany PVC, used with + # subPaths cluster-pki, cache, file-roots and pillar-roots. + sharedStorage: + existingClaim: "" + # No numeric runAsUser/runAsGroup/fsGroup here on purpose - the image runs # as the 'salt' system user salt-common's own postinst creates (or this # Dockerfile creates itself for the onedir install - see diff --git a/helm/salt-minion/CHANGELOG.md b/helm/salt-minion/CHANGELOG.md index 0831a85..6b4df7c 100644 --- a/helm/salt-minion/CHANGELOG.md +++ b/helm/salt-minion/CHANGELOG.md @@ -6,6 +6,9 @@ versions it carries — check here. ## Image releases (`salt-minion-image/vX.Y.Z`) +### salt-minion-image/v0.1.2 +- Salt: 3008.5 (no other change) + ### salt-minion-image/v0.1.1 - Salt: 3008.2 - Extensions: saltext.kubernetes==2.1.0, saltext.vault==1.8.0 diff --git a/scripts/ci.sh b/scripts/ci.sh index 52078b7..b8fc131 100755 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -29,7 +29,7 @@ set -euo pipefail #------------------------------------------------------------ # Configuration #------------------------------------------------------------ -IMAGE_TAG_MASTER="3008.2" +IMAGE_TAG_MASTER="3008.5" MINION_K8S_IMAGE_TAG="0.1.0" MINION_VCF_IMAGE_TAG="0.1.0" MAX_IMAGE_SIZE=$((500 * 1024 * 1024)) # 500 MiB diff --git a/src/master/CHANGELOG.md b/src/master/CHANGELOG.md index cc8331f..da2ab1e 100644 --- a/src/master/CHANGELOG.md +++ b/src/master/CHANGELOG.md @@ -5,6 +5,12 @@ Records what each `salt-master-image/vX.Y.Z` release tag (see independent semver for this image — it does not encode the Salt version, so check here before assuming. +## salt-master-image/v1.1.0 +- Salt: 3008.5 +- `entrypoint.sh` renders master cluster config when `SALT_CLUSTER_ID` is set + (`SALT_CLUSTER_PEERS`, `SALT_CLUSTER_SECRET`, `SALT_CLUSTER_PKI_DIR`, + `SALT_CLUSTER_POOL_PORT`, `SALT_CLUSTER_ISOLATED_FILESYSTEM`). + ## salt-master-image/v1.0.0 - Salt: 3008.2 - Base: ubuntu:24.04 diff --git a/src/master/Dockerfile b/src/master/Dockerfile index bec9afd..06ee418 100644 --- a/src/master/Dockerfile +++ b/src/master/Dockerfile @@ -9,7 +9,7 @@ FROM ubuntu:24.04 # Pinned rather than "latest" so a given salt-master-image release tag # reproducibly carries one specific Salt version - see CHANGELOG.md. -ARG SALT_VERSION=3008.2 +ARG SALT_VERSION=3008.5 LABEL org.opencontainers.image.title="Salt Master" LABEL org.opencontainers.image.description="Salt Master runtime for VCF Salt" diff --git a/src/master/README.md b/src/master/README.md index 9a8954d..7a40294 100644 --- a/src/master/README.md +++ b/src/master/README.md @@ -9,7 +9,7 @@ long-running Salt Master container does not communicate with the Kubernetes API The image: -- Uses Salt `3008.2` by default. +- Uses Salt `3008.5` by default. - Runs as the non-root `salt` user with UID/GID `10001`. - Supports an optional corporate CA during image build. - Does not retain the build-time corporate CA in the final image. @@ -74,14 +74,14 @@ is not persisted in the final runtime image. | Argument | Default | Purpose | | --- | --- | --- | -| `SALT_VERSION` | `3008.2` | Salt version to install. Set it to another supported version or `latest` for the newest stable onedir release. | +| `SALT_VERSION` | `3008.5` | Salt version to install. Set it to another supported version or `latest` for the newest stable onedir release. | Example: ```bash docker build \ --platform linux/arm64 \ - --build-arg SALT_VERSION=3008.2 \ + --build-arg SALT_VERSION=3008.5 \ --tag salt-master:local \ ./src/master ``` @@ -111,7 +111,7 @@ docker run --rm \ Expected: ```text -salt-master 3008.2 (Argon) +salt-master 3008.5 (Argon) ``` Verify the runtime identity: diff --git a/src/master/entrypoint.sh b/src/master/entrypoint.sh index 381714b..e6a73bf 100644 --- a/src/master/entrypoint.sh +++ b/src/master/entrypoint.sh @@ -42,6 +42,68 @@ if [ ! -s "$PKI_DIR/master.pem" ] \ echo "Pre-seeded master keypair" fi +# Optional: Salt master cluster mode (Salt 3007+; isolated filesystem mode +# needs 3008+). Enabled by setting SALT_CLUSTER_ID. See +# https://docs.saltproject.io/en/latest/topics/tutorials/master-cluster.html +# +# SALT_CLUSTER_ID cluster_id +# SALT_CLUSTER_PEERS comma-separated peer hostnames; this +# pod's own entry (matched on the short +# hostname) is dropped, and each remaining +# one is resolved to an IP because the +# upstream docs only show IP peers +# SALT_CLUSTER_SECRET cluster_secret (authenticates joins) +# SALT_CLUSTER_PKI_DIR cluster_pki_dir +# SALT_CLUSTER_POOL_PORT cluster_pool_port (peer-to-peer RPC) +# SALT_CLUSTER_ISOLATED_FILESYSTEM "true" -> cluster_isolated_filesystem +if [ -n "${SALT_CLUSTER_ID:-}" ]; then + CLUSTER_CONF="$CONF_DIR/98-cluster.conf" + PEER_IPS="" + SELF="$(hostname -s 2>/dev/null || hostname)" + + IFS=',' read -r -a PEER_HOSTS <<< "${SALT_CLUSTER_PEERS:-}" + for peer in "${PEER_HOSTS[@]:-}"; do + [ -n "$peer" ] || continue + [ "${peer%%.*}" != "$SELF" ] || continue + + # Peer pods may not exist yet when the whole StatefulSet starts at + # once, so retry briefly; a peer that never resolves is skipped and + # can still join us dynamically later (it lists us as *its* peer). + ip="" + for _ in $(seq 1 30); do + # getent exits 2 for an unknown host; don't let pipefail/-e kill us. + ip="$(getent hosts "$peer" | awk '{print $1; exit}' || true)" + [ -z "$ip" ] || break + sleep 1 + done + if [ -n "$ip" ]; then + PEER_IPS="$PEER_IPS $ip" + else + echo "WARNING: cluster peer $peer did not resolve; skipping" >&2 + fi + done + + ( + umask 077 + { + printf 'cluster_id: %s\n' "$SALT_CLUSTER_ID" + printf 'cluster_pki_dir: %s\n' "${SALT_CLUSTER_PKI_DIR:-/etc/salt/pki/cluster}" + [ -z "${SALT_CLUSTER_POOL_PORT:-}" ] || printf 'cluster_pool_port: %s\n' "$SALT_CLUSTER_POOL_PORT" + [ -z "${SALT_CLUSTER_SECRET:-}" ] || printf 'cluster_secret: %s\n' "$SALT_CLUSTER_SECRET" + if [ -n "$PEER_IPS" ]; then + printf 'cluster_peers:\n' + for ip in $PEER_IPS; do printf ' - %s\n' "$ip"; done + fi + if [ "${SALT_CLUSTER_ISOLATED_FILESYSTEM:-}" = "true" ]; then + printf 'cluster_isolated_filesystem: True\n' + printf 'keys.cache_driver: mmap_key\n' + fi + } > "$CLUSTER_CONF" + ) + mkdir -p "${SALT_CLUSTER_PKI_DIR:-/etc/salt/pki/cluster}" + echo "Rendered cluster config for cluster_id=$SALT_CLUSTER_ID" +fi + mkdir -p /var/cache/salt/master/.socks if [ $# -eq 0 ]; then diff --git a/src/minion/README.md b/src/minion/README.md index 78c5072..defafca 100644 --- a/src/minion/README.md +++ b/src/minion/README.md @@ -20,7 +20,7 @@ This minion is designed specifically for running inside Kubernetes clusters and The image: -- Uses Salt `3008.2` by default +- Uses Salt `3008.5` by default - Runs as the non-root `salt` user with UID/GID `10000` - Supports optional corporate CA during image build - Does not retain build-time corporate CA in final image @@ -77,14 +77,14 @@ docker build \ | Argument | Default | Purpose | | --- | --- | --- | -| `SALT_VERSION` | `3008.2` | Salt version to install | +| `SALT_VERSION` | `3008.5` | Salt version to install | Example: ```bash docker build \ --platform linux/arm64 \ - --build-arg SALT_VERSION=3008.2 \ + --build-arg SALT_VERSION=3008.5 \ --tag salt-minion:local \ ./src/minion/kubernetes ``` @@ -114,7 +114,7 @@ docker run --rm \ Expected: ```text -salt-minion 3008.2 (Argon) +salt-minion 3008.5 (Argon) ``` Verify runtime identity and permissions: diff --git a/src/minion/kubernetes/Dockerfile b/src/minion/kubernetes/Dockerfile index b953d91..2dc3815 100644 --- a/src/minion/kubernetes/Dockerfile +++ b/src/minion/kubernetes/Dockerfile @@ -5,7 +5,7 @@ FROM ubuntu:24.04 ARG DEBIAN_FRONTEND=noninteractive -ARG SALT_VERSION=3008.2 +ARG SALT_VERSION=3008.5 ARG SALT_UID=10001 ARG SALT_GID=10001 ARG SALT_HOME=/opt/saltstack/salt diff --git a/src/minion/vcf/Dockerfile b/src/minion/vcf/Dockerfile index 70fc695..ef43e45 100644 --- a/src/minion/vcf/Dockerfile +++ b/src/minion/vcf/Dockerfile @@ -9,7 +9,7 @@ FROM ubuntu:24.04 ARG DEBIAN_FRONTEND=noninteractive # Pinned rather than "latest" so a given salt-minion-kubernetes-image release # tag reproducibly carries one specific Salt version - see CHANGELOG.md. -ARG SALT_VERSION=3008.2 +ARG SALT_VERSION=3008.5 ARG SALT_UID=10001 ARG SALT_GID=10001 ARG SALT_HOME=/opt/saltstack/salt From 89c3c39d4bd320d25f779abf9fceb052b0ab9b38 Mon Sep 17 00:00:00 2001 From: Saifuddin Rangwala Date: Wed, 25 Nov 2026 18:38:07 +0530 Subject: [PATCH 02/10] salt-master: fix cluster mode issues found by testing on a real cluster - prepare-cluster-dirs root init container: PVC subPath dirs are root-owned. - entrypoint: wait for all peers and fail clearly if none resolve (Salt refuses a member with no peers); chart requires replicas >= 2. - set interface and id to the pod IP: Salt uses `interface` as the cluster node identity. - add agent.cluster.keysCacheDriver, autoReplaceVoters (default off) and minVoters; document that a restarted pod gets a new identity. Co-Authored-By: Claude Sonnet 5.5 --- helm/salt-master/CHANGELOG.md | 9 +++ helm/salt-master/templates/_helpers.tpl | 3 + helm/salt-master/templates/statefulset.yaml | 72 +++++++++++++++++++++ helm/salt-master/values.yaml | 18 ++++++ src/master/entrypoint.sh | 68 ++++++++++++++----- 5 files changed, 154 insertions(+), 16 deletions(-) diff --git a/helm/salt-master/CHANGELOG.md b/helm/salt-master/CHANGELOG.md index 0ce4043..63065a4 100644 --- a/helm/salt-master/CHANGELOG.md +++ b/helm/salt-master/CHANGELOG.md @@ -18,6 +18,15 @@ of the image version it happens to default to — check here, not the tag number (the job cache is a `volumeClaimTemplate`). The headless Service gains the `cluster-pool` port when cluster mode is on. - Default image tag `3008.2` -> `3008.5`. +- Found by testing on a real cluster: cluster mode needs `agent.replicas >= 2` (Salt refuses a + member with no peers), each master's `interface` and `id` must be its own pod IP (Salt uses + `interface` as the consensus node identity), and the state directories need a root init + container (`prepare-cluster-dirs`) because kubelet creates PVC subPaths root-owned. New values: + `agent.cluster.keysCacheDriver` (default Salt's `localfs_key`; `mmap_key` could not read its own + keys on Longhorn volumes), `autoReplaceVoters` (default off) and `minVoters`. +- **Known limitation:** the pod IP is the cluster identity, so a restarted or rescheduled master + joins as a new learner while its old identity stays a dead voter. Treat pod restarts as + unsupported until the node identity can be made stable. ## salt-master-chart/v1.0.0 **Breaking - requires a fresh install, not `helm upgrade`, from any prior release:** diff --git a/helm/salt-master/templates/_helpers.tpl b/helm/salt-master/templates/_helpers.tpl index 4da4c12..b28075a 100644 --- a/helm/salt-master/templates/_helpers.tpl +++ b/helm/salt-master/templates/_helpers.tpl @@ -55,6 +55,9 @@ app.kubernetes.io/instance: {{ .Release.Name }} {{- if and $c.enabled (not (has $c.storageMode (list "isolated" "shared"))) -}} {{- fail "agent.cluster.storageMode must be 'isolated' or 'shared'." -}} {{- end -}} +{{- if and $c.enabled (lt (int .Values.agent.replicas) 2) -}} +{{- fail "agent.cluster.enabled requires agent.replicas >= 2: Salt refuses to start a cluster member that has no peers." -}} +{{- end -}} {{- if and $c.enabled (eq $c.storageMode "shared") (not $c.sharedStorage.existingClaim) -}} {{- fail "agent.cluster.sharedStorage.existingClaim (a ReadWriteMany PVC) is required when agent.cluster.storageMode=shared." -}} {{- end -}} diff --git a/helm/salt-master/templates/statefulset.yaml b/helm/salt-master/templates/statefulset.yaml index aae3773..48d3659 100644 --- a/helm/salt-master/templates/statefulset.yaml +++ b/helm/salt-master/templates/statefulset.yaml @@ -80,6 +80,60 @@ spec: - FOWNER - DAC_OVERRIDE {{- end }} + {{- if $cluster.enabled }} + # Kubelet creates PVC subPath directories root-owned, and Salt must + # chmod/own its pki, cluster pki and cache directories as the non-root + # master user, so prepare them once as root (same tradeoff as the + # classic-mode prepare-master-keys init container). + initContainers: + - name: prepare-cluster-dirs + image: {{ .Values.agent.image.repository }}:{{ .Values.agent.image.tag }} + imagePullPolicy: {{ .Values.agent.image.pullPolicy }} + command: + - /bin/sh + - -c + - | + set -eu + + mkdir -p /state/master-pki + chown 10001:10001 /state/master-pki + chmod 0700 /state/master-pki + {{- if $isolated }} + + mkdir -p /state/cluster-pki /state/cache + chown 10001:10001 /state/cluster-pki /state/cache + chmod 0700 /state/cluster-pki + {{- end }} + {{- if $shared }} + + mkdir -p /shared/cluster-pki /shared/cache /shared/file-roots /shared/pillar-roots + # Best effort: NFS with root_squash may refuse the chown; the + # share then needs to be writable by uid/gid 10001 already. + chown 10001:10001 /shared/cluster-pki /shared/cache \ + /shared/file-roots /shared/pillar-roots || \ + echo "WARNING: could not chown the shared directories" >&2 + chmod 0700 /shared/cluster-pki || true + {{- end }} + volumeMounts: + - name: state + mountPath: /state + {{- if $shared }} + - name: shared + mountPath: /shared + {{- end }} + securityContext: + runAsUser: 0 + runAsGroup: 0 + runAsNonRoot: false + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL + add: + - CHOWN + - FOWNER + - DAC_OVERRIDE + {{- end }} containers: - name: salt-master @@ -95,6 +149,14 @@ spec: value: {{ . | quote }} {{- end }} {{- if $cluster.enabled }} + - name: POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP + # Salt's consensus layer identifies a master by its `interface`, + # which must be its own peer-reachable IP. + - name: SALT_CLUSTER_NODE_ADDRESS + value: $(POD_IP) - name: SALT_CLUSTER_ID value: {{ include "salt-master.clusterId" . | quote }} - name: SALT_CLUSTER_PEERS @@ -105,6 +167,16 @@ spec: value: {{ $cluster.poolPort | quote }} - name: SALT_CLUSTER_ISOLATED_FILESYSTEM value: {{ $isolated | quote }} + - name: SALT_CLUSTER_AUTO_REPLACE_VOTERS + # hasKey: `helm upgrade --reuse-values` from an older release + # leaves this key unset; treat that as the default (false). + value: {{ if hasKey $cluster "autoReplaceVoters" }}{{ $cluster.autoReplaceVoters | quote }}{{ else }}"false"{{ end }} + - name: SALT_CLUSTER_MIN_VOTERS + value: {{ $cluster.minVoters | default (max 1 (sub (int .Values.agent.replicas) 1)) | quote }} + {{- with $cluster.keysCacheDriver }} + - name: SALT_CLUSTER_KEYS_CACHE_DRIVER + value: {{ . | quote }} + {{- end }} - name: SALT_CLUSTER_SECRET valueFrom: secretKeyRef: diff --git a/helm/salt-master/values.yaml b/helm/salt-master/values.yaml index 6a42742..f2f5737 100644 --- a/helm/salt-master/values.yaml +++ b/helm/salt-master/values.yaml @@ -65,6 +65,24 @@ agent: # shared: all pods mount one ReadWriteMany claim (NFS, CephFS, ...) for # cluster_pki_dir, cachedir, file_roots and pillar_roots. storageMode: isolated + # LIMITATION: a master's cluster identity is its `interface`, which here + # is the pod IP, and Salt has no setting to separate identity from bind + # address. A pod IP changes whenever the pod is rescheduled or restarted, + # so the restarted pod joins as a NEW learner while its old identity stays + # a dead voter. Salt's own recovery, cluster_auto_replace_voters, is OFF by + # default and was observed to demote a healthy voter instead of the dead + # one (breaking quorum), so the chart leaves it off. Until this is solved + # (stable node IPs, e.g. hostNetwork pinned per node), treat pod restarts + # as unsupported. Replacing a voter also needs a majority of the current + # voters, so use at least 3 replicas. + autoReplaceVoters: false + # Floor below which Salt will not demote a voter. Empty = replicas - 1 + # (at least 1), i.e. one dead voter can always be replaced. + minVoters: "" + # keys.cache_driver for the cluster key store. Empty = Salt's default + # (localfs_key). Salt recommends mmap_key for isolated mode, but see the + # chart CHANGELOG: it failed to read its own keys back on Longhorn PVCs. + keysCacheDriver: "" # Per-pod volume (volumeClaimTemplates): the master's own keypair, and in # isolated mode also cluster_pki_dir and the cachedir. persistence: diff --git a/src/master/entrypoint.sh b/src/master/entrypoint.sh index e6a73bf..55232f5 100644 --- a/src/master/entrypoint.sh +++ b/src/master/entrypoint.sh @@ -47,6 +47,12 @@ fi # https://docs.saltproject.io/en/latest/topics/tutorials/master-cluster.html # # SALT_CLUSTER_ID cluster_id +# SALT_CLUSTER_NODE_ADDRESS this master's own IP, written as `interface:`. +# Salt uses `interface` as the node identity +# in the consensus layer and matches it +# against peers' cluster_peers entries, so +# it must be the real, peer-reachable IP +# (not the 0.0.0.0 default) # SALT_CLUSTER_PEERS comma-separated peer hostnames; this # pod's own entry (matched on the short # hostname) is dropped, and each remaining @@ -56,37 +62,58 @@ fi # SALT_CLUSTER_PKI_DIR cluster_pki_dir # SALT_CLUSTER_POOL_PORT cluster_pool_port (peer-to-peer RPC) # SALT_CLUSTER_ISOLATED_FILESYSTEM "true" -> cluster_isolated_filesystem +# SALT_CLUSTER_KEYS_CACHE_DRIVER optional keys.cache_driver (e.g. mmap_key) +# SALT_CLUSTER_AUTO_REPLACE_VOTERS cluster_auto_replace_voters (true/false) +# SALT_CLUSTER_MIN_VOTERS cluster_min_voters if [ -n "${SALT_CLUSTER_ID:-}" ]; then CLUSTER_CONF="$CONF_DIR/98-cluster.conf" PEER_IPS="" SELF="$(hostname -s 2>/dev/null || hostname)" IFS=',' read -r -a PEER_HOSTS <<< "${SALT_CLUSTER_PEERS:-}" - for peer in "${PEER_HOSTS[@]:-}"; do - [ -n "$peer" ] || continue - [ "${peer%%.*}" != "$SELF" ] || continue - # Peer pods may not exist yet when the whole StatefulSet starts at - # once, so retry briefly; a peer that never resolves is skipped and - # can still join us dynamically later (it lists us as *its* peer). - ip="" - for _ in $(seq 1 30); do + # Salt refuses to start a cluster member without at least one peer + # ("Dynamic peer discovery is not supported"), so there is no founder + # that can start alone. Wait (up to SALT_CLUSTER_PEER_WAIT_SECONDS) for + # every other pod's DNS name to resolve - they all start together, so + # this normally takes a few seconds. After the grace period, carry on + # with whichever peers resolved, but fail loudly if none did. + deadline=$((SECONDS + ${SALT_CLUSTER_PEER_WAIT_SECONDS:-120})) + while :; do + PEER_IPS="" + unresolved="" + for peer in "${PEER_HOSTS[@]:-}"; do + [ -n "$peer" ] || continue + [ "${peer%%.*}" != "$SELF" ] || continue + # getent exits 2 for an unknown host; don't let pipefail/-e kill us. ip="$(getent hosts "$peer" | awk '{print $1; exit}' || true)" - [ -z "$ip" ] || break - sleep 1 + if [ -n "$ip" ]; then + PEER_IPS="$PEER_IPS $ip" + else + unresolved="$unresolved $peer" + fi done - if [ -n "$ip" ]; then - PEER_IPS="$PEER_IPS $ip" - else - echo "WARNING: cluster peer $peer did not resolve; skipping" >&2 - fi + [ -n "$unresolved" ] || break + [ "$SECONDS" -lt "$deadline" ] || break + sleep 2 done + if [ -z "$PEER_IPS" ]; then + echo "ERROR: none of the cluster peers resolved (${SALT_CLUSTER_PEERS:-}); a Salt master cluster needs at least one peer" >&2 + exit 1 + fi + [ -z "$unresolved" ] || echo "WARNING: continuing without unresolved cluster peers:$unresolved" >&2 + ( umask 077 { printf 'cluster_id: %s\n' "$SALT_CLUSTER_ID" + [ -z "${SALT_CLUSTER_NODE_ADDRESS:-}" ] || printf 'interface: %s\n' "$SALT_CLUSTER_NODE_ADDRESS" + # The tutorial's cluster examples use the node's IP as the master + # id, and peers are keyed by IP; the pod FQDN default does not + # match. An explicit SALT_MASTER_ID still wins (99-env.conf). + [ -n "${SALT_MASTER_ID:-}" ] || [ -z "${SALT_CLUSTER_NODE_ADDRESS:-}" ] || printf 'id: %s\n' "$SALT_CLUSTER_NODE_ADDRESS" printf 'cluster_pki_dir: %s\n' "${SALT_CLUSTER_PKI_DIR:-/etc/salt/pki/cluster}" [ -z "${SALT_CLUSTER_POOL_PORT:-}" ] || printf 'cluster_pool_port: %s\n' "$SALT_CLUSTER_POOL_PORT" [ -z "${SALT_CLUSTER_SECRET:-}" ] || printf 'cluster_secret: %s\n' "$SALT_CLUSTER_SECRET" @@ -96,8 +123,17 @@ if [ -n "${SALT_CLUSTER_ID:-}" ]; then fi if [ "${SALT_CLUSTER_ISOLATED_FILESYSTEM:-}" = "true" ]; then printf 'cluster_isolated_filesystem: True\n' - printf 'keys.cache_driver: mmap_key\n' fi + # SALT_CLUSTER_KEYS_CACHE_DRIVER overrides keys.cache_driver + # (localfs_key is Salt's default; Salt recommends mmap_key for + # the isolated filesystem mode). + [ -z "${SALT_CLUSTER_KEYS_CACHE_DRIVER:-}" ] || printf 'keys.cache_driver: %s\n' "$SALT_CLUSTER_KEYS_CACHE_DRIVER" + # Voter replacement: a pod's IP is its cluster identity and changes + # on every restart, so the old identity must be demoted and the + # restarted pod promoted. Salt's defaults (auto-replace off, + # min voters 3) never do that. + [ -z "${SALT_CLUSTER_AUTO_REPLACE_VOTERS:-}" ] || printf 'cluster_auto_replace_voters: %s\n' "$SALT_CLUSTER_AUTO_REPLACE_VOTERS" + [ -z "${SALT_CLUSTER_MIN_VOTERS:-}" ] || printf 'cluster_min_voters: %s\n' "$SALT_CLUSTER_MIN_VOTERS" } > "$CLUSTER_CONF" ) mkdir -p "${SALT_CLUSTER_PKI_DIR:-/etc/salt/pki/cluster}" From de032eaf9bb65c8c3f0eaa949ad40b78cb5eddaa Mon Sep 17 00:00:00 2001 From: Saifuddin Rangwala Date: Wed, 25 Nov 2026 21:02:46 +0530 Subject: [PATCH 03/10] salt-master: run the init containers non-root, like the salt-minion chart prepare-master-keys (classic) and prepare-cluster-dirs (cluster) ran as root with CHOWN/FOWNER/DAC_OVERRIDE. They now use agent.containerSecurityContext, mount the whole volume and create their directories as the master's own user (the pod's fsGroup makes volumes group-writable), and the master mounts the existing subdirectories. The master-key Secret is mounted 0440. Removes the unused agent.initContainers.fixCachePerms value. Verified on a real cluster: cluster mode on fresh Longhorn volumes (3 voters form) and classic mode with a chart-generated key (Salt keeps the supplied key, storing it by master id). Co-Authored-By: Claude Sonnet 5.5 --- helm/salt-master/CHANGELOG.md | 7 ++ helm/salt-master/templates/statefulset.yaml | 87 ++++++++------------- helm/salt-master/values.yaml | 28 +++---- 3 files changed, 50 insertions(+), 72 deletions(-) diff --git a/helm/salt-master/CHANGELOG.md b/helm/salt-master/CHANGELOG.md index 63065a4..49f4a5c 100644 --- a/helm/salt-master/CHANGELOG.md +++ b/helm/salt-master/CHANGELOG.md @@ -24,6 +24,13 @@ of the image version it happens to default to — check here, not the tag number container (`prepare-cluster-dirs`) because kubelet creates PVC subPaths root-owned. New values: `agent.cluster.keysCacheDriver` (default Salt's `localfs_key`; `mmap_key` could not read its own keys on Longhorn volumes), `autoReplaceVoters` (default off) and `minVoters`. +- The init containers no longer run as root or add capabilities. `prepare-master-keys` (classic) + and `prepare-cluster-dirs` (cluster) run with `agent.containerSecurityContext`, create their + directories as the master's own user (the pod's `fsGroup` makes the volumes group-writable) + and the master mounts those existing subdirectories - the same pattern as the salt-minion + chart. The Secret with the master keys is mounted `0440`. The unused + `agent.initContainers.fixCachePerms` value is removed. A `sharedStorage.existingClaim` must + already be writable by uid/gid 10001. - **Known limitation:** the pod IP is the cluster identity, so a restarted or rescheduled master joins as a new learner while its old identity stays a dead voter. Treat pod restarts as unsupported until the node identity can be made stable. diff --git a/helm/salt-master/templates/statefulset.yaml b/helm/salt-master/templates/statefulset.yaml index 48d3659..0fb1bf9 100644 --- a/helm/salt-master/templates/statefulset.yaml +++ b/helm/salt-master/templates/statefulset.yaml @@ -36,9 +36,14 @@ spec: securityContext: {{- toYaml .Values.agent.podSecurityContext | nindent 8 }} {{- if not $cluster.enabled }} - # Kubernetes Secret volumes are read-only. Salt needs its PKI - # directory to be writable so it can secure the directory and create - # minions_pre, minions_rejected and minions_denied. + # Kubernetes Secret volumes are read-only, but Salt needs a writable PKI + # directory (it creates minions_pre, minions_rejected and minions_denied + # in it). Same pattern as the salt-minion chart: this init container + # runs as the same non-root user as the master (the pod's fsGroup makes + # the 0440 Secret files readable), copies the keys into a writable + # emptyDir, and the master mounts that emptyDir's `master` subdirectory. + # The directory is created here, by the master's own user, instead of + # by kubelet as a subPath mount, which would leave it root-owned. # (Classic mode only: in cluster mode every master generates and keeps # its own keypair on its persistent state volume.) initContainers: @@ -51,40 +56,34 @@ spec: - | set -eu - cp /var/run/salt-master-keys/master.pem \ - /etc/salt/pki/master/master.pem + umask 077 + test -s /var/run/salt-master-keys/master.pem + test -s /var/run/salt-master-keys/master.pub - cp /var/run/salt-master-keys/master.pub \ - /etc/salt/pki/master/master.pub - - chown -R 10001:10001 /etc/salt/pki/master - chmod 0700 /etc/salt/pki/master - chmod 0400 /etc/salt/pki/master/master.pem - chmod 0644 /etc/salt/pki/master/master.pub + mkdir -p /pki/master + chmod 0700 /pki/master + cp /var/run/salt-master-keys/master.pem /pki/master/master.pem + cp /var/run/salt-master-keys/master.pub /pki/master/master.pub + test -s /pki/master/master.pem + test -s /pki/master/master.pub + chmod 0400 /pki/master/master.pem + chmod 0644 /pki/master/master.pub volumeMounts: - name: master-keys-source mountPath: /var/run/salt-master-keys readOnly: true - name: master-keys - mountPath: /etc/salt/pki/master + mountPath: /pki securityContext: - runAsUser: 0 - runAsGroup: 0 - runAsNonRoot: false - allowPrivilegeEscalation: false - capabilities: - drop: - - ALL - add: - - CHOWN - - FOWNER - - DAC_OVERRIDE + {{- toYaml .Values.agent.containerSecurityContext | nindent 12 }} {{- end }} {{- if $cluster.enabled }} - # Kubelet creates PVC subPath directories root-owned, and Salt must - # chmod/own its pki, cluster pki and cache directories as the non-root - # master user, so prepare them once as root (same tradeoff as the - # classic-mode prepare-master-keys init container). + # Kubelet creates PVC subPath directories root-owned, which the + # non-root master cannot chmod or own. So the directories are created + # here first, by the master's own user (the pod's fsGroup makes the + # volume root group-writable), and the master then mounts the + # existing subdirectories. Same non-root pattern as the salt-minion + # chart; no root and no added capabilities. initContainers: - name: prepare-cluster-dirs image: {{ .Values.agent.image.repository }}:{{ .Values.agent.image.tag }} @@ -95,24 +94,14 @@ spec: - | set -eu + umask 077 mkdir -p /state/master-pki - chown 10001:10001 /state/master-pki - chmod 0700 /state/master-pki {{- if $isolated }} - mkdir -p /state/cluster-pki /state/cache - chown 10001:10001 /state/cluster-pki /state/cache - chmod 0700 /state/cluster-pki {{- end }} {{- if $shared }} - + # The shared volume must already be writable by this uid/gid. mkdir -p /shared/cluster-pki /shared/cache /shared/file-roots /shared/pillar-roots - # Best effort: NFS with root_squash may refuse the chown; the - # share then needs to be writable by uid/gid 10001 already. - chown 10001:10001 /shared/cluster-pki /shared/cache \ - /shared/file-roots /shared/pillar-roots || \ - echo "WARNING: could not chown the shared directories" >&2 - chmod 0700 /shared/cluster-pki || true {{- end }} volumeMounts: - name: state @@ -122,17 +111,7 @@ spec: mountPath: /shared {{- end }} securityContext: - runAsUser: 0 - runAsGroup: 0 - runAsNonRoot: false - allowPrivilegeEscalation: false - capabilities: - drop: - - ALL - add: - - CHOWN - - FOWNER - - DAC_OVERRIDE + {{- toYaml .Values.agent.containerSecurityContext | nindent 12 }} {{- end }} containers: @@ -222,6 +201,7 @@ spec: {{- else }} - name: master-keys mountPath: /etc/salt/pki/master + subPath: master {{- if .Values.agent.jobCache.persistence.enabled }} - name: job-cache mountPath: /var/cache/salt/master/jobs @@ -300,11 +280,12 @@ spec: volumes: {{- if not $cluster.enabled }} - # The generated/existing Secret is mounted separately and copied - # into a writable emptyDir by prepare-master-keys. + # The generated/existing Secret is mounted read-only and copied into + # a writable emptyDir by prepare-master-keys. - name: master-keys-source secret: secretName: {{ .Values.agent.masterKeySecretName | default (printf "%s-master-keys" .Release.Name) }} + defaultMode: 0440 - name: master-keys emptyDir: {} {{- end }} diff --git a/helm/salt-master/values.yaml b/helm/salt-master/values.yaml index f2f5737..ad812fa 100644 --- a/helm/salt-master/values.yaml +++ b/helm/salt-master/values.yaml @@ -106,17 +106,15 @@ agent: fsGroup: 10001 fsGroupChangePolicy: OnRootMismatch - # No added capabilities: when agent.jobCache.persistence.enabled mounts a - # PVC at /var/cache/salt/master/jobs, it comes back root-owned regardless - # of fsGroup, and capabilities.add can't fix that either - not every - # container runtime populates the *ambient* capability set for a - # non-root container (confirmed on this project's own test cluster: - # CapBnd includes CHOWN/FOWNER, CapEff/CapAmb are still empty, so the - # capability is granted but unusable), and even setcap-based file - # capabilities need allowPrivilegeEscalation: true to take effect on - # exec. initContainers.fixCachePerms below (runs as root, once, briefly) - # is the tradeoff instead: this long-running container never runs as - # root, ever. + # No root and no added capabilities anywhere, including the init + # containers: they run with this same context (as the master's own + # non-root user) and create the directories they need themselves, instead + # of a root init container chowning them. That works because the pod's + # fsGroup (above) makes every volume root group-writable for gid 10001, + # and a directory created by uid 10001 is owned by it. The same pattern is + # used by the salt-minion chart. Consequence: any volume you supply + # yourself (agent.cluster.sharedStorage.existingClaim) must already be + # writable by that uid/gid. containerSecurityContext: allowPrivilegeEscalation: false runAsNonRoot: true @@ -124,14 +122,6 @@ agent: drop: - ALL - # Only relevant when jobCache.persistence.enabled mounts a volume at - # /var/cache/salt/master/jobs. Reuses image.repository/tag itself (not - # e.g. busybox) so it can resolve 'salt' by name via that image's own - # /etc/passwd, rather than duplicating its numeric uid here. - initContainers: - fixCachePerms: - enabled: true - # Auto-accepts new minion keys instead of requiring a manual `salt-key -a` # per minion (or a SaltMinionKey CR, once salt-key-operator is installed). # An orthogonal, weaker "accept literally anyone" dev/test convenience - From d70622f9620e783f5ed6dd00c09a21accc9026d8 Mon Sep 17 00:00:00 2001 From: Saifuddin Rangwala Date: Wed, 25 Nov 2026 21:14:23 +0530 Subject: [PATCH 04/10] docs: review and update the documentation for all charts and images Rewrote or corrected the docs against the current code (charts, Dockerfiles, entrypoints, workflows) after the StatefulSet, non-root and cluster-mode changes: - README, src/README: layout, components, master modes (classic and cluster, with the pod-restart limitation), the minion StatefulSet model, testing, Salt 3008.5. - salt-master chart and image: classic vs cluster, all agent.cluster.* values, storage modes, non-root init containers, entrypoint variables, correct defaults and Secret key names, removed per-ordinal Service and other features that do not exist. NOTES.txt updated. - salt-minion chart and images: StatefulSet identity, per-pod keys, keygen Job behaviour, guard rails, real build args, the extension constraint. - docs/: building, releasing, release-prep, ci-debug, helm-test (registry projects and private-CA trust), complete-system-test and the compliance guide rewritten against the real workflows and charts. - salt-key-operator docs: renamed to salt-master, how it relates to trustedMinions and per-pod minion keys. - CHANGELOGs corrected; the never-published master chart v1.0.0 text no longer claims a StatefulSet. - scripts/salt-kubernetes-e2e-local-test.sh: the workloads are StatefulSets, not Deployments (the minion since the previous merge). Co-Authored-By: Claude Sonnet 5.5 --- README.md | 204 ++-- docs/building.md | 134 +-- docs/ci-debug.md | 63 +- docs/complete-system-test.md | 985 ++++-------------- docs/helm-test.md | 83 +- docs/kubernetes-compliance-guide.md | 270 ++--- docs/release-prep.md | 75 +- docs/releasing.md | 147 +-- docs/skill-shortcuts.md | 40 +- helm/salt-key-operator/CHANGELOG.md | 12 +- helm/salt-key-operator/templates/NOTES.txt | 8 +- helm/salt-key-operator/values.yaml | 11 +- helm/salt-master/CHANGELOG.md | 130 +-- helm/salt-master/README.md | 382 +++++-- helm/salt-master/templates/NOTES.txt | 27 +- .../templates/service-headless.yaml | 6 +- .../salt-master/templates/serviceaccount.yaml | 6 +- helm/salt-master/values.yaml | 185 ++-- helm/salt-minion/CHANGELOG.md | 59 +- helm/salt-minion/README.md | 567 ++++++---- helm/salt-minion/salt-extensions.txt | 4 + helm/salt-minion/values.yaml | 86 +- scripts/salt-kubernetes-e2e-local-test.sh | 20 +- src/README.md | 15 +- src/master/CHANGELOG.md | 28 +- src/master/README.md | 119 ++- src/minion/README.md | 491 ++++----- src/minion/kubernetes/salt-extensions.txt | 16 +- src/minion/vcf/salt-extensions.txt | 16 +- src/salt-key-operator/CHANGELOG.md | 7 +- src/salt-key-operator/README.md | 51 +- 31 files changed, 2139 insertions(+), 2108 deletions(-) diff --git a/README.md b/README.md index 453e0e7..9c8db35 100644 --- a/README.md +++ b/README.md @@ -1,88 +1,166 @@ # salt-kubernetes -Helm charts for deploying different flavours of Salt images to Kubernetes. +Container images and Helm charts for running Salt on Kubernetes: a Salt master, +Salt minions that run as pods, and an operator that manages the master's +accepted minion keys declaratively. -## Charts +Salt version: **3008.5** (pinned in the Dockerfiles, `helm/salt-master/values.yaml` +and `scripts/ci.sh`). The images install Salt with the official +[bootstrap script](https://github.com/saltstack/salt-bootstrap) (onedir). +Each component's `CHANGELOG.md` records which Salt and extension versions a +given release carries. -| Chart | Description | +## Repository layout + +| Path | Contents | | --- | --- | -| [salt-master-kubernetes](salt-master-kubernetes) | Installs a Salt master StatefulSet, supporting Salt's native [multi-master mode](https://docs.saltproject.io/en/3006/topics/tutorials/multimaster.html) for active-active horizontal scaling (all replicas share one pre-seeded keypair). Exposed via a flat Service, a headless Service (in-cluster per-ordinal addressing), and optionally one NodePort Service per replica (external per-ordinal addressing). Deliberately minimal - no RBAC, no saltext.kubernetes install. | -| [salt-minion-kubernetes](salt-minion-kubernetes) | Installs Salt Minion and RBAC. Has built-in support to run CIS Kubernetes compliance assessments via kube-bench on-demand Jobs. Supports in-cluster (minion runs as a pod) and external (RBAC only) modes. Like `salt-minion-vcf`, this is a full project directory - its own `Dockerfile` builds a Salt minion preloaded with `saltext.vault` and `saltext.kubernetes`, with `kubectl` bundled in. | -| [salt-minion-vcf](salt-minion-vcf) | Extensible Salt Minion image (Docker, Docker Compose, Kubernetes, and Helm) preloaded with configurable Salt extensions - `saltext.vcf` (VMware Cloud Foundation automation: vCenter, NSX, SDDC-M, VCF Ops) by default, but not limited to it. Includes `saltext.vault` integration for sourcing credentials from HashiCorp Vault into Pillar instead of storing them on disk. Unlike the other entries here, this directory is the full project (Dockerfile, Docker Compose, scripts, docs), not a chart-only directory - the Helm chart itself lives at [`salt-minion-vcf/helm/salt-minion-vcf`](salt-minion-vcf/helm/salt-minion-vcf). | -| [salt-key-operator](salt-key-operator) | A small Go/controller-runtime operator + `SaltMinionKey` CRD - the declarative replacement for running `salt-key -a ` by hand, which (unlike a manual `salt-key -a`, which only ever affects one pod) keeps a minion trusted consistently across every replica of an active-active `salt-master-kubernetes` release. | +| `helm/salt-master` | Chart: Salt master as a StatefulSet (classic or cluster mode). | +| `helm/salt-minion` | Chart: Salt minion as a StatefulSet (one minion and one keypair per pod), plus RBAC. | +| `helm/salt-key-operator` | Chart: the `SaltMinionKey` CRD and its controller. Also a dependency of the master chart. | +| `src/master` | Dockerfile and entrypoint for the master image. | +| `src/minion/kubernetes` | Minion image with `saltext.kubernetes`, `saltext.vault` and `kubectl`. | +| `src/minion/vcf` | Minion image with the VCF extensions (configurable extension list) and `saltext.vault`. | +| `src/salt-key-operator` | Go source of the operator. | +| `docs/` | Build, release, test and CI guides (see below). | +| `scripts/` | Release tag helpers and CI/e2e helper scripts. | + +There is no Helm chart for the VCF minion image. Use the `salt-minion` chart +and point `agent.image.repository` at the VCF image. + +## Components + +| Chart | Image | What it does | Details | +| --- | --- | --- | --- | +| `salt-master` | `salt-master` | StatefulSet `salt-master` plus a flat Service and a headless Service. | [chart README](helm/salt-master/README.md), [image README](src/master/README.md) | +| `salt-minion` | `salt-minion` (from `src/minion/kubernetes`) or `salt-minion-vcf` | StatefulSet of minions, RBAC, key generation Job. `authMode: external` creates RBAC only. | [chart README](helm/salt-minion/README.md), [image README](src/minion/README.md) | +| `salt-key-operator` | `salt-key-operator` | Writes `SaltMinionKey` public keys into the master's trusted-minions ConfigMap. | [README](src/salt-key-operator/README.md) | + +### Master modes + +`agent.cluster.enabled` selects the mode (see the +[master chart README](helm/salt-master/README.md) for all values): + +- **Classic** (default, `false`): one replica, or classic multi-master + (`agent.replicas > 1`) where every replica shares one keypair supplied in + `agent.masterKeySecretName` (required; the chart refuses to render + otherwise). Minions list each master through the headless Service + (`salt-master-.salt-master-headless..svc.cluster.local`). +- **Cluster** (`true`): a Salt master cluster (Salt 3007+, isolated storage + needs 3008+). Needs `agent.replicas >= 2` (use 3 or more). Each master has + its own keypair, minions connect to the flat `salt-master` Service, and any + replica can serve any minion. Opt-in. **Known limitation:** a restarted or + rescheduled master pod cannot rejoin the cluster, so treat pod restarts as + unsupported for now (see the master chart README). + +The master is a StatefulSet. A release installed from an older chart version +that used a Deployment cannot be upgraded in place: reinstall. + +### Minion model + +The minion chart runs a StatefulSet named `agent.minion.idPrefix` (default +`salt-minion`). Pods are `-0 ... -N-1` and each pod is its own +minion: the minion ID is the pod name and each pod has its own keypair. +`agent.minion.id` and the single inline `privateKeyB64`/`publicKeyB64` pair +only work with `agent.replicas: 1`. One key source is required in `in_cluster` +mode: `agent.minion.keySecretName`, inline keys, or +`agent.minion.allowSelfGeneratedKey` (a keygen Job that writes Secret +`-keys`; it only runs when `agent.minion.keySecretName` is empty). See the +[minion chart README](helm/salt-minion/README.md). + +### Minion acceptance + +The master chart installs `salt-key-operator` as a subchart when +`agent.trustedMinions.enabled` is true (the default), and a sidecar in each +master pod copies the trusted-minions ConfigMap into Salt's key directory. +Keys that are not in the ConfigMap are removed from that directory, so with +this enabled you accept minions with a `SaltMinionKey` (one per minion, +i.e. one per minion pod), not with `salt-key -a`. Set +`agent.trustedMinions.enabled=false` to accept with `salt-key` instead. See +[`src/salt-key-operator/README.md`](src/salt-key-operator/README.md). + +## Quick start (from a checkout) + +The charts default to locally built images, so build them first (see +[`docs/building.md`](docs/building.md)) and make them available to your +nodes, or override the image values. -## Quick install (published images/charts) +```bash +# Images +docker build -t salt-master:3008.5 src/master +docker build -t salt-minion:0.1.0 src/minion/kubernetes +docker build -t salt-key-operator:0.1.0 src/salt-key-operator + +# Master (also installs the salt-key-operator subchart; the operator image +# defaults to ghcr.io/saltstack/salt-kubernetes/salt-key-operator:0.1.0, override +# with --set salt-key-operator.image.repository=... if you built your own) +helm dependency update helm/salt-master +helm install salt-master helm/salt-master \ + --namespace salt-master --create-namespace + +# Minion +helm install salt-minion helm/salt-minion \ + --namespace salt --create-namespace \ + --set agent.saltMasterHost=salt-master.salt-master.svc.cluster.local \ + --set agent.minion.allowSelfGeneratedKey=true +``` -The fastest path to a working deployment: install straight from the -published GHCR OCI charts, no local Docker/Helm build required. See -[`docs/releasing.md`](docs/releasing.md) for the full list of published -artifacts, and each component's own `CHANGELOG.md` for exactly which -Salt/extension versions a given tag carries (the tag itself is just that -component's own semver, independent of Salt's version). +The minion chart's default image is +`ghcr.io/saltstack/salt-kubernetes/salt-minion:0.1.0`; set +`agent.image.repository`/`agent.image.tag` to use the image you built. The +master chart's default is the unqualified `salt-master:3008.5`. -### salt-master-kubernetes +Then trust the minion (the key Secret is `-keys`): ```bash -helm install salt-master-kubernetes \ - oci://ghcr.io/saltstack/salt-kubernetes/charts/salt-master-kubernetes \ - --version 1.0.0 \ - --namespace salt-master --create-namespace \ - --set agent.image.repository=ghcr.io/saltstack/salt-kubernetes/salt-master \ - --set agent.image.tag=1.0.0 +kubectl -n salt get secret salt-minion-keys -o jsonpath='{.data.minion\.pub}' | base64 -d +# put that PEM into a SaltMinionKey named salt-minion-0 in namespace salt-master, +# see src/salt-key-operator/README.md +kubectl -n salt-master exec salt-master-0 -c salt-master -- salt 'salt-minion-0' test.ping ``` -For active-active (multiple replicas) and replacing manual `salt-key -a` -with the `SaltMinionKey` CRD, see -[`salt-master-kubernetes/README.md`](salt-master-kubernetes/README.md) and -[`salt-key-operator/README.md`](salt-key-operator/README.md). +[`docs/complete-system-test.md`](docs/complete-system-test.md) has the full +step-by-step version including the operator, multi-master and cluster mode. -```bash -helm install salt-key-operator \ - oci://ghcr.io/saltstack/salt-kubernetes/charts/salt-key-operator \ - --version 0.1.0 \ - --namespace salt-master -``` +## Published artifacts -### salt-minion-kubernetes +Release workflows publish to GHCR on component tags (see +[`docs/releasing.md`](docs/releasing.md) for tag patterns and exact paths). +Which versions exist depends on which tags have been pushed. -```bash -helm install salt-minion-kubernetes \ - oci://ghcr.io/saltstack/salt-kubernetes/charts/salt-minion-kubernetes \ - --version 1.0.0 \ - --set agent.saltMasterHost=salt-master.example.com -``` +## Testing + +Pull requests to `main` run `.github/workflows/ci-cd-pr.yml`: -(`agent.image.repository` already defaults to the published -`ghcr.io/saltstack/salt-kubernetes/salt-minion-kubernetes` image - no override -needed there.) +- hadolint on every Dockerfile under `src/` +- `helm unittest` on the three charts (only `helm/salt-minion` has test + suites, in `helm/salt-minion/tests`) +- `helm lint` on the three charts +- `go fmt` and `go vet` for the operator +- builds of all four images (nothing is pushed) and Trivy scans in log-only + mode (vulnerabilities do not fail the build) +- `helm package` of the three charts -### salt-minion-vcf +The same workflow without the unit tests runs again after merge +(`post-merge.yml`). To run the chart unit tests locally: ```bash -helm install salt-minion-vcf \ - oci://ghcr.io/saltstack/salt-kubernetes/charts/salt-minion-vcf \ - --version 1.0.0 \ - --set image.repository=ghcr.io/saltstack/salt-kubernetes/salt-minion-vcf \ - --set image.tag=0.1.1 \ - --set salt.master=salt-master.example.com +helm plugin install https://github.com/helm-unittest/helm-unittest +helm unittest helm/salt-minion ``` -`salt-minion-vcf` also runs as a plain Docker container, pulling the -published image directly - no Kubernetes required. See -[`salt-minion-vcf/README.md`](salt-minion-vcf/README.md) for the full guide, -including Docker Compose and the local Vault-backed testing workflow. +There are no unit tests for the master or key operator charts and no Go unit +tests run in CI (`go test` is not part of the workflow). The cluster-level +test procedure is in [`docs/complete-system-test.md`](docs/complete-system-test.md). -```bash -docker run -d \ - --name salt-minion-vcf \ - -e SALT_MASTER=salt-master.example.com \ - -v salt-minion-vcf-pki:/etc/salt/pki/minion \ - ghcr.io/saltstack/salt-kubernetes/salt-minion-vcf:0.1.1 -``` +## Documentation -See each chart's `values.yaml` for the full list of configurable parameters. +- [`docs/building.md`](docs/building.md): build images and charts from source +- [`docs/releasing.md`](docs/releasing.md), [`docs/release-prep.md`](docs/release-prep.md): publishing +- [`docs/helm-test.md`](docs/helm-test.md): try a chart on a real cluster with a private registry +- [`docs/complete-system-test.md`](docs/complete-system-test.md): end-to-end test of all components +- [`docs/kubernetes-compliance-guide.md`](docs/kubernetes-compliance-guide.md): CIS assessment workflow +- [`docs/ci-debug.md`](docs/ci-debug.md): reproduce CI failures locally -## Building from source +## License -Need a patched image, a different Salt version, or an air-gapped build with -no route to GHCR? See [`docs/building.md`](docs/building.md). +See [`LICENSE`](LICENSE). diff --git a/docs/building.md b/docs/building.md index 1f383cf..438f456 100644 --- a/docs/building.md +++ b/docs/building.md @@ -1,95 +1,107 @@ # Building From Source -Most users don't need this — the published images and charts on GHCR (see -the main [`README.md`](../README.md)) are the fastest path to a working -deployment. Build from source instead when you need a patched/local image, -a Salt version other than what's published, or an air-gapped build with no -route to GHCR. +Build from source when you need a patched or local image, a Salt version +other than the pinned one, or a build with no route to GHCR. For published +artifacts see [`releasing.md`](releasing.md). ## Prerequisites -- Docker (or another OCI builder) for the images -- Helm 3+ for the charts +- Docker with BuildKit (the default in current Docker). The Dockerfiles use + `--mount=type=secret` and `TARGETARCH`, which need BuildKit. +- Helm 3 for the charts. ## Docker images -Each image is self-contained (pip-installed Salt extensions from PyPI rather -than a checkout of the extension's own repo, where applicable), so all three -build directly from this repo with that image's own directory as the build -context: +Each image builds with its own directory as the build context: ```bash -docker build -t salt-master:3008.5 docker/salt-master -docker build -t salt-minion-vcf:0.1.0 salt-minion-vcf -docker build -t salt-minion-kubernetes:0.1.0 salt-minion-kubernetes +docker build -t salt-master:3008.5 src/master +docker build -t salt-minion:0.1.0 src/minion/kubernetes +docker build -t salt-minion-vcf:0.1.0 src/minion/vcf +docker build -t salt-key-operator:0.1.0 src/salt-key-operator ``` -See each image's own README for the full build-arg reference (Salt version, -extension selection, internal PyPI/apt mirrors for air-gapped builds, etc.): +Image names and tags are your choice. The chart defaults are +`salt-master:3008.5` (master), `ghcr.io/saltstack/salt-kubernetes/salt-minion:0.1.0` +(minion) and `ghcr.io/saltstack/salt-kubernetes/salt-key-operator:0.1.0` (operator), so +override the image values when you use your own build (see below). -- [`docker/salt-master/README.md`](../docker/salt-master/README.md) -- [`salt-minion-vcf/README.md`](../salt-minion-vcf/README.md) -- [`salt-minion-kubernetes/README.md`](../salt-minion-kubernetes/README.md) +### Build arguments -### Running a locally-built image +| Argument | Images | Default | Purpose | +| --- | --- | --- | --- | +| `SALT_VERSION` | master, both minions | `3008.5` | Salt version. `latest` is also accepted. | +| `SALT_UID`, `SALT_GID` | both minions | `10001` | Numeric user and group of the non-root `salt` user. (The master image uses a fixed `10001:10001`.) | +| `INCLUDE_KUBECTL`, `KUBECTL_VERSION` | both minions | `true`, `v1.30.2` | Bundle `kubectl` (checksum verified). | +| `EXTRA_SALT_EXTENSIONS` | both minions | empty | Extra pip requirements, space separated, installed after `salt-extensions.txt`. | +| `PIP_INDEX_URL`, `PIP_TRUSTED_HOST`, `PIP_ONLY_BINARY` | both minions | empty | Install the Salt extensions through a PyPI mirror. | +| `APT_MIRROR` | both minions | empty | Alternative Ubuntu apt mirror. | +| `SALT_GPG_KEY_URL`, `SALT_APT_REPO_URL` | both minions | public Salt package repository | Override for restricted networks. | -`salt-minion-vcf` also runs as a plain Docker container or via Docker -Compose, without Kubernetes — see -[`salt-minion-vcf/README.md`](../salt-minion-vcf/README.md) for the full -guide, including the local Vault-backed testing workflow: +Both minion Dockerfiles also have `SALT_HOME` and `SALT_SHELL`. Read the +Dockerfiles for the authoritative list. The master Dockerfile only takes +`SALT_VERSION`. -```bash -docker run -d \ - --name salt-minion-vcf \ - -e SALT_MASTER=salt-master.example.com \ - -v salt-minion-vcf-pki:/etc/salt/pki/minion \ - salt-minion-vcf:0.1.0 -``` +Extensions installed by default are listed in +`src/minion/kubernetes/salt-extensions.txt` (`saltext.kubernetes`, +`saltext.vault`) and `src/minion/vcf/salt-extensions.txt` (the same plus +`saltext.vcf` and `saltext.bmc`). The extension step constrains `salt` to the +installed onedir version, so pip does not replace it. -or with Docker Compose: +Examples: ```bash -cd salt-minion-vcf -cp .env.example .env # set SALT_MASTER, etc. -docker compose up -d --build +# Different Salt version +docker build --build-arg SALT_VERSION=3007.1 -t salt-master:3007.1 src/master + +# Extensions through an internal PyPI mirror +docker build \ + --build-arg PIP_INDEX_URL= \ + --build-arg PIP_TRUSTED_HOST= \ + --build-arg PIP_ONLY_BINARY=:all: \ + -t salt-minion:0.1.0 src/minion/kubernetes + +# Private CA needed while downloading build dependencies (BuildKit secret, +# not kept in the final image) +docker build --secret id=build_ca,src=/path/to/ca.crt -t salt-master:3008.5 src/master ``` -### Getting a locally-built image onto a cluster +See [`../src/master/README.md`](../src/master/README.md) and +[`../src/minion/README.md`](../src/minion/README.md) for more. -- **With a registry:** tag and push, then point the chart's - `agent.image.repository`/`image.repository` value at your registry path. -- **Without a registry** (air-gapped/test clusters): `docker save` the image - and `ctr -n k8s.io images import` it directly into every node's containerd - store, then set `image.pullPolicy: Never` (or `agent.image.pullPolicy`) so - Kubernetes doesn't try to pull. +### Getting a locally built image onto a cluster + +- **With a registry:** tag and push, then set the chart's + `agent.image.repository` and `agent.image.tag`. A registry that organises + images in projects (such as Harbor) needs the project in the path: + `//:`. See [`helm-test.md`](helm-test.md). +- **Without a registry:** `docker save` the image and import it into every + node's containerd store (`ctr -n k8s.io images import`), then set + `agent.image.pullPolicy=Never`. ## Helm charts -The charts themselves need no build step — install straight from a checkout -of this repo: +The charts need no build step. Install from a checkout. The master chart +bundles the operator as a dependency, so fetch it first: ```bash -helm install salt-master-kubernetes ./salt-master-kubernetes -f my-values.yaml -helm install salt-minion-kubernetes ./salt-minion-kubernetes -f my-values.yaml -helm install salt-minion-vcf ./salt-minion-vcf/helm/salt-minion-vcf \ - --set salt.master=salt-master.example.com +helm dependency update helm/salt-master +helm install salt-master helm/salt-master --namespace salt-master --create-namespace \ + --set agent.image.repository=//salt-master +helm install salt-minion helm/salt-minion --namespace salt --create-namespace \ + --set agent.saltMasterHost=salt-master.salt-master.svc.cluster.local \ + --set agent.minion.allowSelfGeneratedKey=true \ + --set agent.image.repository=//salt-minion ``` -Remember to also point each chart's image value at whatever you built above -(the charts otherwise default to either the published GHCR image or an -unqualified local tag — check `values.yaml`). - -To produce a distributable `.tgz` instead (e.g. for your own chart repo or -registry): +To produce distributable `.tgz` files (what CI runs as a packaging check): ```bash -helm package salt-master-kubernetes -helm package salt-minion-kubernetes -helm package salt-minion-vcf/helm/salt-minion-vcf +helm dependency update helm/salt-master +helm package helm/salt-master helm/salt-minion helm/salt-key-operator ``` -## Cutting an actual release +## Publishing -Building locally doesn't publish anything. To push a build to -`ghcr.io/saltstack/salt-kubernetes/...` under a real version tag, see -[`docs/releasing.md`](releasing.md). +Building locally publishes nothing. To push under a real version tag, see +[`releasing.md`](releasing.md). diff --git a/docs/ci-debug.md b/docs/ci-debug.md index 2a47d3f..3c26ade 100644 --- a/docs/ci-debug.md +++ b/docs/ci-debug.md @@ -1,30 +1,51 @@ -# CI Debug Shortcut +# CI Debug -When a GitHub Actions workflow fails, follow this checklist to reproduce the error locally and apply fixes. +When a GitHub Actions run fails, reproduce the failing step locally. The +pull request workflow is `.github/workflows/ci-cd-pr.yml`; it is the +reference for what runs and in what order. ## Checklist -1. **Identify the failing job** – Open the Actions run, locate the job name (e.g., `helm`). -2. **Pull the latest code** on your local machine: + +1. Open the failing run and note the failing step name (for example `Helm lint`). +2. Check out the branch: ```bash git fetch origin && git checkout ``` -3. **Run the same steps locally**: - - For Helm lint: - ```bash - helm lint ./salt-master-kubernetes - ``` - - For Dockerfile lint: - ```bash - hadolint docker/salt-master/Dockerfile - ``` -4. **Inspect the error output** – Note line numbers and offending files. -5. **Fix the issue** – Edit the source file, then run the lint step again to ensure it passes. -6. **Commit & push** the fix: +3. Run the same command locally: ```bash - git add - git commit -m "Fix " - git push + # Dockerfile lint (CI scans every Dockerfile under src/) + find src -name Dockerfile | while read -r f; do + docker run --rm -i hadolint/hadolint hadolint --verbose - < "$f" + done + + # Chart dependencies (the master chart depends on salt-key-operator) + helm dependency update helm/salt-master + + # Chart unit tests (CI uses helm-unittest v1.2.1; only helm/salt-minion has suites) + helm plugin install https://github.com/helm-unittest/helm-unittest --version v1.2.1 + helm unittest helm/salt-key-operator + helm unittest --with-subchart=false helm/salt-master + helm unittest helm/salt-minion + + # Helm lint + helm lint helm/salt-key-operator --debug + helm lint helm/salt-master --debug + helm lint helm/salt-minion --debug + + # Go (operator) + (cd src/salt-key-operator && go fmt ./... && go vet ./...) + + # Image build, as CI does it + docker buildx build src/master --file src/master/Dockerfile --load -t salt-master:local ``` -7. **Verify the CI** – The workflow will re‑run automatically; confirm that the job now succeeds. +4. Read the error output for file names and line numbers. For template + errors, `helm template --debug helm/` shows the rendered + output and where it breaks. Some charts fail on purpose without required + values (for example `agent.replicas > 1` without `agent.masterKeySecretName` + on the master chart, or no key source on the minion chart). +5. Fix the source file and re-run the same command until it passes. +6. Commit and push; the workflow re-runs on the pull request. -**Tip:** When the failure is due to YAML parsing (e.g., Helm templates), use `helm template --debug` to get a full rendering and pinpoint the problematic lines. +`scripts/ci.sh` is an older local approximation of the CI pipeline and is not +kept in sync with the workflows (it still references paths that no longer +exist). Prefer the commands above. diff --git a/docs/complete-system-test.md b/docs/complete-system-test.md index ff5a1f3..e5d4ede 100644 --- a/docs/complete-system-test.md +++ b/docs/complete-system-test.md @@ -1,885 +1,334 @@ -# Complete Salt-Kubernetes System Test Guide +# Complete System Test Guide -**Version**: 1.0.0 -**Last Updated**: 2026-09-23 -**Components**: Salt-Key-Operator, Salt-Master, Salt-Minion (Kubernetes & VCF) +Manual end-to-end test of the master chart (`helm/salt-master`), the key +operator (`helm/salt-key-operator`, installed as a subchart of the master +chart) and the minion chart (`helm/salt-minion`) on a real cluster. ---- - -## Overview +The commands were checked against the current chart templates (names, values, +labels, `helm template` output). They have not all been run end to end on a +cluster for this revision; master cluster mode (scenario 6) was run on a real +cluster with three replicas and isolated storage, without the minion steps. If a step fails, trust the chart templates over this text and fix the +document. -This guide provides comprehensive testing procedures for the complete salt-kubernetes system including: -- Salt Key Operator (declarative minion key management) -- Salt Master (multi-master capable) -- Salt Minion Kubernetes (in-cluster minion with kube-bench support) -- Salt Minion VCF (VMware Cloud Foundation extensions) +There is no Helm chart for `salt-minion-vcf`. To test the VCF image, install the +`salt-minion` chart with that image (scenario 7). ## Prerequisites -### Required Tools -```bash -# Verify all required tools are installed -helm version # Helm 3+ -kubectl version --client # Kubernetes 1.24+ -docker --version # Docker for local image builds -go version # Go 1.21+ (for operator development) -``` - -### Kubernetes Cluster -- Kubernetes 1.24+ cluster running -- kubectl authenticated and configured -- Sufficient resources (4+ CPU, 8Gi RAM minimum) +- Kubernetes 1.24+ cluster, `kubectl` and `helm` (v3) configured, about 4 CPU and + 8 GiB free, and a default StorageClass (cluster mode and `jobCache` need PVCs). +- Docker, if you build images yourself (see [`building.md`](building.md)). +- Images the nodes can pull. Chart defaults: master `salt-master:3008.5` + (unqualified, so build and import it, or override it), minion + `ghcr.io/saltstack/salt-kubernetes/salt-minion:0.1.0`, operator + `ghcr.io/saltstack/salt-kubernetes/salt-key-operator:0.1.0`. Override them with + `agent.image.repository`/`agent.image.tag` (master, minion) and + `salt-key-operator.image.repository`/`salt-key-operator.image.tag` (the operator, + set on the master release). A private registry needs + `//`; see [`helm-test.md`](helm-test.md). ```bash -# Verify cluster access -kubectl cluster-info -kubectl get nodes +docker build -t salt-master:3008.5 src/master +docker build -t salt-minion:0.1.0 src/minion/kubernetes +docker build -t salt-key-operator:0.1.0 src/salt-key-operator +helm dependency update helm/salt-master ``` -### Build Local Images (Optional) -For local testing without using published images: +Names used below: the master release is `salt-master` in namespace `salt-master`, +the minion release is `salt-minion` in namespace `salt`. The master StatefulSet +is always named `salt-master` (pods `salt-master-0`, ...), container `salt-master`. +The minion StatefulSet is named `agent.minion.idPrefix`, default `salt-minion` +(pods `salt-minion-0`, ...). ```bash -# Build images from source -docker build --tag salt-master:local ./src/master -docker build --tag salt-minion:local ./src/minion/kubernetes -docker build --tag salt-minion-vcf:local ./src/minion/vcf -docker build --tag salt-key-operator:local ./src/salt-key-operator +M="kubectl -n salt-master exec salt-master-0 -c salt-master --" ``` --- -## Test Scenarios - -### Scenario 1: Basic Salt Master Deployment - -**Objective**: Verify Salt Master starts correctly with persistent identity +## Scenario 1: Single master, manual key acceptance -#### 1.1 Lint and Validate +Disables the operator so `salt-key -a` works. ```bash -# Lint the master chart -helm lint ./helm/salt-master -helm lint ./helm/salt-key-operator - -# Render and validate templates -helm template salt-master ./helm/salt-master \ - --namespace salt-master \ - --include-crds \ - > /tmp/salt-master.yaml - -kubectl apply --dry-run=client --validate=true -f /tmp/salt-master.yaml +helm lint helm/salt-master helm/salt-minion helm/salt-key-operator +helm upgrade --install salt-master helm/salt-master \ + --namespace salt-master --create-namespace \ + --set agent.trustedMinions.enabled=false \ + --wait --timeout 5m +kubectl -n salt-master get pods -l app=salt-master +$M salt-key -L +$M salt-run test.arg testing ``` -**Expected Result**: ✅ No lint errors, validation passes +Expected: pod `salt-master-0` is `Running` and ready, `salt-key -L` lists no +keys, ports 4505 and 4506 listen. There are no Kubernetes probes on the master +pod; "ready" only means the container started. -#### 1.2 Install Salt Master +Master key (chart-generated by the `salt-master-master-keygen` Job into Secret +`salt-master-master-keys`, keys `master.pem` and `master.pub`): ```bash -# Create namespace -kubectl create namespace salt-master - -# Install without Salt Key Operator (basic test) -helm upgrade --install salt-master \ - ./helm/salt-master \ - --namespace salt-master \ - --set namespace=salt-master \ - --set agent.image.pullPolicy=IfNotPresent \ - --wait \ - --timeout 5m - -# Or use published image: -helm upgrade --install salt-master \ - ./helm/salt-master \ - --namespace salt-master \ - --set namespace=salt-master \ - --set agent.image.repository=ghcr.io/saltstack/salt-kubernetes/salt-master \ - --set agent.image.tag=1.0.0 \ - --wait \ - --timeout 5m +kubectl -n salt-master get secret salt-master-master-keys \ + -o jsonpath='{.data.master\.pub}' | base64 -d | sha256sum +$M cat /etc/salt/pki/master/master.pub | sha256sum ``` -#### 1.3 Verify Installation +Expected: identical hashes. -```bash -# Check pod status -kubectl get pods -n salt-master -kubectl describe pod -n salt-master | grep -A 5 "Conditions:" - -# Verify Health -kubectl get pod -n salt-master -o jsonpath='{.items[0].status.containerStatuses[0].ready}' -# Expected: true +## Scenario 2: One minion -# Check master is running -kubectl logs deployment/salt-master -n salt-master --container salt-master | head -20 +```bash +helm upgrade --install salt-minion helm/salt-minion \ + --namespace salt --create-namespace \ + --set agent.saltMasterHost=salt-master.salt-master.svc.cluster.local \ + --set agent.minion.allowSelfGeneratedKey=true \ + --wait --timeout 5m +kubectl -n salt get pods -l app=salt-minion +kubectl -n salt get secret salt-minion-keys # minion.pem, minion.pub from the keygen Job ``` -**Expected Result**: ✅ Pod running, healthy, ports 4505/4506 listening - -#### 1.4 Verify Master Key Persistence +The minion ID is the pod name (`salt-minion-0`). The minion pod has liveness and +readiness probes (`salt-call --local test.ping`). ```bash -# Get master public key from secret -kubectl get secret salt-master-master-keys -n salt-master \ - -o jsonpath='{.data.master\.pub}' | base64 --decode > /tmp/master-secret.pub - -# Get master public key from running pod -kubectl exec deployment/salt-master -n salt-master \ - --container salt-master \ - -- cat /etc/salt/pki/master/master.pub > /tmp/master-pod.pub - -# Compare (hashes should match) -sha256sum /tmp/master-secret.pub /tmp/master-pod.pub +$M salt-key -L # salt-minion-0 is pending +$M salt-key -a salt-minion-0 -y +$M salt salt-minion-0 test.ping # True +kubectl -n salt exec salt-minion-0 -- salt-call --local test.ping ``` -**Expected Result**: ✅ Both hashes match (same key identity) +The chart sets `agent.minion.allowSelfGeneratedKey=true` only to avoid supplying +keys; other key sources (`agent.minion.keySecretName`, inline keys) are in the +[minion chart README](../helm/salt-minion/README.md). -#### 1.5 Verify Salt Functionality +## Scenario 3: Several minions, one keypair each + +Each replica is a separate minion with its own ID and keypair. Replace the single +minion (a release cannot change layout cleanly, and the old Secret holds a single +`minion.pem`/`minion.pub` pair): ```bash -# Test salt-run -kubectl exec deployment/salt-master -n salt-master \ - --container salt-master \ - -- salt-run test.arg testing - -# List minions (empty for now) -kubectl exec deployment/salt-master -n salt-master \ - --container salt-master \ - -- salt-key -L +helm uninstall salt-minion -n salt +kubectl -n salt delete secret salt-minion-keys +helm upgrade --install salt-minion helm/salt-minion \ + --namespace salt \ + --set agent.saltMasterHost=salt-master.salt-master.svc.cluster.local \ + --set agent.minion.allowSelfGeneratedKey=true \ + --set agent.replicas=3 \ + --wait --timeout 5m +kubectl -n salt get pods -l app=salt-minion +kubectl -n salt get secret salt-minion-keys -o json | jq -r '.data | keys[]' +for i in 0 1 2; do + kubectl -n salt exec salt-minion-$i -- sha256sum /etc/salt/pki/minion/minion.pub +done ``` -**Expected Result**: ✅ Command executes, shows empty minion list +Expected: pods `salt-minion-0..2`; the Secret has `salt-minion-N.pem` and +`salt-minion-N.pub` for each pod, and the keygen Job is named +`salt-minion-keygen-3`; the three hashes differ (each pod mounts only its own +pair). `kubectl -n salt exec salt-minion-1 -- salt-call --local grains.get id` +returns `salt-minion-1`. Scaling up later only adds the missing pairs; scaling +down leaves the extra pairs in the Secret. ---- +The chart rejects `agent.minion.id`, and inline `privateKeyB64`/`publicKeyB64`, +when `agent.replicas > 1` (checked with `helm template`). -### Scenario 2: Salt Key Operator Deployment - -**Objective**: Verify operator can manage minion keys declaratively - -#### 2.1 Install Salt Key Operator +Accept all three minions and ping them: ```bash -# Install operator -helm upgrade --install salt-key-operator \ - ./helm/salt-key-operator \ - --namespace salt-master \ - --set image.pullPolicy=IfNotPresent \ - --wait \ - --timeout 5m - -# Or use published: -helm upgrade --install salt-key-operator \ - ./helm/salt-key-operator \ - --namespace salt-master \ - --set image.repository=ghcr.io/saltstack/salt-kubernetes/salt-key-operator \ - --set image.tag=0.1.0 \ - --wait \ - --timeout 5m +for i in 0 1 2; do $M salt-key -a salt-minion-$i -y; done +$M salt '*' test.ping ``` -#### 2.2 Verify Operator Installation +## Scenario 4: Key operator (declarative acceptance) -```bash -# Check operator pod -kubectl get pods -n salt-master | grep operator +With `agent.trustedMinions.enabled=true` (the default) the master chart installs +the operator in the release namespace and runs a `trusted-minions-sync` sidecar in +every master pod. The sidecar copies the ConfigMap `salt-master-trusted-minions` +into Salt's key directory and **removes keys that are not in the ConfigMap**, so +`salt-key -a` no longer sticks. Do not install `helm/salt-key-operator` separately +into the same namespace as well: it would clash with the subchart. -# Check operator logs -kubectl logs deployment/salt-key-operator -n salt-master --tail 50 +```bash +for i in 0 1 2; do $M salt-key -d salt-minion-$i -y; done # remove manual acceptance +helm upgrade salt-master helm/salt-master \ + --namespace salt-master \ + --set agent.trustedMinions.enabled=true \ + --wait --timeout 5m +kubectl -n salt-master get pods -l app=salt-key-operator +kubectl -n salt-master logs deploy/salt-key-operator --tail 50 ``` -**Expected Result**: ✅ Operator pod running, no errors in logs - -#### 2.3 Create Test Minion Key +Create one `SaltMinionKey` per minion pod from its public key: ```bash -# Generate test minion RSA key pair -openssl genrsa -out /tmp/test-minion-key.pem 2048 -openssl rsa -in /tmp/test-minion-key.pem -pubout -out /tmp/test-minion-key.pub - -# Get public key content -PUBLIC_KEY=$(cat /tmp/test-minion-key.pub) - -# Create SaltMinionKey resource -cat < /tmp/salt-minion.yaml - -# Validate -kubectl apply --dry-run=client --validate=true -f /tmp/salt-minion.yaml -``` - -**Expected Result**: ✅ No lint errors, validation passes - -#### 3.2 Create Minion Namespace and Install - -```bash -# Create namespace -kubectl create namespace salt - -# Install minion -helm upgrade --install salt-minion \ - ./helm/salt-minion \ - --namespace salt \ - --set agent.saltMasterHost="salt-master.salt-master.svc.cluster.local" \ - --set agent.image.pullPolicy=IfNotPresent \ - --wait \ - --timeout 5m - -# Or use published: -helm upgrade --install salt-minion \ - ./helm/salt-minion \ - --namespace salt \ - --set agent.saltMasterHost="salt-master.salt-master.svc.cluster.local" \ - --set agent.image.repository=ghcr.io/saltstack/salt-kubernetes/salt-minion \ - --set agent.image.tag=0.1.0 \ - --wait \ - --timeout 5m -``` - -#### 3.3 Monitor Minion Startup - -```bash -# Watch pod initialization -kubectl get pods -n salt -w - -# Check init containers -kubectl describe pod -n salt -l app=salt-minion - -# View minion startup logs -kubectl logs -n salt deployment/salt-minion --all-containers=true -``` - -**Expected Result**: ✅ Pod reaches Running state, container ready - -#### 3.4 Verify Health Checks - -```bash -# Check probe status -kubectl get pod -n salt -l app=salt-minion \ - -o jsonpath='{.items[0].status.containerStatuses[0]}' | jq '.readinessProbes, .livenessProbes' - -# Check probe history in events -kubectl describe pod -n salt -l app=salt-minion | grep -A 2 "Probe" -``` - -**Expected Result**: ✅ Both probes passing, ready status true - -#### 3.5 Verify Minion Authentication to Master +Wait up to two minutes (kubelet ConfigMap resync plus the sidecar's +`syncIntervalSeconds`, default 15 s), then: ```bash -# Get minion ID from pod -MINION_ID=$(kubectl get pod -n salt -l app=salt-minion -o jsonpath='{.items[0].metadata.name}') - -# Check master's pending keys -kubectl exec deployment/salt-master -n salt-master \ - --container salt-master \ - -- salt-key -L - -# Accept the minion -kubectl exec deployment/salt-master -n salt-master \ - --container salt-master \ - -- salt-key -a $MINION_ID -y - -# Verify minion is accepted -kubectl exec deployment/salt-master -n salt-master \ - --container salt-master \ - -- salt-key -L +$M salt-key -L # salt-minion-0..2 accepted +$M salt '*' test.ping ``` -**Expected Result**: ✅ Minion appears in accepted keys - -#### 3.6 Test Minion Connectivity +Delete one and confirm it disappears from `salt-key -L` after the same delay: ```bash -# From master, ping minion -kubectl exec deployment/salt-master -n salt-master \ - --container salt-master \ - -- salt "$MINION_ID" test.ping - -# From minion, test local connectivity -kubectl exec deployment/salt-minion -n salt \ - -- salt-call --local test.ping +kubectl -n salt-master delete saltminionkey salt-minion-2 ``` -**Expected Result**: ✅ Both commands return True - -#### 3.7 Test kube-bench Integration +The `SaltMinionKey` must be in the same namespace as the master release (the +operator finds the ConfigMap labelled `salt.saltstack.io/trusted-minions=true` in +its own namespace). -```bash -# Create test kube-bench job -cat < /tmp/salt-minion-vcf.yaml - -# Validate -kubectl apply --dry-run=client --validate=true -f /tmp/salt-minion-vcf.yaml -``` - -**Expected Result**: ✅ No lint errors, validation passes - -#### 4.2 Create Storage Class (if needed) - -```bash -# Check available storage classes -kubectl get storageclass - -# Create local storage if not available -cat <= 2` (use 3) and a default StorageClass (one PVC per pod). +Start from a clean master as in scenario 5, then: ```bash -# Install with 3 replicas -helm upgrade --install salt-master \ - ./helm/salt-master \ +helm upgrade --install salt-master helm/salt-master \ --namespace salt-master \ + --set agent.cluster.enabled=true \ --set agent.replicas=3 \ - --set agent.image.pullPolicy=IfNotPresent \ - --wait \ - --timeout 5m -``` - -#### 5.2 Verify Master Identity Sharing - -```bash -# All masters should share the same public key -for i in {0,1,2}; do - echo "=== salt-master-$i ===" - kubectl exec statefulset/salt-master -n salt-master --pod=$i \ - --container salt-master \ - -- sha256sum /etc/salt/pki/master/master.pub -done - -# All hashes should be identical + --wait --timeout 10m +kubectl -n salt-master get pods -l app=salt-master +kubectl -n salt-master get secret salt-master-cluster-secret +kubectl -n salt-master exec salt-master-0 -c salt-master -- salt-run cluster.members ``` -**Expected Result**: ✅ All replicas share identical public key - -#### 5.3 Verify Multi-Master Coordination - -```bash -# Create a minion key via the first master -kubectl exec statefulset/salt-master -n salt-master --pod=0 \ - --container salt-master \ - -- salt-key -L - -# Accept a test minion on the first master -MINION_ID="test-multimaster-minion" -cat </dev/null || true - -# Wait for cleanup -sleep 10 +helm upgrade salt-minion helm/salt-minion --namespace salt --reuse-values \ + --set agent.saltMasterHost=salt-master.salt-master.svc.cluster.local ``` -#### 6.2 Deploy Complete Stack +Accept the minions with `SaltMinionKey` objects (as in scenario 4; in cluster mode +the keys are written into the cluster PKI directory). Not covered by this +revision: shared storage mode, minions through the cluster, node failure. -```bash -# 1. Create namespaces -kubectl create namespace salt-master -kubectl create namespace salt - -# 2. Deploy Salt Master -helm upgrade --install salt-master \ - ./helm/salt-master \ - --namespace salt-master \ - --set namespace=salt-master \ - --set agent.image.pullPolicy=IfNotPresent \ - --wait --timeout 5m +**Do not delete or restart a master pod in this scenario.** The pod IP is the +cluster identity and changes on restart; a restarted master cannot rejoin and +quorum is lost after the second restart. See "Master cluster" in the +[master chart README](../helm/salt-master/README.md). -# 3. Deploy Salt Key Operator -helm upgrade --install salt-key-operator \ - ./helm/salt-key-operator \ - --namespace salt-master \ - --set image.pullPolicy=IfNotPresent \ - --wait --timeout 5m +## Scenario 7: VCF minion image -# 4. Deploy Kubernetes Minion -helm upgrade --install salt-minion \ - ./helm/salt-minion \ - --namespace salt \ - --set agent.saltMasterHost="salt-master.salt-master.svc.cluster.local" \ - --set agent.image.pullPolicy=IfNotPresent \ - --wait --timeout 5m - -# 5. Deploy VCF Minion -helm upgrade --install salt-minion-vcf \ - ./helm/salt-minion-vcf \ - --namespace salt \ - --set salt.master="salt-master.salt-master.svc.cluster.local" \ - --set workload.kind=Deployment \ - --set persistence.enabled=false \ - --set image.pullPolicy=IfNotPresent \ - --wait --timeout 5m -``` - -#### 6.3 Accept Minions +The VCF image (`src/minion/vcf`, `salt-minion-vcf`) is used through the same minion +chart. Untested here: ```bash -# List all pending keys -kubectl exec deployment/salt-master -n salt-master \ - --container salt-master \ - -- salt-key -L - -# Get minion names -K8S_MINION=$(kubectl get pod -n salt -l app=salt-minion \ - -o jsonpath='{.items[0].metadata.name}') - -VCF_MINION=$(kubectl get pod -n salt -l app.kubernetes.io/name=salt-minion-vcf \ - -o jsonpath='{.items[0].metadata.name}') - -# Accept both minions -kubectl exec deployment/salt-master -n salt-master \ - --container salt-master \ - -- salt-key -a $K8S_MINION -y - -kubectl exec deployment/salt-master -n salt-master \ - --container salt-master \ - -- salt-key -a $VCF_MINION -y +helm upgrade --install salt-minion helm/salt-minion --namespace salt \ + --set agent.saltMasterHost=salt-master.salt-master.svc.cluster.local \ + --set agent.minion.allowSelfGeneratedKey=true \ + --set agent.image.repository=//salt-minion-vcf \ + --set agent.image.tag=0.1.0 +kubectl -n salt exec salt-minion-0 -- salt-call --local grains.get id ``` -#### 6.4 Verify Connectivity - -```bash -# Ping all minions -kubectl exec deployment/salt-master -n salt-master \ - --container salt-master \ - -- salt '*' test.ping - -# Run a command on all minions -kubectl exec deployment/salt-master -n salt-master \ - --container salt-master \ - -- salt '*' cmd.run 'uname -a' - -# Gather grain data -kubectl exec deployment/salt-master -n salt-master \ - --container salt-master \ - -- salt '*' grains.items -``` - -**Expected Result**: ✅ Both minions respond to master commands - -#### 6.5 Cleanup +## Cleanup ```bash -# Uninstall all releases -helm uninstall salt-minion-vcf -n salt helm uninstall salt-minion -n salt -helm uninstall salt-key-operator -n salt-master helm uninstall salt-master -n salt-master - -# Delete namespaces +kubectl -n salt delete secret salt-minion-keys --ignore-not-found +kubectl -n salt-master delete secret salt-master-master-keys salt-master-keypair --ignore-not-found +kubectl -n salt-master delete pvc --all kubectl delete namespace salt salt-master - -# Verify cleanup -kubectl get ns | grep salt -``` - -**Expected Result**: ✅ All resources cleaned up - ---- - -## Automated Test Script - -A shell script version of the complete integration test: - -```bash -#!/bin/bash -set -e - -echo "=== Complete Salt-Kubernetes Integration Test ===" - -# Configuration -SALT_MASTER_NS="salt-master" -SALT_NS="salt" -TIMEOUT="5m" - -# Cleanup function -cleanup() { - echo "Cleaning up..." - helm uninstall salt-minion-vcf -n $SALT_NS || true - helm uninstall salt-minion -n $SALT_NS || true - helm uninstall salt-key-operator -n $SALT_MASTER_NS || true - helm uninstall salt-master -n $SALT_MASTER_NS || true - kubectl delete namespace $SALT_NS $SALT_MASTER_NS || true - sleep 10 -} - -# Test functions -test_master_install() { - echo "Testing master installation..." - kubectl create namespace $SALT_MASTER_NS - - helm upgrade --install salt-master \ - ./helm/salt-master \ - --namespace $SALT_MASTER_NS \ - --set agent.image.pullPolicy=IfNotPresent \ - --wait --timeout $TIMEOUT - - echo "✅ Master installed" -} - -test_operator_install() { - echo "Testing operator installation..." - helm upgrade --install salt-key-operator \ - ./helm/salt-key-operator \ - --namespace $SALT_MASTER_NS \ - --set image.pullPolicy=IfNotPresent \ - --wait --timeout $TIMEOUT - - echo "✅ Operator installed" -} - -test_minion_kubernetes() { - echo "Testing kubernetes minion..." - kubectl create namespace $SALT_NS - - helm upgrade --install salt-minion \ - ./helm/salt-minion \ - --namespace $SALT_NS \ - --set agent.saltMasterHost="salt-master.$SALT_MASTER_NS.svc.cluster.local" \ - --set agent.image.pullPolicy=IfNotPresent \ - --wait --timeout $TIMEOUT - - echo "✅ Kubernetes minion installed" -} - -test_minion_vcf() { - echo "Testing VCF minion..." - helm upgrade --install salt-minion-vcf \ - ./helm/salt-minion-vcf \ - --namespace $SALT_NS \ - --set salt.master="salt-master.$SALT_MASTER_NS.svc.cluster.local" \ - --set image.pullPolicy=IfNotPresent \ - --wait --timeout $TIMEOUT - - echo "✅ VCF minion installed" -} - -# Main test flow -trap cleanup EXIT - -cleanup -test_master_install -test_operator_install -test_minion_kubernetes -test_minion_vcf - -echo "" -echo "=== All Tests Passed ✅ ===" ``` ---- - -## Success Criteria +Chart-generated Secrets (master keys, cluster secret, minion keys), the +`SaltMinionKey` CRD and PVCs are not removed by `helm uninstall`. Delete them to +start with a new identity. -All tests are considered successful when: +## Success criteria -- ✅ All Helm charts pass linting -- ✅ All templates render without errors -- ✅ All pods reach Running state -- ✅ All containers pass health checks -- ✅ Salt Master is accessible via salt-key and salt commands -- ✅ Minions appear in salt-key listing -- ✅ Master can execute commands on minions via salt -- ✅ Keys persist across pod restarts (VCF) -- ✅ Multi-master shares keypair and minion keys -- ✅ Operator can create/delete minion keys declaratively +- `helm lint` passes for the three charts. +- Master pods start; `salt-key -L` and `salt` commands work. +- Minions appear (pending, then accepted) and answer `test.ping`; with several + replicas each pod has a distinct ID and keypair. +- Operator: `SaltMinionKey` creates and deletes accepted keys on every master + replica. +- Classic multi-master: identical `master.pub` on all replicas. +- Cluster mode: `cluster.members` lists every master. ## Troubleshooting -### Pod stuck in pending -```bash -kubectl describe pod -n -# Check: resource requests, node selectors, node availability -``` - -### Minion not connecting to master -```bash -# Check minion logs -kubectl logs -n salt --all-containers - -# Verify master is accessible -kubectl exec -n salt -- nc -zv salt-master.salt-master.svc.cluster.local 4506 - -# Check minion configuration -kubectl exec -n salt -- cat /etc/salt/minion.d/* -``` - -### Health check failing -```bash -# Test manually -kubectl exec -n salt -- salt-call --local test.ping - -# Check probe configuration -kubectl describe pod -n salt | grep -A 10 "Probe" -``` - -### Key not appearing in master -```bash -# Check ConfigMap -kubectl get configmap salt-master-trusted-minions -n salt-master - -# Check sidecar logs -kubectl logs -n salt-master -c trusted-minions-sync -``` - ---- - -## Performance Metrics to Monitor - -During testing, monitor: - -- Pod startup time (target: < 30s) -- Time to first master connection (target: < 60s) -- Health probe response time (target: < 5s) -- Key propagation latency (target: < 2 minutes) -- Multi-master key sync consistency - +| Symptom | Check | +| --- | --- | +| Pod `Pending` | `kubectl describe pod`; PVC binding, node selector, resources. | +| `ImagePullBackOff` | Image path, registry trust on nodes, `pullPolicy`; see `helm-test.md`. | +| Minion does not connect | `kubectl -n salt logs salt-minion-0`; `kubectl -n salt exec salt-minion-0 -- nc -zv salt-master.salt-master.svc.cluster.local 4506`. | +| Minion pod stuck in init | The key Secret is missing: `kubectl -n salt get job,secret`; check the keygen Job logs. | +| Key not accepted on master | `kubectl -n salt-master get configmap salt-master-trusted-minions -o yaml`; `kubectl -n salt-master logs salt-master-0 -c trusted-minions-sync`; operator logs. | +| `salt-key -a` key vanishes | The operator sidecar removes keys that are not in the ConfigMap (scenario 4). | +| Master install fails on `agent.replicas` | Classic multi-master needs `agent.masterKeySecretName`; cluster mode needs `agent.replicas >= 2`. | diff --git a/docs/helm-test.md b/docs/helm-test.md index 7914881..b366394 100644 --- a/docs/helm-test.md +++ b/docs/helm-test.md @@ -1,53 +1,78 @@ # Helm Test Workflow -This document outlines a reproducible workflow to **test Helm charts on a real Kubernetes cluster** using the local Harbor registry. +A reproducible way to test a chart on a real Kubernetes cluster with an image +built from this checkout and pushed to a private registry. The example uses the +master chart; for the minion chart use `src/minion/kubernetes`, +`helm/salt-minion` and the values shown in +[`complete-system-test.md`](complete-system-test.md). ## Prerequisites -- Access to the Kubernetes cluster (`kubectl` configured). -- `helm` version 3 installed. -- Docker (or an OCI builder) on the machine where the commands run. -- Harbor registry reachable from the cluster (service name `harbor-core` on port `5000`). -- The Helm chart you want to test (e.g., `salt-master-kubernetes`). + +- `kubectl` configured for the target cluster, Helm 3, and Docker. +- A registry the cluster can pull from and you can push to. +- Registry layout: `//:`. Registries that use + projects (Harbor, for example) reject a push to `/` with no + project, so create the project first and always include it. +- If the registry uses a certificate from a private CA, that CA must be trusted + in two places: + - the container runtime on **every node** that will pull the image (for + containerd, a `certs.d//` directory with the CA file or a + `hosts.toml`), and + - the Docker daemon you push from (`/etc/docker/certs.d//ca.crt`, or + the equivalent in Docker Desktop and Rancher Desktop). + The master chart has no `imagePullSecrets` value (the minion chart has + `agent.image.imagePullSecrets`), so for the master use a project that nodes can + pull anonymously or configure registry credentials in the node's containerd. ## Steps -1. **Build the Docker image** + +1. **Build the image** ```bash - docker build -t salt-master:ci-test docker/salt-master + docker build -t salt-master:ci-test src/master ``` -2. **Tag & push the image to Harbor** +2. **Tag and push** ```bash - HARBOR=harbor-core:5000 + REGISTRY=registry.example.com + PROJECT=salt IMAGE=salt-master TAG=ci-test - docker tag ${IMAGE}:${TAG} ${HARBOR}/${IMAGE}:${TAG} - docker push ${HARBOR}/${IMAGE}:${TAG} + docker login ${REGISTRY} + docker tag ${IMAGE}:${TAG} ${REGISTRY}/${PROJECT}/${IMAGE}:${TAG} + docker push ${REGISTRY}/${PROJECT}/${IMAGE}:${TAG} ``` -3. **Render the chart (optional sanity check)** +3. **Fetch chart dependencies and render (sanity check)** ```bash - helm template test ./salt-master-kubernetes \ - --set agent.image.repository=${HARBOR}/${IMAGE} \ + helm dependency update helm/salt-master + helm template test helm/salt-master \ + --namespace salt-master \ + --set agent.image.repository=${REGISTRY}/${PROJECT}/${IMAGE} \ --set agent.image.tag=${TAG} \ - --set agent.trustedMinions.enabled=false \ - --set service.gateway.enabled=false \ - --set service.perOrdinal.gateway.enabled=false + --set agent.trustedMinions.enabled=false ``` -4. **Install/upgrade the chart** +4. **Install or upgrade** ```bash - helm upgrade --install salt-master-test ./salt-master-kubernetes \ - --set agent.image.repository=${HARBOR}/${IMAGE} \ + helm upgrade --install salt-master-test helm/salt-master \ + --namespace salt-master --create-namespace \ + --set agent.image.repository=${REGISTRY}/${PROJECT}/${IMAGE} \ --set agent.image.tag=${TAG} \ --set agent.trustedMinions.enabled=false \ - --set service.gateway.enabled=false \ - --set service.perOrdinal.gateway.enabled=false \ --wait --timeout 5m ``` -5. **Verify the deployment** + `agent.trustedMinions.enabled=false` skips the bundled `salt-key-operator` + subchart (whose image is pulled from GHCR by default) and keeps + `salt-key -a` working. Leave it out to test with the operator. +5. **Verify** ```bash - kubectl get pods -l app=salt-master-kubernetes -o wide + kubectl -n salt-master get pods -l app=salt-master -o wide + kubectl -n salt-master exec salt-master-0 -c salt-master -- salt-key -L ``` -6. **Cleanup (optional)** + The pod is `salt-master-0`: the StatefulSet is named `salt-master` + regardless of the release name. +6. **Clean up** ```bash - helm uninstall salt-master-test + helm uninstall salt-master-test -n salt-master ``` - -You can invoke this workflow by asking the assistant to **execute the steps in `docs/helm-test.md`** on your target environment. + The master key Secret (`-master-keys`) created by the keygen Job is + not owned by the release and remains; delete it before reinstalling under the + same release name if you want a new master identity. PVCs created from + `volumeClaimTemplates` also remain. diff --git a/docs/kubernetes-compliance-guide.md b/docs/kubernetes-compliance-guide.md index 1c25a14..e45f3c8 100644 --- a/docs/kubernetes-compliance-guide.md +++ b/docs/kubernetes-compliance-guide.md @@ -1,229 +1,135 @@ # Kubernetes Compliance Guide -End-to-end walkthrough for running CIS Kubernetes Benchmark compliance -assessments via a Salt master/minion deployed into Kubernetes: - -1. [Build the Docker images](#1-build-the-docker-images) -2. [Install the Helm charts](#2-install-the-helm-charts) -3. [Run a compliance assessment](#3-run-a-compliance-assessment) - -This guide is scoped specifically to that workflow (`salt-master-kubernetes` -+ `salt-minion-kubernetes` + kube-bench), not the other charts/projects in -this repo (e.g. `salt-minion-vcf`). +Walkthrough for running CIS Kubernetes Benchmark assessments through a Salt +master and a Salt minion deployed into Kubernetes, using the `salt-master` and +`salt-minion` charts and kube-bench. + +1. [Build the images](#1-build-the-images) +2. [Install the charts](#2-install-the-charts) +3. [Run an assessment](#3-run-an-assessment) + +> **Scope and status.** The master and minion parts (steps 1 and 2) match the +> charts in this repository. The kube-bench pieces are not part of this +> repository: the minion chart here no longer renders any kube-bench resources +> or pillar, and `kube_bench_cache` comes from `saltext.kubernetes` (pinned in +> `src/minion/kubernetes/salt-extensions.txt`) and the separate +> `salt-k8s-compliance` repository. Steps 2c and 3 are carried over from earlier +> revisions of this guide and **were not re-verified** against the current +> charts; check them against those projects before relying on them. ## Prerequisites -- Docker, for building the images (or skip straight to the published images — - see [`docs/releasing.md`](releasing.md)) -- Helm 3+ and `kubectl` pointed at your target cluster -- A registry (or another way to get images onto your nodes, e.g. `ctr images - import` for air-gapped clusters with no registry configured) - -## 1. Build the Docker images - -Both images are self-contained — pip-installed Salt extensions from PyPI -rather than a checkout of the extension's own repo — so either builds -directly from this repo, with that image's own directory as the build -context. - -### 1a. salt-master - -```bash -docker build -t salt-master:3008.5 docker/salt-master -``` - -Override `SALT_VERSION` to pin a different Salt release (defaults to -`3008.5` — see [`docker/salt-master/CHANGELOG.md`](../docker/salt-master/CHANGELOG.md)): - -```bash -docker build --build-arg SALT_VERSION=3007.1 -t salt-master:3007.1 docker/salt-master -``` - -### 1b. salt-minion-kubernetes - -Preloaded with `saltext.kubernetes` (for `kube_bench_cache`, used in step 3) -and `saltext.vault` — see -[`salt-minion-kubernetes/salt-extensions.txt`](../salt-minion-kubernetes/salt-extensions.txt) -and [`CHANGELOG.md`](../salt-minion-kubernetes/CHANGELOG.md) for exact -versions: - -```bash -docker build -t salt-minion-kubernetes:0.1.0 salt-minion-kubernetes -``` +- Docker to build the images, or use published images (see + [`releasing.md`](releasing.md)). +- Helm 3 and `kubectl` for the target cluster. +- A registry, or another way to get images onto your nodes (see + [`building.md`](building.md)). -If you're behind a proxy/VPN that blocks public PyPI, route the extension -installs through an internal mirror instead: +## 1. Build the images ```bash -docker build \ - --build-arg PIP_INDEX_URL= \ - --build-arg PIP_TRUSTED_HOST= \ - --build-arg PIP_ONLY_BINARY=:all: \ - -t salt-minion-kubernetes:0.1.0 salt-minion-kubernetes +docker build -t salt-master:3008.5 src/master +docker build -t salt-minion:0.1.0 src/minion/kubernetes ``` -See [`docker/salt-master/README.md`](../docker/salt-master/README.md) and -[`salt-minion-kubernetes/README.md`](../salt-minion-kubernetes/README.md) for -the full build-arg reference for each image. +`SALT_VERSION` (default `3008.5`) pins a different Salt version for either image: +`--build-arg SALT_VERSION=...`. The minion image preloads `saltext.kubernetes` +and `saltext.vault` (versions in `src/minion/kubernetes/salt-extensions.txt`) and +bundles `kubectl`. Behind a restricted network, route extension installs through +a mirror with `PIP_INDEX_URL`, `PIP_TRUSTED_HOST` and `PIP_ONLY_BINARY`. The full +argument list is in [`building.md`](building.md). -### 1c. Get the images onto your cluster +Get the images onto the cluster with a registry (`//`, +see [`helm-test.md`](helm-test.md)) or by importing them into every node's +containerd store with `pullPolicy: Never`. -Already published, independently of this build step — see -[`docs/releasing.md`](releasing.md) for the exact `ghcr.io/saltstack/salt-kubernetes/...` -paths — so most of the time step 1 is only needed to build a local/patched -variant. If you do need to move a locally-built image onto your cluster -yourself: +## 2. Install the charts -- **With a registry:** tag and push both images, then reference - `/salt-master`/`/salt-minion-kubernetes` in the Helm - values below. -- **Without a registry** (air-gapped/test clusters): `docker save` each - image and `ctr -n k8s.io images import` it directly into every node's - containerd store, then set `image.pullPolicy: Never` in the Helm values so - Kubernetes doesn't try to pull. - -## 2. Install the Helm charts - -### 2a. salt-master-kubernetes +### 2a. salt-master ```bash -helm install salt-master-kubernetes ./salt-master-kubernetes -f my-master-values.yaml +helm dependency update helm/salt-master +helm install salt-master helm/salt-master \ + --namespace salt-master --create-namespace \ + -f my-master-values.yaml ``` -Key values (see [`salt-master-kubernetes/values.yaml`](../salt-master-kubernetes/values.yaml) -for the full list): +Key values (full list in [`helm/salt-master/values.yaml`](../helm/salt-master/values.yaml)): | Value | Purpose | | --- | --- | -| `agent.image.repository` / `agent.image.tag` | The `salt-master` image built in step 1a. | -| `agent.autoAccept` | Set `true` for dev/test to skip manual `salt-key -a` per minion. Leave `false` in production. | -| `agent.persistence.enabled` | Persist `/etc/salt/pki` (master keypair + accepted-minion list) across restarts. Strongly recommended — without it, every restart forgets every accepted minion key. | -| `service.type` | `NodePort` if minions connect from outside the cluster's pod network (e.g. bare containerd, not cluster pods); `ClusterIP` if minions are pods in the same cluster. | -| `service.nodePorts.publish` / `service.nodePorts.ret` | NodePort values forwarding to the master's `4505`/`4506`, when `service.type=NodePort`. | +| `agent.image.repository` / `agent.image.tag` | The master image from step 1 (default `salt-master:3008.5`). | +| `agent.autoAccept` | `true` skips manual acceptance (dev and test only). | +| `agent.trustedMinions.enabled` | Default `true`: minions are accepted with `SaltMinionKey` objects (the operator is installed as a subchart); `salt-key -a` does not stick. Set `false` to use `salt-key`. | +| `agent.jobCache.persistence.enabled` | Persist the job cache across pod replacement. Master keys are not stored on a volume: they live in a Secret. | +| `service.type`, `service.nodePorts.publish`, `service.nodePorts.ret` | `ClusterIP` (default) for minions inside the cluster; `NodePort` (defaults 30505 and 30506) for minions outside the pod network. | -Verify the master came up healthy: +Check the master: ```bash -kubectl -n salt-master get pods -l app=salt-master-kubernetes -kubectl -n salt-master exec -it statefulset/salt-master-kubernetes -- salt-key -L +kubectl -n salt-master get pods -l app=salt-master +kubectl -n salt-master exec salt-master-0 -c salt-master -- salt-key -L ``` -### 2b. salt-minion-kubernetes +### 2b. salt-minion ```bash -helm install salt-minion-kubernetes ./salt-minion-kubernetes -f my-minion-values.yaml +helm install salt-minion helm/salt-minion \ + --namespace salt --create-namespace \ + -f my-minion-values.yaml ``` -Key values (see [`salt-minion-kubernetes/values.yaml`](../salt-minion-kubernetes/values.yaml) -for the full list): +Key values (full list in [`helm/salt-minion/values.yaml`](../helm/salt-minion/values.yaml)): | Value | Purpose | | --- | --- | -| `agent.image.repository` / `agent.image.tag` | The `salt-minion-kubernetes` image built in step 1b (or the published one — see `docs/releasing.md`). | -| `agent.saltMasterHost` | The master's address. If `salt-master-kubernetes` uses `service.type=NodePort`, this is any node's IP — the NodePort is open on every node regardless of which one runs the master pod. | -| `agent.saltMasterPort` | Master's "ret" port. **Must be the NodePort value** (e.g. `30506`), not `4506`, when the master uses `service.type=NodePort`. | -| `agent.saltPublishPort` | Master's "publish" port. **Must be the NodePort value** (e.g. `30505`), not `4505`, same reasoning. | -| `agent.persistence.enabled` | Persist the minion's own keypair across restarts — without it, every restart regenerates a fresh key and the master rejects it as a mismatch. | - -Both `saltMasterPort` and `saltPublishPort` need to change together — Salt's -minion↔master protocol uses two separate ports (the "ret" channel for the -initial handshake/job returns, and the "publish" channel for broadcasting -jobs), and both must be reachable at whatever address you set -`saltMasterHost` to. +| `agent.image.repository` / `agent.image.tag` | The minion image from step 1 (default `ghcr.io/saltstack/salt-kubernetes/salt-minion:0.1.0`). | +| `agent.saltMasterHost` | Master address: `salt-master.salt-master.svc.cluster.local` from inside the cluster, or a node IP with `NodePort`. | +| `agent.saltMasterPort`, `agent.saltPublishPort` | Default 4506 and 4505. With a `NodePort` master set both to the NodePort values (30506 and 30505 by default); they must change together. | +| One of `agent.minion.keySecretName`, `agent.minion.privateKeyB64` with `publicKeyB64`, `agent.minion.allowSelfGeneratedKey` | Required key source. The minion's keypair is kept in a Secret, so it survives pod restarts. | +| `agent.replicas`, `agent.minion.idPrefix` | One StatefulSet pod per minion, each with its own ID (the pod name) and keypair. | +| `rbac.fullAccess` | Default `true` gives the minion cluster-admin rights. Set `false` and supply `rbac.customRoleRules`/`customClusterRoleRules` to restrict. | +| `namespace` | Namespace of every chart resource (default `salt`). | -Accept the new minion's key from the master: +Accept the minion (the minion ID is the pod name, `salt-minion-0` for one replica): ```bash -kubectl -n salt-master exec -it statefulset/salt-master-kubernetes -- salt-key -L -kubectl -n salt-master exec -it statefulset/salt-master-kubernetes -- salt-key -a -kubectl -n salt-master exec -it statefulset/salt-master-kubernetes -- salt '' test.ping +# trustedMinions disabled on the master: +kubectl -n salt-master exec salt-master-0 -c salt-master -- salt-key -a salt-minion-0 -y +# default (operator): create a SaltMinionKey, see src/salt-key-operator/README.md +kubectl -n salt-master exec salt-master-0 -c salt-master -- salt salt-minion-0 test.ping ``` -`test.ping` returning `True` confirms both ports are wired up correctly. +`test.ping` returning `True` confirms both ports work. -### 2c. kube-bench +### 2c. kube-bench (external, not re-verified) -The `kube-bench-job` chart installs a *suspended* CronJob that acts as a -pod-spec template — `kube_bench_cache.run_assessment` (below) creates -on-demand Jobs from it; the CronJob itself never fires on its own schedule. -It's published as a reference chart in +An earlier version of this guide installed a `kube-bench-job` chart from the [`salt-k8s-compliance`](https://github.com/saltstack/salt-k8s-compliance) -rather than this repo: - -```bash -git clone https://github.com/saltstack/salt-k8s-compliance.git -helm install kube-bench-job salt-k8s-compliance/helm/kube-bench-job -f my-kube-bench-values.yaml -``` - -> Treat this chart as a **reference**, not a drop-in production install. -> Review [`values.yaml`](https://github.com/saltstack/salt-k8s-compliance/blob/main/helm/kube-bench-job/values.yaml) -> before installing — in particular `nodeMounts.*` (host paths differ across -> distros; kubeadm defaults won't match RKE2/k3s), `tolerations` (if -> control-plane nodes should be assessed too), and `cronJob.parallelism` -> (set to your actual node count) — and adapt it to your cluster rather than -> installing it as-is. -> -> **All `nodeMounts.*` paths must be correct for your distro, or assessment -> results will be wrong, not just incomplete.** kube-bench checks that rely -> on a missing/mismatched host path (e.g. the etcd data directory checks) -> come back as an outright **FAIL**, not "skipped" or "not applicable" — -> so a wrong mount silently produces false-negative compliance results -> rather than an obvious error. Verify every path against the actual node -> before trusting the assessment output. - -Two values **must** match the corresponding `salt-minion-kubernetes` values, -or `run_assessment` won't find the CronJob it's looking for: - -| `kube-bench-job` value | Must match `salt-minion-kubernetes` value | -| --- | --- | -| `namespace` | `namespace` | -| `cronJob.name` | `kubeBench.cronJobName` | - -`salt-minion-kubernetes` now defaults `namespace` to `salt` (not `kube-system`), -so install `kube-bench-job` with `--set namespace=salt` unless you've -overridden `salt-minion-kubernetes`'s own `namespace` value too. +repository: a suspended CronJob used as a pod template for on-demand Jobs. Treat +it as a reference, not a drop-in install. Review its `values.yaml` first: host +mount paths (`nodeMounts.*`) differ between distributions, and a wrong path +produces false FAIL results rather than an error. Its namespace must match the +namespace the minion's ServiceAccount can reach (the minion chart's `namespace`, +default `salt`), and the CronJob name must match whatever `kube_bench_cache` is +configured to look for. The current minion chart has no `kubeBench.*` or +`pillar.*` values; provide the `kube_bench` pillar yourself, for example from +the master's `pillar_roots`. -See [`salt-k8s-compliance/helm/kube-bench-job/README.md`](https://github.com/saltstack/salt-k8s-compliance/blob/main/helm/kube-bench-job/README.md) -for the full configuration reference, including host-path mounts for -non-kubeadm distros (RKE2/k3s) and the RBAC gaps to watch for on multi-node -clusters. +## 3. Run an assessment -## 3. Run a compliance assessment - -Assessments are triggered from the Salt master, via the `kube_bench_cache` -execution module (installed on the minion as part of `saltext.kubernetes`). - -Force a fresh assessment right now, regardless of any cached result: +Not re-verified; the module is provided by `saltext.kubernetes`. From the master: ```bash -kubectl -n salt-master exec -it statefulset/salt-master-kubernetes -- \ - salt '' kube_bench_cache.run_assessment -``` - -Returns `{"result": true, "message": ""}` on success (or -`{"result": false, "message": ""}` on failure) once the on-demand Job -completes and results are written to the minion's local cache. +kubectl -n salt-master exec salt-master-0 -c salt-master -- \ + salt 'salt-minion-0' kube_bench_cache.run_assessment -Look up a specific CIS control's aggregated status (collects a fresh -assessment first only if the cache is stale — see `pillar.ttlSeconds` -below): - -```bash -kubectl -n salt-master exec -it statefulset/salt-master-kubernetes -- \ - salt '' kube_bench_cache.status_for_check test_number=1.1.11 +kubectl -n salt-master exec salt-master-0 -c salt-master -- \ + salt 'salt-minion-0' kube_bench_cache.status_for_check test_number=1.1.11 ``` -Returns `{"status": "PASS"|"WARN"|"FAIL"|"ERROR", "comment": ""}`. -kube-bench runs the full check set on every node regardless of role, so a -multi-node cluster can have multiple results for the same control — -`status_for_check` aggregates worst-status-wins (`FAIL` if any node fails, -`PASS` only if every node passes) and lists each node's result in `comment`. - -### Configuration - -`kube_bench_cache`'s behavior (namespace, cache TTL, Job vs. DaemonSet -collection strategy, auth mode, etc.) is driven by the `kube_bench` pillar -key, rendered into `/srv/pillar/kube_bench.sls` by the `pillar.*` values in -`salt-minion-kubernetes/values.yaml` — these must stay in sync with the -`kube-bench-job` chart values from step 2c (namespace, CronJob name, label -selector). +`run_assessment` forces a fresh run; `status_for_check` returns the aggregated +status of one CIS control, collecting a new assessment first when the cache is +stale. kube-bench runs the full check set on every node, so the status is the +worst result across nodes with per-node detail in `comment`. The cache TTL, the +Job namespace and similar options come from the `kube_bench` pillar. diff --git a/docs/release-prep.md b/docs/release-prep.md index ab6ba1a..118921b 100644 --- a/docs/release-prep.md +++ b/docs/release-prep.md @@ -1,40 +1,57 @@ # Release Preparation Checklist -Use this guide to prepare a new release of the `salt-kubernetes` charts and container images. +Prepare a release of one component (an image or a chart) before tagging it. +How tagging and publishing work, and the tag patterns, are in +[`releasing.md`](releasing.md). The release workflows build and push for you: +you do not push images or chart packages by hand. + +## 1. Decide what is being released + +Images and charts are versioned independently. A chart that should ship a new +image needs its `values.yaml` image tag changed in a commit (the workflow does +not do that), and the image has to be released first. + +## 2. Change the sources + +- Image: edit the Dockerfile (`ARG SALT_VERSION`) or `salt-extensions.txt` under + `src/`. +- Chart: edit `Chart.yaml` (`version`) and `values.yaml` under `helm//`. + The release workflow overwrites `version` and `appVersion` on the runner with + the tag's version, so keep `Chart.yaml` equal to the version you are about to + tag (the key operator chart workflow requires this, see `releasing.md`). +- Add the entry to the component's `CHANGELOG.md`: `src/master/CHANGELOG.md`, + `helm/salt-master/CHANGELOG.md`, `helm/salt-minion/CHANGELOG.md` (image and + chart), `src/salt-key-operator/CHANGELOG.md`, + `helm/salt-key-operator/CHANGELOG.md`. Record the Salt and extension versions + for images and the default image for charts. +- Update the documentation that names versions (root `README.md`, chart + READMEs, `docs/`). + +## 3. Verify locally -## 1. Version bump -- Update `Chart.yaml` in each chart directory (`salt-master-kubernetes`, `salt-minion-kubernetes`, `salt-minion-vcf/helm/salt-minion-vcf`). -- Update the image tags in the Helm `values.yaml` files if you are pinning a new version. -- Commit the changes with a message like `chore: bump version to 1.2.3`. - -## 2. Build & push images ```bash -# Example for the master image -docker build -t salt-master:1.2.3 docker/salt-master -docker tag salt-master:1.2.3 ghcr.io/saltstack/salt-kubernetes/salt-master:1.2.3 -docker push ghcr.io/saltstack/salt-kubernetes/salt-master:1.2.3 +helm dependency update helm/salt-master +helm lint helm/salt-master helm/salt-minion helm/salt-key-operator +helm unittest helm/salt-minion # needs the helm-unittest plugin +docker build -t salt-master:test src/master # and the other images you changed ``` -Repeat for `salt-minion-kubernetes` and `salt-minion-vcf`. -## 3. Package Helm charts +Pull request CI runs the same checks plus hadolint, Go vet, image builds and +Trivy scans. Merge the change to `main` first and wait for CI. + +## 4. Tag + +Push the component's tag from the merge commit (see `releasing.md`): + ```bash -helm package salt-master-kubernetes -helm package salt-minion-kubernetes -helm package salt-minion-vcf/helm/salt-minion-vcf +git tag salt-master-v1.1.0 +git push origin salt-master-v1.1.0 ``` -The resulting `.tgz` files can be uploaded to a chart repository or GitHub Releases. - -## 4. Create a GitHub release -- Draft a new release on GitHub, tag it with the new version (e.g., `v1.2.3`). -- Attach the packaged chart `.tgz` files. -- Include a changelog summary (you can copy from `CHANGELOG.md`). ## 5. Verify the release -- Install the charts from the release assets on a test cluster. -- Run basic sanity checks (e.g., `helm test` if tests are defined). - -## 6. Post‑release tasks -- Update the documentation (`README.md`, `docs/*.md`) to reference the new version. -- Announce the release to the relevant channels. -You can ask the assistant to **execute the steps in `docs/release-prep.md`** for a guided release process. +- The workflow run succeeded and created a GitHub Release. +- The package is visible and public on GHCR (first release of a component: + change the package visibility, see `releasing.md`). +- Install the published chart and image on a test cluster, for example with the + steps in [`complete-system-test.md`](complete-system-test.md). diff --git a/docs/releasing.md b/docs/releasing.md index 22d095c..27405c9 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -1,79 +1,110 @@ # Releasing -This is a monorepo with several independently-versioned images and charts, so -there is no single repo-wide release tag. Each component is released by -pushing a tag scoped to that component; only that component's workflow -fires. +This is a monorepo with independently versioned images and charts. There is +no repo-wide release tag: pushing a tag scoped to one component fires only +that component's workflow (`.github/workflows/release-*.yml`). -All artifacts publish to GHCR under `ghcr.io/saltstack/salt-kubernetes/...` -(GitHub Container Registry — public, no extra credentials to set up, and -already the pattern this project used before it moved into this monorepo). +Everything publishes to GHCR under the repository owner (`ghcr.io//...`, +`ghcr.io/saltstack/...` for the upstream repository). -## Docker images +## What the workflows do -Each image installs a pinned Salt version (`ARG SALT_VERSION`) plus, for the -two minion images, a pinned set of Salt extensions from PyPI -(`salt-extensions.txt`). **The release tag is an independent semver for the -image — it does not encode the Salt/extension versions.** Check each -component's own `CHANGELOG.md` for exactly what a given tag carries before -assuming. +The workflows do **not** read `CHANGELOG.md`, `Chart.yaml` or any version file +to decide what to publish: the version is whatever follows the tag prefix. +Keep the changelog entry in the same pull request that changes the component, +and add the release heading before tagging; nothing enforces it. -| Component | Tag to push | Publishes to | Changelog | +### Docker images + +| Component | Source | Tag to push | Published as | | --- | --- | --- | --- | -| `docker/salt-master` | `salt-master-image/vX.Y.Z` | `ghcr.io/saltstack/salt-kubernetes/salt-master:X.Y.Z` (and `:latest`) | [`docker/salt-master/CHANGELOG.md`](../docker/salt-master/CHANGELOG.md) | -| `salt-minion-vcf` | `salt-minion-vcf-image/vX.Y.Z` | `ghcr.io/saltstack/salt-kubernetes/salt-minion-vcf:X.Y.Z` (and `:latest`) | [`salt-minion-vcf/CHANGELOG.md`](../salt-minion-vcf/CHANGELOG.md) | -| `salt-minion-kubernetes` | `salt-minion-kubernetes-image/vX.Y.Z` | `ghcr.io/saltstack/salt-kubernetes/salt-minion-kubernetes:X.Y.Z` (and `:latest`) | [`salt-minion-kubernetes/CHANGELOG.md`](../salt-minion-kubernetes/CHANGELOG.md) | -| `salt-key-operator` | `salt-key-operator-image/vX.Y.Z` | `ghcr.io/saltstack/salt-kubernetes/salt-key-operator:X.Y.Z` (and `:latest`) | [`salt-key-operator/CHANGELOG.md`](../salt-key-operator/CHANGELOG.md) | +| Master | `src/master` | `salt-master-vX.Y.Z` | `ghcr.io//salt-master:X.Y.Z` and `:latest` | +| Minion (Kubernetes) | `src/minion/kubernetes` | `salt-minion-vX.Y.Z` | `ghcr.io//salt-minion:X.Y.Z` and `:latest` | +| Minion (VCF) | `src/minion/vcf` | `salt-minion-vcf-vX.Y.Z` | `ghcr.io//salt-minion-vcf:X.Y.Z` and `:latest` | +| Key operator | `src/salt-key-operator` | `salt-key-operator-vX.Y.Z` | `ghcr.io//salt-key-operator:X.Y.Z` and `:latest` | -Each release workflow refuses to publish unless the tag's version already -has a matching heading in that component's `CHANGELOG.md` — add the entry -(Salt version + extension versions) *before* tagging, not after: +Each run builds the image for `linux/amd64`, scans it with Trivy (log-only: a +finding does not stop the release), pushes `linux/amd64` and `linux/arm64` +images, and creates a GitHub Release for the tag. Salt and extension +versions come from the Dockerfile (`ARG SALT_VERSION`, currently `3008.5`) and +`salt-extensions.txt`, not from the tag. The tag is the image's own semver, so +read the component's `CHANGELOG.md` for what a tag carries. -```bash -# 1. Bump versions (Dockerfile ARG SALT_VERSION / salt-extensions.txt) if needed. -# 2. Add a "## salt-master-image/v1.0.1" heading to docker/salt-master/CHANGELOG.md. -# 3. Then: -git tag salt-master-image/v1.0.1 -git push origin salt-master-image/v1.0.1 -``` +### Helm charts -## Helm charts +| Chart | Tag to push | Published as | +| --- | --- | --- | +| `helm/salt-master` | `chart-salt-master-vX.Y.Z` | `oci://ghcr.io//helm/salt-master:X.Y.Z` | +| `helm/salt-minion` | `chart-salt-minion-vX.Y.Z` | `oci://ghcr.io//helm/salt-minion:X.Y.Z` | +| `helm/salt-key-operator` | `chart-salt-key-operator-vX.Y.Z` | `oci://ghcr.io//helm/salt-key-operator:X.Y.Z` | -Charts publish as OCI artifacts to the *same* registry, under a `charts/` -subpath — no separate `helm repo add` or `gh-pages` branch needed. The tag's -version must exactly match the chart's `version:` in `Chart.yaml`, and have a -matching `CHANGELOG.md` heading, or the release workflow fails before -pushing anything. +On the runner, the workflow rewrites `version:` and `appVersion:` in the +chart's `Chart.yaml` to the tag's version, packages the chart and pushes it +(the master workflow runs `helm dependency build` first so the operator +subchart is bundled). The rewritten `Chart.yaml` is not committed, so the +`version:` in the repository can differ from what was published. The image +tags a chart defaults to come from `values.yaml` and are not changed by the +workflow: update `values.yaml` in a commit before tagging. -| Component | Tag to push | Publishes to | Changelog | -| --- | --- | --- | --- | -| `salt-master-kubernetes` | `salt-master-kubernetes-chart/vX.Y.Z` | `oci://ghcr.io/saltstack/salt-kubernetes/charts/salt-master-kubernetes:X.Y.Z` | [`salt-master-kubernetes/CHANGELOG.md`](../salt-master-kubernetes/CHANGELOG.md) | -| `salt-minion-kubernetes` | `salt-minion-kubernetes-chart/vX.Y.Z` | `oci://ghcr.io/saltstack/salt-kubernetes/charts/salt-minion-kubernetes:X.Y.Z` | [`salt-minion-kubernetes/CHANGELOG.md`](../salt-minion-kubernetes/CHANGELOG.md) | -| `salt-minion-vcf` (chart) | `salt-minion-vcf-chart/vX.Y.Z` | `oci://ghcr.io/saltstack/salt-kubernetes/charts/salt-minion-vcf:X.Y.Z` | [`salt-minion-vcf/helm/salt-minion-vcf/CHANGELOG.md`](../salt-minion-vcf/helm/salt-minion-vcf/CHANGELOG.md) | -| `salt-key-operator` (chart) | `salt-key-operator-chart/vX.Y.Z` | `oci://ghcr.io/saltstack/salt-kubernetes/charts/salt-key-operator:X.Y.Z` | [`salt-key-operator/helm/salt-key-operator/CHANGELOG.md`](../salt-key-operator/helm/salt-key-operator/CHANGELOG.md) | +### Scheduled and manual runs -```bash -# 1. Bump version: in the chart's Chart.yaml. -# 2. Add a "## salt-master-kubernetes-chart/v0.1.0" heading to its CHANGELOG.md -# noting which image version it now defaults to. -# 3. Then: -git tag salt-master-kubernetes-chart/v0.1.0 -git push origin salt-master-kubernetes-chart/v0.1.0 -``` +Every release workflow also has a weekly `schedule` (Mondays, UTC) and +`workflow_dispatch`. Without a tag the Docker workflows build and push +`:latest`, and the chart workflows push version `0.0.0-snapshot`. They create +no GitHub Release in that case. + +## Cutting a release + +1. Update the component: `Chart.yaml`/`values.yaml` (chart) or the + Dockerfile/`salt-extensions.txt` (image), and add the `CHANGELOG.md` entry. +2. Merge to `main`. Pull request CI (see the root `README.md`) must pass. +3. Tag the merge commit and push the tag, for example: + ```bash + git tag salt-master-v1.1.0 + git push origin salt-master-v1.1.0 + ``` + or use the interactive helpers `scripts/release-docker-tags.sh` and + `scripts/release-helm-tags.sh`. See "Known problems" below before using the + Docker one. Both scripts check out and pull `main`, and **delete and + re-create** a tag that already exists, locally and on the remote. Read their + prompts before confirming. +4. Watch the workflow run on GitHub. Installing a published chart: ```bash -helm install salt-master-kubernetes \ - oci://ghcr.io/saltstack/salt-kubernetes/charts/salt-master-kubernetes \ - --version 1.0.0 \ - -f my-values.yaml +helm install salt-master oci://ghcr.io//helm/salt-master \ + --version X.Y.Z --namespace salt-master --create-namespace \ + --set agent.image.repository=ghcr.io//salt-master \ + --set agent.image.tag= ``` ## First-time setup -GHCR packages created via `GITHUB_TOKEN` default to **private** on first -push. After the first release of each component, go to the package's -settings on GitHub (org → Packages) and set visibility to **public**, and -link it to this repository if it isn't already — otherwise consumers can't -`docker pull` / `helm pull` it anonymously. +GHCR packages created with `GITHUB_TOKEN` are private on first push. After the +first release of each image or chart, set the package visibility to public in +the organisation's package settings and link it to this repository. Otherwise +anonymous `docker pull` and `helm pull` fail. + +## Known problems with the release automation + +These are properties of the current workflows and scripts, documented so they +do not surprise you: + +- The tag `salt-minion-vcf-vX.Y.Z` also matches the glob `salt-minion-v*`, so it + starts the Kubernetes minion workflow as well, which publishes a nonsense tag + (`cf-vX.Y.Z`) and a GitHub Release for it. +- `scripts/release-docker-tags.sh` creates `salt-minion-kubernetes-vX.Y.Z` for + the Kubernetes minion image, which matches no workflow. Push + `salt-minion-vX.Y.Z` by hand instead. +- The charts `salt-minion` and `salt-key-operator` are pushed to + `oci://ghcr.io///helm` (double slash) by their workflows, unlike the + master chart. The key operator chart workflow also edits + `helm/salt-minion/Chart.yaml` instead of its own, so it packages the version + committed in `helm/salt-key-operator/Chart.yaml`, and the push step (which + looks for a file named after the tag's version) fails unless the tag matches + that committed version. +- The chart default image repositories in the minion and key operator + `values.yaml` (`ghcr.io/saltstack/salt-kubernetes/...`) differ from the path the + image workflows push to (`ghcr.io//`). Check the path you + actually published and set `agent.image.repository` or `image.repository`. diff --git a/docs/skill-shortcuts.md b/docs/skill-shortcuts.md index 03756de..6d54fa3 100644 --- a/docs/skill-shortcuts.md +++ b/docs/skill-shortcuts.md @@ -1,28 +1,32 @@ -# Skill Shortcut Reference +# Task Shortcut Reference -This repository includes a set of **markdown skill files** that you can refer to when assigning complex or multi‑step tasks to the AI. Each file provides a concise checklist or template that the assistant can follow without having to write custom scripts. +Some documents in this directory are written as step lists that an AI coding +assistant (or a person) can follow end to end. Point the assistant at the file +instead of re-describing the task. -## Available skill shortcuts +## Available shortcuts -- **`helm-test.md`** – Steps to build Docker images, push them to the local Harbor registry, and install the Helm chart on a real Kubernetes cluster. -- **`ci‑debug.md`** – How to reproduce CI failures locally, inspect lint errors, and apply quick fixes. -- **`release‑prep.md`** – Checklist for preparing a release: bump version, build/push images, package charts, and create a GitHub release. +- **[`helm-test.md`](helm-test.md)**: build an image, push it to a private + registry, and install a chart on a real cluster. +- **[`ci-debug.md`](ci-debug.md)**: reproduce CI failures locally (lint, chart + unit tests, image builds) and fix them. +- **[`release-prep.md`](release-prep.md)**: checklist for preparing a component + release before tagging (see also [`releasing.md`](releasing.md)). +- **[`complete-system-test.md`](complete-system-test.md)**: end-to-end test of + master, operator and minions on a cluster. -## Using a skill shortcut - -When you want the assistant to perform a complex workflow, you can reference the markdown file directly in your request, e.g.: +## Using one ``` -Please run the steps described in **docs/helm-test.md** on the remote cluster. +Please run the steps in docs/helm-test.md against my cluster. ``` -The assistant will read the file, execute the outlined commands, and report back with results. - -## Adding a new shortcut +Give the assistant the parameters the document leaves open (registry, project, +namespace, image tag). Review any command that changes the cluster or pushes +tags before it runs. -1. Create a new `*.md` file under `docs/`. -2. Include a clear title, a numbered list of actions, and any required parameters. -3. Commit the file – the assistant will automatically be able to reference it. +## Adding a new one ---- -*These shortcuts are intended to keep the repository clean (no executable scripts) while still providing reproducible, documented workflows.* +1. Add a `*.md` file under `docs/`. +2. Use a clear title, numbered steps, and list required parameters. +3. Only include commands you have run against the current charts. diff --git a/helm/salt-key-operator/CHANGELOG.md b/helm/salt-key-operator/CHANGELOG.md index a457e25..056f899 100644 --- a/helm/salt-key-operator/CHANGELOG.md +++ b/helm/salt-key-operator/CHANGELOG.md @@ -1,19 +1,21 @@ # Changelog (salt-key-operator chart) -Records what each `salt-key-operator-chart/vX.Y.Z` release tag (see -[`docs/releasing.md`](../../docs/releasing.md)) defaults to. The chart's own +Records what each chart release defaults to. The release tag is +`chart-salt-key-operator-vX.Y.Z` (see [`docs/releasing.md`](../../docs/releasing.md)); +headings below use the older `salt-key-operator-chart/vX.Y.Z` naming. The chart's own version is independent of the image version it happens to default to — check here, not the tag number. ## salt-key-operator-chart/v0.1.0 - Default image: `salt-key-operator:0.1.0` (see - [`../CHANGELOG.md`](../CHANGELOG.md) for what that image version carries). + [`src/salt-key-operator/CHANGELOG.md`](../../src/salt-key-operator/CHANGELOG.md) for what that image version carries). - Installs the `SaltMinionKey` CRD (`crds/salt.saltstack.io_saltminionkeys.yaml`). - Deliberately lightweight defaults: `replicas: 1`, `leaderElection.enabled: false`, 20m/32Mi resource requests - no control-plane HA for a controller that does nothing but occasionally patch one ConfigMap per namespace. - `watchNamespace: salt-master` by default, matching - `salt-master-kubernetes`'s own default namespace - scopes RBAC to a + `salt-master`'s own default namespace - scopes RBAC to a namespaced `Role`/`RoleBinding` in just that namespace rather than a cluster-wide `ClusterRole`. Recommended install: same namespace as the - target `salt-master-kubernetes` release (`helm install ... -n salt-master`). + target `salt-master` release (`helm install ... -n salt-master`). The `salt-master` chart also installs this chart + as a subchart when `agent.trustedMinions.enabled` is true (the default). diff --git a/helm/salt-key-operator/templates/NOTES.txt b/helm/salt-key-operator/templates/NOTES.txt index 433b6ab..bb411ff 100644 --- a/helm/salt-key-operator/templates/NOTES.txt +++ b/helm/salt-key-operator/templates/NOTES.txt @@ -4,21 +4,21 @@ Check the operator is running: kubectl -n {{ .Release.Namespace }} get pods -l app.kubernetes.io/instance={{ .Release.Name }} This does NOT do anything on its own yet - it only reconciles SaltMinionKey -objects in namespaces where a salt-master-kubernetes release's trusted- -minions ConfigMap already exists. On the salt-master-kubernetes side, +objects in namespaces where a salt-master release's trusted- +minions ConfigMap already exists. On the salt-master side, install/upgrade that chart with: agent.trustedMinions.enabled=true {{- if .Values.watchNamespace }} This operator only watches namespace "{{ .Values.watchNamespace }}" -(watchNamespace) - make sure that's where your salt-master-kubernetes +(watchNamespace) - make sure that's where your salt-master release and SaltMinionKey objects live, or set watchNamespace="" for cluster-wide watching instead. {{- end }} To trust a minion (replacing `salt-key -a `), apply a -SaltMinionKey in the SAME namespace as the target salt-master-kubernetes +SaltMinionKey in the SAME namespace as the target salt-master release: apiVersion: salt.saltstack.io/v1alpha1 diff --git a/helm/salt-key-operator/values.yaml b/helm/salt-key-operator/values.yaml index 6e75e48..013a1ae 100644 --- a/helm/salt-key-operator/values.yaml +++ b/helm/salt-key-operator/values.yaml @@ -1,7 +1,8 @@ image: - # Published to ghcr.io/saltstack/salt-kubernetes/salt-key-operator (see - # docs/releasing.md). Distroless static image - runs as the built-in - # "nonroot" user (uid/gid 65532), no numeric override needed here the way + # Build from src/salt-key-operator (docs/building.md). The release workflow + # pushes to ghcr.io//salt-key-operator (docs/releasing.md); check + # the path you actually publish and override repository to match. + # Distroless static image - runs as the built-in "nonroot" user (uid/gid 65532), no numeric override needed here the way # this repo's other (apt/onedir-based) images require. repository: ghcr.io/saltstack/salt-kubernetes/salt-key-operator tag: "0.1.0" @@ -15,10 +16,10 @@ replicas: 1 # Restricts the operator's watches to a single namespace - and, as long as # this matches the namespace the operator itself is installed into (the -# recommended setup - see README.md and salt-master-kubernetes's own +# recommended setup - see README.md and salt-master's own # namespace default), also switches RBAC from a cluster-wide ClusterRole to # a namespaced Role, the smallest footprint this operator can run with. -# Defaults to "salt-master" to match salt-master-kubernetes's own default +# Defaults to "salt-master" to match salt-master's own default # namespace - install both charts into the same namespace and everything # lines up with no further configuration. Set to "" (cluster-wide) only for # a genuine multi-tenant cluster with SaltMinionKey objects and target diff --git a/helm/salt-master/CHANGELOG.md b/helm/salt-master/CHANGELOG.md index 49f4a5c..12e5e7f 100644 --- a/helm/salt-master/CHANGELOG.md +++ b/helm/salt-master/CHANGELOG.md @@ -1,77 +1,78 @@ # Changelog (salt-master chart) -Records what each `salt-master-chart/vX.Y.Z` release tag (see -[`docs/releasing.md`](../docs/releasing.md)) defaults to. The chart's own version is independent +Records what each chart release defaults to (release tag `chart-salt-master-vX.Y.Z`, see +[`docs/releasing.md`](../../docs/releasing.md); the headings below use the older +`salt-master-chart/vX.Y.Z` form). The chart's own version is independent of the image version it happens to default to — check here, not the tag number. ## salt-master-chart/v1.1.0 -- New `agent.cluster.*`: Salt master cluster mode (`cluster_id`, `cluster_peers`, - `cluster_pki_dir`, `cluster_secret`, `cluster_pool_port`). `agent.cluster.storageMode` - is `isolated` (default; Salt 3008 `cluster_isolated_filesystem`, one PVC per pod, no - shared storage) or `shared` (one ReadWriteMany claim for pki/cache/file_roots/pillar_roots). - In cluster mode each master keeps its own keypair, so `agent.masterKeySecretName` and the - master-keygen Job are not used, and `trustedMinions` writes into `cluster_pki_dir`. - The chart creates (and keeps across upgrades) a random `cluster_secret` Secret unless - `agent.cluster.secretName` is set. -- New `agent.replicas` (default `1`) and `templates/statefulset.yaml`; the leftover - `templates/deployment.yaml` and standalone `templates/job-cache-pvc.yaml` are removed - (the job cache is a `volumeClaimTemplate`). The headless Service gains the - `cluster-pool` port when cluster mode is on. +**Breaking - requires a fresh install, not `helm upgrade`, from v1.0.0 or earlier:** +- `kind: Deployment` -> `kind: StatefulSet` (`templates/deployment.yaml` and the standalone + `templates/job-cache-pvc.yaml` removed, replaced by `templates/statefulset.yaml`). Kubernetes + cannot reconcile a Deployment-owned release into a StatefulSet of the same name in place. The + job cache is now a per-replica `volumeClaimTemplate` (`agent.jobCache.persistence.*`, off by + default), mounted at `/var/cache/salt/master/jobs` in classic mode. +- New `agent.replicas` (default `1`). `agent.replicas > 1` without cluster mode is classic + multi-master: it requires `agent.masterKeySecretName` (the chart fails to render otherwise) + because every replica must share one keypair, and minions list each replica through the + headless Service's per-pod DNS names. Pods start in parallel (`podManagementPolicy: Parallel`). - Default image tag `3008.2` -> `3008.5`. -- Found by testing on a real cluster: cluster mode needs `agent.replicas >= 2` (Salt refuses a - member with no peers), each master's `interface` and `id` must be its own pod IP (Salt uses - `interface` as the consensus node identity), and the state directories need a root init - container (`prepare-cluster-dirs`) because kubelet creates PVC subPaths root-owned. New values: - `agent.cluster.keysCacheDriver` (default Salt's `localfs_key`; `mmap_key` could not read its own - keys on Longhorn volumes), `autoReplaceVoters` (default off) and `minVoters`. - The init containers no longer run as root or add capabilities. `prepare-master-keys` (classic) and `prepare-cluster-dirs` (cluster) run with `agent.containerSecurityContext`, create their directories as the master's own user (the pod's `fsGroup` makes the volumes group-writable) and the master mounts those existing subdirectories - the same pattern as the salt-minion - chart. The Secret with the master keys is mounted `0440`. The unused - `agent.initContainers.fixCachePerms` value is removed. A `sharedStorage.existingClaim` must - already be writable by uid/gid 10001. + chart. The Secret with the master keys is mounted `0440`. The `agent.initContainers.fixCachePerms` + value (a root init container) is removed. A volume you supply yourself + (`sharedStorage.existingClaim`) must already be writable by uid/gid 10001. + +**New: Salt master cluster mode (opt-in, `agent.cluster.enabled`, default `false`):** +- New `agent.cluster.*` values: `enabled`, `id` (default the release name), `clusterDomain`, + `poolPort` (`cluster_pool_port`, default `4520`, also added to the headless Service), + `secretName`, `storageMode`, `persistence.{storageClassName,accessMode,size}`, + `sharedStorage.existingClaim`, `keysCacheDriver`, `autoReplaceVoters` (default `false`) and + `minVoters` (default replicas - 1, at least 1). New `templates/cluster-secret.yaml`: a random + `cluster_secret` Secret `-cluster-secret`, generated once and kept across upgrades + (`helm.sh/resource-policy: keep`) unless `agent.cluster.secretName` is set. +- `agent.cluster.storageMode` is `isolated` (default; Salt 3008 `cluster_isolated_filesystem`, one + PVC per pod, no shared storage; `file_roots`/`pillar_roots` changes need + `salt-run cluster.sync_roots`) or `shared` (one existing ReadWriteMany claim for + pki/cache/file_roots/pillar_roots; `sharedStorage.existingClaim` required). +- In cluster mode each master keeps its own keypair on its own PVC, so `agent.masterKeySecretName` + and the master-keygen Job are not used, and `trustedMinions` writes into `cluster_pki_dir` + (`/etc/salt/pki/cluster`). The chart fails to render when `agent.replicas < 2`. +- Found by testing on a real cluster: Salt refuses a member with no peers, so cluster mode needs + `agent.replicas >= 2` (use 3 or more); each master's `interface` and `id` must be its own pod IP + (Salt uses `interface` as the consensus node identity); `keysCacheDriver` is empty because + `mmap_key` could not read its own keys back on Longhorn volumes (Salt's default `localfs_key` + is used). +- Tested: 3 replicas with isolated storage. Not tested: shared storage, minions connecting + through the cluster, node failure. - **Known limitation:** the pod IP is the cluster identity, so a restarted or rescheduled master - joins as a new learner while its old identity stays a dead voter. Treat pod restarts as - unsupported until the node identity can be made stable. + joins as a new learner while its old identity stays a dead voter; quorum is lost after the + second restart and a 2-replica cluster cannot recover from any single failure. + `cluster_auto_replace_voters` is left off because it was seen to demote a healthy voter. + Treat pod restarts in cluster mode as unsupported until the node identity can be made stable. +- Requires master image `salt-master-image/v1.1.0` or later (the cluster configuration is rendered + by the image's `entrypoint.sh`). `Chart.yaml` `appVersion` is not updated to track the image. ## salt-master-chart/v1.0.0 -**Breaking - requires a fresh install, not `helm upgrade`, from any prior release:** -- `kind: Deployment` → `kind: StatefulSet` (`templates/deployment.yaml` removed, replaced - by `templates/statefulset.yaml`). Kubernetes cannot reconcile a Deployment-owned release - into StatefulSet manifests of the same name in place. -- New `templates/service-headless.yaml` (`clusterIP: None`) for in-cluster per-ordinal DNS, - and optional `templates/service-per-ordinal.yaml` (`service.perOrdinal.enabled`) for - external per-ordinal access. The existing flat `templates/service.yaml`'s default - `service.type` changed `NodePort` → `ClusterIP` (standard practice - nothing exposed - outside the cluster unless explicitly configured); its `clusterIP`/type semantics can - still conflict with a prior release's Service object on `helm upgrade` regardless - - reinstall rather than upgrade. -- New `service.gateway.*` / `service.perOrdinal.gateway.*` (default `enabled: false`): - generates Gateway API `TCPRoute` objects (raw TCP passthrough, e.g. via Envoy Gateway) - for external access instead of NodePort/LoadBalancer - a standard Kubernetes `Ingress` - cannot do this at all (HTTP(S)-only; Salt's ports are raw ZeroMQ). New - `templates/gateway-tcproute.yaml`; per-ordinal TCPRoutes folded into - `templates/service-per-ordinal.yaml`. `service.perOrdinal.type` also changed from - hardcoded `NodePort` to a configurable value, default `ClusterIP` (works as a TCPRoute - backend without needing NodePort at all). -- `agent.persistence.*` (PKI persistence) removed entirely - `agent.masterKeySecretName` - is now the only supported way to give the master a stable identity, and is **required** - when `agent.replicas > 1` (the chart fails fast otherwise). Replaced by - `agent.jobCache.persistence.*`, a separate per-replica PVC (via `volumeClaimTemplates`) - for the master's job/event cache only (`/var/cache/salt/master/jobs`) - an operational - concern, decoupled from identity, which no longer needs protecting since it's always - pre-seeded rather than generated. -- `agent.initContainers.fixPkiPerms` renamed `agent.initContainers.fixCachePerms`. -- Enables genuine active-active multi-master: with `agent.masterKeySecretName` set and - `agent.replicas > 1`, all replicas share one keypair (per Salt's own multi-master - convention) and minions can hold independent, simultaneous connections to every - replica via a `master:` list - see - [`docs.saltproject.io/en/3006/topics/tutorials/multimaster.html`](https://docs.saltproject.io/en/3006/topics/tutorials/multimaster.html). - Accepting minion keys consistently across all replicas still requires the separate - `salt-key-operator` component (see its own `CHANGELOG.md`) - manual `salt-key -a` - only ever affects whichever single pod `kubectl exec` happens to pick. -- New `agent.trustedMinions.*` (default `enabled: false`): delegates minion acceptance +Correction: the earlier text of this entry described a StatefulSet, `service.perOrdinal.*` +Services and an `agent.replicas` value. None of those are in the templates of this +chart version, which still rendered a `Deployment`; the StatefulSet arrived in v1.1.0 above, and +the chart has no per-ordinal Services at all (use the headless Service's per-pod DNS names, or the +flat Service). What v1.0.0 does carry: +- New `templates/service-headless.yaml` (`clusterIP: None`). The flat `templates/service.yaml`'s + default `service.type` changed `NodePort` -> `ClusterIP` (standard practice - nothing exposed + outside the cluster unless explicitly configured). +- New `service.gateway.*` (default `enabled: false`): generates Gateway API `TCPRoute` objects + (raw TCP passthrough, e.g. via Envoy Gateway) for external access instead of + NodePort/LoadBalancer - a standard Kubernetes `Ingress` cannot do this at all (HTTP(S)-only; + Salt's ports are raw ZeroMQ). New `templates/gateway-tcproute.yaml`. +- `agent.persistence.*` (PKI persistence) removed - the master's identity comes from the Secret + named by `agent.masterKeySecretName` (keys `master.pem`/`master.pub`; or the keygen Job's + `-master-keys`). Replaced by `agent.jobCache.persistence.*` for the job/event cache + only (`/var/cache/salt/master/jobs`). +- New `agent.trustedMinions.*` (default `enabled: true`): delegates minion acceptance to `salt-key-operator` entirely. New `templates/configmap.yaml` creates a ConfigMap (rendered with no `data:` key, so `helm upgrade` never stomps the operator's out-of-band writes to it) that a new `trusted-minions-sync` sidecar container @@ -81,12 +82,11 @@ of the image version it happens to default to — check here, not the tag number Salt 3008's `localfs_key` cache driver explicitly rejects symlinks in every key read path as a PKI-tampering hardening measure. `cp` dereferences a symlink source by default, which is what makes the sidecar's copy actually work. Once - enabled, `salt-key -a` no longer works against this master at all (Salt only - ever reads what the sidecar copies in) - that's intentional, see `values.yaml`'s - comment. + enabled, `salt-key -a` no longer sticks (the sidecar removes keys that are not in the + ConfigMap) - that's intentional, see `values.yaml`'s comment. ## salt-master-chart/v0.1.0 - Default image: `salt-master:1.0.0` (`appVersion` in `Chart.yaml`) — see - [`../docker/salt-master/CHANGELOG.md`](../docker/salt-master/CHANGELOG.md) for what that image + [`../../src/master/CHANGELOG.md`](../../src/master/CHANGELOG.md) for what that image version carries. Chart default `agent.image.repository` is still the unqualified local name `salt-master` (see `values.yaml`), not this published tag. diff --git a/helm/salt-master/README.md b/helm/salt-master/README.md index 453e62b..bbf8b9d 100644 --- a/helm/salt-master/README.md +++ b/helm/salt-master/README.md @@ -1,50 +1,114 @@ # salt-master -Installs a Salt master as a Kubernetes `StatefulSet`, supporting Salt's -native [multi-master mode](https://docs.saltproject.io/en/3006/topics/tutorials/multimaster.html) -for active-active horizontal scaling: all replicas share one pre-seeded -keypair, so any of them can be trusted equally by minions. +Installs a Salt master as a Kubernetes `StatefulSet` (`salt-master`, pods +`salt-master-0` .. `salt-master-N-1`). It runs in one of two modes: -Deliberately minimal: unlike `salt-minion-kubernetes`, this chart creates no -RBAC and the image installs no `saltext.kubernetes` — the master never calls -the Kubernetes API itself, only minions do. +- **Classic** (default, `agent.cluster.enabled=false`): one master, or Salt's + native [multi-master mode](https://docs.saltproject.io/en/3006/topics/tutorials/multimaster.html) + with several independent masters that share one pre-supplied keypair. +- **Master cluster** (`agent.cluster.enabled=true`, opt-in): Salt's + [master cluster](https://docs.saltproject.io/en/latest/topics/tutorials/master-cluster.html), + where the masters present one identity to minions. **Read the known + limitation below before using it.** + +Deliberately minimal: unlike the salt-minion chart, this chart gives the master +no Kubernetes API access (the pod's service-account token is not mounted) and +the image installs no `saltext.kubernetes`. The master never calls the +Kubernetes API itself, only minions do. The only RBAC created is a Role for the +one-time master-key generation Job. ## Prerequisites - Kubernetes 1.24+ - Helm 3+ -- The `salt-master` image (built from `docker/salt-master/` in - [saltext-kubernetes](https://github.com/saltstack/saltext-kubernetes)) - available on your nodes/registry +- The `salt-master` image (built from [`src/master`](../../src/master), or + pulled from the published image, see [`docs/releasing.md`](../../docs/releasing.md)) + available on your nodes or registry. Set `agent.image.repository` and + `agent.image.tag` accordingly. +- `agent.trustedMinions.enabled` defaults to `true`, which pulls the + `salt-key-operator` chart in as a dependency: run + `helm dependency update helm/salt-master` before installing from the + repository checkout, or set `agent.trustedMinions.enabled=false`. +- Cluster mode only: a StorageClass that can provision a ReadWriteOnce PVC per + pod (isolated storage, the default) or an existing ReadWriteMany PVC (shared + storage). + +All objects are created in the namespace given by the `namespace` value +(default `salt-master`), and use fixed names (`salt-master`, +`salt-master-headless`, pods `salt-master-N`), so install one release per +namespace. Create the namespace first (`kubectl create namespace salt-master`) +if you create the key Secret before installing, as below. ## Installing the chart -Single replica (dev/test - the master generates its own keypair on first -start if `agent.masterKeySecretName` is left unset): +Single master (dev/test). With `agent.masterKeySecretName` unset, a one-time Job +generates a keypair into the Secret `-master-keys`: ```bash helm install salt-master . -f my-values.yaml ``` -Active-active (3 replicas, one shared identity - see "Active-active" below): +Classic multi-master (3 replicas, one shared keypair): ```bash -kubectl create secret generic salt-master-keypair \ - --from-literal=private-key-b64="$(base64 < master.pem)" \ - --from-literal=public-key-b64="$(base64 < master.pub)" \ - -n salt-master +kubectl create secret generic salt-master-keypair -n salt-master \ + --from-file=master.pem --from-file=master.pub helm install salt-master . \ --set agent.replicas=3 \ --set agent.masterKeySecretName=salt-master-keypair ``` +The Secret must contain the raw PEM files under the keys `master.pem` and +`master.pub`. Create it from files named exactly that, or use +`--from-file=master.pem=`. + +Master cluster (3 replicas, isolated per-pod storage): + +```bash +helm install salt-master . \ + --set agent.cluster.enabled=true \ + --set agent.replicas=3 + +kubectl -n salt-master exec salt-master-0 -c salt-master -- salt-run cluster.members +``` + +## Upgrading from an earlier release + +Chart v1.0.0 and earlier ran the master as a `Deployment`. Since v1.1.0 it is a +`StatefulSet`, and Kubernetes cannot convert one into the other in place: +uninstall the old release and install again (`helm upgrade` fails or leaves an +orphaned Deployment). Also note: + +- The standalone job-cache PVC of the old chart is no longer created; with + `agent.jobCache.persistence.enabled` the job cache now comes from a + `volumeClaimTemplate`, so the new volume starts empty. +- The `agent.initContainers.fixCachePerms` value no longer exists. The init + containers now run non-root (see "Security"). +- The `service.perOrdinal.*` values are not part of this chart (see + "Accessing the masters"). +- Keep the master-key Secret (`-master-keys` or your own + `agent.masterKeySecretName`) when reinstalling so minions keep trusting the + same master keypair. It stays behind after `helm uninstall` if it was + generated by the key Job. +- Do not toggle `agent.cluster.enabled` on an existing release: the + StatefulSet's `volumeClaimTemplates` differ between the modes and are + immutable. Reinstall instead. + ## Uninstalling the chart ```bash helm uninstall salt-master ``` +PVCs created from `volumeClaimTemplates` (the cluster `state` volume or the +`job-cache` volume) are not deleted by Kubernetes when the StatefulSet goes +away. Delete them yourself if you no longer need them. The generated +`-cluster-secret` is annotated `helm.sh/resource-policy: keep` and +also stays behind, so delete it before reinstalling if you want a new cluster +secret. The generated `-master-keys` Secret was created by a Job, not +by Helm, and also stays behind. + ## Configuration The following table lists the most commonly overridden values. See @@ -54,108 +118,248 @@ The following table lists the most commonly overridden values. See | --- | --- | --- | | `namespace` | Namespace for all chart resources. | `salt-master` | | `agent.image.repository` | Salt master image repository. | `salt-master` | -| `agent.image.tag` | Salt master image tag. | `3008.5` | -| `agent.replicas` | Number of master replicas (active-active - see below). | `1` | -| `agent.cluster.enabled` | Salt master cluster mode (see "Master cluster" below). | `false` | -| `agent.cluster.storageMode` | `isolated` (per-pod PVCs, Salt 3008+) or `shared` (one RWX claim). | `isolated` | -| `agent.cluster.secretName` | Existing Secret with key `cluster-secret`. Empty = chart generates one. | `""` | -| `agent.masterKeySecretName` | Existing Secret with the master's keypair (`private-key-b64`/`public-key-b64`). **Required** when `agent.replicas > 1`. | `""` | +| `agent.image.tag` | Salt master image tag (the Salt version the image carries). | `3008.5` | +| `agent.replicas` | Number of masters (StatefulSet replicas). `> 1` needs `agent.masterKeySecretName` (classic) or `agent.cluster.enabled` (cluster, which needs `>= 2`; use 3 or more). | `1` | +| `agent.masterKeySecretName` | Classic mode. Existing Secret with the master keypair as raw files under keys `master.pem` and `master.pub`. **Required** when `agent.replicas > 1` and cluster mode is off. Empty uses `-master-keys`, created by a one-time Job if missing. Ignored in cluster mode. | `""` | | `agent.autoAccept` | Auto-accept new minion keys instead of requiring `salt-key -a`/a `SaltMinionKey`. Leave `false` for a production master. | `false` | -| `agent.masterId` | Sets `id:` on the master itself. Empty uses the pod hostname. Need not be unique across replicas. | `""` | +| `agent.masterId` | Sets `id:` on the master itself. Empty lets Salt choose (classic) or uses the pod IP (cluster). Need not be unique across replicas in classic mode. | `""` | | `agent.presenceEvents` | Fires `salt/presence/present`/`change` events so `manage.present`/`manage.status` reflect which minions are actually connected right now. | `true` | -| `agent.jobCache.persistence.enabled` | Per-replica PVC (via `volumeClaimTemplates`) for the master's job/event cache. Decoupled from identity - PKI is never persisted, only pre-seeded. | `true` | -| `agent.trustedMinions.enabled` | Delegate minion acceptance to `salt-key-operator` (../salt-key-operator) instead of `salt-key -a`. See "Minion acceptance" below. | `false` | +| `agent.jobCache.persistence.enabled` | Classic mode only. Per-replica PVC (via `volumeClaimTemplates`) mounted at `/var/cache/salt/master/jobs`. Ignored in cluster mode. | `false` | +| `agent.jobCache.persistence.storageClassName` / `.accessMode` / `.size` | Settings for that PVC. | `""` / `ReadWriteOnce` / `1Gi` | +| `agent.trustedMinions.enabled` | Delegate minion acceptance to `salt-key-operator` (../salt-key-operator) instead of `salt-key -a`. See "Minion acceptance" below. | `true` | +| `agent.trustedMinions.createConfigMap` / `.configMapName` / `.syncIntervalSeconds` | Whether the chart creates the ConfigMap, its name, and how often the sidecar copies it into Salt's key directories. | `true` / `salt-master-trusted-minions` / `15` | | `agent.nodeSelector` | Pins every replica to a node. | `{}` | -| `service.type` | `ClusterIP`, `NodePort`, or `LoadBalancer` for the flat (non-per-ordinal) Service. `ClusterIP` (in-cluster only) by default - see "External access" below to actually reach the master from outside the cluster. | `ClusterIP` | -| `service.gateway.enabled` | Expose the flat Service via a Gateway API `TCPRoute` (e.g. Envoy Gateway) instead of/alongside NodePort. See "External access" below. | `false` | -| `service.perOrdinal.enabled` | One Service per replica ordinal - needed for **external** minions to hold independent connections to every replica (see "Active-active" below). | `false` | -| `service.perOrdinal.type` | `ClusterIP`, `NodePort`, or `LoadBalancer` for each per-ordinal Service. | `ClusterIP` | +| `agent.podSecurityContext` / `agent.containerSecurityContext` | Non-root uid/gid `10001`, `fsGroup: 10001`, all capabilities dropped. Used by the master, the sidecar and the init containers. | see `values.yaml` | +| `service.type` | `ClusterIP`, `NodePort`, or `LoadBalancer` for the flat `salt-master` Service. `ClusterIP` (in-cluster only) by default - see "External access". | `ClusterIP` | +| `service.nodePorts.publish` / `.ret` | Node ports used when `service.type=NodePort`. | `30505` / `30506` | +| `service.gateway.enabled` | Expose the flat Service via Gateway API `TCPRoute` objects (e.g. Envoy Gateway). See "External access". | `false` | +| `service.gateway.gatewayName` / `.gatewayNamespace` / `.publishSectionName` / `.retSectionName` | The existing Gateway and its two TCP listeners to attach to. `gatewayName` is required when enabled; the namespace defaults to the release namespace. | `""` / `""` / `salt-publish` / `salt-ret` | +| `agent.cluster.enabled` | Salt master cluster mode (see "Master cluster"). | `false` | +| `agent.cluster.id` | `cluster_id`. Empty uses the release name. | `""` | +| `agent.cluster.clusterDomain` | Cluster DNS suffix used to build peer names. | `cluster.local` | +| `agent.cluster.poolPort` | `cluster_pool_port`: peer-to-peer RPC port (container port and headless Service port). | `4520` | +| `agent.cluster.secretName` | Existing Secret with key `cluster-secret`. Empty = the chart generates `-cluster-secret` once and keeps it across upgrades. | `""` | +| `agent.cluster.storageMode` | `isolated` (per-pod PVCs, Salt 3008+) or `shared` (one existing RWX claim). | `isolated` | +| `agent.cluster.persistence.storageClassName` / `.accessMode` / `.size` | Per-pod `state` PVC. Empty class = cluster default. | `""` / `ReadWriteOnce` / `5Gi` | +| `agent.cluster.sharedStorage.existingClaim` | Existing ReadWriteMany PVC. **Required** when `storageMode=shared`. | `""` | +| `agent.cluster.keysCacheDriver` | `keys.cache_driver`. Empty = Salt's default (`localfs_key`). | `""` | +| `agent.cluster.autoReplaceVoters` | `cluster_auto_replace_voters`. Left off on purpose, see the limitation. | `false` | +| `agent.cluster.minVoters` | `cluster_min_voters`. Empty = replicas - 1 (at least 1). Only matters with `autoReplaceVoters`. | `""` | +| `serviceAccount.name` / `.annotations` | Service account of the pods and the key-generation Job. | `salt-master` / `{}` | +| `rbac.create` | Create the Role and RoleBinding the master-key generation Job needs (create/get/list on Secrets). | `true` | + +## Classic or cluster mode + +| | Classic, 1 replica | Classic multi-master | Master cluster | +| --- | --- | --- | --- | +| Enabled by | default | `agent.replicas > 1` and `agent.masterKeySecretName` | `agent.cluster.enabled=true`, `agent.replicas >= 2` (use 3) | +| Master keypair | from Secret | one keypair shared by all, from the Secret | each master generates its own, kept on its PVC | +| What minions see | one master | independent masters, each is a separate connection | one cluster identity | +| Minion `master:` | `salt-master` Service | every pod's headless DNS name, as a list | the flat `salt-master` Service | +| Accepted keys | in the pod (lost on pod replacement) unless `trustedMinions` is on | per pod, so use `trustedMinions` | `cluster_pki_dir` (`/etc/salt/pki/cluster`), shared between masters | +| Pod restarts | fine | fine | **not supported**, see below | + +Use classic mode unless you specifically need minions to see one identity with +jobs routed between masters. Classic mode with one replica is the simplest +setup, and classic multi-master is the more mature way to have more than one +master. ## Master cluster -With `agent.cluster.enabled=true` the masters form a -[Salt master cluster](https://docs.saltproject.io/en/latest/topics/tutorials/master-cluster.html): -minions see one cluster identity, so point them at the flat `salt-master` Service and -any replica can serve any minion (unlike the classic multi-master mode above). +With `agent.cluster.enabled=true` the masters form a Salt master cluster: +minions see one cluster identity, so you point them at the flat `salt-master` +Service and any master can serve any minion (unlike classic multi-master). + +Requirements and behaviour: + +- Salt 3007+ (the image carries 3008.5). The default `isolated` storage mode + uses `cluster_isolated_filesystem`, which needs Salt 3008+. +- `agent.replicas` must be at least 2: Salt refuses to start a cluster member + with no peers, and the chart fails to render with fewer. Use **3 or more** so + the cluster can survive the loss of one member. A 2-replica cluster cannot + recover from any single failure. +- Every master has its own keypair, stored on its own volume. + `agent.masterKeySecretName` and the key-generation Job are not used. +- Each pod sets its `interface` and `id` to its pod IP (Salt uses `interface` + as the node identity in cluster consensus and matches it against + `cluster_peers`). The peers are the other pods' headless-Service DNS names; + the entrypoint waits for them to resolve (up to + `SALT_CLUSTER_PEER_WAIT_SECONDS`, 120 by default) and writes their IPs. The + pods start in parallel (`podManagementPolicy: Parallel`). +- The cluster secret (`cluster_secret`, authenticates joining masters) is read + from `agent.cluster.secretName` (key `cluster-secret`) or generated once by + the chart as `-cluster-secret`. +- The peer RPC port (`agent.cluster.poolPort`, 4520) is added to the pods and + the headless Service. Do not expose it outside the cluster. +- The accepted minion keys and the cluster key pair live in `cluster_pki_dir` + (`/etc/salt/pki/cluster`). `agent.trustedMinions` then writes into + `/etc/salt/pki/cluster/minions` and its siblings. +- `agent.jobCache.persistence` is ignored. + +Storage modes (`agent.cluster.storageMode`): + +- `isolated` (default): every pod gets a PVC (`state`, from + `agent.cluster.persistence`) holding its own keypair, `cluster_pki_dir` and + `cachedir`; masters sync in-band. Changes to `file_roots`/`pillar_roots` + have to be propagated with `salt-run cluster.sync_roots`. No shared storage is + needed. +- `shared`: set `agent.cluster.sharedStorage.existingClaim` to an existing + ReadWriteMany PVC. It is used with the subPaths `cluster-pki`, `cache`, + `file-roots` (mounted at `/srv/salt`) and `pillar-roots` (`/srv/pillar`); each + pod's own keypair still lives on its `state` PVC. The init container creates + those directories as uid/gid `10001`, so the claim must already be writable + by that user. + +The `keysCacheDriver` value is empty by default (Salt's `localfs_key`). Salt +recommends `mmap_key` for isolated mode, but in testing it failed to read its +own keys back on Longhorn volumes, so the chart does not set it. + +Verify the cluster (all masters should be listed): ```bash -helm install salt-master . --set agent.cluster.enabled=true --set agent.replicas=3 kubectl -n salt-master exec salt-master-0 -c salt-master -- salt-run cluster.members ``` -- `isolated` (default): each pod keeps `cluster_pki_dir` and `cachedir` on its own PVC - and peers sync in-band. `file_roots`/`pillar_roots` changes must be propagated with - `salt-run cluster.sync_roots`. -- `shared`: set `agent.cluster.sharedStorage.existingClaim` to a ReadWriteMany PVC. -- Each master has its own keypair; `agent.masterKeySecretName` is ignored. Do not expose - the `cluster-pool` port outside the cluster. +### Known limitation: pod restarts + +A master's cluster identity is its `interface`, which here is the pod IP, and +Salt 3008.5 has no setting that separates identity from bind address. A pod IP +changes whenever the pod is restarted or rescheduled. What that means in +practice: + +- A restarted or rescheduled master joins as a **new** learner and cannot + rejoin under its old identity, which stays behind as a dead voter. +- Quorum is lost after the second restart. A cluster of 2 cannot recover from + any single failure. +- Salt's own recovery option (`cluster_auto_replace_voters`, the chart's + `agent.cluster.autoReplaceVoters`) is off by default. It was seen to demote + a healthy voter instead of the dead one, so the chart leaves it off and you + should not rely on it. + +Until the identity can be made stable (for example `hostNetwork` pinned one pod +per node, or fixed pod IPs), treat pod restarts, node drains and upgrades that +roll the pods in cluster mode as unsupported, and use cluster mode only where +you can accept rebuilding the cluster (reinstall and, if needed, delete the +`state` PVCs) after a restart. Classic mode is not affected. Cluster mode is +opt-in and is not the default. + +### What was tested + +Tested on a real cluster: cluster mode with 3 replicas and isolated storage +(including the pod-restart behaviour described above). **Not tested:** shared storage mode, minions connecting through the cluster, +and node failure. + +## Accessing the masters + +- **In-cluster, cluster mode or a single master:** minions use the flat + Service, `salt-master..svc.cluster.local` ports `4505`/`4506` + (the salt-minion chart's `agent.saltMasterHost`). +- **In-cluster, classic multi-master:** list every pod individually in the + minion's `master:` setting (for the salt-minion chart, give + `agent.saltMasterHost` a list). The always-created headless Service gives each + pod a stable name: + `salt-master-.salt-master-headless..svc.cluster.local` for `N` + in `0..agent.replicas-1`. +- **External minions:** see "External access". This chart creates one flat + Service (and optional TCPRoutes for it) only. There is no per-replica + Service, so it does not provide external addresses for individual classic + replicas. + +Check where your minions point: a minion given only the flat Service in front +of several classic masters is load-balanced per connection, so it sees only the +one master it landed on. ## External access Everything defaults to `ClusterIP` - nothing is reachable from outside the cluster unless you explicitly opt into one of these (standard Kubernetes Ingress cannot do this at all: Ingress is HTTP(S)-only, and Salt's -`4505`/`4506` carry raw ZeroMQ traffic, not HTTP): +`4505`/`4506` carry raw ZeroMQ traffic, not HTTP). They all apply to the flat +`salt-master` Service: - **`service.gateway.enabled=true`** (recommended if you have a Gateway API-compatible controller, e.g. Envoy Gateway): generates two `TCPRoute` - objects (`gateway.networking.k8s.io`) for raw TCP passthrough, attaching - to a `Gateway` your platform team manages separately. Requires - `service.gateway.gatewayName` and two pre-existing TCP listeners on that - Gateway (`service.gateway.publishSectionName`/`retSectionName`). -- **`service.type=NodePort`**: exposes the port directly on every node's - own IP. Simple, no extra controller needed, but not standard practice - for a production cluster (opens a host-level port on every node - regardless of where the pod is actually scheduled) - prefer the Gateway - option above if available. + objects (`gateway.networking.k8s.io/v1alpha2`, one for `4505` and one for + `4506`) for raw TCP passthrough, attaching to a `Gateway` managed separately. + Requires `service.gateway.gatewayName` and two pre-existing TCP listeners on + that Gateway (`service.gateway.publishSectionName`/`retSectionName`). +- **`service.type=NodePort`**: exposes the ports (`service.nodePorts`, default + `30505`/`30506`) on every node's own IP. Simple, no extra controller needed, + but not standard practice for a production cluster (opens a host-level port on + every node regardless of where the pod is scheduled) - prefer the Gateway + option if available. - **`service.type=LoadBalancer`**: standard cloud LB provisioning, if your cluster supports it. -`service.perOrdinal.*` has the equivalent three options -(`gateway.enabled`, `type=NodePort`, `type=LoadBalancer`) for active-active -external access - see below. - -## Active-active (multiple replicas) +When minions reach the masters through one of these, set the minion's +`master_port`/`publish_port` to the exposed ports if they differ from +`4506`/`4505` (see the salt-minion chart's `agent.saltMasterPort` and +`agent.saltPublishPort`). -Every master replica is an independent Salt process - Salt's PUB (`4505`) -and REQ/REP (`4506`) channels are per-process, never shared between -replicas. A minion connected to only one replica only ever sees jobs -dispatched via *that* replica. For genuine fan-out (any replica can reach -any minion), point each minion's `master:` config at a **list** of every -replica's address, not a single Service: +## Classic multi-master (more than one replica) -- **In-cluster minions**: `salt-master-.salt-master-headless..svc.cluster.local` - for `N` in `0..agent.replicas-1` (the headless Service is always created). -- **External minions**: set `service.perOrdinal.enabled=true` for one - Service per replica (see "External access" above for `type`/`gateway` - choices), then use either that replica's NodePort/LoadBalancer address - or its Gateway TCPRoute address. +Every classic master is an independent Salt process - Salt's PUB (`4505`) and +REQ/REP (`4506`) channels are per-process, never shared between replicas. A +minion connected to only one replica only ever sees jobs dispatched via *that* +replica. For genuine fan-out (any replica can reach any minion), point each +minion's `master:` at a **list** of every replica's address, not a single +Service (see "Accessing the masters"). -All replicas must share the identical keypair (`agent.masterKeySecretName`) -- the chart fails to render otherwise. There is no cross-replica job/event -cache by design (matching Salt's own multi-master docs: "the masters do not -share any information") - `agent.jobCache.persistence` is per-replica. +All replicas must share the identical keypair (`agent.masterKeySecretName`) - +the chart fails to render otherwise. Each pod's init container +(`prepare-master-keys`) copies the keys into a writable `emptyDir`; nothing in +`/etc/salt/pki` is persisted. There is no cross-replica job/event cache by +design (matching Salt's own multi-master docs: "the masters do not share any +information"); `agent.jobCache.persistence` is per-replica. ## Minion acceptance Two ways to accept a minion's key, mutually exclusive per release: -- **Traditional** (`agent.trustedMinions.enabled: false`, the default): - `salt-key -a` against a specific pod. With more than one replica this - only affects that one pod - repeat against every replica, or accept the - inconsistency isn't safe for production active-active use. +- **`salt-key-operator`** (`agent.trustedMinions.enabled: true`, the + default): the `salt-key-operator` chart is installed as a dependency of this + chart (`helm dependency update` first). Apply a `SaltMinionKey` custom + resource per minion - it keeps every replica consistent automatically. See + [`salt-key-operator`](../../src/salt-key-operator) and its chart for the full + flow. A `trusted-minions-sync` sidecar in each master pod continuously copies + the operator's ConfigMap into the directories Salt reads, and also removes + any key that is not in the ConfigMap. `salt-key -a` therefore does not stick: + a key accepted that way is removed again within + `agent.trustedMinions.syncIntervalSeconds`. (It is not a direct ConfigMap + volume mount: Kubernetes always mounts ConfigMaps as symlinks, and Salt 3008 + explicitly rejects symlinks in its key store - confirmed by live testing, see + [`CHANGELOG.md`](CHANGELOG.md).) This is intentional, not a bug. Allow about + a minute for kubelet's ConfigMap propagation plus the sync interval. +- **Traditional** (`agent.trustedMinions.enabled: false`): `salt-key -a` + against a pod. ```bash - kubectl -n salt-master exec -it salt-master-0 -- salt-key -L - kubectl -n salt-master exec -it salt-master-0 -- salt-key -a '' + kubectl -n salt-master exec -it salt-master-0 -c salt-master -- salt-key -L + kubectl -n salt-master exec -it salt-master-0 -c salt-master -- salt-key -a '' ``` -- **`salt-key-operator`** (`agent.trustedMinions.enabled: true`): install - the separate [`salt-key-operator`](../salt-key-operator) chart, then - apply a `SaltMinionKey` custom resource instead - it keeps every replica - consistent automatically. See that component's own README for the full - flow. Once enabled, `salt-key -a` no longer works against this master at - all - a `trusted-minions-sync` sidecar continuously copies the - operator's ConfigMap into the directory Salt reads, and that's the only - path in. (Not a direct ConfigMap volume mount: Kubernetes always mounts - ConfigMaps as symlinks, and Salt 3008 explicitly rejects symlinks in its - key store - confirmed by live testing, see the chart's own - `CHANGELOG.md`.) This is intentional, not a bug. + In classic multi-master each master keeps its own accepted keys, so repeat + the command against every pod, or use the operator. In classic mode the + accepted keys sit in an `emptyDir` and are lost when the pod is replaced; in + cluster mode they are in `cluster_pki_dir` on the pod's volume and shared + between the masters. + +## Security + +- No root and no added capabilities anywhere, including the init containers. + Every container uses `agent.containerSecurityContext` (`runAsNonRoot`, + `allowPrivilegeEscalation: false`, all capabilities dropped) and the pod runs + as uid/gid `10001` with `fsGroup: 10001`. +- The init containers (`prepare-master-keys` in classic mode, + `prepare-cluster-dirs` in cluster mode) run as that same non-root user and + create the directories they need themselves; the master then mounts the + existing subdirectories. This works because `fsGroup` makes each volume's + root group-writable for gid `10001`. The same pattern is used by the + salt-minion chart. +- **Consequence:** any volume you supply yourself (for example + `agent.cluster.sharedStorage.existingClaim`) must already be writable by + uid/gid `10001`; the chart cannot fix ownership without root. +- The master-key Secret is mounted read-only with mode `0440`, copied by the + init container into a writable `emptyDir` (private key `0400`). +- The master's service-account token is not mounted. Only the master-key + generation Job mounts one, to create the Secret. +- The pods have no liveness or readiness probe. The image's Docker + `HEALTHCHECK` is not used by Kubernetes. diff --git a/helm/salt-master/templates/NOTES.txt b/helm/salt-master/templates/NOTES.txt index f4e7d04..f4e2ddb 100644 --- a/helm/salt-master/templates/NOTES.txt +++ b/helm/salt-master/templates/NOTES.txt @@ -5,10 +5,24 @@ Check the workload: kubectl -n {{ .Values.namespace }} get pods -l app=salt-master {{- if .Values.agent.cluster.enabled }} + Salt master cluster "{{ include "salt-master.clusterId" . }}" ({{ .Values.agent.replicas }} replicas, {{ .Values.agent.cluster.storageMode }} storage). Point minions at the flat Service (salt-master.{{ .Values.namespace }}.svc), not at individual pods. Verify: kubectl -n {{ .Values.namespace }} exec salt-master-0 -c salt-master -- salt-run cluster.members + +Known limitation: each master's pod IP is its cluster identity and changes when +the pod restarts, so a restarted master cannot rejoin. Treat pod restarts as +unsupported (see the chart README, "Master cluster"). +{{- else }} +{{- if gt (int .Values.agent.replicas) 1 }} + +Classic multi-master ({{ .Values.agent.replicas }} replicas sharing one keypair). Minions must list every master +individually in their `master:` setting: +{{ range $i := until (int .Values.agent.replicas) }} + salt-master-{{ $i }}.salt-master-headless.{{ $.Values.namespace }}.svc.{{ $.Values.agent.cluster.clusterDomain }} +{{- end }} +{{- end }} {{- end }} Check the Salt Master logs: @@ -18,7 +32,7 @@ Check the Salt Master logs: List known minion keys: - kubectl -n {{ .Values.namespace }} exec statefulset/salt-master \ + kubectl -n {{ .Values.namespace }} exec salt-master-0 \ --container salt-master \ -- salt-key -L @@ -54,12 +68,19 @@ salt-key-operator integration is disabled. Accept a pending minion manually: - kubectl -n {{ .Values.namespace }} exec statefulset/salt-master \ + kubectl -n {{ .Values.namespace }} exec salt-master-0 \ --container salt-master \ -- salt-key -a '' +{{- if and (not .Values.agent.cluster.enabled) (gt (int .Values.agent.replicas) 1) }} + +Repeat this against every master pod (salt-master-0 .. salt-master-{{ sub (int .Values.agent.replicas) 1 }}): in +classic multi-master mode each master keeps its own list of accepted keys. +{{- end }} +{{- if not .Values.agent.cluster.enabled }} Warning: manually accepted minion keys are stored in the pod's writable temporary PKI volume and do not survive a Salt Master pod replacement. Enable agent.trustedMinions.enabled for persistent declarative trust. +{{- end }} -{{- end }} \ No newline at end of file +{{- end }} diff --git a/helm/salt-master/templates/service-headless.yaml b/helm/salt-master/templates/service-headless.yaml index 52fe4e6..56160f1 100644 --- a/helm/salt-master/templates/service-headless.yaml +++ b/helm/salt-master/templates/service-headless.yaml @@ -4,9 +4,9 @@ # This is what lets an in-cluster minion's multi-master `master:` config list # address every master replica individually rather than being randomly # load-balanced across them by a normal Service - see -# https://docs.saltproject.io/en/3006/topics/tutorials/multimaster.html and -# salt-minion-vcf/helm/salt-minion-vcf/templates/service.yaml, which uses the -# exact same pattern for its own StatefulSet. +# https://docs.saltproject.io/en/3006/topics/tutorials/multimaster.html. +# In cluster mode it also carries the cluster-pool port, and the entrypoint +# resolves these names to the peer pod IPs. apiVersion: v1 kind: Service metadata: diff --git a/helm/salt-master/templates/serviceaccount.yaml b/helm/salt-master/templates/serviceaccount.yaml index 996023d..63a8eea 100644 --- a/helm/salt-master/templates/serviceaccount.yaml +++ b/helm/salt-master/templates/serviceaccount.yaml @@ -11,7 +11,7 @@ metadata: annotations: {{- toYaml . | nindent 4 }} {{- end }} -# The master never calls the Kubernetes API itself (see docker/salt-master/ -# README.md), so unlike salt-minion-kubernetes it gets no Role/RoleBinding -# and doesn't need its token automounted. +# The master never calls the Kubernetes API itself (see src/master/README.md), +# so unlike the salt-minion chart it gets no Role/RoleBinding and doesn't +# need its token automounted. automountServiceAccountToken: false diff --git a/helm/salt-master/values.yaml b/helm/salt-master/values.yaml index ad812fa..dc1df71 100644 --- a/helm/salt-master/values.yaml +++ b/helm/salt-master/values.yaml @@ -5,35 +5,38 @@ rbac: agent: image: - # Built from docker/salt-master/Dockerfile. Also published to + # Built from src/master/Dockerfile. Also published to # ghcr.io/saltstack/salt-kubernetes/salt-master (see docs/releasing.md), but - # this default is unqualified for the push-to-node lab workflow below -- - # push it to each node's containerd store with - # scripts/push-image-to-nodes.sh --role=master, or set repository to the - # GHCR path to pull instead. + # this default is unqualified so a locally built image can be used as is: + # load it into each node's container runtime, or set repository to the + # GHCR path (or your own registry) to pull instead. The tag is the Salt + # version the image was built with (3008.5). repository: salt-master tag: "3008.5" pullPolicy: IfNotPresent - # 1 (default) = simplest possible setup: single master, single Service - # address, no ambiguity about which replica serves a given minion. + # Number of master pods (StatefulSet replicas; pods are salt-master-0..N-1). # - # > 1 = active-active, but ONLY genuinely so for clients that address - # each replica individually - the headless Service's per-ordinal DNS - # names in-cluster (always created, no config needed), or - # service.perOrdinal for external minions. A single flat Service address - # (service.type/service.gateway below) in front of >1 replica still only - # gives connection-level load-balancing + auto-failover, never "any - # replica can dispatch to any minion" - that's inherent to Salt's - # per-process pub/sub, not something any Service type or gateway can - # change. Also requires agent.masterKeySecretName (the chart fails fast - # otherwise) - every replica must share the identical keypair. - - + # 1 (default) = a single classic master. + # + # > 1 needs one of two modes: + # - classic multi-master (agent.cluster.enabled=false): requires + # agent.masterKeySecretName (the chart fails to render otherwise) because + # every replica must present the identical keypair. Only genuinely + # active-active for minions that address each replica individually, i.e. + # list the headless Service's per-pod DNS names + # (salt-master-.salt-master-headless..svc.) + # in the minion's `master:` list. A single flat Service address in front + # of >1 classic replica only gives per-connection load balancing and + # failover, never "any replica can dispatch to any minion": that is + # inherent to Salt's per-process pub/sub. + # - master cluster (agent.cluster.enabled=true): requires >= 2 replicas + # (use 3 or more); see agent.cluster below. replicas: 1 # Salt master cluster (Salt 3007+; the isolated-filesystem mode below needs - # 3008+). Distinct from the classic multi-master mode described above: all + # 3008+). Opt-in, and see the LIMITATION below before using it. Distinct from + # the classic multi-master mode described above: all # masters present ONE cluster identity to minions, so a plain Service in # front of the StatefulSet (service.type/service.gateway) is the intended # minion endpoint - any replica can serve any minion, and jobs/events are @@ -41,13 +44,21 @@ agent: # cluster-wide keypair and the accepted minion keys live in cluster_pki_dir. # See https://docs.saltproject.io/en/latest/topics/tutorials/master-cluster.html # - # When enabled: masterKeySecretName is not used (no shared master keypair), - # jobCache.persistence is ignored (the state volume below holds the cache), - # and trustedMinions writes into /minions instead. + # When enabled: needs replicas >= 2 (the chart fails below that: Salt + # refuses a member with no peers); use 3 or more to tolerate a failure. + # masterKeySecretName and the master-keygen Job are not used (every master + # generates and keeps its own keypair on its state volume), jobCache.persistence + # is ignored (the state volume holds the cache in isolated mode), and + # trustedMinions writes into /minions instead. Each pod's + # `interface` and `id` are set to its pod IP, and the pod's entrypoint waits + # (up to 120s) for the other pods' DNS names to resolve before starting. + # Minions point at the flat salt-master Service, not at individual pods. cluster: enabled: false # cluster_id. Defaults to the release name. id: "" + # Cluster DNS suffix, used to build the per-pod peer names + # salt-master-.salt-master-headless..svc.. clusterDomain: cluster.local # cluster_pool_port: peer-to-peer RPC between masters (headless Service # and container port are added automatically). Must be reachable between @@ -63,8 +74,11 @@ agent: # No shared storage required. file_roots/pillar_roots then have to be # propagated with `salt-run cluster.sync_roots`. # shared: all pods mount one ReadWriteMany claim (NFS, CephFS, ...) for - # cluster_pki_dir, cachedir, file_roots and pillar_roots. + # cluster_pki_dir, cachedir, file_roots and pillar_roots. Requires + # sharedStorage.existingClaim. Not yet tested with this chart. storageMode: isolated + # cluster_auto_replace_voters (default false, same as Salt). + # # LIMITATION: a master's cluster identity is its `interface`, which here # is the pod IP, and Salt has no setting to separate identity from bind # address. A pod IP changes whenever the pod is rescheduled or restarted, @@ -76,29 +90,33 @@ agent: # as unsupported. Replacing a voter also needs a majority of the current # voters, so use at least 3 replicas. autoReplaceVoters: false - # Floor below which Salt will not demote a voter. Empty = replicas - 1 - # (at least 1), i.e. one dead voter can always be replaced. + # cluster_min_voters: floor below which Salt will not demote a voter. + # Empty = replicas - 1 (at least 1), i.e. one dead voter can always be + # replaced (only relevant when autoReplaceVoters is true). minVoters: "" # keys.cache_driver for the cluster key store. Empty = Salt's default # (localfs_key). Salt recommends mmap_key for isolated mode, but see the # chart CHANGELOG: it failed to read its own keys back on Longhorn PVCs. keysCacheDriver: "" - # Per-pod volume (volumeClaimTemplates): the master's own keypair, and in - # isolated mode also cluster_pki_dir and the cachedir. + # Per-pod volume (volumeClaimTemplates, named `state`): the master's own + # keypair (subPath master-pki), and in isolated mode also cluster_pki_dir + # (cluster-pki) and the cachedir (cache). In shared mode it only holds the + # master's own keypair. Empty storageClassName = the cluster default. persistence: storageClassName: "" accessMode: ReadWriteOnce size: 5Gi # storageMode=shared only: an EXISTING ReadWriteMany PVC, used with - # subPaths cluster-pki, cache, file-roots and pillar-roots. + # subPaths cluster-pki, cache, file-roots (/srv/salt) and pillar-roots + # (/srv/pillar). The init container creates those directories as uid/gid + # 10001, so the volume must already be writable by that user. sharedStorage: existingClaim: "" - # No numeric runAsUser/runAsGroup/fsGroup here on purpose - the image runs - # as the 'salt' system user salt-common's own postinst creates (or this - # Dockerfile creates itself for the onedir install - see - # docker/salt-master/Dockerfile), whose numeric uid isn't a stable - # constant to pin. runAsNonRoot alone still gets enforced. + # The image runs as the 'salt' user, normalised to uid/gid 10001 in + # src/master/Dockerfile, so the same numbers are used here. fsGroup makes + # mounted volumes group-writable for that gid (needed by the non-root init + # containers and by volumes you supply yourself). podSecurityContext: runAsNonRoot: true runAsUser: 10001 @@ -141,33 +159,45 @@ agent: # come and go independently of their accepted-key status. presenceEvents: true - # Name of an EXISTING Kubernetes Secret (created out-of-band - e.g. by - # whatever generates and registers this master's identity with RaaS/the - # minion side before this chart is ever installed - never via Helm - # values) with keys 'private-key-b64' and 'public-key-b64': a - # base64-encoded PEM RSA keypair for the master itself. REQUIRED when - # replicas > 1 (every pod must present the identical keypair, matching - # Salt's own multi-master convention - see + # Classic mode only (ignored when agent.cluster.enabled=true). + # + # Name of an EXISTING Kubernetes Secret (created out-of-band, never via + # Helm values) with keys 'master.pem' and 'master.pub': the master's PEM + # RSA keypair as raw files, e.g. + # kubectl create secret generic -n \ + # --from-file=master.pem --from-file=master.pub + # REQUIRED when replicas > 1 (every pod must present the identical + # keypair, matching Salt's own multi-master convention - see # https://docs.saltproject.io/en/3006/topics/tutorials/multimaster.html, - # "masters share the same private key") - the StatefulSet template fails - # fast otherwise. With a single replica it's optional: leave empty to - # fall back to the master generating its own keypair on first start - # (fine for dev/test, but any minion that already trusts an old keypair - # won't trust the new one, and it can never be scaled past 1 replica - # without setting this). + # "masters share the same private key") - the chart fails to render + # otherwise. The Secret is mounted 0440 and copied by the prepare-master-keys + # init container into a writable emptyDir. + # + # Empty = the Secret -master-keys is used instead, created by the + # master-keygen Job (an RSA 2048 pair, generated once; needs rbac.create) + # if it does not exist yet. The pods wait in ContainerCreating until it + # does. That is fine for a single replica, but it cannot be used with + # replicas > 1 (set this value). Back the generated Secret up if minions + # already trust it: a new keypair will not be trusted by minions that have + # pinned the old one. masterKeySecretName: "" # Replaces manual `salt-key -a ` with salt-key-operator's - # SaltMinionKey CRD (see ../salt-key-operator) - a ConfigMap it manages, - # mounted READ-ONLY at /etc/salt/pki/master/minions. Once enabled, - # `salt-key -a` no longer works against this master at all (the directory - # it would write into is read-only) - every accepted minion must go - # through a SaltMinionKey instead. That's intentional: across an - # active-active master tier, mixing operator-managed and manually- - # accepted keys would mean different replicas disagreeing on who's - # trusted, exactly the gap salt-key-operator exists to close. Leave + # SaltMinionKey CRD (see ../salt-key-operator). The operator maintains a + # ConfigMap; a trusted-minions-sync sidecar in every master pod copies its + # entries into writable emptyDirs mounted at /minions, + # minions_pre and minions_rejected ( is /etc/salt/pki/master, or + # /etc/salt/pki/cluster in cluster mode). The sidecar also deletes any key + # in minions/ that is not in the ConfigMap, so a key accepted by hand with + # `salt-key -a` is removed again within syncIntervalSeconds: every accepted + # minion must go through a SaltMinionKey instead. That is intentional: + # across several replicas, mixing operator-managed and manually accepted + # keys would mean different replicas disagreeing on who is trusted. Set # false to keep the traditional salt-key workflow (fine for a single - # replica; does NOT give consistent acceptance across replicas > 1). + # replica; does NOT give consistent acceptance across classic replicas > 1). + # + # Enabled by default, which makes the salt-key-operator subchart part of + # the release (run `helm dependency update` first, see Chart.yaml). trustedMinions: enabled: true # Set false to reference an existing ConfigMap (e.g. created by another @@ -181,15 +211,14 @@ agent: # once kubelet has already synced the ConfigMap's mounted content. syncIntervalSeconds: 15 - # Once masterKeySecretName is set, the master's own identity is supplied - # externally on every start - there's nothing left to persist for PKI. - # The accepted-minion-keys list is likewise no longer local/persisted - # state once salt-key-operator is installed (see its own chart) - it - # lives in a ConfigMap the operator manages, mounted read-only into - # /etc/salt/pki/master/minions. What *does* still benefit from - # persistence is the master's job/event cache (jobs dispatched and their - # returns) - see jobCache below. This intentionally does NOT persist - # /etc/salt/pki at all anymore. + # Classic mode only (ignored in cluster mode, where the per-pod `state` + # volume holds the cache). The master's identity comes from the key Secret + # and, with trustedMinions enabled, the accepted-minion keys come from the + # operator's ConfigMap, so no PKI is persisted in classic mode. What can + # still benefit from persistence is the job/event cache (jobs dispatched and + # their returns): when enabled, a per-replica PVC (volumeClaimTemplates, + # named job-cache) is mounted at /var/cache/salt/master/jobs. Off by + # default, in which case the job cache is lost when a pod is replaced. jobCache: persistence: enabled: false @@ -203,10 +232,9 @@ agent: size: 1Gi # Pins every replica to a node (e.g. {kubernetes.io/hostname: k8s-cp}). - # Not needed for the job-cache PVC above (that's a normal StorageClass - # volume, one per ordinal, no node affinity required) - only relevant if - # your cluster needs it for other reasons. - # `kubectl get nodes` for hostnames. + # Not needed for the PVCs above (normal StorageClass volumes, one per + # ordinal, no node affinity required) - only relevant if your cluster needs + # it for other reasons. `kubectl get nodes` for hostnames. nodeSelector: {} serviceAccount: @@ -217,14 +245,17 @@ serviceAccount: service: # ClusterIP by default - standard practice: nothing is reachable from # outside the cluster unless you explicitly opt into one of the - # mechanisms below. A single Service address only gives genuine - # multi-master fan-out at replicas: 1 - with replicas > 1 it still - # load-balances per-connection across all of them (auto-failover if one - # dies, but NOT "any replica can dispatch to any minion"; see - # agent.replicas' own comment above). For real fan-out with replicas > 1, - # in-cluster minions use the always-created headless Service's - # per-ordinal DNS names directly (templates/service-headless.yaml, no - # config needed here) - external minions need perOrdinal below. + # mechanisms below. + # + # This is the flat `salt-master` Service in front of every pod. In cluster + # mode it is the intended minion endpoint (any master can serve any minion). + # With replicas: 1 it is simply the master. With classic multi-master + # (replicas > 1, no cluster) it only load-balances per connection, so + # minions should instead list each pod through the always-created headless + # Service `salt-master-headless` (per-pod DNS names, see + # templates/service-headless.yaml). There is no per-replica Service for + # external minions; external access to individual classic replicas is not + # provided by this chart. type: ClusterIP # Only used when type=NodePort - exposes the port directly on every diff --git a/helm/salt-minion/CHANGELOG.md b/helm/salt-minion/CHANGELOG.md index 6b4df7c..3ce8219 100644 --- a/helm/salt-minion/CHANGELOG.md +++ b/helm/salt-minion/CHANGELOG.md @@ -1,11 +1,33 @@ # Changelog (salt-minion) Image and chart in this directory publish under separate release tags (see -[`docs/releasing.md`](../docs/releasing.md)) but neither tag encodes the Salt/extension +[`docs/releasing.md`](../../docs/releasing.md)) but neither tag encodes the Salt/extension versions it carries — check here. ## Image releases (`salt-minion-image/vX.Y.Z`) +### Unreleased +Applies to both `src/minion/kubernetes` and `src/minion/vcf`. +- **Fix: installing the Salt extensions no longer replaces the onedir Salt.** The + extensions (for example `saltext.kubernetes`) require `salt>=3006`, and pip does not + count the bootstrap-installed onedir Salt as satisfying that, so it downloaded + another `salt` from the index and installed it over the onedir one, which removed the + `salt-minion` launcher. The extension step now reads the installed version with + `salt-pip list --format=freeze` and passes it to pip as a constraint, so pip only adds + the extensions and their other dependencies. The build fails if no `salt==` entry is + found. +- The runtime identity is now a build-time choice: `SALT_UID`/`SALT_GID` (default + `10001`), `SALT_HOME` (`/opt/saltstack/salt`) and `SALT_SHELL` (`/usr/sbin/nologin`). + The `salt` user and group are created before Salt is installed, and `USER` is the + numeric `10001:10001`. (The VCF image previously ran as `999:999`.) +- Build arguments `INCLUDE_KUBECTL`, `KUBECTL_VERSION`, `EXTRA_SALT_EXTENSIONS`, + `PIP_INDEX_URL`, `PIP_TRUSTED_HOST`, `PIP_ONLY_BINARY` and `APT_MIRROR` are + documented in [`src/minion/README.md`](../../src/minion/README.md). +- Salt is pinned to 3008.5 in both Dockerfiles (`SALT_VERSION=3008.5`); `latest` is + also accepted. +- Extensions are unchanged: `saltext.kubernetes==2.1.0`, `saltext.vault==1.8.0` in both + images, plus `saltext.vcf==1.0.0` and `saltext.bmc==0.0.1` in the VCF image. + ### salt-minion-image/v0.1.2 - Salt: 3008.5 (no other change) @@ -30,19 +52,40 @@ versions it carries — check here. ## Chart releases (`salt-minion-chart/vX.Y.Z`) ### Unreleased +**Breaking - reinstall rather than `helm upgrade` from any earlier release.** - `Deployment` -> `StatefulSet` (`templates/deployment.yaml` is now `templates/statefulset.yaml`), - so every replica gets a stable, unique identity. Reinstall rather than `helm upgrade`: a - Deployment cannot be converted in place. + so every replica gets a stable, unique identity. The StatefulSet is named + `agent.minion.idPrefix` (default `salt-minion`) and uses `podManagementPolicy: Parallel`. + A Deployment cannot be converted in place. - Previously `agent.replicas > 1` made every pod register as one and the same minion, all - sharing one keypair. Now each pod is its own minion (`` as ID) with its own - keypair. New `agent.minion.idPrefix` names the StatefulSet and the pods. + sharing one keypair. Now each pod is its own minion (the pod name is the ID, taken from + `POD_NAME`) with its own keypair. New `agent.minion.idPrefix` names the StatefulSet and + the pods. A default single-replica install registers as `salt-minion-0`. - With `agent.replicas > 1` the chart rejects `agent.minion.id` and `agent.minion.privateKeyB64`/`publicKeyB64` (single-identity settings). `keySecretName` - then points at a Secret holding `.pem`/`.pub` pairs; each pod mounts only its own. -- The keygen Job generates one keypair per replica, only adds missing pairs when scaling up, - and is named `-keygen-` when `replicas > 1`. Its Role gains `patch`. + then points at a Secret holding `.pem`/`.pub` pairs; each pod mounts only its + own (Secret `items` plus `subPathExpr: $(POD_NAME)`). +- The keygen Job generates one keypair per replica, only adds missing pairs when scaling up + (existing pairs are never regenerated), and is named `-keygen-` when + `replicas > 1`. Its Role gains `patch`. Scaling down leaves the extra pairs in the Secret. - With `agent.replicas: 1` the Secret layout (`minion.pem`/`minion.pub`) and `agent.minion.id` behave as before. +- Key handling and security (from the earlier PKI preparation fix): + - Keys always come from a Secret and are copied by the `prepare-minion-keys` init + container into an `emptyDir` PKI volume. The init container runs as the minion's + own non-root user with `agent.containerSecurityContext` (no root init container). + - `agent.podSecurityContext` defaults gain `fsGroup: 10001`; the key Secret is mounted + with mode `0440`; private key `0400`, public key `0644`. + - `agent.persistence.*` (PVC/hostPath PKI storage) and + `agent.initContainers.fixPkiPerms` are removed. Remove them from your values. + - A key source is required in in_cluster mode (`keySecretName`, inline keys, or + `allowSelfGeneratedKey`). `privateKeyB64` and `publicKeyB64` must be set together. + Inline keys fail the install if an unmanaged Secret of that name exists. The keygen + Job only runs when `keySecretName` and inline keys are empty. +- Images are configurable: `agent.image.{repository,tag,pullPolicy,imagePullSecrets}` and + `keygen.image.{repository,tag,pullPolicy,imagePullSecrets}` (default `bitnami/kubectl:latest`). +- Documentation: the README now describes the StatefulSet identity model and key + layouts, and how to run the helm-unittest suites (`helm unittest helm/salt-minion`). ### salt-minion-chart/v1.0.0 **Breaking - defaults change on `helm upgrade` from any prior release:** diff --git a/helm/salt-minion/README.md b/helm/salt-minion/README.md index e9e3845..73f803c 100644 --- a/helm/salt-minion/README.md +++ b/helm/salt-minion/README.md @@ -1,162 +1,182 @@ # salt-minion -Installs a Salt Minion Kubernetes Deployment with RBAC, health checks, and optional CIS -Kubernetes compliance assessment support via kube-bench on-demand Jobs. +Installs Salt minions into a Kubernetes cluster as a StatefulSet, with RBAC, health +probes, and optional Vault and Kubernetes (`saltext.kubernetes`) integration. The +minions can also run kube-bench based CIS compliance assessments (see +[Kubernetes compliance guide](../../docs/kubernetes-compliance-guide.md)). Features: -- In-cluster or external minion deployment modes -- Automatic minion key generation via pre-install Job -- Health checks (liveness and readiness probes) -- Vault integration for secrets management -- Multi-master connectivity support -- Stable minion keys stored in a Kubernetes Secret -- CIS kube-bench integration -- Security hardened (non-root, no privilege escalation) +- In-cluster (StatefulSet) or external (RBAC only) deployment modes +- One minion per pod: the pod name is the minion ID, and every pod has its own keypair +- Three ways to supply minion keys: an existing Secret, inline values, or a key + generation Job +- Liveness and readiness probes +- Vault integration (`saltext.vault`) +- Salt multi-master connectivity (a list of masters) +- Security hardened (non-root, no privilege escalation, no added capabilities) The image builds a self-contained Salt minion (core Salt plus `saltext.vault` and -`saltext.kubernetes`) with `kubectl` bundled in. Build it using: +`saltext.kubernetes`) with `kubectl` bundled in. Build it from the repository root: ```bash -docker build -t salt-minion:0.1.0 ./src/minion/kubernetes +docker build -t salt-minion:local ./src/minion/kubernetes ``` -See [`CHANGELOG.md`](CHANGELOG.md) for which Salt/extension versions each release carries. +See [`src/minion/README.md`](../../src/minion/README.md) for build arguments and +[`CHANGELOG.md`](CHANGELOG.md) for which Salt and extension versions each image +release carries. The default `agent.image.tag` is an image release tag (`0.1.0`), not a +Salt version. ## Deployment Modes Selected via `agent.authMode`: -- **in_cluster** (default) — Salt minion runs as a Deployment inside the cluster - - Chart creates Deployment + RBAC (ServiceAccount, Role, ClusterRole, bindings) - - Minion connects to Salt Master on configured ports - - Includes health checks for automatic pod recovery - - Uses a key Secret for stable identity - -- **external** — RBAC only for minion running outside cluster - - ServiceAccount token available for external kubeconfig - - No Deployment created - - Minion runs via salt-ssh or standalone +- **in_cluster** (default): the Salt minion runs as a StatefulSet inside the cluster. + - Chart creates the StatefulSet and RBAC (ServiceAccount, Role, ClusterRole, bindings) + - Each minion connects to the Salt master on the configured ports + - Liveness and readiness probes restart or hold back unhealthy pods + - A key source is required (see [Key Management](#key-management)) +- **external**: RBAC only, for a minion that runs outside the cluster. + - ServiceAccount (and its RBAC) is created; use its token for an external kubeconfig + - No StatefulSet, key Secret, or key generation Job is created + - The minion runs via salt-ssh or standalone ## Prerequisites - Kubernetes 1.24+ - Helm 3+ -- Salt Master reachable from minion (required for in_cluster mode) -- For in-cluster mode, provide `agent.minion.keySecretName` or both `agent.minion.privateKeyB64` and `agent.minion.publicKeyB64`, or explicitly enable `agent.minion.allowSelfGeneratedKey`. +- A Salt master reachable from the minion pods (required for in_cluster mode) +- For in_cluster mode, a key source: `agent.minion.keySecretName`, or both + `agent.minion.privateKeyB64` and `agent.minion.publicKeyB64`, or + `agent.minion.allowSelfGeneratedKey: true`. Without one the install fails with + `set agent.minion.keySecretName or both agent.minion.privateKeyB64 and + agent.minion.publicKeyB64, or enable agent.minion.allowSelfGeneratedKey`. + +The chart creates every namespaced object in `namespace` (default `salt`), not in +the namespace given to `helm --namespace`. Pass both consistently, as the examples do +(`--namespace salt` with the default `namespace: salt`), or set `--set namespace=` +to match. ## Quick Start ### In-Cluster Minion ```bash -# Install with basic configuration helm install salt-minion ./helm/salt-minion \ - --set agent.minion.allowSelfGeneratedKey=true \ --namespace salt \ --create-namespace \ - --set agent.saltMasterHost=salt-master.example.com + --set agent.saltMasterHost=salt-master.salt-master.svc.cluster.local \ + --set agent.minion.allowSelfGeneratedKey=true ``` +This creates a StatefulSet named `salt-minion` with one pod, `salt-minion-0`. The +minion ID is the pod name, `salt-minion-0`. The key generation Job creates the keys +in Secret `-keys` (here `salt-minion-keys`). The public key then has to be +accepted on the master (see [Verification](#verification)). + ### External Minion (RBAC only) ```bash -# Install RBAC only helm install salt-minion ./helm/salt-minion \ + --namespace salt \ + --create-namespace \ --set agent.authMode=external -# Get token for external minion's kubeconfig +# Token for the external minion's kubeconfig kubectl create token salt-minion -n salt ``` ## Installation -### Basic Installation - -```bash -helm install salt-minion ./helm/salt-minion \ - --set agent.minion.allowSelfGeneratedKey=true \ - --namespace salt \ - --create-namespace \ - --set agent.saltMasterHost=salt-master.example.com -``` - ### With Vault Integration -Enable Vault for secure secret sourcing: - ```bash helm install salt-minion ./helm/salt-minion \ - --set agent.minion.allowSelfGeneratedKey=true \ --namespace salt \ --create-namespace \ - --set agent.saltMasterHost=salt-master.example.com \ + --set agent.minion.allowSelfGeneratedKey=true \ + --set agent.saltMasterHost=salt-master.salt-master.svc.cluster.local \ --set agent.vault.addr=https://vault.example.com:8200 \ --set agent.vault.roleId=my-role-id ``` -### Multi-Master Mode +### Multiple Masters -Connect to multiple masters simultaneously: +`agent.saltMasterHost` also accepts a list, which gives every minion one independent, +simultaneous connection to each master (Salt's native multi-master mode, not +failover): ```bash helm install salt-minion ./helm/salt-minion \ - --set agent.minion.allowSelfGeneratedKey=true \ --namespace salt \ --create-namespace \ - --set 'agent.saltMasterHost={master-0.example.com,master-1.example.com,master-2.example.com}' + --set agent.minion.allowSelfGeneratedKey=true \ + --set 'agent.saltMasterHost={master-0.example.com,master-1.example.com}' ``` -### Using Custom Values File +The chart joins the list with commas into `SALT_MASTER`, and the image entrypoint +turns that into a YAML list in the minion configuration. Every master in the list has +to accept every minion key. + +Do not use this for a Salt master *cluster* (`agent.cluster.enabled` in the +[salt-master chart](../salt-master/README.md)). A master cluster presents one +logical master: point `agent.saltMasterHost` at its single `salt-master` Service. A +list is for independent masters, such as the classic multi-master mode of the +salt-master chart, where each replica is addressed through the headless Service +(`...svc.cluster.local`). + +### Using a Values File ```bash helm install salt-minion ./helm/salt-minion \ --namespace salt \ --create-namespace \ - -f test-values-k8s-minion.yaml + -f my-values.yaml ``` ## Verification -### Check Deployment Status +### Check the StatefulSet ```bash # Watch pod initialization -kubectl rollout status deployment/salt-minion -n salt +kubectl rollout status statefulset/salt-minion -n salt -# Verify pod is healthy +# List the pods (named -0, -1, ...) kubectl get pod -n salt -l app=salt-minion -# Check health probe status +# Probe status kubectl describe pod -n salt -l app=salt-minion | grep -A 5 Probe ``` -### Verify Master Connection +Use the `agent.minion.idPrefix` value instead of `salt-minion` in the StatefulSet and +pod names if you set it. -On the Salt Master: +### Verify the Master Connection + +Substitute the master's namespace and pod name. The commands below assume the +salt-master chart's default StatefulSet `salt-master` in namespace `salt-master`: ```bash # List pending keys -kubectl exec deployment/salt-master -n salt-master \ - --container salt-master \ - -- salt-key -L - -# Accept minion -kubectl exec deployment/salt-master -n salt-master \ - --container salt-master \ - -- salt-key -a -y +kubectl exec -n salt-master salt-master-0 -c salt-master -- salt-key -L + +# Accept a minion (when not using salt-key-operator or auto-accept) +kubectl exec -n salt-master salt-master-0 -c salt-master -- salt-key -a salt-minion-0 -y ``` +If the master delegates acceptance to `salt-key-operator` +(`agent.trustedMinions.enabled`), `salt-key -a` does not apply; create a +`SaltMinionKey` instead (see [Accepting the keys on the master](#accepting-the-keys-on-the-master)). + ### Test Minion Connectivity ```bash -# From master -kubectl exec deployment/salt-master -n salt-master \ - --container salt-master \ - -- salt '' test.ping - -# From minion (local test) -kubectl exec deployment/salt-minion -n salt \ - -- salt-call --local test.ping +# From the master +kubectl exec -n salt-master salt-master-0 -c salt-master -- salt 'salt-minion-0' test.ping + +# From the minion (local test, does not use the master) +kubectl exec -n salt salt-minion-0 -- salt-call --local test.ping ``` ## Uninstalling @@ -165,6 +185,13 @@ kubectl exec deployment/salt-minion -n salt \ helm uninstall salt-minion -n salt ``` +The key Secret generated by the key generation Job is not owned by Helm, so it is +left behind. Delete it if you do not want to reuse the keys: + +```bash +kubectl delete secret salt-minion-keys -n salt +``` + ## Configuration See [values.yaml](values.yaml) for the complete list of configuration options. @@ -173,242 +200,382 @@ See [values.yaml](values.yaml) for the complete list of configuration options. | Parameter | Description | Default | | --- | --- | --- | -| `namespace` | Kubernetes namespace for deployment | `salt` | +| `namespace` | Namespace of every namespaced object the chart creates | `salt` | | `agent.authMode` | `in_cluster` or `external` | `in_cluster` | -| `agent.minion.keySecretName` | Key Secret name. Uses an existing Secret when inline keys are not supplied. Empty uses `-keys` | `""` | -| `agent.minion.privateKeyB64` | Base64-encoded private PEM key; requires `publicKeyB64` | `""` | -| `agent.minion.publicKeyB64` | Base64-encoded public PEM key; requires `privateKeyB64` | `""` | -| `agent.minion.allowSelfGeneratedKey` | Allow the keygen Job in in-cluster mode when `keySecretName`, `privateKeyB64`, and `publicKeyB64` are empty | `false` | -| `agent.podSecurityContext.fsGroup` | Group with access to the key Secret and PKI volume | `10001` | -| `agent.containerSecurityContext` | Security context shared by the minion and key-preparation init container | `{"allowPrivilegeEscalation": false, "runAsNonRoot": true, "capabilities": {"drop": ["ALL"]}}` | +| `agent.replicas` | Number of minion pods. Each pod is a separate minion with its own ID and keypair (see [Multiple replicas](#multiple-replicas)) | `1` | +| `agent.minion.id` | Explicit minion ID. Empty uses the pod name. Only allowed with `agent.replicas: 1` | `""` | +| `agent.minion.idPrefix` | Names the StatefulSet; pod `N` is `-N` and that is its minion ID. Empty uses `salt-minion` | `""` | +| `agent.minion.keySecretName` | Existing Secret that holds the keys (see [Key Management](#key-management)). Empty uses `-keys` | `""` | +| `agent.minion.privateKeyB64` | Base64-encoded private PEM key; requires `publicKeyB64`; one replica only | `""` | +| `agent.minion.publicKeyB64` | Base64-encoded public PEM key; requires `privateKeyB64`; one replica only | `""` | +| `agent.minion.allowSelfGeneratedKey` | Let the key generation Job create the keys. The Job only runs when `keySecretName`, `privateKeyB64` and `publicKeyB64` are all empty | `false` | +| `agent.minion.masterPubKeyB64` | Base64-encoded master public key, passed as `SALT_MASTER_PUBKEY_B64` so the minion trusts the master directly | `""` | +| `agent.podSecurityContext` | Pod security context; `fsGroup` gives the containers access to the key Secret and the PKI volume | `{"fsGroup": 10001, "runAsNonRoot": true}` | +| `agent.containerSecurityContext` | Security context shared by the minion and the `prepare-minion-keys` init container | `{"allowPrivilegeEscalation": false, "runAsNonRoot": true, "capabilities": {"drop": ["ALL"]}}` | | `agent.image.repository` | Minion image repository | `ghcr.io/saltstack/salt-kubernetes/salt-minion` | -| `agent.image.tag` | Image tag/version | `0.1.0` | -| `agent.image.pullPolicy` | Image pull policy | `IfNotPresent` | -| `agent.image.imagePullSecrets` | Minion pull Secrets | `[]` | -| `keygen.image.repository` | Keygen image repository | `bitnami/kubectl` | -| `keygen.image.tag` | Keygen image tag | `latest` | -| `keygen.image.pullPolicy` | Keygen image pull policy | `Always` | -| `keygen.image.imagePullSecrets` | Keygen pull Secrets | `[]` | -| `agent.saltMasterHost` | Salt master hostname or comma-separated list (REQUIRED) | `""` | -| `agent.saltMasterPort` | Master request/return port | `4506` | -| `agent.saltPublishPort` | Master publish port | `4505` | -| `agent.replicas` | Number of minion pods. Each pod is a separate minion with its own ID and keypair (see "Multiple replicas") | `1` | +| `agent.image.tag` | Minion image tag | `0.1.0` | +| `agent.image.pullPolicy` | Minion image pull policy | `IfNotPresent` | +| `agent.image.imagePullSecrets` | Pull Secrets for the minion pods | `[]` | +| `keygen.image.repository` | Key generation image (needs `kubectl` and `openssl`) | `bitnami/kubectl` | +| `keygen.image.tag` | Key generation image tag | `latest` | +| `keygen.image.pullPolicy` | Key generation image pull policy | `Always` | +| `keygen.image.imagePullSecrets` | Pull Secrets for the key generation Job | `[]` | +| `agent.saltMasterHost` | Salt master hostname, or a list of masters (REQUIRED in in_cluster mode) | `""` | +| `agent.saltMasterPort` | Master request/return port (`master_port`) | `4506` | +| `agent.saltPublishPort` | Master publish port (`publish_port`) | `4505` | +| `agent.authTimeout`, `agent.masterAliveInterval`, `agent.reconDefault`, `agent.reconMax`, `agent.reconRandomize` | Minion connection and reconnect tuning (see comments in values.yaml) | `60`, `60`, `1000`, `5000`, `true` | | `agent.logLevel` | Minion log level | `info` | -| `agent.minion.id` | Minion ID (uses pod hostname if empty). Only with `agent.replicas: 1` | `""` | -| `agent.minion.idPrefix` | Names the StatefulSet; pod `N` becomes minion `-N`. Default StatefulSet name `salt-minion` | `""` | -| `agent.vault.addr` | Vault server address (enables saltext.vault) | `""` | +| `agent.vault.*` | Vault settings; `agent.vault.addr` enables `saltext.vault` | `""` | +| `agent.nodeSelector` | Node selector for the minion pods | `{}` | | `rbac.create` | Create RBAC resources | `true` | -| `rbac.fullAccess` | Grant full cluster admin rights | `true` | +| `rbac.fullAccess` | Grant the minion cluster-admin-equivalent rights (`*` on `*`, in the namespace and cluster wide) | `true` | | `serviceAccount.name` | ServiceAccount name | `salt-minion` | +The chart has no persistence settings. The minion's PKI directory is an `emptyDir`, +and the keys always come from a Secret (see below). `agent.minion.grains` and +`agent.minion.masterId` exist in `values.yaml` but are only written to the +`-minion-config` ConfigMap, which nothing mounts, so they currently have no +effect on the minion. + +### Pod identity + +Each pod of the StatefulSet is its own minion. The minion ID is the pod name, taken +from `POD_NAME` by the image entrypoint: + +| Settings | StatefulSet | Minion IDs | +| --- | --- | --- | +| defaults | `salt-minion` | `salt-minion-0` | +| `agent.minion.idPrefix=edge`, `agent.replicas=3` | `edge` | `edge-0`, `edge-1`, `edge-2` | +| `agent.minion.id=web`, `agent.replicas=1` | `salt-minion` | `web` (overrides the pod name) | + +Note that a default single-replica install registers as `salt-minion-0`. The +StatefulSet does not need a Service; minions only connect outward to the master. + ### Key storage -The minion Pod uses an `emptyDir` for its working PKI directory. The init -container copies the keys from the Secret when the Pod starts. +Every pod has an `emptyDir` PKI volume at `/pki`. When the pod starts, the +`prepare-minion-keys` init container copies the pod's keys from the key Secret into +`/pki/minion` (through a temporary directory, then an atomic `mv`), and the minion +container mounts that directory at `/etc/salt/pki/minion`. The copy runs on every pod +start, so the Secret is the source of truth and a rescheduled pod keeps its identity. ### Vault Integration -Enable Vault for secure credential sourcing: - ```yaml agent: vault: addr: https://vault.example.com:8200 authMethod: approle roleId: my-role-id - secretId: my-secret-id # Or use secretIdFile + secretId: my-secret-id # or secretIdFile (a path to a mounted file) sdbProfile: vault_sdb ``` Then reference secrets in pillar: + ```sls credentials: api_key: sdb://vault_sdb/secret/data/api:key ``` +The chart has no value for mounting a Secret into the pod, so `secretIdFile` and +`tokenFile` only help if the file is provided some other way. `secretId` and `token` +are plain pod environment variables, visible in `kubectl get pod -o yaml`. + ### Key Management -The key preparation init container and minion use the same image and container security context. The pod `fsGroup` gives them access to the Secret and PKI volume. Secrets must provide `minion.pem` and `minion.pub` files containing PEM text. Set `agent.minion.privateKeyB64` and `agent.minion.publicKeyB64` together to create this Secret from base64-encoded PEM values. +The init container and the minion use the same image and container security context +(uid/gid `10001`, no privilege escalation, all capabilities dropped). The pod +`fsGroup` and the Secret volume mode `0440` let the non-root init container read the +key Secret. Inside the pod the private key ends up with mode `0400` and the public +key with `0644`. + +There are three key sources. One is required in in_cluster mode. + +| Source | Settings | Secret | Replicas | +| --- | --- | --- | --- | +| Existing Secret | `agent.minion.keySecretName` | You create it | any | +| Inline keys | `privateKeyB64` + `publicKeyB64` | Chart creates `keySecretName`, or `-keys` when that is empty | 1 only | +| Key generation Job | `allowSelfGeneratedKey: true` (and no `keySecretName`) | Job creates `-keys` | any | + +Secret layout: -When inline keys are supplied, Helm creates the Secret using `keySecretName` if set. Installation fails if an unmanaged Secret with that name already exists. To use an existing Secret, set `keySecretName` without inline keys. +- One replica: keys `minion.pem` and `minion.pub`, both containing PEM text. +- More than one replica: one pair per pod, `.pem` and `.pub` + (for example `edge-0.pem`, `edge-0.pub`). Each pod mounts only its own pair; the + Secret volume uses `items` and `subPathExpr: $(POD_NAME)` for that. The Secret has + to contain a pair for every pod from `0` to `replicas-1`; if a pair is missing, the + pods cannot mount the volume and stay in `ContainerCreating`. -#### Pre-Seeded Keys +Inline keys: Helm creates the Secret. The install fails if an unmanaged Secret with +that name already exists. To use an existing Secret, set `keySecretName` and no +inline keys. `privateKeyB64` and `publicKeyB64` must be set together. -For production with pre-generated keys: +The key generation Job only runs when `allowSelfGeneratedKey` is `true` and +`keySecretName`, `privateKeyB64` and `publicKeyB64` are all empty. If you set +`keySecretName` as well, no Job is created and the Secret must already exist. + +#### Pre-seeded keys (one replica) ```bash -# Create secret kubectl create secret generic my-minion-keys \ --from-file=minion.pem=/path/to/minion.pem \ --from-file=minion.pub=/path/to/minion.pub \ -n salt -# Use in Helm helm install salt-minion ./helm/salt-minion \ + --namespace salt \ + --set agent.saltMasterHost=salt-master.salt-master.svc.cluster.local \ --set agent.minion.keySecretName=my-minion-keys ``` -#### Auto-Generated Keys - -The chart's pre-install Job automatically generates keys: +#### Auto-generated keys ```bash helm install salt-minion ./helm/salt-minion \ + --namespace salt \ + --set agent.saltMasterHost=salt-master.salt-master.svc.cluster.local \ --set agent.minion.allowSelfGeneratedKey=true ``` +The Job is an ordinary Job, not a Helm hook. It starts together with the +StatefulSet; the pods wait in `ContainerCreating` until the Secret exists. It uses the +ServiceAccount `salt-minion`, bound to a Role (`-minion-keygen-role`) that +can `create`, `get`, `list` and `patch` Secrets in the namespace +(`rbac.create: false` skips the Role and RoleBinding, and then you must provide +equivalent rights). + +With one replica the Job creates Secret `-keys` with `minion.pem` and +`minion.pub`, and does nothing if the Secret already exists. + ### Multiple replicas -The minion runs as a StatefulSet, and every replica is a **separate minion** with -its own ID (the pod name) and its own keypair. Set `agent.minion.idPrefix` to choose -the names: +Every replica is a separate minion with its own ID (the pod name) and its own keypair. +Set `agent.minion.idPrefix` to choose the names: ```bash helm install salt-minion ./helm/salt-minion \ - --set agent.saltMasterHost=salt-master.example.com \ + --namespace salt \ + --set agent.saltMasterHost=salt-master.salt-master.svc.cluster.local \ --set agent.replicas=3 \ --set agent.minion.idPrefix=external-minion \ - --set agent.minion.allowSelfGeneratedKey=true # minions: external-minion-0, -1, -2 + --set agent.minion.allowSelfGeneratedKey=true +# minions: external-minion-0, external-minion-1, external-minion-2 ``` -- `agent.minion.id` and `agent.minion.privateKeyB64`/`publicKeyB64` describe a single - identity, so the chart refuses them when `agent.replicas > 1`. -- With `allowSelfGeneratedKey`, the keygen Job creates one Secret holding a pair per pod - (`.pem` / `.pub`). Scaling up only adds the missing pairs; existing keys are - never regenerated. Each pod mounts only its own pair. -- With your own keys, create that Secret yourself (same key names) and set - `agent.minion.keySecretName`: - - ```bash - kubectl create secret generic my-minion-keys -n salt \ - --from-file=external-minion-0.pem=./0.pem --from-file=external-minion-0.pub=./0.pub \ - --from-file=external-minion-1.pem=./1.pem --from-file=external-minion-1.pub=./1.pub - ``` -- Every pod's public key must be accepted by the master, for example one `SaltMinionKey` - per pod. -- Scaling down leaves the extra pairs in the Secret. Remove them, and the minion keys on - the master, if you don't want them. +Rules the chart enforces for `agent.replicas > 1`: -### Health Checks +- `agent.minion.id` is rejected: `agent.minion.id cannot be used with agent.replicas > 1 + (every pod would register as the same minion); use agent.minion.idPrefix to get + -0, -1, ...` +- `privateKeyB64`/`publicKeyB64` are rejected: `agent.minion.privateKeyB64/publicKeyB64 + hold a single keypair and cannot be used with agent.replicas > 1; set + agent.minion.keySecretName to a Secret with per-pod keys, or enable + agent.minion.allowSelfGeneratedKey` +- The StatefulSet uses `podManagementPolicy: Parallel`, so pods start and are replaced + independently. -The minion includes both liveness and readiness probes: +#### Generated per-pod keys -- **Liveness**: Verifies minion process is responsive (30s initial, 60s period) -- **Readiness**: Verifies minion can handle requests (15s initial, 30s period) +With `allowSelfGeneratedKey`, the key generation Job creates Secret `-keys` +holding a pair per pod. The Job is named `-keygen-` (so a different +replica count is a new Job) and is idempotent: -Both use: `salt-call --local test.ping` +- It reads the Secret's existing keys and never regenerates a pair that exists, because + the master already trusts it. +- It creates the Secret if it does not exist, or adds only the missing pairs with + `kubectl patch`. +- If nothing is missing it logs `All keys already exist; nothing to do` and exits. -Configure probe behavior in values: +Scale up (`helm upgrade --set agent.replicas=5`): the new `-keygen-5` Job adds +the pairs for the new pods only. Existing pods keep their keys. The new minions have to +be accepted on the master. Pods that restart before the Job finishes wait in +`ContainerCreating` until the pairs exist. -```yaml -# Not directly exposed; modify template if needed -# Default: 30s initial delay, 60s period, 10s timeout, 3 failures -``` +Scale down: the extra pods are removed, but their key pairs stay in the Secret, and +their keys stay accepted on the master. Remove both if you do not want them +(edit the Secret to drop the `.pem`/`.pub` entries, and run +`salt-key -d ` on the master or delete the `SaltMinionKey`). Scaling back up +later reuses a stored pair. + +If you change from one replica to several, the existing Secret keeps `minion.pem` and +`minion.pub`, and the Job adds `-0`, `-1`, ... pairs. Pod 0 then uses a +new keypair (and, if you used `agent.minion.id`, a new ID), which must be accepted +again. -### Multi-Master Mode +#### Your own per-pod keys -For Salt's native multi-master setup: +Create the Secret yourself with a pair for every pod and set `keySecretName`: ```bash +kubectl create secret generic my-minion-keys -n salt \ + --from-file=external-minion-0.pem=./0.pem --from-file=external-minion-0.pub=./0.pub \ + --from-file=external-minion-1.pem=./1.pem --from-file=external-minion-1.pub=./1.pub + helm install salt-minion ./helm/salt-minion \ - --set agent.minion.allowSelfGeneratedKey=true \ - --set 'agent.saltMasterHost=master-0.example.com,master-1.example.com,master-2.example.com' + --namespace salt \ + --set agent.saltMasterHost=salt-master.salt-master.svc.cluster.local \ + --set agent.replicas=2 \ + --set agent.minion.idPrefix=external-minion \ + --set agent.minion.keySecretName=my-minion-keys ``` -The comma-separated list is converted to a YAML list in minion configuration. +Add the pairs for new pods to the Secret before you raise `agent.replicas`. Key names +must be exactly `-.pem` and `.pub`. + +#### Accepting the keys on the master + +The master has to accept the public key of every pod. With the +[salt-key-operator](../salt-key-operator/), create one `SaltMinionKey` per pod, in the +master's namespace, using the public key from the Secret: + +```bash +for i in 0 1 2; do + id="external-minion-$i" + pub="$(kubectl get secret salt-minion-keys -n salt \ + -o go-template="{{index .data \"$id.pub\" | base64decode}}")" + kubectl apply -f - <-keys` for a release named `salt-minion`.) Without +the operator, use `salt-key -a ` on the master (see Verification), or enable +auto-accept on the master. With a pod's own key already trusted on the master, the +minion is accepted without any prompt, even if the pod is rescheduled. -### Version 0.1.0+ +### Health Checks -✅ **Health Checks Added** -- Liveness probe: Detects unresponsive minion (salt-call --local test.ping) -- Readiness probe: Ensures minion is ready for commands -- Automatic pod restart on health check failure +The minion container has both probes (not configurable through values): -✅ **Secret Name Consistency** -- Fixed mismatch between Deployment and keygen-job -- Automatic secret name: `${RELEASE_NAME}-keys` -- Configurable via `agent.minion.keySecretName` +| Probe | Initial delay | Period | Timeout | Failure threshold | +| --- | --- | --- | --- | --- | +| Liveness | 30s | 60s | 10s | 3 | +| Readiness | 15s | 30s | 10s | 3 | -✅ **Improved Template** -- Removed unused volume references -- Cleaner manifest generation -- Better variable consistency +Both run `salt-call --local test.ping`, which checks the local minion install, not +the connection to the master. Change the templates if you need other timings. ## Security Design -The chart applies comprehensive security controls: +- Runs as non-root uid/gid `10001` (set by the image); `runAsNonRoot` is enforced +- `fsGroup: 10001`; the key Secret is mounted with mode `0440` +- The init container `prepare-minion-keys` runs with the same non-root container + security context as the minion, with no added capabilities +- Privilege escalation disabled, all Linux capabilities dropped +- Keys are copied atomically into an `emptyDir`; private key mode `0400`, public key + `0644`; Secret volumes are read-only +- Each pod mounts only its own key pair when `agent.replicas > 1` +- The image enables Salt FIPS mode (`SALT_FIPS_MODE=true`) by default; the chart has no + value to turn it off +- RBAC: `rbac.fullAccess` defaults to `true`, which grants `*` on `*` through a Role + and a ClusterRole. Set it to `false` and supply `rbac.customRoleRules` and + `rbac.customClusterRoleRules` to restrict the minion +- Minion keys are not auto-accepted by the chart; acceptance happens on the master + +## Upgrading + +The Deployment from earlier releases was replaced by a StatefulSet, and a Deployment +cannot be converted to a StatefulSet in place. Uninstall and reinstall instead of +`helm upgrade`: + +```bash +helm uninstall salt-minion -n salt +helm install salt-minion ./helm/salt-minion ... # same values +``` -- Runs as non-root user (UID 10000) -- Disables privilege escalation -- Drops all Linux capabilities -- Private keys stored with mode 0400 -- Public keys stored with mode 0644 -- Secret volumes remain read-only -- RBAC scoped to minion permissions -- Automatic minion acceptance disabled by default +Minion IDs change from the old random Deployment pod name (or `agent.minion.id`) to +`-` unless you keep `agent.minion.id` with one replica. Delete the +old minion keys on the master and accept the new ones. An existing key Secret +(`-keys` or your own) with `minion.pem`/`minion.pub` is reused for a +single-replica install and keeps its keypair. ## Troubleshooting -### Minion stuck in pending +### Pods stay in ContainerCreating + +```bash +kubectl describe pod -n salt salt-minion-0 +``` + +Look for a missing Secret or Secret key. With `agent.replicas > 1` the key Secret must +hold `.pem` and `.pub` for every pod, and for the generated case the +key generation Job must have completed (`kubectl get job -n salt`). + +### Pods stay in Pending ```bash kubectl describe pod -n salt -l app=salt-minion -# Check: resource requests, node selectors, storage availability +# Check: node selectors, resource availability, pull secrets ``` +### Install fails at render time + +The chart rejects: no key source in in_cluster mode, `privateKeyB64` without +`publicKeyB64` (or the reverse), `agent.minion.id` with several replicas, inline keys +with several replicas, and inline keys when an unmanaged Secret of that name already +exists. The error text names the setting to change. + ### Minion not connecting to master ```bash # Check master hostname resolution -kubectl exec deployment/salt-minion -n salt -- \ - nslookup salt-master.example.com +kubectl exec -n salt salt-minion-0 -- nslookup salt-master.salt-master.svc.cluster.local # Check connectivity -kubectl exec deployment/salt-minion -n salt -- \ - nc -zv salt-master.example.com 4506 +kubectl exec -n salt salt-minion-0 -- nc -zv salt-master.salt-master.svc.cluster.local 4506 # View minion logs -kubectl logs deployment/salt-minion -n salt +kubectl logs -n salt salt-minion-0 ``` ### Health check failing ```bash -# Test locally -kubectl exec deployment/salt-minion -n salt -- \ - salt-call --local test.ping - -# View probe history -kubectl describe pod -n salt -l app=salt-minion | grep -A 5 "Probe" +kubectl exec -n salt salt-minion-0 -- salt-call --local test.ping +kubectl describe pod -n salt salt-minion-0 | grep -A 5 "Probe" ``` -### Key not appearing in master +### Key not appearing on the master ```bash -# Verify secret was created -kubectl get secret -n salt | grep keys +# Verify the key Secret exists and holds the expected keys +kubectl describe secret salt-minion-keys -n salt -# Check keygen job logs -kubectl logs job/salt-minion-keygen -n salt +# Check the key generation Job +kubectl get job -n salt +kubectl logs job/salt-minion-keygen -n salt # one replica +kubectl logs job/salt-minion-keygen-3 -n salt # three replicas ``` -## Related Documentation +The minion sends its public key to the master on first connect; it appears as a +pending key (`salt-key -L`) unless it has already been accepted or the master +auto-accepts. -- [Salt Minion Source](../../src/minion/README.md) - Docker image documentation -- [Salt Master Chart](../salt-master/README.md) - Master deployment -- [Salt Key Operator](../salt-key-operator/README.md) - Declarative key management -- [Complete System Test](../../docs/complete-system-test.md) - Integration testing -- [Salt Documentation](https://docs.saltproject.io/) - Official Salt resources +## Running the chart tests -## Validation +The chart has [helm-unittest](https://github.com/helm-unittest/helm-unittest) suites +in [`tests/`](tests/). The pull request CI workflow runs them. Locally: -All changes have been validated: +```bash +helm plugin install https://github.com/helm-unittest/helm-unittest --version v1.2.1 +helm unittest helm/salt-minion +helm lint helm/salt-minion +``` + +## Related Documentation -✅ 26/26 helm validation tests passed -✅ Chart linting passes -✅ Templates render correctly -✅ Health checks properly configured -✅ Security context enforced -✅ Production ready +- [Salt Minion Source](../../src/minion/README.md) - image documentation +- [Salt Master Chart](../salt-master/README.md) - master deployment +- [Salt Key Operator](../salt-key-operator/) - declarative key management +- [Complete System Test](../../docs/complete-system-test.md) - integration testing +- [Salt Documentation](https://docs.saltproject.io/) - official Salt resources diff --git a/helm/salt-minion/salt-extensions.txt b/helm/salt-minion/salt-extensions.txt index 4f62ac8..c11dd72 100644 --- a/helm/salt-minion/salt-extensions.txt +++ b/helm/salt-minion/salt-extensions.txt @@ -1,5 +1,9 @@ # Salt extension packages installed into the Salt onedir Python environment. # Add/remove/pin any pip-installable Salt extension here. +# +# NOTE: this copy is not read by any image build. The images use +# src/minion/kubernetes/salt-extensions.txt and src/minion/vcf/salt-extensions.txt; +# edit those. # Kubernetes execution/state modules and cluster-API access # Source: https://github.com/salt-extensions/saltext-kubernetes diff --git a/helm/salt-minion/values.yaml b/helm/salt-minion/values.yaml index ba9fe14..277032b 100644 --- a/helm/salt-minion/values.yaml +++ b/helm/salt-minion/values.yaml @@ -1,21 +1,23 @@ -# Namespace where all salt-minion objects are deployed. -# Must match the namespace used in kube-bench-job. +# Namespace where all salt-minion objects are deployed. Every namespaced object +# uses this value, not the namespace given to `helm --namespace`, so keep the two +# the same. Must also match the namespace used in kube-bench-job. namespace: salt agent: # Deployment mode: - # in_cluster — deploy the Salt minion as a Kubernetes Deployment (default) + # in_cluster — deploy the Salt minion as a Kubernetes StatefulSet (default) # external — create RBAC only; the minion runs outside the cluster authMode: in_cluster - # The image supplies the numeric user and group for the containers. - # fsGroup provides access to the key Secret and the writable PKI volume. + # The image supplies the numeric user and group (10001) for the containers. + # fsGroup lets the non-root containers read the key Secret (mounted 0440) and + # write the emptyDir PKI volume. podSecurityContext: fsGroup: 10001 runAsNonRoot: true - # No added capabilities. The minion and key preparation init container - # use this context and run without privilege escalation. + # No added capabilities. The minion and the prepare-minion-keys init + # container both use this context: non-root, no privilege escalation. containerSecurityContext: allowPrivilegeEscalation: false runAsNonRoot: true @@ -26,30 +28,37 @@ agent: # ── in_cluster mode settings ────────────────────────────────────────────── image: imagePullSecrets: [] - # Published by this repo (see ../docs/releasing.md and CHANGELOG.md for + # Published by this repo (see ../../docs/releasing.md and CHANGELOG.md for # exactly which Salt/extension versions this tag carries) - preloaded - # with saltext.vault and saltext.kubernetes on top of core Salt. Point - # this at a plain saltstack/salt image instead if you don't need either - # extension. + # with saltext.vault and saltext.kubernetes on top of core Salt. The tag + # is an image release number, not a Salt version. A different image has + # to provide the same entrypoint contract (see ../../src/minion/README.md), + # including the POD_NAME fallback for the minion ID. repository: ghcr.io/saltstack/salt-kubernetes/salt-minion - # To use VCF extensions, set repository to the VCF image (e.g., salt-minion-vcf) and appropriate tag + # To use the VCF extensions, set repository to the VCF image (e.g., salt-minion-vcf) and an appropriate tag # repository: ghcr.io/saltstack/salt-kubernetes/salt-minion-vcf tag: "0.1.0" pullPolicy: IfNotPresent # Sets SALT_LOG_LEVEL / `log_level:` on the minion. logLevel: info + # Number of minion pods. Every replica is a separate minion with its own ID + # (-) and its own keypair - this is not plain scaling of + # one identity. With more than one replica see minion.keySecretName below. replicas: 1 # Salt master address. Required when authMode=in_cluster. Also accepts a # list, for Salt's native multi-master mode # (https://docs.saltproject.io/en/3006/topics/tutorials/multimaster.html) - - # one independent, simultaneous connection per address, not failover. - # Point this at every replica address of an active-active - # salt-master-kubernetes release instead of a single master, e.g.: + # one independent, simultaneous connection per address, not failover, and + # every listed master has to accept every minion key. Use it for independent + # masters, e.g. the classic multi-master mode of the salt-master chart + # (agent.cluster.enabled=false, replicas > 1), where each replica has its own + # name through the headless Service: # saltMasterHost: - # - salt-master-kubernetes-0.salt-master-kubernetes-headless.salt-master.svc.cluster.local - # - salt-master-kubernetes-1.salt-master-kubernetes-headless.salt-master.svc.cluster.local - # - salt-master-kubernetes-2.salt-master-kubernetes-headless.salt-master.svc.cluster.local + # - salt-master-0.salt-master-headless.salt-master.svc.cluster.local + # - salt-master-1.salt-master-headless.salt-master.svc.cluster.local + # For a Salt master CLUSTER (agent.cluster.enabled=true) use a single + # address: the one salt-master Service. saltMasterHost: "" # "ret" channel (master_port). Override alongside saltPublishPort whenever # the master isn't reachable on its default ports as-is -- e.g. behind a @@ -80,25 +89,34 @@ agent: reconRandomize: true minion: - # Salt minion ID. Leave empty to use the pod hostname. Only valid with - # agent.replicas: 1 - with more replicas every pod would register as the - # same minion, so the chart refuses; use idPrefix instead. + # Explicit minion ID. Leave empty to use the pod name (default + # "salt-minion-0"). Only valid with agent.replicas: 1 - with more replicas + # every pod would register as the same minion, so the chart refuses; use + # idPrefix instead. id: "" # Names the StatefulSet (default "salt-minion"). Pods are then named # -0, -1, ... and each pod's minion ID is its pod # name, e.g. idPrefix: external-minion -> external-minion-0, -1, ... idPrefix: "" + # masterId and grains are currently only written to the + # -minion-config ConfigMap, which no pod mounts, so they do not + # affect the minion. masterId: "" + # Base64-encoded master public key; passed as SALT_MASTER_PUBKEY_B64 so the + # minion trusts the master directly on first connect. masterPubKeyB64: "" - # Additional grains injected via the minion config ConfigMap. grains: {} + # Inline keypair (base64-encoded PEM), set together. One replica only: the + # chart creates a Secret from them (named keySecretName, or -keys). + # The chart rejects them with replicas > 1. privateKeyB64: "" publicKeyB64: "" # Name of an EXISTING Kubernetes Secret (created out-of-band, never via # Helm values) with raw 'minion.pem' and 'minion.pub' entries. When - # empty, the chart creates a Secret from privateKeyB64 and publicKeyB64 - # or, when explicitly enabled below, a keygen Job. + # empty, the Secret is called -keys; the chart creates it from + # privateKeyB64 and publicKeyB64 or, when explicitly enabled below, a + # keygen Job fills it. Setting this disables the keygen Job. # For pre-registered trust, the minion's public key must already be # trusted (e.g. via salt-key-operator's SaltMinionKey - see # ../../salt-key-operator) *before* the minion starts, so it must be @@ -109,13 +127,16 @@ agent: # holds one pair per pod, as '.pem' and '.pub' (e.g. # external-minion-0.pem), and each pod mounts only its own pair. The # keygen Job creates this layout (and adds missing pairs when you scale - # up); privateKeyB64/publicKeyB64 hold one pair and are rejected. + # up). With your own Secret it must hold a pair for EVERY pod before the + # pods can start; privateKeyB64/publicKeyB64 hold one pair and are rejected. keySecretName: "" # Explicit opt-out of the keySecretName requirement above when # privateKeyB64 and publicKeyB64 are not supplied - allows the keygen - # Job to create a keypair. - # The generated public key must be accepted by the Salt master. + # Job to create the keys in Secret -keys (one pair per pod when + # replicas > 1; existing pairs are never regenerated). The Job only runs + # while keySecretName is empty. + # The generated public keys must be accepted by the Salt master. # Named explicitly rather than just leaving keySecretName empty, so # choosing this behavior is a deliberate, visible decision in your # values file. @@ -123,9 +144,11 @@ agent: # Optional Vault integration (saltext.vault, baked into this chart's # default image) - lets pillar values reference sdb://vault_sdb/: - # instead of plaintext. All optional; disabled unless addr is set. Prefer - # secretIdFile/tokenFile (a mounted Secret) over secretId/token (plain - # values, visible in `kubectl get pod -o yaml`). + # instead of plaintext. All optional; disabled unless addr is set. + # secretId/token are plain pod environment variables, visible in + # `kubectl get pod -o yaml`. secretIdFile/tokenFile are paths read inside the + # container; the chart does not mount anything there, so the file has to + # exist in the image or come from your own customization. vault: addr: "" authMethod: approle @@ -136,9 +159,10 @@ agent: tokenFile: "" sdbProfile: vault_sdb - # Select the nodes on which the minion Pod can run. + # Select the nodes on which the minion pods can run. nodeSelector: {} +# Image for the key generation Job (needs kubectl and openssl). keygen: image: imagePullSecrets: [] diff --git a/scripts/salt-kubernetes-e2e-local-test.sh b/scripts/salt-kubernetes-e2e-local-test.sh index b756f24..d117522 100755 --- a/scripts/salt-kubernetes-e2e-local-test.sh +++ b/scripts/salt-kubernetes-e2e-local-test.sh @@ -216,7 +216,7 @@ kubectl rollout status deployment/salt-key-operator \ --namespace "${MASTER_NAMESPACE}" \ --timeout=3m -kubectl rollout status deployment/salt-master \ +kubectl rollout status statefulset/salt-master \ --namespace "${MASTER_NAMESPACE}" \ --timeout=3m @@ -303,7 +303,7 @@ KEY_FOUND=false for attempt in $(seq 1 24); do ACTUAL_MINION_KEY_HASH="$( - kubectl exec deployment/salt-master \ + kubectl exec statefulset/salt-master \ --namespace "${MASTER_NAMESPACE}" \ --container salt-master \ -- sha256sum \ @@ -327,7 +327,7 @@ if [ "${KEY_FOUND}" != "true" ]; then exit 1 fi -kubectl exec deployment/salt-master \ +kubectl exec statefulset/salt-master \ --namespace "${MASTER_NAMESPACE}" \ --container salt-master \ -- salt-key -L @@ -380,7 +380,7 @@ helm upgrade --install "${MINION_RELEASE}" \ --wait \ --timeout 5m -kubectl rollout status deployment/salt-minion \ +kubectl rollout status statefulset/salt-minion \ --namespace "${MINION_NAMESPACE}" \ --timeout=3m @@ -394,7 +394,7 @@ kubectl get pods \ kubectl get pods \ --namespace "${MINION_NAMESPACE}" -kubectl logs deployment/salt-minion \ +kubectl logs statefulset/salt-minion \ --namespace "${MINION_NAMESPACE}" \ --container salt-minion \ --tail=40 @@ -404,7 +404,7 @@ echo "20. Run the real Master-to-Minion test" echo "====================================================" PING_OUTPUT="$( - kubectl exec deployment/salt-master \ + kubectl exec statefulset/salt-master \ --namespace "${MASTER_NAMESPACE}" \ --container salt-master \ -- salt \ @@ -422,15 +422,15 @@ echo "====================================================" echo "21. Restart the Minion and verify identity" echo "====================================================" -kubectl rollout restart deployment/salt-minion \ +kubectl rollout restart statefulset/salt-minion \ --namespace "${MINION_NAMESPACE}" -kubectl rollout status deployment/salt-minion \ +kubectl rollout status statefulset/salt-minion \ --namespace "${MINION_NAMESPACE}" \ --timeout=3m RESTARTED_MINION_KEY_HASH="$( - kubectl exec deployment/salt-minion \ + kubectl exec statefulset/salt-minion \ --namespace "${MINION_NAMESPACE}" \ --container salt-minion \ -- sha256sum /etc/salt/pki/minion/minion.pub | @@ -443,7 +443,7 @@ echo "Restarted key hash: ${RESTARTED_MINION_KEY_HASH}" test "${EXPECTED_MINION_KEY_HASH}" = "${RESTARTED_MINION_KEY_HASH}" echo "Minion identity after restart: PASS" -kubectl exec deployment/salt-master \ +kubectl exec statefulset/salt-master \ --namespace "${MASTER_NAMESPACE}" \ --container salt-master \ -- salt \ diff --git a/src/README.md b/src/README.md index 2a76cdc..44fc76c 100644 --- a/src/README.md +++ b/src/README.md @@ -1,3 +1,14 @@ -# Source code for Docker Image Production +# Image sources -This directory holds any source files that may be added in the future. Currently the build is driven by Dockerfiles in the `salt-kubernetes` repository. +This directory holds the source for each container image. Each subdirectory is +the Docker build context for its image. + +| Directory | Image | Notes | +| --- | --- | --- | +| [`master`](master) | `salt-master` | Salt master. See [`master/README.md`](master/README.md). | +| [`minion/kubernetes`](minion/kubernetes) | `salt-minion` | Minion with `saltext.kubernetes`, `saltext.vault` and `kubectl`. See [`minion/README.md`](minion/README.md). | +| [`minion/vcf`](minion/vcf) | `salt-minion-vcf` | Minion with configurable extensions (VCF by default). See [`minion/README.md`](minion/README.md). | +| [`salt-key-operator`](salt-key-operator) | `salt-key-operator` | Go operator for the `SaltMinionKey` CRD. See [`salt-key-operator/README.md`](salt-key-operator/README.md). | + +Build commands are in [`../docs/building.md`](../docs/building.md). The Helm charts +are in [`../helm`](../helm). diff --git a/src/master/CHANGELOG.md b/src/master/CHANGELOG.md index da2ab1e..d121701 100644 --- a/src/master/CHANGELOG.md +++ b/src/master/CHANGELOG.md @@ -1,15 +1,31 @@ # Changelog (salt-master image) -Records what each `salt-master-image/vX.Y.Z` release tag (see -[`docs/releasing.md`](../../docs/releasing.md)) actually carries. The tag itself is an +Records what each image release (release tag `salt-master-vX.Y.Z`, see +[`docs/releasing.md`](../../docs/releasing.md); the headings below use the older +`salt-master-image/vX.Y.Z` form) actually carries. The tag itself is an independent semver for this image — it does not encode the Salt version, so check here before assuming. ## salt-master-image/v1.1.0 -- Salt: 3008.5 -- `entrypoint.sh` renders master cluster config when `SALT_CLUSTER_ID` is set - (`SALT_CLUSTER_PEERS`, `SALT_CLUSTER_SECRET`, `SALT_CLUSTER_PKI_DIR`, - `SALT_CLUSTER_POOL_PORT`, `SALT_CLUSTER_ISOLATED_FILESYSTEM`). +- Salt: 3008.5 (was 3008.2). Base and install method unchanged. +- `entrypoint.sh` renders master cluster configuration (`/etc/salt/master.d/98-cluster.conf`) + when `SALT_CLUSTER_ID` is set: `cluster_id`, `cluster_pki_dir`, `cluster_pool_port`, + `cluster_secret`, `cluster_peers`, optionally `cluster_isolated_filesystem`, `keys.cache_driver`, + `cluster_auto_replace_voters` and `cluster_min_voters`. + Variables: `SALT_CLUSTER_ID`, `SALT_CLUSTER_PEERS`, `SALT_CLUSTER_SECRET`, + `SALT_CLUSTER_PKI_DIR`, `SALT_CLUSTER_POOL_PORT`, `SALT_CLUSTER_ISOLATED_FILESYSTEM`, + `SALT_CLUSTER_NODE_ADDRESS`, `SALT_CLUSTER_KEYS_CACHE_DRIVER`, + `SALT_CLUSTER_AUTO_REPLACE_VOTERS`, `SALT_CLUSTER_MIN_VOTERS`, `SALT_CLUSTER_PEER_WAIT_SECONDS`. +- Cluster behaviour found by testing on a real cluster: Salt refuses a cluster member with no + peers, so the entrypoint waits (default 120 seconds) for the other masters' DNS names to resolve, + resolves them to IPs for `cluster_peers` (dropping its own entry), and exits with an error if + none resolve. `SALT_CLUSTER_NODE_ADDRESS` is written as `interface:` and, unless + `SALT_MASTER_ID` is set, also as the master `id:` (Salt uses `interface` as the consensus node + identity). +- Known limitation: with the pod IP as cluster identity, a restarted master cannot rejoin its + cluster (see the chart CHANGELOG). Classic (non-cluster) use is unaffected. +- Behaviour without `SALT_CLUSTER_ID` is unchanged (user 10001, health check on ports + 4505/4506). ## salt-master-image/v1.0.0 - Salt: 3008.2 diff --git a/src/master/README.md b/src/master/README.md index 7a40294..ad66072 100644 --- a/src/master/README.md +++ b/src/master/README.md @@ -13,9 +13,13 @@ The image: - Runs as the non-root `salt` user with UID/GID `10001`. - Supports an optional corporate CA during image build. - Does not retain the build-time corporate CA in the final image. -- Exposes Salt ports `4505` and `4506`. -- Includes a Docker health check for both Salt ports. +- Serves Salt on ports `4505` (publish) and `4506` (request/return). The Dockerfile has no + `EXPOSE` instruction, so publish the ports yourself (`--publish`). +- Includes a Docker health check for both Salt ports. Kubernetes does not use it, and the + Helm chart defines no probes. - Supports externally supplied or Kubernetes-managed master keys. +- Can run as a member of a Salt master cluster, configured through `SALT_CLUSTER_*` + environment variables (see "Environment variables"). The Helm chart sets these. See [CHANGELOG.md](CHANGELOG.md) for the Salt version included in each image release. @@ -32,25 +36,25 @@ docker build \ ### Build behind a corporate TLS proxy -If HTTPS downloads require a corporate root certificate, export the trusted root certificate -from the macOS Keychain: +If HTTPS downloads require a corporate root certificate, obtain that certificate as a PEM file. +For example, on macOS you can export it from the Keychain by its common name: ```bash security find-certificate \ -a \ - -c "Cloud Services Root CA" \ + -c "" \ -p \ "${HOME}/Library/Keychains/login.keychain-db" \ /Library/Keychains/System.keychain \ /System/Library/Keychains/SystemRootCertificates.keychain \ - > /private/tmp/cloud-services-root-ca.crt + > /tmp/corporate-root-ca.crt ``` Verify the certificate: ```bash openssl x509 \ - -in /private/tmp/cloud-services-root-ca.crt \ + -in /tmp/corporate-root-ca.crt \ -noout \ -subject \ -issuer \ @@ -62,7 +66,7 @@ Build the image with the certificate supplied as a BuildKit secret: ```bash docker build \ --platform linux/arm64 \ - --secret id=build_ca,src=/private/tmp/cloud-services-root-ca.crt \ + --secret id=build_ca,src=/tmp/corporate-root-ca.crt \ --tag salt-master:local \ ./src/master ``` @@ -189,10 +193,39 @@ initialize the master key pair: | Variable | Effect | | --- | --- | | `SALT_AUTO_ACCEPT` | Sets Salt's `auto_accept` option. Leave unset or set to `false` when using Salt Key Operator. | -| `SALT_MASTER_ID` | Sets the Salt Master `id`. The pod hostname is used when it is not supplied. | +| `SALT_MASTER_ID` | Sets the Salt Master `id`. When it is not supplied, Salt chooses the id (derived from the host name), except in cluster mode where the entrypoint uses `SALT_CLUSTER_NODE_ADDRESS`. | | `SALT_PRESENCE_EVENTS` | Enables or disables Salt presence events. Defaults to `True`. | -| `SALT_MASTER_PRIVATE_KEY_B64` | Optional base64-encoded master private key used when `master.pem` does not already exist. | -| `SALT_MASTER_PUBLIC_KEY_B64` | Optional base64-encoded master public key used when `master.pub` does not already exist. | +| `SALT_MASTER_PRIVATE_KEY_B64`, `SALT_MASTER_PUBLIC_KEY_B64` | Optional base64-encoded master key pair. Both must be set; they are written to `/etc/salt/pki/master` only when `master.pem` does not already exist there. The Helm chart does not use these; it supplies the keys as files. | + +The entrypoint also always writes `pidfile` and `sock_dir` under `/var/cache/salt/master`, because +a non-root master cannot create directories under `/var/run`. + +### Master cluster variables + +Cluster mode (Salt 3007+; `SALT_CLUSTER_ISOLATED_FILESYSTEM` needs Salt 3008+) is enabled by +setting `SALT_CLUSTER_ID`. The entrypoint then writes `/etc/salt/master.d/98-cluster.conf` +(mode `0600`) and creates the cluster PKI directory. See the +[Salt master cluster tutorial](https://docs.saltproject.io/en/latest/topics/tutorials/master-cluster.html). + +| Variable | Effect | +| --- | --- | +| `SALT_CLUSTER_ID` | Sets `cluster_id` and turns cluster mode on. Unset = classic master. | +| `SALT_CLUSTER_PEERS` | Comma-separated peer host names. The entry whose short name equals this host's name is dropped, and each remaining one is resolved to an IP for `cluster_peers`. At least one peer must resolve or the container exits with an error. | +| `SALT_CLUSTER_PEER_WAIT_SECONDS` | How long to wait for all peer names to resolve before continuing with those that did. Default `120`. | +| `SALT_CLUSTER_NODE_ADDRESS` | This master's own peer-reachable IP. Written as `interface:`, and as `id:` unless `SALT_MASTER_ID` is set. Salt uses `interface` as the node identity in cluster consensus, so it must be a real IP, not `0.0.0.0`. | +| `SALT_CLUSTER_SECRET` | Sets `cluster_secret`, which authenticates masters joining the cluster. | +| `SALT_CLUSTER_PKI_DIR` | Sets `cluster_pki_dir`. Default `/etc/salt/pki/cluster`. | +| `SALT_CLUSTER_POOL_PORT` | Sets `cluster_pool_port` (peer-to-peer RPC). Salt's default applies when unset. | +| `SALT_CLUSTER_ISOLATED_FILESYSTEM` | `true` sets `cluster_isolated_filesystem: True` (each master keeps its own PKI and cache). | +| `SALT_CLUSTER_KEYS_CACHE_DRIVER` | Optional `keys.cache_driver`. Salt's default (`localfs_key`) applies when unset. | +| `SALT_CLUSTER_AUTO_REPLACE_VOTERS` | Sets `cluster_auto_replace_voters` (`true`/`false`) when set. | +| `SALT_CLUSTER_MIN_VOTERS` | Sets `cluster_min_voters` when set. | + +Known limitation: Salt 3008.5 identifies a cluster member by its `interface`, so +`SALT_CLUSTER_NODE_ADDRESS` is the member's identity. If a member restarts with a different IP +(as a Kubernetes pod does), it joins as a new member and its old identity remains a dead voter, so +restarting members of a running cluster is not supported. Cluster mode needs at least two members; +use three or more. Without `SALT_CLUSTER_ID` the image behaves as a classic single master. Additional configuration, pillar and state trees can be mounted as read-only volumes: @@ -292,12 +325,12 @@ docker build \ ./src/salt-key-operator ``` -Build Salt Master: +Build Salt Master (omit the `--secret` line if you do not need a corporate CA): ```bash docker build \ --platform linux/arm64 \ - --secret id=build_ca,src=/private/tmp/cloud-services-root-ca.crt \ + --secret id=build_ca,src=/tmp/corporate-root-ca.crt \ --tag salt-master:local \ ./src/master ``` @@ -372,14 +405,19 @@ kubectl get pods,jobs,secrets,configmaps,services \ Expected pod state: ```text -salt-key-operator 1/1 Running -salt-master 2/2 Running +salt-key-operator-... 1/1 Running +salt-master-0 2/2 Running ``` +The master pod has two containers (`salt-master` and the `trusted-minions-sync` sidecar) when +`agent.trustedMinions.enabled=true`, which is the chart default; with it disabled the pod is +`1/1`. For more than one replica, or cluster mode, see the +[chart README](../../helm/salt-master/README.md). + Verify Salt Master: ```bash -kubectl exec deployment/salt-master \ +kubectl exec salt-master-0 \ --namespace salt-master \ --container salt-master \ -- salt-key -L @@ -395,8 +433,14 @@ master.pem master.pub ``` -The Secret is mounted read-only. An init container copies the key pair into a writable -`emptyDir`, applies the required ownership and permissions, and then exits. +This is classic mode. The Secret is mounted read-only (mode `0440`). The `prepare-master-keys` +init container runs as the same non-root user as the master (UID/GID `10001`), copies the key pair +into a writable `emptyDir`, sets the file modes and exits. To supply your own key pair, create a +Secret with the same two keys and set `agent.masterKeySecretName`; this is required when running +more than one classic replica, so that all of them share one key pair. + +In cluster mode (`agent.cluster.enabled=true`) the key-generation Job and this Secret are not +used: each master generates its own key pair and keeps it on its own persistent volume. The long-running Salt Master container runs as UID/GID `10001` and does not require Kubernetes API access. @@ -404,8 +448,8 @@ API access. The key-generation Job is the only component that requires a service-account token. The normal Salt Master ServiceAccount has automatic token mounting disabled. -The master key Secret is reused across pod restarts, allowing the Salt Master to retain the same -identity. +In classic mode the master key Secret is reused across pod restarts, so the Salt Master keeps the +same identity. Verify that the Secret and running pod use the same public key: @@ -418,7 +462,7 @@ kubectl get secret salt-master-master-keys \ ``` ```bash -kubectl exec deployment/salt-master \ +kubectl exec salt-master-0 \ --namespace salt-master \ --container salt-master \ -- sha256sum /etc/salt/pki/master/master.pub @@ -438,7 +482,8 @@ agent: minion acceptance is managed declaratively through Salt Key Operator. -Do not use `salt-key -a` in this mode. Create a `SaltMinionKey` resource instead: +This is the chart default. Do not use `salt-key -a` in this mode: the sidecar removes any key that +is not in the ConfigMap again. Create a `SaltMinionKey` resource instead: ```yaml apiVersion: salt.saltstack.io/v1alpha1 @@ -472,7 +517,7 @@ refresh plus the configured sidecar polling interval, which defaults to 15 secon List accepted keys: ```bash -kubectl exec deployment/salt-master \ +kubectl exec salt-master-0 \ --namespace salt-master \ --container salt-master \ -- salt-key -L @@ -485,17 +530,20 @@ The image and Helm chart apply the following security controls: - Salt Master runs as non-root UID/GID `10001`. - The long-running containers disable privilege escalation. - The long-running containers drop all Linux capabilities. -- The temporary init container receives only the capabilities required to copy and secure the - master keys. -- The master private key is stored in a Kubernetes Secret. +- The init containers (`prepare-master-keys`, or `prepare-cluster-dirs` in cluster mode) also run + non-root with all capabilities dropped. They create the directories they need as UID/GID + `10001`, relying on the pod `fsGroup: 10001` to make volumes group-writable. A volume you + supply yourself must already be writable by that user. +- The master private key is stored in a Kubernetes Secret (classic mode). - The private key is written with mode `0400`. - The public key is written with mode `0644`. -- The Secret source volume remains read-only. +- The Secret source volume remains read-only and is mounted with mode `0440`. - The normal Salt Master pod does not automatically receive a Kubernetes service-account token. - The key-generation Job receives a service-account token only because it must create the Secret. - The corporate CA is supplied as a temporary BuildKit secret and is not retained in the final image. - Automatic minion acceptance is disabled by default for the Helm deployment. +- In cluster mode, keep the peer port (`4520` by default) inside the cluster. - Trusted keys are managed through `SaltMinionKey` resources when Salt Key Operator is enabled. ## Why the runtime changes were required @@ -505,8 +553,8 @@ different from the UID declared by the image. The image therefore normalizes the group to UID/GID `10001` and assigns ownership of Salt's writable directories to that identity. Kubernetes Secret volumes are read-only, but Salt Master must create and update directories under -`/etc/salt/pki/master`. The Helm chart therefore mounts the Secret separately and uses an init -container to copy the master key pair into a writable volume. +`/etc/salt/pki/master`. The Helm chart therefore mounts the Secret separately and uses a non-root +init container to copy the master key pair into a writable volume. Kubernetes ConfigMap files are symbolic links, while Salt 3008 rejects symlinked key files as a PKI hardening measure. The trusted-minions sidecar converts the mounted ConfigMap entries into @@ -517,7 +565,8 @@ The Docker health check observes the existing Salt Master process by checking po ## Validation performed -The following validations were completed successfully: +The following validations were completed on the original Deployment-based chart (classic, +single master): - Helm linting for Salt Master and Salt Key Operator. - Kubernetes client-side validation of the rendered Helm resources. @@ -529,7 +578,7 @@ The following validations were completed successfully: - Clean Helm installation into a new namespace. - Master-key generation Job completion. - Master-key hash comparison between the Secret and running pod. -- Master identity persistence after a Deployment restart. +- Master identity persistence after a pod restart. - Declarative acceptance of a generated test key named `integration-test-minion`. - Propagation of the accepted key into Salt as a regular file. - Removal of the accepted key after deleting its `SaltMinionKey`. @@ -541,4 +590,10 @@ run an end-to-end command such as: salt '*' test.ping ``` -A real Salt Minion connectivity test can be added as a separate integration test. \ No newline at end of file +Master cluster mode (the `SALT_CLUSTER_*` variables and the chart's `agent.cluster.*` values) was +tested on a real cluster with 3 replicas and isolated storage. Not tested: shared storage, +minions connecting through the cluster, node failure, and restarting a cluster member (which is a +known limitation, see "Master cluster variables"). The StatefulSet-based classic mode was +rendered with Helm but its live testing is not recorded here. + +A real Salt Minion connectivity test can be added as a separate integration test. diff --git a/src/minion/README.md b/src/minion/README.md index defafca..430e030 100644 --- a/src/minion/README.md +++ b/src/minion/README.md @@ -1,94 +1,107 @@ -# Salt Minion Images for Kubernetes +# Salt Minion Images -This directory contains Dockerfiles for building Salt Minion images optimized for Kubernetes deployments. +This directory contains the Dockerfiles for the Salt Minion images used by the +[`salt-minion` Helm chart](../../helm/salt-minion/README.md). -Two flavors are provided: +Two flavors are provided. They share the same entrypoint behaviour, runtime identity and +build arguments and differ in the Salt extensions they carry: -1. **Kubernetes Minion** (`kubernetes/`) - General-purpose minion with Kubernetes and Vault support -2. **VCF Minion** (`vcf/`) - VMware Cloud Foundation-specific extensions +1. **Kubernetes Minion** (`kubernetes/`) - `saltext.kubernetes` and `saltext.vault` +2. **VCF Minion** (`vcf/`) - the same plus `saltext.vcf` (VMware Cloud Foundation) and + `saltext.bmc` + +The extension sets live in `kubernetes/salt-extensions.txt` and +`vcf/salt-extensions.txt`. See [CHANGELOG.md](../../helm/salt-minion/CHANGELOG.md) for the +Salt and extension versions in each image release, and +[`docs/building.md`](../../docs/building.md) for building and publishing. ## Kubernetes Minion -A Salt Minion Docker image built from the official Salt onedir distribution using Salt's [bootstrap script](https://github.com/saltstack/salt-bootstrap). +A Salt Minion Docker image built from the official Salt onedir distribution using Salt's +[bootstrap script](https://github.com/saltstack/salt-bootstrap). -This minion is designed specifically for running inside Kubernetes clusters and includes: -- Support for in-cluster deployments via Kubernetes API -- Integration with Salt's Kubernetes execution module (`saltext.kubernetes`) +It is designed for running inside Kubernetes clusters and includes: +- Salt's Kubernetes execution module (`saltext.kubernetes`) - HashiCorp Vault integration for secrets management (`saltext.vault`) -- Bundled `kubectl` for direct cluster interaction +- Bundled `kubectl` (`INCLUDE_KUBECTL=true`, version `KUBECTL_VERSION`) - Support for CIS Kubernetes compliance assessments via kube-bench The image: -- Uses Salt `3008.5` by default -- Runs as the non-root `salt` user with UID/GID `10000` -- Supports optional corporate CA during image build -- Does not retain build-time corporate CA in final image -- Communicates with Salt Master on ports `4505` (publish) and `4506` (request/return) -- Includes Docker health check -- Supports both self-generated and pre-seeded keypairs -- Enables secure multi-master connectivity - -See [CHANGELOG.md](../../helm/salt-minion/CHANGELOG.md) for Salt versions in each image release. +- Uses Salt `3008.5` by default (`SALT_VERSION`; `latest` is also accepted) +- Installs the extensions without replacing the onedir Salt: `salt` is constrained to the + installed version while pip installs the extensions (see + [CHANGELOG.md](../../helm/salt-minion/CHANGELOG.md)) +- Runs as the non-root `salt` user with UID/GID `10001` (`SALT_UID`/`SALT_GID`) +- Supports an optional extra CA during the image build and does not keep it in the + final image +- Communicates with the Salt Master on ports `4505` (publish) and `4506` (request/return) +- Can pre-seed the minion keypair from environment variables, or use a key already + present in `/etc/salt/pki/minion` +- Supports multiple masters (a comma-separated `SALT_MASTER`) +- Has no Docker `HEALTHCHECK`; the Helm chart supplies Kubernetes probes ### Build -From the root of the `salt-kubernetes` repository: +From the root of the repository: ```bash docker build \ - --platform linux/arm64 \ --tag salt-minion:local \ ./src/minion/kubernetes ``` +Add `--platform linux/arm64` (or `linux/amd64`) to build for a specific architecture. +`TARGETARCH` is set by BuildKit and selects the `kubectl` download. + ### Build behind a corporate TLS proxy -If HTTPS downloads require a corporate root certificate: +If HTTPS downloads need an extra root certificate, pass it as the optional `build_ca` +build secret. It is trusted only while the build downloads Salt, the extensions and +`kubectl`, and is removed again afterwards: ```bash -# Export certificate -security find-certificate \ - -a \ - -c "Cloud Services Root CA" \ - -p \ - "${HOME}/Library/Keychains/login.keychain-db" \ - /Library/Keychains/System.keychain \ - /System/Library/Keychains/SystemRootCertificates.keychain \ - > /private/tmp/cloud-services-root-ca.crt - -# Verify certificate -openssl x509 \ - -in /private/tmp/cloud-services-root-ca.crt \ - -noout \ - -subject \ - -issuer \ - -dates - -# Build with certificate docker build \ - --platform linux/arm64 \ - --secret id=build_ca,src=/private/tmp/cloud-services-root-ca.crt \ + --secret id=build_ca,src=./corporate-root-ca.crt \ --tag salt-minion:local \ ./src/minion/kubernetes ``` +The `build_ca` secret is supported by the Kubernetes Dockerfile only; the VCF Dockerfile +does not read it. + ### Build arguments +Both Dockerfiles take the same arguments: + | Argument | Default | Purpose | | --- | --- | --- | -| `SALT_VERSION` | `3008.5` | Salt version to install | +| `SALT_VERSION` | `3008.5` | Salt version to install (`latest` is accepted) | +| `SALT_UID`, `SALT_GID` | `10001` | Numeric user and group of the `salt` account the container runs as | +| `SALT_HOME` | `/opt/saltstack/salt` | Home directory of the `salt` user | +| `SALT_SHELL` | `/usr/sbin/nologin` | Login shell of the `salt` user | +| `INCLUDE_KUBECTL` | `true` | Install `kubectl` into the image | +| `KUBECTL_VERSION` | `v1.30.2` | `kubectl` version to download | +| `EXTRA_SALT_EXTENSIONS` | empty | Extra pip requirements (space separated), installed after `salt-extensions.txt`, with the same `salt` constraint | +| `PIP_INDEX_URL` | empty | Install the extensions from this PyPI index (for example an internal mirror) | +| `PIP_TRUSTED_HOST` | empty | Passed to pip as `--trusted-host` | +| `PIP_ONLY_BINARY` | empty | Passed to pip as `--only-binary` | +| `APT_MIRROR` | empty | Replaces the `URIs:` of the Ubuntu apt sources | +| `SALT_GPG_KEY_URL`, `SALT_APT_REPO_URL` | Broadcom Salt package repository | Declared in the Dockerfiles but not used by the current build steps | Example: ```bash docker build \ - --platform linux/arm64 \ --build-arg SALT_VERSION=3008.5 \ + --build-arg EXTRA_SALT_EXTENSIONS="saltext.example==1.0.0" \ --tag salt-minion:local \ ./src/minion/kubernetes ``` +The salt user and group IDs must match the `fsGroup` the chart uses +(`agent.podSecurityContext.fsGroup`, default `10001`) if you change them. + ### Verify the image ```bash @@ -96,32 +109,20 @@ docker image inspect salt-minion:local \ --format 'Image={{.RepoTags}} Architecture={{.Architecture}} OS={{.Os}}' ``` -Expected on Apple Silicon Mac: - -```text -Image=[salt-minion:local] Architecture=arm64 OS=linux -``` - -Verify Salt version: +Verify the Salt version and that the onedir launcher is intact: ```bash -docker run --rm \ - --platform linux/arm64 \ - salt-minion:local \ - salt-minion --version +docker run --rm --entrypoint salt-minion salt-minion:local --version +docker run --rm --entrypoint salt-pip salt-minion:local list ``` -Expected: - -```text -salt-minion 3008.5 (Argon) -``` +The first command prints `salt-minion 3008.5 (Argon)` for the default build. The second +should list one `salt` package, at the same version, plus the extensions. Verify runtime identity and permissions: ```bash docker run --rm \ - --platform linux/arm64 \ --entrypoint /bin/sh \ salt-minion:local \ -c ' @@ -129,20 +130,13 @@ docker run --rm \ ls -ldn \ /etc/salt \ /etc/salt/minion.d \ - /etc/salt/pki \ + /etc/salt/pki/minion \ /var/cache/salt/minion ' ``` -Expected: - -```text -uid=10000(salt) gid=10000(salt) -drwxr-xr-x 8 root root 4096 Aug 15 20:31 /etc/salt -drwxr-xr-x 2 root root 4096 Aug 15 20:31 /etc/salt/minion.d -drwxr-xr-x 4 root root 4096 Aug 15 20:31 /etc/salt/pki -drwxr-xr-x 4 salt salt 4096 Aug 15 20:31 /var/cache/salt/minion -``` +Expected: `uid=10001(salt) gid=10001(salt)`, and the listed directories owned by +`10001 10001`. ### Run @@ -157,89 +151,50 @@ docker run --rm \ ### Environment variables -The entrypoint translates these variables into minion configuration or uses them for key provisioning: +The entrypoint turns these variables into minion configuration or uses them for key +provisioning: | Variable | Effect | | --- | --- | -| `SALT_MASTER` | Sets master address (required for in_cluster mode). Can be comma-separated list for multi-master mode. | -| `SALT_MASTER_PORT` | Sets Salt request/return port. Default: `4506`. | -| `SALT_PUBLISH_PORT` | Sets Salt publish port. Default: `4505`. | -| `SALT_MINION_ID` | Sets minion ID. Pod hostname used if not supplied. | -| `SALT_MASTER_FINGER` | Sets master fingerprint for trust verification (legacy - use SALT_MASTER_PUBKEY_B64 instead). | -| `SALT_MASTER_PUBKEY_B64` | Base64-encoded master public key for direct trust without fingerprint. | -| `SALT_MINION_PRIVATE_KEY_B64` | Base64-encoded minion private key (pre-seeded keypair). | -| `SALT_MINION_PUBLIC_KEY_B64` | Base64-encoded minion public key (pre-seeded keypair). | -| `SALT_LOG_LEVEL` | Sets minion log level. Default: `info`. | -| `SALT_AUTH_TIMEOUT` | Seconds to wait before master auth retry. Default: `60`. | -| `SALT_MASTER_ALIVE_INTERVAL` | Seconds between master connection checks. Default: `60`. | -| `SALT_RECON_DEFAULT` | ZeroMQ reconnect backoff start (ms). Default: `1000`. | -| `SALT_RECON_MAX` | ZeroMQ reconnect backoff max (ms). Default: `5000`. | -| `SALT_RECON_RANDOMIZE` | Jitter reconnect delay to prevent thundering herd. Default: `true`. | -| `SALT_FIPS_MODE` | Enable FIPS-compliant crypto. Default: `true`. | -| `VAULT_ADDR` | Vault server address (enables saltext.vault). | -| `VAULT_AUTH_METHOD` | Vault auth method: `approle` or `token`. Default: `approle`. | -| `VAULT_ROLE_ID` | Vault AppRole role ID. | -| `VAULT_SECRET_ID` | Vault AppRole secret ID. | -| `VAULT_SECRET_ID_FILE` | Path to Vault secret ID file. | -| `VAULT_TOKEN` | Vault authentication token. | -| `VAULT_TOKEN_FILE` | Path to Vault token file. | - -Additional configuration can be mounted as read-only volumes: - -```bash -docker run --rm \ - --env SALT_MASTER=salt-master.example.com \ - --volume ./pillar:/srv/pillar:ro \ - --volume ./states:/srv/salt:ro \ - salt-minion:local -``` - -### Health check - -The image health check verifies the minion can respond to local requests: - -```bash -docker run --detach \ - --name salt-minion-test \ - --env SALT_MASTER=127.0.0.1 \ - salt-minion:local -``` - -Wait for health check: - -```bash -sleep 40 -``` - -Inspect health: - -```bash -docker inspect salt-minion-test \ - --format 'Status={{.State.Status}} Health={{.State.Health.Status}}' -``` - -Expected: - -```text -Status=running Health=healthy -``` - -Remove container: - -```bash -docker rm --force salt-minion-test -``` +| `SALT_MASTER` | Master address (required unless `/etc/salt/minion.d/10-master.conf` is mounted). A comma-separated list becomes a YAML list: Salt multi-master mode, one simultaneous connection per master. | +| `SALT_MASTER_PORT` | Request/return port (`master_port`). Default `4506`. Must be numeric. | +| `SALT_PUBLISH_PORT` | Publish port (`publish_port`). Default `4505`. Must be numeric. | +| `SALT_MINION_ID` | Minion ID. If empty, `POD_NAME` is used, then the container hostname. The Helm chart sets `POD_NAME` to the pod name. | +| `POD_NAME` | Used as the minion ID when `SALT_MINION_ID` is empty. | +| `SALT_MASTER_FINGER` | Master fingerprint (`master_finger`), legacy. Ignored when `SALT_MASTER_PUBKEY_B64` is set. | +| `SALT_MASTER_PUBKEY_B64` | Base64-encoded master public key, written to `/etc/salt/pki/minion/minion_master.pub` so the minion trusts the master without a fingerprint. | +| `SALT_MINION_PRIVATE_KEY_B64`, `SALT_MINION_PUBLIC_KEY_B64` | Base64-encoded minion keypair, written to `/etc/salt/pki/minion/minion.pem` (`0400`) and `minion.pub` (`0644`). Applied only when both are set and `minion.pem` does not already exist. | +| `SALT_LOG_LEVEL` | Minion log level. Default `info`. Logs go to stdout. | +| `SALT_AUTH_TIMEOUT` | `auth_timeout` in seconds. Default `60`. | +| `SALT_MASTER_ALIVE_INTERVAL` | `master_alive_interval` in seconds. Default `60`. | +| `SALT_RECON_DEFAULT` | `recon_default` in ms. Default `1000`. | +| `SALT_RECON_MAX` | `recon_max` in ms. Default `5000`. | +| `SALT_RECON_RANDOMIZE` | `recon_randomize`, jitters reconnects. Default `True`. | +| `SALT_FIPS_MODE` | Writes `15-fips.conf` with `fips_mode: True` and the algorithms below. Default `true`. | +| `SALT_ENCRYPTION_ALGORITHM`, `SALT_SIGNING_ALGORITHM` | FIPS algorithms. Defaults `OAEP-SHA224` and `PKCS1v15-SHA224`. | +| `VAULT_ADDR` | Vault server address; enables the `vault` and sdb configuration. | +| `VAULT_AUTH_METHOD` | `approle` (default) or `token`. | +| `VAULT_ROLE_ID` | AppRole role ID. | +| `VAULT_SECRET_ID` | AppRole secret ID. | +| `VAULT_SECRET_ID_FILE` | Path to a file whose content is used as the secret ID, if it exists. | +| `VAULT_TOKEN` | Vault token (for `token` auth). | +| `VAULT_TOKEN_FILE` | Path to a file whose content is used as the token, if it exists. | +| `VAULT_SDB_PROFILE` | Name of the sdb profile that uses the vault driver. Default `vault_sdb`. | + +The entrypoint always sets `master_tries: -1` and `retry_dns: 30`. Extra Salt +configuration can be mounted read-only under `/etc/salt/minion.d/`. If `SALT_MASTER` is +not set, the entrypoint requires `/etc/salt/minion.d/10-master.conf` to be mounted and +exits with status 64 otherwise. ### Smoke test ```bash -docker run --rm \ - salt-minion:local \ - salt-minion --version +docker run --rm --entrypoint salt-minion salt-minion:local --version ``` ```bash docker run --rm \ + --env SALT_MASTER=127.0.0.1 \ --entrypoint /bin/sh \ salt-minion:local \ -c 'salt-call --local test.ping' @@ -247,134 +202,85 @@ docker run --rm \ ## VCF Minion -A specialized Salt Minion image for VMware Cloud Foundation (VCF) deployments. Includes: -- VMware `saltext.vcf` extension (vCenter, NSX, SDDC-M, VCF Ops automation) -- Vault integration for credentials sourcing -- Configurable extensions support -- Full project structure (Dockerfile, Docker Compose, Kubernetes Helm chart) - -The VCF minion is a complete project directory with its own documentation and deployment options. - -### Building VCF Minion - -From the minion/vcf directory: +The VCF image has the same entrypoint, identity and build arguments as the Kubernetes +image. It carries `saltext.vcf` (VMware Cloud Foundation 9.x automation: vCenter, NSX, +SDDC Manager, VCF Operations, and more) and `saltext.bmc` in addition to +`saltext.kubernetes` and `saltext.vault`. ```bash docker build \ - --platform linux/arm64 \ --tag salt-minion-vcf:local \ ./src/minion/vcf ``` -### VCF-Specific Documentation - -See the complete VCF minion documentation: - -- **Helm Chart**: `helm/salt-minion-vcf/README.md` - Kubernetes deployment with StatefulSet -- **Full Project**: `../salt-minion-vcf/README.md` - Docker, Docker Compose, and advanced features +There is no separate VCF chart. Use the `salt-minion` chart and point +`agent.image.repository` and `agent.image.tag` at the VCF image. ## Kubernetes and Helm -Both minion flavors include Helm charts for Kubernetes deployment. - -### Kubernetes Minion Helm Chart - -Located at: `helm/salt-minion` - -Supports two deployment modes: -- **in_cluster** (default): Minion runs as Deployment inside cluster -- **external**: RBAC only for minion running outside cluster +The [`salt-minion` chart](../../helm/salt-minion/README.md) runs either image. It supports +two deployment modes: -Features: -- Declarative minion key management (via Salt Key Operator) -- CIS Kubernetes compliance assessment support -- Optional Vault integration -- PKI persistence across restarts -- Security hardening (non-root, no privilege escalation) +- **in_cluster** (default): the minions run as a StatefulSet inside the cluster. Each pod + is its own minion, with the pod name as the minion ID and its own keypair. +- **external**: RBAC only, for a minion running outside the cluster. ```bash -# Prepare -helm dependency update ./helm/salt-minion - -# Lint -helm lint ./helm/salt-minion - -# Validate -helm template salt-minion \ - ./helm/salt-minion \ +# Lint and render +helm lint ./helm/salt-minion --set agent.saltMasterHost=salt-master.example.com \ + --set agent.minion.allowSelfGeneratedKey=true +helm template salt-minion ./helm/salt-minion \ --set agent.saltMasterHost=salt-master.example.com \ + --set agent.minion.allowSelfGeneratedKey=true \ | kubectl apply --dry-run=client --validate=true -f - # Install -helm upgrade --install salt-minion \ - ./helm/salt-minion \ +helm install salt-minion ./helm/salt-minion \ --namespace salt \ --create-namespace \ - --set agent.saltMasterHost=salt-master.example.com + --set agent.saltMasterHost=salt-master.example.com \ + --set agent.minion.allowSelfGeneratedKey=true ``` -### VCF Minion Helm Chart - -Located at: `helm/salt-minion-vcf` (in separate project directory) - -Features: -- StatefulSet for stable identity -- Persistent PKI storage -- Vault integration -- Pillar Secret support -- Health checks (liveness and readiness probes) - -```bash -helm upgrade --install salt-minion-vcf \ - ./helm/salt-minion-vcf \ - --namespace salt \ - --create-namespace \ - --set salt.master=salt-master.example.com \ - --set persistence.enabled=true -``` +The chart supplies the keys through a Secret and an init container, not through the +`SALT_MINION_*_KEY_B64` variables. It sets `POD_NAME`, so the minion ID is the pod name +unless `agent.minion.id` is set. See the chart README for the key layouts and the +multi-replica model. ## Configuration ### Minion Identity -Minion ID can be set in multiple ways: +The minion ID is chosen in this order: -1. **Environment variable** (highest priority): - ```bash - SALT_MINION_ID=my-minion - ``` - -2. **Pod hostname** (Kubernetes default): - - For Deployment: random pod name - - For StatefulSet: stable ordinal name (e.g., `salt-minion-vcf-0`) - -3. **Explicit values in Helm**: - ```yaml - agent: - minion: - id: my-custom-id - ``` +1. `SALT_MINION_ID`, if set. The chart sets it from `agent.minion.id` (one replica only). +2. `POD_NAME`. The chart sets it from the pod name; in a StatefulSet that is a stable name + such as `salt-minion-0`. +3. The container hostname. ### Key Management -Keys are stored at `/etc/salt/pki/minion/`: +Keys live in `/etc/salt/pki/minion/` (declared as a `VOLUME`): + +- `minion.pem` - private key (mode 0400) +- `minion.pub` - public key (mode 0644) -- `minion.pem` - Private key (mode 0400) -- `minion.pub` - Public key (mode 0644) +#### Self-generated keys (development) -#### Self-Generated Keys (Development) +If no key is supplied and none exists in the directory, Salt generates a keypair when the +minion first starts. Without a volume on `/etc/salt/pki/minion` the key is lost when the +container is removed, and the master sees a new, unaccepted minion each time. ```bash docker run --rm \ --env SALT_MASTER=localhost \ - --env SALT_MINION_PRIVATE_KEY_B64='' \ # Empty = self-generate salt-minion:local ``` -#### Pre-Seeded Keys (Production) +#### Pre-seeded keys ```bash -# Encode existing keypair +# Encode an existing keypair PRIVATE_KEY=$(base64 -w0 < /path/to/minion.pem) PUBLIC_KEY=$(base64 -w0 < /path/to/minion.pub) @@ -385,9 +291,12 @@ docker run --rm \ salt-minion:local ``` +On macOS `base64` has no `-w0`; use `base64 -i ` (it does not wrap lines). + ### Multi-Master Setup -Connect to multiple masters simultaneously (Salt native multi-master mode): +Connect to several independent masters simultaneously (Salt's native multi-master mode, +not failover): ```bash docker run --rm \ @@ -395,12 +304,12 @@ docker run --rm \ salt-minion:local ``` -The comma-separated list becomes a YAML list in minion configuration. +The comma-separated list becomes a YAML list in the minion configuration. Every master +has to accept the minion key. For a Salt master cluster, give the minion the single +address of the cluster instead. ### Vault Integration -Enable Vault for secure credential sourcing: - ```bash docker run --rm \ --env SALT_MASTER=salt-master.example.com \ @@ -412,7 +321,7 @@ docker run --rm \ salt-minion:local ``` -Or in Helm: +Or in Helm values: ```yaml agent: @@ -420,12 +329,13 @@ agent: addr: https://vault.example.com:8200 authMethod: approle roleId: my-role-id - secretIdFile: /var/run/secrets/vault/secret_id + secretId: my-secret-id ``` ### FIPS Compliance -FIPS mode is enabled by default. Disable only if master isn't FIPS-enforced: +FIPS mode is enabled by default (`fips_mode: True`, `OAEP-SHA224` encryption and +`PKCS1v15-SHA224` signing). Disable it only if the master is not FIPS-enforced: ```bash docker run --rm \ @@ -434,73 +344,41 @@ docker run --rm \ salt-minion:local ``` +The Helm chart has no value for this, so chart-deployed minions always run with the +default. + ## Security Design -The images apply the following security controls: +- The Salt Minion runs as non-root UID/GID `10001` (numeric `USER`, so Kubernetes' + `runAsNonRoot` can verify it) +- The `salt` user has no login shell and no created home directory +- The directories the minion writes to (`/etc/salt`, `/var/cache/salt`, `/var/log/salt`) + are owned by that user +- The extra build CA, if used, is not retained in the final image +- Minion keys are never accepted automatically by the image; acceptance happens on the + master +- Pre-seeded keys support a declarative trust model -- Salt Minion runs as non-root UID/GID `10000` -- No privilege escalation allowed -- All Linux capabilities dropped -- Private keys stored with mode `0400` -- Public keys stored with mode `0644` -- Corporate CA (if used) not retained in final image -- Kubernetes Secret sources remain read-only -- Automatic minion acceptance disabled by default -- Pre-seeded keys support declarative trust model +The chart adds no privilege escalation, drops all Linux capabilities, mounts the key +Secret read-only with mode `0440` and sets `fsGroup: 10001`. ## Health Checks -### Docker Health Check - -The image includes a Docker health check: - -```dockerfile -HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \ - CMD salt-call --local test.ping >/dev/null 2>&1 -``` - -### Kubernetes Health Probes - -Helm charts include: +The images define no Docker `HEALTHCHECK`. The Helm chart gives the minion container two +exec probes that run `salt-call --local test.ping`: -**Liveness Probe** - Verifies minion process is responsive -- Initial delay: 30s (kubernetes), 20s (VCF) -- Period: 60s (kubernetes), 30s (VCF) -- Timeout: 10s -- Failure threshold: 3 +| Probe | Initial delay | Period | Timeout | Failure threshold | +| --- | --- | --- | --- | --- | +| Liveness | 30s | 60s | 10s | 3 | +| Readiness | 15s | 30s | 10s | 3 | -**Readiness Probe** - Verifies minion is ready for commands -- Initial delay: 15s (kubernetes), 10s (VCF) -- Period: 30s -- Timeout: 10s -- Failure threshold: 3 - -Both use: `salt-call --local test.ping` - -## Validation Performed - -The following validations were completed: - -- Helm linting for both charts -- Kubernetes client-side validation of rendered templates -- ARM64 builds of both images -- Salt version verification -- Non-root UID/GID verification -- Directory ownership verification -- Build-time CA removal verification -- Docker health check validation -- In-cluster minion deployment and connectivity -- StatefulSet persistent identity verification -- Multi-master minion connectivity -- Key persistence across pod restarts -- Kubernetes API communication (saltext.kubernetes) -- Vault integration (saltext.vault) +The command checks the local minion installation, not the master connection. ## Related Documentation - [Salt Minion Helm Chart](../../helm/salt-minion/README.md) - Kubernetes deployment details -- [VCF Minion Project](../../../salt-minion-vcf/) - Complete VCF minion documentation -- [Complete System Test Guide](../../docs/complete-system-test.md) - Integration testing procedures +- [Building images](../../docs/building.md) - build arguments and publishing +- [Complete System Test Guide](../../docs/complete-system-test.md) - integration testing procedures - [Salt Project Documentation](https://docs.saltproject.io/) - Salt configuration and modules ## Troubleshooting @@ -528,25 +406,30 @@ docker run --rm \ View minion logs: ```bash -docker logs salt-minion-container-name +docker logs salt-minion ``` -### Health check failing +### `salt-minion: not found` or the wrong Salt version -Test manually: +An image built before the extension-constraint fix could have its onedir Salt replaced +by a pip-installed `salt`, which removes the `salt-minion` launcher. Rebuild with the +current Dockerfile. `salt-pip list` in the image should show a single `salt`. -```bash -docker exec salt-minion-container-name \ - salt-call --local test.ping -``` +### Entrypoint exits with "Salt Master configuration is missing" + +Set `SALT_MASTER`, or mount `/etc/salt/minion.d/10-master.conf`. + +### Cannot write keys or cache with a mounted volume + +The container user is `10001:10001`. A volume mounted on `/etc/salt/pki/minion` or +`/var/cache/salt/minion` has to be writable by that user (in Kubernetes, `fsGroup: 10001`). ### FIPS mode issues -If master is not FIPS-enforced, disable FIPS: +If the master is not FIPS-enforced, disable FIPS: ```bash --env SALT_FIPS_MODE=false ``` -Default algorithms: `OAEP-SHA224` and `PKCS1v15-SHA224` - +Default algorithms: `OAEP-SHA224` and `PKCS1v15-SHA224`. diff --git a/src/minion/kubernetes/salt-extensions.txt b/src/minion/kubernetes/salt-extensions.txt index 3207aae..032c634 100644 --- a/src/minion/kubernetes/salt-extensions.txt +++ b/src/minion/kubernetes/salt-extensions.txt @@ -1,14 +1,16 @@ -# Salt extension packages installed into the Salt onedir Python environment. -# Add/remove/pin any pip-installable Salt extension here - see -# salt-minion-vcf/salt-extensions.txt for the sibling minion image's set. +# Salt extension packages installed into the Salt onedir Python environment +# when the image is built (src/minion/kubernetes/Dockerfile). +# Add/remove/pin any pip-installable Salt extension here. Salt itself is +# constrained to the installed onedir version during this step, so an extension's +# "salt" requirement never replaces it. See ../vcf/salt-extensions.txt for the +# VCF image's set. -# Kubernetes execution/state modules and cluster-API access, used by the -# kube-bench compliance Jobs this chart drives. +# Kubernetes execution/state modules and cluster-API access, used for +# kube-bench based compliance assessments. # Source: https://github.com/salt-extensions/saltext-kubernetes saltext.kubernetes==2.1.0 # Vault integration (ext_pillar, sdb driver, execution modules) - lets -# kube-bench pillar values (or anything else) reference sdb://vault_sdb/... -# instead of plaintext. +# pillar values reference sdb://vault_sdb/... instead of plaintext. # Source: https://github.com/salt-extensions/saltext-vault saltext.vault==1.8.0 diff --git a/src/minion/vcf/salt-extensions.txt b/src/minion/vcf/salt-extensions.txt index 6824383..9165c87 100644 --- a/src/minion/vcf/salt-extensions.txt +++ b/src/minion/vcf/salt-extensions.txt @@ -1,15 +1,17 @@ -# Salt extension packages installed into the Salt onedir Python environment. -# Add/remove/pin any pip-installable Salt extension here - see -# salt-minion-vcf/salt-extensions.txt for the sibling minion image's set. +# Salt extension packages installed into the Salt onedir Python environment +# when the image is built (src/minion/vcf/Dockerfile). +# Add/remove/pin any pip-installable Salt extension here. Salt itself is +# constrained to the installed onedir version during this step, so an extension's +# "salt" requirement never replaces it. See ../kubernetes/salt-extensions.txt for the +# Kubernetes image's set. -# Kubernetes execution/state modules and cluster-API access, used by the -# kube-bench compliance Jobs this chart drives. +# Kubernetes execution/state modules and cluster-API access, used for +# kube-bench based compliance assessments. # Source: https://github.com/salt-extensions/saltext-kubernetes saltext.kubernetes==2.1.0 # Vault integration (ext_pillar, sdb driver, execution modules) - lets -# kube-bench pillar values (or anything else) reference sdb://vault_sdb/... -# instead of plaintext. +# pillar values reference sdb://vault_sdb/... instead of plaintext. # Source: https://github.com/salt-extensions/saltext-vault saltext.vault==1.8.0 diff --git a/src/salt-key-operator/CHANGELOG.md b/src/salt-key-operator/CHANGELOG.md index 960e625..9f86c47 100644 --- a/src/salt-key-operator/CHANGELOG.md +++ b/src/salt-key-operator/CHANGELOG.md @@ -1,11 +1,12 @@ # Changelog (salt-key-operator image) -Records what each `salt-key-operator-image/vX.Y.Z` release tag (see -[`docs/releasing.md`](../docs/releasing.md)) actually carries. +Records what each image release carries. The release tag is +`salt-key-operator-vX.Y.Z` (see [`docs/releasing.md`](../../docs/releasing.md)); +headings below use the older `salt-key-operator-image/vX.Y.Z` naming. ## salt-key-operator-image/v0.1.0 - Initial release: `SaltMinionKey` (`salt.saltstack.io/v1alpha1`) controller, - reconciling into a target `salt-master-kubernetes` release's + reconciling into a target `salt-master` release's trusted-minions ConfigMap. Deliberately minimal CRD (just `minionId` + inline `publicKey` - no Secret reference, no explicit target reference; the controller auto-discovers the one trusted-minions ConfigMap in its diff --git a/src/salt-key-operator/README.md b/src/salt-key-operator/README.md index 026d504..73133ec 100644 --- a/src/salt-key-operator/README.md +++ b/src/salt-key-operator/README.md @@ -3,13 +3,14 @@ A small Kubernetes operator (controller-runtime/kubebuilder-style, Go) that reconciles a `SaltMinionKey` custom resource - the declarative replacement for running `salt-key -a ` by hand against a -`salt-master-kubernetes` pod. +`salt-master` pod. ## Why this exists -`salt-master-kubernetes` (see `../salt-master-kubernetes/README.md`) supports -running multiple master replicas that all share one keypair, using Salt's -own [multi-master mode](https://docs.saltproject.io/en/3006/topics/tutorials/multimaster.html). +`salt-master` (see `../../helm/salt-master/README.md`) supports +running multiple master replicas, either as classic multi-master (all replicas +share one keypair) or as a Salt master cluster, and runs as a StatefulSet. Classic +multi-master uses Salt's own [multi-master mode](https://docs.saltproject.io/en/3006/topics/tutorials/multimaster.html). That doc explicitly calls out a gap vanilla Salt multi-master doesn't solve: > Keys accepted, deleted, or rejected on one master will NOT be @@ -21,19 +22,37 @@ steps that all have to stay in sync by hand. `salt-key-operator` replaces that entirely: creating one `SaltMinionKey` object gets a minion trusted by **every** replica of the target master release, consistently. +## Relationship to the charts + +- The `salt-master` chart declares this chart as a dependency + (`helm/salt-master/Chart.yaml`, condition `agent.trustedMinions.enabled`, default + `true`). A normal master install therefore already installs the operator into the + release namespace; do not install `helm/salt-key-operator` a second time in the + same namespace. Override the subchart with the `salt-key-operator.*` prefix, for + example `--set salt-key-operator.image.repository=...`. Install the chart on its + own only for a master release that is not managed by that chart. +- With `agent.trustedMinions.enabled=true` the master's sidecar removes any key in + Salt's `minions` directory that is not in the ConfigMap, so keys accepted with + `salt-key -a` do not persist. Use one mode or the other. In master cluster mode + the keys are written into the cluster PKI directory. +- The `salt-minion` chart runs a StatefulSet in which every pod is its own minion + (ID = pod name) with its own keypair. Create one `SaltMinionKey` per pod, using + that pod's public key: with `agent.replicas: 1` it is `minion.pub` in Secret + `-keys`, with more replicas `.pub` in the same Secret. + ## How it works 1. You create a `SaltMinionKey` with just two fields: the minion ID and its public key, inline (PEM, plain text - a minion's public key isn't sensitive, so there's no separate Secret to create first). There's also no need to say *which* master release to trust it with - the controller - finds the one `salt-master-kubernetes` release installed in the + finds the one `salt-master` release installed in the `SaltMinionKey`'s own namespace automatically (see "Design notes" below for what happens if that's ambiguous). 2. The controller writes `data[] = ` into that - release's trusted-minions ConfigMap (see `salt-master-kubernetes`'s + release's trusted-minions ConfigMap (see the `salt-master` chart's `agent.trustedMinions.*` values). -3. `salt-master-kubernetes` runs a `trusted-minions-sync` sidecar in every +3. `salt-master` runs a `trusted-minions-sync` sidecar in every replica that continuously copies that ConfigMap into the directory Salt actually reads (`/etc/salt/pki/master/minions`) - **not** a direct ConfigMap volume mount. Kubernetes always mounts ConfigMap volumes as @@ -58,7 +77,7 @@ that entirely: creating one `SaltMinionKey` object gets a minion trusted by indirection. And rather than making every `SaltMinionKey` name which master ConfigMap to target, the controller discovers the one `trustedMinionsLabel`-marked ConfigMap in its own namespace - matching - this repo's convention of one `salt-master-kubernetes` release per + this repo's convention of one `salt-master` release per dedicated namespace (e.g. `salt-master`). Running more than one master release in the same namespace isn't supported by this auto-discovery (the controller returns an error - `NoMasterConfigMap` if none, an @@ -66,9 +85,9 @@ that entirely: creating one `SaltMinionKey` object gets a minion trusted by - **No exec-into-pod from the operator, no volume shared *across* replicas.** The operator itself only ever writes to one ConfigMap - it never touches a master pod directly. Making that ConfigMap's content - actually usable by Salt is `salt-master-kubernetes`'s own problem, solved + actually usable by Salt is `salt-master`'s own problem, solved there with a per-pod `trusted-minions-sync` sidecar and a per-pod - `emptyDir` (see that chart's `templates/statefulset.yaml`) - not shared + `emptyDir` (see `helm/salt-master/templates/statefulset.yaml`) - not shared between replicas, just between the two containers of the same pod. - **Propagation latency is bounded by kubelet's ConfigMap resync period** (on the order of a minute) plus the sync sidecar's own poll interval on @@ -93,7 +112,7 @@ that entirely: creating one `SaltMinionKey` object gets a minion trusted by to the repo** - nothing else here touches ConfigMaps or a custom API group (and, per the point above, this design needs no Secret access at all). The chart defaults `watchNamespace: salt-master` - matching - `salt-master-kubernetes`'s own default namespace - which scopes RBAC down + `salt-master`'s own default namespace - which scopes RBAC down to a namespaced `Role`/`RoleBinding` in just that namespace, not a cluster-wide `ClusterRole`. Set `watchNamespace: ""` only for a genuine multi-tenant cluster with target master releases spread across multiple @@ -110,6 +129,8 @@ that entirely: creating one `SaltMinionKey` object gets a minion trusted by ## Development +Run these from `src/salt-key-operator`: + ```bash go build ./... go vet ./... @@ -123,11 +144,11 @@ go install sigs.k8s.io/controller-tools/cmd/controller-gen@latest controller-gen object:headerFile="" paths="./api/..." controller-gen crd paths="./api/..." output:crd:artifacts:config=config/crd/bases controller-gen rbac:roleName=salt-key-operator paths="./..." output:rbac:artifacts:config=config/rbac -cp config/crd/bases/*.yaml helm/salt-key-operator/crds/ +cp config/crd/bases/*.yaml ../../helm/salt-key-operator/crds/ ``` `config/rbac/role.yaml`'s `rules:` also has to be copied by hand into -`helm/salt-key-operator/templates/rbac.yaml` (both the `Role` and +`../../helm/salt-key-operator/templates/rbac.yaml` (both the `Role` and `ClusterRole` branches) - see the comment at the top of that template. Note `api/v1alpha1/saltminionkeystatus_deepcopy.go`: `controller-gen` @@ -146,7 +167,7 @@ for anything under a chart's `crds/` directory) - to pick up a CRD schema change on an existing install, apply it directly: ```bash -kubectl apply -f helm/salt-key-operator/crds/ +kubectl apply -f helm/salt-key-operator/crds/ # from the repository root ``` ## CRD reference @@ -158,7 +179,7 @@ metadata: name: # object name - can differ from spec.minionId, namespace: # which is unconstrained by RFC 1123 (may be an FQDN, etc.) # - and must be the same namespace as the target - # salt-master-kubernetes release + # salt-master release spec: minionId: publicKey: | From e562ef6063e91f0f6ac702046def160ea6860089 Mon Sep 17 00:00:00 2001 From: Saifuddin Rangwala Date: Wed, 25 Nov 2026 21:25:58 +0530 Subject: [PATCH 05/10] docs: point Salt documentation links at the 3008 docs The multi-master links targeted /en/3006/ and the master-cluster links /en/latest/. The images and charts are pinned to Salt 3008.5, so link to /en/3008/ (both pages exist there). Also updates the comments in the entrypoint scripts. Co-Authored-By: Claude Sonnet 5.5 --- helm/salt-master/README.md | 4 ++-- helm/salt-master/templates/service-headless.yaml | 2 +- helm/salt-master/values.yaml | 4 ++-- helm/salt-minion/CHANGELOG.md | 2 +- helm/salt-minion/scripts/docker-entrypoint.sh | 2 +- helm/salt-minion/values.yaml | 2 +- src/master/README.md | 2 +- src/master/entrypoint.sh | 2 +- src/minion/kubernetes/entrypoint.sh | 2 +- src/minion/vcf/entrypoint.sh | 2 +- src/salt-key-operator/README.md | 2 +- 11 files changed, 13 insertions(+), 13 deletions(-) diff --git a/helm/salt-master/README.md b/helm/salt-master/README.md index bbf8b9d..c590ba9 100644 --- a/helm/salt-master/README.md +++ b/helm/salt-master/README.md @@ -4,10 +4,10 @@ Installs a Salt master as a Kubernetes `StatefulSet` (`salt-master`, pods `salt-master-0` .. `salt-master-N-1`). It runs in one of two modes: - **Classic** (default, `agent.cluster.enabled=false`): one master, or Salt's - native [multi-master mode](https://docs.saltproject.io/en/3006/topics/tutorials/multimaster.html) + native [multi-master mode](https://docs.saltproject.io/en/3008/topics/tutorials/multimaster.html) with several independent masters that share one pre-supplied keypair. - **Master cluster** (`agent.cluster.enabled=true`, opt-in): Salt's - [master cluster](https://docs.saltproject.io/en/latest/topics/tutorials/master-cluster.html), + [master cluster](https://docs.saltproject.io/en/3008/topics/tutorials/master-cluster.html), where the masters present one identity to minions. **Read the known limitation below before using it.** diff --git a/helm/salt-master/templates/service-headless.yaml b/helm/salt-master/templates/service-headless.yaml index 56160f1..582a5a5 100644 --- a/helm/salt-master/templates/service-headless.yaml +++ b/helm/salt-master/templates/service-headless.yaml @@ -4,7 +4,7 @@ # This is what lets an in-cluster minion's multi-master `master:` config list # address every master replica individually rather than being randomly # load-balanced across them by a normal Service - see -# https://docs.saltproject.io/en/3006/topics/tutorials/multimaster.html. +# https://docs.saltproject.io/en/3008/topics/tutorials/multimaster.html. # In cluster mode it also carries the cluster-pool port, and the entrypoint # resolves these names to the peer pod IPs. apiVersion: v1 diff --git a/helm/salt-master/values.yaml b/helm/salt-master/values.yaml index dc1df71..4f12b60 100644 --- a/helm/salt-master/values.yaml +++ b/helm/salt-master/values.yaml @@ -42,7 +42,7 @@ agent: # minion endpoint - any replica can serve any minion, and jobs/events are # routed between peers. Each master keeps its OWN master keypair; the # cluster-wide keypair and the accepted minion keys live in cluster_pki_dir. - # See https://docs.saltproject.io/en/latest/topics/tutorials/master-cluster.html + # See https://docs.saltproject.io/en/3008/topics/tutorials/master-cluster.html # # When enabled: needs replicas >= 2 (the chart fails below that: Salt # refuses a member with no peers); use 3 or more to tolerate a failure. @@ -168,7 +168,7 @@ agent: # --from-file=master.pem --from-file=master.pub # REQUIRED when replicas > 1 (every pod must present the identical # keypair, matching Salt's own multi-master convention - see - # https://docs.saltproject.io/en/3006/topics/tutorials/multimaster.html, + # https://docs.saltproject.io/en/3008/topics/tutorials/multimaster.html, # "masters share the same private key") - the chart fails to render # otherwise. The Secret is mounted 0440 and copied by the prepare-master-keys # init container into a writable emptyDir. diff --git a/helm/salt-minion/CHANGELOG.md b/helm/salt-minion/CHANGELOG.md index 3ce8219..139742c 100644 --- a/helm/salt-minion/CHANGELOG.md +++ b/helm/salt-minion/CHANGELOG.md @@ -96,7 +96,7 @@ Applies to both `src/minion/kubernetes` and `src/minion/vcf`. there, but a self-generated key now needs that explicit opt-out too, not just an empty `keySecretName`. - `agent.saltMasterHost` now also accepts a YAML list, for Salt's native - [multi-master mode](https://docs.saltproject.io/en/3006/topics/tutorials/multimaster.html) - + [multi-master mode](https://docs.saltproject.io/en/3008/topics/tutorials/multimaster.html) - point it at every replica address of an active-active `salt-master-kubernetes` release instead of a single master. - Default image: `salt-minion:0.1.1` (see "Image releases" above for what that diff --git a/helm/salt-minion/scripts/docker-entrypoint.sh b/helm/salt-minion/scripts/docker-entrypoint.sh index 87e48af..294d17c 100755 --- a/helm/salt-minion/scripts/docker-entrypoint.sh +++ b/helm/salt-minion/scripts/docker-entrypoint.sh @@ -45,7 +45,7 @@ if [ -n "${SALT_MASTER:-}" ]; then # A comma-separated SALT_MASTER (e.g. "master-0,master-1,master-2") # renders as a YAML list instead of a scalar - Salt's native multi-master - # mode (https://docs.saltproject.io/en/3006/topics/tutorials/multimaster.html): + # mode (https://docs.saltproject.io/en/3008/topics/tutorials/multimaster.html): # one independent, simultaneous connection per address, not failover. case "${SALT_MASTER}" in *,*) diff --git a/helm/salt-minion/values.yaml b/helm/salt-minion/values.yaml index 277032b..d04c864 100644 --- a/helm/salt-minion/values.yaml +++ b/helm/salt-minion/values.yaml @@ -48,7 +48,7 @@ agent: replicas: 1 # Salt master address. Required when authMode=in_cluster. Also accepts a # list, for Salt's native multi-master mode - # (https://docs.saltproject.io/en/3006/topics/tutorials/multimaster.html) - + # (https://docs.saltproject.io/en/3008/topics/tutorials/multimaster.html) - # one independent, simultaneous connection per address, not failover, and # every listed master has to accept every minion key. Use it for independent # masters, e.g. the classic multi-master mode of the salt-master chart diff --git a/src/master/README.md b/src/master/README.md index ad66072..88a13ae 100644 --- a/src/master/README.md +++ b/src/master/README.md @@ -205,7 +205,7 @@ a non-root master cannot create directories under `/var/run`. Cluster mode (Salt 3007+; `SALT_CLUSTER_ISOLATED_FILESYSTEM` needs Salt 3008+) is enabled by setting `SALT_CLUSTER_ID`. The entrypoint then writes `/etc/salt/master.d/98-cluster.conf` (mode `0600`) and creates the cluster PKI directory. See the -[Salt master cluster tutorial](https://docs.saltproject.io/en/latest/topics/tutorials/master-cluster.html). +[Salt master cluster tutorial](https://docs.saltproject.io/en/3008/topics/tutorials/master-cluster.html). | Variable | Effect | | --- | --- | diff --git a/src/master/entrypoint.sh b/src/master/entrypoint.sh index 55232f5..1ca9eb3 100644 --- a/src/master/entrypoint.sh +++ b/src/master/entrypoint.sh @@ -44,7 +44,7 @@ fi # Optional: Salt master cluster mode (Salt 3007+; isolated filesystem mode # needs 3008+). Enabled by setting SALT_CLUSTER_ID. See -# https://docs.saltproject.io/en/latest/topics/tutorials/master-cluster.html +# https://docs.saltproject.io/en/3008/topics/tutorials/master-cluster.html # # SALT_CLUSTER_ID cluster_id # SALT_CLUSTER_NODE_ADDRESS this master's own IP, written as `interface:`. diff --git a/src/minion/kubernetes/entrypoint.sh b/src/minion/kubernetes/entrypoint.sh index 8dfabd0..ab09493 100755 --- a/src/minion/kubernetes/entrypoint.sh +++ b/src/minion/kubernetes/entrypoint.sh @@ -45,7 +45,7 @@ if [ -n "${SALT_MASTER:-}" ]; then # A comma-separated SALT_MASTER (e.g. "master-0,master-1,master-2") # renders as a YAML list instead of a scalar - Salt's native multi-master - # mode (https://docs.saltproject.io/en/3006/topics/tutorials/multimaster.html): + # mode (https://docs.saltproject.io/en/3008/topics/tutorials/multimaster.html): # one independent, simultaneous connection per address, not failover. case "${SALT_MASTER}" in *,*) diff --git a/src/minion/vcf/entrypoint.sh b/src/minion/vcf/entrypoint.sh index 8dfabd0..ab09493 100755 --- a/src/minion/vcf/entrypoint.sh +++ b/src/minion/vcf/entrypoint.sh @@ -45,7 +45,7 @@ if [ -n "${SALT_MASTER:-}" ]; then # A comma-separated SALT_MASTER (e.g. "master-0,master-1,master-2") # renders as a YAML list instead of a scalar - Salt's native multi-master - # mode (https://docs.saltproject.io/en/3006/topics/tutorials/multimaster.html): + # mode (https://docs.saltproject.io/en/3008/topics/tutorials/multimaster.html): # one independent, simultaneous connection per address, not failover. case "${SALT_MASTER}" in *,*) diff --git a/src/salt-key-operator/README.md b/src/salt-key-operator/README.md index 73133ec..6b995eb 100644 --- a/src/salt-key-operator/README.md +++ b/src/salt-key-operator/README.md @@ -10,7 +10,7 @@ for running `salt-key -a ` by hand against a `salt-master` (see `../../helm/salt-master/README.md`) supports running multiple master replicas, either as classic multi-master (all replicas share one keypair) or as a Salt master cluster, and runs as a StatefulSet. Classic -multi-master uses Salt's own [multi-master mode](https://docs.saltproject.io/en/3006/topics/tutorials/multimaster.html). +multi-master uses Salt's own [multi-master mode](https://docs.saltproject.io/en/3008/topics/tutorials/multimaster.html). That doc explicitly calls out a gap vanilla Salt multi-master doesn't solve: > Keys accepted, deleted, or rejected on one master will NOT be From 3a0ca0d8e84312e3c18da7b5d62235a225e9172d Mon Sep 17 00:00:00 2001 From: Saifuddin Rangwala Date: Thu, 26 Nov 2026 09:49:30 +0530 Subject: [PATCH 06/10] Fix release workflow, chart and script problems found in the docs review Release workflows - Kubernetes minion image: trigger on salt-minion-kubernetes-v* (what scripts/release-docker-tags.sh pushes). The old glob salt-minion-v* never matched that tag, so no Kubernetes minion image was published, and it also matched salt-minion-vcf-v* tags. - Key operator chart: version was injected into helm/salt-minion/Chart.yaml instead of its own chart. - Minion and key operator charts: push to oci://ghcr.io//helm, not //helm. - Chart workflows: strip the tag prefix that actually triggers them. Charts - Default image repositories for the minion and key operator charts pointed at ghcr.io/saltstack/salt-kubernetes/..., which does not exist; use ghcr.io/saltstack/, where the workflows publish. - salt-master: add agent.image.imagePullSecrets and a keygen block (image, pull policy, pull secrets, restricted security contexts); the keygen image was hardcoded and the Job had no security context. - salt-minion: keygen Job runs with a restricted security context; remove agent.minion.grains and masterId and the unmounted minion-config ConfigMap (no effect); remove the unused scripts/ and salt-extensions.txt; Chart.yaml describes a StatefulSet. Images and scripts - Remove the unused SALT_GPG_KEY_URL and SALT_APT_REPO_URL build args and fix comments that named the old chart and file paths. - e2e script: no internal CA, mirror or IP; configurable by environment variables. - scripts/ci.sh: fix stale paths and re-enable the chart template checks, including configurations the charts must reject. Docs and changelogs updated to match. Checked on a real cluster: both keygen Jobs complete under the restricted security context and create their Secrets. Co-Authored-By: Claude Sonnet 5.5 --- .../workflows/release-docker-minion-k8s.yml | 4 +- .../workflows/release-helm-key-operator.yml | 10 +- .github/workflows/release-helm-master.yml | 2 +- .github/workflows/release-helm-minion.yml | 4 +- README.md | 4 +- docs/building.md | 5 +- docs/complete-system-test.md | 4 +- docs/kubernetes-compliance-guide.md | 2 +- docs/releasing.md | 43 ++--- helm/salt-key-operator/CHANGELOG.md | 5 + helm/salt-key-operator/values.yaml | 2 +- helm/salt-master/CHANGELOG.md | 6 + helm/salt-master/README.md | 9 + .../templates/master-keygen-job.yaml | 11 +- helm/salt-master/templates/statefulset.yaml | 4 + helm/salt-master/values.yaml | 27 ++- helm/salt-minion/CHANGELOG.md | 15 ++ helm/salt-minion/Chart.yaml | 3 +- helm/salt-minion/README.md | 9 +- helm/salt-minion/salt-extensions.txt | 14 -- helm/salt-minion/scripts/docker-entrypoint.sh | 178 ------------------ helm/salt-minion/scripts/healthcheck.sh | 8 - helm/salt-minion/templates/keygen-job.yaml | 4 + helm/salt-minion/templates/minion-config.yaml | 10 - helm/salt-minion/tests/images_test.yaml | 8 +- helm/salt-minion/tests/keygen_job_test.yaml | 17 ++ helm/salt-minion/values.yaml | 21 ++- scripts/ci.sh | 73 ++++--- scripts/salt-kubernetes-e2e-local-test.sh | 76 +++++--- src/master/entrypoint.sh | 2 +- src/minion/README.md | 1 - src/minion/kubernetes/Dockerfile | 4 +- src/minion/kubernetes/entrypoint.sh | 6 +- src/minion/vcf/Dockerfile | 19 +- src/minion/vcf/entrypoint.sh | 6 +- 35 files changed, 266 insertions(+), 350 deletions(-) delete mode 100644 helm/salt-minion/salt-extensions.txt delete mode 100755 helm/salt-minion/scripts/docker-entrypoint.sh delete mode 100755 helm/salt-minion/scripts/healthcheck.sh delete mode 100644 helm/salt-minion/templates/minion-config.yaml diff --git a/.github/workflows/release-docker-minion-k8s.yml b/.github/workflows/release-docker-minion-k8s.yml index e79bc95..a4c7d33 100644 --- a/.github/workflows/release-docker-minion-k8s.yml +++ b/.github/workflows/release-docker-minion-k8s.yml @@ -3,7 +3,7 @@ name: Release Docker - Salt Minion K8s on: push: tags: - - 'salt-minion-v*' + - 'salt-minion-kubernetes-v*' schedule: - cron: '0 3 * * 1' # Every Monday at 3:00 AM UTC workflow_dispatch: @@ -30,7 +30,7 @@ jobs: run: | if [[ "${{ github.ref }}" == refs/tags/* ]]; then TAG_NAME=${GITHUB_REF#refs/tags/} - VERSION=${TAG_NAME#salt-minion-v} + VERSION=${TAG_NAME#salt-minion-kubernetes-v} echo "is_tag=true" >> $GITHUB_OUTPUT else VERSION="latest" diff --git a/.github/workflows/release-helm-key-operator.yml b/.github/workflows/release-helm-key-operator.yml index 4e39334..a3d9989 100644 --- a/.github/workflows/release-helm-key-operator.yml +++ b/.github/workflows/release-helm-key-operator.yml @@ -29,7 +29,7 @@ jobs: run: | if [[ "${{ github.ref }}" == refs/tags/* ]]; then TAG_NAME=${GITHUB_REF#refs/tags/} - VERSION=${TAG_NAME#chart-operator-v} + VERSION=${TAG_NAME#chart-salt-key-operator-v} echo "is_tag=true" >> $GITHUB_OUTPUT else VERSION="0.0.0-snapshot" @@ -50,8 +50,8 @@ jobs: # Ensure ONLY the clean numeric semver (e.g., 0.1.0) is injected CLEAN_VERSION=$(echo "${{ steps.vars.outputs.version }}" | sed -E 's/.*-v?([0-9]+\.[0-9]+\.[0-9]+.*)/\1/') - sed -i "s/^version:.*/version: ${CLEAN_VERSION}/g" helm/salt-minion/Chart.yaml - sed -i "s/^appVersion:.*/appVersion: \"${CLEAN_VERSION}\"/g" helm/salt-minion/Chart.yaml + sed -i "s/^version:.*/version: ${CLEAN_VERSION}/g" helm/salt-key-operator/Chart.yaml + sed -i "s/^appVersion:.*/appVersion: \"${CLEAN_VERSION}\"/g" helm/salt-key-operator/Chart.yaml echo "CLEAN_VERSION=${CLEAN_VERSION}" >> $GITHUB_ENV @@ -61,7 +61,7 @@ jobs: - name: Push Helm Chart OCI Artifact to GHCR run: | - helm push .dist/salt-key-operator-${{env.CLEAN_VERSION}}.tgz oci://ghcr.io/${{ steps.vars.outputs.registry_owner }}//helm + helm push .dist/salt-key-operator-${{env.CLEAN_VERSION}}.tgz oci://ghcr.io/${{ steps.vars.outputs.registry_owner }}/helm - name: Create GitHub Release if: steps.vars.outputs.is_tag == 'true' @@ -73,7 +73,7 @@ jobs: Automated Helm Chart release for **Salt Key Operator**. Install with: ```bash - helm pull oci://ghcr.io/${{ steps.vars.outputs.registry_owner }}//helm/salt-key-operator --version ${{env.CLEAN_VERSION}} + helm pull oci://ghcr.io/${{ steps.vars.outputs.registry_owner }}/helm/salt-key-operator --version ${{env.CLEAN_VERSION}} ``` draft: false prerelease: false diff --git a/.github/workflows/release-helm-master.yml b/.github/workflows/release-helm-master.yml index f1c6525..6660c75 100644 --- a/.github/workflows/release-helm-master.yml +++ b/.github/workflows/release-helm-master.yml @@ -29,7 +29,7 @@ jobs: run: | if [[ "${{ github.ref }}" == refs/tags/* ]]; then TAG_NAME=${GITHUB_REF#refs/tags/} - VERSION=${TAG_NAME#chart-master-v} + VERSION=${TAG_NAME#chart-salt-master-v} echo "is_tag=true" >> $GITHUB_OUTPUT else VERSION="0.0.0-snapshot" diff --git a/.github/workflows/release-helm-minion.yml b/.github/workflows/release-helm-minion.yml index 4923dc0..f591be6 100644 --- a/.github/workflows/release-helm-minion.yml +++ b/.github/workflows/release-helm-minion.yml @@ -29,7 +29,7 @@ jobs: run: | if [[ "${{ github.ref }}" == refs/tags/* ]]; then TAG_NAME=${GITHUB_REF#refs/tags/} - VERSION=${TAG_NAME#chart-minion-v} + VERSION=${TAG_NAME#chart-salt-minion-v} echo "is_tag=true" >> $GITHUB_OUTPUT else VERSION="0.0.0-snapshot" @@ -60,7 +60,7 @@ jobs: - name: Push Helm Chart OCI Artifact to GHCR run: | - helm push .dist/salt-minion-${{env.CLEAN_VERSION}}.tgz oci://ghcr.io/${{ steps.vars.outputs.registry_owner }}//helm + helm push .dist/salt-minion-${{env.CLEAN_VERSION}}.tgz oci://ghcr.io/${{ steps.vars.outputs.registry_owner }}/helm - name: Create GitHub Release if: steps.vars.outputs.is_tag == 'true' diff --git a/README.md b/README.md index 9c8db35..c52995e 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ docker build -t salt-minion:0.1.0 src/minion/kubernetes docker build -t salt-key-operator:0.1.0 src/salt-key-operator # Master (also installs the salt-key-operator subchart; the operator image -# defaults to ghcr.io/saltstack/salt-kubernetes/salt-key-operator:0.1.0, override +# defaults to ghcr.io/saltstack/salt-key-operator:0.1.0, override # with --set salt-key-operator.image.repository=... if you built your own) helm dependency update helm/salt-master helm install salt-master helm/salt-master \ @@ -105,7 +105,7 @@ helm install salt-minion helm/salt-minion \ ``` The minion chart's default image is -`ghcr.io/saltstack/salt-kubernetes/salt-minion:0.1.0`; set +`ghcr.io/saltstack/salt-minion:0.1.0`; set `agent.image.repository`/`agent.image.tag` to use the image you built. The master chart's default is the unqualified `salt-master:3008.5`. diff --git a/docs/building.md b/docs/building.md index 438f456..28c7ea2 100644 --- a/docs/building.md +++ b/docs/building.md @@ -22,8 +22,8 @@ docker build -t salt-key-operator:0.1.0 src/salt-key-operator ``` Image names and tags are your choice. The chart defaults are -`salt-master:3008.5` (master), `ghcr.io/saltstack/salt-kubernetes/salt-minion:0.1.0` -(minion) and `ghcr.io/saltstack/salt-kubernetes/salt-key-operator:0.1.0` (operator), so +`salt-master:3008.5` (master), `ghcr.io/saltstack/salt-minion:0.1.0` +(minion) and `ghcr.io/saltstack/salt-key-operator:0.1.0` (operator), so override the image values when you use your own build (see below). ### Build arguments @@ -36,7 +36,6 @@ override the image values when you use your own build (see below). | `EXTRA_SALT_EXTENSIONS` | both minions | empty | Extra pip requirements, space separated, installed after `salt-extensions.txt`. | | `PIP_INDEX_URL`, `PIP_TRUSTED_HOST`, `PIP_ONLY_BINARY` | both minions | empty | Install the Salt extensions through a PyPI mirror. | | `APT_MIRROR` | both minions | empty | Alternative Ubuntu apt mirror. | -| `SALT_GPG_KEY_URL`, `SALT_APT_REPO_URL` | both minions | public Salt package repository | Override for restricted networks. | Both minion Dockerfiles also have `SALT_HOME` and `SALT_SHELL`. Read the Dockerfiles for the authoritative list. The master Dockerfile only takes diff --git a/docs/complete-system-test.md b/docs/complete-system-test.md index e5d4ede..c31113b 100644 --- a/docs/complete-system-test.md +++ b/docs/complete-system-test.md @@ -20,8 +20,8 @@ There is no Helm chart for `salt-minion-vcf`. To test the VCF image, install the - Docker, if you build images yourself (see [`building.md`](building.md)). - Images the nodes can pull. Chart defaults: master `salt-master:3008.5` (unqualified, so build and import it, or override it), minion - `ghcr.io/saltstack/salt-kubernetes/salt-minion:0.1.0`, operator - `ghcr.io/saltstack/salt-kubernetes/salt-key-operator:0.1.0`. Override them with + `ghcr.io/saltstack/salt-minion:0.1.0`, operator + `ghcr.io/saltstack/salt-key-operator:0.1.0`. Override them with `agent.image.repository`/`agent.image.tag` (master, minion) and `salt-key-operator.image.repository`/`salt-key-operator.image.tag` (the operator, set on the master release). A private registry needs diff --git a/docs/kubernetes-compliance-guide.md b/docs/kubernetes-compliance-guide.md index e45f3c8..f1ca44a 100644 --- a/docs/kubernetes-compliance-guide.md +++ b/docs/kubernetes-compliance-guide.md @@ -83,7 +83,7 @@ Key values (full list in [`helm/salt-minion/values.yaml`](../helm/salt-minion/va | Value | Purpose | | --- | --- | -| `agent.image.repository` / `agent.image.tag` | The minion image from step 1 (default `ghcr.io/saltstack/salt-kubernetes/salt-minion:0.1.0`). | +| `agent.image.repository` / `agent.image.tag` | The minion image from step 1 (default `ghcr.io/saltstack/salt-minion:0.1.0`). | | `agent.saltMasterHost` | Master address: `salt-master.salt-master.svc.cluster.local` from inside the cluster, or a node IP with `NodePort`. | | `agent.saltMasterPort`, `agent.saltPublishPort` | Default 4506 and 4505. With a `NodePort` master set both to the NodePort values (30506 and 30505 by default); they must change together. | | One of `agent.minion.keySecretName`, `agent.minion.privateKeyB64` with `publicKeyB64`, `agent.minion.allowSelfGeneratedKey` | Required key source. The minion's keypair is kept in a Secret, so it survives pod restarts. | diff --git a/docs/releasing.md b/docs/releasing.md index 27405c9..c213d05 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -19,7 +19,7 @@ and add the release heading before tagging; nothing enforces it. | Component | Source | Tag to push | Published as | | --- | --- | --- | --- | | Master | `src/master` | `salt-master-vX.Y.Z` | `ghcr.io//salt-master:X.Y.Z` and `:latest` | -| Minion (Kubernetes) | `src/minion/kubernetes` | `salt-minion-vX.Y.Z` | `ghcr.io//salt-minion:X.Y.Z` and `:latest` | +| Minion (Kubernetes) | `src/minion/kubernetes` | `salt-minion-kubernetes-vX.Y.Z` | `ghcr.io//salt-minion:X.Y.Z` and `:latest` | | Minion (VCF) | `src/minion/vcf` | `salt-minion-vcf-vX.Y.Z` | `ghcr.io//salt-minion-vcf:X.Y.Z` and `:latest` | | Key operator | `src/salt-key-operator` | `salt-key-operator-vX.Y.Z` | `ghcr.io//salt-key-operator:X.Y.Z` and `:latest` | @@ -64,8 +64,7 @@ no GitHub Release in that case. git push origin salt-master-v1.1.0 ``` or use the interactive helpers `scripts/release-docker-tags.sh` and - `scripts/release-helm-tags.sh`. See "Known problems" below before using the - Docker one. Both scripts check out and pull `main`, and **delete and + `scripts/release-helm-tags.sh`. Both scripts check out and pull `main`, and **delete and re-create** a tag that already exists, locally and on the remote. Read their prompts before confirming. 4. Watch the workflow run on GitHub. @@ -86,25 +85,19 @@ first release of each image or chart, set the package visibility to public in the organisation's package settings and link it to this repository. Otherwise anonymous `docker pull` and `helm pull` fail. -## Known problems with the release automation - -These are properties of the current workflows and scripts, documented so they -do not surprise you: - -- The tag `salt-minion-vcf-vX.Y.Z` also matches the glob `salt-minion-v*`, so it - starts the Kubernetes minion workflow as well, which publishes a nonsense tag - (`cf-vX.Y.Z`) and a GitHub Release for it. -- `scripts/release-docker-tags.sh` creates `salt-minion-kubernetes-vX.Y.Z` for - the Kubernetes minion image, which matches no workflow. Push - `salt-minion-vX.Y.Z` by hand instead. -- The charts `salt-minion` and `salt-key-operator` are pushed to - `oci://ghcr.io///helm` (double slash) by their workflows, unlike the - master chart. The key operator chart workflow also edits - `helm/salt-minion/Chart.yaml` instead of its own, so it packages the version - committed in `helm/salt-key-operator/Chart.yaml`, and the push step (which - looks for a file named after the tag's version) fails unless the tag matches - that committed version. -- The chart default image repositories in the minion and key operator - `values.yaml` (`ghcr.io/saltstack/salt-kubernetes/...`) differ from the path the - image workflows push to (`ghcr.io//`). Check the path you - actually published and set `agent.image.repository` or `image.repository`. +## Tag names and default images + +- Each tag prefix is distinct (`salt-minion-kubernetes-v`, `salt-minion-vcf-v`, + `salt-master-v`, `salt-key-operator-v`, and the `chart-salt-*-v` chart tags), so + one tag starts exactly one workflow. `scripts/release-docker-tags.sh` and + `scripts/release-helm-tags.sh` create these same tag names. +- The default image repositories in the charts point at where the image + workflows publish: `ghcr.io/saltstack/salt-minion`, `ghcr.io/saltstack/salt-minion-vcf` + and `ghcr.io/saltstack/salt-key-operator`. A default only works once an image + with that tag has been released (and its package made public, see above); the + master chart's default repository is the unqualified `salt-master` on purpose, so a + locally built image can be used as is. +- Before the tag fix, the `salt-minion-kubernetes-v0.1.0` tag matched no workflow, + so no Kubernetes minion image was published for it. Releasing the minion image + needs a new tag (for example `salt-minion-kubernetes-v0.1.2`, see the minion + image changelog). diff --git a/helm/salt-key-operator/CHANGELOG.md b/helm/salt-key-operator/CHANGELOG.md index 056f899..07090d2 100644 --- a/helm/salt-key-operator/CHANGELOG.md +++ b/helm/salt-key-operator/CHANGELOG.md @@ -6,6 +6,11 @@ headings below use the older `salt-key-operator-chart/vX.Y.Z` naming. The chart' version is independent of the image version it happens to default to — check here, not the tag number. +## Unreleased +- The default image repository is now `ghcr.io/saltstack/salt-key-operator`, where the image + workflow publishes. The previous default, `ghcr.io/saltstack/salt-kubernetes/salt-key-operator`, + does not exist. + ## salt-key-operator-chart/v0.1.0 - Default image: `salt-key-operator:0.1.0` (see [`src/salt-key-operator/CHANGELOG.md`](../../src/salt-key-operator/CHANGELOG.md) for what that image version carries). diff --git a/helm/salt-key-operator/values.yaml b/helm/salt-key-operator/values.yaml index 013a1ae..5dca4ba 100644 --- a/helm/salt-key-operator/values.yaml +++ b/helm/salt-key-operator/values.yaml @@ -4,7 +4,7 @@ image: # the path you actually publish and override repository to match. # Distroless static image - runs as the built-in "nonroot" user (uid/gid 65532), no numeric override needed here the way # this repo's other (apt/onedir-based) images require. - repository: ghcr.io/saltstack/salt-kubernetes/salt-key-operator + repository: ghcr.io/saltstack/salt-key-operator tag: "0.1.0" pullPolicy: IfNotPresent diff --git a/helm/salt-master/CHANGELOG.md b/helm/salt-master/CHANGELOG.md index 12e5e7f..45d05e9 100644 --- a/helm/salt-master/CHANGELOG.md +++ b/helm/salt-master/CHANGELOG.md @@ -52,6 +52,12 @@ of the image version it happens to default to — check here, not the tag number second restart and a 2-replica cluster cannot recover from any single failure. `cluster_auto_replace_voters` is left off because it was seen to demote a healthy voter. Treat pod restarts in cluster mode as unsupported until the node identity can be made stable. +- New `agent.image.imagePullSecrets` for pulling the master image from a private registry, and a + `keygen` block for the one-time master-key Job: `keygen.image.repository`/`tag`/`pullPolicy`/ + `imagePullSecrets` (defaults unchanged, `bitnami/kubectl:latest`) and restricted + `keygen.podSecurityContext`/`keygen.containerSecurityContext` (non-root, `RuntimeDefault` seccomp, + no privilege escalation, all capabilities dropped). The Job image used to be hardcoded and the + Job had no security context. Checked on a real cluster: the Job completes and creates the Secret. - Requires master image `salt-master-image/v1.1.0` or later (the cluster configuration is rendered by the image's `entrypoint.sh`). `Chart.yaml` `appVersion` is not updated to track the image. diff --git a/helm/salt-master/README.md b/helm/salt-master/README.md index c590ba9..1f54211 100644 --- a/helm/salt-master/README.md +++ b/helm/salt-master/README.md @@ -119,6 +119,7 @@ The following table lists the most commonly overridden values. See | `namespace` | Namespace for all chart resources. | `salt-master` | | `agent.image.repository` | Salt master image repository. | `salt-master` | | `agent.image.tag` | Salt master image tag (the Salt version the image carries). | `3008.5` | +| `agent.image.imagePullSecrets` | Pull Secrets for the master image (list of `{name: ...}`), for a private registry. | `[]` | | `agent.replicas` | Number of masters (StatefulSet replicas). `> 1` needs `agent.masterKeySecretName` (classic) or `agent.cluster.enabled` (cluster, which needs `>= 2`; use 3 or more). | `1` | | `agent.masterKeySecretName` | Classic mode. Existing Secret with the master keypair as raw files under keys `master.pem` and `master.pub`. **Required** when `agent.replicas > 1` and cluster mode is off. Empty uses `-master-keys`, created by a one-time Job if missing. Ignored in cluster mode. | `""` | | `agent.autoAccept` | Auto-accept new minion keys instead of requiring `salt-key -a`/a `SaltMinionKey`. Leave `false` for a production master. | `false` | @@ -129,6 +130,8 @@ The following table lists the most commonly overridden values. See | `agent.trustedMinions.enabled` | Delegate minion acceptance to `salt-key-operator` (../salt-key-operator) instead of `salt-key -a`. See "Minion acceptance" below. | `true` | | `agent.trustedMinions.createConfigMap` / `.configMapName` / `.syncIntervalSeconds` | Whether the chart creates the ConfigMap, its name, and how often the sidecar copies it into Salt's key directories. | `true` / `salt-master-trusted-minions` / `15` | | `agent.nodeSelector` | Pins every replica to a node. | `{}` | +| `keygen.image.repository` / `.tag` / `.pullPolicy` / `.imagePullSecrets` | Image of the one-time Job that generates the master keypair (classic mode); it needs `kubectl` and `openssl`. | `bitnami/kubectl` / `latest` / `Always` / `[]` | +| `keygen.podSecurityContext` / `keygen.containerSecurityContext` | Security contexts of that Job: non-root, `RuntimeDefault` seccomp, no privilege escalation, all capabilities dropped. | see `values.yaml` | | `agent.podSecurityContext` / `agent.containerSecurityContext` | Non-root uid/gid `10001`, `fsGroup: 10001`, all capabilities dropped. Used by the master, the sidecar and the init containers. | see `values.yaml` | | `service.type` | `ClusterIP`, `NodePort`, or `LoadBalancer` for the flat `salt-master` Service. `ClusterIP` (in-cluster only) by default - see "External access". | `ClusterIP` | | `service.nodePorts.publish` / `.ret` | Node ports used when `service.type=NodePort`. | `30505` / `30506` | @@ -243,6 +246,12 @@ you can accept rebuilding the cluster (reinstall and, if needed, delete the `state` PVCs) after a restart. Classic mode is not affected. Cluster mode is opt-in and is not the default. +### One release per namespace + +The chart names its resources fixed names (the StatefulSet `salt-master`, the Services +`salt-master` and `salt-master-headless`, and the peer DNS names derived from them), not +names built from the release name. Install at most one release of this chart per namespace. + ### What was tested Tested on a real cluster: cluster mode with 3 replicas and isolated storage diff --git a/helm/salt-master/templates/master-keygen-job.yaml b/helm/salt-master/templates/master-keygen-job.yaml index 8b11618..4f084cb 100644 --- a/helm/salt-master/templates/master-keygen-job.yaml +++ b/helm/salt-master/templates/master-keygen-job.yaml @@ -11,13 +11,22 @@ spec: template: spec: serviceAccountName: {{ .Values.serviceAccount.name }} + securityContext: + {{- toYaml .Values.keygen.podSecurityContext | nindent 8 }} + {{- with .Values.keygen.image.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} # The normal Salt Master pod does not need an API token, but this # one-time key-generation Job needs one to create the Secret. automountServiceAccountToken: true restartPolicy: OnFailure containers: - name: master-keygen - image: bitnami/kubectl:latest + image: {{ printf "%s:%s" .Values.keygen.image.repository (toString .Values.keygen.image.tag) | quote }} + imagePullPolicy: {{ .Values.keygen.image.pullPolicy }} + securityContext: + {{- toYaml .Values.keygen.containerSecurityContext | nindent 12 }} command: ["/bin/sh", "-c"] args: - | diff --git a/helm/salt-master/templates/statefulset.yaml b/helm/salt-master/templates/statefulset.yaml index 0fb1bf9..ebe690a 100644 --- a/helm/salt-master/templates/statefulset.yaml +++ b/helm/salt-master/templates/statefulset.yaml @@ -29,6 +29,10 @@ spec: app.kubernetes.io/name: salt-master spec: serviceAccountName: {{ .Values.serviceAccount.name }} + {{- with .Values.agent.image.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} {{- with .Values.agent.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} diff --git a/helm/salt-master/values.yaml b/helm/salt-master/values.yaml index 4f12b60..595b4a7 100644 --- a/helm/salt-master/values.yaml +++ b/helm/salt-master/values.yaml @@ -6,7 +6,7 @@ rbac: agent: image: # Built from src/master/Dockerfile. Also published to - # ghcr.io/saltstack/salt-kubernetes/salt-master (see docs/releasing.md), but + # ghcr.io/saltstack/salt-master (see docs/releasing.md), but # this default is unqualified so a locally built image can be used as is: # load it into each node's container runtime, or set repository to the # GHCR path (or your own registry) to pull instead. The tag is the Salt @@ -14,6 +14,10 @@ agent: repository: salt-master tag: "3008.5" pullPolicy: IfNotPresent + # Secrets for pulling the master image from a private registry, as a list + # of {name: }. Used by the StatefulSet (and so by every init + # container in it). + imagePullSecrets: [] # Number of master pods (StatefulSet replicas; pods are salt-master-0..N-1). # @@ -282,4 +286,25 @@ service: gatewayNamespace: "" publishSectionName: salt-publish retSectionName: salt-ret + +# The one-time Job that generates the master keypair Secret (classic mode, +# when agent.masterKeySecretName is empty and the Secret does not exist). +# The image needs kubectl and openssl. +keygen: + image: + repository: bitnami/kubectl + tag: latest + pullPolicy: Always + imagePullSecrets: [] + # Restricted by default; the Job only needs to create one Secret. runAsNonRoot + # needs an image whose default user is not root (bitnami/kubectl is not). + podSecurityContext: + runAsNonRoot: true + seccompProfile: + type: RuntimeDefault + containerSecurityContext: + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL # end of values diff --git a/helm/salt-minion/CHANGELOG.md b/helm/salt-minion/CHANGELOG.md index 139742c..3415f70 100644 --- a/helm/salt-minion/CHANGELOG.md +++ b/helm/salt-minion/CHANGELOG.md @@ -28,6 +28,9 @@ Applies to both `src/minion/kubernetes` and `src/minion/vcf`. - Extensions are unchanged: `saltext.kubernetes==2.1.0`, `saltext.vault==1.8.0` in both images, plus `saltext.vcf==1.0.0` and `saltext.bmc==0.0.1` in the VCF image. +- Removed the unused `SALT_GPG_KEY_URL` and `SALT_APT_REPO_URL` build arguments, and corrected + comments that still named the old chart and file paths. + ### salt-minion-image/v0.1.2 - Salt: 3008.5 (no other change) @@ -87,6 +90,18 @@ Applies to both `src/minion/kubernetes` and `src/minion/vcf`. - Documentation: the README now describes the StatefulSet identity model and key layouts, and how to run the helm-unittest suites (`helm unittest helm/salt-minion`). +- The key generation Job now runs with a restricted security context (new + `keygen.podSecurityContext` and `keygen.containerSecurityContext`: non-root, `RuntimeDefault` + seccomp, no privilege escalation, all capabilities dropped). Checked on a real cluster. +- Removed `agent.minion.grains` and `agent.minion.masterId`, and the `-minion-config` + ConfigMap they were written to: nothing mounted that ConfigMap, so they never had any effect. +- The default image repository is now `ghcr.io/saltstack/salt-minion`, where the image workflow + publishes. The previous default, `ghcr.io/saltstack/salt-kubernetes/salt-minion`, does not + exist. The `0.1.0` tag at the new path exists only once the Kubernetes minion image has been + released (the workflow now triggers on `salt-minion-kubernetes-v*`; see `docs/releasing.md`). +- Removed the unused `scripts/` copies of the entrypoint scripts and `salt-extensions.txt` from the + chart (the images read the files under `src/minion/`). `Chart.yaml` now describes a StatefulSet. + ### salt-minion-chart/v1.0.0 **Breaking - defaults change on `helm upgrade` from any prior release:** - `agent.minion.keySecretName` is now **required** - the chart fails fast diff --git a/helm/salt-minion/Chart.yaml b/helm/salt-minion/Chart.yaml index 4985210..17c06f6 100644 --- a/helm/salt-minion/Chart.yaml +++ b/helm/salt-minion/Chart.yaml @@ -1,7 +1,8 @@ apiVersion: v2 name: salt-minion description: > - Installs Salt minion Deployment and supporting configurations. + Installs Salt minions as a Kubernetes StatefulSet: each pod is its own + minion, with its own ID and keypair. type: application version: 0.1.0 appVersion: "0.1.0" diff --git a/helm/salt-minion/README.md b/helm/salt-minion/README.md index 73f803c..97589ba 100644 --- a/helm/salt-minion/README.md +++ b/helm/salt-minion/README.md @@ -212,7 +212,7 @@ See [values.yaml](values.yaml) for the complete list of configuration options. | `agent.minion.masterPubKeyB64` | Base64-encoded master public key, passed as `SALT_MASTER_PUBKEY_B64` so the minion trusts the master directly | `""` | | `agent.podSecurityContext` | Pod security context; `fsGroup` gives the containers access to the key Secret and the PKI volume | `{"fsGroup": 10001, "runAsNonRoot": true}` | | `agent.containerSecurityContext` | Security context shared by the minion and the `prepare-minion-keys` init container | `{"allowPrivilegeEscalation": false, "runAsNonRoot": true, "capabilities": {"drop": ["ALL"]}}` | -| `agent.image.repository` | Minion image repository | `ghcr.io/saltstack/salt-kubernetes/salt-minion` | +| `agent.image.repository` | Minion image repository | `ghcr.io/saltstack/salt-minion` | | `agent.image.tag` | Minion image tag | `0.1.0` | | `agent.image.pullPolicy` | Minion image pull policy | `IfNotPresent` | | `agent.image.imagePullSecrets` | Pull Secrets for the minion pods | `[]` | @@ -220,6 +220,8 @@ See [values.yaml](values.yaml) for the complete list of configuration options. | `keygen.image.tag` | Key generation image tag | `latest` | | `keygen.image.pullPolicy` | Key generation image pull policy | `Always` | | `keygen.image.imagePullSecrets` | Pull Secrets for the key generation Job | `[]` | +| `keygen.podSecurityContext` | Pod security context of the key generation Job | `runAsNonRoot: true`, `seccompProfile: RuntimeDefault` | +| `keygen.containerSecurityContext` | Container security context of the key generation Job | no privilege escalation, all capabilities dropped | | `agent.saltMasterHost` | Salt master hostname, or a list of masters (REQUIRED in in_cluster mode) | `""` | | `agent.saltMasterPort` | Master request/return port (`master_port`) | `4506` | | `agent.saltPublishPort` | Master publish port (`publish_port`) | `4505` | @@ -232,10 +234,7 @@ See [values.yaml](values.yaml) for the complete list of configuration options. | `serviceAccount.name` | ServiceAccount name | `salt-minion` | The chart has no persistence settings. The minion's PKI directory is an `emptyDir`, -and the keys always come from a Secret (see below). `agent.minion.grains` and -`agent.minion.masterId` exist in `values.yaml` but are only written to the -`-minion-config` ConfigMap, which nothing mounts, so they currently have no -effect on the minion. +and the keys always come from a Secret (see below). ### Pod identity diff --git a/helm/salt-minion/salt-extensions.txt b/helm/salt-minion/salt-extensions.txt deleted file mode 100644 index c11dd72..0000000 --- a/helm/salt-minion/salt-extensions.txt +++ /dev/null @@ -1,14 +0,0 @@ -# Salt extension packages installed into the Salt onedir Python environment. -# Add/remove/pin any pip-installable Salt extension here. -# -# NOTE: this copy is not read by any image build. The images use -# src/minion/kubernetes/salt-extensions.txt and src/minion/vcf/salt-extensions.txt; -# edit those. - -# Kubernetes execution/state modules and cluster-API access -# Source: https://github.com/salt-extensions/saltext-kubernetes -saltext.kubernetes==2.1.0 - -# Vault integration (ext_pillar, sdb driver, execution modules) -# Source: https://github.com/salt-extensions/saltext-vault -saltext.vault==1.8.0 diff --git a/helm/salt-minion/scripts/docker-entrypoint.sh b/helm/salt-minion/scripts/docker-entrypoint.sh deleted file mode 100755 index 294d17c..0000000 --- a/helm/salt-minion/scripts/docker-entrypoint.sh +++ /dev/null @@ -1,178 +0,0 @@ -#!/bin/sh -set -eu - -CONFIG_DIR=/etc/salt/minion.d -MASTER_CONFIG="${CONFIG_DIR}/10-master.conf" -RUNTIME_CONFIG="${CONFIG_DIR}/20-runtime.conf" - -mkdir -p "$CONFIG_DIR" /etc/salt/pki/minion /var/cache/salt/minion/.socks /var/log/salt - -# Pre-seed the minion's own RSA keypair when supplied - same pattern as -# salt-minion-vcf/scripts/docker-entrypoint.sh. Only applied when -# minion.pem doesn't already exist, so a restarted/rescheduled container -# (persistent PKI volume) keeps its established identity rather than -# re-seeding on every start. -if [ ! -s /etc/salt/pki/minion/minion.pem ] \ - && [ -n "${SALT_MINION_PRIVATE_KEY_B64:-}" ] && [ -n "${SALT_MINION_PUBLIC_KEY_B64:-}" ]; then - echo "${SALT_MINION_PRIVATE_KEY_B64}" | base64 -d > /etc/salt/pki/minion/minion.pem - chmod 0400 /etc/salt/pki/minion/minion.pem - echo "${SALT_MINION_PUBLIC_KEY_B64}" | base64 -d > /etc/salt/pki/minion/minion.pub - chmod 0644 /etc/salt/pki/minion/minion.pub - echo "Pre-seeded minion keypair (already registered as trusted)" -fi - -# Kubernetes Deployment pods get a random pod name (no stable identity like a -# StatefulSet's), so fall back to the container hostname when no explicit ID -# is set. -if [ -z "${SALT_MINION_ID:-}" ]; then - if [ -n "${POD_NAME:-}" ]; then - SALT_MINION_ID="${POD_NAME}" - else - SALT_MINION_ID="$(hostname)" - fi -fi - -# Two supported configuration models, same as salt-minion-vcf's entrypoint: -# 1. Docker/env: SALT_MASTER is supplied and this script writes master config. -# 2. Kubernetes/ConfigMap: 10-master.conf is mounted by Kubernetes/Helm. -if [ -n "${SALT_MASTER:-}" ]; then - case "${SALT_MASTER_PORT:-4506}" in - *[!0-9]*|'') echo >&2 "ERROR: SALT_MASTER_PORT must be numeric"; exit 64 ;; - esac - case "${SALT_PUBLISH_PORT:-4505}" in - *[!0-9]*|'') echo >&2 "ERROR: SALT_PUBLISH_PORT must be numeric"; exit 64 ;; - esac - - # A comma-separated SALT_MASTER (e.g. "master-0,master-1,master-2") - # renders as a YAML list instead of a scalar - Salt's native multi-master - # mode (https://docs.saltproject.io/en/3008/topics/tutorials/multimaster.html): - # one independent, simultaneous connection per address, not failover. - case "${SALT_MASTER}" in - *,*) - echo "master:" > "$MASTER_CONFIG" - old_ifs=$IFS - IFS=',' - for m in $SALT_MASTER; do - IFS=$old_ifs - echo " - ${m}" >> "$MASTER_CONFIG" - done - IFS=$old_ifs - ;; - *) - echo "master: ${SALT_MASTER}" > "$MASTER_CONFIG" - ;; - esac - - cat >> "$MASTER_CONFIG" < /etc/salt/pki/minion/minion_master.pub - elif [ -n "${SALT_MASTER_FINGER:-}" ]; then - cat >> "$MASTER_CONFIG" <&2 "ERROR: Salt Master configuration is missing." - echo >&2 "Provide SALT_MASTER or mount ${MASTER_CONFIG} (Kubernetes ConfigMap)." - exit 64 -fi - -# FIPS-compliant crypto defaults - see salt-minion-vcf/scripts/docker-entrypoint.sh -# for the full rationale (masters running FIPS-validated crypto don't -# implement SHA-1 for RSA OAEP/PKCS1v15, which breaks auth with a minion -# defaulting to it). Set SALT_FIPS_MODE=false only if your target master is -# confirmed to NOT be FIPS-enforced. -FIPS_CONFIG="${CONFIG_DIR}/15-fips.conf" -if [ "${SALT_FIPS_MODE:-true}" = "true" ]; then - cat > "$FIPS_CONFIG" < "$RUNTIME_CONFIG" <: instead of containing plaintext secrets. Same -# shape as salt-minion-vcf/scripts/docker-entrypoint.sh. -if [ -n "${VAULT_ADDR:-}" ]; then - if [ -n "${VAULT_SECRET_ID_FILE:-}" ] && [ -f "${VAULT_SECRET_ID_FILE}" ]; then - VAULT_SECRET_ID="$(cat "${VAULT_SECRET_ID_FILE}")" - fi - if [ -n "${VAULT_TOKEN_FILE:-}" ] && [ -f "${VAULT_TOKEN_FILE}" ]; then - VAULT_TOKEN="$(cat "${VAULT_TOKEN_FILE}")" - fi - - { - echo "" - echo "vault:" - echo " server:" - echo " url: ${VAULT_ADDR}" - echo " auth:" - if [ "${VAULT_AUTH_METHOD:-approle}" = "token" ]; then - echo " method: token" - echo " token: '${VAULT_TOKEN:-}'" - else - echo " method: approle" - echo " role_id: '${VAULT_ROLE_ID:-}'" - if [ -n "${VAULT_SECRET_ID:-}" ]; then - echo " secret_id: '${VAULT_SECRET_ID}'" - fi - fi - echo "" - echo "${VAULT_SDB_PROFILE:-vault_sdb}:" - echo " driver: vault" - } >> "$RUNTIME_CONFIG" -fi - -echo "====================================================" -echo " Salt Minion Kubernetes" -echo "====================================================" -echo "Minion ID : ${SALT_MINION_ID}" -if [ -n "${SALT_MASTER:-}" ]; then - echo "Salt Master : ${SALT_MASTER}" -else - echo "Salt Master : configured by mounted ConfigMap" -fi -echo "Log Level : ${SALT_LOG_LEVEL:-info}" -echo "FIPS Mode : $([ "${SALT_FIPS_MODE:-true}" = "true" ] && echo "enabled (${SALT_ENCRYPTION_ALGORITHM:-OAEP-SHA224}/${SALT_SIGNING_ALGORITHM:-PKCS1v15-SHA224})" || echo disabled)" -echo "Vault : $([ -n "${VAULT_ADDR:-}" ] && echo "${VAULT_ADDR}" || echo disabled)" -echo "====================================================" - -exec salt-minion -l "${SALT_LOG_LEVEL:-info}" diff --git a/helm/salt-minion/scripts/healthcheck.sh b/helm/salt-minion/scripts/healthcheck.sh deleted file mode 100755 index 1328034..0000000 --- a/helm/salt-minion/scripts/healthcheck.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -set -eu - -result="$(salt-call --out=newline_values_only --retcode-passthrough status.master 2>/dev/null || true)" -case "$result" in - *True*|*true*) exit 0 ;; - *) exit 1 ;; -esac diff --git a/helm/salt-minion/templates/keygen-job.yaml b/helm/salt-minion/templates/keygen-job.yaml index ad81568..afc87fa 100644 --- a/helm/salt-minion/templates/keygen-job.yaml +++ b/helm/salt-minion/templates/keygen-job.yaml @@ -12,6 +12,8 @@ spec: template: spec: serviceAccountName: {{ .Values.serviceAccount.name }} + securityContext: + {{- toYaml .Values.keygen.podSecurityContext | nindent 8 }} {{- with .Values.keygen.image.imagePullSecrets }} imagePullSecrets: {{- toYaml . | nindent 8 }} @@ -22,6 +24,8 @@ spec: - name: keygen image: {{ include "salt-minion.keygenImage" . | quote }} imagePullPolicy: {{ .Values.keygen.image.pullPolicy }} + securityContext: + {{- toYaml .Values.keygen.containerSecurityContext | nindent 12 }} command: ["/bin/sh", "-c"] args: - | diff --git a/helm/salt-minion/templates/minion-config.yaml b/helm/salt-minion/templates/minion-config.yaml deleted file mode 100644 index 65a811e..0000000 --- a/helm/salt-minion/templates/minion-config.yaml +++ /dev/null @@ -1,10 +0,0 @@ -{{- $configName := printf "%s-minion-config" .Release.Name }} -apiVersion: v1 -kind: ConfigMap -metadata: - name: {{ $configName }} - namespace: {{ .Values.namespace }} -data: - minion_id: {{ .Values.agent.minion.id | default (printf "%s-%s" .Release.Name .Release.Namespace) | quote }} - master_id: {{ .Values.agent.minion.masterId | quote }} - master_pub_key_b64: {{ .Values.agent.minion.masterPubKeyB64 | quote }} diff --git a/helm/salt-minion/tests/images_test.yaml b/helm/salt-minion/tests/images_test.yaml index 9d32b4a..248fdd3 100644 --- a/helm/salt-minion/tests/images_test.yaml +++ b/helm/salt-minion/tests/images_test.yaml @@ -10,11 +10,11 @@ tests: - template: templates/statefulset.yaml equal: path: spec.template.spec.containers[?(@.name == "salt-minion")].image - value: ghcr.io/saltstack/salt-kubernetes/salt-minion:0.1.0 + value: ghcr.io/saltstack/salt-minion:0.1.0 - template: templates/statefulset.yaml equal: path: spec.template.spec.initContainers[?(@.name == "prepare-minion-keys")].image - value: ghcr.io/saltstack/salt-kubernetes/salt-minion:0.1.0 + value: ghcr.io/saltstack/salt-minion:0.1.0 - template: templates/keygen-job.yaml equal: path: spec.template.spec.containers[?(@.name == "keygen")].image @@ -28,7 +28,7 @@ tests: - template: templates/statefulset.yaml equal: path: spec.template.spec.containers[?(@.name == "salt-minion")].image - value: ghcr.io/saltstack/salt-kubernetes/salt-minion:1.10 + value: ghcr.io/saltstack/salt-minion:1.10 - template: templates/keygen-job.yaml equal: path: spec.template.spec.containers[?(@.name == "keygen")].image @@ -42,7 +42,7 @@ tests: - template: templates/statefulset.yaml equal: path: spec.template.spec.containers[?(@.name == "salt-minion")].image - value: ghcr.io/saltstack/salt-kubernetes/salt-minion:123 + value: ghcr.io/saltstack/salt-minion:123 - template: templates/keygen-job.yaml equal: path: spec.template.spec.containers[?(@.name == "keygen")].image diff --git a/helm/salt-minion/tests/keygen_job_test.yaml b/helm/salt-minion/tests/keygen_job_test.yaml index 5cf3430..a541ca6 100644 --- a/helm/salt-minion/tests/keygen_job_test.yaml +++ b/helm/salt-minion/tests/keygen_job_test.yaml @@ -90,3 +90,20 @@ tests: - notMatchRegex: path: spec.template.spec.containers[0].args[0] pattern: "\\.data\\['" + + - it: runs key generation with a restricted security context + set: + agent.minion.allowSelfGeneratedKey: true + asserts: + - equal: + path: spec.template.spec.securityContext.runAsNonRoot + value: true + - equal: + path: spec.template.spec.securityContext.seccompProfile.type + value: RuntimeDefault + - equal: + path: spec.template.spec.containers[0].securityContext.allowPrivilegeEscalation + value: false + - equal: + path: spec.template.spec.containers[0].securityContext.capabilities.drop + value: [ALL] diff --git a/helm/salt-minion/values.yaml b/helm/salt-minion/values.yaml index d04c864..5659d30 100644 --- a/helm/salt-minion/values.yaml +++ b/helm/salt-minion/values.yaml @@ -34,9 +34,9 @@ agent: # is an image release number, not a Salt version. A different image has # to provide the same entrypoint contract (see ../../src/minion/README.md), # including the POD_NAME fallback for the minion ID. - repository: ghcr.io/saltstack/salt-kubernetes/salt-minion + repository: ghcr.io/saltstack/salt-minion # To use the VCF extensions, set repository to the VCF image (e.g., salt-minion-vcf) and an appropriate tag - # repository: ghcr.io/saltstack/salt-kubernetes/salt-minion-vcf + # repository: ghcr.io/saltstack/salt-minion-vcf tag: "0.1.0" pullPolicy: IfNotPresent @@ -98,14 +98,9 @@ agent: # -0, -1, ... and each pod's minion ID is its pod # name, e.g. idPrefix: external-minion -> external-minion-0, -1, ... idPrefix: "" - # masterId and grains are currently only written to the - # -minion-config ConfigMap, which no pod mounts, so they do not - # affect the minion. - masterId: "" # Base64-encoded master public key; passed as SALT_MASTER_PUBKEY_B64 so the # minion trusts the master directly on first connect. masterPubKeyB64: "" - grains: {} # Inline keypair (base64-encoded PEM), set together. One replica only: the # chart creates a Secret from them (named keySecretName, or -keys). # The chart rejects them with replicas > 1. @@ -169,6 +164,18 @@ keygen: repository: bitnami/kubectl tag: latest pullPolicy: Always + # Restricted by default; the Job only needs to create or patch one Secret. + # runAsNonRoot needs an image whose default user is not root (bitnami/kubectl + # is not). + podSecurityContext: + runAsNonRoot: true + seccompProfile: + type: RuntimeDefault + containerSecurityContext: + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL serviceAccount: name: salt-minion diff --git a/scripts/ci.sh b/scripts/ci.sh index b8fc131..9c8f401 100755 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -48,7 +48,7 @@ echo "--- Hadolint Dockerfiles" for df in src/master/Dockerfile \ src/minion/vcf/Dockerfile \ src/minion/kubernetes/Dockerfile \ - salt-key-operator/Dockerfile; do + src/salt-key-operator/Dockerfile; do echo "Linting $df" hadolint "$df" || fail "Hadolint failed for $df" done @@ -73,7 +73,8 @@ echo "# --- Ruff code lint/format check (skipped)" #------------------------------------------------------------ echo "# --- ShellCheck" if command -v shellcheck >/dev/null; then - shellcheck src/minion/vcf/scripts/*.sh src/minion/kubernetes/scripts/*.sh || fail "ShellCheck errors" + shellcheck -S warning src/master/entrypoint.sh src/minion/kubernetes/entrypoint.sh \ + src/minion/vcf/entrypoint.sh scripts/*.sh || fail "ShellCheck errors" else echo "shellcheck not installed; skipping" fi @@ -96,7 +97,7 @@ else echo "yamllint not installed; skipping YAML lint" fi -# Helper to run helm template and optionally fail on error +# Helper to run helm template and fail if it errors helm_template() { local name="$1" shift @@ -104,31 +105,53 @@ helm_template() { helm template test "$@" >/dev/null || fail "Helm template failed for $name" } -# Master chart templates (single and active‑active) -# helm_template "salt-master‑single" helm/salt-master # Skipped due to template issue -# helm_template "salt-master‑aa" helm/salt-master \ -# --set agent.replicas=3 \ -# --set agent.masterKeySecretName=my-master-key \ -# --set service.perOrdinal.enabled=true -# Expected failure when replicas>1 without masterKeySecretName (skipped) +# Helper for configurations the chart must reject (it fails fast on purpose) +helm_template_fails() { + local name="$1" + shift + echo "--- Helm template (must fail): $name" + if helm template test "$@" >/dev/null 2>&1; then + fail "Helm template unexpectedly succeeded for $name" + fi +} + +# Master chart: classic single, classic multi-master, and cluster mode +helm_template "salt-master-single" helm/salt-master +helm_template "salt-master-multi" helm/salt-master \ + --set agent.replicas=3 \ + --set agent.masterKeySecretName=my-master-key +helm_template "salt-master-cluster" helm/salt-master \ + --set agent.cluster.enabled=true \ + --set agent.replicas=3 +helm_template_fails "salt-master replicas>1 without a shared key" helm/salt-master \ + --set agent.replicas=2 +helm_template_fails "salt-master cluster with one replica" helm/salt-master \ + --set agent.cluster.enabled=true # Operator chart template (include CRDs) helm_template "salt-key-operator" helm/salt-key-operator --include-crds -# Minion‑kubernetes chart variants -# helm_template "minion‑k8s‑bundled" helm/salt-minion \ -# --set agent.saltMasterHost=salt-master.example.com \ -# --set agent.minion.keySecretName=my-minion-key -# helm_template "minion‑k8s‑init‑container" helm/salt-minion \ -# --set agent.saltMasterHost=salt-master.example.com \ -# --set agent.minion.keySecretName=my-minion-key \ -# --set agent.kubectl.bundled=false -# helm_template "minion‑k8s‑multi" helm/salt-minion \ -# --set agent.minion.keySecretName=my-minion-key \ -# --set 'agent.saltMasterHost[0]=m0.example.com' \ -# --set 'agent.saltMasterHost[1]=m1.example.com' \ -# --set 'agent.saltMasterHost[2]=m2.example.com' -# Expected failure when keySecretName is missing (skipped) +# Minion chart: one minion, one key pair per pod, and several masters +helm_template "salt-minion-single" helm/salt-minion \ + --set agent.saltMasterHost=salt-master.example.com \ + --set agent.minion.keySecretName=my-minion-key +helm_template "salt-minion-per-pod-keys" helm/salt-minion \ + --set agent.saltMasterHost=salt-master.example.com \ + --set agent.replicas=3 \ + --set agent.minion.idPrefix=ext-minion \ + --set agent.minion.allowSelfGeneratedKey=true +helm_template "salt-minion-multi-master" helm/salt-minion \ + --set agent.minion.keySecretName=my-minion-key \ + --set 'agent.saltMasterHost[0]=m0.example.com' \ + --set 'agent.saltMasterHost[1]=m1.example.com' \ + --set 'agent.saltMasterHost[2]=m2.example.com' +helm_template_fails "salt-minion replicas>1 with a fixed minion id" helm/salt-minion \ + --set agent.saltMasterHost=salt-master.example.com \ + --set agent.replicas=2 \ + --set agent.minion.id=fixed \ + --set agent.minion.allowSelfGeneratedKey=true +helm_template_fails "salt-minion without a key source" helm/salt-minion \ + --set agent.saltMasterHost=salt-master.example.com #------------------------------------------------------------ # 5. Build Docker images (single‑arch is fine locally) @@ -141,7 +164,7 @@ sudo docker build --build-arg TARGETARCH=amd64 --build-arg INCLUDE_KUBECTL=false # Minion‑vcf image sudo docker build --build-arg TARGETARCH=amd64 -t salt-minion-vcf:${MINION_VCF_IMAGE_TAG} -f src/minion/vcf/Dockerfile src/minion/vcf # Operator image -sudo docker build -t salt-key-operator:${IMAGE_TAG_MASTER} -f salt-key-operator/Dockerfile salt-key-operator +sudo docker build -t salt-key-operator:${IMAGE_TAG_MASTER} -f src/salt-key-operator/Dockerfile src/salt-key-operator #------------------------------------------------------------ # 6. Trivy vulnerability scan (high / critical only) diff --git a/scripts/salt-kubernetes-e2e-local-test.sh b/scripts/salt-kubernetes-e2e-local-test.sh index d117522..315e026 100755 --- a/scripts/salt-kubernetes-e2e-local-test.sh +++ b/scripts/salt-kubernetes-e2e-local-test.sh @@ -19,11 +19,33 @@ MINION_RELEASE="salt-minion" MINION_ID="integration-test-minion" MINION_SECRET="integration-test-minion-keys" -BUILD_CA="/private/tmp/cloud-services-root-ca.crt" KEY_DIRECTORY="/private/tmp/salt-minion-integration-keys" -PIP_INDEX_URL="https://packages.vcfd.broadcom.net/artifactory/api/pypi/pypi-virtual/simple" -PACKAGES_IP="10.191.86.43" +# Optional settings for building behind a proxy or private mirror. All empty by +# default; set them in the environment when you need them: +# BUILD_CA PEM file with an extra CA to trust while building images +# PIP_INDEX_URL PyPI mirror used to install the Salt extensions +# PACKAGES_ADD_HOST host:ip passed to `docker build --add-host` +# PLATFORM image platform (default linux/arm64, for Apple silicon) +# KUBE_CONTEXT kubectl context to use (default rancher-desktop) +BUILD_CA="${BUILD_CA:-}" +PIP_INDEX_URL="${PIP_INDEX_URL:-}" +PACKAGES_ADD_HOST="${PACKAGES_ADD_HOST:-}" +PLATFORM="${PLATFORM:-linux/arm64}" +KUBE_CONTEXT="${KUBE_CONTEXT:-rancher-desktop}" + +# Extra `docker build` arguments assembled from the settings above. +build_ca_args=() +if [ -n "${BUILD_CA}" ]; then + build_ca_args=(--secret "id=build_ca,src=${BUILD_CA}") +fi +minion_build_args=() +if [ -n "${PACKAGES_ADD_HOST}" ]; then + minion_build_args+=(--add-host "${PACKAGES_ADD_HOST}") +fi +if [ -n "${PIP_INDEX_URL}" ]; then + minion_build_args+=(--build-arg "PIP_INDEX_URL=${PIP_INDEX_URL}") +fi cd "${REPO_DIR}" @@ -31,7 +53,7 @@ echo "====================================================" echo "1. Select Rancher Desktop" echo "====================================================" -kubectl config use-context rancher-desktop +kubectl config use-context "${KUBE_CONTEXT}" docker context use rancher-desktop kubectl get nodes @@ -108,33 +130,28 @@ helm lint ./helm/salt-minion --set agent.minion.allowSelfGeneratedKey=true git diff --check echo "====================================================" -echo "7. Export the corporate CA certificate" +echo "7. Check the optional build CA certificate" echo "====================================================" -security find-certificate \ - -a \ - -c "Cloud Services Root CA" \ - -p \ - "${HOME}/Library/Keychains/login.keychain-db" \ - /Library/Keychains/System.keychain \ - /System/Library/Keychains/SystemRootCertificates.keychain \ - > "${BUILD_CA}" +if [ -n "${BUILD_CA}" ]; then + test -s "${BUILD_CA}" -test -s "${BUILD_CA}" - -openssl x509 \ - -in "${BUILD_CA}" \ - -noout \ - -subject \ - -issuer \ - -dates + openssl x509 \ + -in "${BUILD_CA}" \ + -noout \ + -subject \ + -issuer \ + -dates +else + echo "BUILD_CA not set; building without an extra CA certificate" +fi echo "====================================================" echo "8. Build Salt Key Operator" echo "====================================================" docker build \ - --platform linux/arm64 \ + --platform "${PLATFORM}" \ --tag salt-key-operator:local \ ./src/salt-key-operator @@ -143,8 +160,8 @@ echo "9. Build Salt Master" echo "====================================================" docker build \ - --platform linux/arm64 \ - --secret "id=build_ca,src=${BUILD_CA}" \ + --platform "${PLATFORM}" \ + ${build_ca_args[@]+"${build_ca_args[@]}"} \ --tag salt-master:local \ ./src/master @@ -153,10 +170,9 @@ echo "10. Build Salt Minion" echo "====================================================" docker build \ - --platform linux/arm64 \ - --add-host "packages.vcfd.broadcom.net:${PACKAGES_IP}" \ - --secret "id=build_ca,src=${BUILD_CA}" \ - --build-arg "PIP_INDEX_URL=${PIP_INDEX_URL}" \ + --platform "${PLATFORM}" \ + ${build_ca_args[@]+"${build_ca_args[@]}"} \ + ${minion_build_args[@]+"${minion_build_args[@]}"} \ --tag salt-minion:local \ ./src/minion/kubernetes @@ -174,12 +190,12 @@ docker image inspect salt-minion:local \ --format 'Image={{.RepoTags}} Architecture={{.Architecture}} OS={{.Os}}' docker run --rm \ - --platform linux/arm64 \ + --platform "${PLATFORM}" \ salt-master:local \ salt-master --version docker run --rm \ - --platform linux/arm64 \ + --platform "${PLATFORM}" \ --entrypoint /bin/sh \ salt-minion:local \ -c ' diff --git a/src/master/entrypoint.sh b/src/master/entrypoint.sh index 1ca9eb3..c9bc87a 100644 --- a/src/master/entrypoint.sh +++ b/src/master/entrypoint.sh @@ -18,7 +18,7 @@ mkdir -p "$CONF_DIR" # /run fresh (root-owned, 0755) on every pod start regardless of what's # baked into the image, so a non-root master can never mkdir under # /var/run/salt/master - same reasoning/pattern as - # salt-minion-vcf/scripts/docker-entrypoint.sh's pidfile/sock_dir. + # src/minion/kubernetes/entrypoint.sh's pidfile/sock_dir. printf 'pidfile: /var/cache/salt/master/master.pid\n' printf 'sock_dir: /var/cache/salt/master/.socks\n' } > "$CONF_DIR/99-env.conf" diff --git a/src/minion/README.md b/src/minion/README.md index 430e030..827325b 100644 --- a/src/minion/README.md +++ b/src/minion/README.md @@ -87,7 +87,6 @@ Both Dockerfiles take the same arguments: | `PIP_TRUSTED_HOST` | empty | Passed to pip as `--trusted-host` | | `PIP_ONLY_BINARY` | empty | Passed to pip as `--only-binary` | | `APT_MIRROR` | empty | Replaces the `URIs:` of the Ubuntu apt sources | -| `SALT_GPG_KEY_URL`, `SALT_APT_REPO_URL` | Broadcom Salt package repository | Declared in the Dockerfiles but not used by the current build steps | Example: diff --git a/src/minion/kubernetes/Dockerfile b/src/minion/kubernetes/Dockerfile index 2dc3815..feab5c4 100644 --- a/src/minion/kubernetes/Dockerfile +++ b/src/minion/kubernetes/Dockerfile @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 # -# Self-contained Salt minion image for salt-minion-kubernetes: core Salt plus +# Self-contained Salt minion image for the salt-minion chart: core Salt plus # saltext.vault and saltext.kubernetes, both pip-installed from PyPI. FROM ubuntu:24.04 @@ -22,8 +22,6 @@ ARG PIP_TRUSTED_HOST="" ARG PIP_ONLY_BINARY="" ARG APT_MIRROR="" -ARG SALT_GPG_KEY_URL="https://packages.broadcom.com/artifactory/api/security/keypair/SaltProjectKey/public" -ARG SALT_APT_REPO_URL="https://packages.broadcom.com/artifactory/saltproject-deb" LABEL org.opencontainers.image.title="Salt Minion" LABEL org.opencontainers.image.description="Salt Minion runtime preloaded with saltext.vault and saltext.kubernetes, for RBAC-driven kube-bench compliance assessments" diff --git a/src/minion/kubernetes/entrypoint.sh b/src/minion/kubernetes/entrypoint.sh index ab09493..161b7e8 100755 --- a/src/minion/kubernetes/entrypoint.sh +++ b/src/minion/kubernetes/entrypoint.sh @@ -8,7 +8,7 @@ RUNTIME_CONFIG="${CONFIG_DIR}/20-runtime.conf" mkdir -p "$CONFIG_DIR" /etc/salt/pki/minion /var/cache/salt/minion/.socks /var/log/salt # Pre-seed the minion's own RSA keypair when supplied - same pattern as -# salt-minion-vcf/scripts/docker-entrypoint.sh. Only applied when +# src/minion/vcf/entrypoint.sh. Only applied when # minion.pem doesn't already exist, so a restarted/rescheduled container # (persistent PKI volume) keeps its established identity rather than # re-seeding on every start. @@ -93,7 +93,7 @@ elif [ ! -s "$MASTER_CONFIG" ]; then exit 64 fi -# FIPS-compliant crypto defaults - see salt-minion-vcf/scripts/docker-entrypoint.sh +# FIPS-compliant crypto defaults - see src/minion/vcf/entrypoint.sh # for the full rationale (masters running FIPS-validated crypto don't # implement SHA-1 for RSA OAEP/PKCS1v15, which breaks auth with a minion # defaulting to it). Set SALT_FIPS_MODE=false only if your target master is @@ -130,7 +130,7 @@ EOF # Optional Vault integration (saltext.vault): configures the 'vault' auth/ # server block plus an sdb profile so pillar values can reference # sdb://vault_sdb/: instead of containing plaintext secrets. Same -# shape as salt-minion-vcf/scripts/docker-entrypoint.sh. +# shape as src/minion/vcf/entrypoint.sh. if [ -n "${VAULT_ADDR:-}" ]; then if [ -n "${VAULT_SECRET_ID_FILE:-}" ] && [ -f "${VAULT_SECRET_ID_FILE}" ]; then VAULT_SECRET_ID="$(cat "${VAULT_SECRET_ID_FILE}")" diff --git a/src/minion/vcf/Dockerfile b/src/minion/vcf/Dockerfile index ef43e45..26ed53d 100644 --- a/src/minion/vcf/Dockerfile +++ b/src/minion/vcf/Dockerfile @@ -1,22 +1,21 @@ # syntax=docker/dockerfile:1 # -# Self-contained Salt minion image for salt-minion-kubernetes: core Salt plus -# saltext.vault and saltext.kubernetes, both pip-installed from PyPI (same -# pattern as salt-minion-vcf/Dockerfile) rather than requiring a checkout of -# any extension's own repo as build context. +# Self-contained Salt minion image with VCF automation support: core Salt plus +# the extensions in salt-extensions.txt, pip-installed from PyPI (same pattern +# as src/minion/kubernetes/Dockerfile) rather than requiring a checkout of any +# extension's own repo as build context. FROM ubuntu:24.04 ARG DEBIAN_FRONTEND=noninteractive -# Pinned rather than "latest" so a given salt-minion-kubernetes-image release -# tag reproducibly carries one specific Salt version - see CHANGELOG.md. +# Pinned rather than "latest" so a given image release tag reproducibly carries +# one specific Salt version - see helm/salt-minion/CHANGELOG.md. ARG SALT_VERSION=3008.5 ARG SALT_UID=10001 ARG SALT_GID=10001 ARG SALT_HOME=/opt/saltstack/salt ARG SALT_SHELL=/usr/sbin/nologin -# Bundles kubectl directly into the image so the salt-minion-kubernetes chart -# can skip its install-kubectl init container (agent.kubectl.bundled: true). +# Optionally bundles kubectl directly into the image (INCLUDE_KUBECTL). ARG INCLUDE_KUBECTL=true ARG KUBECTL_VERSION=v1.30.2 ARG TARGETARCH @@ -35,8 +34,6 @@ ARG PIP_ONLY_BINARY="" # empty to use the public defaults (Ubuntu's own mirrors, Broadcom's public # Artifactory). ARG APT_MIRROR="" -ARG SALT_GPG_KEY_URL="https://packages.broadcom.com/artifactory/api/security/keypair/SaltProjectKey/public" -ARG SALT_APT_REPO_URL="https://packages.broadcom.com/artifactory/saltproject-deb" LABEL org.opencontainers.image.title="Salt Minion VCF" LABEL org.opencontainers.image.description="Portable Salt Minion runtime with configurable Salt extensions for VMware Cloud Foundation automation" @@ -110,7 +107,7 @@ RUN set -eu; \ rm -f /tmp/salt-extensions.txt /tmp/salt-constraint.txt /tmp/salt-packages.txt # Bundled so this image needs no separate init container to reach the -# Kubernetes API - see salt-minion-kubernetes/values.yaml (agent.kubectl.bundled). +# Kubernetes API. RUN if [ "$INCLUDE_KUBECTL" = "true" ]; then \ set -eu; \ curl -fsSL -o /usr/local/bin/kubectl \ diff --git a/src/minion/vcf/entrypoint.sh b/src/minion/vcf/entrypoint.sh index ab09493..ca6a57e 100755 --- a/src/minion/vcf/entrypoint.sh +++ b/src/minion/vcf/entrypoint.sh @@ -8,7 +8,7 @@ RUNTIME_CONFIG="${CONFIG_DIR}/20-runtime.conf" mkdir -p "$CONFIG_DIR" /etc/salt/pki/minion /var/cache/salt/minion/.socks /var/log/salt # Pre-seed the minion's own RSA keypair when supplied - same pattern as -# salt-minion-vcf/scripts/docker-entrypoint.sh. Only applied when +# src/minion/kubernetes/entrypoint.sh. Only applied when # minion.pem doesn't already exist, so a restarted/rescheduled container # (persistent PKI volume) keeps its established identity rather than # re-seeding on every start. @@ -93,7 +93,7 @@ elif [ ! -s "$MASTER_CONFIG" ]; then exit 64 fi -# FIPS-compliant crypto defaults - see salt-minion-vcf/scripts/docker-entrypoint.sh +# FIPS-compliant crypto defaults - see src/minion/kubernetes/entrypoint.sh # for the full rationale (masters running FIPS-validated crypto don't # implement SHA-1 for RSA OAEP/PKCS1v15, which breaks auth with a minion # defaulting to it). Set SALT_FIPS_MODE=false only if your target master is @@ -130,7 +130,7 @@ EOF # Optional Vault integration (saltext.vault): configures the 'vault' auth/ # server block plus an sdb profile so pillar values can reference # sdb://vault_sdb/: instead of containing plaintext secrets. Same -# shape as salt-minion-vcf/scripts/docker-entrypoint.sh. +# shape as src/minion/kubernetes/entrypoint.sh. if [ -n "${VAULT_ADDR:-}" ]; then if [ -n "${VAULT_SECRET_ID_FILE:-}" ] && [ -f "${VAULT_SECRET_ID_FILE}" ]; then VAULT_SECRET_ID="$(cat "${VAULT_SECRET_ID_FILE}")" From b4b2f5697256782a452c1fa1eff0f213eb5305a2 Mon Sep 17 00:00:00 2001 From: Saifuddin Rangwala Date: Thu, 26 Nov 2026 10:22:24 +0530 Subject: [PATCH 07/10] salt-master: add opt-in hostNetwork so cluster masters survive restarts A master's cluster identity is its `interface`. By default that is the pod IP, which changes on restart, so a restarted master cannot rejoin. agent.cluster.hostNetwork runs the masters on the host network: the identity is the node's IP and a pod that returns to the same node keeps it. Adds hostNetwork, dnsPolicy ClusterFirstWithHostNet and a required pod anti-affinity (one master per node); it needs exactly replicas labelled nodes selected with agent.nodeSelector so a replacement can only land on its own node. Rejected without cluster mode. The entrypoint now identifies itself by POD_NAME (the hostname is the node's under hostNetwork) and drops any peer that resolves to its own address. Tested on a real cluster, 3 masters on 3 nodes: after four restarts (the leader three times among them) the cluster stayed at 3 voters with no learners, leadership failed over and every pod returned on its own node with the same IP. Docs, changelogs and ci.sh updated. Co-Authored-By: Claude Sonnet 5.5 --- README.md | 7 ++- docs/complete-system-test.md | 31 ++++++++++ helm/salt-master/CHANGELOG.md | 15 +++-- helm/salt-master/README.md | 65 ++++++++++++++++----- helm/salt-master/templates/_helpers.tpl | 3 + helm/salt-master/templates/statefulset.yaml | 17 ++++++ helm/salt-master/values.yaml | 18 ++++-- scripts/ci.sh | 6 ++ src/master/CHANGELOG.md | 6 +- src/master/README.md | 5 +- src/master/entrypoint.sh | 9 ++- 11 files changed, 155 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index c52995e..e0e54e5 100644 --- a/README.md +++ b/README.md @@ -48,9 +48,10 @@ and point `agent.image.repository` at the VCF image. - **Cluster** (`true`): a Salt master cluster (Salt 3007+, isolated storage needs 3008+). Needs `agent.replicas >= 2` (use 3 or more). Each master has its own keypair, minions connect to the flat `salt-master` Service, and any - replica can serve any minion. Opt-in. **Known limitation:** a restarted or - rescheduled master pod cannot rejoin the cluster, so treat pod restarts as - unsupported for now (see the master chart README). + replica can serve any minion. Opt-in. **Known limitation:** a master's identity + is its pod IP, so a restarted pod cannot rejoin unless you set + `agent.cluster.hostNetwork` (one master per labelled node; see the master chart + README). The master is a StatefulSet. A release installed from an older chart version that used a Deployment cannot be upgraded in place: reinstall. diff --git a/docs/complete-system-test.md b/docs/complete-system-test.md index c31113b..45c011f 100644 --- a/docs/complete-system-test.md +++ b/docs/complete-system-test.md @@ -281,6 +281,37 @@ cluster identity and changes on restart; a restarted master cannot rejoin and quorum is lost after the second restart. See "Master cluster" in the [master chart README](../helm/salt-master/README.md). +### Scenario 6b: restarts with `hostNetwork` + +To test restarts, run the masters on the host network, one per labelled node: + +```bash +kubectl label node salt-masters=true # exactly 3 nodes +helm upgrade --install salt-master helm/salt-master \ + --namespace salt-master \ + --set agent.cluster.enabled=true \ + --set agent.cluster.hostNetwork=true \ + --set agent.replicas=3 \ + --set-string 'agent.nodeSelector.salt-masters=true' \ + --wait --timeout 10m +``` + +The ports `4505`, `4506` and `4520` must be free on those nodes. Then delete one +pod at a time (including the leader), wait for it to be ready, and run +`salt-run cluster.members` on another master: + +```bash +kubectl -n salt-master delete pod salt-master-0 +kubectl -n salt-master exec salt-master-1 -c salt-master -- salt-run cluster.members +``` + +Expected: the pod returns on the same node with the same IP, `voter_count` stays +`3`, `learner_count` stays `0`, and `unhealthy_voters` is empty. This was run +with 3 masters, restarting pods four times, the leader three times among them. +If a pod does not become ready on the very first start (log line +`Failed to decrypt join-notify`), delete that pod once. Remove the labels when +done (`kubectl label node salt-masters-`). + ## Scenario 7: VCF minion image The VCF image (`src/minion/vcf`, `salt-minion-vcf`) is used through the same minion diff --git a/helm/salt-master/CHANGELOG.md b/helm/salt-master/CHANGELOG.md index 45d05e9..1fcdc19 100644 --- a/helm/salt-master/CHANGELOG.md +++ b/helm/salt-master/CHANGELOG.md @@ -47,11 +47,18 @@ of the image version it happens to default to — check here, not the tag number is used). - Tested: 3 replicas with isolated storage. Not tested: shared storage, minions connecting through the cluster, node failure. -- **Known limitation:** the pod IP is the cluster identity, so a restarted or rescheduled master - joins as a new learner while its old identity stays a dead voter; quorum is lost after the - second restart and a 2-replica cluster cannot recover from any single failure. +- **Known limitation:** by default the pod IP is the cluster identity, so a restarted or + rescheduled master joins as a new learner while its old identity stays a dead voter; quorum is + lost after the second restart and a 2-replica cluster cannot recover from any single failure. `cluster_auto_replace_voters` is left off because it was seen to demote a healthy voter. - Treat pod restarts in cluster mode as unsupported until the node identity can be made stable. +- New opt-in `agent.cluster.hostNetwork`: the masters run on the host network, so a master's + identity is its node's IP and survives a pod restart. It adds `hostNetwork: true`, + `dnsPolicy: ClusterFirstWithHostNet` and a required pod anti-affinity (one master per node), and + needs exactly `agent.replicas` labelled nodes selected with `agent.nodeSelector` so a replacement + pod can only land on its own node. The masters also get `POD_NAME`, because under hostNetwork the + container's hostname is the node's. Tested with 3 masters on 3 nodes: after four restarts, the + leader three times among them, the cluster stayed at 3 voters with no learners. Not tested: a node + failing or draining, `trustedMinions` together with `hostNetwork`, minions through the cluster. - New `agent.image.imagePullSecrets` for pulling the master image from a private registry, and a `keygen` block for the one-time master-key Job: `keygen.image.repository`/`tag`/`pullPolicy`/ `imagePullSecrets` (defaults unchanged, `bitnami/kubectl:latest`) and restricted diff --git a/helm/salt-master/README.md b/helm/salt-master/README.md index 1f54211..b860d74 100644 --- a/helm/salt-master/README.md +++ b/helm/salt-master/README.md @@ -145,6 +145,7 @@ The following table lists the most commonly overridden values. See | `agent.cluster.storageMode` | `isolated` (per-pod PVCs, Salt 3008+) or `shared` (one existing RWX claim). | `isolated` | | `agent.cluster.persistence.storageClassName` / `.accessMode` / `.size` | Per-pod `state` PVC. Empty class = cluster default. | `""` / `ReadWriteOnce` / `5Gi` | | `agent.cluster.sharedStorage.existingClaim` | Existing ReadWriteMany PVC. **Required** when `storageMode=shared`. | `""` | +| `agent.cluster.hostNetwork` | Run the masters on the host network so each master's identity is its node's IP, which survives restarts. One master per node; see "Known limitation: pod restarts". | `false` | | `agent.cluster.keysCacheDriver` | `keys.cache_driver`. Empty = Salt's default (`localfs_key`). | `""` | | `agent.cluster.autoReplaceVoters` | `cluster_auto_replace_voters`. Left off on purpose, see the limitation. | `false` | | `agent.cluster.minVoters` | `cluster_min_voters`. Empty = replicas - 1 (at least 1). Only matters with `autoReplaceVoters`. | `""` | @@ -160,7 +161,7 @@ The following table lists the most commonly overridden values. See | What minions see | one master | independent masters, each is a separate connection | one cluster identity | | Minion `master:` | `salt-master` Service | every pod's headless DNS name, as a list | the flat `salt-master` Service | | Accepted keys | in the pod (lost on pod replacement) unless `trustedMinions` is on | per pod, so use `trustedMinions` | `cluster_pki_dir` (`/etc/salt/pki/cluster`), shared between masters | -| Pod restarts | fine | fine | **not supported**, see below | +| Pod restarts | fine | fine | **only with `agent.cluster.hostNetwork`**, see below | Use classic mode unless you specifically need minions to see one identity with jobs routed between masters. Classic mode with one replica is the simplest @@ -225,9 +226,9 @@ kubectl -n salt-master exec salt-master-0 -c salt-master -- salt-run cluster.mem ### Known limitation: pod restarts -A master's cluster identity is its `interface`, which here is the pod IP, and -Salt 3008.5 has no setting that separates identity from bind address. A pod IP -changes whenever the pod is restarted or rescheduled. What that means in +A master's cluster identity is its `interface`, which by default is the pod IP, +and Salt 3008.5 has no setting that separates identity from bind address. A pod +IP changes whenever the pod is restarted or rescheduled. What that means in practice: - A restarted or rescheduled master joins as a **new** learner and cannot @@ -239,12 +240,36 @@ practice: a healthy voter instead of the dead one, so the chart leaves it off and you should not rely on it. -Until the identity can be made stable (for example `hostNetwork` pinned one pod -per node, or fixed pod IPs), treat pod restarts, node drains and upgrades that -roll the pods in cluster mode as unsupported, and use cluster mode only where -you can accept rebuilding the cluster (reinstall and, if needed, delete the -`state` PVCs) after a restart. Classic mode is not affected. Cluster mode is -opt-in and is not the default. +**Workaround: `agent.cluster.hostNetwork=true`.** The masters then run on the +host network, so a master's identity is its **node's** IP, and a restarted pod +that comes back on the same node keeps its identity. The chart adds a required +pod anti-affinity (one master per node, because each binds the node's ports +`4505`, `4506` and `agent.cluster.poolPort`). A replacement pod only keeps its +identity if it lands on the same node, so: + +1. Label exactly `agent.replicas` nodes, for example + `kubectl label node salt-masters=true`. +2. Select them with `--set-string 'agent.nodeSelector.salt-masters=true'`. + +With exactly as many labelled nodes as masters, the only node a replacement can +go to is the one that was freed. More labelled nodes than masters lets a pod +move to a different node, which is a new identity again. Other requirements: the +three ports must be free on those nodes, and the namespace must allow +`hostNetwork` pods (the `baseline` and `restricted` Pod Security levels do not). + +```bash +helm install salt-master . \ + --set agent.replicas=3 \ + --set agent.cluster.enabled=true \ + --set agent.cluster.hostNetwork=true \ + --set-string 'agent.nodeSelector.salt-masters=true' +``` + +Without `hostNetwork`, treat pod restarts, node drains and upgrades that roll +the pods in cluster mode as unsupported, and use cluster mode only where you can +accept rebuilding the cluster (reinstall and, if needed, delete the `state` +PVCs) after a restart. Classic mode is not affected. Cluster mode is opt-in and +is not the default. ### One release per namespace @@ -254,9 +279,23 @@ names built from the release name. Install at most one release of this chart per ### What was tested -Tested on a real cluster: cluster mode with 3 replicas and isolated storage -(including the pod-restart behaviour described above). **Not tested:** shared storage mode, minions connecting through the cluster, -and node failure. +Tested on a real cluster, cluster mode with 3 replicas and isolated storage: + +- **Default (pod IP identity):** the cluster forms. A restarted pod comes back + with a new IP and cannot rejoin, as described above. +- **With `agent.cluster.hostNetwork=true`** (3 masters on 3 labelled nodes): the + cluster forms with the three node IPs as voters, no master lists itself as a + peer, and after four pod restarts, the leader three times among them, the + membership stayed at 3 voters with no learners and nothing unhealthy. Leadership + moved to another master each time the leader was restarted, and every + restarted pod came back on its own node with the same IP and became ready. On + the first start one master came up as a joiner and did not become ready (log: + `Failed to decrypt join-notify`); deleting that pod fixed it. This was seen once. +- **Classic mode** with 1 replica and a chart-generated key. + +**Not tested:** shared storage mode, `hostNetwork` together with `trustedMinions`, +minions connecting through the cluster, a node failing or being drained so that a +master has to move to another node, and Pod Security admission on the namespace. ## Accessing the masters diff --git a/helm/salt-master/templates/_helpers.tpl b/helm/salt-master/templates/_helpers.tpl index b28075a..7d5c548 100644 --- a/helm/salt-master/templates/_helpers.tpl +++ b/helm/salt-master/templates/_helpers.tpl @@ -58,6 +58,9 @@ app.kubernetes.io/instance: {{ .Release.Name }} {{- if and $c.enabled (lt (int .Values.agent.replicas) 2) -}} {{- fail "agent.cluster.enabled requires agent.replicas >= 2: Salt refuses to start a cluster member that has no peers." -}} {{- end -}} +{{- if and $c.hostNetwork (not $c.enabled) -}} +{{- fail "agent.cluster.hostNetwork requires agent.cluster.enabled." -}} +{{- end -}} {{- if and $c.enabled (eq $c.storageMode "shared") (not $c.sharedStorage.existingClaim) -}} {{- fail "agent.cluster.sharedStorage.existingClaim (a ReadWriteMany PVC) is required when agent.cluster.storageMode=shared." -}} {{- end -}} diff --git a/helm/salt-master/templates/statefulset.yaml b/helm/salt-master/templates/statefulset.yaml index ebe690a..00f746d 100644 --- a/helm/salt-master/templates/statefulset.yaml +++ b/helm/salt-master/templates/statefulset.yaml @@ -29,6 +29,19 @@ spec: app.kubernetes.io/name: salt-master spec: serviceAccountName: {{ .Values.serviceAccount.name }} + {{- if and $cluster.enabled $cluster.hostNetwork }} + # The master's cluster identity is its node's IP (status.podIP of a + # hostNetwork pod). One master per node: they bind the node's ports. + hostNetwork: true + dnsPolicy: ClusterFirstWithHostNet + affinity: + podAntiAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + - labelSelector: + matchLabels: + app: salt-master + topologyKey: kubernetes.io/hostname + {{- end }} {{- with .Values.agent.image.imagePullSecrets }} imagePullSecrets: {{- toYaml . | nindent 8 }} @@ -140,6 +153,10 @@ spec: # which must be its own peer-reachable IP. - name: SALT_CLUSTER_NODE_ADDRESS value: $(POD_IP) + - name: POD_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name - name: SALT_CLUSTER_ID value: {{ include "salt-master.clusterId" . | quote }} - name: SALT_CLUSTER_PEERS diff --git a/helm/salt-master/values.yaml b/helm/salt-master/values.yaml index 595b4a7..ff092d8 100644 --- a/helm/salt-master/values.yaml +++ b/helm/salt-master/values.yaml @@ -89,15 +89,25 @@ agent: # so the restarted pod joins as a NEW learner while its old identity stays # a dead voter. Salt's own recovery, cluster_auto_replace_voters, is OFF by # default and was observed to demote a healthy voter instead of the dead - # one (breaking quorum), so the chart leaves it off. Until this is solved - # (stable node IPs, e.g. hostNetwork pinned per node), treat pod restarts - # as unsupported. Replacing a voter also needs a majority of the current - # voters, so use at least 3 replicas. + # one (breaking quorum), so the chart leaves it off. Use hostNetwork + # (below) so the identity is a stable node IP; without it, treat pod + # restarts as unsupported. Replacing a voter also needs a majority of the + # current voters, so use at least 3 replicas. autoReplaceVoters: false # cluster_min_voters: floor below which Salt will not demote a voter. # Empty = replicas - 1 (at least 1), i.e. one dead voter can always be # replaced (only relevant when autoReplaceVoters is true). minVoters: "" + # Run the masters on the host network so each master's cluster identity is + # its NODE's IP, which survives a pod restart (a pod IP does not; see the + # known limitation). Needs agent.cluster.enabled. Each master then binds the + # node's ports 4505, 4506 and poolPort, so the chart adds a required pod + # anti-affinity (one master per node). A replacement pod keeps the same + # identity only if it lands on the SAME node, so label exactly `replicas` + # nodes and select them with agent.nodeSelector: then the only node a + # replacement can go to is the one that was freed. hostNetwork pods are + # blocked by the "baseline" and "restricted" Pod Security levels. + hostNetwork: false # keys.cache_driver for the cluster key store. Empty = Salt's default # (localfs_key). Salt recommends mmap_key for isolated mode, but see the # chart CHANGELOG: it failed to read its own keys back on Longhorn PVCs. diff --git a/scripts/ci.sh b/scripts/ci.sh index 9c8f401..b073fd0 100755 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -123,6 +123,12 @@ helm_template "salt-master-multi" helm/salt-master \ helm_template "salt-master-cluster" helm/salt-master \ --set agent.cluster.enabled=true \ --set agent.replicas=3 +helm_template "salt-master-cluster-hostnetwork" helm/salt-master \ + --set agent.cluster.enabled=true \ + --set agent.cluster.hostNetwork=true \ + --set agent.replicas=3 +helm_template_fails "salt-master hostNetwork without cluster mode" helm/salt-master \ + --set agent.cluster.hostNetwork=true helm_template_fails "salt-master replicas>1 without a shared key" helm/salt-master \ --set agent.replicas=2 helm_template_fails "salt-master cluster with one replica" helm/salt-master \ diff --git a/src/master/CHANGELOG.md b/src/master/CHANGELOG.md index d121701..c0d29c1 100644 --- a/src/master/CHANGELOG.md +++ b/src/master/CHANGELOG.md @@ -22,8 +22,12 @@ assuming. none resolve. `SALT_CLUSTER_NODE_ADDRESS` is written as `interface:` and, unless `SALT_MASTER_ID` is set, also as the master `id:` (Salt uses `interface` as the consensus node identity). +- The entrypoint identifies itself by `POD_NAME` (falling back to the hostname) and also drops any + peer that resolves to its own `SALT_CLUSTER_NODE_ADDRESS`, so it never lists itself as a peer. + This matters with `hostNetwork`, where the container's hostname is the node's, not the pod's. - Known limitation: with the pod IP as cluster identity, a restarted master cannot rejoin its - cluster (see the chart CHANGELOG). Classic (non-cluster) use is unaffected. + cluster; the chart's `agent.cluster.hostNetwork` makes the identity a stable node IP (see the chart + CHANGELOG). Classic (non-cluster) use is unaffected. - Behaviour without `SALT_CLUSTER_ID` is unchanged (user 10001, health check on ports 4505/4506). diff --git a/src/master/README.md b/src/master/README.md index 88a13ae..f12e9d5 100644 --- a/src/master/README.md +++ b/src/master/README.md @@ -212,6 +212,7 @@ setting `SALT_CLUSTER_ID`. The entrypoint then writes `/etc/salt/master.d/98-clu | `SALT_CLUSTER_ID` | Sets `cluster_id` and turns cluster mode on. Unset = classic master. | | `SALT_CLUSTER_PEERS` | Comma-separated peer host names. The entry whose short name equals this host's name is dropped, and each remaining one is resolved to an IP for `cluster_peers`. At least one peer must resolve or the container exits with an error. | | `SALT_CLUSTER_PEER_WAIT_SECONDS` | How long to wait for all peer names to resolve before continuing with those that did. Default `120`. | +| `POD_NAME` | This pod's name, used to drop the master's own entry from the peer list (default: the short hostname, which is the node's name under `hostNetwork`). The chart sets it from the downward API. | | `SALT_CLUSTER_NODE_ADDRESS` | This master's own peer-reachable IP. Written as `interface:`, and as `id:` unless `SALT_MASTER_ID` is set. Salt uses `interface` as the node identity in cluster consensus, so it must be a real IP, not `0.0.0.0`. | | `SALT_CLUSTER_SECRET` | Sets `cluster_secret`, which authenticates masters joining the cluster. | | `SALT_CLUSTER_PKI_DIR` | Sets `cluster_pki_dir`. Default `/etc/salt/pki/cluster`. | @@ -224,7 +225,9 @@ setting `SALT_CLUSTER_ID`. The entrypoint then writes `/etc/salt/master.d/98-clu Known limitation: Salt 3008.5 identifies a cluster member by its `interface`, so `SALT_CLUSTER_NODE_ADDRESS` is the member's identity. If a member restarts with a different IP (as a Kubernetes pod does), it joins as a new member and its old identity remains a dead voter, so -restarting members of a running cluster is not supported. Cluster mode needs at least two members; +restarting members of a running cluster only works when each member keeps its IP: for example +when it runs on the host network and always returns to the same node (the chart's +`agent.cluster.hostNetwork`). Cluster mode needs at least two members; use three or more. Without `SALT_CLUSTER_ID` the image behaves as a classic single master. Additional configuration, pillar and state trees can be mounted as read-only volumes: diff --git a/src/master/entrypoint.sh b/src/master/entrypoint.sh index c9bc87a..691e5d4 100644 --- a/src/master/entrypoint.sh +++ b/src/master/entrypoint.sh @@ -47,6 +47,9 @@ fi # https://docs.saltproject.io/en/3008/topics/tutorials/master-cluster.html # # SALT_CLUSTER_ID cluster_id +# POD_NAME this pod's name (used to drop itself from the +# peer list; the hostname is the node's under +# hostNetwork) # SALT_CLUSTER_NODE_ADDRESS this master's own IP, written as `interface:`. # Salt uses `interface` as the node identity # in the consensus layer and matches it @@ -68,7 +71,9 @@ fi if [ -n "${SALT_CLUSTER_ID:-}" ]; then CLUSTER_CONF="$CONF_DIR/98-cluster.conf" PEER_IPS="" - SELF="$(hostname -s 2>/dev/null || hostname)" + # With hostNetwork the container's hostname is the NODE's, not the pod's, + # so identify this pod by POD_NAME when it is set. + SELF="${POD_NAME:-$(hostname -s 2>/dev/null || hostname)}" IFS=',' read -r -a PEER_HOSTS <<< "${SALT_CLUSTER_PEERS:-}" @@ -88,6 +93,8 @@ if [ -n "${SALT_CLUSTER_ID:-}" ]; then # getent exits 2 for an unknown host; don't let pipefail/-e kill us. ip="$(getent hosts "$peer" | awk '{print $1; exit}' || true)" + # Never list ourselves as a peer, whatever the name resolves to. + [ "$ip" != "${SALT_CLUSTER_NODE_ADDRESS:-}" ] || continue if [ -n "$ip" ]; then PEER_IPS="$PEER_IPS $ip" else From fc9fd92296052897b62598601123bf89cec91d53 Mon Sep 17 00:00:00 2001 From: Saifuddin Rangwala Date: Thu, 26 Nov 2026 10:55:10 +0530 Subject: [PATCH 08/10] salt-key-operator: watch the release namespace by default watchNamespace defaulted to "salt-master". The operator's Role and RoleBinding were created in that namespace, but its Deployment goes into the release namespace, so installing the salt-master chart (which bundles this chart) with defaults into any other namespace failed with `namespaces "salt-master" not found` and left a half-installed release. watchNamespace now defaults to the release namespace (empty), and cluster-wide watching is the explicit `clusterWide: true` (it used to be watchNamespace: ""). The salt-master chart prints a warning in its notes when the release namespace differs from `namespace` while trusted minions are enabled. Docs, changelog and ci.sh updated. Found by installing the master chart with its defaults on a real cluster. Re-tested: the default install, and a 3-replica classic multi-master install with a shared key, both work end to end (a SaltMinionKey is accepted, and removed again, on every master). Co-Authored-By: Claude Sonnet 5.5 --- helm/salt-key-operator/CHANGELOG.md | 7 ++++++ helm/salt-key-operator/templates/NOTES.txt | 10 ++++---- helm/salt-key-operator/templates/_helpers.tpl | 11 +++++++++ .../templates/deployment.yaml | 4 ++-- helm/salt-key-operator/templates/rbac.yaml | 17 ++++++------- helm/salt-key-operator/values.yaml | 24 ++++++++++--------- helm/salt-master/README.md | 8 +++++++ helm/salt-master/templates/NOTES.txt | 8 +++++++ scripts/ci.sh | 1 + src/master/README.md | 2 -- src/salt-key-operator/README.md | 7 +++--- 11 files changed, 68 insertions(+), 31 deletions(-) create mode 100644 helm/salt-key-operator/templates/_helpers.tpl diff --git a/helm/salt-key-operator/CHANGELOG.md b/helm/salt-key-operator/CHANGELOG.md index 07090d2..2ae0cbd 100644 --- a/helm/salt-key-operator/CHANGELOG.md +++ b/helm/salt-key-operator/CHANGELOG.md @@ -7,6 +7,13 @@ version is independent of the image version it happens to default to — check here, not the tag number. ## Unreleased +- **`watchNamespace` now defaults to the release namespace** (empty), not the fixed `salt-master`, + and cluster-wide watching is the explicit `clusterWide: true` (it used to be `watchNamespace: ""`). + The Deployment goes into the release namespace but the Role and RoleBinding went into + `watchNamespace`, so installing the salt-master chart, which bundles this chart, into any other + namespace failed with `namespaces "salt-master" not found` and left a half-installed release. + Found by installing the master chart with its defaults on a real cluster. Installing into a + namespace named `salt-master` behaves as before. - The default image repository is now `ghcr.io/saltstack/salt-key-operator`, where the image workflow publishes. The previous default, `ghcr.io/saltstack/salt-kubernetes/salt-key-operator`, does not exist. diff --git a/helm/salt-key-operator/templates/NOTES.txt b/helm/salt-key-operator/templates/NOTES.txt index bb411ff..0131b06 100644 --- a/helm/salt-key-operator/templates/NOTES.txt +++ b/helm/salt-key-operator/templates/NOTES.txt @@ -9,12 +9,12 @@ minions ConfigMap already exists. On the salt-master side, install/upgrade that chart with: agent.trustedMinions.enabled=true -{{- if .Values.watchNamespace }} +{{- with include "salt-key-operator.watchNamespace" . }} -This operator only watches namespace "{{ .Values.watchNamespace }}" -(watchNamespace) - make sure that's where your salt-master -release and SaltMinionKey objects live, or set watchNamespace="" for -cluster-wide watching instead. +This operator only watches namespace "{{ . }}" (the release namespace unless +watchNamespace is set) - make sure that's where your salt-master release and +SaltMinionKey objects live, or set clusterWide=true for cluster-wide watching +instead. {{- end }} To trust a minion (replacing `salt-key -a `), apply a diff --git a/helm/salt-key-operator/templates/_helpers.tpl b/helm/salt-key-operator/templates/_helpers.tpl new file mode 100644 index 0000000..3030c4f --- /dev/null +++ b/helm/salt-key-operator/templates/_helpers.tpl @@ -0,0 +1,11 @@ +{{/* +The namespace the operator watches, and where its Role/RoleBinding live. +Empty means cluster-wide (ClusterRole). By default this is the namespace the +release is installed into; watchNamespace overrides it, and clusterWide: true +selects cluster-wide watching. +*/}} +{{- define "salt-key-operator.watchNamespace" -}} +{{- if not .Values.clusterWide -}} +{{- .Values.watchNamespace | default .Release.Namespace -}} +{{- end -}} +{{- end -}} diff --git a/helm/salt-key-operator/templates/deployment.yaml b/helm/salt-key-operator/templates/deployment.yaml index a1f2797..cf104a5 100644 --- a/helm/salt-key-operator/templates/deployment.yaml +++ b/helm/salt-key-operator/templates/deployment.yaml @@ -30,8 +30,8 @@ spec: {{- if .Values.leaderElection.enabled }} - --leader-elect {{- end }} - {{- if .Values.watchNamespace }} - - --namespace={{ .Values.watchNamespace }} + {{- with include "salt-key-operator.watchNamespace" . }} + - --namespace={{ . }} {{- end }} ports: - name: healthz diff --git a/helm/salt-key-operator/templates/rbac.yaml b/helm/salt-key-operator/templates/rbac.yaml index cd4990d..897ad5b 100644 --- a/helm/salt-key-operator/templates/rbac.yaml +++ b/helm/salt-key-operator/templates/rbac.yaml @@ -8,17 +8,18 @@ # `helm template`/`helm lint` step will not catch a drifted copy, so treat # updating this file as part of any RBAC-marker change, not optional. # -# Namespaced Role/RoleBinding when watchNamespace is set (the default, -# "salt-master") - the smallest footprint this operator can run with, since -# it only ever touches objects in that one namespace. Falls back to a -# cluster-wide ClusterRole/ClusterRoleBinding only when watchNamespace is -# explicitly cleared for a genuine multi-tenant deployment. -{{- if .Values.watchNamespace }} +# Namespaced Role/RoleBinding in the watched namespace (by default the namespace +# the release is installed into) - the smallest footprint this operator can run +# with, since it only ever touches objects in that one namespace. Falls back to a +# cluster-wide ClusterRole/ClusterRoleBinding only when clusterWide is set for a +# genuine multi-tenant deployment. +{{- $watch := include "salt-key-operator.watchNamespace" . }} +{{- if $watch }} apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: salt-key-operator - namespace: {{ .Values.watchNamespace }} + namespace: {{ $watch }} labels: app.kubernetes.io/name: salt-key-operator app.kubernetes.io/managed-by: {{ .Release.Service }} @@ -47,7 +48,7 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: salt-key-operator - namespace: {{ .Values.watchNamespace }} + namespace: {{ $watch }} labels: app.kubernetes.io/name: salt-key-operator app.kubernetes.io/managed-by: {{ .Release.Service }} diff --git a/helm/salt-key-operator/values.yaml b/helm/salt-key-operator/values.yaml index 5dca4ba..a118244 100644 --- a/helm/salt-key-operator/values.yaml +++ b/helm/salt-key-operator/values.yaml @@ -14,17 +14,19 @@ image: # Bump this only alongside leaderElection.enabled below. replicas: 1 -# Restricts the operator's watches to a single namespace - and, as long as -# this matches the namespace the operator itself is installed into (the -# recommended setup - see README.md and salt-master's own -# namespace default), also switches RBAC from a cluster-wide ClusterRole to -# a namespaced Role, the smallest footprint this operator can run with. -# Defaults to "salt-master" to match salt-master's own default -# namespace - install both charts into the same namespace and everything -# lines up with no further configuration. Set to "" (cluster-wide) only for -# a genuine multi-tenant cluster with SaltMinionKey objects and target -# master releases spread across multiple namespaces. -watchNamespace: salt-master +# Restricts the operator's watches to a single namespace, and gives it a +# namespaced Role (in that namespace) instead of a cluster-wide ClusterRole: +# the smallest footprint this operator can run with. Empty (the default) means +# the namespace this release is installed into, so installing the operator +# (or the salt-master chart that bundles it) into the namespace of the +# salt-master release needs no further configuration. Set it only to watch a +# different single namespace. +watchNamespace: "" + +# Watch every namespace, with a ClusterRole, instead of a single one. Only for a +# genuine multi-tenant cluster with SaltMinionKey objects and target master +# releases spread across namespaces. Takes precedence over watchNamespace. +clusterWide: false # Leader election exists to let >1 operator replica run without split-brain # writers - irrelevant, and pure overhead, at the default replicas: 1. diff --git a/helm/salt-master/README.md b/helm/salt-master/README.md index b860d74..42a0b52 100644 --- a/helm/salt-master/README.md +++ b/helm/salt-master/README.md @@ -378,6 +378,14 @@ Two ways to accept a minion's key, mutually exclusive per release: explicitly rejects symlinks in its key store - confirmed by live testing, see [`CHANGELOG.md`](CHANGELOG.md).) This is intentional, not a bug. Allow about a minute for kubelet's ConfigMap propagation plus the sync interval. + + **Install into the namespace the masters use.** The bundled operator is deployed + into the release namespace and, by default, watches only that namespace, but the + master's objects (and so the trusted-minions ConfigMap) go into `namespace`. Install + with `helm install ... --namespace --set namespace=` (the + default `namespace` is `salt-master`). If they differ, the post-install notes show a + warning; fix it by reinstalling with the right `--namespace`, or set + `salt-key-operator.watchNamespace=`. - **Traditional** (`agent.trustedMinions.enabled: false`): `salt-key -a` against a pod. ```bash diff --git a/helm/salt-master/templates/NOTES.txt b/helm/salt-master/templates/NOTES.txt index f4e2ddb..51ba92f 100644 --- a/helm/salt-master/templates/NOTES.txt +++ b/helm/salt-master/templates/NOTES.txt @@ -37,6 +37,14 @@ List known minion keys: -- salt-key -L {{- if .Values.agent.trustedMinions.enabled }} +{{- if ne .Release.Namespace .Values.namespace }} + +WARNING: this release was installed into namespace "{{ .Release.Namespace }}", but the +salt-master objects are in "{{ .Values.namespace }}". The bundled salt-key-operator is deployed +into the release namespace and watches it by default, so it will not see the master's +trusted-minions ConfigMap. Reinstall with --namespace {{ .Values.namespace }}, or set +salt-key-operator.watchNamespace={{ .Values.namespace }}. +{{- end }} Minion trust is managed declaratively by salt-key-operator. diff --git a/scripts/ci.sh b/scripts/ci.sh index b073fd0..3f0162f 100755 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -136,6 +136,7 @@ helm_template_fails "salt-master cluster with one replica" helm/salt-master \ # Operator chart template (include CRDs) helm_template "salt-key-operator" helm/salt-key-operator --include-crds +helm_template "salt-key-operator-clusterwide" helm/salt-key-operator --set clusterWide=true # Minion chart: one minion, one key pair per pod, and several masters helm_template "salt-minion-single" helm/salt-minion \ diff --git a/src/master/README.md b/src/master/README.md index f12e9d5..930d42d 100644 --- a/src/master/README.md +++ b/src/master/README.md @@ -364,7 +364,6 @@ helm template salt-master \ --set salt-key-operator.image.repository=salt-key-operator \ --set salt-key-operator.image.tag=local \ --set salt-key-operator.image.pullPolicy=Never \ - --set salt-key-operator.watchNamespace=salt-master \ > /tmp/salt-master-rendered.yaml ``` @@ -392,7 +391,6 @@ helm upgrade --install salt-master \ --set salt-key-operator.image.repository=salt-key-operator \ --set salt-key-operator.image.tag=local \ --set salt-key-operator.image.pullPolicy=Never \ - --set salt-key-operator.watchNamespace=salt-master \ --wait \ --wait-for-jobs \ --timeout 5m diff --git a/src/salt-key-operator/README.md b/src/salt-key-operator/README.md index 6b995eb..838ed56 100644 --- a/src/salt-key-operator/README.md +++ b/src/salt-key-operator/README.md @@ -111,10 +111,11 @@ that entirely: creating one `SaltMinionKey` object gets a minion trusted by - **RBAC is the single biggest new attack-surface item this component adds to the repo** - nothing else here touches ConfigMaps or a custom API group (and, per the point above, this design needs no Secret access at - all). The chart defaults `watchNamespace: salt-master` - matching - `salt-master`'s own default namespace - which scopes RBAC down + all). By default the chart watches the namespace the release is + installed into (`watchNamespace` empty; install the operator, or the salt-master + chart that bundles it, into the salt-master namespace), which scopes RBAC down to a namespaced `Role`/`RoleBinding` in just that namespace, not a - cluster-wide `ClusterRole`. Set `watchNamespace: ""` only for a genuine + cluster-wide `ClusterRole`. Set `clusterWide: true` only for a genuine multi-tenant cluster with target master releases spread across multiple namespaces - that falls back to `ClusterRole`/`ClusterRoleBinding`, since `SaltMinionKey` objects and their target ConfigMaps could then be From 3dd66acda626ff5c532df172e87eeaa70283f881 Mon Sep 17 00:00:00 2001 From: Saifuddin Rangwala Date: Thu, 26 Nov 2026 11:39:12 +0530 Subject: [PATCH 09/10] Use the package name salt-minion for the Kubernetes minion image tag The Kubernetes minion image is published as salt-minion and the chart tag is chart-salt-minion-vX, so tag the image salt-minion-vX.Y.Z, not salt-minion-kubernetes-vX.Y.Z. That tag prefix also matches salt-minion-vcf-v* tags, which would start the Kubernetes workflow as well. The workflow now matches salt-minion-v[0-9]*, so a digit has to follow the "v" and only the VCF workflow runs for a salt-minion-vcf-vX tag. scripts/release-docker-tags.sh creates the same tag. Docs, the minion changelog and stale comments that still named the old chart updated. The managed_by grain value is left unchanged: it is a runtime value that external states may target. Co-Authored-By: Claude Sonnet 5.5 --- .../workflows/release-docker-minion-k8s.yml | 5 +++-- docs/releasing.md | 21 +++++++++++-------- helm/salt-minion/CHANGELOG.md | 7 +++++-- scripts/release-docker-tags.sh | 2 +- src/master/Dockerfile | 2 +- src/minion/kubernetes/entrypoint.sh | 2 +- src/minion/vcf/entrypoint.sh | 2 +- 7 files changed, 24 insertions(+), 17 deletions(-) diff --git a/.github/workflows/release-docker-minion-k8s.yml b/.github/workflows/release-docker-minion-k8s.yml index a4c7d33..db7465a 100644 --- a/.github/workflows/release-docker-minion-k8s.yml +++ b/.github/workflows/release-docker-minion-k8s.yml @@ -3,7 +3,8 @@ name: Release Docker - Salt Minion K8s on: push: tags: - - 'salt-minion-kubernetes-v*' + # A digit must follow the "v" so salt-minion-vcf-v* tags do not match. + - 'salt-minion-v[0-9]*' schedule: - cron: '0 3 * * 1' # Every Monday at 3:00 AM UTC workflow_dispatch: @@ -30,7 +31,7 @@ jobs: run: | if [[ "${{ github.ref }}" == refs/tags/* ]]; then TAG_NAME=${GITHUB_REF#refs/tags/} - VERSION=${TAG_NAME#salt-minion-kubernetes-v} + VERSION=${TAG_NAME#salt-minion-v} echo "is_tag=true" >> $GITHUB_OUTPUT else VERSION="latest" diff --git a/docs/releasing.md b/docs/releasing.md index c213d05..1edf106 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -19,7 +19,7 @@ and add the release heading before tagging; nothing enforces it. | Component | Source | Tag to push | Published as | | --- | --- | --- | --- | | Master | `src/master` | `salt-master-vX.Y.Z` | `ghcr.io//salt-master:X.Y.Z` and `:latest` | -| Minion (Kubernetes) | `src/minion/kubernetes` | `salt-minion-kubernetes-vX.Y.Z` | `ghcr.io//salt-minion:X.Y.Z` and `:latest` | +| Minion (Kubernetes) | `src/minion/kubernetes` | `salt-minion-vX.Y.Z` | `ghcr.io//salt-minion:X.Y.Z` and `:latest` | | Minion (VCF) | `src/minion/vcf` | `salt-minion-vcf-vX.Y.Z` | `ghcr.io//salt-minion-vcf:X.Y.Z` and `:latest` | | Key operator | `src/salt-key-operator` | `salt-key-operator-vX.Y.Z` | `ghcr.io//salt-key-operator:X.Y.Z` and `:latest` | @@ -87,17 +87,20 @@ anonymous `docker pull` and `helm pull` fail. ## Tag names and default images -- Each tag prefix is distinct (`salt-minion-kubernetes-v`, `salt-minion-vcf-v`, - `salt-master-v`, `salt-key-operator-v`, and the `chart-salt-*-v` chart tags), so - one tag starts exactly one workflow. `scripts/release-docker-tags.sh` and - `scripts/release-helm-tags.sh` create these same tag names. +- Image and chart tags use the package name: `salt-minion-vX.Y.Z` for the image and + `chart-salt-minion-vX.Y.Z` for the chart (likewise `salt-master-`, `salt-key-operator-` + and `salt-minion-vcf-`). The Kubernetes minion workflow matches `salt-minion-v[0-9]*`: + a digit has to follow the `v`, so a `salt-minion-vcf-vX.Y.Z` tag starts only the VCF + workflow. Each tag therefore starts exactly one workflow. + `scripts/release-docker-tags.sh` and `scripts/release-helm-tags.sh` create these same + tag names. - The default image repositories in the charts point at where the image workflows publish: `ghcr.io/saltstack/salt-minion`, `ghcr.io/saltstack/salt-minion-vcf` and `ghcr.io/saltstack/salt-key-operator`. A default only works once an image with that tag has been released (and its package made public, see above); the master chart's default repository is the unqualified `salt-master` on purpose, so a locally built image can be used as is. -- Before the tag fix, the `salt-minion-kubernetes-v0.1.0` tag matched no workflow, - so no Kubernetes minion image was published for it. Releasing the minion image - needs a new tag (for example `salt-minion-kubernetes-v0.1.2`, see the minion - image changelog). +- The tag `salt-minion-kubernetes-v0.1.0` that already exists on the remote matches no + workflow, so no Kubernetes minion image was ever published for it. Release the + Kubernetes minion image with a new `salt-minion-vX.Y.Z` tag (for example + `salt-minion-v0.1.2`, see the minion image changelog). diff --git a/helm/salt-minion/CHANGELOG.md b/helm/salt-minion/CHANGELOG.md index 3415f70..26f1867 100644 --- a/helm/salt-minion/CHANGELOG.md +++ b/helm/salt-minion/CHANGELOG.md @@ -2,7 +2,9 @@ Image and chart in this directory publish under separate release tags (see [`docs/releasing.md`](../../docs/releasing.md)) but neither tag encodes the Salt/extension -versions it carries — check here. +versions it carries — check here. The release tags are `salt-minion-vX.Y.Z` for the image and +`chart-salt-minion-vX.Y.Z` for the chart; the headings below use the older +`salt-minion-image/vX.Y.Z` and `salt-minion-chart/vX.Y.Z` naming. ## Image releases (`salt-minion-image/vX.Y.Z`) @@ -98,7 +100,8 @@ Applies to both `src/minion/kubernetes` and `src/minion/vcf`. - The default image repository is now `ghcr.io/saltstack/salt-minion`, where the image workflow publishes. The previous default, `ghcr.io/saltstack/salt-kubernetes/salt-minion`, does not exist. The `0.1.0` tag at the new path exists only once the Kubernetes minion image has been - released (the workflow now triggers on `salt-minion-kubernetes-v*`; see `docs/releasing.md`). + released (the workflow's tag pattern now matches `salt-minion-vX.Y.Z` and no longer also matches the + `salt-minion-vcf-v*` tags; see `docs/releasing.md`). - Removed the unused `scripts/` copies of the entrypoint scripts and `salt-extensions.txt` from the chart (the images read the files under `src/minion/`). `Chart.yaml` now describes a StatefulSet. diff --git a/scripts/release-docker-tags.sh b/scripts/release-docker-tags.sh index 472b6e5..b16c167 100755 --- a/scripts/release-docker-tags.sh +++ b/scripts/release-docker-tags.sh @@ -34,7 +34,7 @@ fi # 4. Map Tag Entities TAG_MASTER="salt-master-v${MASTER_VER}" -TAG_MINION_K8S="salt-minion-kubernetes-v${MINION_K8S_VER}" +TAG_MINION_K8S="salt-minion-v${MINION_K8S_VER}" TAG_MINION_VCF="salt-minion-vcf-v${MINION_VCF_VER}" TAG_OPERATOR="salt-key-operator-v${OPERATOR_VER}" diff --git a/src/master/Dockerfile b/src/master/Dockerfile index 06ee418..f630252 100644 --- a/src/master/Dockerfile +++ b/src/master/Dockerfile @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 # -# Master-only counterpart to the salt-minion-vcf/salt-minion-kubernetes +# Master-only counterpart to the salt-minion and salt-minion-vcf # minion images. Deliberately minimal: unlike either minion variant, this # image doesn't need any Salt extensions (execution/state modules run on # minions, not the master) or kubectl (the master never talks to a cluster diff --git a/src/minion/kubernetes/entrypoint.sh b/src/minion/kubernetes/entrypoint.sh index 161b7e8..f85772a 100755 --- a/src/minion/kubernetes/entrypoint.sh +++ b/src/minion/kubernetes/entrypoint.sh @@ -108,7 +108,7 @@ EOF fi # Deliberately does NOT set pillar_roots or touch /srv/pillar: the -# salt-minion-kubernetes chart's kube_bench.sls ConfigMap is consumed via the +# salt-minion chart's kube_bench.sls ConfigMap is consumed via the # Master's own pillar_roots (see chart README "kube-bench coordination"), not # a local pillar tree - unlike salt-minion-vcf, which is meant to run # disconnected enough to need one. diff --git a/src/minion/vcf/entrypoint.sh b/src/minion/vcf/entrypoint.sh index ca6a57e..fad8672 100755 --- a/src/minion/vcf/entrypoint.sh +++ b/src/minion/vcf/entrypoint.sh @@ -108,7 +108,7 @@ EOF fi # Deliberately does NOT set pillar_roots or touch /srv/pillar: the -# salt-minion-kubernetes chart's kube_bench.sls ConfigMap is consumed via the +# salt-minion chart's kube_bench.sls ConfigMap is consumed via the # Master's own pillar_roots (see chart README "kube-bench coordination"), not # a local pillar tree - unlike salt-minion-vcf, which is meant to run # disconnected enough to need one. From 011aff1ab176774a988ba6b8e94555aedbf0afd8 Mon Sep 17 00:00:00 2001 From: Saifuddin Rangwala Date: Thu, 26 Nov 2026 11:54:29 +0530 Subject: [PATCH 10/10] minion images: name the managed_by grain after the package The entrypoints set the grain managed_by: salt-minion-kubernetes, the old chart name. Use salt-minion, the package name, in both the Kubernetes and the VCF image (the VCF image is run through the salt-minion chart too). Behaviour change: any states or targeting that match the old grain value need updating; noted in the minion image changelog. Checked by running both entrypoints against a stub salt-minion and reading the generated config. Co-Authored-By: Claude Sonnet 5.5 --- helm/salt-minion/CHANGELOG.md | 3 +++ src/minion/kubernetes/entrypoint.sh | 2 +- src/minion/vcf/entrypoint.sh | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/helm/salt-minion/CHANGELOG.md b/helm/salt-minion/CHANGELOG.md index 26f1867..87a2bd8 100644 --- a/helm/salt-minion/CHANGELOG.md +++ b/helm/salt-minion/CHANGELOG.md @@ -30,6 +30,9 @@ Applies to both `src/minion/kubernetes` and `src/minion/vcf`. - Extensions are unchanged: `saltext.kubernetes==2.1.0`, `saltext.vault==1.8.0` in both images, plus `saltext.vcf==1.0.0` and `saltext.bmc==0.0.1` in the VCF image. +- **Behaviour change:** the `managed_by` grain that both entrypoints set is now `salt-minion` + (it was `salt-minion-kubernetes`, the old chart name), matching the package name. Update any + states or targeting that match `managed_by: salt-minion-kubernetes`. - Removed the unused `SALT_GPG_KEY_URL` and `SALT_APT_REPO_URL` build arguments, and corrected comments that still named the old chart and file paths. diff --git a/src/minion/kubernetes/entrypoint.sh b/src/minion/kubernetes/entrypoint.sh index f85772a..c49c6d4 100755 --- a/src/minion/kubernetes/entrypoint.sh +++ b/src/minion/kubernetes/entrypoint.sh @@ -124,7 +124,7 @@ pidfile: /var/cache/salt/minion/minion.pid sock_dir: /var/cache/salt/minion/.socks grains: - managed_by: salt-minion-kubernetes + managed_by: salt-minion EOF # Optional Vault integration (saltext.vault): configures the 'vault' auth/ diff --git a/src/minion/vcf/entrypoint.sh b/src/minion/vcf/entrypoint.sh index fad8672..b92eb57 100755 --- a/src/minion/vcf/entrypoint.sh +++ b/src/minion/vcf/entrypoint.sh @@ -124,7 +124,7 @@ pidfile: /var/cache/salt/minion/minion.pid sock_dir: /var/cache/salt/minion/.socks grains: - managed_by: salt-minion-kubernetes + managed_by: salt-minion EOF # Optional Vault integration (saltext.vault): configures the 'vault' auth/