Skip to content

feat(auth)!: LiveKit CLI 3.0: sign in by default, API keys behind --legacy-auth - #1158

Draft
rektdeckard wants to merge 3 commits into
mainfrom
tobiasfried/cli-3-user-auth-default
Draft

rektdeckard wants to merge 3 commits into
mainfrom
tobiasfried/cli-3-user-auth-default

Conversation

@rektdeckard

@rektdeckard rektdeckard commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

LiveKit CLI 3.0. Commands run as the signed-in LiveKit Cloud user by default. API keys stay available behind --legacy-auth and LIVEKIT_LEGACY_AUTH, which #1156 added in 2.20.2. Follows #1156 (merged).

Two commits: the behavior change, then the mechanical module rename to /v3 with the version bump. Review them separately.

How a command picks its auth mode

One resolver (cmd/lk/auth_mode.go) decides. The first match wins:

  1. --legacy-auth: API key
  2. --user-auth: signed-in user. It is now hidden, since it is the default, and still overrides the rules below
  3. LIVEKIT_LEGACY_AUTH: API key
  4. --dev: API key
  5. --api-key or --api-secret on the command line: API key
  6. A self-hosted target: API key. That is a non-Cloud --url or LIVEKIT_URL with a key and secret, or --project naming a saved self-hosted project
  7. Saved auth_mode: legacy in the CLI config: API key
  8. A user is signed in: that user. An expired session counts only when lk can ask them to sign in again
  9. Nobody is signed in and an API key is at hand: API key
  10. Otherwise the signed-in user, who is then asked to sign in

LIVEKIT_API_KEY and LIVEKIT_API_SECRET in the environment alone don't take a signed-in user off their session.

What a 2.x setup sees

  • CI with a LiveKit Cloud key and nobody signed in: keeps working, and prints one warning per command. LIVEKIT_LEGACY_AUTH=1 or --legacy-auth removes it.
  • A terminal with saved Cloud keys and nobody signed in: asked once to sign in, keep using API keys (saved as auth_mode: legacy), or decide later.
  • Self-hosted keys: no notice and no prompt.
  • Signed in under 2.x with --user-auth: nothing to do. The flag still works.

Behavior changes

  • lk cloud auth signs in, and needs no terminal: the device is named after the host and the link is printed. With --legacy-auth it claims an API key as before.
  • lk cloud auth --project sets the default project after sign-in. With several projects and nobody to ask, no default is set and lk says how to set one.
  • lk cloud auth --revoke signs out. With nobody signed in, it says to pass --legacy-auth to revoke a key.
  • A command that needs a signed-in user offers to sign in when it can ask. Otherwise the error says how to sign in or use an API key.
  • Commands and flags for signed-in users are listed in help. Unlisted groups (workspace, evals) stay hidden.
  • lk token create --valid-for over 24h fails for a signed-in user. The API would shorten it without saying.
  • lk agent dev runs the agent with a worker token (LIVEKIT_TOKEN, support for token mode agents#8557, token mode: supports running without an api key/secret agents-js#2999) when no key can be found or created. It is the last step of the key chain, and only for an SDK with token mode: livekit-agents 1.19.0 or later for Python, @livekit/agents 1.11.0 or later for Node.js. A hidden --token-mode asks for it first.
  • The key prompt in lk agent init and lk app create can be skipped.
  • lk update and lk can-update warn before a major update and link its migration guide.
  • A follow-up command that lk prints (simulate hints) repeats --user-auth or --legacy-auth when that flag chose the mode.
  • The config permissions warning prints once per run.
  • Module path is github.com/livekit/livekit-cli/v3. Version is 3.0.0.

Open points

  • release.yaml blocks a 3.0.0 release. It requires the CLI's major.minor to match server-sdk-go's, which stays on v2. Left unchanged here on purpose.
  • The 3.0 announcement goes live on merge. banner.json on main reaches installed 2.x CLIs, and this PR adds a notice there for < 3.0.0 that links the migration guide. Merge it when 3.0.0 is released and the guide is published.
  • The migration guide the update notice links (/reference/developer-tools/livekit-cli/migrate-to-v3/) is on a livekit/web branch that isn't pushed yet.

Testing

  • go test ./... passes.
  • TestDecideAuthMode covers every resolver rule, with flags on both sides of the subcommand.
  • TestCredentialResolution (property test) has a second telling of the mode rules and passes 5000 random cases.
  • New scripts: cloud-auth-signs-in, auth-fallback-to-api-key, token-create-valid-for-cap, agent-dev-token-mode. Existing scripts are updated for the new default and messages.
  • The tests no longer read the CLI config or session of the machine they run on. With the new default they would otherwise act as whoever is signed in there.
  • Not covered by tests: the interactive prompts (migration choice, sign-in offer, skip a key), which need a terminal.

🤖 Generated with Claude Code

Commands now run as the signed-in LiveKit Cloud user unless something asks
for an API key. One resolver decides, first match wins: --legacy-auth,
--user-auth (now hidden: it is the default), LIVEKIT_LEGACY_AUTH, --dev,
--api-key or --api-secret on the command line, a self-hosted target, a
saved auth_mode: legacy, a signed-in user, and then an API key that is at
hand when nobody is signed in. LIVEKIT_API_KEY and LIVEKIT_API_SECRET in the
environment alone don't take a signed-in user off their session.

A machine set up for 2.x keeps working. With a LiveKit Cloud key and nobody
signed in, a terminal is asked once whether to sign in or keep using API
keys, and a run that can't ask goes on with the key and prints a warning.
A key for a self-hosted server prints nothing.

Also in this change:

- lk cloud auth signs in, with no terminal needed: the device is named
  after the host and the link is printed. --project sets the default
  project. With --legacy-auth it claims an API key as before. --revoke
  with nobody signed in says how to revoke a key instead.
- A command that needs a signed-in user offers to sign in when it can ask.
- Commands and flags for signed-in users are listed in help. Unlisted ones
  stay hidden.
- lk token create refuses a --valid-for over 24h for a signed-in user,
  which the API would shorten without saying.
- lk agent dev runs an agent whose SDK has token mode (livekit-agents
  1.19.0 or later for Python, @livekit/agents 1.11.0 or later for Node.js)
  with a worker token when no key can be found or created, as the last
  step of the key chain. A hidden --token-mode asks for it first.
- A key prompt while setting up a new app or agent can be skipped.
- lk update and lk can-update warn before a major update, with a link to
  its migration guide.
- A follow-up command that lk prints repeats an auth mode flag that chose
  the mode.
- The config permissions warning prints once per run.
- Tests no longer read the CLI config or session of the machine they run
  on, which the default mode now depends on.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…on 3.0.0

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
banner.json on main is what installed CLIs read, so this reaches 2.x users
before they update, which the notice in lk update can't until it ships in
the binary they run.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@rektdeckard
rektdeckard force-pushed the tobiasfried/cli-3-user-auth-default branch from d1cc4a2 to 9e3c377 Compare December 3, 2026 00:51
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.

1 participant