feat: Check moca's grants on both paths, bind credential lookups to them, and serve MOCA_TENANCY=multi
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 8/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- go
調査の方向性
Start with core/listener/vmcontrol/registry.go around Register (lines 110-112), where a non-empty grant is currently refused, and core/listener/vmcontrol/wire.go for the ControlRequest layout. The work is blocked on moca step 6 and on #2087, #2088 and #2089, so confirm those have landed first. Done means both grant paths verify, the lookup is bound to the grant, and the multi-tenant conformance cases pass.
索引モデルが issue の本文から書いたものです。
説明
Parent: #2042, step 7 of the build order (#2085 → #2087 → #2086 → #2088 → #2091 → #2089 → (moca step 6) → #2090). Needs #2087 (Binding), #2088 (credresolve) and #2089 (Record).
Blocked by moca (#2042 step 6):
- The grant on
Exec, inRegisterand inRebind(D4, D5). - The grant-bound credential lookup (D10): the sandbox service's phase 2, and MI1 §6.3's token endpoint for harness sessions.
- multi-tenant cases in moca's conformance suite, and a split of
grant_refused_under_single.
The token formats are fixed in moca's code already, so the verifiers can be built and tested now.
Problem
MOCA_TENANCY=multi is the reason Cortex replaces moca-egress (#2042). Two things must hold in multi-tenant mode:
- A VM's binding is proven by a grant that moca's control plane signed. A compromised VM worker can then bind only sessions it holds live grants for.
- A credential is released only against that grant. A stolen host token then yields nothing on its own.
Today Cortex refuses any grant, refuses to start under multi, and looks up credentials with the host's token alone.
Shared contract
Nothing new. The grant lives in the moca driver's vmBinding and reaches the rest of Cortex only through Binding.Admit, as Caller.Subject, Caller.Claims["tenant"], Caller.Credentials, Caller.Expires and the opaque Caller.Grant (#2042, "Shared contract").
moca's design (read in full on 2026-11-23)
Two paths, each with its own token:
| Path | The grant | How the credential lookup uses it | Source |
|---|---|---|---|
Sandbox service (mocactl sbx) |
The user's sandbox token: typ moca-sandbox+jwt, aud moca-sandbox, with the sandbox, the worker (wrk) and the workspace (wsk) |
Phase 2: the egress proxy adds the token to POST /v1/egress/credential. The control plane verifies it in addition to the host token, and caps ttlSeconds at the token's remaining life. |
moca docs/specs/2026-10-26-sbx-egress-credentials-design.md §9 |
| Harness sessions | moca's grant: typ moca-grant+jwt, aud moca-sandbox, claims iss, sub, tenant, sid, iat, exp, jti, turn_exp, egress[], cfg? |
MI1 §6.3: POST /internal/token, RFC 8693: grant_type=urn:ietf:params:oauth:grant-type:token-exchange, subject_token=<grant>, subject_token_type=urn:moca:token-type:session-grant, audience=<destination host>. Reply {access_token, issued_token_type, token_type, expires_in, moca_binding: {header, format}}, expires_in at most 60 s. Errors: grant_invalid, session_not_found, credential_ambiguous, no_credential. Only the egress proxy may call it, with MOCA_EGRESS_CP_TOKEN. Cache per (sid, credential) for min(expires_in, grant exp). |
MI1 (docs/specs/2026-09-28-moca-multi-user-isolation-design.md) §6.1, §6.3, §10.1 · packages/control-plane/src/grant.ts:24-86 |
Both paths deliver the grant the same way: the relay or the worker puts it on Exec, and the VM worker passes the newest grant for each session in Register{vm_id, sid, grant} and in Rebind{sid, grant} (MI1 §8.3, the sandbox spec §9).
Today
Read at Cortex main 7f3eec7 and moca main e464dd6 (2026-11-23).
| What | Where |
|---|---|
| Cortex refuses grants | vmcontrol.Registry.Register: a non-empty grant is bad_request (core/listener/vmcontrol/registry.go:110-112) |
Cortex refuses multi |
MOCA_TENANCY=multi is a boot failure (cmd/cortex/vmcontrol.go) |
Rebind |
ControlRequest field 3 is reserved (core/listener/vmcontrol/wire.go:24, moca proto/egress/v1/control.proto) |
The grant on Exec |
Not built. Both specs name field 7, which is now mode (moca proto/sandbox/v1/sandbox.proto). Fields 1–12 are used, so 13 is the next free one (D4). |
| moca's grant check | verifyGrant (moca packages/control-plane/src/grant.ts:184-240) and golden vectors (packages/control-plane/test/fixtures/grant-vectors.json, MI1 §12.2). The vectors include aud moca-inference grants that must be accepted for that audience. Keyset rule: each kid equals the first 16 hex characters of sha256(SPKI DER) (moca token.ts:103-106, 157-162). |
| moca's sandbox-token check | moca packages/control-plane/src/sandbox-token.ts:11-41, 100-158, and the relay's packages/sandbox-relay/src/sandbox-auth.ts:38, 91-99. The relay requires SH_SANDBOX_TOKEN_ISSUER whenever the keyset is set, with no default (sbx-control-plane is only the minting default). The verifier does not check sbx == wsk. The control plane checks sbx = sandbox and wrk ∈ the host's workers (sbx spec §9). |
| Keys | Grants: MOCA_GRANT_PUBLIC_KEYS, <kid>:<base64 SPKI>, comma-separated, Ed25519 only (moca token.ts, docs/reference/configuration.md:251). Sandbox tokens: SH_SANDBOX_TOKEN_PUBLIC_KEYS, same format. |
| Grant lifetime | MOCA_GRANT_TTL_S, default 300 s. exp = min(iat + TTL, turn_exp). Refreshed at half-life, except for async turns, where exp == turn_exp for the whole turn and there is no refresh (moca docs/reference/configuration.md:252). No revocation list. |
| A JWT library Cortex already uses | github.com/lestrrat-go/jwx/v2 v2.1.7 (core/go.mod), with EdDSA. Its jwt.Parse validation refuses now >= exp (jwt/validate.go:380), which fails moca's valid-through-exp vector, and refuses a future iat, which moca allows. |
| The RFC 8693 client | tokenexchange/exchange.Client (core/plugins/tokenexchange/exchange/client.go). Exchange hardcodes subject_token_type and requested_token_type to urn:ietf:params:oauth:token-type:access_token (:83-85). The reply parser reads only access_token, token_type and expires_in (:164-178). It uses a default http.Client with a 30 s timeout (:51-53). ClientAuth.Apply can add form fields only (auth.go:10-12). Option exists, with no options defined (:41-44). |
Rebind in moca's proto |
reserved 3 is at message level, not inside the oneof (moca proto/egress/v1/control.proto:15-20) |
| The conflict in moca's suite | grant_refused_under_single also requires that MOCA_TENANCY=multi fails to start, naming MOCA_TENANCY (moca remote-worker/egress/conformance/cases.go:908-921). A Cortex that serves multi fails it as written. |
| The SSRF guard | listener.egress_guard is off by default and set only in YAML (cmd/cortex/main.go:905, core/config/config.go:1206) |
| Lease VMs | A lease VM lives up to 8 h (4 h at level 2) across many Execs, and level-2 processes use egress between Execs (moca docs/specs/2026-11-08-sbx-lease-mode-design.md §4, §7). Register happens once per VM restore. The sandbox token lives 15 min by default (SH_SANDBOX_TOKEN_TTL_SECONDS). The relay cancels a running Exec 30 s after its token expires (moca packages/sandbox-relay/src/main.ts:91). |
Change
- Keep the newest grant for each session in the moca driver. Under
multi,Registermust carry a grant.Rebind{sid, grant}(field 3, shape per D5) replaces it for every VM of that session. Reads and writes are safe across goroutines, becauseAdmitruns on every request. - Check the grant on
RegisterandRebind, by its path. Select the path from the token'styp: one proxy serves both kinds of VM on a host, and both workers run as root, so the peer's UID cannot tell them apart. Each path accepts only its own token type. Uselestrrat-go/jwx/v2'sjws.Verifyfor the signature, check thetypheader by hand, parse the claims withencoding/json, and run moca's checks yourself. Do not usejwt.Parse's validation (see the table).- Harness grant, the checks of moca's
verifyGrant:- A valid Ed25519 signature from a known
kid.algisEdDSA.typismoca-grant+jwt.audismoca-sandbox.issismoca-control-plane-grant. sub,tenantandsidare not empty strings.iat,expandturn_expare numbers, andjtiis a string. Foraud moca-sandbox,egressis an array of strings.cfg, when present, is a string.- Each
kidinMOCA_GRANT_PUBLIC_KEYSequals the first 16 hex characters of sha256 of its SPKI DER. A key that breaks this is a start-up error. now > expandnow > turn_expare refused, so a grant is valid through itsexpsecond. There is no clock leeway. (MI1's 2026-11-05 amendment saysturn_expis not built. The code checks it, so follow the code.)sidequals theRegister'ssid.- The verifier takes the audience as a parameter. Every vector in moca's golden file passes or fails for the right reason, run with its own
aud.
- A valid Ed25519 signature from a known
- Sandbox token, the checks of moca's sandbox-token verifier:
typismoca-sandbox+jwt.audismoca-sandbox.issequalsSH_SANDBOX_TOKEN_ISSUER, which is required with the keyset (no default).scopecontainsexec.sub,tenant,sbx,wrkandwskare not empty strings.iatis a number andjtia string. The mode claims (mode,mode_epoch,idle_timeout_s) pass moca's checks (sandbox-token.ts:100-158).sbxequals theRegister'ssid(the sandbox ID is the session on this path).sbx == wskis not checked, because moca's verifier does not check it.expwith a 30 s leeway. The keys areSH_SANDBOX_TOKEN_PUBLIC_KEYS, notMOCA_GRANT_PUBLIC_KEYS.- Refuse
typ moca-sandbox-mode+jwt, which has the sameaudand keys.
- A failure answers the control request with a named refusal (
grant_invalidproposed).
- Harness grant, the checks of moca's
- Fill the caller in
vmBinding.Admit:Subjectfromsub,Claims["tenant"]fromtenant,Credentialsfromegress(nil on the sandbox path, whose token has noegressclaim),Expiresfromexp,Grantfrom the raw token. AfterExpires,Admitanswers403 grant_expired(MI1 §8.5 item 1) throughvmBinding.Refusal, and nothing is dialed. This one check covers CONNECTs and every decrypted request, because each one passesAdmit. - Bind the lookup to the grant, in the moca resolver (#2088):
- Sandbox service: add the sandbox token to
POST /v1/egress/credential(phase 2). No cache entry outlives the token. - Harness: call
POST /internal/tokenthroughexchange.Client, with small, general additions to that package: aSubjectTokenTypefield onExchangeRequest(empty keeps today's value), the reply's unknown fields kept as raw JSON onExchangeResponse, and an optionWithHTTPClient(*http.Client). The moca driver passes a client with #2088's hardening (no proxy, no redirects, its CA, a 3 s timeout) and aRoundTripperthat adds its own authentication.requested_token_typekeeps its default, which RFC 8693 allows. The moca driver readsmoca_bindingfrom them and turns the reply into onecredresolve.Credential(Headersfrommoca_binding.headerandformat,PathPrefix: "/", the destination's port). A missingmoca_bindingmeansAuthorization: Bearer. The client authenticates withMOCA_EGRESS_CP_TOKEN, read from a file. Thetoken-exchangeplugin and its config do not change. - Map
session_not_foundto an empty list cached for 5 s, andgrant_invalidandcredential_ambiguousto&credresolve.Refusal{Status: 401, Code: <code>}. no_credentialis a departure from MI1. MI1 §6.3 item 4 answers the guest401, because MI1 intercepts by matching the host against the grant'segressnames first (§8.5 item 4). This design decides interception by the lookup at CONNECT, for both paths, sono_credentialbecomes an empty list: an opaque tunnel. Confirm with moca (below).- Set each
Credential.Expirestomin(now + expires_in, Caller.Expires), so #2088's 5 s rule removes it before the grant ends. Start atime.AfterFuncatCaller.Expiresthat callsForget(sid), and reset it on eachRebind.
- Sandbox service: add the sandbox token to
- Never use the guest's own
Authorizationas a subject token. The subject comes only fromCaller.Grant. - Start-up under
multi. The moca driver adds its rules to shared mode's checks (#2087). Cortex refuses to start, naming the missing setting, unless all of these are present:- The interception CA key.
- A non-empty allowlist, and not
*(D14: allow-all is refused undermulti). - The SSRF guard on.
- The credentials URL and token.
MOCA_EGRESS_CP_TOKENas a file, when the harness path is on.- the keys for each enabled path.
- Under
single(the default), grants stay refused, exactly as today.
Not in scope
- The container tier's identity source (MI1 S5, later).
- Minting or refreshing grants and sandbox tokens. That is moca's control plane.
Tests
- moca's golden grant vectors: every valid one passes, and every invalid one is refused for the right reason.
- Sandbox tokens: each check in item 2,
moca-sandbox-mode+jwtrefused, and the 30 s leeway at both edges. - Each path refuses the other path's token type.
- Under
multi: aRegisterwithout a grant is refused. Afterexp, a CONNECT and a decrypted request on an open tunnel each get403 grant_expired. ARebindextends every VM of the session. ConcurrentRebindand requests pass-race. - Sandbox service: the lookup carries the token, and no cache entry outlives it.
- Harness: the exchange request has RFC 8693's form fields and
subject_token_type=urn:moca:token-type:session-grant. Each named error maps as item 4 says.moca_bindingsets the header. Thetoken-exchangeplugin's own tests pass unchanged. - Under
single: aRegisterwith a grant is stillbad_request. - The start-up checks fail once for each missing setting.
Done when
- A
hostegressbuild servesMOCA_TENANCY=multi. Each binding is proven by a grant, and each credential lookup carries that grant. - moca's multi-tenant conformance cases pass against it (#1489), once moca has written them.
For a human after review
-
Ask moca: D5's field numbers for
Rebind. The proposal issid = 1,grant = 2. -
Ask moca: the name of the field that carries the sandbox token on
/v1/egress/credential(phase 2), and the grammar ofmoca_binding.format. The proposal is{"header": "Authorization", "format": "Bearer {token}"}. -
Ask moca: the
no_credentialdeparture from MI1 §6.3 above. -
Ask moca: how does the egress proxy authenticate to
/internal/token? MI1 §6.3 says only "moca-egress's OWN credential" (MOCA_EGRESS_CP_TOKEN). The proposal isAuthorization: Bearer, as on/v1/egress/credential, which needs one moreOptiononexchange.Client. -
Ask moca: D15 (lease mode). Who sends
Rebindwith a fresh token while a lease VM runs between Execs? -
Ask moca: split
grant_refused_under_single, so thatmultican pass the suite.
- 主要言語
- Go
- スター
- 31
- フォーク
- 49
- 平均マージ
- 9時間 43分
- マージ済み PR(30日)
- 367
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
rossoctl/cortex のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
bug laptop
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
メンテナーはふだん 1 日以内に返信
rossoctl/cortex の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
taskmanager: a failed v1alpha1 backup leaves the partial backup behind対応中かも @arshil42 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
ether/etherpad-go#571 ·
メンテナーはふだん 1 日以内に返信
-
labeler: read a limit above math.MaxInt as math.MaxInt in nonNegative (CodeQL alerts #20 and #21)オープンcost:approved factory:queued factory:tracking priority:p2 rank:12 ready-for-doing task:approved tokens:50k
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
sisaku-security/sisakulint#860 · コメント 2 件 ·