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

Only add cluster role permissions for enabled sources #2413

Conversation

haines
Copy link
Contributor

@haines haines commented Nov 3, 2021

Following up on a previous discussion, this PR changes the cluster role permissions to only include permissions for enabled sources. This doesn't require any additional configuration by the end user, because we know which permissions need to be added based on the sources selected in .Values.sources.

We run external-dns with only one source (istio-gateway), so we don't need to grant it permission to access endpoints, ingresses, nodes, pods, or services; the existing setup in the chart grants these permissions regardless.

I think it's beneficial to follow principle of least privilege here, and to be consistent with the setup for the Istio sources.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Nov 3, 2021
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 3, 2021
@stevehipwell
Copy link
Contributor

@haines have you tested this locally? It looks good to me but I'd like to know that if a source is set that it'll continue working.

@haines haines force-pushed the helm-chart-cluster-role-permissions branch from e97f0d3 to fdcc0d4 Compare November 3, 2021 14:53
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 3, 2021
@haines
Copy link
Contributor Author

haines commented Nov 3, 2021

@stevehipwell I've reviewed the code for those sources and found that some of them have informers for multiple resource kinds, so the permissions have some degree of overlap. See what you think - I haven't attempted to deduplicate (so if you use both pod and service sources, you'll have two rules granting pod and node permissions).

I've also tested all the sources on a local cluster with the updated chart and they are working correctly in dry-run mode.

@stevehipwell
Copy link
Contributor

@haines I thought that might be the case. Wouldn't it be clearer to only have each rule once but have it enabled via an or?

For example.

{{- if or (or (has "node" .Values.sources) (has "pod" .Values.sources)) (has "service" .Values.sources) }}
  - apiGroups: [""]
    resources: ["nodes"]
    verbs: ["list","watch"]
{{- end }}

@haines
Copy link
Contributor Author

haines commented Nov 3, 2021

Wouldn't it be clearer to only have each rule once but have it enabled via an or?

Personally, I found it clearer to just have a separate block for each source; I find those or chains a bit hard to scan, so it's difficult to see at a glance "if I enable the X source, this grants these additional permissions to the cluster role".

What about including a comment in the generated manifest to show those blocks, so the template can be easier to read but also produce less confusing output?

So something like

{{- if has "ingress" .Values.sources }}
  # permissions for "ingress" source
  - apiGroups: ["extensions","networking.k8s.io"]
    resources: ["ingresses"]
    verbs: ["get","watch","list"]
{{- end }}

{{- if has "istio-gateway" .Values.sources }}
  # permissions for "istio-gateway" source
  - apiGroups: ["networking.istio.io"]
    resources: ["gateways"]
    verbs: ["get","watch","list"]
{{- end }}

...

@stevehipwell
Copy link
Contributor

@haines the chains add a bit of complexity for chart development, but result in much cleaner manifests for the end users. I'd much prefer the pattern that results in clearer outputs for the users.

@haines haines force-pushed the helm-chart-cluster-role-permissions branch from fdcc0d4 to 8b5bcb4 Compare November 3, 2021 19:11
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 3, 2021
@haines
Copy link
Contributor Author

haines commented Nov 3, 2021

@stevehipwell done! I think it's pretty readable in the end - I realised the or function can take many arguments, eliminating the need to juggle parentheses.

I'll submit a PR to the Helm docs which incorrectly state that or takes two arguments. (update: helm/helm-www#1232)

@stevehipwell
Copy link
Contributor

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: haines, stevehipwell

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 4, 2021
@stevehipwell
Copy link
Contributor

@Raffo I'll leave you to do the LGTM.

/assign @Raffo

@Raffo
Copy link
Contributor

Raffo commented Nov 4, 2021

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 4, 2021
@k8s-ci-robot k8s-ci-robot merged commit c9e0c91 into kubernetes-sigs:master Nov 4, 2021
@stevehipwell
Copy link
Contributor

@Raffo the release process worked correctly!! 🥳

@Raffo
Copy link
Contributor

Raffo commented Nov 4, 2021

That is very good to hear!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants