feat: Add a tenant-listener identity source to demo multi-tenancy without moca
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 25/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- go
調査の方向性
Start from the pattern in core/listener/vmcontrol/registry.go and handler.go, which wrap the forward proxy's handler per listener, and from config.ListenerPlan in core/config/listenerplan.go. The work depends on unmerged issues #2086, #2087 and #2088, so confirm those land first. Done means the end-to-end test in core/listener/tenantlisten passes in the core module's CI with no moca code in the build.
索引モデルが issue の本文から書いたものです。
説明
Parent: #2042, step 5 of the build order (#2085 → #2087 → #2086 → #2088 → #2091 → #2089 → #2090). Needs #2087 (Binding, shared mode), #2086 (Binding.Refusal) and #2088 (credresolve). It needs no moca code and no moca decision.
Problem
After #2042, Cortex serves many tenants from one process, but the only identity source is the moca driver. Nobody can see the feature without a moca KVM host. And only one user has shaped the seams, so they may fit only that user.
Goal
A small, general identity source and a small, general resolver, so that anyone can show multi-tenancy on a laptop:
- Two clients use two local proxy addresses.
- Each client gets its own credential for the same host.
- A header that a client sends never changes which tenant it is.
It is built before #2089 and #2090 on purpose. If it needs anything from the moca driver, a seam is wrong, and the fix goes into #2087, #2086 or #2088 while that is still cheap.
This driver is a demo and a test fixture, not a security boundary. Any local process can connect to any loopback port, so the port does not prove who the caller is (#2042, "Security model", G1).
Shared contract
This issue implements pipeline.Binding (Admit, Refusal) and registers a credresolve resolver, as #2042's "Shared contract" defines them. It turns on shared mode (Config.SharedMode). #2089 later adds Binding.Record, and gives this driver an empty Record.
Today
Read at Cortex main 7f3eec7 (2026-11-23).
| What | Where |
|---|---|
| The pattern to copy | vmcontrol serves one http.Server for each listener, with a handler that wraps the forward proxy's handler (core/listener/vmcontrol/registry.go:115-127, handler.go:42-55, 189-222). After #2087 the wrapper stamps pipeline.WithBinding. |
| The forward proxy's handler | forwardproxy.Server.Handler() (core/listener/forwardproxy/server.go:433) |
| A credential directory | static-inject's FileResolver refuses any key that leaves the directory (core/plugins/staticinject/resolver.go). Its key_by: host keys on pctx.Host, which can be host:port (plugin.go:202, 269). Its old sources require a bearer from the client (:189-191) and answer 401 for a missing file (:207-209). source: resolver (#2088) does neither. |
| The listener plan | config.ListenerPlan (core/config/listenerplan.go:20-51) feeds reserveListeners, reportListenFailure and agentop's port preflight |
| The moca channel | It is turned on by the environment only (cmd/cortex/vmcontrol.go:46-50) |
| Where tests run | The core module's CI runs go test ./... with no tags (ci.yaml:68). cmd/cortex tests run once per profile (ci.yaml:455-466), local included. |
| A loopback check | httpx.LoopbackHost (core/listener/httpx/loopback.go:18) |
| Where listener config lives | config.ListenerConfig (core/config/config.go:955) |
Profiles with static-inject |
full, fullcpex, lite, envoy, hostegress (scripts/profile-tags/profiles.go:85, plus #2085). Not local. |
Change
-
A tenant-listener identity source in the general core, package
core/listener/tenantlisten. Config:listener: roles: [forward] tenants: - name: alice addr: 127.0.0.1:47610 credentials_dir: /path/to/alice - name: bob addr: 127.0.0.1:47611 credentials_dir: /path/to/bob- For each entry, Cortex opens one listener and serves the forward proxy's handler on it, wrapped so that each request carries the tenant's
Binding. Add the tenant addresses toconfig.ListenerPlan, so the existing reservation, error report and port preflight see them, and a clash with another listener is refused. AdmitreturnsCaller{SessionID: "tenant-<name>", Subject: <name>, Claims: {"tenant": <name>}}. It removesProxy-Authorizationand the session headers (a local copy of thesession.*Headerconstants that vmcontrol strips. Do not import or move vmcontrol's unexported list), so headers never change the caller.- Because
Subjectis set,pctx.Identityis not nil (#2087). In this demo onlystatic-injectruns, so nothing reads it. The doc says thattokenexchange,tokenexchangeaiacandopawould take the subject from it. Refusalreturns its input unchanged, so the client gets Cortex's own shape, plugin headers included.cmd/cortexsetsConfig.SharedModewhenlistener.tenantsis not empty, so every shared-mode rule of #2087 applies: no session store, no session API, no transparent listener, loopback addresses, and403 no_bindingon the TCP forward proxy.- Start-up refuses each of these, with an error that names the setting:
- An
addrthat is not loopback. - Two entries with the same name or the same
addr. - A name that does not match
[a-z0-9-]+. - A
credentials_dirthat is not absolute or does not exist. listener.tenantsinenvoy-sidecarmode (config.Validate).listener.tenantstogether withMOCA_EGRESS_CONTROL_SOCK. One identity source at a time. This check is incmd/cortex, because the moca channel is set by the environment only.
- An
- For each entry, Cortex opens one listener and serves the forward proxy's handler on it, wrapped so that each request carries the tenant's
-
A directory resolver, registered as
credresolve.Register("tenant-dir", …). For a caller and a host, it reads the caller's tenant directory, with the same path rules asFileResolver:- A file named
<host>is a credential for port 443. A file named<host>:<port>is a credential for that port. Each file gives oneCredential{Name: <file name>, Port: <port>, PathPrefix: "/", Headers: [{Authorization, "Bearer <value>"}]}. The value is trimmed. - No file for the host returns an empty list with a TTL of 60 s, so the host stays an opaque tunnel. The process-wide cache of #2088 (
credresolve.Get) holds it.
- A file named
-
No moca names. The driver uses only
pipeline.Caller,pipeline.Binding,credresolveandConfig.SharedMode.cmd/cortexsetsSharedModefor it in the same places as for the moca driver (#2087 item 11). It imports nothing fromcore/listener/vmcontrolorcmd/cortex/vmcontrol*.go. -
The driver is compiled in every build and is inert when
listener.tenantsis empty. No preset sets it. -
A short doc,
docs/multi-tenant-demo.md:- Build
cmd/cortexwith thefullprofile (localhas nostatic-inject). - A config with two tenants, two credential directories,
static-injectwithsource: resolver,resolver: tenant-dir, andtls_bridgewith a CA from files (generate_cais refused in shared mode). The clients trust that CA. - two
HTTPS_PROXYvalues, and the commands that show each result in "Tests".
The doc says that the session store is off in this mode, so agentop shows nothing during the demo. The results show in the echoed headers.
- Build
Not in scope
- Real identity: OS users, Unix sockets with file permissions, mTLS client certificates. Each is a later identity source, if someone needs it.
- Grants,
Rebindand expiry (#2090). - Hot reload of
listener.tenants. Everylistenerfield needs a restart.
Tests
One end-to-end Go test in core/listener/tenantlisten. It imports core/plugins/staticinject directly, because the core module's CI runs with no tags. It builds the TLS bridge with a CA written to a temp dir, and a local TLS upstream (httptest) that echoes the request headers. The credential files are named 127.0.0.1:<upstream port>:
- A request through alice's address gets alice's credential, and one through bob's gets bob's. The host is the same.
- A host with no file in a tenant's directory stays an opaque tunnel: no interception and no credential.
- A client that sends a session header,
X-Forwarded-Useror its ownAuthorizationis still its listener's tenant. ItsAuthorizationis replaced when a credential applies, and passes unchanged when none applies. - Plain HTTP to a host with a credential:
403 plaintext_credential, in JSON. - A request on the TCP forward proxy:
403 no_binding. - Across tenants: alice and bob in parallel, many requests each. Every echoed header belongs to the right tenant.
- Each start-up refusal in item 1 fires once, with an error that names the setting.
- A guard test:
go list -deps ./core/listener/tenantlistencontains novmcontrolpackage.
Done when
- The test above passes in the core module's CI, with no moca code in the build.
- The doc's commands show two tenants on one laptop with one Cortex process.
- The driver needed no change to the moca driver. Any change to a seam is in the PR's description.
- 主要言語
- 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 件 ·