This repository has been archived by the owner on Aug 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 385
feat: add rbac support #29
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6330895
feat: add rbac support
tomwganem 32ed79e
fix: move .Values.rbac.enabled to .Values.syncCatalog.rbac.enabled
tomwganem 6d9c884
feat: create serviceAccount for sync catalog cluster role bind
tomwganem 973cc2e
fix: use a "-" instead of a ":" for names
tomwganem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,21 @@ | ||
{{- $rbacEnabled := (or (and (ne (.Values.rbac.enabled | toString) "-") .Values.rbac.enabled) (and (eq (.Values.rbac.enabled | toString) "-") .Values.rbac.enabled)) }} | ||
{{- $syncEnabled := (or (and (ne (.Values.syncCatalog.enabled | toString) "-") .Values.syncCatalog.enabled) (and (eq (.Values.syncCatalog.enabled | toString) "-") .Values.global.enabled)) }} | ||
{{- if (and $rbacEnabled $syncEnabled) }} | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: consul:sync | ||
labels: | ||
app: {{ template "consul.name" . }} | ||
chart: {{ template "consul.chart" . }} | ||
heritage: {{ .Release.Service }} | ||
release: {{ .Release.Name }} | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: consul:sync | ||
subjects: | ||
- kind: Group | ||
name: system:serviceaccounts:{{ .Release.Namespace }} | ||
apiGroup: rbac.authorization.k8s.io | ||
{{- 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,25 @@ | ||
{{- $rbacEnabled := (or (and (ne (.Values.rbac.enabled | toString) "-") .Values.rbac.enabled) (and (eq (.Values.rbac.enabled | toString) "-") .Values.rbac.enabled)) }} | ||
{{- $syncEnabled := (or (and (ne (.Values.syncCatalog.enabled | toString) "-") .Values.syncCatalog.enabled) (and (eq (.Values.syncCatalog.enabled | toString) "-") .Values.global.enabled)) }} | ||
{{- if (and $rbacEnabled $syncEnabled) }} | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: consul:sync | ||
labels: | ||
app: {{ template "consul.name" . }} | ||
chart: {{ template "consul.chart" . }} | ||
heritage: {{ .Release.Service }} | ||
release: {{ .Release.Name }} | ||
rules: | ||
- apiGroups: [""] | ||
resources: | ||
- services | ||
- endpoints | ||
verbs: | ||
- get | ||
- list | ||
- watch | ||
- update | ||
- patch | ||
- delete | ||
{{- 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,56 @@ | ||
#!/usr/bin/env bats | ||
|
||
load _helpers | ||
|
||
@test "sync/ClusterRoleBinding: disabled by default" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/sync-cluster-role-binding.yaml \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} | ||
|
||
@test "sync/ClusterRoleBinding: enable with global.enabled false" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/sync-cluster-role-binding.yaml \ | ||
--set 'global.enabled=false' \ | ||
--set 'syncCatalog.enabled=true' \ | ||
--set 'rbac.enabled=true' \ | ||
. | tee /dev/stderr | | ||
yq -s 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "true" ] | ||
} | ||
|
||
@test "sync/ClusterRoleBinding: disable with syncCatalog.enabled" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/sync-cluster-role-binding.yaml \ | ||
--set 'syncCatalog.enabled=false' \ | ||
--set 'rbac.enabled=true' \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} | ||
|
||
@test "sync/ClusterRoleBinding: disable with rbac.enabled" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/sync-cluster-role-binding.yaml \ | ||
--set 'syncCatalog.enabled=true' \ | ||
--set 'rbac.enabled=false' \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} | ||
|
||
@test "sync/ClusterRoleBinding: disable with global.enabled" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/sync-cluster-role-binding.yaml \ | ||
--set 'global.enabled=false' \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} |
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,56 @@ | ||
#!/usr/bin/env bats | ||
|
||
load _helpers | ||
|
||
@test "sync/ClusterRole: disabled by default" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/sync-cluster-role.yaml \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} | ||
|
||
@test "sync/ClusterRole: enable with global.enabled false" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/sync-cluster-role.yaml \ | ||
--set 'global.enabled=false' \ | ||
--set 'syncCatalog.enabled=true' \ | ||
--set 'rbac.enabled=true' \ | ||
. | tee /dev/stderr | | ||
yq -s 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "true" ] | ||
} | ||
|
||
@test "sync/ClusterRole: disable with syncCatalog.enabled" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/sync-cluster-role.yaml \ | ||
--set 'syncCatalog.enabled=false' \ | ||
--set 'rbac.enabled=true' \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} | ||
|
||
@test "sync/ClusterRole: disable with rbac.enabled" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/sync-cluster-role.yaml \ | ||
--set 'syncCatalog.enabled=true' \ | ||
--set 'rbac.enabled=false' \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} | ||
|
||
@test "sync/ClusterRole: disable with global.enabled" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/sync-cluster-role.yaml \ | ||
--set 'global.enabled=false' \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} |
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 |
---|---|---|
|
@@ -186,3 +186,8 @@ connectInject: | |
# defaults but can be customized if necessary. | ||
certName: tls.crt | ||
keyName: tls.key | ||
|
||
# Enabling rbac will create cluster roles and cluster role bindings to allow the | ||
# syncCatalog service to communicate with the kubernetes api to get/create services | ||
rbac: | ||
enabled: false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should probably go under the syncCatalog:
rbac:
enabled: false/true |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was getting
error="services is forbidden: User "system:serviceaccount:platform:consul-sync-catalog" cannot create services in the namespace "platform""
without this. Once added, theconsul
service was synced to k8s.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Yep.
It seems possible that we should create two roles here. One for k8s => Consul and one for Consul => k8s, since either one-way can be disabled/enabled and k8s => Consul only requires read-only privileges which is a nice to have.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually decided to just add
-create
for now and keep the simple thing, we can split it out later if its useful.