forked from hashicorp/consul-k8s
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request hashicorp#37 from anubhavmishra/service-account-ge…
…nerate-certs Add a Service account for the Consul Connect Injector to generate certificates automatically
- Loading branch information
Showing
9 changed files
with
240 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# The ClusterRole to enable the Connect injector to get, list, watch and patch MutatingWebhookConfiguration. | ||
{{- if and (not .Values.connectInject.certs.secretName) (or (and (ne (.Values.connectInject.enabled | toString) "-") .Values.connectInject.enabled) (and (eq (.Values.connectInject.enabled | toString) "-") .Values.global.enabled)) }} | ||
apiVersion: rbac.authorization.k8s.io/v1beta1 | ||
kind: ClusterRole | ||
metadata: | ||
name: {{ template "consul.fullname" . }}-connect-injector-webhook | ||
labels: | ||
app: {{ template "consul.name" . }} | ||
chart: {{ template "consul.chart" . }} | ||
heritage: {{ .Release.Service }} | ||
release: {{ .Release.Name }} | ||
rules: | ||
- apiGroups: ["admissionregistration.k8s.io"] | ||
resources: ["mutatingwebhookconfigurations"] | ||
verbs: | ||
- "get" | ||
- "list" | ||
- "watch" | ||
- "patch" | ||
{{- 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,19 @@ | ||
{{- if and (not .Values.connectInject.certs.secretName) (or (and (ne (.Values.connectInject.enabled | toString) "-") .Values.connectInject.enabled) (and (eq (.Values.connectInject.enabled | toString) "-") .Values.global.enabled)) }} | ||
apiVersion: rbac.authorization.k8s.io/v1beta1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: {{ template "consul.fullname" . }}-connect-injector-webhook-admin-role-binding | ||
labels: | ||
app: {{ template "consul.name" . }} | ||
chart: {{ template "consul.chart" . }} | ||
heritage: {{ .Release.Service }} | ||
release: {{ .Release.Name }} | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: {{ template "consul.fullname" . }}-connect-injector-webhook | ||
subjects: | ||
- kind: ServiceAccount | ||
name: {{ template "consul.fullname" . }}-connect-injector-webhook-svc-account | ||
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,12 @@ | ||
{{- if and (not .Values.connectInject.certs.secretName) (or (and (ne (.Values.connectInject.enabled | toString) "-") .Values.connectInject.enabled) (and (eq (.Values.connectInject.enabled | toString) "-") .Values.global.enabled)) }} | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: {{ template "consul.fullname" . }}-connect-injector-webhook-svc-account | ||
namespace: {{ .Release.Namespace }} | ||
labels: | ||
app: {{ template "consul.name" . }} | ||
chart: {{ template "consul.chart" . }} | ||
heritage: {{ .Release.Service }} | ||
release: {{ .Release.Name }} | ||
{{- 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,53 @@ | ||
#!/usr/bin/env bats | ||
|
||
load _helpers | ||
@test "connectInject/ClusterRole: disabled by default" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/connect-inject-clusterrole.yaml \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} | ||
|
||
@test "connectInject/ClusterRole: enabled with global.enabled false" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/connect-inject-clusterrole.yaml \ | ||
--set 'global.enabled=false' \ | ||
--set 'connectInject.enabled=true' \ | ||
. | tee /dev/stderr | | ||
yq -s 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "true" ] | ||
} | ||
|
||
@test "connectInject/ClusterRole: disabled with connectInject.enabled" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/connect-inject-clusterrole.yaml \ | ||
--set 'connectInject.enabled=false' \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} | ||
|
||
@test "connectInject/ClusterRole: disabled with connectInject.certs.secretName set" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/connect-inject-clusterrole.yaml \ | ||
--set 'connectInject.enabled=true' \ | ||
--set 'connectInject.certs.secretName=foo' \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} | ||
|
||
@test "connectInject/ClusterRole: enabled with connectInject.certs.secretName not set" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/connect-inject-clusterrole.yaml \ | ||
--set 'connectInject.enabled=true' \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "true" ] | ||
} |
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,53 @@ | ||
#!/usr/bin/env bats | ||
|
||
load _helpers | ||
@test "connectInject/ClusterRoleBinding: disabled by default" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/connect-inject-clusterrolebinding.yaml \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} | ||
|
||
@test "connectInject/ClusterRoleBinding: enabled with global.enabled false" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/connect-inject-clusterrolebinding.yaml \ | ||
--set 'global.enabled=false' \ | ||
--set 'connectInject.enabled=true' \ | ||
. | tee /dev/stderr | | ||
yq -s 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "true" ] | ||
} | ||
|
||
@test "connectInject/ClusterRoleBinding: disabled with connectInject.enabled false" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/connect-inject-clusterrolebinding.yaml \ | ||
--set 'connectInject.enabled=false' \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} | ||
|
||
@test "connectInject/ClusterRoleBinding: disabled with connectInject.certs.secretName set" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/connect-inject-clusterrolebinding.yaml \ | ||
--set 'connectInject.enabled=true' \ | ||
--set 'connectInject.certs.secretName=foo' \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} | ||
|
||
@test "connectInject/ClusterRoleBinding: enabled with connectInject.certs.secretName not set" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/connect-inject-clusterrolebinding.yaml \ | ||
--set 'connectInject.enabled=true' \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "true" ] | ||
} |
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,53 @@ | ||
#!/usr/bin/env bats | ||
|
||
load _helpers | ||
@test "connectInject/ServiceAccount: disabled by default" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/connect-inject-serviceaccount.yaml \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} | ||
|
||
@test "connectInject/ServiceAccount: enabled with global.enabled false" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/connect-inject-serviceaccount.yaml \ | ||
--set 'global.enabled=false' \ | ||
--set 'connectInject.enabled=true' \ | ||
. | tee /dev/stderr | | ||
yq -s 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "true" ] | ||
} | ||
|
||
@test "connectInject/ServiceAccount: disabled with connectInject.enabled false" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/connect-inject-serviceaccount.yaml \ | ||
--set 'connectInject.enabled=false' \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} | ||
|
||
@test "connectInject/ServiceAccount: disabled with connectInject.certs.secretName set" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/connect-inject-serviceaccount.yaml \ | ||
--set 'connectInject.enabled=true' \ | ||
--set 'connectInject.certs.secretName=foo' \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} | ||
|
||
@test "connectInject/ServiceAccount: enabled with connectInject.certs.secretName not set" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/connect-inject-serviceaccount.yaml \ | ||
--set 'connectInject.enabled=true' \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "true" ] | ||
} |
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