Repository navigation
nix: shorten get-missing-paths and push audits - #40
Merged
Merged
Conversation
Resolve the cache, refresh retention, and read both the published and the upstream membership of the requested hashes in a single statement. Previously the handler looked the cache up, then ran the refresh and membership statement, then asked upstream_paths about the absent hashes whenever upstreams were configured. Each was its own pool checkout and round trip to a database about 2 ms away, which is most of what this endpoint costs. Authorization used to sit between the lookup and the refresh, and the refresh is a write. The statement therefore receives the caller's push scope, computed by authz::authorize for the named cache without an ID and for each cache ID the token is granted, and neither reads nor refreshes paths outside it. The handler still authorizes against the resolved cache afterwards, so an unknown cache, another org's cache, and a cache without the Nix protocol stay 404 ahead of a scope failure, which stays 403. The upstream lookup is gated on a parameter-only condition, so without configured upstreams it is never started. With them it now probes all requested hashes rather than only the absent ones; the response is unchanged because published membership is applied first.
Record a Nix write endpoint's audit row as tracked background work instead of awaiting the insert before returning the response. Previously every authorized push request, from get-missing-paths to the upload and push-job routes, paid one more pool checkout and round trip to the database after its handler had already decided the answer. The insert runs on the state's task tracker, so a graceful shutdown still waits for it before closing SQL. What changes is durability: a response used to imply its audit row was written, and a crash between the response and the insert now loses that row. Rows may also commit in a different order than their requests completed. A failed insert is logged and ignored, as before. The refusal of a token without push permission stays awaited. It is the one row here that records an attempt to exceed a credential's permissions, and it is off the hot path. Tests that read audit_logs after a response now drain background work first, and the inline batch test selects its endpoint's row rather than assuming it is the newest.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.