During incidents, Acme Corp sometimes grants the admin role to engineers for troubleshooting. But once the incident
is resolved, that elevated access is rarely revoked. This violates the principle of least privilege and creates long-term
risk.
Here’s a workflow that enforces a maximum duration for admin access:
name: Temporary admin auto-removal
on: user-role-granted(admin)
if: not has-user-attribute(permanent-admin=true)
steps:
- uses: notify-user
after: 7d
with:
subject: Admin access expiring soon
message: |
<p>Hi ${user.firstName},</p>
<p>Your temporary admin access to ${realm.displayName} will be
revoked in 24 hours. If you still need admin access, contact
your team lead to request an extension.</p>
- uses: revoke-role
after: 1d
with:
role: admin
- uses: notify-user
with:
subject: Admin access revoked
message: |
<p>Hi ${user.firstName},</p>
<p>Your temporary admin access to ${realm.displayName} has been
revoked as scheduled. Thank you for helping out!</p>
When the admin role is granted to a user, this workflow starts a 7-day countdown. After 7 days, it sends a warning.
After one more day, it revokes the role and sends a confirmation email.
The condition not has-user-attribute(permanent-admin=true) ensures that users who are meant to have permanent admin
access (like the identity team itself) are excluded from the auto-removal workflow.
Notice how the on setting uses a parameterized event: user-role-granted(admin) triggers only when the specific
admin role is granted, not for any role grant. This is important - you don’t want this workflow firing when someone
gets a viewer role.