Write audit events when Artifact Registry roles change
What does this MR do and why?
Every Artifact Registry role grant and revoke now writes an audit event. Enterprise buyers check for an audit trail of access changes, and this is P0 for Artifact Central GA.
- Two new types:
artifact_registry_role_grantedandartifact_registry_role_revoked. Both are saved to the database and streamed. - One event per assignment. A bulk grant of 5 assignments writes 5 events. A revocation listed twice writes 1.
- Written after IAM succeeds. No event for a rejected or failed write.
- Never blocks the role change. The IAM write has already happened, so an audit failure goes to error tracking, and the mutation still succeeds.
- Covers every path. The single and bulk mutations and the Organization Access edit role all go through
GrantRoleAssignmentsServiceandRevokeRoleAssignmentsService.
Scope decision: the organization's top-level group. There's no Organization audit scope yet, and Instance events are visible only to GitLab admins on GitLab.com. At GA every GitLab.com organization has exactly one top-level group, the same group that bills for Artifact Registry. So events go to that group, and its owners see them on the group audit page and in its streaming destinations. With zero or several top-level groups, as in the Self-Managed default organization, events fall back to Instance scope.
Not in this MR:
- The previous role. Neither service knows it without a slow IAM lookup on every write.
- Access-time auditing of admin and auditor reads. It follows #605591.
- A feature flag or changelog entry. The four role mutations (Grant, BulkGrant, Revoke, BulkRevoke) are mounted as experiments, and experiment changes don't get a changelog entry.
References
Closes #634604 (closed)
How to set up and validate locally
- Enable Artifact Registry for an organization that has one top-level group.
- Grant a role with the
artifactRegistryRoleGrantmutation, then revoke it withartifactRegistryRoleRevoke. - Open the top-level group's Secure > Audit events. You should see one granted and one revoked event, with the assignee as the target.
The service specs cover the group scope, the Instance fallback for zero and several groups, one event per assignment, deduplicated revocations, an audit failure that doesn't block the change, and no event when IAM rejects the write.
Implementation notes
- Batching: events go through
Gitlab::Audit::Auditor.auditwith a block, so a bulk change does one bulk insert. The block queue lives in the request store. Only the four GraphQL role mutations call these services, and they always run inside one, so there's noensure_request_storewrapper. The specs tag:request_store. - Event name: a queued event's
additional_detailsreplaces the context's, which carryevent_name. The helper merges it back into each event. - Shared lookup:
ArtifactRegistry::TopLevelGroups.first_tworeplaces the inline query inProvisionNamespaceService#resolve_billing_group. Billing and audit agree on the group while the organization keeps the single top-level group it had at provisioning. See the open question on storing the billing group. - RuboCop todo: !267558 (merged) moved these services out of
Authzbut left the old paths in.rubocop_todo/gitlab/comment_length.yml. This MR points the five entries it touches at the new paths. Other staleauthz/artifact_registryentries remain. - Docs:
doc/user/compliance/audit_event_types.mdis regenerated.
Reviewers
@gitlab-org/govern/compliance/backend reviews new audit event types. The open question for them is on the issue: does group scope look right for an organization-level resource, until an Organization scope exists?
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.