Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport of [NET-6466] Remove secrets from termgw role into release/1.3.x #3946

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
3 changes: 3 additions & 0 deletions .changelog/3928.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
terminating-gateways: Remove unnecessary permissions from terminating gateways role
```
13 changes: 1 addition & 12 deletions charts/consul/templates/terminating-gateways-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,14 @@ metadata:
release: {{ $root.Release.Name }}
component: terminating-gateway
terminating-gateway-name: {{ template "consul.fullname" $root }}-{{ .name }}
{{- if (or $root.Values.global.acls.manageSystemACLs $root.Values.global.enablePodSecurityPolicies) }}
rules:
{{- if $root.Values.global.enablePodSecurityPolicies }}
rules:
- apiGroups: ["policy"]
resources: ["podsecuritypolicies"]
resourceNames:
- {{ template "consul.fullname" $root }}-{{ .name }}
verbs:
- use
{{- end }}
{{- if $root.Values.global.acls.manageSystemACLs }}
- apiGroups: [""]
resources:
- secrets
resourceNames:
- {{ template "consul.fullname" $root }}-{{ .name }}-acl-token
verbs:
- get
{{- end }}
{{- else }}
rules: []
{{- end }}
Expand Down
23 changes: 3 additions & 20 deletions charts/consul/test/unit/terminating-gateways-role.bats
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,6 @@ load _helpers
[ "${actual}" = "podsecuritypolicies" ]
}

@test "terminatingGateways/Role: rules for global.acls.manageSystemACLs=true" {
cd `chart_dir`
local object=$(helm template \
-s templates/terminating-gateways-role.yaml \
--set 'terminatingGateways.enabled=true' \
--set 'connectInject.enabled=true' \
--set 'global.acls.manageSystemACLs=true' \
. | tee /dev/stderr |
yq -s -r '.[0].rules[0]' | tee /dev/stderr)

local actual=$(echo $object | yq -r '.resources[0]' | tee /dev/stderr)
[ "${actual}" = "secrets" ]

local actual=$(echo $object | yq -r '.resourceNames[0]' | tee /dev/stderr)
[ "${actual}" = "release-name-consul-terminating-gateway-acl-token" ]
}

@test "terminatingGateways/Role: rules is empty if no ACLs, PSPs" {
cd `chart_dir`
local actual=$(helm template \
Expand All @@ -70,7 +53,7 @@ load _helpers
--set 'global.enablePodSecurityPolicies=true' \
. | tee /dev/stderr |
yq -s -r '.[0].rules | length' | tee /dev/stderr)
[ "${actual}" = "2" ]
[ "${actual}" = "1" ]
}

@test "terminatingGateways/Role: rules for ACLs, PSPs with multiple gateways" {
Expand All @@ -93,10 +76,10 @@ load _helpers
[ "${actual}" = "release-name-consul-gateway2" ]

local actual=$(echo $object | yq '.[0].rules | length' | tee /dev/stderr)
[ "${actual}" = "2" ]
[ "${actual}" = "1" ]

local actual=$(echo $object | yq '.[1].rules | length' | tee /dev/stderr)
[ "${actual}" = "2" ]
[ "${actual}" = "1" ]

local actual=$(echo $object | yq '.[2] | length > 0' | tee /dev/stderr)
[ "${actual}" = "false" ]
Expand Down
Loading