Skip to content

feat: Kanidm OIDC sign-in and per-principal thread access (fork) - #2

Closed
caniko wants to merge 12 commits into
mainfrom
feat/oidc-principals
Closed

caniko wants to merge 12 commits into
mainfrom
feat/oidc-principals

Conversation

@caniko

@caniko caniko commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

Fork-only. Rebases the principals prototype (#1) onto v0.1.7-nightly.20261102.4066 and adds:

  • OIDC sign-in (/auth/oidc/start, /auth/oidc/callback). The server is a confidential client of Kanidm, using code flow with PKCE, state and nonce. It verifies the ID token against JWKS, requires t3code_users, and takes the principal from preferred_username. Web gets a principal browser session; desktop gets a 2-minute pairing link via t3code://pair. Configured through T3CODE_OIDC_* env.
  • One thread access check (canAccessThread(principal, thread, read|write)) used by WS, HTTP, MCP and search. The default owner principal sees everything. Principal scopes allow normal app use, and a short deny-list keeps server-wide reads owner-only.

Not yet: session groups and invites, the per-user runner, the UI, and per-principal peer-link storage on the linking side.

Known CI-irrelevant local failures: 7 tests whose temp-repo git commit fails under the operator's global hooks (also on the untouched tree).

Supersedes #1.

Council review

Rounds: 1 (question: close as superseded by #6)

Delegate Round 1
Claude Opus 5.5 8/10
GPT-6.1 Sol 9/10

🤖 Generated with Claude Code

caniko added 10 commits November 2, 2026 08:23
One server per machine serves several people, each with their own workspace,
instead of one server and port per person. Covers principals bound to the
pairing subject, owner-stamped threads and projects, fail-closed RPC and HTTP
surfaces, per-principal execution (recommends a per-user runner over one OS
user with per-principal HOMEs), peer links per principal, migration, the
threat model including pingdotgg#26490, and a C2 outline for groups. Also adds an
unposted draft reply for Ideas pingdotgg#12283.
A pairing grant or session issued with --principal <id> carries subject
principal:<id>. Threads that session creates are stamped with ownerPrincipal,
and shell, thread, history and dispatch paths over WebSocket and HTTP only
show or act on threads the caller's principal owns. Other threads fail as not
found. Principals are capped at orchestration scopes, may call only an
allowlist of RPCs, and every other scoped HTTP, raw and media route fails
closed for them. Existing subjects map to the default "owner" principal, so
single-user state and behavior are unchanged.

Projects, MCP tool reads and per-principal execution are not covered yet; see
docs/internals/multi-user.md.
Upstream's CI needs Blacksmith runners, so the fork gets one hosted job that
typechecks and runs the contracts and server suites on pull requests.
…threads

Agents reading or changing a thread through MCP now pass the same visibility
check as clients: an agent acts as its thread's owner, and an outside MCP
client as the default principal. Principals can launch threads; the launch is
stamped with the caller's principal and a reused thread must be visible. The
older-settled page filters by owner before its limit, so a hidden row no
longer ends a principal's pagination early.
t3_thread_list and t3_thread_search now filter by the calling thread's owner
before pagination and the hit limit, so a principal's agent sees neither the
other principals' threads nor short pages. Threads an agent launches through
t3_thread_launch inherit its owner.
Principals could not search their own threads because searchThread and
searchThreadStream were missing from the principal RPC allowlist. Both
now check thread visibility first. t3_thread_wait and the other tools
that resolve a target through loadScopedThread skipped the ownership
check; they now fail with thread_not_found for another principal's thread.
A shared server needs to know which person a client is without handing
out pairing links by hand. With T3CODE_OIDC_ISSUER set, the server is a
confidential OIDC client: /auth/oidc/start runs the authorization-code
flow with PKCE, state and nonce, and /auth/oidc/callback verifies the ID
token against the issuer's JWKS, requires the allowed group and takes the
principal from preferred_username. The web client gets a principal
browser session; the desktop app gets a two-minute principal pairing link
through the existing t3code://pair deep link. The auth descriptor
advertises oidcSignIn so clients can offer the button.
Principals now arrive through OIDC sign-in and must be able to use the
app normally, so the prototype's owner-only filter and RPC allowlist were
too tight. canAccessThread(principal, thread, read|write) is now the one
rule every WS, HTTP, MCP and search path asks; the server's default owner
principal sees every thread. Principal scopes cover orchestration,
providers, terminals, source control and files, and a short deny-list
keeps server-wide reads under those scopes (storage reports, agent
session import, ACP registry, webhook delivery) for the owner only.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T10:09:14.743271Z 5e872c5 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4836605e0e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/server/src/ws.ts Outdated
Comment on lines +1932 to +1933
const found = yield* threadManagement.getThreadRecords(threadId, []).pipe(Effect.option);
return Option.isSome(found) && canAccessThread(principal, found.value.thread, action);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Gate the remaining thread-scoped RPCs

A principal with orchestration:operate can still call worktreeSetupCancel directly, and assetsCreateUrl can mint a signed URL for a tool-output-image using another thread's IDs without checking ownership. A principal who knows those IDs can cancel another user's setup or read its tool output; apply the visibility check to these auxiliary handlers too.

Useful? React with 👍 / 👎.

Comment on lines +133 to +138
pending.set(state, {
nonce,
verifier,
client: input.client,
origin: input.origin,
expiresAt: now + LOGIN_TTL_MS,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Bind OIDC state to the initiating browser

If an allowed user gives someone their callback URL before it is consumed, the process-wide pending entry lets that other browser complete the flow: the callback checks only state, while the PKCE verifier and nonce are also stored server-side. The victim can therefore be signed into the attacker's principal, causing subsequent prompts to land in an account the attacker can read; bind the state to the browser that started sign-in and require that binding at callback.

Useful? React with 👍 / 👎.

Comment on lines +284 to +285
WS_METHODS.scheduledTasksListWebhookDeliveries,
WS_METHODS.scheduledTasksGetWebhookDelivery,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Restrict global scheduled-task RPCs for principals

The principal-specific denylist blocks only delivery-log calls here, but scheduledTasksSubscribe is read-scoped and principals hold that scope; its shared service returns every task. Principals also hold the operate scope required by the upsert, disable, delete, run, and token-rotation RPCs, which act on task IDs without owner filtering. A signed-in principal can therefore read another user's prompts and webhook URLs, then mutate or trigger their scheduled agents; deny this RPC family to principals or scope task reads and mutations by principal.

Useful? React with 👍 / 👎.

requireThreadAccess read the thread on every request, even for the
default principal that can reach every thread. That added a store read to
the owner's snapshot path and failed the bounded snapshot transport tests,
whose stub ThreadManagementService has no getThreadRecords.
…roles

People on a shared server need to bring each other into their work
without seeing everything. A thread owner can share a thread with a
principal, and a group owner can put their threads in a named session
group and invite members, each as viewer (read) or participant (read and
write). canAccessThread stays the one rule and now takes the caller's
grants; the older-settled SQL filter includes shared and group threads.
Messages a participant sends carry a server-stamped senderPrincipal while
the thread, and so its turns, stay the owner's. Exposed as
sessionAccess.list/threadShares/mutate RPCs and `t3 group` / `t3 share`.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5e872c55e5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

);
}
yield* assertThreadOwnedByCallerPrincipal(
parent?.thread.ownerPrincipal ?? DEFAULT_PRINCIPAL_ID,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Scope owner-thread MCP reads to owner-owned threads

When an MCP tool runs from an owner-owned thread, its ownerPrincipal is omitted, so this fallback passes DEFAULT_PRINCIPAL_ID to assertThreadOwnedByCallerPrincipal; canAccessThread treats that principal as an unrestricted admin. The agent can therefore use t3_thread_read and other cross-thread tools to access any principal’s private threads, contrary to the MCP isolation described in docs/internals/multi-user.md. Use an owner-only visibility check for thread-bound MCP callers instead of the admin bypass.

Useful? React with 👍 / 👎.

Comment thread apps/server/src/ws.ts
Comment on lines +2356 to +2359
whenThreadsVisible(
[input.threadId],
() => threadNotFound(input.threadId),
subscribeOrchestrationV2Thread(input),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Filter raw events before streaming to viewer grants

When a principal has only a viewer grant, this read check admits them and then returns the unfiltered subscribeOrchestrationV2Thread stream, which replays stored event payloads directly. That exposes raw thread events rather than the allowlisted projection required for group viewers by docs/internals/multi-user.md; apply the safe projection before streaming shared threads.

Useful? React with 👍 / 👎.

Comment thread apps/server/src/ws.ts
});
}),
),
"write",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Restrict participant dispatch to collaboration actions

When an owner grants participant, this gate authorizes every existing-thread command as a write, not just the collaboration actions described for participants. A participant can submit checkpoint.rollback (which restores files by default) or thread.metadata.update against the shared thread, changing the owner's workspace or thread state; restrict dispatch by command type or keep those mutations owner-only.

Useful? React with 👍 / 👎.

Comment thread apps/server/src/ws.ts
);
return {
...result,
matches: result.matches.filter((_, index) => visible[index]),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Filter principal search results before applying the limit

For a principal search, this filters only after the search has capped its results; if the first 50 hits belong to inaccessible threads, they are dropped without refilling the response, so matches in the caller's own or shared threads disappear. Apply thread visibility before ranking and limiting search results.

Useful? React with 👍 / 👎.

const state = random();
const verifier = random();
const nonce = random();
pending.set(state, {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Rate-limit unauthenticated OIDC login starts

On an OIDC-enabled server reachable at a configured public origin, /auth/oidc/start is unauthenticated and each request inserts a pending login here. A network caller can issue 1,000 starts to fill this process-wide map, after which legitimate starts are rejected until entries expire; repeated requests can keep the pool full. Throttle admissions so one caller cannot exhaust the global login pool.

Useful? React with 👍 / 👎.

readonly oidcPrincipalClaim: string;
readonly oidcPublicOrigins: ReadonlyArray<string>;
}) {
const issuer = env.oidcIssuer?.trim().replace(/\/+$/, "");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve the configured OIDC issuer identifier

When T3CODE_OIDC_ISSUER contains a valid trailing slash, this normalization removes it before discovery, then OidcLogin.discover rejects providers whose metadata issuer retains that slash because it compares the identifiers exactly. Keep the original issuer for metadata validation and normalize separately when constructing the discovery URL.

Useful? React with 👍 / 👎.

@caniko

caniko commented Nov 8, 2026

Copy link
Copy Markdown
Owner Author

Note

🤖 Claude Opus 5.5 responding on behalf of caniko

Closing #1–#4 as superseded by #6, which rebased all 26 of their commits onto the 20261104 nightly and merged them into main (now 54109db634). Closing does not fix the review findings below. Two council reviewers rechecked them against main@54109db634 and found them still open. Issues are disabled on this fork, so this comment is where they are tracked.

Access control (from #1, #2, #4)

  • Scheduled tasks are not scoped to a principal: subscribe, upsert, setEnabled, delete, runNow and rotateWebhookToken have no owner check (apps/server/src/ws.ts:2460-2477). The principal denylist covers only the delivery-log methods (apps/server/src/auth/RpcAuthorization.ts:283-293).
  • MCP callers on default-owner threads fall back to the default principal, which bypasses every check (apps/server/src/mcp/OrchestratorMcpService.ts:1218, :1287; apps/server/src/orchestration-v2/ThreadOwnership.ts:27).
  • worktreeSetupCancel and assetsCreateUrl for tool-output-image skip thread visibility (apps/server/src/ws.ts:3169, :3247-3250).
  • Viewers receive the raw subscribeOrchestrationV2Thread stream, not a viewer projection (apps/server/src/ws.ts:882-893, :2436-2444).
  • Unsharing does not revoke subscriptions that are already open; access is checked only when a subscription starts (apps/server/src/ws.ts:2436-2444).
  • Participants may dispatch general write commands, including rollback and metadata changes (apps/server/src/ws.ts:2091-2133).
  • Search filters visibility after limiting results (apps/server/src/ws.ts:2229-2245).
  • New-thread launches do not check project ownership (apps/server/src/ws.ts:2321-2341).
  • The mobile client ignores viewer roles (apps/mobile/src/features/threads/ThreadRouteScreen.tsx:356-359).

OIDC (from #2)

  • The callback checks state but does not bind it to the browser that started sign-in (apps/server/src/auth/OidcLogin.ts:157-160, apps/server/src/auth/oidcHttp.ts:60-67).
  • Unauthenticated starts can fill the global pending-login pool (apps/server/src/auth/OidcLogin.ts:19, :128-138).
  • The configured issuer loses its trailing slash before an exact comparison with the provider metadata (apps/server/src/cli/config.ts:232, apps/server/src/auth/OidcLogin.ts:113).

Runner (from #3)

  • Runner output ignores socket backpressure (apps/server/src/runner/RunnerServer.ts:118-119).
  • Startup unlinks whatever file sits at the socket path without checking that it is a socket (apps/server/src/runner/RunnerServer.ts:252-254).
  • getWorktreeOwners leaves out the default principal, so a worktree it shares with another principal is routed to that principal instead of failing closed (apps/server/src/orchestration-v2/ProjectionStore.ts:6693-6697).
  • Selected-file commits create the temporary GIT_INDEX_FILE as the server user, but git runs through the principal's runner (apps/server/src/vcs/GitVcsDriverCore.ts:2514-2518).

Web (from #4)

  • Moving a thread to another group removes the old membership before the new one is confirmed, with no rollback (apps/web/src/components/chat/ShareThreadDialog.tsx:57-69).

@caniko

caniko commented Nov 8, 2026

Copy link
Copy Markdown
Owner Author

Note

🤖 Claude Opus 5.5 responding on behalf of caniko

Superseded by #6, which rebased these commits onto the 20261104 nightly and merged them into main. Open review findings are carried in #2 (comment).

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