Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix(helm): address review findings on infisical-nkp chart

ArshBallagandf2c37059bca
diff --git a/helm-charts/infisical-nkp/templates/_helpers.tpl b/helm-charts/infisical-nkp/templates/_helpers.tpl
index 7f7ee18049..e9c7e204b3 100644
--- a/helm-charts/infisical-nkp/templates/_helpers.tpl
+++ b/helm-charts/infisical-nkp/templates/_helpers.tpl
@@ -8,7 +8,12 @@
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
-{{- printf "%s" (include "infisical.name" .) | trunc 63 | trimSuffix "-" -}}
+{{- $name := default .Chart.Name .Values.nameOverride -}}
+{{- if contains $name .Release.Name -}}
+{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
+{{- else -}}
+{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
+{{- end -}}
{{- end -}}
{{- end -}}
@@ -23,6 +28,7 @@ helm.sh/chart: {{ printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" }}
{{/* Selector labels */}}
{{- define "infisical.selectorLabels" -}}
app.kubernetes.io/name: {{ include "infisical.name" . }}
+app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: backend
{{- end -}}
@@ -61,12 +67,18 @@ use the external URI stored in the chart's own secret.
{{- end }}
{{- end -}}
-{{/* REDIS_URL: in-cluster Redis service when enabled, else the external URL. */}}
-{{- define "infisical.redisUrl" -}}
-{{- if .Values.redis.enabled -}}
-redis://{{ include "infisical.fullname" . }}-redis:{{ .Values.redis.port }}
+{{/*
+Password for the bundled Redis: reuse the one already stored in the Secret
+(so upgrades don't rotate it), else generate a new one. Call this exactly once
+per render and reuse the result (each call generates a fresh random value on
+first install).
+*/}}
+{{- define "infisical.redisPassword" -}}
+{{- $existing := lookup "v1" "Secret" .Release.Namespace (printf "%s-secrets" (include "infisical.fullname" .)) -}}
+{{- if and $existing $existing.data.REDIS_PASSWORD -}}
+{{- $existing.data.REDIS_PASSWORD | b64dec -}}
{{- else -}}
-{{ .Values.secrets.redisUrl }}
+{{- randAlphaNum 32 -}}
{{- end -}}
{{- end -}}
diff --git a/helm-charts/infisical-nkp/templates/deployment.yaml b/helm-charts/infisical-nkp/templates/deployment.yaml
index e63ba0bbe0..1d7175ba80 100644
--- a/helm-charts/infisical-nkp/templates/deployment.yaml
+++ b/helm-charts/infisical-nkp/templates/deployment.yaml
@@ -11,6 +11,10 @@ spec:
{{- include "infisical.selectorLabels" . | nindent 6 }}
template:
metadata:
+ annotations:
+ # Roll pods when generated configuration changes.
+ checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
+ checksum/secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
labels:
{{- include "infisical.selectorLabels" . | nindent 8 }}
spec:
@@ -56,7 +60,7 @@ spec:
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
- containerPort: 8080
+ containerPort: {{ .Values.config.port }}
protocol: TCP
envFrom:
- configMapRef:
diff --git a/helm-charts/infisical-nkp/templates/redis.yaml b/helm-charts/infisical-nkp/templates/redis.yaml
index 1993c50f9c..0f88b69e52 100644
--- a/helm-charts/infisical-nkp/templates/redis.yaml
+++ b/helm-charts/infisical-nkp/templates/redis.yaml
@@ -11,17 +11,32 @@ spec:
selector:
matchLabels:
app.kubernetes.io/name: {{ include "infisical.name" . }}
+ app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: redis
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "infisical.name" . }}
+ app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: redis
spec:
containers:
- name: redis
image: "{{ .Values.redis.image.repository }}:{{ .Values.redis.image.tag }}"
imagePullPolicy: {{ .Values.redis.image.pullPolicy }}
+ # $(REDIS_PASSWORD) is expanded by the kubelet from the env var below,
+ # so the password itself never appears in the pod spec.
+ args:
+ - --port
+ - {{ .Values.redis.port | quote }}
+ - --requirepass
+ - $(REDIS_PASSWORD)
+ env:
+ - name: REDIS_PASSWORD
+ valueFrom:
+ secretKeyRef:
+ name: {{ include "infisical.fullname" . }}-secrets
+ key: REDIS_PASSWORD
ports:
- name: redis
containerPort: {{ .Values.redis.port }}
@@ -49,10 +64,39 @@ spec:
type: ClusterIP
selector:
app.kubernetes.io/name: {{ include "infisical.name" . }}
+ app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: redis
ports:
- name: redis
port: {{ .Values.redis.port }}
targetPort: redis
protocol: TCP
+{{- if .Values.redis.networkPolicy }}
+---
+# Defense in depth alongside requirepass: only Infisical pods may reach Redis.
+# Enforced only where the cluster CNI supports NetworkPolicy (NKP's does).
+apiVersion: networking.k8s.io/v1
+kind: NetworkPolicy
+metadata:
+ name: {{ include "infisical.fullname" . }}-redis
+ labels:
+ {{- include "infisical.labels" . | nindent 4 }}
+ app.kubernetes.io/component: redis
+spec:
+ podSelector:
+ matchLabels:
+ app.kubernetes.io/name: {{ include "infisical.name" . }}
+ app.kubernetes.io/instance: {{ .Release.Name }}
+ app.kubernetes.io/component: redis
+ policyTypes:
+ - Ingress
+ ingress:
+ - from:
+ - podSelector:
+ matchLabels:
+ {{- include "infisical.selectorLabels" . | nindent 14 }}
+ ports:
+ - protocol: TCP
+ port: {{ .Values.redis.port }}
+{{- end }}
{{- end }}
diff --git a/helm-charts/infisical-nkp/templates/secret.yaml b/helm-charts/infisical-nkp/templates/secret.yaml
index 526ee7237d..e523866072 100644
--- a/helm-charts/infisical-nkp/templates/secret.yaml
+++ b/helm-charts/infisical-nkp/templates/secret.yaml
@@ -8,7 +8,13 @@ type: Opaque
stringData:
ENCRYPTION_KEY: {{ include "infisical.encryptionKey" . | quote }}
AUTH_SECRET: {{ include "infisical.authSecret" . | quote }}
- REDIS_URL: {{ include "infisical.redisUrl" . | quote }}
+ {{- if .Values.redis.enabled }}
+ {{- $redisPassword := include "infisical.redisPassword" . }}
+ REDIS_PASSWORD: {{ $redisPassword | quote }}
+ REDIS_URL: {{ printf "redis://:%s@%s-redis:%v" $redisPassword (include "infisical.fullname" .) .Values.redis.port | quote }}
+ {{- else }}
+ REDIS_URL: {{ .Values.secrets.redisUrl | quote }}
+ {{- end }}
{{- if not .Values.postgres.cnpg.enabled }}
# Only used when CNPG is disabled and an external Postgres is provided.
DB_CONNECTION_URI: {{ .Values.postgres.externalConnectionUri | quote }}
diff --git a/helm-charts/infisical-nkp/values.yaml b/helm-charts/infisical-nkp/values.yaml
index 57cdbc0fe2..87b8698e53 100644
--- a/helm-charts/infisical-nkp/values.yaml
+++ b/helm-charts/infisical-nkp/values.yaml
@@ -34,6 +34,10 @@ redis:
tag: "7.4-alpine"
pullPolicy: IfNotPresent
port: 6379
+ # Restrict Redis ingress to the Infisical pods (enforced where the CNI
+ # supports NetworkPolicy). The bundled Redis is also password-protected with
+ # a generated password stored in the chart Secret (REDIS_PASSWORD).
+ networkPolicy: true
# PostgreSQL is provided by the NKP CloudNativePG (CNPG) operator.
# REQUIRES the CloudNativePG platform application to be enabled in the
@@ -61,6 +65,8 @@ service:
type: ClusterIP
port: 8080
+# TLS is handled by the NKP kommander-traefik controller via the router
+# annotations below; there is no separate tls toggle.
ingress:
enabled: true
className: kommander-traefik
@@ -68,7 +74,6 @@ ingress:
annotations:
traefik.ingress.kubernetes.io/router.tls: "true"
traefik.ingress.kubernetes.io/router.entrypoints: websecure
- tls: true
resources:
requests: