Skip to content

feat: add auto-revoke mechanism for stale API tokens#2734

Open
migmartri wants to merge 15 commits intochainloop-dev:mainfrom
migmartri:migmartri/stale-token-revoke
Open

feat: add auto-revoke mechanism for stale API tokens#2734
migmartri wants to merge 15 commits intochainloop-dev:mainfrom
migmartri:migmartri/stale-token-revoke

Conversation

@migmartri
Copy link
Member

@migmartri migmartri commented Feb 11, 2026

Summary

Adds an organization-level configurable inactivity threshold (default 30 days) for automatic API token revocation. A background job periodically sweeps for inactive tokens and revokes them based on each organization's configured threshold.

Adds an organization-level configurable inactivity threshold (default 30 days) and a background job that periodically sweeps for inactive tokens and revokes them. Includes proto API changes, CLI flag for token threshold configuration, and a new APITokenStaleRevoker background service that runs hourly.

Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
Changes the default API token inactivity threshold from 30 to 90 days
and removes the backfill UPDATE so existing organizations are not
affected. Also resolves merge conflicts with main branch.

Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
…er input

Renames the flag from --api-token-inactivity-threshold (duration string)
to --api-token-max-days-inactive (integer days) for clarity. Users now
pass a simple number of days instead of Go duration syntax.

Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
Replaces `google.protobuf.Duration api_token_inactivity_threshold`
with `int32 api_token_max_days_inactive` in proto definitions. This
eliminates unnecessary duration-to-days conversion in the service and
CLI layers since the feature inherently operates on whole days.

Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
…ax days

Addresses CodeQL finding about potential integer overflow when converting
the api-token-max-days-inactive value from int (architecture-dependent)
to int32.

Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
The api_token_inactivity_threshold_days column is now NULL by default,
meaning the feature is opt-in rather than enabled for all organizations.

Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
Rename repo RevokeInactive to FindInactive (query-only) and have the
stale revoker call APITokenUseCase.Revoke per token so audit events
are properly dispatched.

Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants