audit2rbac takes a Kubernetes audit log and username as input, and generates RBAC role and binding objects that cover all the API requests made by that user.
Obtain a Kubernetes audit log containing all the API requests you expect your user to perform:
The log must be in JSON format. This requires running an API server with --feature-gates=AdvancedAudit=true and an --audit-policy-file defined. See documentation for more details.
v1alpha1 or v1beta1 audit events are supported.
The Metadata log level works best to minimize log size.
To exercise all API calls, it is sometimes necessary to grant broad access to a user or application to avoid short-circuiting code paths on failed API requests. This should be done cautiously, ideally in a development environment.
A sample log containing requests from alice, bob, and the service account ns1:sa1 is available.
Identify a specific user you want to scan for audit events for and generate roles and role bindings for:
Specify a normal user with --user <username>
Specify a service account with --serviceaccount <namespace>:<name>