Files
rustfs/.github/workflows
唐小鸭 2fd613157b refactor(sse): extract SSE into the rustfs-sse crate and layer it (#9574)
* refactor(sse): extract server-side encryption into rustfs-sse crate

Move the SSE-S3 / SSE-KMS / SSE-C key resolution, metadata and authorization logic out of rustfs/src/storage/sse.rs into a new crates/sse (rustfs-sse) so its outward references are explicit.

The crate depends only on rustfs-config, rustfs-kms, rustfs-policy, rustfs-s3-types and rustfs-utils. It does not reach the storage engine, IAM, the gateway or the server binary; scripts/check_architecture_migration_rules.sh now pins that dependency set.

Everything the crate needs from the running server arrives through the SseHost port (current KMS service, KMS manager state, bucket default encryption, per-key authorization). The host is an explicit parameter on every entry point that needs it rather than a global, so a missing installation cannot silently fall back to the local key provider.

The crate reports failures as SseError, which carries the S3 error code. The KMS-to-S3 error mapping moves with it and rustfs/src/error.rs reuses it, so response codes and messages are unchanged. The source of an SSE-internal error is no longer wrapped in StorageError::Io.

rustfs/src/storage/sse.rs stays as the adapter: it implements the host, binds the entry points to this server and converts back to ApiError, and keeps the conversions that cross the engine boundary (read-side resolver, multipart completion gate, reader error mapping).

Tests split with the code. Four provider round-trips over rio streams move to storage/sse_test.rs because the crate does not depend on rio. Cross-crate test seams sit behind the test-util feature, enabled only from the rustfs dev-dependencies. The rio-v2 CI lane and cache warm-up now include -p rustfs-sse so the rio-v2-only SSE tests keep running.

* refactor(sse): remove three unused configuration helpers

get_sse_type, sse_configuration_to_metadata and SseTypeV2::to_metadata have no caller in the crate, its tests, or the server. All three carried #[allow(unused)], which is what kept the compiler from reporting them.

* refactor(sse): split the crate root into core and kms modules

Move every item of the single-file crate into modules without changing
any of them:

- core/s3: what S3 defines for SSE (request headers, scheme selection,
  SSE-C validation, key-policy authorization)
- core/keying: how RustFS seals and records object keys (key material,
  direct and object-key forms, stored metadata, encryption context)
- core/{request,write,read,rewrap,audit}: the per-request entry points
- kms: data-key providers (KMS-backed, local master key, MinIO
  builtin-KMS ciphertext) and the provider registry

The rio-v2 only modules carry the feature gate at module level instead
of on each item. Inline tests move to a crate-level tests module. The
public surface is unchanged and is now an explicit re-export list in
lib.rs; visibility is otherwise tightened to pub(crate) or private.

Documentation that cited the old file now points at the module that
holds the symbol.

* refactor(sse): add an explicit startup step for process-level state

Give rustfs-sse one entry point, `startup::init`, for the state that is
fixed for the lifetime of the process. The server calls it where it used
to log the SSE-KMS key policy mode.

- Resolve the key policy enforcement switch once and log its mode.
- Check `RUSTFS_SSE_S3_MASTER_KEY` at startup and report it through the
  `sse_local_master_key` event as `loaded`, `not_set`, or `invalid`. An
  unusable value is logged as an error; startup still succeeds and
  requests fail exactly as before.
- Return a `StartupReport` so the caller can see both results. Repeated
  calls return the first report without logging again.

Anything that follows the KMS service state stays resolved per request:
the service follows configuration and can be started, restarted, or
stopped from the admin API while the process runs.

`get_local_sse_dek_provider` becomes synchronous, since it never awaited
anything. The "Using RUSTFS_SSE_S3_MASTER_KEY for SSE-S3" line that was
logged when the key was first used is replaced by the startup event.

* refactor(sse): split the write path into S3 scheme and keying mode

The write entry points mixed two questions: which SSE scheme S3 asks for,
and how this build forms and stores the object key. Give each a home.

- `core/s3/scheme.rs` gains `resolve_write_scheme`, which validates the
  headers and resolves the request, then the bucket default, to a
  `WriteScheme`. PutObject and CreateMultipartUpload now share it; the
  second copy of that decision (`SseTypeV2`,
  `prepare_sse_configuration_v2`) is removed.
- `core/keying/` gains one constructor per key source
  (`new_key_under_customer_key`, `new_session_key_under_customer_key`,
  `new_key_under_data_key`) in each mode. `keying/mod.rs` is the only
  place that says which mode a build writes.
- `core/write.rs` only orders the steps and no longer carries any
  `rio-v2` conditional compilation.

No behavior change. A multipart session still validates the SSE-C key at
creation only in the mode that seals the session key under it.

`SseTypeV2` leaves the public surface; nothing outside the crate used it.

* refactor(sse): split the read path into S3 scheme and keying mode

The read entry points decided the scheme, authorized the key, and
recovered the object key in one function, with the SSE-C preamble and
the managed key resolution written out twice. Separate the steps.

- `core/keying/stored.rs` (new) recognizes how a stored object was keyed
  (`recognize_stored_managed_key`) and recovers its key
  (`open_under_customer_key`, `open_under_stored_data_key`). The unwrap
  body moves there unchanged.
- `core/s3/ssec.rs` gains `require_matching_ssec_key` and
  `stored_ssec_algorithm`, shared by the unwrap and the response-header
  paths.
- `core/read.rs` orders the steps: recognize, name the key, authorize,
  recover. Both read entry points resolve the key through one helper, so
  authorization and the response header cannot name different keys.
- `core/keying/` no longer imports from `core/s3/`: the request check
  `reject_kms_context_location_override` moves to `core/s3/headers.rs`,
  and the legacy SSE-C nonce hashes with `md5` directly.

`rio-v2` conditional compilation is now confined to `core/keying/` and
`kms/`. No behavior change: the order of checks on a read is preserved.

* docs(sse): describe the module layout and its layer rules

Record in the crate instructions what the split settled: where startup
state, the entry points, the S3 layer, the keying layer, and the
data-key providers live, and the rules that keep them apart.

- `core/keying/` never imports from `core/s3/`; `core/s3/` reads stored
  metadata only through `core/keying/metadata.rs`.
- `rio-v2` conditional compilation stays under `core/keying/` and `kms/`.
- A new stored format is added under `core/keying/` without changes
  under `core/s3/`.

* refactor(sse): let each keying mode own its stored record

One function wrote the stored metadata of every keying mode, and one
function read it back, each switching on the mode and the build inline.
Give a mode both directions of its own record instead.

- `core/keying/direct.rs` records and reads the Direct record
  (`record_customer_key_nonce`, `record_wrapped_data_key`,
  `read_wrapped_data_key`).
- `core/keying/object.rs` records and reads the sealed-key record in
  MinIO's slots (`record_sealed_customer_key`,
  `record_data_key_in_minio_slots`, `read_sealed_data_key`).
- `encryption_material_to_metadata` records the scheme and hands the key
  to the mode that formed it.
- `core/keying/stored.rs` reads in three named steps: the recognition
  order of the modes (`read_stored_data_key`), the choice of the
  provider that unwraps the data key (`unwrap_stored_data_key`), and the
  opening of the object key. A stored key carries its mode as
  `StoredKeyMode` rather than as an optional sealed key.

No behavior change. The stored metadata is identical for every
combination of scheme, mode, sealed key, key id, context, and size in
both builds, and the order of the read-side failures is preserved.

* test(sse): add a black-box suite that compares two server binaries

Unit tests cannot show that moving SSE into its own crate left what a
client sees, and what lands on disk, unchanged. This suite drives a real
server process and can compare two binaries.

- 30 cases over six process configurations: no key source, a loaded and
  an invalid local master key, the Local KMS backend with per-key
  authorization off and enforced. They cover round trips and response
  headers, bucket default encryption, CopyObject, multipart uploads,
  run-time KMS stop and start, malformed requests and authorization.
- Every HTTP exchange inside a case is recorded as an observation:
  status, error code and message, SSE headers, response header names,
  body hash, and the encryption metadata key names stored for the
  object. `diff` compares two runs field by field against a closed list
  of accepted differences.
- `cross` has one binary write every stored form and another read the
  same data directory.
- A registered binary is pinned by SHA-256, and a run fails when the
  stored form does not match the build the binary was registered as.

Results for this branch against its base, default build: 93 verdicts and
252 exchanges equal, no blocking difference; the only accepted one is the
new `sse_local_master_key` startup event. Cross reads pass in both
directions, 42 objects each.

The suite also pins two behaviors that predate this branch. Multipart
responses for SSE-C uploads carry `x-amz-server-side-encryption: AES256`
besides the customer-key headers; MP-03 records that as a known deviation.
A `rio-v2` build cannot read back encrypted objects of roughly 64 to
128 KiB, or of 3 MiB and more, so under that build the comparison only
shows that both binaries fail the same cases.

* test(sse): stop the black-box suite from overlooking two regressions

The known-deviation marker in MP-03 accepted any SSE headers that
contained the expected ones, so an unrelated extra header, the raw
customer key included, was still reported as the known deviation. It now
tolerates exactly the one documented difference and fails on anything
else.

The observation of a result document kept only the set of element names.
A wrong part size, a missing part or reordered parts in a listing changed
nothing, so a comparison between two binaries could not see them. It now
keeps every leaf with its value in document order and reduces only the
elements that vary between runs: upload ids, timestamps, markers and
ETags of encrypted objects.

`suite.py selftest` checks both offline, together with the rules of the
comparison. Against the previous observation code it fails on the three
listing cases. The comparison of this branch with its base still shows no
blocking difference in either build.

* test(sse): prepare the black-box suite for P1 cases and more backends

The suite could only run P0 cases on six built-in configurations with one
shared site each. The next groups of cases need more than that:

- `run --level p0|p1|all`, and a `skip` verdict for a case the backend's
  capability table rules out.
- `register_config` lets a case module add a process configuration with
  what it needs before the process starts, once it answers, and at the
  end of the run. The two Local KMS configurations now use the same
  mechanism instead of special cases in the driver.
- `isolated` cases get a site of their own on a fresh data directory and
  may restart it with another configuration or environment.
- Exchange hooks and post-run checks, for modules that keep everything a
  run saw and judge it as a whole.
- Case modules are discovered by file name, and the binary registry can
  be shared between state directories.

The P0 results and the comparison with the base are unchanged.

* test(sse): cover run-time state, authorization, leaks and stored form

Three groups of cases are added to the black-box suite, with what they
need to run.

Run-time state (14 cases). A write follows the state the process is in
now, a read follows what the object recorded: the master key across
restarts, KMS stopped, started and configured at run time, a deployment
moving between key sources, a changed backend, and keys disabled,
destroyed and rotated. New configurations: Local KMS with a master key,
Vault Transit, Vault KV2 and the Static backend. Vault is a development
server started by the driver with a token generated per run; when it
cannot be started its cases report an environment error.

Authorization and leaks (18 cases). Per-key authorization on bucket
defaults, both ends of a copy, multipart uploads, every read entry point,
anonymous access, internal work and audit entries. Every exchange of a
run is archived with secrets redacted, and four checks over the whole run
look for key material in responses and server logs, for internal headers,
and for unexpected internal-error messages.

Stored form (8 cases). What an encrypted object looks like on disk is
read with the repository's `dump_fileinfo` tool and held to one manifest
per build: every metadata key with its exact value or, for random values,
its shape. The cases also search the drives for plaintext, customer keys
and unwrapped data keys. `cross` records the stored form of everything
the writer stored.

Compared with the base on the default build, all levels: 382 verdicts and
887 exchanges equal, no blocking difference; 86 case runs pass on each
side. Three cases report a known deviation that predates this branch: the
multipart SSE-C response header (MP-03), an SSE-KMS write that turns from
400 into 503 after a refused KMS start (KS-09), and a read by a caller
without a grant that reveals whether the key was destroyed or KMS is
stopped (SEC-05). The manifests were written from the base binaries and
the branch stores the same form in both builds.

Each group was shown to fail when it should: Vault unavailable gives
environment errors, the two authorization configurations swapped fail the
matrix both ways, a planted key is found in a log and in a response, a
`rio-v2` binary registered as the default build fails the manifest and
the build check.

* test(sse): expect only customer-key headers on SSE-C multipart replies

MP-03 recorded the extra `x-amz-server-side-encryption: AES256` header on
SSE-C CreateMultipartUpload and CompleteMultipartUpload responses as a
known deviation. The header is gone on main, so the case now checks the
intended headers directly; left as a marker it would report the deviation
as fixed and fail the run.

On both builds the base and this branch pass the case.

* test(sse): take the black-box suite out of this repository

The suite under `scripts/test/sse_blackbox/` drives a server binary from
the outside and compares two binaries. It is a product-level test
harness, not part of the server's own tests, and belongs with the other
external test suites rather than in this repository.

The directory is removed, with the paragraph in `crates/sse/AGENTS.md`
that pointed to it. No server code changes.

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Hauser Zhi <housemecn@gmail.com>
2026-11-25 06:19:21 +08:00
..

Workflow runners: what is billed and where a job belongs

Use this when: adding a job, changing a runs-on, moving a lane between runner pools, or deciding whether a new check is worth its runner cost. Source of truth: runs-on in each workflow file for current placement; .github/actionlint.yaml for the declared self-hosted labels; the organisation's Settings → Billing → Usage page for what is actually charged; docs/testing/ci-gates.md for which checks block a merge (that does not change when a runner changes).

Billing facts

This repository is public. For a public repository, GitHub's standard hosted runners (ubuntu-latest, windows-latest, macos-latest) cost nothing and have no minute cap, whatever plan the organisation is on. GitHub bills only two things: larger hosted runners, including the macos-latest-xlarge release lane used here, and standard runners in private repositories.

Every other label in this repository is capacity RustFS pays for. ARC pods and lab machines accrue cost while the machine exists. A Ubicloud label is metered for the minutes a job holds its VM:

Label Paid by What it is Use it for
ubuntu-latest nobody GitHub-hosted, Ubuntu 24.04, 4 vCPU, 16 GB RAM, about 14 GB of free disk. Ships a C toolchain, docker, gh, curl, wget, jq, Python. Can mount tmpfs and loop devices; io_uring works the default for every job
windows-latest, macos-latest nobody GitHub-hosted standard runners Windows and macOS targets
macos-latest-xlarge RustFS GitHub-hosted larger Apple Silicon runner macOS release builds, deferred until Linux acceptance for candidates
sm-standard-2 RustFS ARC pod, Ubuntu 24.04, minimal image: no gh, no C toolchain; Docker only on the dind- label only a job that a hosted runner cannot run (see the placement rule)
sm-standard-4 RustFS ARC pod, Ubuntu 24.04, 14 CPUs and 28 GB (the label is not the core count), large disk workspace-scale Cargo builds
ubicloud-standard-16-arm RustFS Ubicloud VM, alias of ubicloud-standard-16-arm-ubuntu-2404: Ubuntu 24.04 arm64, 16 vCPU, 48 GB, 300 GB disk. Reached through the build.yml matrix, so actionlint.yaml does not list it native aarch64 release builds (linux-aarch64-musl, linux-aarch64-gnu)
dind-sm-standard-2 RustFS ARC pod with Docker-in-Docker Docker workloads with a measured resource or environment requirement beyond the hosted runner
smoke-testing, pf-testing RustFS long-lived lab machines the packaged functional chain and performance suites

The self-hosted pods and the hosted image are both Ubuntu 24.04, so a binary built on one runs on the other; ci.yml builds the debug binary on sm-standard-4 and runs it on both pools.

Placement rule

A job runs on ubuntu-latest unless it has one of these reasons, and the reason goes in a comment next to its runs-on:

  1. Disk. It restores or produces the workspace target/: cargo build or cargo test with --all-targets, cargo nextest run --all, or any reader of the ci-dev / ci-feat-* caches. The workspace test build leaves about 64 GB in target/; a hosted runner has about 14 GB.
  2. Critical-path CPU. It is a build that several downstream lanes wait on and would blow its timeout at 4 vCPU (build-rustfs-debug-binary gates the e2e and s3-tests lanes).
  3. Hardware or environment. Native aarch64 or access to the lab machines. Docker alone is not a reason: hosted Ubuntu ships Docker and supports the QEMU and Buildx setup actions.
  4. Cache ownership. It reads a rust-cache key that a self-hosted job writes (see the cache rule below).

Jobs that do only the following have no reason to be self-hosted: shell or Python scripts, cargo fmt, cargo deny, typos, actionlint, API calls (gh, dependency review, issue and stale bots, CLA checks), downloading an artifact and running a prebuilt binary, or a cargo build -p rustfs with its own cache key. e2e-distributed.yml and e2e-upgrade.yml build the server and the e2e_test harness on ubuntu-latest inside their budgets, so "it compiles something" alone is not a reason.

The functional chain's prepare and complete-chain jobs, the performance runner availability check, and runner hygiene use ubuntu-latest: they inspect APIs or artifacts, not the lab hosts. The actual functional and performance suites remain on their lab runners. Functional-chain health collection uses ubuntu-latest so a lab outage cannot also stop its independent monitor. Docker image packaging also uses ubuntu-latest for both musl and glibc variants; it wraps verified candidate binaries rather than compiling the workspace, and still sets up QEMU and Buildx explicitly.

Moving these jobs off AKS reduces capacity demand, not necessarily the Azure bill immediately. VM costs fall only when nodes scale down or smaller capacity replaces them.

A hosted runner is also the only choice for a few things the pods cannot do: mount -o loop and mount -t tmpfs fail inside the ARC pods, and a container runtime cannot guarantee that io_uring_setup is allowed. uring-integration and e2e-distributed are on ubuntu-latest for that reason, not for cost.

Cache rule

Swatinem/rust-cache builds its key from the OS, architecture, toolchain and lockfile. It does not include the runner label or image, so a cache written on an sm-standard-4 pod and one written on ubuntu-latest would overwrite each other under the same shared-key.

  • Every shared-key has exactly one writer. cache-warm.yml owns ci-dev, ci-feat-rio, ci-feat-proto and ci-uring; every other ./.github/actions/setup call states cache-save-if explicitly, and scripts/security/check_cache_save_if.sh fails the build when one does not.
  • The ci-dev key ends in a digest of warm-ci-dev's build commands. Changing what that job warms therefore needs a new key, or readers keep restoring the old artifacts: scripts/ci_gate.py --check-workflow prints the key the commands require and fails until the writer and every reader in ci.yml and reference-parity.yml name it.
  • All readers of a key run on the same image as its writer. Keys that live on hosted runners say so in their name (ci-uring is warmed on ubuntu-latest; ci-e2e-distributed-hosted, e2e-upgrade-server-hosted, e2e-upgrade-tests-hosted).
  • Moving a job between pools therefore means renaming its key. The new key is empty until a run from main (a scheduled run, or a manual dispatch of that workflow from main) saves it; until then that lane does a cold build. The build.yml aarch64 release legs append -ubicloud-arm for this reason. cache-warm.yml does not write those keys.
  • CARGO_BUILD_JOBS and every other CARGO*, CC*, CFLAGS*, CXX*, CMAKE* and RUST* variable is hashed into the key. ci.yml sets CARGO_BUILD_JOBS at step level for that reason; promoting it to job level rotates the key for every lane that shares it.

Where self-hosted minutes leak

These are the patterns that have cost real money here without validating anything more:

  • An if: always() summary or alert job on a self-hosted label inside a workflow_run-triggered workflow. The upstream workflow completes many times a day, the real jobs skip, and the summary still starts a pod each time. Gate it on the upstream job having run, and keep it on ubuntu-latest.
  • Per-push workflows on main. A merge triggers cache warming and a ci.yml run, which validates the merged tree in full unless a merge-queue run already validated that tree; build.yml development builds are scheduled or manual; with tens of merges a day that is as much self-hosted time as all pull requests together. Anything that does not verify the merged tree itself belongs on a schedule or behind a paths filter.
  • apt-get install of tools the hosted image already ships. It is only needed on the minimal pod images.
  • A throttled CARGO_BUILD_JOBS on a 14-CPU pod. The limit exists for link-storm reasons documented in ci.yml; measure before raising it, and measure before lowering it further.
  • Tiny jobs on ARC pods. Each one pays roughly a minute of pod start-up before its first step; a compile-free job that takes ten seconds costs more to schedule than to run.

Measuring a run

To see which pool each job of a run used and for how long:

gh api "repos/rustfs/rustfs/actions/runs/<run_id>/jobs?per_page=100" \
  --jq '.jobs[] | "\(.conclusion)\t\(.labels | join(","))\t\(.started_at)\t\(.completed_at)\t\(.name)"'

Rows using macos-latest-xlarge or a label starting with sm-, dind-, ubicloud-, smoke- or pf- use paid capacity. At the October 2026 review, a full pull-request run of ci.yml spent about 150 self-hosted minutes, a third of it in jobs that never compiled; treat that as the scale of what a placement mistake costs, not as a current figure.

Checklist for a new or moved job

  • runs-on is a literal label. A new self-hosted label is declared in .github/actionlint.yaml in the same change (.github/AGENTS.md).
  • The job declares timeout-minutes (scripts/security/check_job_timeouts.sh).
  • actionlint reports nothing.
  • A self-hosted runs-on carries a comment naming its reason from the placement rule.
  • Every ./.github/actions/setup call states cache-save-if, and a key read from one pool is not written from the other.
  • Moving a job does not change its check name, so the main ruleset and docs/testing/ci-gates.md stay as they are; renaming it does, and then that document's change checklist applies.

Release stages

The candidate release pipeline builds Linux first and defers paid desktop capacity until acceptance. The daily build.yml schedule selects Linux; the Sunday 16:17 UTC schedule selects macOS and Windows. Manual dispatch can still select any platform list. All six platforms remain required before publication. The pipeline records and promotes the exact tested bytes. Builder workflows have no public-release credentials. Keep periodic development builds, PR verification and field-test chains separate when their contracts differ; do not re-enable disabled workflows as part of a source-file migration.

Larger runners remain billed for public repositories; see GitHub runner billing. Actual spending comes from organization billing, not runner labels or an estimated build duration.