Skip to content
This repository was archived by the owner on Nov 14, 2024. It is now read-only.

internal/checks/kube: add more API resource requirements #10

Merged
merged 2 commits into from
Aug 27, 2021

Conversation

johnstcn
Copy link
Member

This updates the list of ResourceRequirements based on the permissions required to install Coder into a clean KinD cluster.
An initial role/rolebinding/user were created in the cluster, and permissions gradually added to the role until the helm install succeeded.

I ended up needing to break out some of the ResourceRequirements into a separate RoleOnlyResourceRequirements, due to how the role is specified in enterprise-helm. A number of the resources required to create the role don't seem to be things that can exist in the real world (please do correct me if I'm mistaken!)

At this point, running the check is starting to take a while, so I'd say the next step is to look into parallelising the RBAC checks (or using the equivalent API call to kubectl auth can-i --list).

@johnstcn johnstcn requested a review from jawnsy August 27, 2021 14:40
@johnstcn johnstcn self-assigned this Aug 27, 2021
@shortcut-integration
Copy link

This pull request has been linked to Clubhouse Story #15962: Checks for required cluster API resources.

}

// TODO: delete this when the enterprise-helm role no longer requests resources on things
// that don't exist.
Copy link
Member Author

Choose a reason for hiding this comment

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

This is 100% duplicated code, but it's easy to delete.

NewResourceRequirement("metrics.k8s.io", "v1beta1", "storageclasses"): verbsGetListWatch,
NewResourceRequirement("networking.k8s.io", "v1", "deployments"): verbsAll,
NewResourceRequirement("networking.k8s.io", "v1", "events"): verbsAll,
NewResourceRequirement("networking.k8s.io", "v1", "persistentvolumeclaims"): verbsAll,
Copy link
Contributor

Choose a reason for hiding this comment

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

some of these don't appear to be networking requirements, maybe a typo of the group name here?

Not sure if that's related to your comment:

I ended up needing to break out some of the ResourceRequirements into a separate RoleOnlyResourceRequirements, due to how the role is specified in enterprise-helm. A number of the resources required to create the role don't seem to be things that can exist in the real world (please do correct me if I'm mistaken!)

There might be an issue in our Helm chart... The RBAC permissions are done very generically at an API level, so do not account for whether or not the resources actually exist.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, the enterprise helm chart specifies the following:

rules:
  - apiGroups: ["", "apps", "networking.k8s.io"] # "" indicates the core API group
    resources: ["persistentvolumeclaims", "pods", "deployments", "services", "secrets", "pods/exec","pods/log", "events", "networkpolicies"]
    verbs: ["create", "get", "list", "watch", "update", "patch", "delete", "deletecollection"]
  - apiGroups: ["metrics.k8s.io", "storage.k8s.io"]
    resources: ["pods", "storageclasses"]
    verbs: ["get", "list", "watch"]

That seems to be exploded by Kubernetes to the things we're seeing.
I agree that we should fix it. However, it's a pretty high-impact change that we'd want to approach carefully, and I don't want to make coder-doctor working properly dependant on that being fixed.

NewResourceRequirement("networking.k8s.io", "networking.k8s.io/v1", "ingresses"): verbsCreateDeleteList,
NewResourceRequirement("rbac.authorization.k8s.io", "rbac.authorization.k8s.io/v1", "roles"): verbsCreateDeleteList,
NewResourceRequirement("rbac.authorization.k8s.io", "rbac.authorization.k8s.io/v1", "rolebindings"): verbsCreateDeleteList,
NewResourceRequirement("", "v1", "events"): verbsAll,
Copy link
Contributor

Choose a reason for hiding this comment

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

Putting this here so we can have a threaded discussion:

At this point, running the check is starting to take a while, so I'd say the next step is to look into parallelising the RBAC checks (or using the equivalent API call to kubectl auth can-i --list).

@johnstcn I think it's preferable to figure out if we can reduce our requests before we parallelize, because doing stuff in parallel increases load on the API server and it might have throttling in place anyways. Is it possible to check multiple RBAC settings in one API call?

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, I believe doing the equivalent of kubectl auth can-i --list should work here.
Would you be happy with me pursuing this in a separate PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, working code is better than perfect code :)

@johnstcn johnstcn merged commit e9134d0 into main Aug 27, 2021
@johnstcn johnstcn deleted the cianjohnston/ch15962/more-api-resources branch August 27, 2021 15:10
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.

2 participants