Skip to content

Commit

Permalink
Backport of [NET-6466] Remove secrets from termgw role into release/1…
Browse files Browse the repository at this point in the history
….3.x (#3946)

* backport of commit 975434f

* backport of commit 4e61f68

* fix bats test

* fix lengths of rules

---------

Co-authored-by: jm96441n <john.maguire@hashicorp.com>
  • Loading branch information
hc-github-team-consul-core and jm96441n authored Apr 23, 2024
1 parent 7169aed commit 648ed54
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 32 deletions.
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

0 comments on commit 648ed54

Please sign in to comment.