Sentinel 開發日誌:被相信,而非被檢查
Sentinel Dev Diary: Believed, Not Checked
Sentinel 開發日誌記錄安全文件的設計缺口如何在實際執行時浮現:權限表未涵蓋 JetStream 所需的主題及收件匣,令訊息請求逾時。修正方案為各主體設定專屬收件匣前綴,並由同一函數生成權限與連線設定;能力檢查則有 read、claim、suspend 和 direct 四項,但沒有羣組映射。
Most entries so far have followed a build step. Step one was read against The Semantic Model, step four against the watchdog, step six against The Rules Engine. Each step had an owning document and an audit, and the entry was about what the audit found.
The Security Model, published here last Wednesday, has no step of its own. The Introduction says so on purpose:
Security is not a step. The subject layout and the publisher check land in step 3, bus credentials with the first driver host, and forward auth with the API when it exists. Deferring it to a step of its own is how it becomes a retrofit.
I still think that was right, but it meant no audit ever read the document whole. Step three's audit checked its six exit criteria, each a test that asserts a refusal, and stopped there. The rest of the document was built in pieces inside other steps, by work that was busy with something else, and its gaps were found whenever one of those pieces first ran for real.
The document saw this coming. Its exit criteria open with a warning:
Security properties are the ones most likely to be believed rather than checked, because nothing fails when they are absent.
In each finding below, a sentence read as complete and nothing failed until someone ran the real thing.
A table that times out
The published copy gives the bus permissions as a three-row table: what each principal may publish and what it may subscribe to. The host row grants publish on its own observation, availability, quarantine and command-result subjects, and subscribe on its commands and its assignment. The criterion that checks it is specific about how:
Asserted against a real server with the real permission set, because a permission file that was never exercised is a permission file that is probably wrong.
On 6 September the real credentials were minted from that table and run against a real broker. The table could not run the system.
The observation path is a JetStream stream, and the table only names plain NATS subjects. JetStream has subjects of its own. The core needs to publish on $JS.API.> to create the stream, bind its consumer and fetch, and on $JS.ACK.> to acknowledge what it has processed. Without the second, every message is redelivered forever. And anything doing request and reply needs an inbox for the reply to land in. The core needs one for every JetStream call. So does a host, for the acknowledgement the broker sends back on every observation it publishes. That last one was the part that hid.
A host holding the table's grants exactly was not refused. Its publishes timed out, silently, because the acknowledgement had nowhere to go. The core did no better without its JetStream grants, and the decision that added them puts it plainly:
A credential minted from the table alone connects and can do nothing - which is worse than one that cannot connect, because the failure is a stalled consumer rather than a startup error.
The open question it raised, OI-27, describes the result as a table that "reads complete and the fleet does not work".
The fix kept the document's narrowness where it could. Granting every principal _INBOX.> would have worked, and it would have let any host read every other host's replies. Instead each principal gets an inbox under its own prefix, and connects using it. A host that connects with another host's prefix gets no replies at all, and a test asserts that. The prefix is a constant in the code, and the permission set is generated from the same function the client connects with. They are not allowed to drift, because a mismatch shows up as a timeout and not a refusal: the request goes out, and the reply lands on a subject the client may not read.
The amendment landed on 14 September, and it was wrong in one place when first written. It gave hosts $JS.ACK.> as well, on the reasoning that anything touching a stream acknowledges. The generated permission set gave it only to the core, and the generated set was right. A host publishes into the stream and never consumes from it, so it has nothing to acknowledge. The document was corrected against the artefact, and now states the asymmetry outright, "because the obvious guess is the other one".
Four capabilities, mapped to nothing
The published copy, on what a person may do:
Capabilities, not roles. There are four, carried as a second header from the identity provider and mapped in the registry:
The four are read, claim, suspend and direct. On 9 September the capability check was built, and it had nothing to look the header up against. There was no capability file in the registry, no vocabulary that declared the four, and no document saying what was mapped to what.
Two readings fit the words, and they are different systems. The registry could map the identity provider's groups to capabilities. That would make who may do what a reviewable diff, the way band authorisation already is. Or the registry could just name the four, and the header would be the authority. The code took the second, because it builds the smaller thing. Nothing about it would need undoing if the first reading won: a mapping would sit in front of the check and resolve groups before the core saw them, and the core's side would not change. The decision recording that reading also pointed out it was no weaker than the alternative, because both trust the same header for the same reason:
so a registry lookup would be a lookup keyed on an unverified header either way. What the mapping would add is not verification but review
Review was worth having, so the question was whether to build it. On 14 September the clause was struck instead. The argument against it was already in the document, a few lines further down:
A per-point permission matrix is deliberately not built. A few thousand points maintained by one person would rot within a month and then be trusted anyway.
A group mapping is the same shape. It is a second place to maintain, it drifts from the identity provider, and then it is trusted anyway, which is worse than having nothing, because it looks like a control. So the header is now the authority on purpose, and the mapping went onto the document's list of things it deliberately does not do, with the condition that would bring it back. What a mapping would defend against is not a compromised proxy, which could forge either header. It is a misconfigured provider: someone added to the wrong group, and silently gaining direct over the physical plant with no diff anybody reviews. So the trigger is written against that. The question reopens when more than one person holds direct, or when the UI is published.
Building the mapping for direct alone was considered and not taken.
Forward auth with nothing to forward to
The published copy has people sign in through forward auth at the proxy: "The proxy terminates TLS, an identity provider authenticates the person, and the proxy injects the principal as a header that the core trusts." In mid-September, when the read surface was ready to route, the deploy host had no identity provider.
Waiting for one was tempting, and the decision of 17 September explains why it was worse. It would have left the routing, the network and the header handling all untested until the day someone was also debugging a new identity provider. So the surface was routed straight away, and the proxy strips both identity headers from every incoming request, unconditionally. Every request arrived with no principal and was refused, which is the document's "absent principal is a rejection, never a default" running on every request.
The surface is therefore reachable and answers nothing, which is the honest state of a system whose authentication has not been built.
The same decision named the trap for later. The strip has to come first and the authenticator after it, because the proxy copies the authenticator's answer over whatever the strip left. Any header the authenticator does not name passes straight through from the client. Add forward auth and name only the principal, and you have authenticated the caller and let them choose their own capabilities.
The identity provider was my call, and I made it the same day. It is a tinyauth, because it joins groups with a comma, which is exactly what the capability check splits on, and because the whole integration is labels on a router the repository already configures. Two things moved with it. The service had to read tinyauth's header names, since tinyauth cannot be told to emit Sentinel's, and the strip had to move to those names too. A strip still blanking the old headers while the service read the new ones would have let the real principal header arrive from the client, guarded only by the authenticator being in the chain.
Then the order. The proxy's README told whoever wired this up to put the authenticator before the strip. The decision written four lines away in another file said the opposite, and the two disagreed from the day they landed. The wrong one was in the file an operator would actually follow. Put the authenticator first and the strip erases its answer, so every request is refused. It fails closed, and a surface that refuses everyone looks like one that simply isn't wired up yet. Nothing had been deployed from it, because there had been no provider to wire. The order was measured on the running proxy, all four combinations, the README was corrected, and a test now asserts the order instead of a document describing it.
The first request that got through
Within the hour, the first authenticated request went through the staging proxy to the route that tells a caller who they are and what they may do. The capabilities it reported were:
["claim", "direct", "lldap_admin", "read", "suspend"]
lldap_admin is a group in my directory, not a capability, and there are four capabilities, not five. The route had reported every group in the provider's header as a capability. Authority was not affected, because lldap_admin grants nothing. The answer was still wrong, and a UI reading it to decide which controls to offer would have believed it.
Filtering out unknown names was the obvious fix, and it was turned down, because it would have deleted the only place a misspelled group shows up. The response now has two fields. capabilities holds only real capabilities and is closed, so a consumer may treat it as the whole list. groups holds what the provider sent. A misspelling becomes readable off one response: the group is in groups and not in capabilities, and that difference says it had no effect. That shape was mine too.
The one found last week
While The Security Model was being prepared for publication last week, one paragraph was flagged for a closer look. As published, it is headed:
Bands above
manualare unreachable from the API.
It goes on to list schedule, safety and interlock as reached only by a rule. The Command Plane ranks schedule below manual. Each sentence is true on its own. The bands above manual are safety and interlock, and schedule is reached only by a rule. Read together, they say schedule outranks manual. The paragraph also left out automation, which only a rule reaches too, and default, which only the registry writes.
The code was never confused. The API only accepts manual, and the rule loader accepts the four rule bands, which is what the other two documents already said in full. The wording dated from the import of the specification in August, and an earlier fix to the same paragraph, in October, had edited around it without noticing. It was filed as OI-198 on 17 November and resolved the same day. The canonical document now heads the paragraph "The API reaches manual and no other band" and names every band and who reaches it.
The published copy still reads the old way, and will. Parts of the specification go out as the September snapshot, edited for readability and never for meaning, and a heading that implies an order is a meaning question. So the fix lives in the canonical document, and this entry is where the difference is written down.
What running it found
Nothing was scheduled to read the security document against the code, so the first three were found the first time the real thing ran: credentials minted and run against a broker, a capability check that had to look something up, a read surface routed before a provider existed and the first real request through it. OI-198 was found by reading, but by a reading done for publication rather than as an audit.
The document's own exit criteria pushed that way. Every one of them asserts a refusal against something real: a real broker, a database role connecting as itself, a request with no header. The table that timed out was found because its criterion said to use a real server.
The missing step cost timing. The gaps surfaced inside whichever step happened to be nearby and were handled there. Every amendment here was approved by me, and two are recorded as my choice outright: the identity provider and the two-field answer. The smaller calls inside the work were the agent's, recorded as decisions in the register, in sessions I run and steer and whose every step I approved before it started. Most of these gaps were closed within a week of being found. The heading stood for eleven weeks, from the import in August until someone read it closely enough to publish it.
This Wednesday - Observability. The specification's tenth part: what signals every mechanism must expose.
Next Monday - the Dev Diary. The latest on where the specification and the build disagree as the system takes shape, and which of the two had to change.
Start of the diary: Four Registers and a Drift Check. Why the registers exist at all, and the one rule about where a sentence is allowed to live.
來源:DEV Community · dev.to