# Asignación de permisos para el API

<span style="font-weight: 400;">A continuación se describen los pasos a seguir para crear un usuario con los permisos suficientes para obtener los datos de la monitorización.</span>

1. <span style="font-weight: 400;">Creación de un “</span>*<span style="font-weight: 400;">Cluster role</span>*<span style="font-weight: 400;">” de lectura llamado “</span>*<span style="font-weight: 400;">api-read-only</span>*<span style="font-weight: 400;">”: Se creará un rol que conceda los permisos “</span>*<span style="font-weight: 400;">get</span>*<span style="font-weight: 400;">”, “</span>*<span style="font-weight: 400;">list</span>*<span style="font-weight: 400;">” y “</span>*<span style="font-weight: 400;">watch</span>*<span style="font-weight: 400;">” de todos los recursos de Kubernetes.</span>

```
cat <<EOF | kubectl apply -f -
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  annotations:
    rbac.authorization.kubernetes.io/autoupdate: "true"
  labels:
  name: api-read-only
rules:
- apiGroups:
  - '*'
  resources:
  - '*'
  verbs:
  - get
  - list
  - watch
- nonResourceURLs:
  - '*'
  verbs:
  - get
  - list
  - watch
EOF

```

<span style="font-weight: 400;">2. Creación de un “</span>*<span style="font-weight: 400;">Cluster role binding</span>*<span style="font-weight: 400;">” llamado “</span>*<span style="font-weight: 400;">bind-api-read-only</span>*<span style="font-weight: 400;">”: Se vinculará el rol creado anteriormente a una “</span>*<span style="font-weight: 400;">service account</span>*<span style="font-weight: 400;">” ya existente.</span>

```
kubectl create clusterrolebinding bind-api-read-only \
  --clusterrole=api-read-only \
  --serviceaccount=namespace:user
```