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

Run with fewer privileges #228

Merged
merged 3 commits into from
Oct 7, 2020
Merged

Run with fewer privileges #228

merged 3 commits into from
Oct 7, 2020

Conversation

negz
Copy link
Member

@negz negz commented Oct 6, 2020

Fixes #218

This commit updates the Helm chart to avoid running as cluster-admin. Instead, the controller runs only with the privileges it needs 'out of the box'; i.e. to manage all core OAM types, as well as deployments and services.

The commit also includes a few small chart hygiene fixes; i.e. ensuring that names will not collide when multiple releases exist in the same cluster, and that all resources include the standard labels.

aggregationRule:
clusterRoleSelectors:
- matchLabels:
rbac.oam.dev/aggregate-to-controller: "true"
Copy link
Member Author

Choose a reason for hiding this comment

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

I elected to use cluster role aggregation here so that it would be easy for users to extend the privileges of the OAM controller. I was thinking this could help with supporting new non-core kinds of workloads and traits; e.g. if those kinds were created by the core AppConfig controller, but reconciled by controllers running as distinct deployments in the cluster.

This commit updates the Helm chart to avoid running as cluster-admin. Instead,
the controller runs only with the privileges it needs 'out of the box'; i.e. to
manage all core OAM types, as well as deployments and services.

The commit also includes a few small chart hygiene fixes; i.e. ensuring that
names will not collide when multiple releases exist in the same cluster, and
that all resources include the standard labels.

Signed-off-by: Nic Cope <[email protected]>
@negz negz marked this pull request as ready for review October 6, 2020 22:34
This ensures the Helm chart grants the required permissions for the e2e tests to
pass (except for the custom example.com types used by the test).

Signed-off-by: Nic Cope <[email protected]>
@negz
Copy link
Member Author

negz commented Oct 7, 2020

I believe this is good to go - I've tested it by updating the e2e tests to run with only the privileges the Helm chart grants them (plus an additional aggregate role that grants access to example.com resources).

@wonderflow
Copy link
Member

Thanks @negz ! This PR is good, but I wonder it would be hard for user to register a new CRD to work as an OAM trait/workload.

Currently, only a WorkloadDefinition/TraitDefinition is needed. Can you give an example workflow if we add this aggregate mechanism to register a new CRD, it would also help us to understand this PR better!

@negz
Copy link
Member Author

negz commented Oct 7, 2020

I wonder it would be hard for user to register a new CRD to work as an OAM trait/workload.

Can you give an example workflow if we add this aggregate mechanism to register a new CRD, it would also help us to understand this PR better!

The process is identical, except that the person who authors the CRD and the WorkloadDefinition (or ScopeDefinition) must also author a ClusterRole that grants the OAM controller access to that type, so that the AppConfig controller can create, update, and delete it as necessary. This seems like a critical best practice to me; we should not run our controllers as cluster-admin.

The example in the e2e tests may be a good illustration of this. We create the CRD and WorkloadDefinition for foo.example.com so that it may be used as a workload. At this point the OAM controller does not have RBAC access to use a kind: Foo, so we must also grant that access via a ClusterRole:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: foo.example.com
  labels:
    rbac.oam.dev/aggregate-to-controller: "true"
rules:
- apiGroups:
  - example.com
  resources:
  - foo
  verbs:
  - "*"

https://crossplane.slack.com/archives/CTHADJCEN/p1600977951000500

This approach was discussed in the above Slack conversation. There may be further automation we can do in future, like Crossplane's RBAC manager, but for now I feel it's a good compromise to allow us to feel comfortable including oam-kubernetes-runtime with Crossplane v0.13 later this week.

Copy link
Collaborator

@ryanzhang-oss ryanzhang-oss left a comment

Choose a reason for hiding this comment

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

Thank you for working on this

Copy link
Member

@wonderflow wonderflow left a comment

Choose a reason for hiding this comment

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

Thanks @negz

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Run with fewer privileges
4 participants