RBAC and admission¶
Who may do what¶
| Actor | Identity | May |
|---|---|---|
| Platform admin | Member of an adminGroups group |
Create, delete, change every field, set approval annotations |
| Flux provisioner | system:serviceaccount:charter-system:charter-provisioner |
Same as an admin, plus create the per-client owner Role |
| Owning team | The ownerGroup bound by the per-client RoleBinding |
get, patch, update its one IAMClient; only redirectURIs may differ |
| Controller | system:serviceaccount:charter-system:charter-iam |
Finalizer and status, Secrets, PushSecrets, Events |
Controller ClusterRole¶
# Copyright (c) 2026 Erick Bourgeois, charter
# SPDX-License-Identifier: Apache-2.0
apiVersion: v1
kind: ServiceAccount
metadata:
name: charter-iam
namespace: charter-system
annotations:
# Azure Workload Identity: the Entra app (or user-assigned managed identity)
# this controller runs as. It needs Graph Application.ReadWrite.OwnedBy only.
azure.workload.identity/client-id: "00000000-0000-0000-0000-000000000000"
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: charter-iam
rules:
- apiGroups: ["iam.rbc.example"]
resources: ["iamclients"]
verbs: ["get", "list", "watch", "patch", "update"]
- apiGroups: ["iam.rbc.example"]
resources: ["iamclients/status"]
verbs: ["get", "patch", "update"]
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get", "list", "watch", "create", "patch"]
# Optional OpenBao delivery (spec.pushSecret). Harmless if ESO is not installed.
- apiGroups: ["external-secrets.io"]
resources: ["pushsecrets"]
verbs: ["get", "create", "patch", "delete"]
- apiGroups: ["events.k8s.io"]
resources: ["events"]
verbs: ["create"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: charter-iam
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: charter-iam
subjects:
- kind: ServiceAccount
name: charter-iam
namespace: charter-system
The controller cannot create or delete IAMClients, and it has no access to
Roles, RoleBindings or anything outside the resources listed.
Owner Role (per client)¶
Rendered by the ResourceSet in the client's namespace:
rules:
- apiGroups: ["iam.rbc.example"]
resources: ["iamclients"]
resourceNames: ["<name>"]
verbs: ["get", "patch", "update"]
- apiGroups: ["iam.rbc.example"]
resources: ["iamclients/status"]
resourceNames: ["<name>"]
verbs: ["get"]
RBAC alone would let the owner change any field; the admission policy narrows
it to redirectURIs.
Admission policy¶
deploy/admission-policy.yaml installs two policies, parameterised by the
iamclient-policy ConfigMap in charter-system:
| ConfigMap key | Meaning |
|---|---|
provisioners |
Comma-separated usernames allowed to provision |
adminGroups |
Comma-separated admin groups |
allowedRedirectDomains |
Comma-separated allowed domains (with leading dot) |
iamclient-admin-gates (ValidatingAdmissionPolicy)¶
Applies to every create, update and delete of an IAMClient, except by the
controller's own service account:
- Only admins and provisioners may create or delete.
- On update, a non-admin may only change
spec.redirectURIs. The compared fields aredisplayName,owners,groups,secretRotation,deletionPolicy,dexandpushSecret. - On update, a non-admin may not change the approval annotations.
- Every redirect URI must be a URL, HTTPS, without
*, on an allowed domain.
The binding uses validationActions: [Deny, Audit] and denies if the
ConfigMap is missing (parameterNotFoundAction: Deny).
Keep the field list in step
The list in rule 2 must match OWNER_EDITABLE in src/policy.rs: every
field not listed there is admin-only. If a new field is missed here, the
controller's admin-hash check still blocks the change without a new
change reference, but the write is accepted at admission.
iamclient-stamp-author (MutatingAdmissionPolicy)¶
On every create and update (except by the controller), sets
iam.rbc.example/last-modified-by to the authenticated username, overwriting
any value supplied. The controller copies it into every audit record.
MutatingAdmissionPolicy is GA (admissionregistration.k8s.io/v1) from
Kubernetes 1.36, which serves no other version. On older clusters replace it
with an equivalent Kyverno mutate rule.
Both policies are exercised against a real API server on every PR by the kind tests.
# Copyright (c) 2026 Erick Bourgeois, charter
# SPDX-License-Identifier: Apache-2.0
# Who may do what to an IAMClient, enforced by the API server:
# - create and delete: platform admins, or the Flux provisioner identity
# - change admin-only fields or approval annotations: same
# - change redirectURIs: the owning team (granted per client by RBAC, see flux/)
# The controller re-checks creation and admin changes as defence in depth.
apiVersion: v1
kind: ConfigMap
metadata:
name: iamclient-policy
namespace: charter-system
data:
# Comma-separated Kubernetes usernames allowed to provision (Flux ResourceSet SA).
provisioners: "system:serviceaccount:charter-system:charter-provisioner"
# Comma-separated groups of platform admins (Entra group object IDs on AKS).
adminGroups: "00000000-0000-0000-0000-00000000ad01"
# Leading dot: host must equal the domain or be a subdomain of it.
allowedRedirectDomains: ".apps.example.rbc.com"
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: iamclient-admin-gates
spec:
failurePolicy: Fail
paramKind: { apiVersion: v1, kind: ConfigMap }
matchConstraints:
resourceRules:
- apiGroups: ["iam.rbc.example"]
apiVersions: ["*"]
operations: ["CREATE", "UPDATE", "DELETE"]
resources: ["iamclients"]
matchConditions:
# The controller only manages its finalizer; status is a separate subresource.
- name: not-controller
expression: "request.userInfo.username != 'system:serviceaccount:charter-system:charter-iam'"
variables:
- name: isAdmin
expression: >-
request.userInfo.username in params.data.provisioners.split(',') ||
request.userInfo.groups.exists(g, g in params.data.adminGroups.split(','))
- name: approvalKeys
expression: "['iam.rbc.example/requested-by', 'iam.rbc.example/approved-by', 'iam.rbc.example/change-ref']"
validations:
- expression: "request.operation == 'UPDATE' || variables.isAdmin"
messageExpression: "'only platform admins can ' + request.operation.lowerAscii() + ' an IAMClient'"
reason: Forbidden
# Every spec field except redirectURIs is admin-only. Keep this list in step
# with OWNER_EDITABLE in src/policy.rs; the controller's admin hash catches misses.
- expression: >-
request.operation != 'UPDATE' || variables.isAdmin || (
object.spec.displayName == oldObject.spec.displayName &&
object.spec.?owners == oldObject.spec.?owners &&
object.spec.?groups == oldObject.spec.?groups &&
object.spec.?secretRotation == oldObject.spec.?secretRotation &&
object.spec.?deletionPolicy == oldObject.spec.?deletionPolicy &&
object.spec.?dex == oldObject.spec.?dex &&
object.spec.?pushSecret == oldObject.spec.?pushSecret)
message: "owners may only change spec.redirectURIs; other fields need a platform admin"
reason: Forbidden
- expression: >-
request.operation != 'UPDATE' || variables.isAdmin ||
variables.approvalKeys.all(k, object.metadata.?annotations[?k] == oldObject.metadata.?annotations[?k])
message: "approval annotations can only be set by platform admins"
reason: Forbidden
- expression: >-
request.operation == 'DELETE' || !has(object.spec.redirectURIs) ||
object.spec.redirectURIs.all(u, isURL(u) && !u.contains('*') &&
url(u).getScheme() == 'https' &&
params.data.allowedRedirectDomains.split(',').exists(d, ('.' + url(u).getHostname()).endsWith(d)))
message: "redirect URIs must be https, without wildcards, on an allowed domain"
reason: Invalid
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
name: iamclient-admin-gates
spec:
policyName: iamclient-admin-gates
validationActions: ["Deny", "Audit"]
paramRef:
name: iamclient-policy
namespace: charter-system
parameterNotFoundAction: Deny
---
# Stamp the real author of every create/update so the controller's audit
# records say who changed what. Any value a user writes is overwritten.
# MutatingAdmissionPolicy is GA (admissionregistration.k8s.io/v1) from
# Kubernetes 1.36, which serves no other version; earlier releases served it
# as v1beta1 behind a feature gate. On older clusters use the equivalent
# Kyverno mutate rule.
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingAdmissionPolicy
metadata:
name: iamclient-stamp-author
spec:
failurePolicy: Fail
reinvocationPolicy: Never
matchConstraints:
resourceRules:
- apiGroups: ["iam.rbc.example"]
apiVersions: ["*"]
operations: ["CREATE", "UPDATE"]
resources: ["iamclients"]
matchConditions:
- name: not-controller
expression: "request.userInfo.username != 'system:serviceaccount:charter-system:charter-iam'"
mutations:
- patchType: ApplyConfiguration
applyConfiguration:
expression: >-
Object{
metadata: Object.metadata{
annotations: {"iam.rbc.example/last-modified-by": request.userInfo.username}
}
}
---
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingAdmissionPolicyBinding
metadata:
name: iamclient-stamp-author
spec:
policyName: iamclient-stamp-author