-
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 optional long lived SA token (#923)
--------- Co-authored-by: Caleb Gill <cgill@stavvy.com>
- Loading branch information
1 parent
ec964a3
commit 1e12d49
Showing
5 changed files
with
118 additions
and
0 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,21 @@ | ||
{{/* | ||
Copyright (c) HashiCorp, Inc. | ||
SPDX-License-Identifier: MPL-2.0 | ||
*/}} | ||
|
||
{{ template "vault.serverServiceAccountSecretCreationEnabled" . }} | ||
{{- if .serverServiceAccountSecretCreationEnabled -}} | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: {{ template "vault.serviceAccount.name" . }}-token | ||
namespace: {{ include "vault.namespace" . }} | ||
annotations: | ||
kubernetes.io/service-account.name: {{ template "vault.serviceAccount.name" . }} | ||
labels: | ||
helm.sh/chart: {{ include "vault.chart" . }} | ||
app.kubernetes.io/name: {{ include "vault.name" . }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
type: kubernetes.io/service-account-token | ||
{{ 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,77 @@ | ||
#!/usr/bin/env bats | ||
|
||
load _helpers | ||
|
||
@test "server/ServiceAccountSecret: verify service account name match" { | ||
cd `chart_dir` | ||
|
||
local actual=$( (helm template \ | ||
--show-only templates/server-serviceaccount-secret.yaml \ | ||
--set 'server.dev.enabled=true' \ | ||
--set 'server.serviceAccount.create=false' \ | ||
. || echo "---") | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
|
||
local actual=$(helm template \ | ||
--show-only templates/server-serviceaccount-secret.yaml \ | ||
--set 'server.dev.enabled=true' \ | ||
--set 'server.serviceAccount.name=user-defined-ksa' \ | ||
--set 'server.serviceAccount.createSecret=true' \ | ||
. | tee /dev/stderr | | ||
yq -r '.metadata.name' | tee /dev/stderr) | ||
[ "${actual}" = "user-defined-ksa-token" ] | ||
|
||
local actual=$(helm template \ | ||
--show-only templates/server-serviceaccount-secret.yaml \ | ||
--set 'server.dev.enabled=true' \ | ||
--set 'server.serviceAccount.createSecret=true' \ | ||
. | tee /dev/stderr | | ||
yq -r '.metadata.name' | tee /dev/stderr) | ||
[ "${actual}" = "release-name-vault-token" ] | ||
|
||
} | ||
|
||
@test "server/ServiceAccountSecret: annotation mapping to service account" { | ||
cd `chart_dir` | ||
|
||
local actual=$(helm template \ | ||
--show-only templates/server-serviceaccount-secret.yaml \ | ||
--set 'server.dev.enabled=true' \ | ||
--set 'server.serviceAccount.name=user-defined-ksa' \ | ||
--set 'server.serviceAccount.createSecret=true' \ | ||
. | tee /dev/stderr | | ||
yq -r '.metadata.annotations["kubernetes.io/service-account.name"]' | tee /dev/stderr) | ||
[ "${actual}" = "user-defined-ksa" ] | ||
|
||
local actual=$(helm template \ | ||
--show-only templates/server-serviceaccount-secret.yaml \ | ||
--set 'server.dev.enabled=true' \ | ||
--set 'server.serviceAccount.createSecret=true' \ | ||
. | tee /dev/stderr | | ||
yq -r '.metadata.annotations["kubernetes.io/service-account.name"]' | tee /dev/stderr) | ||
[ "${actual}" = "release-name-vault" ] | ||
|
||
} | ||
|
||
@test "server/ServiceAccountSecret: namespace" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
--show-only templates/server-serviceaccount-secret.yaml \ | ||
--set 'server.serviceAccount.create=true' \ | ||
--set 'server.serviceAccount.createSecret=true' \ | ||
--namespace foo \ | ||
. | tee /dev/stderr | | ||
yq -r '.metadata.namespace' | tee /dev/stderr) | ||
[ "${actual}" = "foo" ] | ||
local actual=$(helm template \ | ||
--show-only templates/server-serviceaccount-secret.yaml \ | ||
--set 'server.serviceAccount.create=true' \ | ||
--set 'server.serviceAccount.createSecret=true' \ | ||
--set 'global.namespace=bar' \ | ||
--namespace foo \ | ||
. | tee /dev/stderr | | ||
yq -r '.metadata.namespace' | tee /dev/stderr) | ||
[ "${actual}" = "bar" ] | ||
} | ||
|
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