Skip to content

Commit

Permalink
Allow setting the -acl-auth-method flag
Browse files Browse the repository at this point in the history
For users that are setting up ACLs themselves (e.g. they have external
Consul servers so can't use bootstrapACLs) this allows them to create
their own Kubernetes auth method that the init container will use during
connect injection to receive an ACL token.

Fixes hashicorp#131
  • Loading branch information
lkysow committed Oct 31, 2019
1 parent 341f785 commit 56be9a6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
4 changes: 3 additions & 1 deletion templates/connect-inject-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ spec:
-envoy-image="{{ .Values.connectInject.imageEnvoy }}" \
{{ end -}}
-listen=:8080 \
{{- if .Values.global.bootstrapACLs }}
{{- if .Values.connectInject.overrideAuthMethodName }}
-acl-auth-method="{{ .Values.connectInject.overrideAuthMethodName }}" \
{{ else if .Values.global.bootstrapACLs }}
-acl-auth-method="{{ .Release.Name }}-consul-k8s-auth-method" \
{{- end }}
{{- if .Values.connectInject.centralConfig.enabled }}
Expand Down
47 changes: 47 additions & 0 deletions test/unit/connect-inject-deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,50 @@ load _helpers
yq '.spec.template.spec.containers[0].command | any(contains("-default-protocol=\"grpc\""))' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

#--------------------------------------------------------------------
# authMethod

@test "connectInject/Deployment: -acl-auth-method is not set by default" {
cd `chart_dir`
local actual=$(helm template \
-x templates/connect-inject-deployment.yaml \
--set 'connectInject.enabled=true' \
. | tee /dev/stderr |
yq '.spec.template.spec.containers[0].command | any(contains("-acl-auth-method="))' | tee /dev/stderr)
[ "${actual}" = "false" ]
}

@test "connectInject/Deployment: -acl-auth-method is set when global.bootstrapACLs is true" {
cd `chart_dir`
local actual=$(helm template \
-x templates/connect-inject-deployment.yaml \
--set 'connectInject.enabled=true' \
--set 'global.bootstrapACLs=true' \
. | tee /dev/stderr |
yq '.spec.template.spec.containers[0].command | any(contains("-acl-auth-method=\"release-name-consul-k8s-auth-method\""))' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "connectInject/Deployment: -acl-auth-method is set to connectInject.overrideAuthMethodName" {
cd `chart_dir`
local actual=$(helm template \
-x templates/connect-inject-deployment.yaml \
--set 'connectInject.enabled=true' \
--set 'connectInject.overrideAuthMethodName=override' \
. | tee /dev/stderr |
yq '.spec.template.spec.containers[0].command | any(contains("-acl-auth-method=\"override\""))' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "connectInject/Deployment: -acl-auth-method is overridden by connectInject.overrideAuthMethodName if global.bootstrapACLs is true" {
cd `chart_dir`
local actual=$(helm template \
-x templates/connect-inject-deployment.yaml \
--set 'connectInject.enabled=true' \
--set 'global.bootstrapACLs=true' \
--set 'connectInject.overrideAuthMethodName=override' \
. | tee /dev/stderr |
yq '.spec.template.spec.containers[0].command | any(contains("-acl-auth-method=\"override\""))' | tee /dev/stderr)
[ "${actual}" = "true" ]
}
4 changes: 4 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ connectInject:
# Requires Consul >= v1.5 and consul-k8s >= v0.8.0.
aclBindingRuleSelector: "serviceaccount.name!=default"

# If not using global.bootstrapACLs and instead manually setting up an auth
# method for Connect inject, set this to the name of your auth method.
overrideAuthMethodName: ""

# Requires Consul >= v1.5 and consul-k8s >= v0.8.1.
centralConfig:
enabled: false
Expand Down

0 comments on commit 56be9a6

Please sign in to comment.