Safeguard
Developer Tools•

How should you manage service accounts and API tokens for AppSec in CI?

A practical setup for scanner tokens in CI: dedicated service accounts, narrow scopes, secret storage, rotation and logging, with a pilot test list.

Safeguard Security Team
4 min read

Give each pipeline its own scoped service identity, store its token in your CI secret store, set the narrowest permissions the scan needs, rotate on a schedule, and log its use. Never use a person's personal token for automation, because it leaves when they do.

What goes wrong

Scanner tokens are often created in a hurry by one developer, pasted into a variable and forgotten. The token has the creator's full access, never expires, and is shared across dozens of pipelines. When that person leaves or the token leaks, nobody knows where it is used.

Principles

GitHub's guidance on workflow tokens recommends granting the least required access, set per workflow or per job, and warns that an action can read the token even when it is not passed explicitly. GitHub's app guidance advises selecting minimum permissions and never using personal access tokens for app authentication. OWASP's logging guidance lists adding and assigning tokens among events to record. Together these give a clear pattern.

Setup steps

  1. Create a dedicated service account in the AppSec tool, named for the purpose, with an owner recorded.
  2. Assign the narrowest role. A scan upload token needs to submit results, not edit policy or read every project. See RBAC roles to ask for.
  3. Scope it to projects or repos, not the whole tenant, where the tool allows.
  4. Store it as a CI secret, at the narrowest level: repository or environment, not organisation wide unless needed.
  5. Limit exposure in pipelines. Do not echo it, do not pass it to untrusted pull requests from forks, and pin third party actions to a commit.
  6. Set an expiry or rotation date, and record it in your register.
  7. Alert on use from unexpected places or at unusual volume.

Comparison of credential types

TypeStrengthRisk
Personal tokenQuickTied to a person, broad, often never expires
Shared team tokenSimpleNo attribution, hard to rotate
Per pipeline service tokenClear owner, scopedMore to manage
Short lived federated credentialNo stored secretNeeds tool and CI support

Ask your vendor whether it supports short lived or federated credentials for CI. If it does, prefer that over a stored secret.

Test it in the pilot

  1. Create a token with the narrowest role. Confirm a scan still uploads.
  2. Try to use it to change a policy. It should fail.
  3. Revoke it and check that the next pipeline run fails clearly instead of passing silently. See fail open or fail closed.
  4. Find its creation, use and revocation in the audit log.

Try it yourself

The pull request gate demo shows a scan result feeding a merge decision. Think about which identity delivers that result in your pipeline and what it is allowed to do.

Click through it at your own pace, or open it full screen.

Safeguard offers a CLI for CI use and policy gates, and a free scan is at gold.safeguard.sh/scan.

Quick check

Can one token serve all pipelines?

It can, but it makes attribution and rotation hard. Per pipeline or per team tokens are easier to trace and revoke.

Should tokens be available to pull requests from forks?

Generally no. Untrusted code could read them. Use separate, restricted workflows for forks.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.