Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

[stable/nginx-ingress] Add RBAC support #1235

Merged
merged 10 commits into from
Aug 14, 2017
Merged

[stable/nginx-ingress] Add RBAC support #1235

merged 10 commits into from
Aug 14, 2017

Conversation

jsulinski
Copy link
Contributor

@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://github.com/kubernetes/kubernetes/wiki/CLA-FAQ to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Jun 4, 2017
@k8s-ci-robot
Copy link
Contributor

Hi @jsulinski. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with @k8s-bot ok to test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jun 4, 2017
@k8s-ci-robot
Copy link
Contributor

@jsulinski: you can't request testing unless you are a kubernetes member.

In response to this:

/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@jsulinski jsulinski changed the title Add RBAC support [stable/nginx-ingress] Add RBAC support Jun 4, 2017
@@ -22,6 +25,9 @@ spec:
component: "{{ .Values.controller.name }}"
release: {{ .Release.Name }}
spec:
{{- if .Values.controller.rbac.enabled }}
serviceAccountName: {{ template "fullname" . }}
{{- end }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I submitted a similar update for Traefik in #1225. When switching RBAC enabled from true to false and helm installing, I found the serviceAccountName stays as the Traefik specific one rather than being reset to default. I wondered if you had encountered that issue here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I didn't experience this. I would presume the issue is elsewhere in your case, as this conditional logic is very simple.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsulinski hmmm strange the Traefik chart doesn't have any complex logic here, the switch is pretty much identical.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you'll also want to apply this to the controller-daemonset.yaml.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Pulled your changes.

@@ -9,6 +9,9 @@ metadata:
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
name: {{ template "controller.fullname" . }}
{{- if .Values.controller.rbac.enabled }}
namespace: {{ .Release.Namespace }}
Copy link
Contributor

@linki linki Jun 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems weird. I think we prefer to leave out the namespace in the metadata section of manifests and let helm take care of that when the --namespace flag is used.

However, you probably need it when you reference the subject in the role bindings, but it shouldn't be required here. Can you give it a try? (including the other manfiests)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, thanks so much! You were spot on.

# Here: "<ingress-controller-leader>-<nginx>"
# This has to be adapted if you change either parameter
# when launching the nginx-ingress-controller.
- "ingress-controller-leader-nginx"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it should be a user-supplied list defaulting to ["ingress-controller-leader-nginx"].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Will update.

@bison
Copy link

bison commented Jun 18, 2017

This looks great. Hope it's merged soon. I think the example RBAC rules here have been updated in the last few days. Might want to pull in the latest version.

@flah00
Copy link
Collaborator

flah00 commented Jun 26, 2017

@jsulinski I have been testing this PR with the latest nginx-ingress-controller 0.9.0 beta and found that I had to add create, delete, and patch for configmaps. It seems that the controller maintains a configmap named ingress-controller-leader-nginx.

Disregard, I made a mistake, when I merged your branch ... derp.

@@ -36,6 +36,10 @@ controller:
##
kind: Deployment

## enable RBAC as per: https://github.com/kubernetes/ingress/tree/master/examples/rbac/nginx and https://github.com/kubernetes/ingress/issues/266
rbac:
enabled: false

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: The two charts with optional RBAC support that have merged seem to be stable/etcd-operator and incubator/istio and both use .Values.rbac.install as the flag. Personally i prefer enabled, but thought i'd point it out for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point. I'll update when I have a free moment.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi, looks like the Traefik chart is merged w/ rbac.enabled, 👍

https://github.com/kubernetes/charts/blob/master/stable/traefik/values.yaml#L63

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sticking with rbac.enabled.

@ReSearchITEng
Copy link
Contributor

Once merged, it will solve: #927

- apiGroups:
- ""
resources:
- events
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit; spacing is off just a bit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

- apiGroups:
- ""
resources:
- nodes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when using --watch-namespace I had to add namespaces here to avoid the following error:

F0710 18:20:42.008164      10 launch.go:145] no watchNamespace with name stage-1-osf found: User "system:serviceaccount:stage-1-osf:mfjzdy-nginx-ingress" cannot get namespaces in the namespace "stage-1-osf".: "Unknown user \"system:serviceaccount:stage-1-osf:mfjzdy-nginx-ingress\"" (get namespaces stage-1-osf)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate on this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The controller is attempting to request a list of namespaces and due to lack of permissions throws an exception (get namespaces stage-1-osf). This command option essentially allows you to have the controller only watch a specified namespace for ingress' tagged with nginx, rather than a single global ingress nginx controller for the entire cluster.

In our case we are evaluating dedicated ip/ingress for each significant component of a larger application, thinking more towards a potential future of adding ModSecurity at this controller ingress point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you share an example? I haven't used --watch-namespace yet.

Copy link
Collaborator

@icereval icereval Jul 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

                             .─────────────────.                              
                         _.─'                   `──.                          
                        (         Internet          )                         
                         `───.                 _.──'                          
                              `───────────────'                               
                                      │                                       
                                      ▼                                       
                          ┌───────────────────────┐                           
                          │  Google Load Balancer │                           
                          └───────────────────────┘                           
                                      │                                       
                    ┌─────────────────┴──────────────────┐                    
┌─Cluster #1────────┼────────────────────────────────────┼───────────────────┐
│                   ▼                                    ▼                   │
│  ┌Namespace (Testing)──────────────┐  ┌Namespace (Staging)──────────────┐  │
│  │┌──────────────┐ ┌──────────────┐│  │┌──────────────┐ ┌──────────────┐│  │
│  ││   Ingress    │ │   Default    ││  ││   Ingress    │ │   Default    ││  │
│  ││  Controller  │ │   Backend    ││  ││  Controller  │ │   Backend    ││  │
│  │└──────────────┘ └──────────────┘│  │└──────────────┘ └──────────────┘│  │
│  │        │                ▲       │  │        │                ▲       │  │
│  │        └───────┬────────┘       │  │        └───────┬────────┘       │  │
│  │                │                │  │                │                │  │
│  │       ┌────────────────┐        │  │       ┌────────────────┐        │  │
│  │       │  ingress.yaml  │        │  │       │  ingress.yaml  │        │  │
│  │       └────────────────┘        │  │       └────────────────┘        │  │
│  │                │                │  │                │                │  │
│  │     ┌──────────┼──────────┐     │  │     ┌──────────┼──────────┐     │  │
│  │     ▼          ▼          ▼     │  │     ▼          ▼          ▼     │  │
│  │ ┌───────┐  ┌───────┐  ┌───────┐ │  │ ┌───────┐  ┌───────┐  ┌───────┐ │  │
│  │ │ Pod 1 │  │ Pod 2 │  │ Pod 3 │ │  │ │ Pod 1 │  │ Pod 2 │  │ Pod 3 │ │  │
│  │ └───────┘  └───────┘  └───────┘ │  │ └───────┘  └───────┘  └───────┘ │  │
│  └─────────────────────────────────┘  └─────────────────────────────────┘  │
│                                                                            │
└────────────────────────────────────────────────────────────────────────────┘

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please tell me how you made that diagram! (programatically i hope)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I'll work on this as soon as I have a moment.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@viglesiasce, using this awesome tool https://monodraw.helftone.com/

@jsulinski
Copy link
Contributor Author

I'm working on testing revisions but having some issues with my RBAC enabled Kube cluster and chart. I'll push the changes without testing if I can't make progress soon.

icereval added a commit to CenterForOpenScience/helm-charts that referenced this pull request Jul 11, 2017
@jsulinski
Copy link
Contributor Author

This is tested with all changes except making resourceNames a value. I'll do that as soon as I can, or anyone else is welcome to.

@jsulinski
Copy link
Contributor Author

Thanks @icereval!

@jsulinski
Copy link
Contributor Author

@bison Thanks, updated.

@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://github.com/kubernetes/kubernetes/wiki/CLA-FAQ to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. and removed cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jul 14, 2017
@jsulinski
Copy link
Contributor Author

@icereval Do you want to add watchNamespace too? I haven't had time to test this yet but it would be good to add. Thanks!

@mgoodness
Copy link
Contributor

I can take care of watchNamespace, too, since it's RBAC-related. Will ping you all when I think it's ready.

@mgoodness
Copy link
Contributor

I think this will do it. RBAC for --watch-namespace is a bit funky. If controller.scope.enabled=true and controller.scope.namespace is set (meaning we're watching a namespace that isn't .Release.Namespace), we'll add get namespaces for that namespace to the ClusterRole. If controller.scope.enabled=true and controller.scope.namespace is not set, then we don't add get namespaces to the ClusterRole and simply rely on permission granted by the Role.

I've not actually tested this, but wanted to document it before I shut down for the night.

@jsulinski
Copy link
Contributor Author

Thanks a lot! I tested this and it works for my albeit limited use case. I have not tested namespaces, however.

The design you described for clusterRole makes sense to me, but I would take that with a grain of salt. :)

@mgoodness
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 14, 2017
@mgoodness
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 14, 2017
@mgoodness mgoodness merged commit c1ede62 into helm:master Aug 14, 2017
@jsulinski
Copy link
Contributor Author

Awesome. Thanks a lot for helping get this over the finish line! Really appreciate it.

erickt added a commit to erickt/charts that referenced this pull request Oct 31, 2017
This option was added helm#1235 by @jsulinski, but as best as I can tell,
`defaultSSLCertificate` was not wired up.
dmitry-j-mikhin pushed a commit to dmitry-j-mikhin/ingress-chart that referenced this pull request Feb 27, 2020
* nginx-ingress: fix spacing for events

* Add RBAC support

* Add RBAC support for nginx-ingress

based on: helm/charts#1235

* Pull in new RBAC changes from kubernetes/ingress-nginx@4618fd2

* Move resourceNames to a value

* templates: use a range loop to render the resourceNames

* this produces the correctly formatted output we are looking for, specifically
  with regard to the extra carriage return which didn't want to be chomped away
  by the usual `-` method.

* Tweak RBAC

* Bump chart versions

* Fix README

* Restrict namespace RBAC if scoped
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.