Skip to content

Commit 69eaaa0

Browse files
authored
Document RBAC configuration for Flux (#62)
This relies on the "RBAC for Users" documentation, and it generalizes those steps a bit to make it easier to cut-n-paste them for the flux user case. Signed-off-by: Dean Roehrich <dean.roehrich@hpe.com>
1 parent b5eea22 commit 69eaaa0

1 file changed

Lines changed: 72 additions & 19 deletions

File tree

docs/guides/rbac-for-users/readme.md

Lines changed: 72 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ authors: Matt Richerson <matthew.richerson@hpe.com>
33
categories: setup
44
---
55

6-
# RBAC for Users
6+
# RBAC: Role-Based Access Control
77

8-
This document shows how to create a kubeconfig file with RBAC set up to restrict access to view only for resources.
8+
RBAC (Role Based Access Control) determines the operations a user or service can perform on a list of Kubernetes resources. RBAC affects everything that interacts with the kube-apiserver (both users and services internal or external to the cluster). More information about RBAC can be found in the Kubernetes [***documentation***](https://kubernetes.io/docs/reference/access-authn-authz/rbac/).
99

10-
## Overview
10+
## RBAC for Users
1111

12-
RBAC (Role Based Access Control) determines the operations a user or service can perform on a list of Kubernetes resources. RBAC affects everything that interacts with the kube-apiserver (both users and services internal or external to the cluster). More information about RBAC can be found in the Kubernetes [***documentation***](https://kubernetes.io/docs/reference/access-authn-authz/rbac/).
12+
This section shows how to create a kubeconfig file with RBAC set up to restrict access to view only for resources.
13+
14+
### Overview
1315

1416
User access to a Kubernetes cluster is defined through a kubeconfig file. This file contains the address of the kube-apiserver as well as the key and certificate for the user. Typically this file is located in `~/.kube/config`. When a kubernetes cluster is created, a config file is generated for the admin that allows unrestricted access to all resources in the cluster. This is the equivalent of `root` on a Linux system.
1517

@@ -19,46 +21,49 @@ The goal of this document is to create a new kubeconfig file that allows view on
1921
- Creating a new kubeconfig file
2022
- Adding RBAC rules for the "hpe" user to allow read access
2123

22-
## Generate a Key and Certificate
24+
### Generate a Key and Certificate
2325

2426
The first step is to create a new key and certificate so that HPE employees can authenticate as the "hpe" user. This will likely be done on one of the master nodes. The `openssl` command needs access to the certificate authority file. This is typically located in `/etc/kubernetes/pki`.
2527

2628
```bash
2729

2830
# make a temporary work space
29-
mkdir /tmp/hpe
30-
cd /tmp/hpe
31+
mkdir /tmp/rabbit
32+
cd /tmp/rabbit
33+
34+
# Create this user
35+
export USERNAME=hpe
3136

3237
# generate a new key
33-
openssl genrsa -out hpe.key 2048
38+
openssl genrsa -out rabbit.key 2048
3439

35-
# create a certificate signing request for the "hpe" user
36-
openssl req -new -key hpe.key -out hpe.csr -subj "/CN=hpe"
40+
# create a certificate signing request for this user
41+
openssl req -new -key rabbit.key -out rabbit.csr -subj "/CN=$USERNAME"
3742

3843
# generate a certificate using the certificate authority on the k8s cluster. This certificate lasts 500 days
39-
openssl x509 -req -in hpe.csr -CA /etc/kubernetes/pki/ca.crt -CAkey /etc/kubernetes/pki/ca.key -CAcreateserial -out hpe.crt -days 500
44+
openssl x509 -req -in rabbit.csr -CA /etc/kubernetes/pki/ca.crt -CAkey /etc/kubernetes/pki/ca.key -CAcreateserial -out rabbit.crt -days 500
4045

4146
```
4247

43-
## Create a kubeconfig
48+
### Create a kubeconfig
4449

45-
After the keys have been generated, a new kubeconfig file can be created for the "hpe" user. The admin kubeconfig `/etc/kubernetes/admin.conf` can be used to determine the cluster name kube-apiserver address.
50+
After the keys have been generated, a new kubeconfig file can be created for this user. The admin kubeconfig `/etc/kubernetes/admin.conf` can be used to determine the cluster name kube-apiserver address.
4651

4752
```bash
4853

4954
# create a new kubeconfig with the server information
50-
kubectl config set-cluster {CLUSTER_NAME} --kubeconfig=/tmp/hpe/hpe.conf --server={SERVER_ADDRESS} --certificate-authority=/etc/kubernetes/pki/ca.crt --embed-certs=true
55+
kubectl config set-cluster $CLUSTER_NAME --kubeconfig=/tmp/rabbit/rabbit.conf --server=$SERVER_ADDRESS --certificate-authority=/etc/kubernetes/pki/ca.crt --embed-certs=true
5156

52-
# add the key and cert for the "hpe" user to the config
53-
kubectl config set-credentials hpe --kubeconfig=/tmp/hpe/hpe.conf --client-certificate=/tmp/hpe/hpe.crt --client-key=/tmp/hpe/hpe.key --embed-certs=true
57+
# add the key and cert for this user to the config
58+
kubectl config set-credentials $USERNAME --kubeconfig=/tmp/rabbit/rabbit.conf --client-certificate=/tmp/rabbit/rabbit.crt --client-key=/tmp/rabbit/rabbit.key --embed-certs=true
5459

5560
# add a context
56-
kubectl config set-context hpe-context --kubeconfig=/tmp/hpe/hpe.conf --cluster={CLUSTER_NAME} --user=hpe
61+
kubectl config set-context $USERNAME --kubeconfig=/tmp/rabbit/rabbit.conf --cluster=$CLUSTER_NAME --user=$USERNAME
5762
```
5863

5964
The kubeconfig file should be placed in a location where HPE employees have read access to it.
6065

61-
## Create ClusterRole and ClusterRoleBinding
66+
### Create ClusterRole and ClusterRoleBinding
6267

6368
The next step is to create ClusterRole and ClusterRoleBinding resources. The ClusterRole provided allows viewing all cluster and namespace scoped resources, but disallows creating, deleting, or modifying any resources.
6469

@@ -92,10 +97,58 @@ roleRef:
9297
9398
Both of these resources can be created using the `kubectl apply` command.
9499

95-
## Testing
100+
### Testing
96101

97102
Get, List, Create, Delete, and Modify operations can be tested as the "hpe" user by setting the KUBECONFIG environment variable to use the new kubeconfig file. Get and List should be the only allowed operations. Other operations should fail with a "forbidden" error.
98103

99104
```bash
100105
export KUBECONFIG=/tmp/hpe/hpe.conf
101106
```
107+
108+
## RBAC for Workload Manager (WLM)
109+
110+
**Note** This section assumes the reader has read and understood the steps described above for setting up `RBAC for Users`.
111+
112+
A workload manager (WLM) such as [Flux](https://github.com/flux-framework) or [Slurm](https://slurm.schedmd.com) will interact with [DataWorkflowServices](https://dataworkflowservices.github.io) as a privileged user. RBAC is used to limit the operations that a WLM can perform on a Rabbit system.
113+
114+
The following steps are required to create a user and a role for the WLM. In this case, we're creating a user to be used with the Flux WLM:
115+
116+
- Generate a new key/cert pair for a "flux" user
117+
- Creating a new kubeconfig file
118+
- Adding RBAC rules for the "flux" user to allow appropriate access to the DataWorkflowServices API.
119+
120+
### Generate a Key and Certificate
121+
122+
Generate a key and certificate for our "flux" user, similar to the way we created one for the "hpe" user above. Substitute "flux" in place of "hpe".
123+
124+
### Create a kubeconfig
125+
126+
After the keys have been generated, a new kubeconfig file can be created for the "flux" user, similar to the one for the "hpe" user above. Again, substitute "flux" in place of "hpe".
127+
128+
### Apply the provided ClusterRole and create a ClusterRoleBinding
129+
130+
DataWorkflowServices has already defined the role to be used with WLMs. Simply apply the `workload-manager` ClusterRole from DataWorkflowServices to the system:
131+
132+
```console
133+
kubectl apply -f https://github.com/HewlettPackard/dws/raw/master/config/rbac/workload_manager_role.yaml
134+
```
135+
136+
Create and apply a ClusterRoleBinding to associate the "flux" user with the `workload-manager` ClusterRole:
137+
138+
ClusterRoleBinding
139+
```yaml
140+
apiVersion: rbac.authorization.k8s.io/v1
141+
kind: ClusterRoleBinding
142+
metadata:
143+
name: flux
144+
subjects:
145+
- kind: User
146+
name: flux
147+
apiGroup: rbac.authorization.k8s.io
148+
roleRef:
149+
kind: ClusterRole
150+
name: workload-manager
151+
apiGroup: rbac.authorization.k8s.io
152+
```
153+
154+
The WLM should then use the kubeconfig file associated with this "flux" user to access the DataWorkflowServices API and the Rabbit system.

0 commit comments

Comments
 (0)