Skip to content

Commit 8d535a6

Browse files
bentitocamilamacedo86michaelryanpeterjoelanford
authored
📖 [Docs] Document the granting of API access (operator-framework#1407)
* Document granting API access Signed-off-by: Brett Tofel <[email protected]> * Addressing PR comments Signed-off-by: Brett Tofel <[email protected]> * Addressing PR comments 2 Signed-off-by: Brett Tofel <[email protected]> * Reorders document Signed-off-by: Brett Tofel <[email protected]> * Improve wording on explanation around access needs Co-authored-by: Camila Macedo <[email protected]> * Improved wording on OLM not managing RBAC Co-authored-by: Camila Macedo <[email protected]> * Clarify admin and edit roles Co-authored-by: Camila Macedo <[email protected]> * Draw attention to RBAC all verbs grant Co-authored-by: Camila Macedo <[email protected]> * Clarify role vs. binding recommendations in notes Signed-off-by: Brett Tofel <[email protected]> * Cluster extension everywhere we had operator ref Signed-off-by: Brett Tofel <[email protected]> * Improved wordigin on rbac mention Co-authored-by: Michael Peter <[email protected]> * Improve wording around who the users are Co-authored-by: Michael Peter <[email protected]> * Add mkdocs ref and move to howto Signed-off-by: Brett Tofel <[email protected]> * Clarify what admin clusterrole does Co-authored-by: Joe Lanford <[email protected]> * Clean up what * verb allows Co-authored-by: Joe Lanford <[email protected]> * Removes Notes section - covered in intro Signed-off-by: Brett Tofel <[email protected]> * Reword mkdocs link text Signed-off-by: Brett Tofel <[email protected]> * ReReword mkdocs link text Signed-off-by: Brett Tofel <[email protected]> --------- Signed-off-by: Brett Tofel <[email protected]> Co-authored-by: Camila Macedo <[email protected]> Co-authored-by: Michael Peter <[email protected]> Co-authored-by: Joe Lanford <[email protected]>
1 parent bb80643 commit 8d535a6

File tree

2 files changed

+175
-0
lines changed

2 files changed

+175
-0
lines changed

Diff for: docs/howto/how-to-grant-api-access.md

+174
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
2+
# Granting Users Access to API Resources in OLM
3+
4+
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.
5+
6+
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.
7+
8+
---
9+
10+
## 1. Finding API Groups and Resources Provided by a ClusterExtension
11+
12+
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:
13+
14+
```bash
15+
kubectl get crds
16+
```
17+
18+
This will list all available CRDs, and you can inspect individual CRDs for their API groups:
19+
20+
```bash
21+
kubectl get crd <crd-name> -o yaml
22+
```
23+
24+
A user can use label selectors to find CRDs owned by a specific cluster extension:
25+
26+
```bash
27+
kubectl get crds -l 'olm.operatorframework.io/owner-kind=ClusterExtension,olm.operatorframework.io/owner-name=<clusterExtensionName>'
28+
```
29+
30+
---
31+
32+
## 2. Creating Default ClusterRoles for API/CRD Access
33+
34+
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.
35+
36+
### Default Roles
37+
38+
- **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.
39+
- **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.
40+
- **Admin ClusterRole**: Provides full permissions (create, update, delete) over all custom resource objects for the specified API resources across the cluster.
41+
42+
### Example: Defining a Custom "View" ClusterRole
43+
44+
```yaml
45+
apiVersion: rbac.authorization.k8s.io/v1
46+
kind: ClusterRole
47+
metadata:
48+
name: custom-resource-view
49+
rules:
50+
- apiGroups:
51+
- <your-api-group>
52+
resources:
53+
- <your-custom-resources>
54+
verbs:
55+
- get
56+
- list
57+
- watch
58+
```
59+
60+
### Example: Defining a Custom "Edit" ClusterRole
61+
62+
```yaml
63+
apiVersion: rbac.authorization.k8s.io/v1
64+
kind: ClusterRole
65+
metadata:
66+
name: custom-resource-edit
67+
rules:
68+
- apiGroups:
69+
- <your-api-group>
70+
resources:
71+
- <your-custom-resources>
72+
verbs:
73+
- get
74+
- list
75+
- watch
76+
- create
77+
- update
78+
- patch
79+
- delete
80+
```
81+
82+
### Example: Defining a Custom "Admin" ClusterRole
83+
84+
```yaml
85+
apiVersion: rbac.authorization.k8s.io/v1
86+
kind: ClusterRole
87+
metadata:
88+
name: custom-resource-admin
89+
rules:
90+
- apiGroups:
91+
- <your-api-group>
92+
resources:
93+
- <your-custom-resources>
94+
verbs:
95+
- '*'
96+
```
97+
**Note**: The `'*'` in verbs allows all actions on the specified resources
98+
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.
99+
100+
---
101+
102+
## 3. Granting User Access to API Resources
103+
104+
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:
105+
106+
### Option 1: Binding Default ClusterRoles to Users
107+
108+
- **ClusterRoleBinding**: Use this to grant access across all namespaces.
109+
- **RoleBinding**: Use this to grant access within a specific namespace.
110+
111+
#### Example: ClusterRoleBinding
112+
113+
```yaml
114+
apiVersion: rbac.authorization.k8s.io/v1
115+
kind: ClusterRoleBinding
116+
metadata:
117+
name: custom-resource-view-binding
118+
subjects:
119+
- kind: User
120+
name: <username> # Or use Group for group-based binding
121+
roleRef:
122+
kind: ClusterRole
123+
name: custom-resource-view
124+
apiGroup: rbac.authorization.k8s.io
125+
```
126+
127+
This binding grants `<username>` read-only access to the custom resource across all namespaces.
128+
129+
#### Example: RoleBinding
130+
131+
```yaml
132+
apiVersion: rbac.authorization.k8s.io/v1
133+
kind: RoleBinding
134+
metadata:
135+
name: custom-resource-edit-binding
136+
namespace: <namespace>
137+
subjects:
138+
- kind: User
139+
name: <username>
140+
roleRef:
141+
kind: Role
142+
name: custom-resource-edit
143+
apiGroup: rbac.authorization.k8s.io
144+
```
145+
146+
This RoleBinding restricts permissions to a specific namespace.
147+
148+
### Option 2: Extending Default Kubernetes Roles
149+
150+
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.
151+
152+
#### Example: Adding Aggregation Labels to a ClusterRole
153+
154+
```yaml
155+
apiVersion: rbac.authorization.k8s.io/v1
156+
kind: ClusterRole
157+
metadata:
158+
name: custom-resource-aggregated-view
159+
labels:
160+
rbac.authorization.k8s.io/aggregate-to-view: "true"
161+
rules:
162+
- apiGroups:
163+
- <your-api-group>
164+
resources:
165+
- <your-custom-resource>
166+
verbs:
167+
- get
168+
- list
169+
- watch
170+
```
171+
172+
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.
173+
174+
> **Source**: [Kubernetes RBAC Aggregation](https://kubernetes.io/docs/reference/access-authn-authz/rbac/#default-roles-and-role-bindings)

Diff for: mkdocs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ nav:
4141
- Version Range Upgrades: howto/how-to-version-range-upgrades.md
4242
- Z-Stream Upgrades: howto/how-to-z-stream-upgrades.md
4343
- Derive Service Account Permissions: howto/derive-service-account.md
44+
- Grant Access to Your Extension's API: howto/how-to-grant-api-access.md
4445
- Conceptual Guides:
4546
- Single Owner Objects: concepts/single-owner-objects.md
4647
- Upgrade Support: concepts/upgrade-support.md

0 commit comments

Comments
 (0)