How do you handle per-user tokens for CLI access?

November 16, 2026 5 answers
Asked by _k36!plumfolder.5

Our internal API gives users static tokens for CLI and scripted access. The tokens keep the permissions they had when created, even if the user's role changes, and people have to copy and store them themselves.

What are good alternatives? I'm especially interested in SSO for a CLI, the cost of checking current permissions, and how to handle longer-running scripts.

Answers

4v!cobaltspanner_629

Separate authentication from authorization. Let the credential identify the user, then check what that user can do against your current role data when a request comes in. That way a token doesn't retain an old account entitlement just because it was minted before a role change.

A cache can reduce directory traffic, but its lifetime becomes part of your revocation delay. There isn't a useful universal number for latency or cache duration without knowing your traffic and role store. Measure both, and decide explicitly what happens when the role lookup fails. Failing closed protects against stale access but can make a directory outage an API outage.

wobble~switch:

Also check how role changes reach the store you're querying. A fresh lookup still won't see a removal that hasn't propagated there yet.

Reply to this answer
n0odle+9

For interactive CLI use, see whether your identity provider supports the OAuth device authorization flow. The CLI can prompt the user to complete sign-in in a browser, then obtain a short-lived access token without asking them to paste a long-lived API secret into a config file.

A browser-based authorization flow with a temporary local callback is another option. Either way, check what your provider actually supports and how renewal and revocation work. A short token lifetime alone doesn't guarantee immediate revocation.

_k36!plumfolder.5:

Does that still work for scripts that need to run longer than the access token lasts?

p.712!drainwhistle:

It can if the provider permits renewal, but that introduces another credential to protect and a policy for when the user must sign in again. For unattended jobs, a dedicated non-human identity may fit better.

Reply to this answer
Veslor.9c

If a full SSO integration isn't practical yet, static tokens can still be made less risky. Give them an expiry, let users revoke them, audit their use, and check current permissions rather than treating the permissions at creation as permanent.

That doesn't solve distribution by itself. A setup credential that is exchanged once for an API credential can reduce repeated copying, but the resulting credential still needs safe storage and a renewal plan.

Reply to this answer
plain_sprocket

Don't assume a secret manager makes rotation invisible. Clients that read a secret once and keep it in memory can continue using the old value after rotation. Decide how clients reload credentials, allow a transition period if your system supports it, and test the failure path before relying on automatic rotation.

Reply to this answer
_v36+parcelgauge.8

Per-user certificates are another authentication option, but they still need issuance, renewal, revocation, and a way to map the certificate to a user. They don't fix frozen permissions on their own. You'd still want an authorization check against current roles.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions