Skip to content
Merged
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
11 changes: 11 additions & 0 deletions templates/imperative/vault-exec-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
{{- if or (eq .Values.global.secretStore.backend "vault") (not (hasKey .Values.global.secretStore "backend")) }}
{{- if not (eq .Values.enabled "plumbing") }}
{{- if $.Values.clusterGroup.imperative.serviceAccountCreate }}
{{- $hashicorp_vault_found := false }}
{{- range .Values.clusterGroup.applications }}
{{- if . }} {{- /* Skip null applications */}}
{{- if eq .chart "hashicorp-vault" }}
{{- $hashicorp_vault_found = true }}
{{- end }}
{{- end }}
{{- end }}

{{- if or (eq (include "clustergroup.ishubcluster" .) "true") $hashicorp_vault_found }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
Expand Down Expand Up @@ -34,3 +44,4 @@ subjects:
{{- end }}
{{- end }}
{{- end }}
{{- end }}
58 changes: 57 additions & 1 deletion tests/imperative_vault_exec_role_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ templates:
release:
name: release-test
tests:
- it: should create vault exec role by default
- it: should create vault exec role by default on hub cluster
set:
clusterGroup:
isHubCluster: true
asserts:
- hasDocuments:
count: 2
Expand All @@ -15,6 +18,7 @@ tests:
secretStore:
backend: vault
clusterGroup:
isHubCluster: true
imperative:
serviceAccountCreate: true
serviceAccountName: imperative-sa
Expand Down Expand Up @@ -94,6 +98,7 @@ tests:
global:
secretStore: {}
clusterGroup:
isHubCluster: true
imperative:
serviceAccountCreate: true
serviceAccountName: imperative-sa
Expand Down Expand Up @@ -130,6 +135,7 @@ tests:
secretStore:
backend: vault
clusterGroup:
isHubCluster: true
imperative:
serviceAccountCreate: true
serviceAccountName: imperative-sa
Expand All @@ -146,3 +152,53 @@ tests:
equal:
path: metadata.namespace
value: custom-vault

- it: should not create vault exec role on spoke cluster without hashicorp-vault app
set:
global:
secretStore:
backend: vault
clusterGroup:
isHubCluster: false
imperative:
serviceAccountCreate: true
serviceAccountName: imperative-sa
namespace: imperative
vaultNamespace: vault
applications:
test:
name: test
namespace: test
project: test
chart: test-chart
asserts:
- hasDocuments:
count: 0

- it: should create vault exec role on spoke cluster with hashicorp-vault app
set:
global:
secretStore:
backend: vault
clusterGroup:
isHubCluster: false
imperative:
serviceAccountCreate: true
serviceAccountName: imperative-sa
namespace: imperative
vaultNamespace: vault
applications:
vault:
name: vault
namespace: vault
project: hub
chart: hashicorp-vault
asserts:
- hasDocuments:
count: 2
- documentIndex: 0
isKind:
of: Role
- documentIndex: 1
isKind:
of: RoleBinding