Repository navigation
chore(auth): prepare for migration to user-auth as default - #1156
rektdeckard wants to merge 14 commits into
Conversation
…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>
Topherhindman
left a comment
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
| } | ||
| if projectID == "" && workspaceID == "" { | ||
| return errors.New("one of --project or --workspace is required") | ||
| if workspaceID == "" || cmd.String("project") != "" { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
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>
…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>
2b44bc1 to
2d1ad71
Compare
|
heads up: |
|
I've reviewed by adding commits with failing tests with things that should work. Feel free to drop my commits if you feel they are wrong or if the issues are fixed/invalid. |
Prepare auth mode and project resolution steps for 3.0:
resolveAuthMode). Reads--legacy-auth, then--user-auth, then theLIVEKIT_LEGACY_AUTHenv var, then falls back to the default (API keys until 3.0). An explicit--user-authwins 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.--legacy-authglobal flag visibleresolveProjectRef), and adds the same detection order to user-auth as existed in legacy-auth. Reads--projectflag or positional arg, then--subdomain, then--urlorLIVEKIT_URL, thenlivekit.toml, then the default project, and finally shows the project picker if no other match.livekit.toml,--subdomainor LiveKit Cloud URL naming a project the user can't access is an error, not a fallback to the default. So is an explicit--urlnaming no project (except in agent runs, where--urlis where the agent connects). ALIVEKIT_URLnaming no project (e.g. a local server) is skipped, with a notice.--urlis read from the root command, so a subcommand's own--url(e.g. a webhook's delivery URL) doesn't hide it.lk project deleteonly acts on a project named on the command line (positional,--projector--subdomain); otherwise it shows the picker, never inferring one fromLIVEKIT_URL,livekit.tomlor the default project.agent init, whose argument is the directory it creates);agent updateno longer rewrites the current directory'slivekit.toml.LoadTOMLFilereturnsErrInvalidConfigfor alivekit.tomlit can't decode, instead of a half-decoded config or an unwrapped error.Behavior change for API-key users: a
livekit.tomlwith a TOML syntax error used to be skipped silently, so commands ran on the default project. It's now aninvalid configuration fileerror. (A type error, e.g.subdomain = 42, or an empty file already errored, withinvalid URL.)