feat: Write one complete, asynchronous audit event per request through Binding.Record
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 6/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- go, json, linux
調査の方向性
Start from core/listener/vmcontrol/audit.go (the Event struct and AuditSink) and vmcontrol/handler.go where vmBinding.ServeHTTP and emit write today's lines, then tunnel.go for tunnelLog.close. Done means one complete moca-format event per admitted request, decrypted ones included, an async sink that never blocks the proxy, and the moca-conformance cases removed from known-failures.txt. It depends on #2087 and #2088 and needs the wider Binding design from #2042, so it is not a newcomer task.
索引モデルが issue の本文から書いたものです。
説明
Parent: #2042, step 6 of the build order (#2085 → #2087 → #2086 → #2088 → #2091 → #2089 → #2090). Needs #2087 (Binding, shared mode) and #2088 (credential names). Replaces #1482 and #1486, which are closed.
Problem
On a shared egress host, the audit event is the record of what each tenant did. moca's host agent forwards it to moca's control plane. It must be complete for every request, decrypted ones included, it must be in moca's exact format, and it must never slow the proxy down.
Today vmcontrol writes one audit line per request from its own wrapper. That wrapper never sees a decrypted request, and it does not know the credential, the dialed address or the byte counts. Its sink writes synchronously.
Shared mode (#2087) already turns off the session store, the session API and the other listeners on this role, so this issue is only about the audit event.
Shared contract
This issue adds the last method of Binding (#2042, "Shared contract"), and the Outcome type:
// Record receives the one terminal outcome of each admitted request.
Record(r *http.Request, o Outcome)
// core/pipeline
type Outcome struct {
Status int
Code string // the refusal code, "" when the request was not refused
Tunnel bool // an opaque CONNECT
Intercepted bool // a CONNECT that the TLS bridge opened
Credential string // the injected or revoked credential's name, "" when none
Revoked bool // the credential was revoked during the connection
Subject string // the credential's subject from the lookup, "" when none
DialAddr string // the checked address that was dialed, "" when none
BytesUp int64
BytesDown int64
}
Today
Read at Cortex main 7f3eec7 and moca main e464dd6 (2026-11-23).
| What | Where |
|---|---|
| The audit event, in moca's shape | vmcontrol.Event (core/listener/vmcontrol/audit.go:29-46): time, via, vm_id, sid, sub, host, dial_addr, method, path, status, bytes_up, bytes_down, credential, decision, dropped, coalesced |
| The sink | AuditSink interface{ Emit(Event) } (audit.go:49). cmd/cortex/vmcontrol_unix.go:28 uses vmcontrol.NewJSONSink(os.Stdout) (audit.go:63), which writes synchronously. There is no asynchronous sink. |
| Why synchronous is a problem | A stalled sink ties up a VM's 8 refusal slots, so over-cap connections close without a 429. Unregister waits for each in-flight request's line, so a stalled sink stalls Unregister (#1482's comment). moca uses NewAsyncSink(NewJSONSink(os.Stdout), 0). |
| Where lines are written today | vmBinding.ServeHTTP (vmcontrol/handler.go:189-223) → emit (:228-243): aborted, tunnel for a CONNECT, forward otherwise. chargeRequest (:82-95, request_cap) and refuseConn (:60-76, conn_cap). Nothing is written for a decrypted request. event() uses r.Host, which can carry a port (:247). moca's host has no port, is lower case and has no trailing dot (moca handler.go:115-141). |
| Byte counts | Counted for tunnels (sessionevent.TunnelClose, forwardproxy/transparent.go:373) and WebSockets (websocket.go:277, 482, 881). For forwarded requests only the response is counted (pctx.ResponseBytes through bodycount.Wrap, server.go:964-990, pipeline/context.go:326). |
| Paths that skip work when the store is off | recordTunnelClosed (transparent.go:370) and refuseMisdirected (tunnel.go:139) return early when s.Sessions == nil. Shared mode turns the store off. |
| Where a request ends | Tunnels: tunnelLog.close (tunnel.go:771-786). Plain requests: the end of serveOutbound. Decrypted requests: the end of the bridged handler. |
| The dial address | pctx.DialedAddr is set only for CONNECT tunnels and the transparent listener (tunnel.go:436, transparent.go:187). On a bound, intercepted connection, #2088 dials the checked address once and keeps it. |
conn_cap events in Cortex |
Combined by count: one event per 64 refusals (vmcontrol/registry.go:56, 271-280). moca combines them by time: at most one per second per VM. |
| moca's sink | A queue of 4096, a drop report every 10 s, a flush on close, and time stamped when the event is emitted, not when it is written (moca remote-worker/internal/egress/audit.go:99-202) |
| moca's decision names | tunnel, forward, destination_denied, destination_private, conn_cap, request_cap, no_binding, credential_unavailable, upstream_unreachable, bad_request, aborted, credential_injected, credential_revoked, plaintext_credential, upstream_unverified, misdirected_request, leaf_unavailable, audit_dropped (moca audit.go:13-34) |
The sub rule |
sub is present only on credential_injected, and on upstream_unreachable after an injection, where the token may have been sent. The suite checks it on every event it reads (moca remote-worker/egress/conformance/conformance.go:467, helpers at cases.go:1030-1042, doc.go). |
| Other rules the suite checks | Exactly one credential_injected event per request (cases.go:1152-1160). One aborted event for each live connection that Unregister ends, and nothing else on it (moca handler.go:191-202). No event for the CONNECT of an intercepted connection: only its requests get events, plus a handshake-time misdirected_request or leaf_unavailable (moca intercept.go:127-138). conn_cap events combined to at most one per second per VM, with at most 8 refusals per VM in flight (handler.go:27-36). Case audit_query_removed. |
| The reader | moca's host agent reads the unit's journal, keeps .via == "moca-egress", and posts the events unchanged (moca deploy/sbx/host-agent.sh:37-60, 806-807). moca's control plane does not store an event with a field it does not know, and the host agent does not send an event over 8 KiB (moca deploy/sbx/host-agent.sh:806-807, docs/specs/2026-11-08-sandbox-egress-records-design.md §3). moca closes its sink after the proxy closes (CloseAudit, moca audit.go:67-75). |
Change
- The core calls
Recordonce for each admitted request, when it ends, with anOutcome:- Tunnels: in
tunnelLog.close. Plain requests: at the end ofserveOutbound. Decrypted requests: at the end of the bridged handler. - These calls do not depend on the session store. They must not sit behind the
s.Sessions == nilreturns (transparent.go:370,tunnel.go:139). - A request that
Admitrefused gets noRecord, because the driver already wrote its line.
- Tunnels: in
- The
Outcomefields:Code: the refusal writer of #2086 stores the code of the refusal it wrote in the request context, and the core copies it. That covers every refusal site, thehttp.Errorsites included.Credential,Subject,Revoked: frompctx.SetCredential(#2088).DialAddr: for a tunnel,pctx.DialedAddr. For a decrypted request, the address that #2088's bound connection dialed. For a plain forwarded request, the address its dial used (httptrace.GotConn).BytesUp: count the request body, as moca does.BytesDown:pctx.ResponseBytes, as today. For tunnels, the existing counts.
vmBinding.Recordbuilds moca's event from the outcome, and emits it:- Drop the outcome when the binding is aborted: the wrapper writes the one
abortedline. - Drop the outcome of an intercepted CONNECT unless it has a
Code. Its requests get their own events. decision:Codewhen it is set, elsecredential_revokedwhenRevoked, elsecredential_injectedwhenCredentialis set, elsetunnelwhenTunnel, elseforward.sub:Subject, only oncredential_injected, and onupstream_unreachablewhenCredentialis set and notRevoked.credential: the name, never a value. It is also set oncredential_revoked.path:RedactPath, never on a CONNECT.host: without a port, lower case, no trailing dot, as moca's. Use the same rule in the wrapper's own lines.viastays"moca-egress". A change is moca's decision (D9 in #2042).- Exactly moca's field set, nothing more. An extra field makes moca drop the event with no error. A worker field (D6) waits for moca's control plane.
- Drop the outcome when the binding is aborted: the wrapper writes the one
vmBinding.ServeHTTPno longer writes thetunnelandforwardlines. It keeps theabortedline and the "binding closed"503line, which happen outside the core. Update the vmcontrol tests that expect the old lines (server_test.go,bridge_binding_test.go).conn_capevents by time: combine them to at most one event per second per VM, with acoalescedcount, as moca does. Keep at most 8 refusals per VM in flight.- An asynchronous sink,
vmcontrol.NewAsyncSink(inner AuditSink, size int), as moca's: a queue of 4096 by default,audit_droppedwith adroppedcount every 10 s, andtimestamped atEmit. A request and anUnregisternever wait for it.startVMControluses it.vmControlServer.Closecloses it after the forward proxy and the registry close, and the close flushes the queue. - The demo driver (#2091) gets an empty
Record.
Not in scope
- The session store, the session API and the other listeners on this role. Shared mode (#2087) turns them off.
- Recording for each subject, with an operator-only API. Later, if someone needs it.
- The host agent reading Cortex's unit name (D9, moca's work).
Tests
- The core with a test binding: exactly one
Recordfor a plain request, a CONNECT, and each decrypted request, with the rightOutcomefields. None for a request thatAdmitrefused. vmBinding.Record: one case for each decision name above, and thesubrule on every one. An aborted request writes onlyaborted. An intercepted CONNECT writes no line of its own.hosthas no port.- The core with shared mode on (no session store):
Recordstill runs for a tunnel and for a misdirected request. conn_cap: a burst of refusals in one second gives one event with the rightcoalescedcount.- A
credential_injectedevent hassub,credential,dial_addrand byte counts, and no credential value. The JSON has exactly moca's keys. Unregisterwith live connections: oneabortedevent for each, and nothing else on them.- A sink whose writer blocks: requests and
Unregistercomplete, andaudit_droppedreports the count. - The
moca-conformancejob (#2085): remove each case this issue makes pass fromknown-failures.txt, among them the credential cases that #2088 left on it because they wait for an audit event.
Done when
- Every request on a handed-over connection leaves exactly one complete audit event in moca's format, decrypted requests included.
- A slow journal cannot slow the proxy.
known-failures.txtlists no audit case and no credential case.
- 主要言語
- 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 件 ·