Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions helm/salt-minion/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Selected via `agent.authMode`:
- 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`.
- Persistent storage (optional, for PKI persistence)

## Quick Start
Expand All @@ -51,6 +52,7 @@ Selected via `agent.authMode`:
```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
Expand All @@ -73,6 +75,7 @@ kubectl create token salt-minion -n salt

```bash
helm install salt-minion ./helm/salt-minion \
--set agent.minion.allowSelfGeneratedKey=true \
--namespace salt \
--create-namespace \
--set agent.saltMasterHost=salt-master.example.com
Expand All @@ -84,6 +87,7 @@ For production, enable PKI persistence to maintain minion identity across restar

```bash
helm install salt-minion ./helm/salt-minion \
--set agent.minion.allowSelfGeneratedKey=true \
--namespace salt \
--create-namespace \
--set agent.saltMasterHost=salt-master.example.com \
Expand All @@ -97,6 +101,7 @@ 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 \
Expand All @@ -110,6 +115,7 @@ Connect to multiple masters simultaneously:

```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}'
Expand Down Expand Up @@ -184,10 +190,18 @@ See [values.yaml](values.yaml) for the complete list of configuration options.
| --- | --- | --- |
| `namespace` | Kubernetes namespace for deployment | `salt` |
| `agent.authMode` | `in_cluster` or `external` | `in_cluster` |
| `agent.minion.keySecretName` | Key Secret name. Uses an existing Secret unless `privateKeyB64` and `publicKeyB64` are supplied to create it. Empty uses `<release-name>-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` | Pod security context shared by the minion and key-preparation init container | See [values.yaml](values.yaml) |
| `agent.containerSecurityContext` | Container security context applied to both the minion and key-preparation init container | See [values.yaml](values.yaml) |
| `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.podSecurityContext` | Pod security context for the key-generation Job | See [values.yaml](values.yaml) |
| `keygen.containerSecurityContext` | Container security context for key generation | See [values.yaml](values.yaml) |
| `keygen.image.repository` | Keygen image repository | `bitnami/kubectl` |
| `keygen.image.tag` | Keygen image tag | `latest` |
| `keygen.image.pullPolicy` | Keygen image pull policy | `Always` |
Expand All @@ -214,6 +228,7 @@ Requires a StorageClass:

```bash
helm install salt-minion ./helm/salt-minion \
--set agent.minion.allowSelfGeneratedKey=true \
--set agent.persistence.enabled=true \
--set agent.persistence.type=pvc \
--set agent.persistence.size=1Gi
Expand All @@ -223,6 +238,7 @@ Or use an existing PVC:

```bash
helm install salt-minion ./helm/salt-minion \
--set agent.minion.allowSelfGeneratedKey=true \
--set agent.persistence.enabled=true \
--set agent.persistence.pvc.existingClaim=my-pvc
```
Expand All @@ -233,6 +249,7 @@ For clusters without dynamic provisioning:

```bash
helm install salt-minion ./helm/salt-minion \
--set agent.minion.allowSelfGeneratedKey=true \
--set agent.persistence.enabled=true \
--set agent.persistence.type=hostPath \
--set agent.persistence.hostPath.path=/var/lib/salt-minion/pki \
Expand Down Expand Up @@ -261,19 +278,23 @@ credentials:

### Key Management

Provide the minion keypair using one of these options:

- Set `agent.minion.keySecretName` to an existing Secret containing `minion.pem` (private key) and `minion.pub` (public key), both as PEM text.
- Set `agent.minion.privateKeyB64` and `agent.minion.publicKeyB64` together to have the chart create a Secret from base64-encoded PEM values.
- Set `agent.minion.allowSelfGeneratedKey=true` to generate a keypair when none is supplied.

The Salt master must trust the minion's public key. After changing the keypair in the Secret, recreate the minion Pod to apply it.

#### Pre-Seeded Keys

For production with pre-generated keys:

```bash
# Encode keys
PRIVATE_KEY=$(base64 -w0 < /path/to/minion.pem)
PUBLIC_KEY=$(base64 -w0 < /path/to/minion.pub)

# Create secret
kubectl create secret generic my-minion-keys \
--from-literal=minion.pem="$PRIVATE_KEY" \
--from-literal=minion.pub="$PUBLIC_KEY" \
--from-file=minion.pem=/path/to/minion.pem \
--from-file=minion.pub=/path/to/minion.pub \
-n salt

# Use in Helm
Expand All @@ -287,7 +308,7 @@ The chart's pre-install Job automatically generates keys:

```bash
helm install salt-minion ./helm/salt-minion \
--set agent.minion.keySecretName="" # Let job create it
--set agent.minion.allowSelfGeneratedKey=true
```

### Health Checks
Expand All @@ -312,6 +333,7 @@ For Salt's native multi-master setup:

```bash
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'
```

Expand Down Expand Up @@ -340,7 +362,7 @@ The comma-separated list is converted to a YAML list in minion configuration.

The chart applies comprehensive security controls:

- Runs as non-root user (UID 10000)
- Runs as a non-root user by default
- Disables privilege escalation
- Drops all Linux capabilities
- Private keys stored with mode 0400
Expand Down
63 changes: 63 additions & 0 deletions helm/salt-minion/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
{{/* Validation */}}
{{- define "salt-minion.validateKeyPair" -}}
{{- $minion := .Values.agent.minion -}}
{{- if ne (empty $minion.privateKeyB64) (empty $minion.publicKeyB64) -}}
{{- fail "agent.minion.privateKeyB64 and agent.minion.publicKeyB64 must be set together" -}}
{{- end -}}
{{- end -}}

{{- define "salt-minion.validateKeySource" -}}
{{- $minion := .Values.agent.minion -}}
{{- if not (or $minion.keySecretName $minion.privateKeyB64 $minion.allowSelfGeneratedKey) -}}
{{- fail "set agent.minion.keySecretName or both agent.minion.privateKeyB64 and agent.minion.publicKeyB64, or enable agent.minion.allowSelfGeneratedKey" -}}
{{- end -}}
{{- end -}}

{{/* Values */}}
{{- define "salt-minion.keySecretName" -}}
{{- .Values.agent.minion.keySecretName | default (printf "%s-keys" .Release.Name) -}}
{{- end -}}

{{/* Format an image repository and tag. */}}
{{- define "salt-minion.image" -}}
{{- printf "%s:%s" .repository (toString .tag) -}}
Expand All @@ -12,3 +32,46 @@
{{- define "salt-minion.keygenImage" -}}
{{- include "salt-minion.image" .Values.keygen.image -}}
{{- end -}}

{{- define "salt-minion.masterHost" -}}
{{- if kindIs "slice" .Values.agent.saltMasterHost -}}
{{- join "," .Values.agent.saltMasterHost -}}
{{- else -}}
{{- .Values.agent.saltMasterHost -}}
{{- end -}}
{{- end -}}

{{/* Flags */}}
{{- define "salt-minion.keySecretEnabled" -}}
{{- if .Values.agent.minion.privateKeyB64 -}}
true
{{- end -}}
{{- end -}}

{{- define "salt-minion.keygenEnabled" -}}
{{- $minion := .Values.agent.minion -}}
{{- if and (eq .Values.agent.authMode "in_cluster") $minion.allowSelfGeneratedKey (not $minion.keySecretName) (not $minion.privateKeyB64) -}}
true
{{- end -}}
{{- end -}}

{{- define "salt-minion.keygenJobEnabled" -}}
{{- if include "salt-minion.keygenEnabled" . -}}
{{- $secretName := include "salt-minion.keySecretName" . -}}
{{- if not (lookup "v1" "Secret" .Values.namespace $secretName) -}}
true
{{- end -}}
{{- end -}}
{{- end -}}

{{- define "salt-minion.keygenRbacEnabled" -}}
{{- if and .Values.rbac.create (include "salt-minion.keygenEnabled" .) -}}
true
{{- end -}}
{{- end -}}

{{- define "salt-minion.deploymentEnabled" -}}
{{- if eq .Values.agent.authMode "in_cluster" -}}
true
{{- end -}}
{{- end -}}
47 changes: 21 additions & 26 deletions helm/salt-minion/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{{- if eq .Values.agent.authMode "in_cluster" }}
{{- $keySecret := .Values.agent.minion.keySecretName | default (printf "%s-keys" .Release.Name) }}
{{- if include "salt-minion.deploymentEnabled" . }}
{{- include "salt-minion.validateKeySource" . -}}
{{- $keySecret := include "salt-minion.keySecretName" . }}
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down Expand Up @@ -45,46 +46,38 @@ spec:
- |
set -eu

cp /var/run/salt-minion-keys/minion.pem \
/etc/salt/pki/minion/minion.pem
umask 077
test -s /var/run/salt-minion-keys/minion.pem
test -s /var/run/salt-minion-keys/minion.pub

mkdir -p /pki/minion
chmod 0700 /pki/minion
rm -f /pki/minion/minion.pem /pki/minion/minion.pub
cp /var/run/salt-minion-keys/minion.pem \
/pki/minion/minion.pem
cp /var/run/salt-minion-keys/minion.pub \
/etc/salt/pki/minion/minion.pub
/pki/minion/minion.pub

chown -R 10001:10001 /etc/salt/pki/minion
chmod 0700 /etc/salt/pki/minion
chmod 0400 /etc/salt/pki/minion/minion.pem
chmod 0644 /etc/salt/pki/minion/minion.pub
test -s /pki/minion/minion.pem
test -s /pki/minion/minion.pub
chmod 0400 /pki/minion/minion.pem
chmod 0644 /pki/minion/minion.pub
volumeMounts:
- name: minion-keys-source
mountPath: /var/run/salt-minion-keys
readOnly: true
- name: minion-pki
mountPath: /etc/salt/pki/minion
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 }}

containers:
- name: salt-minion
image: {{ include "salt-minion.agentImage" . | quote }}
imagePullPolicy: {{ .Values.agent.image.pullPolicy }}
env:
- name: SALT_MASTER
{{- if kindIs "slice" .Values.agent.saltMasterHost }}
value: {{ join "," .Values.agent.saltMasterHost | quote }}
{{- else }}
value: {{ .Values.agent.saltMasterHost | quote }}
{{- end }}
value: {{ include "salt-minion.masterHost" . | quote }}

- name: SALT_MASTER_PORT
value: {{ .Values.agent.saltMasterPort | quote }}
Expand Down Expand Up @@ -147,6 +140,7 @@ spec:
volumeMounts:
- name: minion-pki
mountPath: /etc/salt/pki/minion
subPath: minion

livenessProbe:
exec:
Expand Down Expand Up @@ -177,6 +171,7 @@ spec:
- name: minion-keys-source
secret:
secretName: {{ $keySecret }}
defaultMode: 0444

- name: minion-pki
emptyDir: {}
Expand Down
9 changes: 6 additions & 3 deletions helm/salt-minion/templates/keygen-job.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{{- $secretName := .Values.agent.minion.keySecretName | default (printf "%s-keys" .Release.Name) -}}
{{- $existingSecret := lookup "v1" "Secret" .Values.namespace $secretName -}}
{{- if and (not .Values.agent.minion.keySecretName) (not $existingSecret) }}
{{- if include "salt-minion.keygenJobEnabled" . }}
{{- $secretName := include "salt-minion.keySecretName" . }}
apiVersion: batch/v1
kind: Job
metadata:
Expand All @@ -11,6 +10,8 @@ spec:
template:
spec:
serviceAccountName: {{ .Values.serviceAccount.name }}
securityContext:
{{- toYaml .Values.keygen.podSecurityContext | nindent 8 }}
{{- with .Values.keygen.image.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
Expand All @@ -21,6 +22,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:
- |
Expand Down
2 changes: 1 addition & 1 deletion helm/salt-minion/templates/minion-keygen-rb.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if and .Values.rbac.create (not .Values.agent.minion.keySecretName) }}
{{- if include "salt-minion.keygenRbacEnabled" . }}
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
Expand Down
2 changes: 1 addition & 1 deletion helm/salt-minion/templates/minion-keygen-role.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if and .Values.rbac.create (not .Values.agent.minion.keySecretName) }}
{{- if include "salt-minion.keygenRbacEnabled" . }}
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
Expand Down
9 changes: 5 additions & 4 deletions helm/salt-minion/templates/minion-secret.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{{- $secretName := .Values.agent.minion.keySecretName | default (printf "%s-keys" .Release.Name) -}}
{{- if and .Values.agent.minion.privateKeyB64 .Values.agent.minion.publicKeyB64 }}
{{- include "salt-minion.validateKeyPair" . -}}
{{- if include "salt-minion.keySecretEnabled" . }}
{{- $secretName := include "salt-minion.keySecretName" . }}
apiVersion: v1
kind: Secret
metadata:
Expand All @@ -11,6 +12,6 @@ metadata:
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}
type: Opaque
data:
private-key-b64: {{ .Values.agent.minion.privateKeyB64 | b64enc }}
public-key-b64: {{ .Values.agent.minion.publicKeyB64 | b64enc }}
minion.pem: {{ .Values.agent.minion.privateKeyB64 | quote }}
minion.pub: {{ .Values.agent.minion.publicKeyB64 | quote }}
{{- end }}
Loading
Loading