Skip to content

chore(auth): prepare for migration to user-auth as default - #1156

Open
rektdeckard wants to merge 7 commits into
mainfrom
tobiasfried/legacy-auth-flag
Open

rektdeckard wants to merge 7 commits into
mainfrom
tobiasfried/legacy-auth-flag

Conversation

@rektdeckard

@rektdeckard rektdeckard commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Prepare auth mode and project resolution steps for 3.0:

  • Unifies auth mode detection in a single code path (resolveAuthMode). Reads --legacy-auth, then --user-auth, then the LIVEKIT_LEGACY_AUTH env var, then falls back to the default (API keys until 3.0). An explicit --user-auth wins over the env var instead of being a usage error. Sign-in state isn't a rule yet: 3.0 adds the session- and config-based rules here. The default is injectable (decideAuthMode), so the tests already cover 3.0's rows.
  • Makes --legacy-auth global flag visible
  • Unifies project resolution further (resolveProjectRef), and adds the same detection order to user-auth as existed in legacy-auth. Reads --project flag or positional arg, then --subdomain, then --url or LIVEKIT_URL, then livekit.toml, then the default project, and finally shows the project picker if no other match.
    • A livekit.toml, --subdomain or LiveKit Cloud URL naming a project the user can't access is an error, not a fallback to the default. So is an explicit --url naming no project (except in agent runs, where --url is where the agent connects). A LIVEKIT_URL naming no project (e.g. a local server) is skipped, with a notice.
    • A Cloud URL matches by subdomain only within the same Cloud (production or staging).
    • The global --url is read from the root command, so a subcommand's own --url (e.g. a webhook's delivery URL) doesn't hide it.
    • Exception: lk project delete only acts on a project named on the command line (positional, --project or --subdomain); otherwise it shows the picker, never inferring one from LIVEKIT_URL, livekit.toml or the default project.
  • Agent commands apply their directory argument before resolving the project (except agent init, whose argument is the directory it creates); agent update no longer rewrites the current directory's livekit.toml.
  • LoadTOMLFile returns ErrInvalidConfig for a livekit.toml it can't decode, instead of a half-decoded config or an unwrapped error.
  • Adds unit tests for both resolvers, and testscripts for the resolution order and error cases.

Behavior change for API-key users: a livekit.toml with a TOML syntax error used to be skipped silently, so commands ran on the default project. It's now an invalid configuration file error. (A type error, e.g. subdomain = 42, or an empty file already errored, with invalid URL.)

devin-ai-integration[bot]

This comment was marked as resolved.

rektdeckard added a commit that referenced this pull request Dec 2, 2026
…auth

Addresses review on #1156:

- Agent commands apply their working-dir argument before resolving the
  project, so the livekit.toml read (and cached) is the requested agent's,
  not the current directory's. This also affected API-key mode.
- A CLI config entry without a project id maps to a user's project only by
  its URL, or by subdomain when that URL is a LiveKit Cloud one, so a
  self-hosted entry never maps to a Cloud project sharing its first label.
- Under --user-auth, a livekit.toml that can't be read or names no project
  is an error instead of falling through to the default project.
- LoadTOMLFile returns ErrInvalidConfig for a decode error instead of
  panicking on a syntax error or returning a half-decoded config.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
devin-ai-integration[bot]

This comment was marked as resolved.

rektdeckard added a commit that referenced this pull request Dec 2, 2026
Addresses review on #1156:

- `lk agent update DIR` no longer saves the agent's unchanged config to the
  current directory, which overwrote another agent's livekit.toml there.
- `lk agent init NAME` takes its project from the current directory again,
  as before #1156's working-dir change (NAME is a directory it creates), and
  then drops the current directory's agent config rather than carrying it
  into the new agent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rektdeckard added a commit that referenced this pull request Dec 2, 2026
Addresses review on #1156:

- `lk user list` without --workspace resolves its project with
  resolveProjectRef (--subdomain, LIVEKIT_URL, livekit.toml, default,
  picker) instead of jumping straight to the default project.
- `lk project delete` also takes the project by --subdomain, which is as
  explicit as --project. It still never infers one from LIVEKIT_URL, a
  livekit.toml or the default project.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rektdeckard
rektdeckard requested a review from u9g December 2, 2026 04:12

@Topherhindman Topherhindman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

took a pass at 5bbc661. the resolver reads cleanly and the scripts cover the matrix well. one real one inline (webhook update's --url hides LIVEKIT_URL), the rest are nits.

Comment thread cmd/lk/user_auth.go Resolved
Comment thread cmd/lk/user_auth.go Resolved
Comment thread cmd/lk/user_auth.go Resolved
Comment thread cmd/lk/user_auth.go Resolved
Comment thread cmd/lk/user_auth.go Resolved
Comment thread cmd/lk/user_auth.go Resolved
Comment thread pkg/config/livekit.go
if _, err = toml.DecodeFile(tomlFile, &config); err != nil {
// A syntax error leaves config nil, and a type error leaves it
// partly decoded: neither is a config to act on.
return nil, configExists, fmt.Errorf("%w: %s: %w", ErrInvalidConfig, tomlFile, err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with api keys, lk room list next to a broken livekit.toml used to fall back to the default project and now errors. i think that's right, but it's a change for api-key users, so worth calling out in the body? also, which command panicked before? couldn't get main to

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Called out in the PR body. You're right that nothing panicked on main, and my earlier claim was wrong: the decoder allocates the config before parsing, so a syntax error returned (nil, true, err). resolveProject ignored that error (not ErrInvalidConfig) and fell through to the default project. So the API-key change is: a syntax error used to silently use the default project and now errors. A type error or empty file already errored (invalid URL). I fixed the comment in LoadTOMLFile and dropped the dead nil guard.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for digging. small correction for the body: with a single api-key project configured, room list on main fell back to it for a type error or an empty toml too (the sole-project fallback), so it's only "already errored" once there are two or more projects. with this pr a type error now errors either way

Comment thread cmd/lk/agent.go Resolved
Comment thread cmd/lk/user.go
}
if projectID == "" && workspaceID == "" {
return errors.New("one of --project or --workspace is required")
if workspaceID == "" || cmd.String("project") != "" {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: with nothing set, the error used to mention --workspace. now it's the picker's "set --project", so --workspace drops out of the hint

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6e7b9f4: when nothing names a project, the resolver's error gets ", or --workspace to list a workspace's users" appended. Asserted in user-auth-project-scoped-commands.txtar.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks. one thing: the suffix lands on any resolver error, not just the picker's. with a broken livekit.toml, user list says "…toml: line 2 … instead, or --workspace to list a workspace's users", and with a LIVEKIT_URL that isn't yours you get three "or"s in a row. only append it to the non-interactive picker error?

rektdeckard added a commit that referenced this pull request Dec 2, 2026
Addresses review on #1156:

- Read the global --url/LIVEKIT_URL from the root command, so a
  subcommand's own --url (webhook update's delivery URL) doesn't hide it.
- An explicit --url that names no project is an error under --user-auth,
  except in agent runs, where --url is where the agent connects.
- Match a LiveKit Cloud URL by subdomain only within the same Cloud, so a
  staging URL never picks a production project.
- Say "Ignoring LIVEKIT_URL" from the resolver, where it's actually
  skipped (an earlier step wins, it names no project, or project delete's
  picker), instead of guessing in announceUser.
- Point URL errors at --legacy-auth, and user list's at --workspace.
- Make the default auth mode injectable so tests cover 3.0's rows.
- Fold createAgentClientWithOpts into createAgentClient.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
devin-ai-integration[bot]

This comment was marked as resolved.

rektdeckard and others added 7 commits December 2, 2026 10:24
…auth

Addresses review on #1156:

- Agent commands apply their working-dir argument before resolving the
  project, so the livekit.toml read (and cached) is the requested agent's,
  not the current directory's. This also affected API-key mode.
- A CLI config entry without a project id maps to a user's project only by
  its URL, or by subdomain when that URL is a LiveKit Cloud one, so a
  self-hosted entry never maps to a Cloud project sharing its first label.
- Under --user-auth, a livekit.toml that can't be read or names no project
  is an error instead of falling through to the default project.
- LoadTOMLFile returns ErrInvalidConfig for a decode error instead of
  panicking on a syntax error or returning a half-decoded config.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Addresses review on #1156:

- `lk agent update DIR` no longer saves the agent's unchanged config to the
  current directory, which overwrote another agent's livekit.toml there.
- `lk agent init NAME` takes its project from the current directory again,
  as before #1156's working-dir change (NAME is a directory it creates), and
  then drops the current directory's agent config rather than carrying it
  into the new agent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Addresses review on #1156:

- `lk user list` without --workspace resolves its project with
  resolveProjectRef (--subdomain, LIVEKIT_URL, livekit.toml, default,
  picker) instead of jumping straight to the default project.
- `lk project delete` also takes the project by --subdomain, which is as
  explicit as --project. It still never infers one from LIVEKIT_URL, a
  livekit.toml or the default project.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Addresses review on #1156:

- Read the global --url/LIVEKIT_URL from the root command, so a
  subcommand's own --url (webhook update's delivery URL) doesn't hide it.
- An explicit --url that names no project is an error under --user-auth,
  except in agent runs, where --url is where the agent connects.
- Match a LiveKit Cloud URL by subdomain only within the same Cloud, so a
  staging URL never picks a production project.
- Say "Ignoring LIVEKIT_URL" from the resolver, where it's actually
  skipped (an earlier step wins, it names no project, or project delete's
  picker), instead of guessing in announceUser.
- Point URL errors at --legacy-auth, and user list's at --workspace.
- Make the default auth mode injectable so tests cover 3.0's rows.
- Fold createAgentClientWithOpts into createAgentClient.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
projectURLSetting decided that LIVEKIT_URL set the global --url when the
two values were equal, so `--url "$LIVEKIT_URL"` naming no project was
skipped as ambient and the command fell through to the default project.
The flag's LIVEKIT_URL source now records whether it set the value last.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rektdeckard
rektdeckard force-pushed the tobiasfried/legacy-auth-flag branch from 2b44bc1 to 2d1ad71 Compare December 2, 2026 17:26
@Topherhindman

Copy link
Copy Markdown
Contributor

heads up: TestCredentialResolution fails with -rapid.seed=11599178079549652730. under user auth its namedProjects only allows --project, the default or the sole project, so a draw with a livekit.toml (or --subdomain/url) naming one of the user's projects trips it now. passed in CI by luck. could you teach the oracle about the new steps?

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.

2 participants