Kubernetes authorization
Set up authorization policies for cluster state updates
Requests authorization follows an allow list pattern: explicit policies must be set to allow state updates.
- Any request to
kube-apiserverthat includes an API group AND an API version is a resource request :- Specs for supported resource requests are available in the
openapiAPI. - Resource requests can target cluster resources as well as workload resources.
-
kube-apiserversupports mutiple verbs for resource requests. - Authorized resource requests can lead to desired cluster state updates.
- Specs for supported resource requests are available in the
- Examples:
/api/v1,/apis/apps/v1,/apis/apps/v1/namespaces/{ns}/deployments/{dp}/status, etc ...
- Any request to
kube-apiservernot including an API group and version is a non-resource request :- Non-resources requests are not documented in the
openapiAPI. - Non-resource requests exist mainly for cluster observability purposes.
- As a result,
kube-apiserveronly supportsGETfor non-resource requests. - Authorized non-resource requests do not update the desired cluster state.
- Non-resources requests are not documented in the
- Examples :
/api,/apis,/metrics/*,/healthz/*, etc ...
- Authorizations are configured the same way for resource and non-resource requests.
- Observability solutions relying on non-resource requests usually ship with the required authorizations.
- As a result, authorization configuration for non-resource requests is considered out of scope for this document.
- Relevant attributes for authorization are read from requests and evaluated against configured authorizers.
- Configured authorizers for
kube-apiservercan be set up with the--authorization-modeoption. - For simplicity's sake, this document will focus on
kubeadm initdefault authorizersRBACandNode. - The following authorizers are relevant but considered out of scope :
- Role-based authorization policies are implemented in the API group
rbac.authorization.k8s.io/v1. - This API provides a set of resource types for management of authorization policies as part of the cluster state.
-
PolicyRuleis a subresource authorizing verbs for an API version and a resource type. - The discovery API exposes supported resource types for all API groups and versions.
- For instance, GET
/apis/apps/v1will list resource types for named API groupapps. -
resourcesforPolicyRuleobjects may refer to :- singular resource types if the verbs acts on a single resource.
- plural resource types if the verbs acts on a collection of resources.
Role and ClusterRole
-
RoleandClusterRoleobjects store sets of permissions as lists ofPolicyRuleobjects. -
Roleobjects are namespaced as opposed toClusterRoleobjects :-
Rolepermissions only apply to objects in the same namespace. -
ClusterRolepermissions apply to all objects in the cluster.
-
- Permissions for non namespaced objects (cluster resources) can only be managed using
ClusterRole.
-
Subjectis a subresource referencing the origin user of an authenticated request. -
kindforSubjectobjects can beUser(for normal users),ServiceAccountorGroup.
-
RoleBindingandClusterRoleBindingobjects bind lists ofSubjectobjects to existing roles :-
RoleBindingobjects are namespaced as opposed toClusterRoleBindingobjects. -
RoleBindingrestricts permissions granted by the role to objects in the same namespace. -
ClusterRoleBindingsystematically allows every permission granted by the role.
-
- The
roleRefproperty for both objects is immutable: the referenced role cannot change.
- When configured, the
RBACauthorizer automatically provisions roles and bindings :
# list bindings and roles and mappings for default RBAC policies
kubectl get clusterrolebindings -l kubernetes.io/bootstrapping=rbac-defaults
kubectl get rolebindings -l kubernetes.io/bootstrapping=rbac-defaults --all-namespaces-
Matching those policies against user
groupsprovide default authorization settings for requests. -
Most roles and bindings are reserved for component authorization (controllers, etc ...) except :
ClusterRoleBindingGroupsubjectdescription cluster-adminsystem:mastersFull cluster control system:discoverysystem:authenticatedRead discovery API system:basic-usersystem:authenticatedCreate self-subject reviews system:public-info-viewerEveryone Read versionand health API
Notes :
- Additional provisioning of
RBACpolicies is also done bykubeadmas well as by installed add-ons. - Modifying
RBACobjects can lead to privilege escalation, however K8s performs additional security checks. kubectl auth reconcilecan be used as an alternative tokubectl applyto updateRBACobjects without removing any existing permission: however, using it is not recommended.
- The default configured, special purpose
Nodeauthorizer authorizeskubeletrequests tokube-apiserver. - The default configured
NodeRestrictionadmission controller restrictskubeletwrite requests to :- Updates of the
Nodeobject for its own node. - Updates of the
Podobjects for pods running on its own node. - Creation of
Events. - Creation of CSRs and self-review objects.
- Updates of the
-
RBACdefaults also provision asystem:noderole and binding that seem to mirrorNodepermissions :
# YAML list of allowed verbs and resource types for the system:node role
kubectl get clusterrole system:node -o JSON | \
jq -r '.rules[] | {groups: (.apiGroups | join(", ")), resources: (.resources | join(", ")), verbs: (.verbs | join(", "))} | "- group: \(.groups)\n resources: \(.resources)\n verbs: \"\(.verbs)\""'- However, it is unsure whether or not those permissions are actually considered by the
Nodeauthorizer.