Skip to content

No way to get a short-lived, least-privilege token as the logged-in user (account_api_tokens:create is listed but never granted) #607

Closed as not planned

Description

@KitanosonoIku

Context

We use cf for day-to-day Workers development, and our developers increasingly run it through AI coding agents.
cf auth login grants a very broad set of permissions by default (475 scopes in our case, including membership, SSO and DNS writes), and the grant stays on disk until logout.
For agent-driven work we want the opposite: credentials limited to the account and permissions the task needs, and expiring within hours.

The natural way to do this would be to log in, mint a short-lived, scoped account API token as yourself, and log out right away.
That keeps no broad credential on disk, needs no extra service, and the audit log shows the person who created the token.
As far as we can tell, this is not possible today.

What we tried

Versions: cf 1.0.0-beta.13 and 1.0.0-beta.31, macOS, OAuth device flow.
The user is a Super Administrator of the account.

  1. cf auth login --force --scopes account:read user:read account_api_tokens:create
    • Login succeeds, but the granted scopes are user:read, offline_access, account:read.
    • account_api_tokens:create is dropped without any message, even though it appears in the scope list built into cf (checked in 1.0.0-beta.13).
  2. cf accounts tokens create --name … --expires-on <now+1h> --policies '[{"effect":"allow","resources":{"com.cloudflare.api.account.<id>":"*"},"permission_groups":[{"id":"<Workers Scripts Write>"}]}]'
    • 403 [9109] Unauthorized to access requested resource on POST /accounts/<id>/tokens.
    • cf accounts tokens permission-groups list also fails.
  3. The same with the default login (cf auth login --force): token creation still returns 403.
    • 1.0.0-beta.13 reported "475 selected"; 1.0.0-beta.31 reported "476 granted". In beta.31 the only token-related scopes in the grant were access-service-token.read and access-service-token.write.

So neither a narrowed nor the default login can create an account API token, and there is no other way to get a short-lived, scoped credential from an interactive login.

Expected

Some supported way for a logged-in user to obtain a credential that is:

  • limited to chosen permission groups and accounts,
  • short-lived (hours), and
  • attributed to that user in the audit log.

Possible directions

Any of these would solve it for us:

  1. Make account_api_tokens:create grantable when explicitly requested with --scopes, without adding it to the default grant (similar to the on-demand sensitive scope discussed in Support on-demand OAuth authorization for PlanetScale signature creation #248).
  2. A command such as cf auth token create --permissions <groups> --account <id> --ttl 12h that mints a scoped, expiring token for the current user and prints or stores it.
  3. Time-limited or preset logins, e.g. cf auth login --preset workers-dev --ttl 12h, so the OAuth grant itself is narrow and expires.

Also related: when a requested scope is not granted, cf auth login should say which ones were dropped (see #552), and the granted list should be easy to inspect (#34).

Happy to provide more details or test a build.

Activity

  1. workers-devprod commented on Nov 16, 2026

    @workers-devprod
    Collaborator

    Thanks for the detailed report. cf auth login only gets the scopes the OAuth grant allows, so account_api_tokens:create isn't granted and token creation returns 403. Minting scoped, expiring credentials would be a change to the product, which we track in Discussions, so please follow and upvote it at #632.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions