Set VAULT_ADDR env var for CSI Provider pods (#745)

This commit is contained in:
Tom Proctor 2022-06-07 10:16:37 +01:00 committed by GitHub
parent d78a292f47
commit 44a07b8970
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 85 additions and 6 deletions

View file

@ -1,11 +1,13 @@
## Unreleased ## Unreleased
CHANGES: CHANGES:
* Start testing against Kubernetes 1.24 * Start testing against Kubernetes 1.24. [GH-744](https://github.com/hashicorp/vault-helm/pull/744)
* Deprecated `injector.externalVaultAddr`. Added `global.externalVaultAddr`, which applies to both the Injector and the CSI Provider. [GH-745](https://github.com/hashicorp/vault-helm/pull/745)
* CSI Provider pods now set the `VAULT_ADDR` environment variable to either the internal Vault service or the configured external address. [GH-745](https://github.com/hashicorp/vault-helm/pull/745)
## 0.20.1 (May 25th, 2022) ## 0.20.1 (May 25th, 2022)
CHANGES: CHANGES:
* `vault-k8s` updated to 0.16.1 * `vault-k8s` updated to 0.16.1 [GH-739](https://github.com/hashicorp/vault-helm/pull/739)
Improvements: Improvements:
* Mutating webhook will no longer target the agent injector pod [GH-736](https://github.com/hashicorp/vault-helm/pull/736) * Mutating webhook will no longer target the agent injector pod [GH-736](https://github.com/hashicorp/vault-helm/pull/736)

View file

@ -122,7 +122,7 @@ template logic.
*/}} */}}
{{- define "vault.mode" -}} {{- define "vault.mode" -}}
{{- template "vault.serverEnabled" . -}} {{- template "vault.serverEnabled" . -}}
{{- if .Values.injector.externalVaultAddr -}} {{- if or (.Values.injector.externalVaultAddr) (.Values.global.externalVaultAddr) -}}
{{- $_ := set . "mode" "external" -}} {{- $_ := set . "mode" "external" -}}
{{- else if not .serverEnabled -}} {{- else if not .serverEnabled -}}
{{- $_ := set . "mode" "external" -}} {{- $_ := set . "mode" "external" -}}

View file

@ -50,6 +50,13 @@ spec:
{{- if .Values.csi.extraArgs }} {{- if .Values.csi.extraArgs }}
{{- toYaml .Values.csi.extraArgs | nindent 12 }} {{- toYaml .Values.csi.extraArgs | nindent 12 }}
{{- end }} {{- end }}
env:
- name: VAULT_ADDR
{{- if .Values.global.externalVaultAddr }}
value: "{{ .Values.global.externalVaultAddr }}"
{{- else }}
value: {{ include "vault.scheme" . }}://{{ template "vault.fullname" . }}.{{ .Release.Namespace }}.svc:{{ .Values.server.service.port }}
{{- end }}
volumeMounts: volumeMounts:
- name: providervol - name: providervol
mountPath: "/provider" mountPath: "/provider"

View file

@ -60,7 +60,9 @@ spec:
- name: AGENT_INJECT_LOG_LEVEL - name: AGENT_INJECT_LOG_LEVEL
value: {{ .Values.injector.logLevel | default "info" }} value: {{ .Values.injector.logLevel | default "info" }}
- name: AGENT_INJECT_VAULT_ADDR - name: AGENT_INJECT_VAULT_ADDR
{{- if .Values.injector.externalVaultAddr }} {{- if .Values.global.externalVaultAddr }}
value: "{{ .Values.global.externalVaultAddr }}"
{{- else if .Values.injector.externalVaultAddr }}
value: "{{ .Values.injector.externalVaultAddr }}" value: "{{ .Values.injector.externalVaultAddr }}"
{{- else }} {{- else }}
value: {{ include "vault.scheme" . }}://{{ template "vault.fullname" . }}.{{ .Release.Namespace }}.svc:{{ .Values.server.service.port }} value: {{ include "vault.scheme" . }}://{{ template "vault.fullname" . }}.{{ .Release.Namespace }}.svc:{{ .Values.server.service.port }}

View file

@ -563,3 +563,32 @@ load _helpers
yq -r '.timeoutSeconds' | tee /dev/stderr) yq -r '.timeoutSeconds' | tee /dev/stderr)
[ "${actual}" = "14" ] [ "${actual}" = "14" ]
} }
@test "csi/daemonset: with only injector.externalVaultAddr" {
cd `chart_dir`
local object=$(helm template \
--show-only templates/csi-daemonset.yaml \
--set 'csi.enabled=true' \
--release-name not-external-test \
--set 'injector.externalVaultAddr=http://vault-outside' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].env' | tee /dev/stderr)
local value=$(echo $object |
yq -r 'map(select(.name=="VAULT_ADDR")) | .[] .value' | tee /dev/stderr)
[ "${value}" = "http://not-external-test-vault.default.svc:8200" ]
}
@test "csi/daemonset: with global.externalVaultAddr" {
cd `chart_dir`
local object=$(helm template \
--show-only templates/csi-daemonset.yaml \
--set 'csi.enabled=true' \
--set 'global.externalVaultAddr=http://vault-outside' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].env' | tee /dev/stderr)
local value=$(echo $object |
yq -r 'map(select(.name=="VAULT_ADDR")) | .[] .value' | tee /dev/stderr)
[ "${value}" = "http://vault-outside" ]
}

View file

@ -209,6 +209,33 @@ load _helpers
[ "${value}" = "http://vault-outside" ] [ "${value}" = "http://vault-outside" ]
} }
@test "injector/deployment: with global.externalVaultAddr" {
cd `chart_dir`
local object=$(helm template \
--show-only templates/injector-deployment.yaml \
--set 'global.externalVaultAddr=http://vault-outside' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].env' | tee /dev/stderr)
local value=$(echo $object |
yq -r 'map(select(.name=="AGENT_INJECT_VAULT_ADDR")) | .[] .value' | tee /dev/stderr)
[ "${value}" = "http://vault-outside" ]
}
@test "injector/deployment: global.externalVaultAddr takes precendence over injector.externalVaultAddr" {
cd `chart_dir`
local object=$(helm template \
--show-only templates/injector-deployment.yaml \
--set 'global.externalVaultAddr=http://global-vault-outside' \
--set 'injector.externalVaultAddr=http://injector-vault-outside' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].env' | tee /dev/stderr)
local value=$(echo $object |
yq -r 'map(select(.name=="AGENT_INJECT_VAULT_ADDR")) | .[] .value' | tee /dev/stderr)
[ "${value}" = "http://global-vault-outside" ]
}
@test "injector/deployment: without externalVaultAddr" { @test "injector/deployment: without externalVaultAddr" {
cd `chart_dir` cd `chart_dir`
local object=$(helm template \ local object=$(helm template \

View file

@ -185,6 +185,9 @@
}, },
"tlsDisable": { "tlsDisable": {
"type": "boolean" "type": "boolean"
},
"externalVaultAddr": {
"type": "string"
} }
} }
}, },

View file

@ -4,15 +4,23 @@ global:
# enabled is the master enabled switch. Setting this to true or false # enabled is the master enabled switch. Setting this to true or false
# will enable or disable all the components within this chart by default. # will enable or disable all the components within this chart by default.
enabled: true enabled: true
# Image pull secret to use for registry authentication. # Image pull secret to use for registry authentication.
# Alternatively, the value may be specified as an array of strings. # Alternatively, the value may be specified as an array of strings.
imagePullSecrets: [] imagePullSecrets: []
# imagePullSecrets: # imagePullSecrets:
# - name: image-pull-secret # - name: image-pull-secret
# TLS for end-to-end encrypted transport # TLS for end-to-end encrypted transport
tlsDisable: true tlsDisable: true
# External vault server address for the injector and CSI provider to use.
# Setting this will disable deployment of a vault server.
externalVaultAddr: ""
# If deploying to OpenShift # If deploying to OpenShift
openshift: false openshift: false
# Create PodSecurityPolicy for pods # Create PodSecurityPolicy for pods
psp: psp:
enable: false enable: false
@ -43,8 +51,7 @@ injector:
metrics: metrics:
enabled: false enabled: false
# External vault server address for the injector to use. Setting this will # Deprecated: Please use global.externalVaultAddr instead.
# disable deployment of a vault server along with the injector.
externalVaultAddr: "" externalVaultAddr: ""
# image sets the repo and tag of the vault-k8s image to use for the injector. # image sets the repo and tag of the vault-k8s image to use for the injector.
@ -946,4 +953,6 @@ csi:
debug: false debug: false
# Pass arbitrary additional arguments to vault-csi-provider. # Pass arbitrary additional arguments to vault-csi-provider.
# See https://www.vaultproject.io/docs/platform/k8s/csi/configurations#command-line-arguments
# for the available command line flags.
extraArgs: [] extraArgs: []