-
Notifications
You must be signed in to change notification settings - Fork 880
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add role for creating CSI's HMAC secret key (#872)
- Loading branch information
Showing
7 changed files
with
149 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{{/* | ||
Copyright (c) HashiCorp, Inc. | ||
SPDX-License-Identifier: MPL-2.0 | ||
*/}} | ||
|
||
{{- template "vault.csiEnabled" . -}} | ||
{{- if .csiEnabled -}} | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
metadata: | ||
name: {{ template "vault.fullname" . }}-csi-provider-role | ||
labels: | ||
app.kubernetes.io/name: {{ include "vault.name" . }}-csi-provider | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
rules: | ||
- apiGroups: [""] | ||
resources: ["secrets"] | ||
verbs: ["get"] | ||
resourceNames: | ||
{{- if .Values.csi.hmacSecretName }} | ||
- {{ .Values.csi.hmacSecretName }} | ||
{{- else }} | ||
- {{ include "vault.name" . }}-csi-provider-hmac-key | ||
{{- end }} | ||
# 'create' permissions cannot be restricted by resource name: | ||
# https://kubernetes.io/docs/reference/access-authn-authz/rbac/#referring-to-resources | ||
- apiGroups: [""] | ||
resources: ["secrets"] | ||
verbs: ["create"] | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{{/* | ||
Copyright (c) HashiCorp, Inc. | ||
SPDX-License-Identifier: MPL-2.0 | ||
*/}} | ||
|
||
{{- template "vault.csiEnabled" . -}} | ||
{{- if .csiEnabled -}} | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: {{ template "vault.fullname" . }}-csi-provider-rolebinding | ||
labels: | ||
app.kubernetes.io/name: {{ include "vault.name" . }}-csi-provider | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: Role | ||
name: {{ template "vault.fullname" . }}-csi-provider-role | ||
subjects: | ||
- kind: ServiceAccount | ||
name: {{ template "vault.fullname" . }}-csi-provider | ||
namespace: {{ .Release.Namespace }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env bats | ||
|
||
load _helpers | ||
|
||
@test "csi/Role: disabled by default" { | ||
cd `chart_dir` | ||
local actual=$( (helm template \ | ||
--show-only templates/csi-role.yaml \ | ||
. || echo "---") | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} | ||
|
||
@test "csi/Role: names" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
--show-only templates/csi-role.yaml \ | ||
--set "csi.enabled=true" \ | ||
. | tee /dev/stderr | | ||
yq -r '.metadata.name' | tee /dev/stderr) | ||
[ "${actual}" = "release-name-vault-csi-provider-role" ] | ||
local actual=$(helm template \ | ||
--show-only templates/csi-role.yaml \ | ||
--set "csi.enabled=true" \ | ||
. | tee /dev/stderr | | ||
yq -r '.rules[0].resourceNames[0]' | tee /dev/stderr) | ||
[ "${actual}" = "vault-csi-provider-hmac-key" ] | ||
} | ||
|
||
@test "csi/Role: HMAC secret name configurable" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
--show-only templates/csi-role.yaml \ | ||
--set "csi.enabled=true" \ | ||
--set 'csi.hmacSecretName=foo' \ | ||
. | tee /dev/stderr | | ||
yq -r '.rules[0].resourceNames[0]' | tee /dev/stderr) | ||
[ "${actual}" = "foo" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bats | ||
|
||
load _helpers | ||
|
||
@test "csi/RoleBinding: disabled by default" { | ||
cd `chart_dir` | ||
local actual=$( (helm template \ | ||
--show-only templates/csi-rolebinding.yaml \ | ||
. || echo "---") | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} | ||
|
||
@test "csi/RoleBinding: name" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
--show-only templates/csi-rolebinding.yaml \ | ||
--set "csi.enabled=true" \ | ||
. | tee /dev/stderr | | ||
yq -r '.metadata.name' | tee /dev/stderr) | ||
[ "${actual}" = "release-name-vault-csi-provider-rolebinding" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters