-
Notifications
You must be signed in to change notification settings - Fork 67
📖 [Docs] Document the granting of API access #1407
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
Merged
bentito
merged 18 commits into
operator-framework:main
from
bentito:doc-granting-api-access
Nov 7, 2024
Merged
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
883473c
Document granting API access
bentito 9db34a2
Addressing PR comments
bentito 746c32c
Addressing PR comments 2
bentito 899bf9e
Reorders document
bentito 2c96081
Improve wording on explanation around access needs
bentito 9f75853
Improved wording on OLM not managing RBAC
bentito f4821bd
Clarify admin and edit roles
bentito 8e1a3e1
Draw attention to RBAC all verbs grant
bentito 3ff403a
Clarify role vs. binding recommendations in notes
bentito 98c3b3b
Cluster extension everywhere we had operator ref
bentito 6e022f2
Improved wordigin on rbac mention
bentito 25f0612
Improve wording around who the users are
bentito b836ea5
Add mkdocs ref and move to howto
bentito ef713c5
Clarify what admin clusterrole does
bentito 1e170e4
Clean up what * verb allows
bentito d74fe78
Removes Notes section - covered in intro
bentito 784a378
Reword mkdocs link text
bentito 99d27c4
ReReword mkdocs link text
bentito 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 hidden or 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,181 @@ | ||
|
||
# Granting Users Access to API Resources in OLM | ||
|
||
When cluster extensions are managed via OLM, they often provide Custom Resource Definitions (CRDs) that expose new API resources. Typically, cluster administrators have full management access to these resources by default, whereas non-administrative users might lack sufficient permissions. Cluster administrators must create the needed permissions to create, view, or edit these Custom Resources for these users. | ||
|
||
OLM v1 does **not** automatically configure or manage role-based access control (RBAC) for users to interact with the APIs provided by installed packages. Cluster administrators must manage RBAC to grant appropriate permissions to non-administrative users. This guide outlines the steps to manually configure RBAC, with a focus on creating ClusterRoles and binding them to specific users or groups. | ||
|
||
--- | ||
|
||
## 1. Finding API Groups and Resources Provided by a ClusterExtension | ||
|
||
To create appropriate RBAC policies, you need to know which API groups and resources are exposed by the installed cluster extension. You can inspect the installed CRDs and resources by running: | ||
|
||
```bash | ||
kubectl get crds | ||
``` | ||
|
||
This will list all available CRDs, and you can inspect individual CRDs for their API groups: | ||
|
||
```bash | ||
kubectl get crd <crd-name> -o yaml | ||
``` | ||
|
||
A user can use label selectors to find CRDs owned by a specific cluster extension: | ||
|
||
```bash | ||
kubectl get crds -l 'olm.operatorframework.io/owner-kind=ClusterExtension,olm.operatorframework.io/owner-name=<clusterExtensionName>' | ||
``` | ||
|
||
--- | ||
|
||
## 2. Creating Default ClusterRoles for API/CRD Access | ||
|
||
Administrators can define standard roles to control access to the API resources provided by installed cluster extensions. If the cluster extension does not provide default roles, you can create them yourself. | ||
|
||
### Default Roles | ||
|
||
- **View ClusterRole**: Grants read-only access to all custom resource objects of specified API resources across the cluster. This role is intended for users who need visibility into the resources without any permissions to modify them. It’s ideal for monitoring purposes and limited access viewing. | ||
- **Edit ClusterRole**: Allows users to modify all custom resource objects within the cluster. This role enables users to create, update, and delete resources, making it suitable for team members who need to manage resources but should not control RBAC or manage permissions for others. | ||
- **Admin ClusterRole**: Provides full permissions (create, update, delete) over all custom resource objects for the specified API resources across the cluster. In addition to resource management, it grants users the ability to modify roles and bindings within the cluster, allowing them to delegate specific permissions to other users or groups as needed. | ||
|
||
### Example: Defining a Custom "View" ClusterRole | ||
|
||
```yaml | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: custom-resource-view | ||
rules: | ||
- apiGroups: | ||
- <your-api-group> | ||
resources: | ||
- <your-custom-resources> | ||
verbs: | ||
- get | ||
- list | ||
- watch | ||
``` | ||
### Example: Defining a Custom "Edit" ClusterRole | ||
```yaml | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: custom-resource-edit | ||
rules: | ||
- apiGroups: | ||
- <your-api-group> | ||
resources: | ||
- <your-custom-resources> | ||
verbs: | ||
- get | ||
- list | ||
- watch | ||
- create | ||
- update | ||
- patch | ||
- delete | ||
``` | ||
### Example: Defining a Custom "Admin" ClusterRole | ||
```yaml | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: custom-resource-admin | ||
rules: | ||
- apiGroups: | ||
- <your-api-group> | ||
resources: | ||
- <your-custom-resources> | ||
verbs: | ||
- '*' | ||
``` | ||
**Note**: The `'*'` in verbs allows all actions on the specified resources, including RBAC management actions such as assigning roles and creating role bindings. | ||
bentito marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
In each case, replace `<your-api-group>` and `<your-custom-resources>` with the actual API group and resource names provided by the installed cluster extension. | ||
|
||
--- | ||
|
||
## 3. Granting User Access to API Resources | ||
|
||
Once the roles are created, you can bind them to specific users or groups to grant them the necessary permissions. There are two main ways to do this: | ||
|
||
### Option 1: Binding Default ClusterRoles to Users | ||
|
||
- **ClusterRoleBinding**: Use this to grant access across all namespaces. | ||
- **RoleBinding**: Use this to grant access within a specific namespace. | ||
|
||
#### Example: ClusterRoleBinding | ||
|
||
```yaml | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: custom-resource-view-binding | ||
subjects: | ||
- kind: User | ||
name: <username> # Or use Group for group-based binding | ||
roleRef: | ||
kind: ClusterRole | ||
name: custom-resource-view | ||
apiGroup: rbac.authorization.k8s.io | ||
``` | ||
|
||
This binding grants `<username>` read-only access to the custom resource across all namespaces. | ||
|
||
#### Example: RoleBinding | ||
|
||
```yaml | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: custom-resource-edit-binding | ||
namespace: <namespace> | ||
subjects: | ||
- kind: User | ||
name: <username> | ||
roleRef: | ||
kind: Role | ||
name: custom-resource-edit | ||
apiGroup: rbac.authorization.k8s.io | ||
``` | ||
|
||
This RoleBinding restricts permissions to a specific namespace. | ||
|
||
### Option 2: Extending Default Kubernetes Roles | ||
|
||
To automatically extend existing Kubernetes roles (e.g., the default `view`, `edit`, and `admin` roles), you can add **aggregation labels** to **ClusterRoles**. This allows users who already have `view`, `edit`, or `admin` roles to interact with the custom resource without needing additional RoleBindings. | ||
|
||
#### Example: Adding Aggregation Labels to a ClusterRole | ||
|
||
```yaml | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: custom-resource-aggregated-view | ||
labels: | ||
rbac.authorization.k8s.io/aggregate-to-view: "true" | ||
rules: | ||
- apiGroups: | ||
- <your-api-group> | ||
resources: | ||
- <your-custom-resource> | ||
verbs: | ||
- get | ||
- list | ||
- watch | ||
``` | ||
|
||
You can create similar ClusterRoles for `edit` and `admin` with appropriate verbs (such as `create`, `update`, `delete` for `edit` and `admin`). By using aggregation labels, the permissions for the custom resources are added to the default roles. | ||
|
||
> **Source**: [Kubernetes RBAC Aggregation](https://kubernetes.io/docs/reference/access-authn-authz/rbac/#default-roles-and-role-bindings) | ||
|
||
--- | ||
|
||
## Notes | ||
|
||
- OLM does not handle RBAC for users interacting with CRDs, so it's up to cluster administrators to configure these settings. | ||
- It is not recommended for cluster extension bundles to include RBAC policies granting access via bindings or role aggregation to the cluster extension's APIs because cluster administrators should maintain control over the permissions in their clusters. Cluster extension packages can certainly add Roles that facilitate the functioning of the Cluster Exension. | ||
bentito marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.