It appears kubectl
has first-class support via api-resources
like:
$ kubectl api-resources -o wide
$ kubectl api-resources --api-group certificates.k8s.io -o wide
$ kubectl api-resources --namespaced -o wide
Alternatively, we can use curl
to query Kubernetes API, but we have to expose the API endpoint first:
$ kubectl proxy --port 8080 &
Lookup API groups (known as named groups)
$ GROUP_NAME="certificates.k8s.io"
$ RESOURCE_NAME="certificatesigningrequests"
$ curl -s http://localhost:8080/apis | jq -r '.groups[] | .name'
$ curl -s http://localhost:8080/apis | jq -r --arg group_name "$GROUP_NAME" '.groups[] | select(.name | contains($group_name))'
$ api_uri=$(curl -s http://localhost:8080/apis | jq -r --arg group_name "$GROUP_NAME" '.groups[] | select(.name | contains($group_name)) | .preferredVersion.groupVersion')
$ curl -s http://localhost:8080/apis/$api_uri | jq -r '.resources[] | [.name, (.verbs | join(" "))] | join(" = ")'
$ curl -s http://localhost:8080/apis/$api_uri | jq -r --arg resource_name "$RESOURCE_NAME" '.resources[] | select(.name | contains($resource_name)) | [.name, (.verbs | join(" "))] | join(" = ")'
Lookup core APIs (known as legacy)
$ RESOURCE_NAME="configmaps"
$ curl -s http://localhost:8080/api/v1 | jq -r '.resources[] | .name'
$ curl -s http://localhost:8080/api/v1 | jq -r '.resources[] | [.name, (.verbs | join(" "))] | join(" = ")'
$ curl -s http://localhost:8080/api/v1 | jq -r --arg resource_name "$RESOURCE_NAME" '.resources[] | select(.name | contains($resource_name)) | [.name, (.verbs | join(" "))] | join(" = ")'
Reference
Special verbs (permissions)
impersonate
- allows impersonation in typical CLI commands by using--as
and--as-group
, https://kubernetes.io/docs/concepts/security/rbac-good-practices/#impersonate-verbbind
- grants special or exceptional authority to permit roles binding, it covers onlyroles
orclusterroles
resources of therbac.authorization.k8s.io
API group (a list of roles can be controlled viaresourceNames
), ref. https://kubernetes.io/docs/concepts/security/rbac-good-practices/#bind-verbescalate
- allows elevation of privileges beyond the existing permissions boundary, it covers onlyroles
orclusterroles
resources of therbac.authorization.k8s.io
API group, ref. https://kubernetes.io/docs/concepts/security/rbac-good-practices/#escalate-verbNotes
Examples
For example, this
ClusterRole
andRoleBinding
would allowuser-1
to grant other users theadmin
,edit
, andview
roles in the namespaceuser-1-namespace
:Impersonate all SAs:
Impersonate a user:
References