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 own rpm_signing_keys table, except that a key's name never changes, so the OpenPGP user ID built from it always matches it, and a key create takes no default: the first key becomes the default, and only a PATCH moves 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 422 with code invalid_signing_key, as S36 does. ADR-030 (!3768 (merged)) sets this rule, and S38 drops its create-time default key.
    • The routes check read_repository and create_repository on 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 a PATCH that carries signing_key_id or secondary_signing_key_id also checks create_repository on the namespace, even when the value is unchanged, as S17 does for upstream_repository_ids. Without it, the PATCH answers 403 to a caller who can read the namespace, and the masked 404 to 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 PATCH and a key delete take FOR NO KEY UPDATE on 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 503 with Retry-After at once.
    • A deleted repository keeps its keys selected until S20-A's purger removes its row. So the key DELETE answers 409 with code signing_key_in_use until then, and the key's repositories_count counts 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 404 even when the PATCH resends 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_version keep that path open with no backfill.
      • Bulk delete waits, with its two routes recorded (POST …/packages/bulk_delete and POST …/packages/{package_id}/versions/bulk_delete, as S37 has them for Go). S17 gets no bulk-delete change.
      • The in-process repomd.xml cache and the S05-B rate limit wait too.
      • Group, updateinfo and module metadata, and a slower filelists, move there from Out of scope.
    • An upload takes upload-session slots to cover a header's size, rounded up, without waiting. When the slots are not free, it answers 503 with Retry-After. When the cap holds too few besides the session's own, it answers 413.
    • A rebuild writes primary, filelists and other one 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_keys on the repository read path, for the key fingerprints in settings, and its invalid_signing_key row covers a namespace with no RPM key.
    • filelists and other take their package list from the new primary, not from the database, so the three files hold the same packages even when an upload or a delete lands during the rebuild. packages_digest hashes the list primary was 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. On rpm_packages that key also serves a repository delete's foreign-key check. The checksum index on rpm_versions covers deleted rows, for the rebuild's lookup by checksum.
  • 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 503 sooner, because it does not wait for slots. At the derived floor of two slots, an upload answers 503 while 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 primary back twice, once for filelists and once for other, and reads each version's file rows twice, for primary and filelists. The RPM plan's publish-lag run measures the time.
    • A rebuild stops without committing when a version it is adding gets deleted before filelists or other is written. The rebuild that the delete enqueued runs next.
    • Under a burst of key creates, a create answers 503 and 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_sessions set to 1 by hand, an upload holds the only slot, so its header never gets one and every RPM upload answers 413. 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 503 often, 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 name mutable with the same user ID rule, so after a rename its user ID no longer matches. Whether Debian makes name immutable 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_repository namespace-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_repository and create_repository on 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

Related to gitlab-org/gitlab#605699

Edited by Dzmitry (Dima) Meshcharakou

Merge request reports

Loading
Loading