Skip to content

Code layout

A single binary crate, charter-iam.

src/
  main.rs        startup; `charter-iam crd` prints the CRD
  crd.rs         IAMClient spec and status types (source of the CRD)
  controller.rs  reconcile, cleanup, drift diff, rotation decision, PushSecret handling
  policy.rs      Policy (from env), redirect and lifetime checks, approval gate, hashes
  graph.rs       Microsoft Graph client: token, applications, SPs, owners, passwords
  push.rs        PushSecret rendering and sync-state parsing
  audit.rs       Auditor: hash-chained JSON records and Kubernetes Events
deploy/
  crd.yaml                 generated by `make crd`
  rbac.yaml                controller ServiceAccount and ClusterRole
  deployment.yaml          controller Deployment
  admission-policy.yaml    ValidatingAdmissionPolicy + MutatingAdmissionPolicy
  flux/resourceset.yaml    admin provisioning path
  example-iamclient.yaml
docs/                      this site (MkDocs Material)

main.rs

Builds the Kubernetes client, Graph::from_env, Policy::from_env and the Auditor, then runs the controller. With the argument crd it prints the CRD YAML and exits.

controller.rs

run sets up a kube-runtime Controller over all IAMClients, also watching Secrets labelled app.kubernetes.io/managed-by=charter-iam (so deleting or editing a delivered Secret triggers a reconcile). reconcile wraps apply and cleanup in the finalizer helper. error_policy sets the retry delay.

Functions worth knowing:

Function Purpose
apply The nine reconcile steps
cleanup Deletion: PushSecret, then Entra per deletionPolicy
check_policy All policy rules, all violations collected
diff Which managed Entra properties differ
rotation_reason Whether to issue a new password, and why (unit-tested)
reconcile_push, delete_push_secret The PushSecret lifecycle
dex_config Renders the Dex fragment
parse_duration 90d, 720h, 30m

policy.rs

Policy holds every controller-wide rule. spec_hash and admin_hash hash canonical JSON (sorted keys) of the spec, the latter without OWNER_EDITABLE fields. classify and gate implement the change kinds.

graph.rs

A deliberately small client over reqwest with rustls and https_only. token caches the app-only token and supports federated and secret credentials. Each Graph operation is one method returning a typed result; 404 on deletes is success. Errors carry the HTTP status and body.

push.rs

spec renders PushSecret.spec (one data entry per Secret key, all to one remote key, deletionPolicy: Delete). synced_since reads the PushSecret's Ready condition and refreshTime into SyncState (Synced, Pending, Failed). It uses DynamicObject, so there is no compile-time dependency on External Secrets types.

audit.rs

Auditor::record serialises a Record, chains it to the previous one with SHA-256 under a mutex, logs it on the audit target and publishes a Kubernetes Event. Auditor::audited brackets a future with attempted and succeeded/failed.