Loading
docs(specs): add RPM key routes, settle slot use and record deferrals in S38
Summary
- Problem: S38 lets a repository rotate from key A to key B, but nothing in it can create key B. It left the signing-key routes to ADR-030 (its Open question 5). It also says bulk delete "follows S17" without listing any routes, and it charges an upload's header "size" to a budget that counts slots, not bytes. A rebuild writes its three metadata files at once, so it needs three upload-session slots, and a process with fewer than three never rebuilds.
- Impact: the RPM implementation plan cannot build key rotation without these routes, and its bulk-delete and upload steps would build on a guess. Users see nothing yet: RPM is not released.
- Change:
- S38 gets the RPM key resource and routes at
/api/v1/{slug}/rpm/signing_keys. They have the same shape and rules as Debian's in S36 (!3447 (merged)), over RPM's ownrpm_signing_keystable, except that a key'snamenever changes, so the OpenPGP user ID built from it always matches it, and a key create takes nodefault: the first key becomes the default, and only aPATCHmoves it. A new key,rpm.max_signing_keys_per_namespace, caps the keys at 20. Open question 5 goes. - A repository create never generates a key. With no RPM key in the namespace, it answers
422with codeinvalid_signing_key, as S36 does. ADR-030 (!3768 (merged)) sets this rule, and S38 drops its create-timedefaultkey. - The routes check
read_repositoryandcreate_repositoryon the namespace. A repository needs a key, so whoever can create repositories manages the keys they sign with: today every role reads keys, and only an Admin changes them. Selecting a key is key management on the namespace, as ADR-030 sets, so aPATCHthat carriessigning_key_idorsecondary_signing_key_idalso checkscreate_repositoryon the namespace, even when the value is unchanged, as S17 does forupstream_repository_ids. Without it, thePATCHanswers403to a caller who can read the namespace, and the masked404to one with only repository roles, as S09's denial mapping sets. S09 lists the RPM key routes and that check as namespace-scoped. Key permissions of their own are a Deferred row, for when a role needs to split the two. - A key create, a key
PATCHand a key delete takeFOR NO KEY UPDATEon the namespace row first. Uploads and repository writes do not wait on that lock, and a create generates its key before its transaction. So two creates in an empty namespace make one default, no create passes the cap, and no delete leaves keys with no default. A key delete that races a repository create or a key change is settled by the foreign key. - Generating a key is the costly part of a create, and S05-B leaves the management API without a rate limit. So a create checks its body, the cap and the name before it makes the key, and the transaction checks the cap and the name again. A process generates at most as many keys at once as half its CPUs, rounded down and never below one, and a create past that answers
503withRetry-Afterat once. - A deleted repository keeps its keys selected until S20-A's purger removes its row. So the key
DELETEanswers409with codesigning_key_in_useuntil then, and the key'srepositories_countcounts that repository. - The registry sends no notice of a key switch, which ADR-030 leaves to S38: the customer runs each rotation step and tells its own hosts.
- No route accepts or returns a private key. A key import and key permissions of their own each say they need an ADR-030 amendment first.
- The S09 criterion for namespace-scoped checks says a principal with only repository roles gets the masked 404, and the plan's Step 43 expects that
404even when thePATCHresends the stored keys. - S38 links ADR-030 by relative path, now that it is on
main. - S38 gets a Deferred section, as !3866 (merged) proposes for every spec. Each row says how we would add the feature and when:
- A rebuild renders every version. Merging new versions into the current files waits until a repository misses the 60-second target. The fixed file layout and
render_versionkeep that path open with no backfill. - Bulk delete waits, with its two routes recorded (
POST …/packages/bulk_deleteandPOST …/packages/{package_id}/versions/bulk_delete, as S37 has them for Go). S17 gets no bulk-delete change. - The in-process
repomd.xmlcache and the S05-B rate limit wait too. - Group,
updateinfoand module metadata, and a slowerfilelists, move there from Out of scope.
- A rebuild renders every version. Merging new versions into the current files waits until a repository misses the 60-second target. The fixed file layout and
- An upload takes upload-session slots to cover a header's size, rounded up, without waiting. When the slots are not free, it answers
503withRetry-After. When the cap holds too few besides the session's own, it answers413. - A rebuild writes
primary,filelistsandotherone after another through one blob session, so it takes one slot. Rebuilds hold at most half the slots, rounded down, and never fewer than one, so a rebuild fits any budget. From three slots up, running rebuilds still leave room for an upload. - S17 lists
rpm_signing_keyson the repository read path, for the key fingerprints insettings, and itsinvalid_signing_keyrow covers a namespace with no RPM key. filelistsandothertake their package list from the newprimary, not from the database, so the three files hold the same packages even when an upload or a delete lands during the rebuild.packages_digesthashes the listprimarywas written from.- S38's index table lists the two unique keys that the repository-id foreign keys reference, in the
(namespace_id, rpm_repository_id, id)order of the plan's Step 8, and S38's sentence on the parent key takes that order too. Onrpm_packagesthat key also serves a repository delete's foreign-key check. The checksum index onrpm_versionscovers deleted rows, for the rebuild's lookup by checksum.
- S38 gets the RPM key resource and routes at
- Downsides:
- A namespace that wants one key for Debian and RPM creates and rotates it twice. ADR-030 accepts that.
- Rendering every version costs more as a repository grows. The publish target now holds up to a size measured before GA, and the lag metric shows when a repository needs the merge.
- The first RPM repository of a namespace needs a key first. An Admin creates it at the key routes, then creates the repository.
- S36 (!3447 (merged)) still defines four signing-key permissions for Debian, so the two formats check different permissions until S36 follows or RPM splits its own later.
- On a busy registry, an upload with a large header gets a
503sooner, because it does not wait for slots. At the derived floor of two slots, an upload answers503while a rebuild runs. - A repository's Manager cannot rotate its keys. An Admin runs every rotation step.
- A key's name cannot be fixed after it is created. A new key and a rotation replace it.
- A rebuild reads its new
primaryback twice, once forfilelistsand once forother, and reads each version's file rows twice, forprimaryandfilelists. The RPM plan's publish-lag run measures the time. - A rebuild stops without committing when a version it is adding gets deleted before
filelistsorotheris written. The rebuild that the delete enqueued runs next. - Under a burst of key creates, a create answers
503and the client retries. Two creates that pass the first cap or name check together both make a key, and the one the transaction refuses made it for nothing.
Checklist
- Gaps: key import and private-key export stay out of scope, because ADR-030 leaves them out. Audit events for key changes wait for S21, like the other RPM audit events. With
storage.max_concurrent_upload_sessionsset to 1 by hand, an upload holds the only slot, so its header never gets one and every RPM upload answers413. The derived value is never below 2. Refusing 1 at startup would change a key every format shares, so it is not in this MR. - Least sure: the header slot rule. The upload already holds its session's slot when it learns the header's size. Waiting for more slots while holding one can deadlock under load, so it does not wait. If real packages hit the
503often, the next step is to let the header wait with a short timeout. - Compatibility: nothing breaks. RPM is a new format and none of this has shipped.
- Agreement:
- S36 (!3447 (merged)) adds four signing-key permissions to the same S09 lines. Whichever merges second rebases. Whether Debian reuses the repository permissions too is S36's call.
- S36 (!3447 (merged)) keeps a key's
namemutable with the same user ID rule, so after a rename its user ID no longer matches. Whether Debian makesnameimmutable too is S36's call. - S36 (!3447 (merged)) accepts
default?on a key create and does not say what it does. RPM drops it. Whether Debian drops it too is S36's call. - ADR-030 (!3768 (merged)) sets the per-format key tables this builds on, and the rule that a repository create never generates a key.
- ADR-021 already makes
create_repositorynamespace-only, so RPM needs nothing from !3853 (closed). - ADR-030 (!3768 (merged)) says keys add no permission, and that selecting a key is key management on the namespace. This MR checks
read_repositoryandcreate_repositoryon the namespace for both. - AppSec: no key route accepts or returns a private key, and only an Admin can create, change or delete a key, or change the keys a repository selects.
- Simplicity: I rejected one key route set for both formats, such as
/signing_keys?format=rpm. ADR-030 gives each format its own key table, and S36 already puts Debian's routes under/debian/.
Merge order
- ADR-030 merged in !3768 (merged), and this branch is rebased onto it.
- This MR and S36 (!3447 (merged)) merge in either order. The second one rebases on S09.
- !3743 (S39) and !3872 (merged) (ADR-020) also edit S09, in other sections, so they do not conflict with this MR.
- !3447 (merged), !3735 (merged), !3797 (merged) and !3831 (merged) also edit S17, in other sections, so they do not conflict with this MR.
- The RPM implementation plan (!3867 (merged)) is on
main. This MR changes lines in its Steps 43, 44 and 45. !4071 (merged) (Step 8) edits other lines of the plan and S38's index table, and the two merge cleanly in either order.
Related to gitlab-org/gitlab#605699
Edited by Dzmitry (Dima) Meshcharakou