Project API Token permission scoping and credential lifecycle
0 reputation · 07 Mar 2022, 00:52 UTC
0 reputation · 07 Mar 2022, 00:52 UTC
CircleCI Project API tokens are used to automate build triggers and manage project-level settings. While these tokens provide isolation between different projects, they currently lack granular permission scopes, granting broad access to all project-level API endpoints once authenticated.
When managing credentials at scale, the lack of a native expiration mechanism or a built-in rotation trigger within the CircleCI UI creates a dependency on external orchestration to prevent the use of stale or compromised secrets. This is particularly relevant for teams attempting to implement a strict least-privilege security model across multiple environments.
29275 reputation · 07 Mar 2022, 05:16 UTC
1. Can Project API tokens be restricted to read‑only or write‑only actions? No. The token payload does not contain a scope field; once issued it can call any project‑level API endpoint that the bearer has permission to use. Permission granularity is not exposed at the token level in CircleCI’s public API or UI.
2. Is there a documented method to enforce a mandatory expiration date on these tokens without manual deletion? No. CircleCI does not provide a TTL or auto‑rotation feature for Project API tokens. Expiration must be handled by revoking the token (via the UI or the API) and creating a new one, typically orchestrated by an external secret‑management workflow.
/api/v2/token) show only id, name, created_at, and expires_at (if set manually), but no scope flags.Because there is no built‑in expiration, teams usually adopt one of the following patterns:
curl:
curl -X GET "https://circleci.com/api/v2/project/${VCS}/${ORG}/${REPO}/token" \
-H "Circle-Token: ${CIRCLECI_PERSONAL_TOKEN}" \
| jq '.items[] | select(.created_at < "$(date -u -d "-30 days" +%Y-%m-%dT%H:%M:%SZ)") | .id' \
| xargs -I{} curl -X DELETE "https://circleci.com/api/v2/token/{}" \
-H "Circle-Token: ${CIRCLECI_PERSONAL_TOKEN}"
Because token scoping and expiration are not available natively, the most effective approach is to treat the token as a short‑lived secret managed outside of CircleCI. If you need finer access control, consider using CircleCI’s Personal Access Tokens with scope flags, but note that those are not project‑isolated and may expose broader access.
Could you confirm which CircleCI plan you are using (Free, Pro, Enterprise)? The token capabilities and available API endpoints can vary slightly between tiers, and that may affect the exact rotation strategy you can implement.
Use comments to ask for clarification. Post a solution as an answer.
29,275 reputation · 07 Mar 2022, 04:18 UTC
When you create a Project API token via the v2 API you may include an expires_at timestamp. CircleCI records this value in the token object, but it does not validate the date; the token remains usable until you explicitly delete or revoke it. Therefore the field can only serve as a reminder for external rotation processes.
The token payload contains no scopes or permission flags. Once issued, a project token can call any project‑level API endpoint that the bearer is authorized to use. Achieving least privilege therefore requires separating tokens by environment or workflow and managing them outside CircleCI.