mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-10-03 00:02:08 +00:00
* feat: give the AI chat per-folder instructions from ai_instruction resources Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix: hold a change back until the model has read its folder instructions Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix: find nested trigger paths and scope instruction deliveries by workspace Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix: cap folder instructions per result and record holds as their own outcome Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix: show a held call as its own row and cover group folders Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix: state how folder instructions combine with workspace and user ones Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
11 KiB
11 KiB
Auth surface: facts that are easy to get wrong
Symbols, not line numbers, are cited: they drift less.
- Credential precedence (
windmill-api-auth/src/auth.rsextract_token):Authorization: Bearer→tokencookie →?token=query param. A URL with?token=is a credential on every route, but an existing cookie silently wins over it. AUTH_CACHEcaches a token's identity for 120 s. Deleting a token row does not purge it: the DB trigger (migrations/20260316000001_token_hash_pk_swap.up.sql) notifies only forlabel = 'session'rows, anddelete_tokennever callsinvalidate_token_from_cache.- Sessions are
tokenrows withlabel='session'plus the HttpOnlytokencookie, minted only bycreate_session_token(windmill-api-users/src/users.rs).GET /api/users/refresh_tokenmints one for any non-job token but returns plain text, no redirect. tokens/impersonate(superadmin) returns a multi-use token and sets no cookie.max_token_expiration_dayscapsPOST /users/tokens/createandtokens/impersonate, by shortening the stored expiration (cap_token_expiration), never by refusing: the CLI authorization page,wmill user create-tokenand the editor's language-server token all pick a lifetime without reading the setting, and CLIs already installed never will. The CLI signs in again on its own when its token expires, which is why the authorization page labels itcli-login:<username>, reserved inis_user_tokenso its expiry does not email the user. A token owned by a service account is exempt: one in the workspace the token names, or in any workspace for a workspace-less token (fortokens/impersonate, the impersonated account). Any workspace admin can therefore create and impersonate a service account to hold an uncapped token, so the ceiling bounds personal tokens only. Only the stored expiration is capped: the auth lookup never reads the setting, so tokens that exist when it is turned on or lowered keep theirs, including none. Deliberately outside it: server-side mints (create_token_internalcallers such as native trigger webhook tokens, which never expire for GitHub and Nextcloud), and tokens with their own fixed lifetime that outlive a short ceiling: sessions (MAX_SESSION_VALIDITY_SECONDS, 3 days, and re-mintable throughGET /users/refresh_token) and MCP OAuth access tokens (7 days, with a rotating 30-day refresh token). Any logged-in user can read the setting throughGET /settings/global/{key}, which the token form uses to offer only expirations within it. The settings API and config sync reject any valueparse_max_token_expiration_dayscannot read, since the token routes would read it as no ceiling;parseMaxTokenExpirationDaysin the frontend must accept exactly the same values.- A token's label decides whether its expiry raises alerts. When
delete_expired_itemsremoves an expiredtokenrow, the monitor emails the owner and raises a critical alert (if enabled); rows registered byregister_token_expiry_notificationalso get an "expiring soon" warning first, except a token whose whole lifetime fits inTOKEN_EXPIRY_WARNING_DAYS(7), which gets no row since the warning would arrive minutes after it was created. Neither happens whenis_user_token(windmill-common/src/auth.rs) reserves the label, so a token the system mints for itself, whether from the backend or from the frontend throughtokens/create, needs a reserved label. Anephemeral-prefix needs no other change (keep it clear ofis_server_minted_labelif minted throughtokens/create); a new prefix also goes into the SQL and Svelte mirrors that function's doc lists. - Every superadmin route refuses a job token:
require_super_admin(windmill-api-auth/src/lib.rs) errors onauthed.job_id.is_some(). A script that needsusers/create,tokens/impersonate,set_login_type, … must use a dedicated superadmin user token stored as a secret, never$WM_TOKEN. Token scopes cannot narrow superadmin routes. - Write access to a folder steers its readers' AI chat. An
ai_instructionresource's body is delivered to the global chat of everyone who can read the resource, with no opt-in, whenever the chat touches a path under its folder (copilot/chat/folderInstructions.ts); the chat then acts with that reader's permissions, outside the folder too.ai_skillbodies are likewise in play for every reader until turned off. The resource ACL is the only control, so granting write on a folder grants that influence. - A remote deploy token is a credential for another instance, held per account and workspace
(
remote_deploy_token, encrypted under the workspace key, re-keyed byset_encryption_key). Itsemailreferencespassword(email)withON DELETE/UPDATE CASCADE, so whatever deletes or renames an account takes the token along and a recycled address cannot inherit it; removal from a workspace deletes it explicitly (delete_workspace_user_internal, bothleave_workspace). The row records the target it was granted for, andremote_deploy::proxyonly sends it to a target still matching the workspace setting, so re-pointing the setting cannot redirect anyone's token to a URL of the admin's choosing.require_own_credentialsrefuses job, scoped and read-only tokens (onset_targettoo): the stored token carries none of their restrictions. The proxy turns the local session into a remote bearer credential, so every ambient-cookie vector becomes one on the remote: its URL carries the row's randomproxy_key(a link riding theSameSite=Laxcookie cannot know it; a header would do, but the frontend's only per-call hook is the globalOpenAPI.HEADERS, whose mere presence switches every download to in-memory blobs). The key is servedno-store, withheld from the credentialsrequire_own_credentialsrefuses, and masked in this instance's own request logs (RedactedUri, used by the request span and the log context); a reverse proxy in front still writes the full path to its access log.connectnames the target the token was obtained for and is refused, before the token is sent anywhere, if the workspace now points elsewhere; the token only ever goes to that target. It takes no lock against what clears these rows (a removal from the workspace, a target change, a key rotation): their writers take the account, membership, key and settings rows in every order, so any lock held there could close a deadlock. A row can therefore land after one of them ran, however long its remote call took, and every read (load_connection) voids it instead, by identity rather than by comparing times: the connect records, before its remote call, the target setting's version (remote_deploy_target_changed_at) and thecreated_atof the owner's membership, and the row counts only while both are still the same (or the owner is a superadmin) and it decrypts. So a target set A → B → A, or a removal and re-add, voids it whatever the clocks say. A superadmin with no membership is bound through the credential making the request instead: the insert requires itstokenrow to still exist, anddelete_user, offboarding and SCIM removal delete an account's tokens, so an address deleted that way and re-created during the call does not inherit the connection (a JWT, having no row, cannot connect a workspace its owner is not a member of).leave_instancedeletes only thepasswordrow, leaving the tokens and the memberships, which is not covered. Neither is a member's connect across an account re-creation: an address is not expected to pass to another person. A disconnect empties and stamps the row (inserting one if needed) rather than deleting it,connected_atis when a connect started, and the connect's upsert leaves a row stamped after that alone, so an older connect cannot undo a disconnect or a newer connect. Connecting by redirect: the remote's/user/remote_deploy_authorizepage mints a token bound to the one remote workspace (remote-deploy:<source host>, a label reserved inis_user_tokenso its expiry emails nobody) only on an explicit Authorize, only for a callback whose path is/remote_deploy/callback, and refuses to render inside a frame; the token travels in the fragment, and the callback checks a single-usestatethe drawer stored, so no other page can plant a token as the user's. The proxy also refuses a path the URL parser would rewrite, serves every response underCSP: sandbox+nosniff, forwards only the method, query, body, content-type and accept — never this instance's cookie or token — and turns the target's 401 into a 502, because the browser logs the user out of this instance on an unhandled 401. login_type(passwordtable) is a free-formVARCHAR(50). Password login and password reset requirelogin_type = 'password';set_passwordalso acceptspending_oauthand turns the account into apasswordone in the same statement (an account created ahead of its owner gets its first credential that way, or through the OAuth claim below).- Login links (
login_linktable,POST /users/login_linkssuperadmin-only,GET /auth/login_link/{token}unauthenticated): single-use, ≤15 min, a session cookie and a 302 to a same-originrd.require_login_typeon the mint refuses (409) an account whoselogin_typehas moved on — the way a caller re-entering an account it created stops being able to once the owner has a password or a provider. - Pre-approved trial offer (
cloud_trial_offer, cloud-only routes under/users/cloud_trial_offer): written by a superadmin at provisioning, consumed by{consumed: true}or by the portal's refusal;…/gois the one Windmill→portal hop that mints a portal login, over the sameCUSTOMER_SERVICE_TOKENtrust the onboarding hook uses (users_ee.rs, the portal's admin token). It never expires on its own. - OAuth login (
oauth2_ee.rslogin_externally, decision inexisting_login_decision) matches an existing account by lowercased email only. Same provider → login; apending_oauthaccount (seePENDING_OAUTH_LOGIN_TYPE) is claimed by the first login whose address the provider itself asserted and did not mark unverified —login_typebecomes the client key and the hash is nulled; otherwiserequire_preexisting_user_for_oauthdecides: on, every existing account is loggable-into by any provider; off, "exists but with a different login type". A new account getslogin_type = <client key>. - OAuth email trust:
LoginUserInfo.email_verifiedis read leniently (bool or "true"/"false" strings) and is only consulted for the claim above; only GitHub is filtered toprimary && verified; a missing email is fabricated fromnameas<name>@windmill.devand reacheslogin_externallywithemail_asserted = false. GET /api/oauth/login/{client}is an unauthenticated 302 to the provider — a plain link from any page starts SSO.CLOUD_HOSTEDis presence-tested (windmill-common/src/worker.rs):CLOUD_HOSTED=falsestill enables cloud mode. Of the routes above only the cloud trial offer and onboarding profile routes are cloud-gated; for the rest, cloud only adds quotas.CREATE_WORKSPACE_REQUIRE_SUPERADMINdefaults totruewhen unset; only the literal"true"enables it when set.