mirror of
https://github.com/rustfs/rustfs.git
synced 2026-11-19 14:32:28 +00:00
Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4a1ce44a37 | |||
| 55be4e3f79 | |||
| 5be4ef65e8 | |||
| ce20ed4a4b | |||
| 24f3e783c2 | |||
| 583df55d90 | |||
| 670ae01f7a | |||
| 3a1f0c09b3 | |||
| eed50fc5ff | |||
| e462fafb65 | |||
| 9c0bc265c3 | |||
| 74bf3ca5fa | |||
| 31c4f4a7ff | |||
| 3fb8d861f0 | |||
| 4b386794e1 | |||
| 23a2593aac | |||
| 7b1befa6f9 | |||
| 2f3359df69 | |||
| ea522c18b6 | |||
| 9f13eb22a5 | |||
| fec2d4bb4b | |||
| 42a1417ed0 | |||
| 7b7f96924b | |||
| a3d6b59d03 | |||
| 924eb06968 | |||
| 5a44944095 | |||
| 4c869cd08c |
@@ -103,8 +103,6 @@ script-tests: ## Run shell script tests
|
||||
$(RUSTFS_PYTHON_BIN) ./scripts/test_retain_validation_evidence.py
|
||||
$(RUSTFS_PYTHON_BIN) ./scripts/test_ci_timing_report.py
|
||||
$(RUSTFS_PYTHON_BIN) ./scripts/test_junit_diff.py
|
||||
$(RUSTFS_PYTHON_BIN) ./scripts/test_dual_stack.py
|
||||
$(RUSTFS_PYTHON_BIN) ./scripts/test_mint_stack_diff.py
|
||||
$(RUSTFS_PYTHON_BIN) ./scripts/check_conformance_rulings.py --self-test
|
||||
$(RUSTFS_PYTHON_BIN) ./scripts/compat_matrix_report.py --self-test
|
||||
$(RUSTFS_PYTHON_BIN) ./scripts/s3-tests/test_report_compat.py
|
||||
|
||||
@@ -723,9 +723,8 @@ test-group = 'ecstore-serial-flaky'
|
||||
# fixture as the existing smoke modules.
|
||||
#
|
||||
# Dual-stack differential (rustfs/backlog#2740): `dual_stack_differential::`
|
||||
# starts two single-node servers from the same binary, one per
|
||||
# RUSTFS_S3_STACK value, on random ports with isolated temp dirs, and runs one
|
||||
# SDK script covering every operation of `impl S3 for FS` against both. Its
|
||||
# starts two single-node servers on random ports with isolated temp
|
||||
# dirs, and runs one SDK script covering every S3 operation against both. Its
|
||||
# comparator unit tests need no server. It meets the admission criteria
|
||||
# unchanged; the module clause admits a new differential test without another
|
||||
# filter edit.
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
# Adding a target is one more [[targets]] table, for example:
|
||||
#
|
||||
# [[targets]]
|
||||
# name = "candidate-gateway"
|
||||
# name = "candidate-tuned"
|
||||
# binary = "candidate"
|
||||
# env = { RUSTFS_S3_STACK = "gateway" }
|
||||
# env = { RUSTFS_EXAMPLE_SETTING = "on" }
|
||||
|
||||
schema = 1
|
||||
|
||||
|
||||
@@ -28,8 +28,6 @@ rustfs/src/app/storage_api.rs
|
||||
rustfs/src/admin/router.rs
|
||||
rustfs/src/app/metadata_route.rs
|
||||
rustfs/src/server/http.rs
|
||||
rustfs/src/server/layer.rs
|
||||
rustfs/src/server/hybrid.rs
|
||||
rustfs/src/protocols/client.rs
|
||||
|
||||
# e2e oracle: the test target that verifies S3 behaviour against s3s
|
||||
|
||||
@@ -13,6 +13,6 @@
|
||||
# s3_error_lines lines holding s3_error!, same scope, minus those the script
|
||||
# header's rule clears (rustfs_s3_types's macro); fails closed
|
||||
# ecstore_files Rust files referencing s3s paths under crates/ecstore/src
|
||||
files=63
|
||||
s3_error_lines=209
|
||||
files=50
|
||||
s3_error_lines=103
|
||||
ecstore_files=0
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
# Copyright 2026 RustFS Team
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
name: Both-stack leg
|
||||
description: Prove which S3 stack one e2e leg's servers selected and upload the leg for the summary (call with if always)
|
||||
|
||||
inputs:
|
||||
profile:
|
||||
description: The nextest profile the leg ran
|
||||
required: true
|
||||
stack:
|
||||
description: The stack the leg requested, legacy or gateway
|
||||
required: true
|
||||
logs:
|
||||
description: Directory or file holding the servers' output
|
||||
required: true
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Prove which stack the servers selected
|
||||
shell: bash
|
||||
env:
|
||||
PROFILE: ${{ inputs.profile }}
|
||||
STACK: ${{ inputs.stack }}
|
||||
LOGS: ${{ inputs.logs }}
|
||||
run: |
|
||||
# Outside the workspace: e2e_binary.py refuses a run whose source tree changed.
|
||||
mkdir -p "$RUNNER_TEMP/leg"
|
||||
junit="target/nextest/${PROFILE}/junit.xml"
|
||||
if [ -s "$junit" ]; then cp "$junit" "$RUNNER_TEMP/leg/junit.xml"; fi
|
||||
# A gateway leg stopped by its preflight has no output; the preflight's stack.json stays.
|
||||
if [ -e "$LOGS" ]; then python3 scripts/dual_stack.py stack --expect "$STACK" --out "$RUNNER_TEMP/leg/stack.json" "$LOGS"; fi
|
||||
|
||||
- name: Upload the leg
|
||||
if: always()
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: dual-stack-leg-${{ inputs.profile }}-${{ inputs.stack }}
|
||||
overwrite: true
|
||||
path: ${{ runner.temp }}/leg
|
||||
if-no-files-found: warn
|
||||
retention-days: 7
|
||||
@@ -1,56 +0,0 @@
|
||||
# Copyright 2026 RustFS Team
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
name: Both-stack summary
|
||||
description: Diff the legacy and gateway legs of this run (scripts/junit_diff.py) and upload one dated summary
|
||||
|
||||
inputs:
|
||||
profiles:
|
||||
description: Comma-separated nextest profiles whose two legs this run uploaded
|
||||
required: true
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Download the legs
|
||||
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
||||
with:
|
||||
pattern: dual-stack-leg-*
|
||||
path: legs
|
||||
|
||||
- name: Diff every profile and write the summary
|
||||
id: summary
|
||||
shell: bash
|
||||
env:
|
||||
PROFILES: ${{ inputs.profiles }}
|
||||
run: |
|
||||
# The shell runs with -e; the exit status is reported after the summary is written.
|
||||
set +e -u -o pipefail
|
||||
date="$(date -u +%F)"
|
||||
echo "date=${date}" >> "$GITHUB_OUTPUT"
|
||||
mkdir -p legs
|
||||
python3 scripts/dual_stack.py summary --profiles "$PROFILES" --legs legs --date "$date" --out-dir dual-stack
|
||||
status=$?
|
||||
if [ -f dual-stack/summary.md ]; then cat dual-stack/summary.md >> "$GITHUB_STEP_SUMMARY"; fi
|
||||
exit "$status"
|
||||
|
||||
- name: Upload the dated summary
|
||||
if: always() && steps.summary.outputs.date != ''
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: dual-stack-summary-${{ steps.summary.outputs.date }}
|
||||
overwrite: true
|
||||
path: dual-stack
|
||||
if-no-files-found: error
|
||||
retention-days: 30
|
||||
@@ -814,7 +814,7 @@
|
||||
"monitor": "workflow",
|
||||
"max_age_hours": 36,
|
||||
"result_owner": "dual-stack-nightly.yml",
|
||||
"disposition": "both-stack JUnit diff of the two profiles only ci.yml runs; the gateway legs are report-only until T2.10",
|
||||
"disposition": "nightly run of the two e2e profiles only ci.yml runs, on the gateway stack, with the JUnit reports retained for 30 days",
|
||||
"failure_owner": "watchdog",
|
||||
"origin": "added"
|
||||
},
|
||||
|
||||
+1
-173
@@ -92,7 +92,6 @@ jobs:
|
||||
connect: ${{ steps.scope.outputs.connect || 'true' }}
|
||||
packages: ${{ steps.scope.outputs.packages }}
|
||||
full_validation: ${{ steps.scope.outputs.full_validation || 'true' }}
|
||||
gateway_smoke: ${{ steps.scope.outputs.gateway_smoke || 'true' }}
|
||||
steps:
|
||||
- uses: actions/checkout@f548e57e544e1ff5a4c46bf1e1b8685f8e4a348a # v7
|
||||
with:
|
||||
@@ -119,7 +118,7 @@ jobs:
|
||||
echo "Base CI policy unavailable; running the full matrix."
|
||||
fi
|
||||
if ! grep -q '^plan=' "$GITHUB_OUTPUT" || ! grep -q '^plan_contract=8$' "$GITHUB_OUTPUT"; then
|
||||
printf '%s\n' 'mode=full' 'connect=true' 'full_validation=true' 'gateway_smoke=true' 'packages=' 'plan=' >> "$GITHUB_OUTPUT"
|
||||
printf '%s\n' 'mode=full' 'connect=true' 'full_validation=true' 'packages=' 'plan=' >> "$GITHUB_OUTPUT"
|
||||
echo "Base policy does not cover this workflow contract; retaining the full matrix."
|
||||
fi
|
||||
- name: Retain verification plan
|
||||
@@ -676,54 +675,6 @@ jobs:
|
||||
retention-days: 3
|
||||
if-no-files-found: warn
|
||||
|
||||
test-and-lint-gateway-stack:
|
||||
name: Test and Lint (gateway-stack)
|
||||
# The gateway S3 stack (rustfs/backlog#2734) sits behind the rustfs
|
||||
# `gateway-stack` feature, which no other pull-request lane lints or tests.
|
||||
# Unlike the dormant feature lanes above, this one runs for every code
|
||||
# change: each operation slice puts its handler tests and its refusal-matrix
|
||||
# row behind the feature, and a lane that ran only on demand would let them
|
||||
# rot behind a green pull request.
|
||||
if: needs.classify-changes.outputs.mode == 'full' && (github.event_name != 'pull_request' || github.event.action != 'closed')
|
||||
needs: [ quick-checks, classify-changes ]
|
||||
# Self-hosted for build scale and cache ownership: a workspace-scale Cargo
|
||||
# build that reads the ci-dev cache written on this image.
|
||||
runs-on: sm-standard-4
|
||||
timeout-minutes: 90
|
||||
env:
|
||||
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@f548e57e544e1ff5a4c46bf1e1b8685f8e4a348a # v7
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Setup Rust environment
|
||||
uses: ./.github/actions/setup
|
||||
with:
|
||||
rust-version: stable
|
||||
cache-shared-key: ci-dev-ea7eec74fe14
|
||||
cache-save-if: 'false'
|
||||
install-build-packaging-tools: 'false'
|
||||
|
||||
# A feature that does not compile fails here; nothing below is skipped
|
||||
# into a pass.
|
||||
- name: Run clippy with gateway-stack
|
||||
run: cargo clippy --locked -p rustfs --all-targets --features gateway-stack -- -D warnings
|
||||
|
||||
# The gateway stack's own tests: the assembly, the operation table and
|
||||
# its completeness, the shared handler sequence, the stack selection, and
|
||||
# the embedded server driven through the whole middleware stack. The
|
||||
# filter names modules, never operations.
|
||||
- name: Run tests with gateway-stack
|
||||
env:
|
||||
# The same bounded link concurrency as the other feature lanes.
|
||||
CARGO_BUILD_JOBS: "2"
|
||||
run: |
|
||||
cargo nextest run --profile ci --locked -p rustfs --features gateway-stack --no-tests fail \
|
||||
--status-level all --final-status-level all \
|
||||
-E 'test(/gateway_stack|gateway_handlers|server::stack::/) | binary(embedded_gateway_stack_test)'
|
||||
|
||||
build-rustfs-debug-binary:
|
||||
name: Build RustFS Debug Binary
|
||||
if: contains(fromJSON('["full", "e2e"]'), needs.classify-changes.outputs.mode) && (github.event_name != 'pull_request' || github.event.action != 'closed')
|
||||
@@ -986,8 +937,6 @@ jobs:
|
||||
# Retain the producer image and fixture paths until the runtime pilot passes.
|
||||
runs-on: sm-standard-4
|
||||
timeout-minutes: 30
|
||||
env:
|
||||
RUSTFS_S3_STACK: legacy
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@f548e57e544e1ff5a4c46bf1e1b8685f8e4a348a # v7
|
||||
@@ -1108,125 +1057,6 @@ jobs:
|
||||
path: ${{ runner.temp }}/rustfs-e2e-*/rustfs.log
|
||||
retention-days: 3
|
||||
|
||||
# The same e2e-smoke suite against the same debug binary with the gateway
|
||||
# S3 stack selected (rustfs/backlog#2734). Report-only: it is outside the
|
||||
# Test and Lint aggregate and becomes required at T2.10. The test-binary
|
||||
# download, identity, membership, run and completeness steps must stay
|
||||
# identical to e2e-tests; scripts/ci_gate.py enforces that.
|
||||
#
|
||||
# When it runs: every push to main or gateway/integration, merge group,
|
||||
# nightly schedule and manual dispatch, and every pull request that changes a
|
||||
# gateway-stack input (GATEWAY_SMOKE_PATHS and the rustfs-gateway pins in
|
||||
# scripts/ci_gate.py, published by Select CI scope as gateway_smoke).
|
||||
# Why it is skipped on every other pull request: until T2.10 the gateway
|
||||
# stack does not serve the whole smoke suite, so the lane fails on any
|
||||
# revision. A pull request that touches none of its inputs can neither cause
|
||||
# nor fix that failure, and a red check there says nothing about the change.
|
||||
# Skipped is the honest state; a failure must never be rendered green, so no
|
||||
# step here may carry continue-on-error. A selection that is missing or
|
||||
# unreadable runs the lane. At T2.10, when the lane becomes required, it
|
||||
# must run on every pull request again: delete the selection, do not extend
|
||||
# it.
|
||||
e2e-tests-gateway:
|
||||
name: e2e-smoke (gateway, report-only until T2.10)
|
||||
needs: [ classify-changes, build-rustfs-debug-binary ]
|
||||
if: github.event_name != 'pull_request' || needs.classify-changes.outputs.gateway_smoke != 'false'
|
||||
runs-on: sm-standard-2
|
||||
timeout-minutes: 30
|
||||
continue-on-error: true
|
||||
env:
|
||||
RUSTFS_S3_STACK: gateway
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@f548e57e544e1ff5a4c46bf1e1b8685f8e4a348a # v7
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Install verification runtime
|
||||
uses: ./.github/actions/test-runtime
|
||||
|
||||
- name: Download E2E test binaries
|
||||
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
||||
with:
|
||||
name: e2e-test-binaries
|
||||
path: ${{ runner.temp }}
|
||||
|
||||
- name: Verify E2E archive identity
|
||||
run: python3 scripts/ci_test_artifact.py verify --configuration e2e --archive "$RUNNER_TEMP/e2e-tests.tar.zst"
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
|
||||
with:
|
||||
python-version: "3.12"
|
||||
|
||||
- name: Install awscurl
|
||||
run: |
|
||||
python3 -m pip install --user --upgrade pip "awscurl==0.44"
|
||||
echo "AWSCURL_PATH=$HOME/.local/bin/awscurl" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Verify awscurl
|
||||
run: test -x "$AWSCURL_PATH"
|
||||
|
||||
# Download after the cache restore so the freshly built binary from the
|
||||
# build job always wins over anything restored into target/debug.
|
||||
- name: Download debug binary
|
||||
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
||||
with:
|
||||
name: rustfs-debug-binary
|
||||
path: target/debug
|
||||
|
||||
- name: Make binary executable
|
||||
run: chmod +x ./target/debug/rustfs
|
||||
|
||||
# Build the e2e test graph once. The archive is reused by the smoke
|
||||
# selection guard, security exact-count check, and run below, avoiding a
|
||||
# second compile of the same e2e_test target on cold runners (backlog#1645).
|
||||
- name: Verify e2e smoke test membership
|
||||
env:
|
||||
NEXTEST_ARCHIVE: ${{ runner.temp }}/e2e-tests.tar.zst
|
||||
NEXTEST_LISTING: ${{ runner.temp }}/rustfs-e2e-smoke-list.json
|
||||
run: |
|
||||
cargo nextest list --profile e2e-smoke --archive-file "${NEXTEST_ARCHIVE}" --workspace-remap "$GITHUB_WORKSPACE" --extract-to "$GITHUB_WORKSPACE" --extract-overwrite --message-format json > "${NEXTEST_LISTING}"
|
||||
python3 ./scripts/check_test_wiring.py --check-profile e2e-smoke "${NEXTEST_LISTING}"
|
||||
./scripts/check_security_smoke_count.sh check "${NEXTEST_LISTING}"
|
||||
|
||||
# PR smoke subset of the in-repo e2e suite (backlog#1149 ci-4). The
|
||||
# profile.e2e-smoke default-filter in .config/nextest.toml is the single
|
||||
# wiring mechanism for e2e tests in CI — extend that filter instead of
|
||||
# adding new e2e jobs here. Each test spawns its own rustfs server on a
|
||||
# random port and reuses the downloaded debug binary above.
|
||||
- name: Run e2e smoke suite
|
||||
env:
|
||||
NEXTEST_ARCHIVE: ${{ runner.temp }}/e2e-tests.tar.zst
|
||||
RUSTFS_E2E_LOG_DIR: ${{ runner.temp }}/rustfs-e2e-smoke-logs
|
||||
SAMPLER_INTERVAL_SECS: "15"
|
||||
run: |
|
||||
./scripts/ci/resource_sampler.sh start e2e-smoke
|
||||
trap './scripts/ci/resource_sampler.sh stop' EXIT
|
||||
python3 scripts/e2e_binary.py run --features e2e-test-hooks -- cargo nextest run --profile e2e-smoke --cargo-metadata target/nextest/cargo-metadata.json --binaries-metadata target/nextest/binaries-metadata.json --workspace-remap "$GITHUB_WORKSPACE" --target-dir-remap "$GITHUB_WORKSPACE/target" \
|
||||
--status-level all --final-status-level all --failure-output final
|
||||
|
||||
- name: Verify e2e smoke execution completeness
|
||||
run: python3 scripts/ci_test_artifact.py evidence "$RUNNER_TEMP/rustfs-e2e-smoke-list.json" target/nextest/e2e-smoke/junit.xml
|
||||
|
||||
- name: Upload e2e smoke diagnostics
|
||||
if: always()
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: e2e-smoke-gateway-diagnostics-${{ github.run_number }}-${{ github.run_attempt }}
|
||||
path: |
|
||||
${{ runner.temp }}/rustfs-e2e-smoke-logs/
|
||||
${{ runner.temp }}/rustfs-e2e-smoke-list.json
|
||||
if-no-files-found: warn
|
||||
|
||||
- name: Upload e2e smoke JUnit report
|
||||
if: always()
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: e2e-smoke-gateway-junit-${{ github.run_number }}-${{ github.run_attempt }}
|
||||
path: target/nextest/e2e-smoke/junit.xml
|
||||
if-no-files-found: warn
|
||||
|
||||
e2e-full:
|
||||
name: End-to-End Tests (full merge gate)
|
||||
# Merge gate only (backlog#1149 ci-5): the never-automated user-visible
|
||||
@@ -1612,7 +1442,6 @@ jobs:
|
||||
- fips-provider
|
||||
- test-and-lint-rio-v2
|
||||
- test-and-lint-protocols
|
||||
- test-and-lint-gateway-stack
|
||||
- build-rustfs-debug-binary
|
||||
- uring-integration
|
||||
- e2e-tests
|
||||
@@ -1648,7 +1477,6 @@ jobs:
|
||||
- core-contract
|
||||
- test-and-lint-rio-v2
|
||||
- test-and-lint-protocols
|
||||
- test-and-lint-gateway-stack
|
||||
- build-rustfs-debug-binary
|
||||
- build-rustfs-debug-binary-rio-v2
|
||||
- uring-integration
|
||||
|
||||
@@ -12,21 +12,18 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Nightly both-stack diff of the two e2e profiles only ci.yml runs, e2e-smoke
|
||||
# and e2e-full (rustfs/backlog#2772, T3.1). The other profiles carry a `stack`
|
||||
# dimension in their own workflows, where the existing lane is the legacy leg.
|
||||
# Nightly run of the two e2e profiles only ci.yml runs, e2e-smoke and e2e-full
|
||||
# (rustfs/backlog#2772, T3.1), on the gateway stack, which is the only S3 stack.
|
||||
# The workflow keeps its file and registry name from the period when it diffed two
|
||||
# stacks. Each leg uploads its JUnit report and server logs for 30 days; the one
|
||||
# comparison against the last legacy record (the `dual-stack-leg-<profile>-legacy`
|
||||
# artifacts of the final both-stack run) is made by hand with scripts/junit_diff.py.
|
||||
#
|
||||
# One build serves every leg. One preflight starts that binary with
|
||||
# RUSTFS_S3_STACK=gateway (scripts/dual_stack.py preflight); without a proven
|
||||
# gateway start the gateway legs do not run and the summary says `skipped:
|
||||
# gateway stack refuses startup: <why>`. Which stack a leg ran is read from the
|
||||
# servers' own start-up line. The gateway legs are report-only until T2.10.
|
||||
#
|
||||
# Left out of both stacks: `dual_stack_differential::` (servers with an explicit
|
||||
# Left out: `dual_stack_differential::` (servers with an explicit
|
||||
# stack), `fake_s3_target::`, the upgrade write-readiness cases and one deadline
|
||||
# case (no server), and `distributed_startup_regression_test::` (needs ci.yml's
|
||||
# hooks-binary manifest). Both e2e-full stacks use ci.yml's pinned mc and
|
||||
# Vault binaries and network fault-injection tools.
|
||||
# hooks-binary manifest). e2e-full uses ci.yml's pinned mc and Vault binaries
|
||||
# and network fault-injection tools.
|
||||
|
||||
name: dual-stack-nightly
|
||||
|
||||
@@ -50,13 +47,11 @@ defaults:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build once and probe the gateway stack
|
||||
name: Build once
|
||||
if: github.repository == 'rustfs/rustfs'
|
||||
# The runner and cache of ci.yml's build-rustfs-debug-binary.
|
||||
runs-on: sm-standard-4
|
||||
timeout-minutes: 60
|
||||
outputs:
|
||||
stacks: ${{ steps.preflight.outputs.stacks }}
|
||||
env:
|
||||
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"
|
||||
steps:
|
||||
@@ -86,47 +81,15 @@ jobs:
|
||||
if-no-files-found: error
|
||||
retention-days: 1
|
||||
|
||||
# Without a proven gateway start there is no gateway leg to run.
|
||||
- name: Gateway preflight
|
||||
id: preflight
|
||||
run: |
|
||||
if python3 scripts/dual_stack.py preflight --binary target/debug/rustfs --out "$RUNNER_TEMP/preflight/stack.json"; then
|
||||
echo 'stacks=["legacy","gateway"]' >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo 'stacks=["legacy"]' >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
# The evidence stands in for a gateway leg that is skipped; a leg that runs overwrites it.
|
||||
- name: Upload the preflight evidence for e2e-smoke
|
||||
if: always()
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: dual-stack-leg-e2e-smoke-gateway
|
||||
path: ${{ runner.temp }}/preflight
|
||||
if-no-files-found: warn
|
||||
retention-days: 7
|
||||
|
||||
- name: Upload the preflight evidence for e2e-full
|
||||
if: always()
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: dual-stack-leg-e2e-full-gateway
|
||||
path: ${{ runner.temp }}/preflight
|
||||
if-no-files-found: warn
|
||||
retention-days: 7
|
||||
|
||||
leg:
|
||||
name: ${{ matrix.profile }} (${{ matrix.stack }}${{ matrix.stack == 'gateway' && ', report-only until T2.10' || '' }})
|
||||
name: ${{ matrix.profile }}
|
||||
needs: [ build ]
|
||||
runs-on: sm-standard-4
|
||||
timeout-minutes: 120
|
||||
# Report-only until T2.10: the gateway stack cannot serve the suites yet.
|
||||
continue-on-error: ${{ matrix.stack == 'gateway' }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
profile: [ e2e-smoke, e2e-full ]
|
||||
stack: ${{ fromJSON(needs.build.outputs.stacks) }}
|
||||
env:
|
||||
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"
|
||||
steps:
|
||||
@@ -208,10 +171,9 @@ jobs:
|
||||
run: |
|
||||
"$RUSTFS_TEST_VAULT_BIN" version
|
||||
|
||||
- name: Run the profile on the ${{ matrix.stack }} stack
|
||||
- name: Run the profile
|
||||
env:
|
||||
PROFILE: ${{ matrix.profile }}
|
||||
RUSTFS_S3_STACK: ${{ matrix.stack }}
|
||||
RUSTFS_E2E_LOG_DIR: ${{ runner.temp }}/server-logs
|
||||
run: |
|
||||
chmod +x target/debug/rustfs
|
||||
@@ -220,23 +182,14 @@ jobs:
|
||||
filter="$filter & not test(=list_objects_v2_pagination_test::tests::test_list_objects_v2_deadline_rejects_unresponsive_peer)"
|
||||
python3 scripts/e2e_binary.py run --features e2e-test-hooks -- cargo nextest run --profile "$PROFILE" -p e2e_test -E "$filter"
|
||||
|
||||
- name: Prove the stack and upload the leg
|
||||
- name: Upload the leg
|
||||
if: always()
|
||||
uses: ./.github/actions/dual-stack-leg
|
||||
with: { profile: "${{ matrix.profile }}", stack: "${{ matrix.stack }}", logs: "${{ runner.temp }}/server-logs" }
|
||||
|
||||
summary:
|
||||
name: Both-stack diff summary
|
||||
needs: [ build, leg ]
|
||||
if: github.repository == 'rustfs/rustfs' && always()
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 15
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@f548e57e544e1ff5a4c46bf1e1b8685f8e4a348a # v7
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- uses: ./.github/actions/dual-stack-summary
|
||||
with:
|
||||
profiles: e2e-smoke,e2e-full
|
||||
name: e2e-nightly-${{ matrix.profile }}
|
||||
overwrite: true
|
||||
path: |
|
||||
target/nextest/${{ matrix.profile }}/junit.xml
|
||||
${{ runner.temp }}/server-logs
|
||||
if-no-files-found: warn
|
||||
retention-days: 30
|
||||
|
||||
@@ -53,14 +53,11 @@ concurrency:
|
||||
jobs:
|
||||
distributed:
|
||||
if: github.repository == 'rustfs/rustfs'
|
||||
name: Distributed 4-node 4-disk e2e (${{ matrix.stack }}${{ matrix.stack == 'gateway' && ', report-only until T2.10' || '' }})
|
||||
name: Distributed 4-node 4-disk e2e
|
||||
# GitHub-hosted VM: loop and tmpfs mounts work here. sm-standard-4 is an
|
||||
# ARC pod and rejects both (`mount -o loop` ENOENT, tmpfs "read-only").
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 180
|
||||
# The gateway leg is report-only until T2.10.
|
||||
continue-on-error: ${{ matrix.stack == 'gateway' }}
|
||||
strategy: { fail-fast: false, matrix: { stack: [legacy, gateway] } }
|
||||
env:
|
||||
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"
|
||||
NO_PROXY: 127.0.0.1,localhost
|
||||
@@ -132,11 +129,6 @@ jobs:
|
||||
run: |
|
||||
python3 scripts/e2e_binary.py build --bins --features e2e-test-hooks
|
||||
|
||||
# A gateway binary that refuses to start skips the suite; the summary says why.
|
||||
- name: Gateway preflight
|
||||
if: matrix.stack == 'gateway'
|
||||
run: python3 scripts/dual_stack.py preflight --binary target/debug/rustfs --out "$RUNNER_TEMP/leg/stack.json"
|
||||
|
||||
- name: Verify distributed e2e membership
|
||||
env:
|
||||
NEXTEST_LISTING: ${{ runner.temp }}/rustfs-e2e-distributed-list.json
|
||||
@@ -148,7 +140,6 @@ jobs:
|
||||
env:
|
||||
RUSTFS_E2E_LOG_DIR: ${{ runner.temp }}/rustfs-e2e-distributed-logs
|
||||
FILTER: ${{ inputs.filter }}
|
||||
RUSTFS_S3_STACK: ${{ matrix.stack }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
rm -f target/nextest/e2e-distributed/junit.xml
|
||||
@@ -159,19 +150,11 @@ jobs:
|
||||
fi
|
||||
test -s target/nextest/e2e-distributed/junit.xml
|
||||
|
||||
- name: Prove the stack and upload the leg
|
||||
if: always()
|
||||
uses: ./.github/actions/dual-stack-leg
|
||||
with:
|
||||
profile: e2e-distributed
|
||||
stack: ${{ matrix.stack }}
|
||||
logs: ${{ runner.temp }}/rustfs-e2e-distributed-logs
|
||||
|
||||
- name: Upload distributed e2e diagnostics
|
||||
if: always()
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: e2e-distributed-${{ github.run_number }}-${{ matrix.stack }}
|
||||
name: e2e-distributed-${{ github.run_number }}
|
||||
path: |
|
||||
target/nextest/e2e-distributed/junit.xml
|
||||
${{ runner.temp }}/rustfs-e2e-distributed-list.json
|
||||
@@ -191,20 +174,6 @@ jobs:
|
||||
fi
|
||||
done
|
||||
|
||||
dual-stack-summary:
|
||||
name: Both-stack diff summary
|
||||
needs: [distributed]
|
||||
if: github.repository == 'rustfs/rustfs' && always()
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 15
|
||||
steps:
|
||||
- uses: actions/checkout@f548e57e544e1ff5a4c46bf1e1b8685f8e4a348a # v7
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: ./.github/actions/dual-stack-summary
|
||||
with:
|
||||
profiles: e2e-distributed
|
||||
|
||||
alert-on-failure:
|
||||
name: Alert on scheduled failure
|
||||
needs: [distributed]
|
||||
|
||||
@@ -54,18 +54,15 @@ concurrency:
|
||||
jobs:
|
||||
repl-nightly:
|
||||
if: github.repository == 'rustfs/rustfs'
|
||||
name: Replication e2e (nightly, ${{ matrix.stack }}${{ matrix.stack == 'gateway' && ', report-only until T2.10' || '' }})
|
||||
name: Replication e2e (nightly)
|
||||
# dual-node tests spawn two full rustfs servers each; the extra headroom
|
||||
# over the per-PR sm-standard-2 e2e job keeps the parallel process fan-out
|
||||
# from starving the runner. Mirrors the ILM serial lane's runner class.
|
||||
runs-on: sm-standard-4
|
||||
timeout-minutes: 45
|
||||
# The gateway leg is report-only until T2.10.
|
||||
continue-on-error: ${{ matrix.stack == 'gateway' }}
|
||||
strategy: { fail-fast: false, matrix: { stack: [legacy, gateway] } }
|
||||
env:
|
||||
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"
|
||||
RUSTFS_BUILD_FEATURES: ${{ matrix.stack == 'gateway' && 'gateway-stack' || '' }}
|
||||
RUSTFS_BUILD_FEATURES: ""
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@f548e57e544e1ff5a4c46bf1e1b8685f8e4a348a # v7
|
||||
@@ -99,11 +96,6 @@ jobs:
|
||||
run: |
|
||||
python3 scripts/e2e_binary.py build --bins --features "$RUSTFS_BUILD_FEATURES"
|
||||
|
||||
# A gateway binary that refuses to start skips the suite; the summary says why.
|
||||
- name: Gateway preflight
|
||||
if: matrix.stack == 'gateway'
|
||||
run: python3 scripts/dual_stack.py preflight --binary target/debug/rustfs --out "$RUNNER_TEMP/leg/stack.json"
|
||||
|
||||
- name: Verify replication e2e membership
|
||||
env:
|
||||
NEXTEST_LISTING: ${{ runner.temp }}/rustfs-e2e-repl-nightly-list.json
|
||||
@@ -114,22 +106,13 @@ jobs:
|
||||
- name: Run replication e2e nightly suite
|
||||
env:
|
||||
RUSTFS_E2E_LOG_DIR: ${{ runner.temp }}/rustfs-e2e-repl-nightly-logs
|
||||
RUSTFS_S3_STACK: ${{ matrix.stack }}
|
||||
run: python3 scripts/e2e_binary.py run --features "$RUSTFS_BUILD_FEATURES" -- cargo nextest run --profile e2e-repl-nightly -p e2e_test
|
||||
|
||||
- name: Prove the stack and upload the leg
|
||||
if: always()
|
||||
uses: ./.github/actions/dual-stack-leg
|
||||
with:
|
||||
profile: e2e-repl-nightly
|
||||
stack: ${{ matrix.stack }}
|
||||
logs: ${{ runner.temp }}/rustfs-e2e-repl-nightly-logs
|
||||
|
||||
- name: Upload nextest junit report
|
||||
if: always()
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: e2e-replication-nightly-junit-${{ github.run_number }}-${{ matrix.stack }}
|
||||
name: e2e-replication-nightly-junit-${{ github.run_number }}
|
||||
path: |
|
||||
target/nextest/e2e-repl-nightly/junit.xml
|
||||
${{ runner.temp }}/rustfs-e2e-repl-nightly-list.json
|
||||
@@ -139,12 +122,9 @@ jobs:
|
||||
|
||||
cluster-nightly:
|
||||
if: github.repository == 'rustfs/rustfs'
|
||||
name: Cluster fault e2e (nightly, ${{ matrix.stack }}${{ matrix.stack == 'gateway' && ', report-only until T2.10' || '' }})
|
||||
name: Cluster fault e2e (nightly)
|
||||
runs-on: sm-standard-4
|
||||
timeout-minutes: 90
|
||||
# The gateway leg is report-only until T2.10.
|
||||
continue-on-error: ${{ matrix.stack == 'gateway' }}
|
||||
strategy: { fail-fast: false, matrix: { stack: [legacy, gateway] } }
|
||||
env:
|
||||
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"
|
||||
steps:
|
||||
@@ -165,11 +145,6 @@ jobs:
|
||||
run: |
|
||||
python3 scripts/e2e_binary.py build --bins --features e2e-test-hooks
|
||||
|
||||
# A gateway binary that refuses to start skips the suite; the summary says why.
|
||||
- name: Gateway preflight
|
||||
if: matrix.stack == 'gateway'
|
||||
run: python3 scripts/dual_stack.py preflight --binary target/debug/rustfs --out "$RUNNER_TEMP/leg/stack.json"
|
||||
|
||||
- name: Verify cluster fault e2e membership
|
||||
env:
|
||||
NEXTEST_LISTING: ${{ runner.temp }}/rustfs-e2e-nightly-list.json
|
||||
@@ -181,22 +156,13 @@ jobs:
|
||||
env:
|
||||
CARGO_BIN_EXE_rustfs: ${{ github.workspace }}/target/debug/rustfs
|
||||
RUSTFS_E2E_LOG_DIR: ${{ runner.temp }}/rustfs-e2e-nightly-logs
|
||||
RUSTFS_S3_STACK: ${{ matrix.stack }}
|
||||
run: python3 scripts/e2e_binary.py run --features e2e-test-hooks -- cargo nextest run --profile e2e-nightly -p e2e_test
|
||||
|
||||
- name: Prove the stack and upload the leg
|
||||
if: always()
|
||||
uses: ./.github/actions/dual-stack-leg
|
||||
with:
|
||||
profile: e2e-nightly
|
||||
stack: ${{ matrix.stack }}
|
||||
logs: ${{ runner.temp }}/rustfs-e2e-nightly-logs
|
||||
|
||||
- name: Upload cluster fault diagnostics
|
||||
if: always()
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: e2e-cluster-nightly-${{ github.run_number }}-${{ matrix.stack }}
|
||||
name: e2e-cluster-nightly-${{ github.run_number }}
|
||||
path: |
|
||||
target/nextest/e2e-nightly/junit.xml
|
||||
${{ runner.temp }}/rustfs-e2e-nightly-list.json
|
||||
@@ -206,15 +172,12 @@ jobs:
|
||||
|
||||
protocols-nightly:
|
||||
if: github.repository == 'rustfs/rustfs'
|
||||
name: Protocol e2e (nightly, ${{ matrix.stack }}${{ matrix.stack == 'gateway' && ', report-only until T2.10' || '' }})
|
||||
name: Protocol e2e (nightly)
|
||||
runs-on: sm-standard-4
|
||||
timeout-minutes: 90
|
||||
# The gateway leg is report-only until T2.10.
|
||||
continue-on-error: ${{ matrix.stack == 'gateway' }}
|
||||
strategy: { fail-fast: false, matrix: { stack: [legacy, gateway] } }
|
||||
env:
|
||||
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"
|
||||
RUSTFS_BUILD_FEATURES: ${{ matrix.stack == 'gateway' && 'ftps,webdav,sftp,gateway-stack' || 'ftps,webdav,sftp' }}
|
||||
RUSTFS_BUILD_FEATURES: ftps,webdav,sftp
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@f548e57e544e1ff5a4c46bf1e1b8685f8e4a348a # v7
|
||||
@@ -238,11 +201,6 @@ jobs:
|
||||
- name: Build protocol server
|
||||
run: python3 scripts/e2e_binary.py build --features "$RUSTFS_BUILD_FEATURES"
|
||||
|
||||
# A gateway binary that refuses to start skips the suite; the summary says why.
|
||||
- name: Gateway preflight
|
||||
if: matrix.stack == 'gateway'
|
||||
run: python3 scripts/dual_stack.py preflight --binary target/debug/rustfs --out "$RUNNER_TEMP/leg/stack.json"
|
||||
|
||||
# The suite owns fixed protocol ports and serializes its internal cases.
|
||||
- name: Verify protocol e2e membership
|
||||
env:
|
||||
@@ -254,28 +212,16 @@ jobs:
|
||||
- name: Run protocol e2e nightly suite
|
||||
env:
|
||||
RUSTFS_E2E_LOG_DIR: ${{ runner.temp }}/rustfs-protocol-e2e-logs
|
||||
RUSTFS_S3_STACK: ${{ matrix.stack }}
|
||||
# These servers set no log level of their own; the stack proof reads their start-up line.
|
||||
RUST_LOG: rustfs=info
|
||||
# The servers inherit nextest's stdout (--no-capture): keep it where the stack proof reads it.
|
||||
run: |
|
||||
set -o pipefail
|
||||
mkdir -p "$RUSTFS_E2E_LOG_DIR"
|
||||
python3 scripts/e2e_binary.py run --features "$RUSTFS_BUILD_FEATURES" -- cargo nextest run -j 1 --profile e2e-protocols -p e2e_test --no-capture 2>&1 | tee "$RUSTFS_E2E_LOG_DIR/nextest.log"
|
||||
|
||||
- name: Prove the stack and upload the leg
|
||||
if: always()
|
||||
uses: ./.github/actions/dual-stack-leg
|
||||
with:
|
||||
profile: e2e-protocols
|
||||
stack: ${{ matrix.stack }}
|
||||
logs: ${{ runner.temp }}/rustfs-protocol-e2e-logs
|
||||
|
||||
- name: Upload protocol diagnostics
|
||||
if: always()
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: e2e-protocol-nightly-${{ github.run_number }}-${{ matrix.stack }}
|
||||
name: e2e-protocol-nightly-${{ github.run_number }}
|
||||
path: |
|
||||
target/nextest/e2e-protocols/junit.xml
|
||||
${{ runner.temp }}/rustfs-e2e-protocols-list.json
|
||||
@@ -283,20 +229,6 @@ jobs:
|
||||
retention-days: 7
|
||||
if-no-files-found: warn
|
||||
|
||||
dual-stack-summary:
|
||||
name: Both-stack diff summary
|
||||
needs: [repl-nightly, cluster-nightly, protocols-nightly]
|
||||
if: github.repository == 'rustfs/rustfs' && always()
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 15
|
||||
steps:
|
||||
- uses: actions/checkout@f548e57e544e1ff5a4c46bf1e1b8685f8e4a348a # v7
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: ./.github/actions/dual-stack-summary
|
||||
with:
|
||||
profiles: e2e-repl-nightly,e2e-nightly,e2e-protocols
|
||||
|
||||
alert-on-failure:
|
||||
name: Alert on scheduled failure
|
||||
needs: [repl-nightly, cluster-nightly, protocols-nightly]
|
||||
|
||||
@@ -15,31 +15,20 @@
|
||||
# Gateway black-box acceptance lanes (rustfs/backlog#2775 T3.4, #2776 T3.5).
|
||||
#
|
||||
# Runs two suites of the rustfs/gateway repository against the candidate binary,
|
||||
# once per S3 stack (RUSTFS_S3_STACK=legacy and =gateway), one server per stack:
|
||||
# one server:
|
||||
#
|
||||
# - the conformance corpus, `--profile rustfs`. That profile describes the
|
||||
# gateway edge, so scripts/check_conformance_rulings.py judges the gateway
|
||||
# stack against .config/conformance-rulings.toml (red: an unruled failure, a
|
||||
# ruled case failing differently, a stale ruling, a skip on the server's own
|
||||
# answer) and publishes the legacy run as a reference that is never judged:
|
||||
# it only has to serve, stay up and complete;
|
||||
# - the client matrix, ci/compat/run_matrix.sh --external, judged per stack by
|
||||
# - the conformance corpus, `--profile rustfs`, judged by
|
||||
# scripts/check_conformance_rulings.py against .config/conformance-rulings.toml
|
||||
# (red: an unruled failure, a ruled case failing differently, a stale ruling,
|
||||
# a skip on the server's own answer);
|
||||
# - the client matrix, ci/compat/run_matrix.sh --external, judged by
|
||||
# scripts/compat_matrix_report.py (no `fail`, no `sut-unregistered`, every
|
||||
# client ran; a client that could not be installed is reported as skipped).
|
||||
# The legacy matrix is the baseline: every cell that passes on legacy must
|
||||
# pass on gateway (`compare`).
|
||||
#
|
||||
# The suites are checked out at the rustfs/gateway rev Cargo.toml pins, so the
|
||||
# suite and the framework under test never drift apart. The verdict of each
|
||||
# stack is computed from what the run left on disk (startup record, the stack
|
||||
# the server's own log names, runner exit code, liveness after the corpus,
|
||||
# report), never from the exit status of an earlier step. Needs
|
||||
# scripts/dual_stack.py and the `s3_stack` startup field of rustfs/rustfs#9367.
|
||||
#
|
||||
# The gateway stack is report-only until T2.10: its job may fail without failing
|
||||
# the workflow, and its summary says what it observed (did not start, or how many
|
||||
# cases ran, passed, failed and were answered 501). The stack comparison is
|
||||
# report-only for the same reason; its conformance half is information only.
|
||||
# suite and the framework under test never drift apart. The verdict is computed
|
||||
# from what the run left on disk (startup record, runner exit code, liveness
|
||||
# after the corpus, report), never from the exit status of an earlier step.
|
||||
#
|
||||
# Not a pull-request gate. Scheduled failures are owned by the scheduled-validation
|
||||
# watchdog (.github/scheduled-validations.json).
|
||||
@@ -166,21 +155,15 @@ jobs:
|
||||
retention-days: 1
|
||||
|
||||
acceptance:
|
||||
name: ${{ matrix.stack == 'gateway' && 'Acceptance (gateway, report-only until T2.10)' || 'Acceptance (legacy)' }}
|
||||
name: Acceptance
|
||||
needs: [ plan, build-candidate, build-gateway-tools ]
|
||||
# GitHub-hosted like the s3-tests targets of reference-parity.yml: the job
|
||||
# only runs prebuilt binaries and the pinned clients, none of which needs Docker.
|
||||
runs-on: ubuntu-latest
|
||||
# About 3x the 15 minutes the legacy job took in run 43325101234 (client install about
|
||||
# About 3x the 15 minutes the job took in run 43325101234 (client install about
|
||||
# 8, matrix about 3, corpus about 3), so a hung server costs 45 runner minutes, not more.
|
||||
timeout-minutes: 45
|
||||
continue-on-error: ${{ matrix.stack == 'gateway' }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
stack: [ legacy, gateway ]
|
||||
env:
|
||||
STACK: ${{ matrix.stack }}
|
||||
ENDPOINT: http://127.0.0.1:9000
|
||||
# The conformance suite signs with these fixed fixture credentials (the AWS
|
||||
# documentation example pair), so the candidate is started with them and the
|
||||
@@ -213,10 +196,8 @@ jobs:
|
||||
name: gateway-acceptance-tools
|
||||
path: tools
|
||||
|
||||
# Records `ready`, or what the process said when it exited, in lane/startup.txt. `ready`
|
||||
# also needs the server's own `server_starting` log event to name the requested stack
|
||||
# (its `s3_stack` field comes from rustfs/rustfs#9367; scripts/dual_stack.py reads it).
|
||||
- name: Start candidate (${{ matrix.stack }} stack)
|
||||
# Records `ready`, or what the process said when it exited, in lane/startup.txt.
|
||||
- name: Start candidate
|
||||
run: |
|
||||
set -uo pipefail
|
||||
chmod +x target/debug/rustfs tools/*
|
||||
@@ -224,7 +205,7 @@ jobs:
|
||||
target/debug/rustfs --version | tee lane/candidate-version.txt
|
||||
# The four directories share the runner's one disk; the bypass is the CI case the
|
||||
# physical-disk guard sanctions (as in mint.yml).
|
||||
RUSTFS_S3_STACK="$STACK" RUSTFS_UNSAFE_BYPASS_DISK_CHECK=true RUST_LOG=info target/debug/rustfs --address 127.0.0.1:9000 \
|
||||
RUSTFS_UNSAFE_BYPASS_DISK_CHECK=true RUST_LOG=info target/debug/rustfs --address 127.0.0.1:9000 \
|
||||
--access-key "$ACCESS_KEY" --secret-key "$SECRET_KEY" "$RUNNER_TEMP"/data/rustfs{0..3} \
|
||||
> lane/rustfs.log 2>&1 &
|
||||
pid=$!
|
||||
@@ -239,13 +220,8 @@ jobs:
|
||||
exit 1
|
||||
fi
|
||||
if curl -sf "$ENDPOINT/health/ready" >/dev/null; then
|
||||
if python3 scripts/dual_stack.py stack --expect "$STACK" --out lane/stack.json lane/rustfs.log > /dev/null; then
|
||||
echo ready > lane/startup.txt
|
||||
exit 0
|
||||
fi
|
||||
echo "did not start: stack not observed" > lane/startup.txt
|
||||
cat lane/startup.txt
|
||||
exit 1
|
||||
echo ready > lane/startup.txt
|
||||
exit 0
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
@@ -338,58 +314,23 @@ jobs:
|
||||
run: |
|
||||
set -uo pipefail
|
||||
status=0
|
||||
python3 scripts/check_conformance_rulings.py --stack "$STACK" --run-dir lane | tee -a "$GITHUB_STEP_SUMMARY" || status=1
|
||||
python3 scripts/compat_matrix_report.py check --stack "$STACK" --run-dir lane | tee -a "$GITHUB_STEP_SUMMARY" || status=1
|
||||
python3 scripts/check_conformance_rulings.py --run-dir lane | tee -a "$GITHUB_STEP_SUMMARY" || status=1
|
||||
python3 scripts/compat_matrix_report.py check --run-dir lane | tee -a "$GITHUB_STEP_SUMMARY" || status=1
|
||||
exit "$status"
|
||||
|
||||
- name: Upload lane results
|
||||
if: always()
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: gateway-acceptance-lane-${{ matrix.stack }}
|
||||
name: gateway-acceptance-lane
|
||||
overwrite: true
|
||||
path: |
|
||||
lane/*.txt
|
||||
lane/*.log
|
||||
lane/report.json
|
||||
lane/stack.json
|
||||
lane/compat/matrix.json
|
||||
lane/compat/probe.jsonl
|
||||
lane/compat/sut.log
|
||||
lane/compat/results/**
|
||||
if-no-files-found: error
|
||||
retention-days: 14
|
||||
|
||||
compare:
|
||||
name: Compare stacks (report-only until T2.10)
|
||||
needs: [ acceptance ]
|
||||
if: always()
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 10
|
||||
continue-on-error: true
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@f548e57e544e1ff5a4c46bf1e1b8685f8e4a348a # v7
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Download lane results
|
||||
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
||||
with:
|
||||
pattern: gateway-acceptance-lane-*
|
||||
path: lanes
|
||||
|
||||
- name: Diff legacy and gateway
|
||||
run: |
|
||||
set -uo pipefail
|
||||
status=0
|
||||
{
|
||||
python3 scripts/check_conformance_rulings.py \
|
||||
--diff lanes/gateway-acceptance-lane-legacy lanes/gateway-acceptance-lane-gateway || status=1
|
||||
echo
|
||||
python3 scripts/compat_matrix_report.py diff \
|
||||
--legacy lanes/gateway-acceptance-lane-legacy --gateway lanes/gateway-acceptance-lane-gateway || status=1
|
||||
} > diff.md
|
||||
cat diff.md
|
||||
cat diff.md >> "$GITHUB_STEP_SUMMARY"
|
||||
exit "$status"
|
||||
|
||||
@@ -44,13 +44,6 @@
|
||||
# well inside the 120-minute budget and buys deterministic infra. The
|
||||
# docker-capable self-hosted `dind-sm-standard-2` label was the alternative but
|
||||
# has fewer cores and reintroduces fleet-state risk for no reliability gain.
|
||||
#
|
||||
# Stack dimension (rustfs/backlog#2774, T3.3): one image, run with RUSTFS_S3_STACK=legacy and
|
||||
# =gateway. `compare` (scripts/mint_stack_diff.py) holds the gate that every case legacy passes
|
||||
# passes on gateway with no new failure. The gateway leg and `compare` are report-only until
|
||||
# T2.10. A gateway server that refuses to start stops its leg at "Wait for RustFS ready", before
|
||||
# mint runs; the summary says `skipped: gateway stack refuses startup: <why>`. The stack is read
|
||||
# from the server's own start-up line (scripts/dual_stack.py stack).
|
||||
|
||||
name: mint
|
||||
|
||||
@@ -145,16 +138,8 @@ jobs:
|
||||
retention-days: 1
|
||||
|
||||
mint:
|
||||
name: mint (${{ matrix.stack }}${{ matrix.stack == 'gateway' && ', report-only until T2.10' || '' }})
|
||||
name: mint
|
||||
needs: [image]
|
||||
# Report-only until T2.10: the gateway stack cannot serve the suites yet.
|
||||
continue-on-error: ${{ matrix.stack == 'gateway' }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
stack: [legacy, gateway]
|
||||
env:
|
||||
STACK: ${{ matrix.stack }}
|
||||
# GitHub-hosted: reliably provides a running Docker daemon + buildx +
|
||||
# python3. See the header note (ci-2) for why the self-hosted sm-standard-4
|
||||
# label was abandoned (no docker.sock on the pod its only run landed on).
|
||||
@@ -194,7 +179,6 @@ jobs:
|
||||
-e RUSTFS_SECRET_KEY="${S3_SECRET_KEY}" \
|
||||
-e RUSTFS_VOLUMES="/data/rustfs{0...3}" \
|
||||
-e RUSTFS_UNSAFE_BYPASS_DISK_CHECK=true \
|
||||
-e RUSTFS_S3_STACK="${STACK}" \
|
||||
-e RUST_LOG=rustfs=info \
|
||||
-v /tmp/rustfs-mint:/data \
|
||||
rustfs-ci
|
||||
@@ -291,47 +275,13 @@ jobs:
|
||||
mkdir -p artifacts/rustfs-mint
|
||||
docker logs rustfs-mint > artifacts/rustfs-mint/rustfs.log 2>&1 || true
|
||||
|
||||
- name: Prove which stack the server selected
|
||||
if: always()
|
||||
run: python3 scripts/dual_stack.py stack --expect "${STACK}" --out artifacts/stack.json artifacts/rustfs-mint
|
||||
|
||||
- name: Upload artifacts
|
||||
if: always() && env.ACT != 'true'
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: mint-${{ matrix.stack }}
|
||||
name: mint
|
||||
path: artifacts/**
|
||||
|
||||
compare:
|
||||
name: Compare stacks (report-only until T2.10)
|
||||
needs: [mint]
|
||||
if: always()
|
||||
continue-on-error: true
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 10
|
||||
steps:
|
||||
- uses: actions/checkout@f548e57e544e1ff5a4c46bf1e1b8685f8e4a348a # v7
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Download both legs
|
||||
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
||||
with:
|
||||
pattern: mint-{legacy,gateway}
|
||||
path: legs
|
||||
|
||||
# A leg that never uploaded leaves no directory: create both so that the
|
||||
# comparison reports "no result" for it instead of failing to find it.
|
||||
- name: Compare the stacks
|
||||
run: |
|
||||
# The shell runs with -e; the exit status is reported after the summary is written.
|
||||
set +e -u -o pipefail
|
||||
mkdir -p legs/mint-legacy legs/mint-gateway
|
||||
python3 scripts/mint_stack_diff.py legs/mint-legacy legs/mint-gateway | tee report.txt
|
||||
status="${PIPESTATUS[0]}"
|
||||
{ echo '## Mint: gateway versus legacy'; echo; echo '```'; cat report.txt; echo '```'; } >> "$GITHUB_STEP_SUMMARY"
|
||||
exit "$status"
|
||||
|
||||
alert-on-failure:
|
||||
name: Alert on scheduled failure
|
||||
needs: [image, mint]
|
||||
|
||||
@@ -68,14 +68,11 @@ env:
|
||||
|
||||
jobs:
|
||||
minio-source:
|
||||
name: MinIO source (read-through, list-through, backfill, ${{ matrix.stack }}${{ matrix.stack == 'gateway' && ', report-only until T2.10' || '' }})
|
||||
name: MinIO source (read-through, list-through, backfill)
|
||||
# Keep this scheduled interoperability lane scoped to the upstream repo.
|
||||
if: github.repository == 'rustfs/rustfs'
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 90
|
||||
# The gateway leg is report-only until T2.10.
|
||||
continue-on-error: ${{ matrix.stack == 'gateway' }}
|
||||
strategy: { fail-fast: false, matrix: { stack: [legacy, gateway] } }
|
||||
env:
|
||||
NO_PROXY: 127.0.0.1,localhost
|
||||
# Fixed credentials of the container this job starts and throws away;
|
||||
@@ -140,11 +137,6 @@ jobs:
|
||||
- name: Build the RustFS binary under test
|
||||
run: python3 scripts/e2e_binary.py build --bins
|
||||
|
||||
# A gateway binary that refuses to start skips the suite; the summary says why.
|
||||
- name: Gateway preflight
|
||||
if: matrix.stack == 'gateway'
|
||||
run: python3 scripts/dual_stack.py preflight --binary target/debug/rustfs --out "$RUNNER_TEMP/leg/stack.json"
|
||||
|
||||
# The lane selects tests by module, so a rename would quietly shrink it.
|
||||
# The committed digest in .config/e2e-odm-interop-selection.txt fails
|
||||
# closed on that.
|
||||
@@ -155,18 +147,9 @@ jobs:
|
||||
|
||||
- name: Run the interop cases against MinIO
|
||||
env:
|
||||
RUSTFS_S3_STACK: ${{ matrix.stack }}
|
||||
RUSTFS_E2E_LOG_DIR: ${{ runner.temp }}/rustfs-e2e-logs
|
||||
run: python3 scripts/e2e_binary.py run -- cargo nextest run --profile e2e-odm-interop -p e2e_test --no-tests=fail
|
||||
|
||||
- name: Prove the stack and upload the leg
|
||||
if: always()
|
||||
uses: ./.github/actions/dual-stack-leg
|
||||
with:
|
||||
profile: e2e-odm-interop
|
||||
stack: ${{ matrix.stack }}
|
||||
logs: ${{ runner.temp }}/rustfs-e2e-logs
|
||||
|
||||
- name: Build the MinIO interop report
|
||||
if: always()
|
||||
uses: ./.github/actions/odm-interop-report
|
||||
@@ -190,7 +173,7 @@ jobs:
|
||||
if: always()
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: odm-interop-minio-${{ github.run_number }}-${{ github.run_attempt }}-${{ matrix.stack }}
|
||||
name: odm-interop-minio-${{ github.run_number }}-${{ github.run_attempt }}
|
||||
path: |
|
||||
artifacts/odm-interop/minio
|
||||
target/nextest/e2e-odm-interop/junit.xml
|
||||
@@ -316,20 +299,6 @@ jobs:
|
||||
target/nextest/e2e-odm-interop/junit.xml
|
||||
retention-days: 14
|
||||
|
||||
dual-stack-summary:
|
||||
name: Both-stack diff summary
|
||||
needs: [minio-source]
|
||||
if: github.repository == 'rustfs/rustfs' && always()
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 15
|
||||
steps:
|
||||
- uses: actions/checkout@f548e57e544e1ff5a4c46bf1e1b8685f8e4a348a # v7
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: ./.github/actions/dual-stack-summary
|
||||
with:
|
||||
profiles: e2e-odm-interop
|
||||
|
||||
alert-on-failure:
|
||||
name: Alert on scheduled failure
|
||||
needs: [minio-source, cloud-source]
|
||||
|
||||
@@ -32,9 +32,9 @@
|
||||
#
|
||||
# The `differential` job adds the 73-operation dual-stack differential
|
||||
# (crates/e2e_test/src/dual_stack_differential, rustfs/backlog#2740) against the
|
||||
# same pinned reference: side A is the released binary (RUSTFS_E2E_REFERENCE_BINARY,
|
||||
# started without RUSTFS_S3_STACK), side B is the candidate built above on its
|
||||
# legacy stack. It reuses the candidate build artifact, never builds the candidate
|
||||
# same pinned reference: side A is the released binary (RUSTFS_E2E_REFERENCE_BINARY),
|
||||
# side B is the candidate built above.
|
||||
# It reuses the candidate build artifact, never builds the candidate
|
||||
# twice, and prints reference_side, version_a and version_b from the report the test
|
||||
# wrote; it fails when side A was not the reference or both sides report the same
|
||||
# version. Every (op, field, a, b) difference goes to the job summary. Report-only
|
||||
@@ -310,7 +310,7 @@ jobs:
|
||||
chmod +x target/debug/rustfs
|
||||
test -x "$REFERENCE_PATH"
|
||||
mkdir -p "$RUSTFS_E2E_LOG_DIR"
|
||||
# Side A: the released binary. Side B: the candidate on its legacy stack.
|
||||
# Side A: the released binary. Side B: the candidate.
|
||||
export RUSTFS_E2E_REFERENCE_BINARY="$REFERENCE_PATH"
|
||||
test_name='dual_stack_differential::tests::both_stacks_answer_every_operation_identically'
|
||||
python3 scripts/e2e_binary.py run --features e2e-test-hooks -- \
|
||||
|
||||
@@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Deployment
|
||||
|
||||
- **The S3 protocol stack is now rustfs/gateway**, and it is the only S3 stack. The legacy s3s-based stack is removed, and so are the `RUSTFS_S3_STACK` environment variable and the `gateway-stack` cargo feature. There is no on-disk format change. `RUSTFS_S3_STACK` no longer selects anything: a server started with it set, to any value, refuses to start and prints `RUSTFS_S3_STACK is no longer supported; the gateway stack is the only S3 stack since <version>`, where `<version>` is the release's version. Remove the variable from service units, container environments, Helm values and orchestration files before upgrading. To roll back, run the previous release binary on the same data.
|
||||
|
||||
- Before upgrading, verify that the configured root access key is at least 3 bytes and the root secret key is at least 8 bytes. RustFS now rejects shorter values at startup and identifies the setting to update. Version 1.0.5 accepted these settings at startup and returned HTTP 500 when root requested STS credentials. Coordinate root credential changes across all nodes and clients. See [root credential rotation considerations](docs/operations/two-factor-auth.md#root-credentials-cannot-be-changed-at-runtime).
|
||||
|
||||
- Existing volumes created by older root-running container images must be writable by the non-root runtime identity before upgrading. The default container UID/GID is `10001:10001`; stop the affected instances, verify host mount paths, and for ordinary bind mounts run `sudo chown -R 10001:10001 /actual/data /actual/logs` on each RustFS data/log mount. Account for ACLs, NFS, Kubernetes, and rootless UID mappings. Image-build ownership changes do not migrate mounted data. See the Docker Quick Start in [README.md](README.md).
|
||||
|
||||
@@ -29,7 +29,7 @@ Registered in [`src/lib.rs`](src/lib.rs). Grouped by concern:
|
||||
| **distributed 4×4** | [`src/distributed/`](src/distributed) | Nightly `e2e-distributed` lane: S3, object lock/WORM, versioning, bucket/site replication, quota, expand/decommission/rebalance, concurrency, chaos, 4-node upgrade of historical data and IAM AK/SK. Map: [`docs/testing/distributed-e2e.md`](../../docs/testing/distributed-e2e.md) |
|
||||
| **chaos / reliability** | [`src/chaos.rs`](src/chaos.rs), `reliability_disk_fault_test`, `heal_erasure_disk_rebuild_test`, `server_startup_failfast_test` | Disk offline/replace/corrupt, EC rebuild, heal, fail-fast startup |
|
||||
| **upgrade compatibility** | `upgrade_compatibility_test` | Pinned previous-release writes followed by current-build reads on the same data directory |
|
||||
| **dual-stack differential** | `dual_stack_differential` | Two single-node servers answer one SDK script for all 73 S3 operations and every differing `(op, field, a, b)` is reported. Side A is the binary under test on `RUSTFS_S3_STACK=legacy`; side B runs `RUSTFS_E2E_STACK_B`. Set `RUSTFS_E2E_REFERENCE_BINARY` to a released `rustfs` binary to make side A that binary instead (started without `RUSTFS_S3_STACK`, which older releases do not know). A missing, non-file or non-executable path fails the run; it never skips or falls back to the same-binary mode. The report in `<target>/dual-stack/<run>.json` records `reference_side` and each side's `--version` output |
|
||||
| **dual-stack differential** | `dual_stack_differential` | Two single-node servers answer one SDK script for all 73 S3 operations and every differing `(op, field, a, b)` is reported. Both sides run the binary under test on its only (gateway) stack unless `RUSTFS_E2E_REFERENCE_BINARY` names a released `rustfs` binary, which then runs side A. A missing, non-file or non-executable path fails the run; it never skips or falls back to the same-binary mode. `RUSTFS_E2E_STACK_B_REGION` starts side B in another region to inject a difference. The report in `<target>/dual-stack/<run>.json` records `reference_side` and each side's `--version` output |
|
||||
|
||||
The external-tool `storage_metric_ownership_test` validates the OTLP/Collector/Prometheus path, including a rolling upgrade and node failures. See the [storage metrics guide](../../docs/operations/storage-metrics.md) for its required binaries and focused command.
|
||||
|
||||
|
||||
@@ -12,14 +12,15 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Dual-stack differential: one `rustfs` binary, two processes, one SDK script (rustfs/backlog#2740).
|
||||
//! Differential: two `rustfs` processes, one SDK script (rustfs/backlog#2740).
|
||||
//!
|
||||
//! Stack A runs `RUSTFS_S3_STACK=legacy` of the binary under test, unless `RUSTFS_E2E_REFERENCE_BINARY`
|
||||
//! names a released binary: then A is that binary, started without `RUSTFS_S3_STACK` (older
|
||||
//! releases do not know it), and a bad path fails the run instead of falling back (see
|
||||
//! `reference`). The report names which side is the reference and the `--version` each side ran. Stack B runs the value of `RUSTFS_E2E_STACK_B`
|
||||
//! (default `legacy` until the gateway stack is assembled), and `RUSTFS_E2E_STACK_B_REGION`, when
|
||||
//! set, starts B in another region so that a difference can be injected by hand. Both servers
|
||||
//! Side B is the binary under test. Side A is the binary under test too, unless
|
||||
//! `RUSTFS_E2E_REFERENCE_BINARY` names a released binary: then A is that binary, and a bad path
|
||||
//! fails the run instead of falling back (see `reference`). The report names which side is the
|
||||
//! reference and the `--version` each side ran. `RUSTFS_E2E_STACK_B_REGION`, when set, starts B
|
||||
//! in another region so that a difference can be injected by hand. Neither side is given the
|
||||
//! retired stack selector: the binary under test refuses to start with it, and the gateway stack
|
||||
//! is its only S3 stack. Both servers
|
||||
//! answer the script in `scenarios`, which covers every operation of `impl S3 for FS`; `compare`
|
||||
//! reports each `(op, field, a, b)` on which the answers differ, and every run writes its report
|
||||
//! to `<target>/dual-stack/<run>.json`. Two processes, not two embedded servers: bucket metadata
|
||||
@@ -37,20 +38,18 @@ use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
type BoxError = Box<dyn std::error::Error + Send + Sync>;
|
||||
|
||||
const STACK_A: &str = "legacy";
|
||||
/// Label of a side that runs the binary under test.
|
||||
const UNDER_TEST: &str = "under-test";
|
||||
/// Label of side A in the report when it is the released reference binary.
|
||||
const STACK_A_REFERENCE: &str = "reference";
|
||||
const ENV_STACK_B: &str = "RUSTFS_E2E_STACK_B";
|
||||
const ENV_STACK_B_REGION: &str = "RUSTFS_E2E_STACK_B_REGION";
|
||||
/// Becomes `gateway` once rustfs/backlog#2734 T2.5 assembles the gateway stack.
|
||||
const DEFAULT_STACK_B: &str = "legacy";
|
||||
/// The region the negative control gives stack A explicitly, so an inherited `RUSTFS_REGION`
|
||||
/// cannot erase the injected difference. Not `us-east-1`: that region answers GetBucketLocation
|
||||
/// with an empty LocationConstraint and re-creating an owned bucket with 200, so it would not
|
||||
/// report its own name and would add CreateBucket differences to the control.
|
||||
const CONTROL_REGION_A: &str = "us-west-2";
|
||||
const CONTROL_REGION_B: &str = "eu-west-1";
|
||||
/// `normal` cases the legacy stack must answer with a 2xx. The comparison alone cannot tell a
|
||||
/// `normal` cases side A must answer with a 2xx. The comparison alone cannot tell a
|
||||
/// script that exercises real behavior from one in which both stacks fail the same way. Five of
|
||||
/// the 73 fail on legacy by design of this script: PutBucketReplication (no registered remote
|
||||
/// target), GetBucketReplication (so no configuration), PutBucketNotificationConfiguration (no
|
||||
@@ -60,7 +59,6 @@ const MIN_NORMAL_SUCCESSES: usize = 68;
|
||||
|
||||
struct PairConfig {
|
||||
side_a: SideA,
|
||||
stack_b: String,
|
||||
region_a: Option<String>,
|
||||
region_b: Option<String>,
|
||||
}
|
||||
@@ -69,7 +67,6 @@ impl PairConfig {
|
||||
fn from_env() -> Result<Self, BoxError> {
|
||||
Ok(Self {
|
||||
side_a: SideA::from_env()?,
|
||||
stack_b: std::env::var(ENV_STACK_B).unwrap_or_else(|_| DEFAULT_STACK_B.to_owned()),
|
||||
region_a: None,
|
||||
region_b: std::env::var(ENV_STACK_B_REGION).ok(),
|
||||
})
|
||||
@@ -77,16 +74,16 @@ impl PairConfig {
|
||||
|
||||
fn stack_a_label(&self) -> &'static str {
|
||||
match self.side_a {
|
||||
SideA::SameBinary => STACK_A,
|
||||
SideA::SameBinary => UNDER_TEST,
|
||||
SideA::Reference(_) => STACK_A_REFERENCE,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Starts one server of the binary under test on `stack`, overriding its region only when asked.
|
||||
async fn start_stack(stack: &str, region: Option<&str>) -> Result<RustFSTestEnvironment, BoxError> {
|
||||
/// Starts one server of the binary under test, overriding its region only when asked.
|
||||
async fn start_under_test(region: Option<&str>) -> Result<RustFSTestEnvironment, BoxError> {
|
||||
let mut env = RustFSTestEnvironment::new().await?;
|
||||
let mut vars = vec![("RUSTFS_S3_STACK", stack)];
|
||||
let mut vars = Vec::new();
|
||||
if let Some(region) = region {
|
||||
vars.push(("RUSTFS_REGION", region));
|
||||
}
|
||||
@@ -94,8 +91,7 @@ async fn start_stack(stack: &str, region: Option<&str>) -> Result<RustFSTestEnvi
|
||||
Ok(env)
|
||||
}
|
||||
|
||||
/// Starts one server of a released binary. `RUSTFS_S3_STACK` is not passed: older releases do not
|
||||
/// know it and have exactly one stack.
|
||||
/// Starts one server of a released binary.
|
||||
async fn start_reference(binary: &Path, region: Option<&str>) -> Result<RustFSTestEnvironment, BoxError> {
|
||||
let mut env = RustFSTestEnvironment::new().await?;
|
||||
let mut vars = Vec::new();
|
||||
@@ -111,11 +107,11 @@ async fn start_reference(binary: &Path, region: Option<&str>) -> Result<RustFSTe
|
||||
async fn spawn_pair(config: &PairConfig) -> Result<(RustFSTestEnvironment, RustFSTestEnvironment), BoxError> {
|
||||
let side_a = async {
|
||||
match &config.side_a {
|
||||
SideA::SameBinary => start_stack(STACK_A, config.region_a.as_deref()).await,
|
||||
SideA::SameBinary => start_under_test(config.region_a.as_deref()).await,
|
||||
SideA::Reference(binary) => start_reference(binary, config.region_a.as_deref()).await,
|
||||
}
|
||||
};
|
||||
tokio::try_join!(side_a, start_stack(&config.stack_b, config.region_b.as_deref()))
|
||||
tokio::try_join!(side_a, start_under_test(config.region_b.as_deref()))
|
||||
}
|
||||
|
||||
fn report_directory() -> PathBuf {
|
||||
@@ -160,7 +156,7 @@ async fn run_differential(label: &str, config: &PairConfig) -> Run {
|
||||
schema: 2,
|
||||
run: format!("{label}-{millis}-{}", std::process::id()),
|
||||
stack_a: config.stack_a_label().to_owned(),
|
||||
stack_b: config.stack_b.clone(),
|
||||
stack_b: UNDER_TEST.to_owned(),
|
||||
reference_side: matches!(config.side_a, SideA::Reference(_)).then_some("a"),
|
||||
version_a,
|
||||
version_b,
|
||||
@@ -235,7 +231,6 @@ mod tests {
|
||||
init_logging();
|
||||
let config = PairConfig {
|
||||
side_a: SideA::SameBinary,
|
||||
stack_b: STACK_A.to_owned(),
|
||||
region_a: Some(CONTROL_REGION_A.to_owned()),
|
||||
region_b: Some(CONTROL_REGION_B.to_owned()),
|
||||
};
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
//! Which binary side A of the differential runs, and what it reports about itself.
|
||||
//!
|
||||
//! `RUSTFS_E2E_REFERENCE_BINARY` names a released `rustfs` binary to use as the reference. Unset,
|
||||
//! side A is the binary under test on `RUSTFS_S3_STACK=legacy`. Set, it must resolve to an
|
||||
//! side A is the binary under test. Set, it must resolve to an
|
||||
//! executable file or the run fails: a reference that was asked for and silently replaced by the
|
||||
//! binary under test would report an agreement with itself as agreement with the release.
|
||||
|
||||
@@ -28,9 +28,9 @@ pub(super) const ENV_REFERENCE_BINARY: &str = "RUSTFS_E2E_REFERENCE_BINARY";
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub(super) enum SideA {
|
||||
/// Both sides are the binary under test; A runs `RUSTFS_S3_STACK=legacy`.
|
||||
/// Both sides are the binary under test.
|
||||
SameBinary,
|
||||
/// A is this released binary, started without `RUSTFS_S3_STACK`.
|
||||
/// A is this released binary.
|
||||
Reference(PathBuf),
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@ pub mod chaos;
|
||||
#[cfg(test)]
|
||||
pub mod fake_s3_target;
|
||||
|
||||
// Dual-stack differential (rustfs/backlog#2740): one binary, two processes on
|
||||
// different RUSTFS_S3_STACK values, the same SDK script for every S3 operation,
|
||||
// Differential (rustfs/backlog#2740): two processes, the binary under test against
|
||||
// itself or a released reference binary, the same SDK script for every S3 operation,
|
||||
// compared on status, error code, allowlisted headers and typed body fields.
|
||||
#[cfg(test)]
|
||||
mod dual_stack_differential;
|
||||
|
||||
@@ -1405,7 +1405,7 @@ impl BucketMetadata {
|
||||
/// | public access block | Fails closed in `get_public_access_block_config`: degrading grants the anonymous access the operator asked to block. |
|
||||
/// | quota | Fails closed in `get_quota_config`; the enforcement path in `quota::checker` already re-parses the raw JSON and refuses on error. |
|
||||
/// | lifecycle | `get_lifecycle_config` fails closed, so GetBucketLifecycle reports the fault instead of NoSuchLifecycleConfiguration. ILM, scanner and expiry-header consumers still degrade to "no rules": nothing is deleted or moved on the strength of an unreadable rule set, and the bucket keeps serving reads and writes. |
|
||||
/// | notification | `get_notification_config` fails closed, so GetBucketNotificationConfiguration reports the fault and startup leaves that one bucket's rules unchanged instead of clearing them; other buckets are unaffected. |
|
||||
/// | notification | `get_notification_config` fails closed, so GetBucketNotificationConfiguration reports the fault and startup skips that bucket's rule registration; metadata-bound server dispatch suppresses external delivery for the unreadable snapshot. Other buckets are unaffected. |
|
||||
/// | tagging, CORS, logging, website, accelerate, request payment | The getter fails closed so the matching GET API reports the fault instead of "not configured". Per-request consumers (CORS response headers) still degrade to "not configured", which is the restrictive direction. |
|
||||
/// | bucket ACL | Safe to degrade: it only shapes an optional response. |
|
||||
///
|
||||
|
||||
@@ -2612,6 +2612,10 @@ impl BucketMetadataSys {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn cached_metadata(&self) -> Vec<Arc<BucketMetadata>> {
|
||||
self.metadata_map.read().await.values().cloned().collect()
|
||||
}
|
||||
|
||||
pub async fn set(&self, bucket: String, bm: Arc<BucketMetadata>) {
|
||||
self.revoke_pending_bucket_creation(&bucket).await;
|
||||
bump_local_meta_mutation_gen();
|
||||
@@ -5760,6 +5764,64 @@ mod tests {
|
||||
assert_eq!(tags.tag_set.len(), WRITERS, "every concurrent rewrite must survive: {tags:?}");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn notification_snapshots_follow_periodic_refresh_after_lost_peer_signals() {
|
||||
let (dirs, store) = isolated_store_over_temp_disks().await;
|
||||
let writer = BucketMetadataSys::new(store.clone());
|
||||
let peer = Arc::new(RwLock::new(BucketMetadataSys::new(store.clone())));
|
||||
let bucket = "notification-periodic-snapshots";
|
||||
for dir in &dirs {
|
||||
std::fs::create_dir_all(dir.path().join(bucket)).expect("create empty fixture bucket");
|
||||
}
|
||||
let mut original = BucketMetadata::new(bucket);
|
||||
original.notification_config_xml = concat!(
|
||||
"<NotificationConfiguration><QueueConfiguration><Event>s3:ObjectCreated:Put</Event>",
|
||||
"<Queue>arn:rustfs:sqs:us-east-1:inert:webhook</Queue></QueueConfiguration></NotificationConfiguration>"
|
||||
)
|
||||
.as_bytes()
|
||||
.to_vec();
|
||||
original.parse_all_configs().expect("parse inert subscription");
|
||||
writer
|
||||
.persist_new_and_set(original)
|
||||
.await
|
||||
.expect("persist initial subscription");
|
||||
peer.read().await.reload_from_store(bucket).await.expect("prime peer cache");
|
||||
let old = peer.read().await.get(bucket).await.expect("cached original snapshot");
|
||||
|
||||
let mut removed = (*old).clone();
|
||||
removed.notification_config_xml = b"<NotificationConfiguration/>".to_vec();
|
||||
removed.parse_all_configs().expect("parse removed subscription");
|
||||
writer
|
||||
.persist_new_and_set(removed)
|
||||
.await
|
||||
.expect("persist removal without peer callback");
|
||||
assert!(Arc::ptr_eq(&old, &peer.read().await.get(bucket).await.expect("peer remains stale")));
|
||||
|
||||
// Exercise the timer's actual one-pass entry point, not the peer RPC.
|
||||
refresh_buckets_metadata_once(peer.clone()).await;
|
||||
let snapshots = peer.read().await.cached_metadata().await;
|
||||
assert_eq!(snapshots.len(), 1);
|
||||
assert!(!Arc::ptr_eq(&old, &snapshots[0]));
|
||||
assert_eq!(old.bucket_incarnation_id, snapshots[0].bucket_incarnation_id);
|
||||
assert_eq!(snapshots[0].notification_config_xml, b"<NotificationConfiguration/>");
|
||||
assert!(
|
||||
snapshots[0]
|
||||
.notification_config
|
||||
.as_ref()
|
||||
.expect("parsed removal")
|
||||
.behavior()
|
||||
.queue_routes
|
||||
.is_empty()
|
||||
);
|
||||
|
||||
for dir in &dirs {
|
||||
std::fs::remove_dir(dir.path().join(bucket)).expect("remove empty fixture bucket without peer callback");
|
||||
}
|
||||
refresh_buckets_metadata_once(peer.clone()).await;
|
||||
assert!(peer.read().await.cached_metadata().await.is_empty());
|
||||
assert!(peer.read().await.get(bucket).await.is_err());
|
||||
}
|
||||
|
||||
/// Pins the peer reload-notification contract (`reload_from_store`, the
|
||||
/// LoadBucketMetadata RPC path): only metadata actually read from
|
||||
/// persisted storage enters the cache. A load miss errors out and leaves
|
||||
|
||||
@@ -775,6 +775,15 @@ impl ECStore {
|
||||
sys.read().await.get(bucket).await
|
||||
}
|
||||
|
||||
/// Snapshots this instance's cached bucket metadata without disk IO.
|
||||
///
|
||||
/// # Errors
|
||||
/// Returns an error when this instance's metadata system is not initialized.
|
||||
pub async fn cached_bucket_metadata(&self) -> Result<Vec<Arc<BucketMetadata>>> {
|
||||
let sys = metadata_sys::require_bucket_metadata_sys_in(&self.ctx)?;
|
||||
Ok(sys.read().await.cached_metadata().await)
|
||||
}
|
||||
|
||||
/// Resolve stored tags for authorization. Only confirmed absence returns an
|
||||
/// empty map; unavailable, fabricated or malformed metadata must not grant access.
|
||||
pub async fn get_bucket_tags_for_policy(&self, bucket: &str) -> Result<HashMap<String, String>> {
|
||||
|
||||
@@ -47,12 +47,18 @@ impl NotifyBucketConfigManager {
|
||||
}
|
||||
|
||||
pub async fn has_subscriber(&self, bucket: &str, event: &EventName) -> bool {
|
||||
if !self.subscriber_view.has_subscriber(bucket, event) {
|
||||
// The standalone index is only a fast negative check for name-only
|
||||
// rules. Metadata-bound rules can change without an index callback.
|
||||
if !self.rule_engine.uses_bucket_metadata_source() && !self.subscriber_view.has_subscriber(bucket, event) {
|
||||
return false;
|
||||
}
|
||||
self.rule_engine.has_subscriber(bucket, event).await
|
||||
}
|
||||
|
||||
pub(crate) fn bind_bucket_metadata_source(&self, store: &Arc<crate::NotifyStore>) {
|
||||
self.rule_engine.bind_bucket_metadata_source(store);
|
||||
}
|
||||
|
||||
/// Validates that the runtime can accept `cfg` for `bucket` without
|
||||
/// mutating any state.
|
||||
pub async fn validate_bucket_notification_config(
|
||||
|
||||
@@ -249,6 +249,16 @@ impl NotificationSystem {
|
||||
self.services.bucket_config_manager.has_subscriber(bucket, event).await
|
||||
}
|
||||
|
||||
/// Binds server dispatch to the store-owned metadata cache. Local writes,
|
||||
/// peer reloads, deletes and periodic metadata refreshes then select rules
|
||||
/// from the same snapshot; delayed name-only rule replacements are ignored
|
||||
/// and clears only evict compiled snapshots. Missing/unreadable metadata or
|
||||
/// a dropped store suppresses external dispatch without falling back to the
|
||||
/// standalone rules. Already queued or in-flight deliveries are not recalled.
|
||||
pub fn bind_bucket_metadata_source(&self, store: &Arc<crate::NotifyStore>) {
|
||||
self.services.bucket_config_manager.bind_bucket_metadata_source(store);
|
||||
}
|
||||
|
||||
/// Returns true when at least one in-process consumer is subscribed to live events.
|
||||
pub fn has_live_listeners(&self) -> bool {
|
||||
self.services.pipeline.has_live_listeners()
|
||||
|
||||
@@ -12,12 +12,14 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use crate::rules::xml_config::{FilterRule, S3KeyFilter};
|
||||
use crate::rules::{RulesMap, TargetIdSet};
|
||||
use crate::storage_api::bucket_metadata::{BucketMetadata, NotifyStore};
|
||||
use percent_encoding::percent_decode_str;
|
||||
use rustfs_s3_types::EventName;
|
||||
use rustfs_targets::arn::TargetID;
|
||||
use rustfs_targets::arn::{ARN, TargetID};
|
||||
use starshard::{AsyncShardedHashMap, DEFAULT_SHARDS, SnapshotMode};
|
||||
use std::sync::Arc;
|
||||
use std::sync::{Arc, RwLock, Weak};
|
||||
use tracing::info;
|
||||
|
||||
const LOG_COMPONENT_NOTIFY: &str = "notify";
|
||||
@@ -35,20 +37,82 @@ fn decoded_object_key_for_matching(object_key: &str) -> Option<String> {
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct NotifyRuleEngine {
|
||||
bucket_rules_map: Arc<AsyncShardedHashMap<String, RulesMap, rustc_hash::FxBuildHasher>>,
|
||||
bucket_rules_map: Arc<AsyncShardedHashMap<String, CachedBucketRules, rustc_hash::FxBuildHasher>>,
|
||||
// Never hold this short synchronous guard across an await. Metadata cache
|
||||
// reads precede the compiled-rules cache, so there is no reverse lock order.
|
||||
metadata_source: Arc<RwLock<Option<Weak<NotifyStore>>>>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct CachedBucketRules {
|
||||
metadata: Option<Weak<BucketMetadata>>,
|
||||
// Cache rejected snapshots too, so corrupt persisted routes are not
|
||||
// repeatedly compiled on the event hot path.
|
||||
rules: Option<RulesMap>,
|
||||
}
|
||||
|
||||
fn rules_from_metadata(metadata: &BucketMetadata) -> Option<RulesMap> {
|
||||
let mut rules = RulesMap::new();
|
||||
let Some(config) = metadata.notification_config.as_ref() else {
|
||||
// Unreadable metadata is not authority to keep an old subscription.
|
||||
return metadata.notification_config_xml.is_empty().then_some(rules);
|
||||
};
|
||||
let config = config.behavior();
|
||||
for route in config
|
||||
.queue_routes
|
||||
.into_iter()
|
||||
.chain(config.topic_routes)
|
||||
.chain(config.lambda_routes)
|
||||
{
|
||||
let target = ARN::parse(&route.destination).ok()?.target_id;
|
||||
let events: Vec<_> = route.events.iter().filter_map(|event| EventName::parse(event).ok()).collect();
|
||||
let mut filter = S3KeyFilter::default();
|
||||
for (name, value) in route.filter_rules.into_iter().flatten() {
|
||||
filter.filter_rule_list.push(FilterRule {
|
||||
name: name?,
|
||||
value: value?,
|
||||
});
|
||||
}
|
||||
filter.validate().ok()?;
|
||||
rules.add_rule_config(&events, filter.pattern(), target);
|
||||
}
|
||||
Some(rules)
|
||||
}
|
||||
|
||||
impl NotifyRuleEngine {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
bucket_rules_map: Arc::new(AsyncShardedHashMap::with_snapshot_mode(DEFAULT_SHARDS, SnapshotMode::Cached)),
|
||||
metadata_source: Arc::new(RwLock::new(None)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Uses this store's immutable metadata snapshots as rule authority. Once
|
||||
/// bound, missing metadata or a dropped store fails closed, never falling
|
||||
/// back to the standalone name-only table. The weak handle avoids cycles.
|
||||
pub fn bind_bucket_metadata_source(&self, store: &Arc<NotifyStore>) {
|
||||
*self.metadata_source.write().unwrap_or_else(|err| err.into_inner()) = Some(Arc::downgrade(store));
|
||||
}
|
||||
|
||||
fn metadata_source(&self) -> Option<Weak<NotifyStore>> {
|
||||
self.metadata_source.read().unwrap_or_else(|err| err.into_inner()).clone()
|
||||
}
|
||||
|
||||
pub(crate) fn uses_bucket_metadata_source(&self) -> bool {
|
||||
self.metadata_source().is_some()
|
||||
}
|
||||
|
||||
pub async fn is_target_bound_to_any_bucket(&self, target_id: &TargetID) -> bool {
|
||||
if let Some(source) = self.metadata_source() {
|
||||
let Some(store) = source.upgrade() else { return true };
|
||||
let Ok(metadata) = store.cached_bucket_metadata().await else { return true };
|
||||
return metadata
|
||||
.iter()
|
||||
.any(|metadata| rules_from_metadata(metadata).is_none_or(|rules| rules.contains_target_id(target_id)));
|
||||
}
|
||||
let items = self.bucket_rules_map.iter().await;
|
||||
for (_bucket, rules_map) in items {
|
||||
if rules_map.contains_target_id(target_id) {
|
||||
if rules_map.rules.is_some_and(|rules| rules.contains_target_id(target_id)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -56,11 +120,24 @@ impl NotifyRuleEngine {
|
||||
}
|
||||
|
||||
pub async fn set_bucket_rules(&self, bucket: &str, rules_map: RulesMap) {
|
||||
if self.uses_bucket_metadata_source() {
|
||||
// Delayed PUT/startup callbacks cannot override a newer revision or
|
||||
// a same-name replacement. Only published metadata is authoritative.
|
||||
return;
|
||||
}
|
||||
let event_count = rules_map.iter_events().count();
|
||||
if rules_map.is_empty() {
|
||||
self.bucket_rules_map.remove(&bucket.to_string()).await;
|
||||
} else {
|
||||
self.bucket_rules_map.insert(bucket.to_string(), rules_map).await;
|
||||
self.bucket_rules_map
|
||||
.insert(
|
||||
bucket.to_string(),
|
||||
CachedBucketRules {
|
||||
metadata: None,
|
||||
rules: Some(rules_map),
|
||||
},
|
||||
)
|
||||
.await;
|
||||
}
|
||||
info!(
|
||||
event = EVENT_NOTIFY_RULES_UPDATED,
|
||||
@@ -74,7 +151,47 @@ impl NotifyRuleEngine {
|
||||
}
|
||||
|
||||
pub async fn get_bucket_rules(&self, bucket: &str) -> Option<RulesMap> {
|
||||
self.bucket_rules_map.get(&bucket.to_string()).await
|
||||
if let Some(source) = self.metadata_source() {
|
||||
let metadata = match source.upgrade() {
|
||||
Some(store) => store.get_bucket_metadata(bucket).await.ok(),
|
||||
None => None,
|
||||
};
|
||||
return self.rules_for_metadata(bucket, metadata).await;
|
||||
}
|
||||
self.bucket_rules_map
|
||||
.get(&bucket.to_string())
|
||||
.await
|
||||
.and_then(|cached| cached.rules)
|
||||
}
|
||||
|
||||
async fn rules_for_metadata(&self, bucket: &str, metadata: Option<Arc<BucketMetadata>>) -> Option<RulesMap> {
|
||||
let key = bucket.to_owned();
|
||||
let Some(metadata) = metadata else {
|
||||
self.bucket_rules_map.remove(&key).await;
|
||||
return None;
|
||||
};
|
||||
if let Some(cached) = self.bucket_rules_map.get(&key).await
|
||||
&& cached
|
||||
.metadata
|
||||
.as_ref()
|
||||
.is_some_and(|snapshot| Weak::ptr_eq(snapshot, &Arc::downgrade(&metadata)))
|
||||
{
|
||||
return cached.rules;
|
||||
}
|
||||
// Snapshot identity covers incarnation, revision AND bytes, without
|
||||
// trusting wall-clock ordering. A late compilation may evict a newer
|
||||
// cache entry, but cannot be reused by a reader of a different snapshot.
|
||||
let rules = rules_from_metadata(&metadata);
|
||||
self.bucket_rules_map
|
||||
.insert(
|
||||
key,
|
||||
CachedBucketRules {
|
||||
metadata: Some(Arc::downgrade(&metadata)),
|
||||
rules: rules.clone(),
|
||||
},
|
||||
)
|
||||
.await;
|
||||
rules
|
||||
}
|
||||
|
||||
pub async fn clear_bucket_rules(&self, bucket: &str) {
|
||||
@@ -119,8 +236,177 @@ impl Default for NotifyRuleEngine {
|
||||
mod tests {
|
||||
use super::NotifyRuleEngine;
|
||||
use crate::rules::RulesMap;
|
||||
use crate::storage_api::bucket_metadata::{BucketMetadata, deserialize_bucket_config};
|
||||
use rustfs_s3_types::EventName;
|
||||
use rustfs_targets::arn::TargetID;
|
||||
use std::sync::{Arc, Weak};
|
||||
|
||||
fn metadata(target: &str) -> Arc<BucketMetadata> {
|
||||
let mut metadata = BucketMetadata::new("bucket");
|
||||
metadata.notification_config_xml = format!(
|
||||
"<NotificationConfiguration><QueueConfiguration><Event>s3:ObjectCreated:Put</Event>\
|
||||
<Queue>arn:rustfs:sqs:us-east-1:{target}:webhook</Queue></QueueConfiguration></NotificationConfiguration>"
|
||||
)
|
||||
.into_bytes();
|
||||
metadata.notification_config =
|
||||
Some(deserialize_bucket_config(&metadata.notification_config_xml).expect("parse inert notification fixture"));
|
||||
Arc::new(metadata)
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn notification_snapshot_cache_never_reuses_replaced_incarnation_or_revision() {
|
||||
let engine = NotifyRuleEngine::new();
|
||||
let old = metadata("old");
|
||||
let mut replacement = (*metadata("new")).clone();
|
||||
// Identical timestamps must not make different configurations equal.
|
||||
replacement.notification_config_updated_at = old.notification_config_updated_at;
|
||||
let replacement = Arc::new(replacement);
|
||||
assert_ne!(old.bucket_incarnation_id, replacement.bucket_incarnation_id);
|
||||
let old_target = TargetID::new("old".into(), "webhook".into());
|
||||
let new_target = TargetID::new("new".into(), "webhook".into());
|
||||
|
||||
for (snapshot, wanted, unwanted) in [
|
||||
(old.clone(), &old_target, &new_target),
|
||||
(replacement.clone(), &new_target, &old_target),
|
||||
// Simulate a late compilation of a captured, older snapshot.
|
||||
(old.clone(), &old_target, &new_target),
|
||||
(replacement.clone(), &new_target, &old_target),
|
||||
] {
|
||||
let rules = engine
|
||||
.rules_for_metadata("bucket", Some(snapshot))
|
||||
.await
|
||||
.expect("readable snapshot");
|
||||
let targets = rules.match_rules(EventName::ObjectCreatedPut, "object");
|
||||
assert!(targets.contains(wanted));
|
||||
assert!(!targets.contains(unwanted));
|
||||
}
|
||||
|
||||
let mut next_revision = (*old).clone();
|
||||
next_revision.notification_config = replacement.notification_config.clone();
|
||||
next_revision.notification_config_xml = replacement.notification_config_xml.clone();
|
||||
let rules = engine
|
||||
.rules_for_metadata("bucket", Some(Arc::new(next_revision)))
|
||||
.await
|
||||
.expect("same-incarnation revision");
|
||||
assert!(!rules.contains_target_id(&old_target));
|
||||
assert!(rules.contains_target_id(&new_target));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn notification_snapshot_absence_and_corruption_never_fall_back_to_old_rules() {
|
||||
let engine = NotifyRuleEngine::new();
|
||||
let old = metadata("old");
|
||||
assert!(engine.rules_for_metadata("bucket", Some(old.clone())).await.is_some());
|
||||
|
||||
let mut unreadable = (*old).clone();
|
||||
unreadable.notification_config = None;
|
||||
unreadable.notification_config_xml = b"<broken>".to_vec();
|
||||
assert!(
|
||||
engine
|
||||
.rules_for_metadata("bucket", Some(Arc::new(unreadable)))
|
||||
.await
|
||||
.is_none()
|
||||
);
|
||||
assert!(
|
||||
engine
|
||||
.bucket_rules_map
|
||||
.get(&"bucket".to_owned())
|
||||
.await
|
||||
.expect("cache rejected snapshot")
|
||||
.rules
|
||||
.is_none()
|
||||
);
|
||||
assert!(engine.rules_for_metadata("bucket", None).await.is_none());
|
||||
assert!(engine.bucket_rules_map.get(&"bucket".to_owned()).await.is_none());
|
||||
|
||||
// A recreated bucket without notifications has no inherited targets.
|
||||
let replacement = Arc::new(BucketMetadata::new("bucket"));
|
||||
assert!(
|
||||
engine
|
||||
.rules_for_metadata("bucket", Some(replacement))
|
||||
.await
|
||||
.expect("empty snapshot")
|
||||
.is_empty()
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn notification_snapshot_binding_never_falls_back_after_store_loss() {
|
||||
let engine = NotifyRuleEngine::new();
|
||||
let target = TargetID::new("old".into(), "webhook".into());
|
||||
let mut rules = RulesMap::new();
|
||||
rules.add_rule_config(&[EventName::ObjectCreatedPut], "*".into(), target.clone());
|
||||
engine.set_bucket_rules("bucket", rules.clone()).await;
|
||||
assert!(engine.has_subscriber("bucket", &EventName::ObjectCreatedPut).await);
|
||||
|
||||
*engine.metadata_source.write().expect("metadata source lock") = Some(Weak::new());
|
||||
// A delayed validated PUT must not revive the standalone table, even
|
||||
// when its owning store is gone. Target removal also fails closed.
|
||||
engine.set_bucket_rules("bucket", rules).await;
|
||||
assert!(!engine.has_subscriber("bucket", &EventName::ObjectCreatedPut).await);
|
||||
assert!(
|
||||
engine
|
||||
.match_targets("bucket", EventName::ObjectCreatedPut, "object")
|
||||
.await
|
||||
.is_empty()
|
||||
);
|
||||
assert!(engine.is_target_bound_to_any_bucket(&target).await);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn notification_snapshot_compilation_preserves_destinations_events_and_filters() {
|
||||
let mut metadata = (*metadata("queue")).clone();
|
||||
metadata.notification_config_xml = concat!(
|
||||
"<NotificationConfiguration>",
|
||||
"<QueueConfiguration><Event>s3:ObjectCreated:*</Event><Event>s3:Future:Unrecognized</Event>",
|
||||
"<Queue>arn:rustfs:sqs:us-east-1:queue:webhook</Queue>",
|
||||
"<Filter><S3Key><FilterRule><Name>Prefix</Name><Value>logs/</Value></FilterRule>",
|
||||
"<FilterRule><Name>Suffix</Name><Value>.csv</Value></FilterRule></S3Key></Filter></QueueConfiguration>",
|
||||
"<TopicConfiguration><Event>s3:ObjectRemoved:*</Event><Topic>arn:rustfs:sqs:us-east-1:topic:webhook</Topic></TopicConfiguration>",
|
||||
"<CloudFunctionConfiguration><Event>s3:ObjectCreated:Put</Event>",
|
||||
"<CloudFunction>arn:rustfs:sqs:us-east-1:lambda:webhook</CloudFunction></CloudFunctionConfiguration>",
|
||||
"</NotificationConfiguration>"
|
||||
).as_bytes().to_vec();
|
||||
metadata.notification_config =
|
||||
Some(deserialize_bucket_config(&metadata.notification_config_xml).expect("parse destinations"));
|
||||
let rules = super::rules_from_metadata(&metadata).expect("compile destinations");
|
||||
assert_eq!(rules.match_rules(EventName::ObjectCreatedPut, "logs/data.csv").len(), 2);
|
||||
assert_eq!(rules.match_rules(EventName::ObjectCreatedPut, "other/data.csv").len(), 1);
|
||||
assert_eq!(rules.match_rules(EventName::ObjectCreatedPut, "logs/data.txt").len(), 1);
|
||||
let removed = rules.match_rules(EventName::ObjectRemovedDelete, "object");
|
||||
assert_eq!(removed.len(), 1);
|
||||
assert!(removed.contains(&TargetID::new("topic".into(), "webhook".into())));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn notification_snapshot_compilation_rejects_invalid_persisted_routes() {
|
||||
for (destination, filter) in [
|
||||
("not-an-arn", ""),
|
||||
(
|
||||
"arn:rustfs:sqs:us-east-1:inert:webhook",
|
||||
"<Filter><S3Key><FilterRule><Value>logs/</Value></FilterRule></S3Key></Filter>",
|
||||
),
|
||||
(
|
||||
"arn:rustfs:sqs:us-east-1:inert:webhook",
|
||||
concat!(
|
||||
"<Filter><S3Key><FilterRule><Name>prefix</Name><Value>logs/</Value></FilterRule>",
|
||||
"<FilterRule><Name>Prefix</Name><Value>private/</Value></FilterRule></S3Key></Filter>"
|
||||
),
|
||||
),
|
||||
] {
|
||||
let mut metadata = BucketMetadata::new("bucket");
|
||||
metadata.notification_config_xml = format!(
|
||||
"<NotificationConfiguration><QueueConfiguration><Event>s3:ObjectCreated:Put</Event>\
|
||||
<Queue>{destination}</Queue>{filter}</QueueConfiguration></NotificationConfiguration>"
|
||||
)
|
||||
.into_bytes();
|
||||
metadata.notification_config = Some(
|
||||
deserialize_bucket_config(&metadata.notification_config_xml)
|
||||
.expect("parse invalid but well-formed persisted route"),
|
||||
);
|
||||
assert!(super::rules_from_metadata(&metadata).is_none(), "invalid route must not dispatch");
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn rule_engine_tracks_bucket_rule_lifecycle() {
|
||||
|
||||
@@ -70,3 +70,10 @@ pub(crate) mod crate_boundary {
|
||||
save_notify_server_config_snapshot, with_notify_server_config_read_lock,
|
||||
};
|
||||
}
|
||||
|
||||
pub(crate) mod bucket_metadata {
|
||||
pub(crate) use super::NotifyStore;
|
||||
pub(crate) use rustfs_ecstore::api::bucket::metadata::BucketMetadata;
|
||||
#[cfg(test)]
|
||||
pub(crate) use rustfs_ecstore::api::bucket::utils::deserialize as deserialize_bucket_config;
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ For batch-delete codec acceptance, run `delete_versions_request_encoding_preserv
|
||||
```bash
|
||||
cargo nextest run -p rustfs-ecstore --lib --features test-util --no-tests fail \
|
||||
-E 'test(delete_versions_request_encoding_preserves_batches_and_fleet_guards)'
|
||||
NO_PROXY='*' no_proxy='*' cargo nextest run -p rustfs --lib --features gateway-stack --no-tests fail \
|
||||
NO_PROXY='*' no_proxy='*' cargo nextest run -p rustfs --lib --no-tests fail \
|
||||
-E 'test(delete_versions_wire_roundtrip_preserves_json_and_binary_only_batches)'
|
||||
```
|
||||
|
||||
|
||||
@@ -56,13 +56,11 @@ The four site-replication state-writer concurrency proofs reserve the available
|
||||
| PR, non-doc change | `Typos` | `ci.yml` `typos` | Via aggregate | `typos` |
|
||||
| Full selection | `Workspace tests` (serial ILM step) | `ci.yml` `workspace-tests` | Via aggregate | exact `Run ignored ILM integration tests serially` command in the job |
|
||||
| Nightly schedule, manual dispatch | `Test and Lint (rio-v2)`, `Test and Lint (swift)`, `Test and Lint (sftp)`, `Test and Lint (http3)` | `ci.yml` `test-and-lint-rio-v2`, `test-and-lint-protocols` | Via aggregate on these events; skipped on PRs, merge groups and main pushes | `cargo nextest run` with the job's `--features` |
|
||||
| Full selection, every event | `Test and Lint (gateway-stack)` | `ci.yml` `test-and-lint-gateway-stack` | Via aggregate | `cargo clippy -p rustfs --all-targets --features gateway-stack -- -D warnings`; `cargo nextest run -p rustfs --features gateway-stack` with the job's filter |
|
||||
| Nightly schedule, manual dispatch, full selection | `Connect Feature Boundaries` | `ci.yml` `connect-feature-boundaries` | Via aggregate on these events; skipped on PRs, merge groups and main pushes | `cargo test -p rustfs --test connect_registration --features connect-e2e-short-credentials`; `scripts/check_connect_release_boundary.py`: `cargo check -p rustfs --release` with `connect-e2e-short-credentials` and with `gateway-stack` must each fail at its guard; `scripts/check_offline_enrollment_e2e.sh` |
|
||||
| Nightly schedule, manual dispatch, full selection | `Connect Feature Boundaries` | `ci.yml` `connect-feature-boundaries` | Via aggregate on these events; skipped on PRs, merge groups and main pushes | `cargo test -p rustfs --test connect_registration --features connect-e2e-short-credentials`; `scripts/check_connect_release_boundary.py`: `cargo check -p rustfs --release` with `connect-e2e-short-credentials` must fail at its guard; `scripts/check_offline_enrollment_e2e.sh` |
|
||||
| PR, non-doc change | `Build RustFS Debug Binary` | `ci.yml` `build-rustfs-debug-binary` | Via aggregate; prerequisite for black-box jobs | `python3 scripts/e2e_binary.py build --bins --features e2e-test-hooks` (binary plus its `rustfs.e2e.json` sidecar) |
|
||||
| Nightly schedule, manual dispatch, full selection | `io_uring Integration (real)` | `ci.yml` `uring-integration` | Via aggregate on these events; skipped on PRs, merge groups and main pushes | `cargo test -p rustfs-ecstore --lib uring_ -- --test-threads=1 --nocapture` |
|
||||
| PR, non-doc change | `End-to-End Tests` | `ci.yml` `e2e-tests` | Via aggregate | `python3 scripts/e2e_binary.py run --features e2e-test-hooks -- cargo nextest run --profile e2e-smoke -p e2e_test`, then `./scripts/e2e-run.sh ./target/debug/rustfs <data-dir>` under the same wrapper; membership guards `scripts/check_test_wiring.py --check-profile e2e-smoke <listing.json>` and `scripts/check_security_smoke_count.sh check <listing.json>` |
|
||||
| PR, non-doc change | `Core contract` | `ci.yml` `core-contract` | Via aggregate | existing write/read, anonymous denial and restart-byte tests via `core-contract` profile and the E2E archive |
|
||||
| Push to `main` or `gateway/integration`, merge group, nightly schedule, manual dispatch; PR only when it changes a gateway-stack input (`GATEWAY_SMOKE_PATHS` or a `rustfs-gateway*` pin, `scripts/ci_gate.py`) | `e2e-smoke (gateway, report-only until T2.10)` | `ci.yml` `e2e-tests-gateway` | Report-only until rustfs/backlog#2734 T2.10 makes it required; `continue-on-error`, outside the aggregate; skipped, never green, on PRs that touch no gateway-stack input. At T2.10, when the lane becomes required, it must run on every pull request again — delete this selection, do not extend it | `RUSTFS_S3_STACK=gateway python3 scripts/e2e_binary.py run --features e2e-test-hooks -- cargo nextest run --profile e2e-smoke -p e2e_test`; `scripts/ci_gate.py` keeps its archive and run steps identical to `e2e-tests`, which sets `RUSTFS_S3_STACK=legacy` on this branch |
|
||||
| PR, non-doc change | `S3 Implemented Tests` | `ci.yml` `s3-implemented-tests` | Via aggregate | build `rustfs`, then `scripts/s3-tests/run.sh` with the job's `DEPLOY_MODE` / `TEST_MODE` / `MAXFAIL` env |
|
||||
| PR, non-doc change | `S3 Lifecycle Behavior Tests` | `ci.yml` `s3-lifecycle-behavior-tests` | Via aggregate | `scripts/s3-tests/run.sh` with the job's accelerated-scanner env |
|
||||
| PR touching `paths` in `audit.yml` | `Cargo Deny`, `Workflow Pin Report`, `Dependency Review` | `audit.yml` `cargo-deny`, `workflow-pin-report`, `dependency-review` | Report-only | `cargo deny check`; `scripts/security/check_workflow_pins.sh` |
|
||||
@@ -93,7 +91,7 @@ Scheduled lanes never block a PR. Their workflow-local gate fails the run. The v
|
||||
| `cache-warm.yml` (every six hours, plus main pushes that change `Cargo.lock`, `rust-toolchain.toml` or the setup action) | `warm-ci-dev`, `warm-ci-feat-rio`, `warm-ci-feat-proto`, `warm-ci-uring` | no verdict; sole writer of the `rust-cache` keys that `ci.yml` restores | yes | dispatch `cache-warm.yml` |
|
||||
| `build.yml` (nightly Linux, weekly desktop) | `build-rustfs` over the `prepare-platform-matrix` subset for the firing cron: four Linux targets at 01:13 UTC, and macOS aarch64 plus Windows x86_64 at Sunday 16:17 UTC | build/package integrity | yes | dispatch `build.yml` with an exact platform set |
|
||||
| `e2e-replication-nightly.yml` (nightly) | `repl-nightly`, `cluster-nightly`, `protocols-nightly` | three independent gates; JUnit, membership listing, server logs | yes | `python3 scripts/e2e_binary.py build --bins`, then `python3 scripts/e2e_binary.py run -- cargo nextest run --profile e2e-repl-nightly -p e2e_test`; `--features e2e-test-hooks` on both steps with `--profile e2e-nightly`; `--features ftps,webdav,sftp` on both steps with `-j 1 --profile e2e-protocols` |
|
||||
| `dual-stack-nightly.yml` (nightly) | `build`, `leg` (`e2e-smoke` and `e2e-full`, each on the legacy and, once a gateway start is proven, the gateway stack), `summary` | report-only both-stack diff of the two profiles only `ci.yml` runs; the other e2e profiles carry the same `stack` dimension in their own workflows. A gateway binary that refuses to start skips the gateway legs and the summary says why; the gateway legs are report-only until T2.10 | yes | `python3 scripts/dual_stack.py summary --help`; dispatch `dual-stack-nightly.yml` |
|
||||
| `dual-stack-nightly.yml` (nightly) | `build`, `leg` (`e2e-smoke` and `e2e-full`) | the two profiles only `ci.yml` runs, nightly on the gateway stack (the workflow keeps its name from the both-stack period); per-profile JUnit and server logs retained 30 days. The one comparison against the last legacy record is made by hand with `scripts/junit_diff.py` | yes | dispatch `dual-stack-nightly.yml` |
|
||||
| `e2e-distributed.yml` (nightly) | `distributed` | fail-closed 4-node 4-disk S3, durability, replication, movement, fault, and direct/rolling upgrade gate; JUnit, membership listing, per-node server logs | yes | download the pinned previous release as in the workflow, export `RUSTFS_UPGRADE_SOURCE_BINARY`, run `python3 scripts/e2e_binary.py build --bins --features e2e-test-hooks`, then `python3 scripts/e2e_binary.py run --features e2e-test-hooks -- cargo nextest run --profile e2e-distributed -p e2e_test` |
|
||||
| `e2e-s3tests.yml` (weekly) | `s3tests` (single and distributed, four shards each), `upstream-head-canary` | compatibility gate; report, JUnit, node IDs, server logs | yes | `scripts/s3-tests/run.sh` against an existing single or distributed target |
|
||||
| `fuzz.yml` (nightly) | `nightly-fuzz-corpus` per target | gate; corpus and crash artifacts | yes (disabled) | `MAX_TOTAL_TIME=<seconds> ./scripts/fuzz/run.sh` |
|
||||
@@ -101,12 +99,12 @@ Scheduled lanes never block a PR. Their workflow-local gate fails the run. The v
|
||||
| `on-demand-migration-interop.yml` (nightly) | `minio-source`, `cloud-source` (`aws`, `r2`, `gcs`) | report-only provider interop; one JSON report per provider naming cases, timings and source request counts, plus JUnit and MinIO logs. A cloud provider whose `ODM_INTEROP_*` secrets are absent is skipped with a summary note, not failed | yes | start the pinned MinIO container as in the job, export the `RUSTFS_ODM_INTEROP_*` variables, run `python3 scripts/e2e_binary.py build --bins`, then `python3 scripts/e2e_binary.py run -- cargo nextest run --profile e2e-odm-interop -p e2e_test` |
|
||||
| `nightly-gnu.yml` (nightly) | `build`, `kms-vault-lane`, `kms-vault-ha-failover` | build, live Vault, and HA failover gates | yes | commands and pinned Vault images in the workflow |
|
||||
| `audit.yml` (nightly) | `cargo-deny`, `workflow-pin-report` | dependency and workflow-pin gates | yes | `cargo deny check`; `scripts/security/check_workflow_pins.sh` |
|
||||
| `mint.yml` (weekly) | `image`, `mint` (legacy and gateway), `compare` | report-only by design; per-suite PASS/FAIL/NA and raw `log.json` per stack. The image is built once. `compare` holds the gate that every case legacy passes is present and passing on gateway and prints the cases that break it; the gateway leg and `compare` are report-only until T2.10 | yes | pinned Docker sequence in the workflow; `python3 scripts/mint_stack_diff.py <legacy-leg-dir> <gateway-leg-dir>` |
|
||||
| `mint.yml` (weekly) | `image`, `mint` | report-only by design; per-suite PASS/FAIL/NA and raw `log.json`. The image is built once | yes | pinned Docker sequence in the workflow |
|
||||
| `coverage.yml` (weekly) | `coverage` | report-only trend; lcov and JSON artifact | yes (disabled) | `make coverage` |
|
||||
| `runner-hygiene.yml` (monthly) | `check-ephemerality` | runner ephemerality | yes | dispatch |
|
||||
| `e2e-upgrade.yml` (weekly, and on version tags) | `upgrade` (serial cases sharing one harness build) | upgrade and rollback gate; server logs | yes | `python3 scripts/e2e_binary.py build`, then the job's `python3 scripts/e2e_binary.py run -- cargo test --locked -p e2e_test` commands with `RUSTFS_UPGRADE_SOURCE_BINARY` pointing at the pinned previous release (`UPGRADE_SOURCE_VERSION`) |
|
||||
| `reference-parity.yml` (nightly, and on PRs that change the lane's own files) | `plan`, `build-candidate`, `s3tests` (one job per target in `.config/reference-parity-targets.toml`), `compare` | report-only parity gate: fails on any per-node-id s3-tests difference between a branch candidate and the release pinned in `.config/reference-binary.toml` that `.config/reference-parity-tolerated.txt` does not list, and on a stale tolerated entry; per-target JUnit, logs and `diff.md`/`diff.json` | yes | `DEPLOY_MODE=binary RUSTFS_BINARY=<binary> MAXFAIL=0 XDIST=4 ./scripts/s3-tests/run.sh` once per target, then `python3 scripts/s3-tests/reference_parity.py compare` as in the `compare` job |
|
||||
| `gateway-acceptance.yml` (nightly) | `plan`, `build-candidate`, `build-gateway-tools`, `acceptance` (one job per S3 stack), `compare` | the rustfs/gateway conformance corpus (`--profile rustfs`) and client matrix (`--external`), both checked out at the rev `Cargo.toml` pins. Each stack must be observed in the server's own `server_starting` log event (`scripts/dual_stack.py stack`). Legacy stack: the corpus run is a reference that is never judged (it must serve, stay up and complete); the matrix is the baseline and fails on a `fail` or `sut-unregistered` cell or a client that could not be installed. Gateway stack, report-only until T2.10: fails on a conformance failure without a `.config/conformance-rulings.toml` row, on a ruled case failing differently, on a stale row, on a skip on the server's own answer, and on any matrix cell that passes on legacy but not on gateway. Per-stack `report.json`, `matrix.json` and logs, and a legacy-vs-gateway diff | yes | start the candidate with `RUSTFS_S3_STACK=<stack>`, then the job's `rustfs-gateway-conformance run` and `ci/compat/run_matrix.sh --external` commands, then `python3 scripts/check_conformance_rulings.py` and `python3 scripts/compat_matrix_report.py check` |
|
||||
| `gateway-acceptance.yml` (nightly) | `plan`, `build-candidate`, `build-gateway-tools`, `acceptance` | the rustfs/gateway conformance corpus (`--profile rustfs`) and client matrix (`--external`), both checked out at the rev `Cargo.toml` pins, against one candidate server. Fails on a conformance failure without a `.config/conformance-rulings.toml` row, on a ruled case failing differently, on a stale row, on a skip on the server's own answer, and on a matrix `fail` or `sut-unregistered` cell or a client that could not be installed. `report.json`, `matrix.json` and logs | yes | start the candidate, then the job's `rustfs-gateway-conformance run` and `ci/compat/run_matrix.sh --external` commands, then `python3 scripts/check_conformance_rulings.py --run-dir <dir>` and `python3 scripts/compat_matrix_report.py check --run-dir <dir>` |
|
||||
| `oidc-keycloak.yml` (weekly) | `oidc-keycloak-live` | live OIDC gate | yes | see the PR row |
|
||||
| `targets-integration.yml` (nightly) | `targets-live` | live target gate; container logs | yes (disabled) | see the PR row |
|
||||
| `gateway-integration-sync.yml` (weekdays) | `sync` | merges `main` into `gateway/integration` as a `--no-ff` merge commit; a conflicting merge is aborted and opens a `sync/<source>-<date>` pull request listing the conflicting files, which keeps the run green; a rejected push or missing pull request fails it | yes | dispatch, optionally with `source_ref` |
|
||||
|
||||
+6
-15
@@ -56,12 +56,10 @@ required-features = ["swift"]
|
||||
name = "swift_object_integration_test"
|
||||
required-features = ["swift"]
|
||||
|
||||
# Starts an embedded server on the gateway stack, which only a build with the
|
||||
# feature can select.
|
||||
# Starts an embedded server on the gateway stack.
|
||||
[[test]]
|
||||
name = "embedded_gateway_stack_test"
|
||||
path = "tests/embedded_gateway_stack_test/main.rs"
|
||||
required-features = ["gateway-stack"]
|
||||
|
||||
[features]
|
||||
internode-transport = ["rustfs-ecstore/internode-transport", "rustfs-rio/internode-transport"]
|
||||
@@ -77,19 +75,12 @@ license = []
|
||||
io-scheduler-debug = [] # Enable debug information in I/O scheduler
|
||||
tracing-chunk-debug = [] # Enable per-chunk tracing in data plane (high noise, for debugging only)
|
||||
full = ["metrics-gpu", "ftps", "swift", "webdav", "sftp", "pyroscope", "gcs"]
|
||||
# The debug-only E2E binary also carries the gateway S3 stack, so the gateway smoke
|
||||
# lane runs the same artifact as the legacy one with RUSTFS_S3_STACK as its only change.
|
||||
e2e-test-hooks = ["rustfs-ecstore/e2e-test-hooks", "rustfs-scanner/e2e-test-hooks", "gateway-stack"]
|
||||
e2e-test-hooks = ["rustfs-ecstore/e2e-test-hooks", "rustfs-scanner/e2e-test-hooks"]
|
||||
# Shortens Connect credentials only in debug E2E builds.
|
||||
connect-e2e-short-credentials = []
|
||||
# Builds the dedicated rustfs-cli-e2e target with a build-time public enrollment root.
|
||||
offline-enrollment-e2e-root = []
|
||||
rio-v2 = ["rustfs-ecstore/rio-v2"]
|
||||
# The rustfs-gateway S3 stack, selected at startup with RUSTFS_S3_STACK=gateway
|
||||
# (rustfs/backlog#2734). Under construction: off by default and never enabled in a
|
||||
# release build; the stack refuses to compile without debug assertions, and
|
||||
# `scripts/check_connect_release_boundary.py` keeps every release-reachable feature from enabling it.
|
||||
gateway-stack = ["dep:rustfs-gateway", "dep:rustfs-gateway-adapter", "dep:rustfs-gateway-core", "dep:rustfs-gateway-dialect-rustfs-admin"]
|
||||
# Linux-only cuObject S3-over-RDMA GET into client (GPU) memory; needs libcuobjserver.
|
||||
cuobject = ["dep:rustfs-cuobject", "rustfs-cuobject/server"]
|
||||
# NIXL/UCX transport for S3-over-RDMA; replaces cuobject when both are enabled.
|
||||
@@ -279,10 +270,10 @@ rustfs-notify = { workspace = true }
|
||||
rustfs-obs = { workspace = true }
|
||||
rustfs-policy = { workspace = true }
|
||||
rustfs-protocols = { workspace = true }
|
||||
rustfs-gateway = { workspace = true, optional = true }
|
||||
rustfs-gateway-adapter = { workspace = true, optional = true }
|
||||
rustfs-gateway-core = { workspace = true, optional = true }
|
||||
rustfs-gateway-dialect-rustfs-admin = { workspace = true, optional = true }
|
||||
rustfs-gateway = { workspace = true }
|
||||
rustfs-gateway-adapter = { workspace = true }
|
||||
rustfs-gateway-core = { workspace = true }
|
||||
rustfs-gateway-dialect-rustfs-admin = { workspace = true }
|
||||
rustfs-gateway-stream = { workspace = true }
|
||||
rustfs-gateway-types = { workspace = true, features = ["compat-s3s-rustfs"] }
|
||||
rustfs-protos = { workspace = true }
|
||||
|
||||
@@ -1261,7 +1261,16 @@ async fn table_storage_credentials_are_rejected_by_catalog_authentication() {
|
||||
}
|
||||
let mut credential = get_new_credentials_with_metadata(&claims, root_secret).expect("sign a temporary credential");
|
||||
credential.parent_user = parent.to_string();
|
||||
iam.set_temp_user(&credential.access_key, &credential, None)
|
||||
// A regular parent's sessions must carry its durable STS generation, so publish
|
||||
// through the parent-bound path instead of storing an unversioned session.
|
||||
let parent_secret = if parent == root_key { root_secret } else { parent_secret };
|
||||
let authenticated_parent = rustfs_credentials::Credentials {
|
||||
access_key: parent.to_string(),
|
||||
secret_key: parent_secret.to_string(),
|
||||
status: "on".to_string(),
|
||||
..Default::default()
|
||||
};
|
||||
iam.set_temp_user_from_parent(&credential, &authenticated_parent)
|
||||
.await
|
||||
.expect("store temporary credential");
|
||||
let request = load_table_request_builder(context.clone(), &credential.access_key, &credential.secret_key)
|
||||
|
||||
@@ -916,14 +916,12 @@ async fn handle_object_lambda_request(req: &mut S3Request<Body>, bucket: &str, o
|
||||
invoke_object_lambda_target(req, bucket, object, get_resp).await
|
||||
}
|
||||
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
/// The bucket and key of an Object Lambda request, which takes precedence over every other route
|
||||
/// this router claims; `None` for any other request.
|
||||
pub(crate) fn object_lambda_target(method: &Method, uri: &Uri) -> Option<(String, String)> {
|
||||
parse_object_lambda_request(method, uri)
|
||||
}
|
||||
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
/// Serves an admitted Object Lambda request that another edge verified, through the same handler
|
||||
/// the legacy `call` runs.
|
||||
pub(crate) async fn serve_object_lambda(
|
||||
@@ -973,7 +971,6 @@ pub(crate) fn console_listener_route(method: &Method, uri: &Uri, headers: &Heade
|
||||
|
||||
/// Whether this router answers the request itself rather than an S3 operation: the RustFS extension
|
||||
/// routes and every control-plane route.
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
pub(crate) fn claims_route(method: &Method, uri: &Uri, headers: &HeaderMap) -> bool {
|
||||
s3_extension::route_key(method, uri).is_some()
|
||||
|| parse_object_lambda_request(method, uri).is_some()
|
||||
@@ -981,7 +978,6 @@ pub(crate) fn claims_route(method: &Method, uri: &Uri, headers: &HeaderMap) -> b
|
||||
}
|
||||
|
||||
/// Signed system-status and catalog-configuration reads, after object-lambda routing.
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
pub(crate) fn claims_native_admin_route(method: &Method, uri: &Uri) -> bool {
|
||||
method == Method::GET
|
||||
&& matches!(
|
||||
@@ -1011,7 +1007,6 @@ pub(crate) fn claims_native_admin_route(method: &Method, uri: &Uri) -> bool {
|
||||
}
|
||||
|
||||
/// Console paths whose requests do not belong to an earlier extension route.
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
pub(crate) fn claims_native_console_route(method: &Method, uri: &Uri) -> bool {
|
||||
is_console_path(uri.path())
|
||||
&& parse_object_lambda_request(method, uri).is_none()
|
||||
|
||||
@@ -22,7 +22,7 @@ use super::storage_api::bucket_usecase::StorageObjectInfo as ObjectInfo;
|
||||
#[cfg(test)]
|
||||
use super::storage_api::bucket_usecase::access::ReqInfo;
|
||||
use super::storage_api::bucket_usecase::access::{
|
||||
TableDataPlaneListAccess, authorize_request, bucket_config_mutation_incarnation, log_list_buckets_iam_implicit_deny,
|
||||
authorize_request, bucket_config_mutation_incarnation, log_list_buckets_iam_implicit_deny,
|
||||
prepare_list_buckets_iam_authorization, prepare_odm_read_generation, req_info_ref,
|
||||
};
|
||||
#[cfg(test)]
|
||||
@@ -121,7 +121,6 @@ use tracing::{Instrument as _, debug, error, info, instrument, warn};
|
||||
mod accelerate;
|
||||
mod acl;
|
||||
mod core;
|
||||
#[cfg(any(test, feature = "gateway-stack"))]
|
||||
pub(crate) use self::core::requested_location_constraint;
|
||||
mod cors;
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -22,7 +22,9 @@ use crate::app::storage_api::s3::dto::{
|
||||
UserMetadata,
|
||||
};
|
||||
use crate::app::storage_api::s3::xml::{SerResult, SerializeContent};
|
||||
use crate::app::storage_api::s3::{S3Request, S3Response, S3Result, xml};
|
||||
#[cfg(test)]
|
||||
use crate::app::storage_api::s3::{S3ErrorCode, S3Request, S3Response};
|
||||
use crate::app::storage_api::s3::{S3Result, xml};
|
||||
|
||||
type ListObjectVersionsInfo = StorageListObjectVersionsInfo<ObjectInfo>;
|
||||
|
||||
@@ -320,31 +322,20 @@ fn metadata_count_to_i32(value: usize) -> i32 {
|
||||
i32::try_from(value).unwrap_or(i32::MAX)
|
||||
}
|
||||
|
||||
async fn is_list_objects_metadata_action_allowed<T>(
|
||||
req: &S3Request<T>,
|
||||
async fn is_list_objects_metadata_action_allowed(
|
||||
envelope: &RequestEnvelope,
|
||||
bucket: &str,
|
||||
object: &str,
|
||||
action: S3Action,
|
||||
) -> S3Result<bool> {
|
||||
let mut auth_req = S3Request {
|
||||
input: (),
|
||||
method: req.method.clone(),
|
||||
uri: req.uri.clone(),
|
||||
headers: req.headers.clone(),
|
||||
extensions: req.extensions.clone(),
|
||||
credentials: req.credentials.clone(),
|
||||
region: req.region.clone(),
|
||||
service: req.service.clone(),
|
||||
trailing_headers: req.trailing_headers.clone(),
|
||||
};
|
||||
|
||||
let mut req_info = req_info_ref(req)?.clone();
|
||||
let mut auth_req = envelope.fork_for_authorization();
|
||||
let mut req_info = req_info_ref(envelope)?.clone();
|
||||
req_info.bucket = Some(bucket.to_string());
|
||||
req_info.object = Some(object.to_string());
|
||||
req_info.version_id = None;
|
||||
// Denial here is an expected filter outcome, not an error (issue #5740).
|
||||
req_info.suppress_denial_log = true;
|
||||
auth_req.extensions.insert(req_info);
|
||||
auth_req.install_req_info(req_info);
|
||||
|
||||
match authorize_request(&mut auth_req, Action::S3Action(action)).await {
|
||||
Ok(()) => Ok(true),
|
||||
@@ -353,8 +344,8 @@ async fn is_list_objects_metadata_action_allowed<T>(
|
||||
}
|
||||
}
|
||||
|
||||
async fn collect_list_objects_metadata_permissions<T>(
|
||||
req: &S3Request<T>,
|
||||
async fn collect_list_objects_metadata_permissions(
|
||||
envelope: &RequestEnvelope,
|
||||
bucket: &str,
|
||||
objects: &[ObjectInfo],
|
||||
) -> S3Result<HashMap<String, ObjectMetadataPermissions>> {
|
||||
@@ -366,9 +357,9 @@ async fn collect_list_objects_metadata_permissions<T>(
|
||||
}
|
||||
|
||||
let metadata_allowed =
|
||||
is_list_objects_metadata_action_allowed(req, bucket, &object.name, S3Action::GetObjectAction).await?;
|
||||
is_list_objects_metadata_action_allowed(envelope, bucket, &object.name, S3Action::GetObjectAction).await?;
|
||||
let tags_allowed =
|
||||
is_list_objects_metadata_action_allowed(req, bucket, &object.name, S3Action::GetObjectTaggingAction).await?;
|
||||
is_list_objects_metadata_action_allowed(envelope, bucket, &object.name, S3Action::GetObjectTaggingAction).await?;
|
||||
|
||||
permissions.insert(
|
||||
object.name.clone(),
|
||||
@@ -605,11 +596,22 @@ fn build_list_objects_v2_metadata_output(
|
||||
}
|
||||
|
||||
impl DefaultBucketUsecase {
|
||||
#[cfg(test)]
|
||||
pub(crate) async fn execute_list_objects_v2m(
|
||||
&self,
|
||||
req: S3Request<ListObjectsV2Input>,
|
||||
) -> S3Result<S3Response<ListObjectsV2MetadataOutput>> {
|
||||
let input = req.input.clone();
|
||||
let envelope = RequestEnvelope::from_s3s(&req);
|
||||
self.list_objects_v2_metadata(&envelope, req.input).await.map(S3Response::new)
|
||||
}
|
||||
|
||||
/// One page of `GET /{bucket}?list-type=2&metadata=true`, for the caller the envelope's
|
||||
/// authorization installed: each entry's metadata and tags as far as that caller may read them.
|
||||
pub(crate) async fn list_objects_v2_metadata(
|
||||
&self,
|
||||
envelope: &RequestEnvelope,
|
||||
input: ListObjectsV2Input,
|
||||
) -> S3Result<ListObjectsV2MetadataOutput> {
|
||||
let ListObjectsV2Input {
|
||||
bucket,
|
||||
continuation_token,
|
||||
@@ -624,14 +626,14 @@ impl DefaultBucketUsecase {
|
||||
|
||||
let params = parse_list_objects_v2_params(prefix, delimiter, max_keys, continuation_token, start_after)?;
|
||||
|
||||
validate_list_object_unordered_with_delimiter(params.delimiter.as_ref(), req.uri.query())?;
|
||||
validate_list_object_unordered_with_delimiter(params.delimiter.as_ref(), envelope.uri().query())?;
|
||||
|
||||
let store = get_validated_store(&bucket).await?;
|
||||
let incl_deleted = get_header(&req.headers, rustfs_utils::http::SUFFIX_INCLUDE_DELETED)
|
||||
let incl_deleted = get_header(envelope.headers(), rustfs_utils::http::SUFFIX_INCLUDE_DELETED)
|
||||
.map(|value| value.as_ref() == "true")
|
||||
.unwrap_or_default();
|
||||
|
||||
let object_infos = match req.extensions.get::<TableDataPlaneListAccess>() {
|
||||
let object_infos = match envelope.table_list_access() {
|
||||
Some(access) => {
|
||||
table_list_isolation::list_objects_v2(
|
||||
store.clone(),
|
||||
@@ -664,24 +666,34 @@ impl DefaultBucketUsecase {
|
||||
.map_err(ApiError::from)?,
|
||||
};
|
||||
|
||||
let permissions = collect_list_objects_metadata_permissions(&req, &bucket, &object_infos.objects).await?;
|
||||
let output = build_list_objects_v2_metadata_output(
|
||||
let permissions = collect_list_objects_metadata_permissions(envelope, &bucket, &object_infos.objects).await?;
|
||||
Ok(build_list_objects_v2_metadata_output(
|
||||
object_infos,
|
||||
&bucket,
|
||||
¶ms,
|
||||
encoding_type.as_ref(),
|
||||
fetch_owner.unwrap_or_default(),
|
||||
&permissions,
|
||||
);
|
||||
|
||||
Ok(S3Response::new(output))
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) async fn execute_list_object_versions_m(
|
||||
&self,
|
||||
req: S3Request<ListObjectVersionsInput>,
|
||||
) -> S3Result<S3Response<ListObjectVersionsMetadataOutput>> {
|
||||
let input = req.input.clone();
|
||||
let envelope = RequestEnvelope::from_s3s(&req);
|
||||
self.list_object_versions_metadata(&envelope, req.input)
|
||||
.await
|
||||
.map(S3Response::new)
|
||||
}
|
||||
|
||||
/// One page of `GET /{bucket}?versions&metadata=true`, as [`Self::list_objects_v2_metadata`].
|
||||
pub(crate) async fn list_object_versions_metadata(
|
||||
&self,
|
||||
envelope: &RequestEnvelope,
|
||||
input: ListObjectVersionsInput,
|
||||
) -> S3Result<ListObjectVersionsMetadataOutput> {
|
||||
let ListObjectVersionsInput {
|
||||
bucket,
|
||||
delimiter,
|
||||
@@ -696,7 +708,7 @@ impl DefaultBucketUsecase {
|
||||
let params = parse_list_object_versions_params(prefix, delimiter, key_marker, version_id_marker, max_keys)?;
|
||||
|
||||
let store = get_validated_store(&bucket).await?;
|
||||
let object_infos = match req.extensions.get::<TableDataPlaneListAccess>() {
|
||||
let object_infos = match envelope.table_list_access() {
|
||||
Some(access) => {
|
||||
table_list_isolation::list_object_versions(
|
||||
store.clone(),
|
||||
@@ -725,11 +737,14 @@ impl DefaultBucketUsecase {
|
||||
.map_err(ApiError::from)?,
|
||||
};
|
||||
|
||||
let permissions = collect_list_objects_metadata_permissions(&req, &bucket, &object_infos.objects).await?;
|
||||
let output =
|
||||
build_list_object_versions_metadata_output(object_infos, &bucket, ¶ms, encoding_type.as_ref(), &permissions);
|
||||
|
||||
Ok(S3Response::new(output))
|
||||
let permissions = collect_list_objects_metadata_permissions(envelope, &bucket, &object_infos.objects).await?;
|
||||
Ok(build_list_object_versions_metadata_output(
|
||||
object_infos,
|
||||
&bucket,
|
||||
¶ms,
|
||||
encoding_type.as_ref(),
|
||||
&permissions,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -457,3 +457,130 @@ fn legacy_put_notification_does_not_write_after_the_bucket_is_recreated() {
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn notification_dispatch_follows_peer_reload_delete_and_recreation() {
|
||||
run_large_stack_test("notification-metadata-authority", || async {
|
||||
let ambient = shared_gating_ambient().await;
|
||||
let store = ambient.object_store();
|
||||
let bucket = format!("notify-authority-{}", uuid::Uuid::new_v4().simple());
|
||||
store
|
||||
.make_bucket(&bucket, &MakeBucketOptions::default())
|
||||
.await
|
||||
.expect("create bucket");
|
||||
let xml = |event: &str| {
|
||||
format!(
|
||||
"<NotificationConfiguration><QueueConfiguration><Event>{event}</Event>\
|
||||
<Queue>arn:rustfs:sqs:us-east-1:inert:webhook</Queue></QueueConfiguration></NotificationConfiguration>"
|
||||
)
|
||||
.into_bytes()
|
||||
};
|
||||
store
|
||||
.update_bucket_metadata_config(&bucket, BUCKET_NOTIFICATION_CONFIG, xml("s3:ObjectCreated:Put"))
|
||||
.await
|
||||
.expect("persist initial subscription");
|
||||
let old = store.get_bucket_metadata(&bucket).await.expect("initial cached metadata");
|
||||
let system = rustfs_notify::NotificationSystem::new(Default::default());
|
||||
system.bind_bucket_metadata_source(&store);
|
||||
let engine = rustfs_notify::NotifyRuleEngine::new();
|
||||
engine.bind_bucket_metadata_source(&store);
|
||||
let inert_target = TargetID::new("inert".into(), "webhook".into());
|
||||
assert!(system.has_subscriber(&bucket, &EventName::ObjectCreatedPut).await);
|
||||
assert!(engine.is_target_bound_to_any_bucket(&inert_target).await);
|
||||
|
||||
store
|
||||
.update_bucket_metadata_config(&bucket, BUCKET_NOTIFICATION_CONFIG, EMPTY_XML.to_vec())
|
||||
.await
|
||||
.expect("remove subscription durably");
|
||||
// Stand in for a peer whose cache has not received the reload yet.
|
||||
crate::storage::storage_api::set_bucket_metadata(bucket.clone(), (*old).clone())
|
||||
.await
|
||||
.expect("install stale peer cache");
|
||||
assert!(system.has_subscriber(&bucket, &EventName::ObjectCreatedPut).await);
|
||||
crate::storage::storage_api::reload_bucket_metadata(store.clone(), &bucket)
|
||||
.await
|
||||
.expect("peer reload");
|
||||
assert!(!system.has_subscriber(&bucket, &EventName::ObjectCreatedPut).await);
|
||||
assert!(
|
||||
engine
|
||||
.match_targets(&bucket, EventName::ObjectCreatedPut, "object")
|
||||
.await
|
||||
.is_empty()
|
||||
);
|
||||
assert!(!engine.is_target_bound_to_any_bucket(&inert_target).await);
|
||||
|
||||
store
|
||||
.update_bucket_metadata_config(&bucket, BUCKET_NOTIFICATION_CONFIG, xml("s3:ObjectCreated:Put"))
|
||||
.await
|
||||
.expect("restore initial subscription");
|
||||
assert!(system.has_subscriber(&bucket, &EventName::ObjectCreatedPut).await);
|
||||
store
|
||||
.delete_bucket(&bucket, &DeleteBucketOptions::default())
|
||||
.await
|
||||
.expect("delete bucket");
|
||||
assert!(!system.has_subscriber(&bucket, &EventName::ObjectCreatedPut).await);
|
||||
// A peer may still have the deleted incarnation cached until its delete
|
||||
// callback (or the periodic metadata refresh) establishes absence.
|
||||
crate::storage::storage_api::set_bucket_metadata(bucket.clone(), (*old).clone())
|
||||
.await
|
||||
.expect("install deleted peer snapshot");
|
||||
assert!(system.has_subscriber(&bucket, &EventName::ObjectCreatedPut).await);
|
||||
assert!(
|
||||
crate::storage::storage_api::remove_bucket_metadata_if_absent(store.clone(), &bucket)
|
||||
.await
|
||||
.expect("peer deletion")
|
||||
);
|
||||
assert!(!system.has_subscriber(&bucket, &EventName::ObjectCreatedPut).await);
|
||||
assert!(
|
||||
engine
|
||||
.match_targets(&bucket, EventName::ObjectCreatedPut, "object")
|
||||
.await
|
||||
.is_empty()
|
||||
);
|
||||
store
|
||||
.make_bucket(&bucket, &MakeBucketOptions::default())
|
||||
.await
|
||||
.expect("recreate bucket");
|
||||
assert_ne!(
|
||||
old.bucket_incarnation_id,
|
||||
store.bucket_incarnation_id(&bucket).await.expect("replacement identity")
|
||||
);
|
||||
assert!(!system.has_subscriber(&bucket, &EventName::ObjectCreatedPut).await);
|
||||
store
|
||||
.update_bucket_metadata_config(&bucket, BUCKET_NOTIFICATION_CONFIG, xml("s3:ObjectRemoved:Delete"))
|
||||
.await
|
||||
.expect("replacement subscription");
|
||||
assert!(system.has_subscriber(&bucket, &EventName::ObjectRemovedDelete).await);
|
||||
assert!(engine.has_subscriber(&bucket, &EventName::ObjectRemovedDelete).await);
|
||||
|
||||
assert!(
|
||||
!crate::storage::storage_api::remove_bucket_metadata_if_absent(store.clone(), &bucket)
|
||||
.await
|
||||
.expect("delayed peer deletion")
|
||||
);
|
||||
let mut stale = rustfs_notify::BucketNotificationConfig::new("us-east-1");
|
||||
stale.add_rule(&[EventName::ObjectCreatedPut], "*".into(), TargetID::new("old".into(), "webhook".into()));
|
||||
// No runtime targets are activated: all assertions inspect inert rules.
|
||||
system.remove_bucket_notification_config(&bucket).await;
|
||||
// Applying already-validated rules models a delayed PUT completion.
|
||||
engine.set_bucket_rules(&bucket, stale.get_rules_map().clone()).await;
|
||||
assert!(engine.has_subscriber(&bucket, &EventName::ObjectRemovedDelete).await);
|
||||
assert!(!engine.has_subscriber(&bucket, &EventName::ObjectCreatedPut).await);
|
||||
assert!(
|
||||
engine
|
||||
.match_targets(&bucket, EventName::ObjectCreatedPut, "object")
|
||||
.await
|
||||
.is_empty()
|
||||
);
|
||||
assert_eq!(
|
||||
engine
|
||||
.match_targets(&bucket, EventName::ObjectRemovedDelete, "object")
|
||||
.await
|
||||
.into_iter()
|
||||
.collect::<Vec<_>>(),
|
||||
vec![inert_target]
|
||||
);
|
||||
assert!(system.has_subscriber(&bucket, &EventName::ObjectRemovedDelete).await);
|
||||
assert!(!system.has_subscriber(&bucket, &EventName::ObjectCreatedPut).await);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -198,7 +198,6 @@ pub struct RequestEnvelope {
|
||||
website_read: Option<WebsiteRead>,
|
||||
post_object: Option<PostObjectRequestMarker>,
|
||||
gateway_post: bool,
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
gateway_post_archive_identity: Option<Arc<()>>,
|
||||
post_object_policy_headers: Option<PostObjectPolicyHeaders>,
|
||||
// Attached by the authorization phase (`storage/access.rs`) for the use case.
|
||||
@@ -252,7 +251,6 @@ impl RequestEnvelope {
|
||||
website_read: extensions.remove(),
|
||||
post_object: extensions.remove(),
|
||||
gateway_post: false,
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
gateway_post_archive_identity: None,
|
||||
post_object_policy_headers: extensions.remove(),
|
||||
req_info: extensions.remove(),
|
||||
@@ -304,7 +302,6 @@ impl RequestEnvelope {
|
||||
website_read: self.website_read.clone(),
|
||||
post_object: self.post_object.clone(),
|
||||
gateway_post: self.gateway_post,
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
gateway_post_archive_identity: self.gateway_post_archive_identity.clone(),
|
||||
post_object_policy_headers: self.post_object_policy_headers.clone(),
|
||||
req_info: self.req_info.clone(),
|
||||
@@ -465,7 +462,6 @@ impl RequestEnvelope {
|
||||
&self.residual_extensions
|
||||
}
|
||||
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
/// The payloads the connection, request and signature layers attached, back in the extensions
|
||||
/// they arrive in, for an edge that hands this request to a handler still taking those.
|
||||
pub(crate) fn transport_extensions(&self) -> Extensions {
|
||||
@@ -528,13 +524,11 @@ impl RequestEnvelope {
|
||||
self.gateway_post
|
||||
}
|
||||
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
pub(crate) fn mark_gateway_post(&mut self) {
|
||||
self.gateway_post = true;
|
||||
self.gateway_post_archive_identity = None;
|
||||
}
|
||||
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
pub(crate) fn bind_gateway_post_archive_identity(&mut self) -> Option<&Arc<()>> {
|
||||
if !self.gateway_post {
|
||||
return None;
|
||||
@@ -542,7 +536,6 @@ impl RequestEnvelope {
|
||||
Some(self.gateway_post_archive_identity.get_or_insert_with(|| Arc::new(())))
|
||||
}
|
||||
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
pub(crate) fn gateway_post_identity(&self) -> Option<&Arc<()>> {
|
||||
self.gateway_post_archive_identity.as_ref()
|
||||
}
|
||||
@@ -563,7 +556,6 @@ impl RequestEnvelope {
|
||||
self.bucket_generation.as_ref()
|
||||
}
|
||||
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
pub(crate) fn take_bucket_generation(&mut self) -> Option<BucketGenerationGuard> {
|
||||
self.bucket_generation.take()
|
||||
}
|
||||
@@ -593,7 +585,6 @@ impl RequestEnvelope {
|
||||
}
|
||||
|
||||
/// Releases preflight guards before uncommitted POST staging; publication must reauthorize.
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
pub(crate) fn release_table_publication_guards(&mut self) {
|
||||
self.table_publication_guards = None;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,267 @@
|
||||
// Copyright 2024 RustFS Team
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! RustFS's two metadata listings, `GET /{bucket}?list-type=2&metadata=true` and
|
||||
//! `GET /{bucket}?versions&metadata=true`: their authorization and their answer.
|
||||
//!
|
||||
//! Responsible for: [`authorize`], the listing check both stacks run once the caller is
|
||||
//! installed, and [`answer`], which reads the listing's parameters from the request, runs the
|
||||
//! owned listing use case and renders the listing document with each entry's metadata, tags and
|
||||
//! internal fields.
|
||||
//! NOT responsible for: which requests are metadata listings (the legacy `MetadataRoute` and the
|
||||
//! gateway's RustFS dialect each select them), resolving the caller, or the listing itself
|
||||
//! (`bucket_usecase/listing.rs`).
|
||||
//! Upstream: the legacy `MetadataRoute` and the gateway stack's metadata listing handler.
|
||||
//! Downstream: the bucket listing authorization and the listing use case.
|
||||
|
||||
use crate::app::RequestEnvelope;
|
||||
use crate::app::bucket_usecase::DefaultBucketUsecase;
|
||||
use crate::app::storage_api::s3::dto::{EncodingType, ListObjectVersionsInput, ListObjectsV2Input};
|
||||
use crate::app::storage_api::s3::xml;
|
||||
use crate::storage::access::access_owned::listing_multipart::authorize_bucket_listing;
|
||||
use crate::storage::authorization::AuthorizationRequest;
|
||||
use http::{HeaderMap, Uri};
|
||||
use rustfs_policy::policy::action::S3Action;
|
||||
use rustfs_s3_types::{S3Error, S3Result, s3_error};
|
||||
use url::form_urlencoded;
|
||||
|
||||
/// Which of the two metadata listings a request is.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum MetadataListing {
|
||||
ListObjectVersions,
|
||||
ListObjectsV2,
|
||||
}
|
||||
|
||||
impl MetadataListing {
|
||||
/// The action the listing is authorized by on its bucket.
|
||||
fn action(self) -> S3Action {
|
||||
match self {
|
||||
Self::ListObjectVersions => S3Action::ListBucketVersionsAction,
|
||||
Self::ListObjectsV2 => S3Action::ListBucketAction,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Authorizes `listing` of `bucket` for the caller `req` carries: the bucket listing check of
|
||||
/// the standard listing with the same action, the table snapshot included.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// What the bucket listing authorization refuses.
|
||||
pub(crate) async fn authorize<R: AuthorizationRequest + ?Sized>(
|
||||
req: &mut R,
|
||||
listing: MetadataListing,
|
||||
bucket: &str,
|
||||
) -> S3Result<()> {
|
||||
authorize_bucket_listing(req, bucket, listing.action()).await
|
||||
}
|
||||
|
||||
/// The listing document of `listing` over `bucket`, after [`authorize`] ran on `envelope`.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// `InvalidArgument` for a malformed listing parameter; otherwise what the listing use case
|
||||
/// refuses.
|
||||
pub(crate) async fn answer(envelope: &RequestEnvelope, listing: MetadataListing, bucket: String) -> S3Result<Vec<u8>> {
|
||||
let usecase = DefaultBucketUsecase::from_global();
|
||||
match listing {
|
||||
MetadataListing::ListObjectVersions => {
|
||||
let input = list_object_versions_input(bucket, envelope.uri(), envelope.headers())?;
|
||||
render(&usecase.list_object_versions_metadata(envelope, input).await?)
|
||||
}
|
||||
MetadataListing::ListObjectsV2 => {
|
||||
let input = list_objects_v2_input(bucket, envelope.uri(), envelope.headers())?;
|
||||
render(&usecase.list_objects_v2_metadata(envelope, input).await?)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn render<T: xml::Serialize>(output: &T) -> S3Result<Vec<u8>> {
|
||||
let mut body = Vec::with_capacity(1024);
|
||||
let mut serializer = xml::Serializer::new(&mut body);
|
||||
serializer
|
||||
.decl()
|
||||
.and_then(|()| output.serialize(&mut serializer))
|
||||
.map_err(S3Error::internal_error)?;
|
||||
Ok(body)
|
||||
}
|
||||
|
||||
fn list_object_versions_input(bucket: String, uri: &Uri, headers: &HeaderMap) -> S3Result<ListObjectVersionsInput> {
|
||||
let query = uri.query().unwrap_or_default();
|
||||
|
||||
Ok(ListObjectVersionsInput {
|
||||
bucket,
|
||||
delimiter: query_value(query, "delimiter"),
|
||||
encoding_type: parse_encoding_type(query_value(query, "encoding-type"))?,
|
||||
expected_bucket_owner: header_value(headers, "x-amz-expected-bucket-owner")?,
|
||||
key_marker: query_value(query, "key-marker"),
|
||||
max_keys: query_i32(query, "max-keys")?,
|
||||
optional_object_attributes: None,
|
||||
prefix: query_value(query, "prefix"),
|
||||
request_payer: header_value(headers, "x-amz-request-payer")?.map(Into::into),
|
||||
version_id_marker: query_value(query, "version-id-marker"),
|
||||
})
|
||||
}
|
||||
|
||||
fn list_objects_v2_input(bucket: String, uri: &Uri, headers: &HeaderMap) -> S3Result<ListObjectsV2Input> {
|
||||
let query = uri.query().unwrap_or_default();
|
||||
|
||||
Ok(ListObjectsV2Input {
|
||||
bucket,
|
||||
continuation_token: query_value(query, "continuation-token"),
|
||||
delimiter: query_value(query, "delimiter"),
|
||||
encoding_type: parse_encoding_type(query_value(query, "encoding-type"))?,
|
||||
expected_bucket_owner: header_value(headers, "x-amz-expected-bucket-owner")?,
|
||||
fetch_owner: query_bool(query, "fetch-owner")?,
|
||||
max_keys: query_i32(query, "max-keys")?,
|
||||
optional_object_attributes: None,
|
||||
prefix: query_value(query, "prefix"),
|
||||
request_payer: header_value(headers, "x-amz-request-payer")?.map(Into::into),
|
||||
start_after: query_value(query, "start-after"),
|
||||
})
|
||||
}
|
||||
|
||||
/// The first value the query gives `key`.
|
||||
pub(crate) fn query_value(query: &str, key: &str) -> Option<String> {
|
||||
form_urlencoded::parse(query.as_bytes())
|
||||
.find(|(name, _)| name == key)
|
||||
.map(|(_, value)| value.into_owned())
|
||||
}
|
||||
|
||||
fn query_i32(query: &str, key: &str) -> S3Result<Option<i32>> {
|
||||
query_value(query, key)
|
||||
.map(|value| {
|
||||
value
|
||||
.parse::<i32>()
|
||||
.map_err(|_| s3_error!(InvalidArgument, "invalid integer query value"))
|
||||
})
|
||||
.transpose()
|
||||
}
|
||||
|
||||
fn query_bool(query: &str, key: &str) -> S3Result<Option<bool>> {
|
||||
query_value(query, key)
|
||||
.map(|value| {
|
||||
value
|
||||
.parse::<bool>()
|
||||
.map_err(|_| s3_error!(InvalidArgument, "invalid boolean query value"))
|
||||
})
|
||||
.transpose()
|
||||
}
|
||||
|
||||
fn parse_encoding_type(value: Option<String>) -> S3Result<Option<EncodingType>> {
|
||||
value
|
||||
.map(|value| {
|
||||
if value == EncodingType::URL {
|
||||
Ok(EncodingType::from_static(EncodingType::URL))
|
||||
} else {
|
||||
Err(s3_error!(InvalidArgument, "invalid encoding-type"))
|
||||
}
|
||||
})
|
||||
.transpose()
|
||||
}
|
||||
|
||||
fn header_value(headers: &HeaderMap, name: &str) -> S3Result<Option<String>> {
|
||||
headers
|
||||
.get(name)
|
||||
.map(|value| {
|
||||
value
|
||||
.to_str()
|
||||
.map(str::to_owned)
|
||||
.map_err(|_| s3_error!(InvalidArgument, "invalid header value"))
|
||||
})
|
||||
.transpose()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::app::storage_api::s3::dto::EncodingType;
|
||||
|
||||
fn uri(value: &str) -> Uri {
|
||||
value.parse().expect("test URI should parse")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn metadata_route_list_objects_v2_input_parses_query_headers_and_decodes_bucket() {
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert("x-amz-expected-bucket-owner", "123456789012".parse().expect("valid header"));
|
||||
headers.insert("x-amz-request-payer", "requester".parse().expect("valid header"));
|
||||
|
||||
let input = list_objects_v2_input(
|
||||
"demo bucket".to_string(),
|
||||
&uri("/demo%20bucket?list-type=2&metadata=true&prefix=logs%2F&delimiter=%2F&encoding-type=url&fetch-owner=true&max-keys=25&continuation-token=opaque&start-after=start"),
|
||||
&headers,
|
||||
)
|
||||
.expect("list objects v2 input should parse");
|
||||
|
||||
assert_eq!(input.bucket, "demo bucket");
|
||||
assert_eq!(input.prefix.as_deref(), Some("logs/"));
|
||||
assert_eq!(input.delimiter.as_deref(), Some("/"));
|
||||
assert_eq!(input.encoding_type.as_ref().map(EncodingType::as_str), Some(EncodingType::URL));
|
||||
assert_eq!(input.fetch_owner, Some(true));
|
||||
assert_eq!(input.max_keys, Some(25));
|
||||
assert_eq!(input.continuation_token.as_deref(), Some("opaque"));
|
||||
assert_eq!(input.start_after.as_deref(), Some("start"));
|
||||
assert_eq!(input.expected_bucket_owner.as_deref(), Some("123456789012"));
|
||||
assert_eq!(input.request_payer.as_ref().map(|payer| payer.as_str()), Some("requester"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn metadata_route_list_object_versions_input_parses_markers_and_rejects_invalid_encoding() {
|
||||
let input = list_object_versions_input(
|
||||
"bucket".to_string(),
|
||||
&uri("/bucket?versions&metadata=true&prefix=logs%2F&delimiter=%2F&encoding-type=url&key-marker=start&version-id-marker=v1&max-keys=10"),
|
||||
&HeaderMap::new(),
|
||||
)
|
||||
.expect("list versions input should parse");
|
||||
|
||||
assert_eq!(input.bucket, "bucket");
|
||||
assert_eq!(input.prefix.as_deref(), Some("logs/"));
|
||||
assert_eq!(input.delimiter.as_deref(), Some("/"));
|
||||
assert_eq!(input.encoding_type.as_ref().map(EncodingType::as_str), Some(EncodingType::URL));
|
||||
assert_eq!(input.key_marker.as_deref(), Some("start"));
|
||||
assert_eq!(input.version_id_marker.as_deref(), Some("v1"));
|
||||
assert_eq!(input.max_keys, Some(10));
|
||||
|
||||
let err = list_object_versions_input(
|
||||
"bucket".to_string(),
|
||||
&uri("/bucket?versions&metadata=true&encoding-type=xml"),
|
||||
&HeaderMap::new(),
|
||||
)
|
||||
.expect_err("invalid encoding-type should be rejected");
|
||||
assert_eq!(err.code(), &rustfs_s3_types::S3ErrorCode::InvalidArgument);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn metadata_route_listing_parameters_refuse_malformed_values() {
|
||||
for target in [
|
||||
"/b?list-type=2&metadata=true&max-keys=ten",
|
||||
"/b?list-type=2&metadata=true&max-keys=99999999999",
|
||||
"/b?list-type=2&metadata=true&fetch-owner=yes",
|
||||
"/b?list-type=2&metadata=true&encoding-type=URL",
|
||||
"/b?list-type=2&metadata=true&encoding-type=",
|
||||
] {
|
||||
let err = list_objects_v2_input("b".to_owned(), &uri(target), &HeaderMap::new()).expect_err(target);
|
||||
assert_eq!(err.code(), &rustfs_s3_types::S3ErrorCode::InvalidArgument, "{target}");
|
||||
}
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert(
|
||||
"x-amz-request-payer",
|
||||
http::HeaderValue::from_bytes(b"\xffpayer").expect("an opaque header value"),
|
||||
);
|
||||
let err = list_object_versions_input("b".to_owned(), &uri("/b?versions&metadata=true"), &headers)
|
||||
.expect_err("a non-text header is refused");
|
||||
assert_eq!(err.code(), &rustfs_s3_types::S3ErrorCode::InvalidArgument);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -26,7 +26,7 @@ pub(crate) mod bucket_list_through;
|
||||
pub mod bucket_usecase;
|
||||
pub mod context;
|
||||
pub(crate) mod dto_values;
|
||||
pub(crate) mod metadata_route;
|
||||
pub(crate) mod metadata_listing;
|
||||
pub mod multipart_usecase;
|
||||
pub mod object;
|
||||
pub(crate) mod object_data_cache;
|
||||
@@ -39,6 +39,7 @@ pub(crate) mod select_request;
|
||||
pub(crate) mod storage_api;
|
||||
pub(crate) mod table_list_isolation;
|
||||
pub(crate) mod trailer_adapter;
|
||||
pub(crate) mod website;
|
||||
|
||||
// Request-scoped facts are not AppContext resolution, so consumers import them
|
||||
// from here rather than through `app::context`.
|
||||
|
||||
@@ -132,7 +132,6 @@ mod create;
|
||||
mod create_values;
|
||||
pub(crate) use create_values::{CreateMultipartUploadFields, CreateMultipartUploadResult};
|
||||
mod list;
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
pub(crate) use list::ListPartsInfo;
|
||||
pub(crate) use list::{ListPartsFields, ListPartsTarget};
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -16,13 +16,10 @@
|
||||
|
||||
use super::*;
|
||||
use crate::app::RequestEnvelope;
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
use crate::app::storage_api::multipart_usecase::contract::multipart::{MultipartAbortAuthorization, MultipartOwner};
|
||||
use http::StatusCode;
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
use rustfs_gateway_types::{BucketName, ObjectKey, RecordedUpload, UploadIdClaim, resolve_upload, resolve_upload_async};
|
||||
use rustfs_s3_types::{S3Error, S3ErrorCode, S3Result};
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
use std::sync::OnceLock;
|
||||
|
||||
pub(crate) enum AbortMultipartUploadTarget {
|
||||
@@ -31,7 +28,6 @@ pub(crate) enum AbortMultipartUploadTarget {
|
||||
key: String,
|
||||
upload_id: String,
|
||||
},
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
Gateway {
|
||||
bucket: BucketName,
|
||||
key: ObjectKey,
|
||||
@@ -43,7 +39,6 @@ impl AbortMultipartUploadTarget {
|
||||
fn resource(&self) -> (&str, &str) {
|
||||
match self {
|
||||
Self::Legacy { bucket, key, .. } => (bucket, key),
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
Self::Gateway { bucket, key, .. } => (bucket.as_str(), key.as_str()),
|
||||
}
|
||||
}
|
||||
@@ -79,7 +74,6 @@ impl DefaultMultipartUsecase {
|
||||
let (bucket, key) = target.resource();
|
||||
let mut opts = ObjectOptions::default();
|
||||
apply_bucket_generation_guard(&envelope, bucket, &mut opts)?;
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
if matches!(&target, AbortMultipartUploadTarget::Gateway { .. }) && opts.expected_bucket_incarnation_id.is_none()
|
||||
{
|
||||
return Err(S3Error::with_message(S3ErrorCode::InternalError, "bucket generation guard is missing"));
|
||||
@@ -95,7 +89,6 @@ impl DefaultMultipartUsecase {
|
||||
.abort_multipart_upload(bucket, key, upload_id, &opts)
|
||||
.await
|
||||
.map_err(multipart_upload_api_error)?,
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
AbortMultipartUploadTarget::Gateway { bucket, key, upload_id } => {
|
||||
abort_gateway(&store, bucket, key, upload_id, opts).await?
|
||||
}
|
||||
@@ -112,10 +105,8 @@ impl DefaultMultipartUsecase {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
struct AbortOwner(MultipartOwner);
|
||||
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
impl RecordedUpload for AbortOwner {
|
||||
fn bucket(&self) -> &str {
|
||||
&self.0.bucket
|
||||
@@ -126,7 +117,6 @@ impl RecordedUpload for AbortOwner {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
struct AbortAuthorization {
|
||||
bucket: BucketName,
|
||||
key: ObjectKey,
|
||||
@@ -134,7 +124,6 @@ struct AbortAuthorization {
|
||||
observed: OnceLock<MultipartOwner>,
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
impl MultipartAbortAuthorization for AbortAuthorization {
|
||||
type Error = StorageError;
|
||||
|
||||
@@ -148,7 +137,6 @@ impl MultipartAbortAuthorization for AbortAuthorization {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
async fn abort_gateway(
|
||||
store: &ECStore,
|
||||
bucket: &BucketName,
|
||||
|
||||
@@ -1195,7 +1195,6 @@ mod tests {
|
||||
let response = result.expect("verified key completes and replays");
|
||||
assert!(response.checksum_sha256.is_some(), "verified key retains checksum response");
|
||||
assert_eq!(response.sse_customer_key_md5.as_deref(), Some(customer_md5));
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
{
|
||||
use rustfs_gateway::{Limits, MetaView, OperationCodec, TargetKind, WireRequest};
|
||||
let request = http::Request::builder()
|
||||
|
||||
@@ -19,13 +19,10 @@ use crate::app::RequestEnvelope;
|
||||
use crate::app::dto_values;
|
||||
use crate::app::storage_api::multipart_usecase::contract::multipart::ListMultipartsInfo;
|
||||
pub(crate) use crate::app::storage_api::multipart_usecase::contract::multipart::ListPartsInfo;
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
use crate::app::storage_api::multipart_usecase::contract::multipart::ListPartsOwner;
|
||||
use rustfs_gateway_types::dto as gateway_dto;
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
use rustfs_gateway_types::{BucketName, ObjectKey, RecordedUpload, UploadIdClaim, resolve_upload_async};
|
||||
use rustfs_s3_types::S3Result;
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
use rustfs_s3_types::{S3Error, S3ErrorCode};
|
||||
|
||||
pub(crate) enum ListPartsTarget {
|
||||
@@ -34,7 +31,6 @@ pub(crate) enum ListPartsTarget {
|
||||
key: String,
|
||||
upload_id: String,
|
||||
},
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
Gateway {
|
||||
bucket: BucketName,
|
||||
key: ObjectKey,
|
||||
@@ -46,7 +42,6 @@ impl ListPartsTarget {
|
||||
fn resource(&self) -> (&str, &str) {
|
||||
match self {
|
||||
Self::Legacy { bucket, key, .. } => (bucket, key),
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
Self::Gateway { bucket, key, .. } => (bucket.as_str(), key.as_str()),
|
||||
}
|
||||
}
|
||||
@@ -58,13 +53,11 @@ pub(crate) struct ListPartsFields {
|
||||
pub(crate) max_parts: Option<i32>,
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
struct RecordedListParts {
|
||||
owner: ListPartsOwner,
|
||||
page: ListPartsInfo,
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
impl RecordedUpload for RecordedListParts {
|
||||
fn bucket(&self) -> &str {
|
||||
&self.owner.bucket
|
||||
@@ -75,7 +68,6 @@ impl RecordedUpload for RecordedListParts {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
async fn resolve_list_parts<'a, F>(
|
||||
upload_id: &'a UploadIdClaim,
|
||||
bucket: &BucketName,
|
||||
@@ -210,7 +202,6 @@ impl DefaultMultipartUsecase {
|
||||
.list_object_parts(bucket, key, upload_id, params.part_number_marker, params.max_parts, &opts)
|
||||
.await
|
||||
.map_err(|error| multipart_upload_api_error(error).into()),
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
ListPartsTarget::Gateway {
|
||||
bucket: bucket_name,
|
||||
key: object_key,
|
||||
|
||||
@@ -20,21 +20,17 @@ use crate::app::object::BodyChunks;
|
||||
use crate::app::object::request_body::{DemandReader, UploadChunks, guard_native_upload_progress};
|
||||
use crate::app::storage_api::multipart_usecase::access::AuthorizationRequest;
|
||||
use crate::app::storage_api::multipart_usecase::contract::multipart::MultipartInfo;
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
use crate::app::storage_api::multipart_usecase::contract::multipart::MultipartOwner;
|
||||
use http_body::Body as _;
|
||||
use rustfs_gateway_stream::Body;
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
use rustfs_gateway_types::{RecordedUpload, resolve_upload_async};
|
||||
use rustfs_s3_types::{S3Error, S3ErrorCode, S3Result, s3_error};
|
||||
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
pub(super) struct PartUpload {
|
||||
pub(super) owner: MultipartOwner,
|
||||
pub(super) info: MultipartInfo,
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
impl RecordedUpload for PartUpload {
|
||||
fn bucket(&self) -> &str {
|
||||
&self.owner.bucket
|
||||
@@ -50,7 +46,6 @@ async fn lookup_part_upload(store: &ECStore, bucket: &str, key: &str, id: &str,
|
||||
result.map_err(|error| multipart_upload_api_error(error).into())
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
pub(super) async fn lookup_recorded_part_upload(
|
||||
store: &ECStore,
|
||||
bucket: &str,
|
||||
@@ -221,7 +216,6 @@ impl DefaultMultipartUsecase {
|
||||
let info = lookup_part_upload(&store, bucket, key, upload_id, &opts).await?;
|
||||
(upload_id.clone(), info)
|
||||
}
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
UploadPartTarget::Gateway {
|
||||
bucket: bucket_name,
|
||||
key: object_key,
|
||||
|
||||
@@ -269,7 +269,6 @@ impl DefaultMultipartUsecase {
|
||||
.map_err(multipart_upload_api_error)?;
|
||||
(upload_id, info)
|
||||
}
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
UploadPartTarget::Gateway {
|
||||
bucket: bound_bucket,
|
||||
key: bound_key,
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
use crate::app::object::FrameTrailers;
|
||||
use rustfs_gateway_stream::Body;
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
use rustfs_gateway_types::{BucketName, ObjectKey, UploadIdClaim};
|
||||
use rustfs_rio::SharedTrailerSource;
|
||||
use std::sync::Arc;
|
||||
@@ -27,7 +26,6 @@ pub(crate) enum UploadPartTarget {
|
||||
key: String,
|
||||
upload_id: String,
|
||||
},
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
Gateway {
|
||||
bucket: BucketName,
|
||||
key: ObjectKey,
|
||||
@@ -39,7 +37,6 @@ impl UploadPartTarget {
|
||||
pub(super) fn resource(&self) -> (&str, &str) {
|
||||
match self {
|
||||
Self::Legacy { bucket, key, .. } => (bucket, key),
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
Self::Gateway { bucket, key, .. } => (bucket.as_str(), key.as_str()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,99 +19,98 @@ use http_body_util::{BodyExt as _, Empty};
|
||||
use hyper_util::rt::TokioIo;
|
||||
|
||||
fn get_object_attributes_completion(stack: Option<&'static str>) {
|
||||
temp_env::with_vars([("RUSTFS_S3_STACK", stack), ("RUSTFS_AUDIT_ENABLE", Some("true"))], || {
|
||||
crate::app::gating_test_env::run_large_stack_test("attributes-completion", || async {
|
||||
use crate::app::storage_api::object_usecase::helper::MutationCompletionProbe;
|
||||
use crate::app::storage_api::test::contract::bucket::{BucketOperations as _, MakeBucketOptions};
|
||||
use crate::app::storage_api::test::contract::object::ObjectIO as _;
|
||||
use crate::embedded::{RustFSServerBuilder, find_available_port};
|
||||
temp_env::with_vars(
|
||||
[
|
||||
(crate::config::RETIRED_S3_STACK_SELECTOR, stack),
|
||||
("RUSTFS_AUDIT_ENABLE", Some("true")),
|
||||
],
|
||||
|| {
|
||||
crate::app::gating_test_env::run_large_stack_test("attributes-completion", || async {
|
||||
use crate::app::storage_api::object_usecase::helper::MutationCompletionProbe;
|
||||
use crate::app::storage_api::test::contract::bucket::{BucketOperations as _, MakeBucketOptions};
|
||||
use crate::app::storage_api::test::contract::object::ObjectIO as _;
|
||||
use crate::embedded::{RustFSServerBuilder, find_available_port};
|
||||
|
||||
let server = RustFSServerBuilder::new()
|
||||
.address(format!("127.0.0.1:{}", find_available_port().unwrap()))
|
||||
.access_key("attributesprobe")
|
||||
.secret_key("attributes-fixture-test-secret")
|
||||
.build()
|
||||
.await
|
||||
.unwrap();
|
||||
crate::server::refresh_audit_module_enabled();
|
||||
let context = crate::app::runtime_sources::current_app_context().unwrap();
|
||||
let store = context.object_store();
|
||||
let bucket = "attributes-completion";
|
||||
store.make_bucket(bucket, &MakeBucketOptions::default()).await.unwrap();
|
||||
let policy = serde_json::json!({
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [{
|
||||
"Effect": "Allow",
|
||||
"Principal": {"AWS": "*"},
|
||||
"Action": ["s3:GetObject", "s3:GetObjectAttributes"],
|
||||
"Resource": [format!("arn:aws:s3:::{bucket}/object"), format!("arn:aws:s3:::{bucket}/missing")],
|
||||
}],
|
||||
});
|
||||
store
|
||||
.update_bucket_metadata_config(
|
||||
bucket,
|
||||
crate::app::storage_api::object_usecase::bucket::metadata::BUCKET_POLICY_CONFIG,
|
||||
serde_json::to_vec(&policy).unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
store
|
||||
.put_object(
|
||||
bucket,
|
||||
"object",
|
||||
&mut crate::app::storage_api::object_usecase::StoragePutObjReader::from_vec(b"payload".to_vec()),
|
||||
&Default::default(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
let probe = MutationCompletionProbe::install(bucket);
|
||||
for (key, expected) in [("object", 200), ("missing", 404), ("other", 403)] {
|
||||
let socket = tokio::net::TcpStream::connect(server.address()).await.unwrap();
|
||||
let (mut sender, connection) = hyper::client::conn::http1::handshake(TokioIo::new(socket)).await.unwrap();
|
||||
let transport = tokio::spawn(connection);
|
||||
let request = http::Request::get(format!("/{bucket}/{key}?attributes"))
|
||||
.header(http::header::HOST, "localhost")
|
||||
.header("x-amz-object-attributes", "ObjectSize")
|
||||
.body(Empty::<Bytes>::new())
|
||||
let server = RustFSServerBuilder::new()
|
||||
.address(format!("127.0.0.1:{}", find_available_port().unwrap()))
|
||||
.access_key("attributesprobe")
|
||||
.secret_key("attributes-fixture-test-secret")
|
||||
.build()
|
||||
.await
|
||||
.unwrap();
|
||||
let response = sender.send_request(request).await.unwrap();
|
||||
assert_eq!(response.status().as_u16(), expected);
|
||||
response.into_body().collect().await.unwrap();
|
||||
drop(sender);
|
||||
transport.abort();
|
||||
let _ = transport.await;
|
||||
}
|
||||
probe.wait_for(2, 0).await;
|
||||
let audits = probe
|
||||
.audits
|
||||
.lock()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.filter(|entry| entry.api.name.as_deref() == Some(rustfs_s3_ops::S3Operation::GetObjectAttributes.as_str()))
|
||||
.map(|entry| (entry.api.object.clone(), entry.api.status.clone(), entry.api.status_code))
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(
|
||||
audits,
|
||||
[
|
||||
(Some("object".to_owned()), Some("success".to_owned()), Some(200)),
|
||||
(Some("missing".to_owned()), Some("failure".to_owned()), Some(500)),
|
||||
],
|
||||
);
|
||||
assert!(probe.events.lock().unwrap().is_empty());
|
||||
server.shutdown().await;
|
||||
})
|
||||
})
|
||||
crate::server::refresh_audit_module_enabled();
|
||||
let context = crate::app::runtime_sources::current_app_context().unwrap();
|
||||
let store = context.object_store();
|
||||
let bucket = "attributes-completion";
|
||||
store.make_bucket(bucket, &MakeBucketOptions::default()).await.unwrap();
|
||||
let policy = serde_json::json!({
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [{
|
||||
"Effect": "Allow",
|
||||
"Principal": {"AWS": "*"},
|
||||
"Action": ["s3:GetObject", "s3:GetObjectAttributes"],
|
||||
"Resource": [format!("arn:aws:s3:::{bucket}/object"), format!("arn:aws:s3:::{bucket}/missing")],
|
||||
}],
|
||||
});
|
||||
store
|
||||
.update_bucket_metadata_config(
|
||||
bucket,
|
||||
crate::app::storage_api::object_usecase::bucket::metadata::BUCKET_POLICY_CONFIG,
|
||||
serde_json::to_vec(&policy).unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
store
|
||||
.put_object(
|
||||
bucket,
|
||||
"object",
|
||||
&mut crate::app::storage_api::object_usecase::StoragePutObjReader::from_vec(b"payload".to_vec()),
|
||||
&Default::default(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
let probe = MutationCompletionProbe::install(bucket);
|
||||
for (key, expected) in [("object", 200), ("missing", 404), ("other", 403)] {
|
||||
let socket = tokio::net::TcpStream::connect(server.address()).await.unwrap();
|
||||
let (mut sender, connection) = hyper::client::conn::http1::handshake(TokioIo::new(socket)).await.unwrap();
|
||||
let transport = tokio::spawn(connection);
|
||||
let request = http::Request::get(format!("/{bucket}/{key}?attributes"))
|
||||
.header(http::header::HOST, "localhost")
|
||||
.header("x-amz-object-attributes", "ObjectSize")
|
||||
.body(Empty::<Bytes>::new())
|
||||
.unwrap();
|
||||
let response = sender.send_request(request).await.unwrap();
|
||||
assert_eq!(response.status().as_u16(), expected);
|
||||
response.into_body().collect().await.unwrap();
|
||||
drop(sender);
|
||||
transport.abort();
|
||||
let _ = transport.await;
|
||||
}
|
||||
probe.wait_for(2, 0).await;
|
||||
let audits = probe
|
||||
.audits
|
||||
.lock()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.filter(|entry| entry.api.name.as_deref() == Some(rustfs_s3_ops::S3Operation::GetObjectAttributes.as_str()))
|
||||
.map(|entry| (entry.api.object.clone(), entry.api.status.clone(), entry.api.status_code))
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(
|
||||
audits,
|
||||
[
|
||||
(Some("object".to_owned()), Some("success".to_owned()), Some(200)),
|
||||
(Some("missing".to_owned()), Some("failure".to_owned()), Some(500)),
|
||||
],
|
||||
);
|
||||
assert!(probe.events.lock().unwrap().is_empty());
|
||||
server.shutdown().await;
|
||||
})
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial_test::serial]
|
||||
fn legacy_get_object_attributes_completion() {
|
||||
get_object_attributes_completion(None);
|
||||
}
|
||||
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
#[test]
|
||||
#[serial_test::serial]
|
||||
fn gateway_get_object_attributes_completion() {
|
||||
get_object_attributes_completion(Some("gateway"));
|
||||
get_object_attributes_completion(None);
|
||||
}
|
||||
|
||||
@@ -1188,7 +1188,6 @@ impl DefaultObjectUsecase {
|
||||
/// The access phase has installed `ReqInfo` and the pending bucket-generation guard; this
|
||||
/// adds `ReplicateDelete` for a replica delete, repeats `ForceDeleteObject` for a non-owner,
|
||||
/// and authorizes every descendant of a recursive force delete.
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
#[instrument(level = "info", skip(self, envelope, input))]
|
||||
pub async fn execute_delete_object(
|
||||
&self,
|
||||
|
||||
@@ -2018,7 +2018,6 @@ impl DefaultObjectUsecase {
|
||||
if envelope.post_object().is_some() && !envelope.is_gateway_post() {
|
||||
return Err(rustfs_s3_types::s3_error!(NotImplemented, "POST archive extraction is not supported"));
|
||||
}
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
let input = if envelope.is_gateway_post() {
|
||||
let mut input = input;
|
||||
let archive = input
|
||||
@@ -2045,10 +2044,6 @@ impl DefaultObjectUsecase {
|
||||
}
|
||||
input
|
||||
};
|
||||
#[cfg(not(feature = "gateway-stack"))]
|
||||
if envelope.is_gateway_post() {
|
||||
return Err(rustfs_s3_types::s3_error!(NotImplemented, "POST archive extraction is not supported"));
|
||||
}
|
||||
Box::pin(self.execute_put_object_extract_inner(envelope, input)).await
|
||||
}
|
||||
|
||||
@@ -2831,7 +2826,6 @@ impl DefaultObjectUsecase {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
#[path = "extract/post_archive_preflight.rs"]
|
||||
pub(super) mod post_archive_preflight;
|
||||
|
||||
|
||||
@@ -4502,7 +4502,6 @@ impl DefaultObjectUsecase {
|
||||
crate::app::test_seams::get_object(self, request).await
|
||||
}
|
||||
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
pub(crate) async fn execute_get_object(
|
||||
&self,
|
||||
envelope: RequestEnvelope,
|
||||
|
||||
@@ -86,23 +86,16 @@ fn operation_counts() -> std::collections::BTreeMap<&'static str, u64> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial_test::serial]
|
||||
fn get_boundary_legacy() {
|
||||
get_boundary(None);
|
||||
}
|
||||
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
#[test]
|
||||
#[serial_test::serial]
|
||||
fn get_boundary_gateway() {
|
||||
get_boundary(Some("gateway"));
|
||||
get_boundary(None);
|
||||
}
|
||||
|
||||
fn get_boundary(stack: Option<&str>) {
|
||||
temp_env::with_vars(
|
||||
[
|
||||
("RUSTFS_S3_STACK", stack),
|
||||
(crate::config::RETIRED_S3_STACK_SELECTOR, stack),
|
||||
("RUSTFS_AUDIT_ENABLE", Some("true")),
|
||||
("RUSTFS_SSE_C_REQUIRE_TLS", Some("false")),
|
||||
],
|
||||
|
||||
@@ -21,7 +21,6 @@ use crate::app::dto_values::{stored_etag, timestamp};
|
||||
use crate::app::storage_api::s3::header::X_AMZ_RESTORE;
|
||||
use crate::app::{Answered, RequestEnvelope};
|
||||
use rustfs_gateway_types::ByteRange;
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
use rustfs_gateway_types::RangeParse;
|
||||
use rustfs_gateway_types::dto as gateway_dto;
|
||||
use rustfs_s3_types::{S3Error, S3ErrorCode, S3Result, s3_error};
|
||||
@@ -447,7 +446,6 @@ impl DefaultObjectUsecase {
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
pub(crate) async fn execute_head_object(
|
||||
&self,
|
||||
envelope: RequestEnvelope,
|
||||
|
||||
@@ -214,7 +214,7 @@ const INVALID_HEAD_ETAGS: &[HeadEtagRow] = &[
|
||||
fn head_etag_wire_and_audit(stack: Option<&'static str>, rows: &'static [HeadEtagRow]) {
|
||||
temp_env::with_vars(
|
||||
[
|
||||
("RUSTFS_S3_STACK", stack),
|
||||
(crate::config::RETIRED_S3_STACK_SELECTOR, stack),
|
||||
("RUSTFS_AUDIT_ENABLE", Some("true")),
|
||||
("RUSTFS_NOTIFY_ENABLE", Some("false")),
|
||||
],
|
||||
@@ -307,28 +307,14 @@ fn head_etag_wire_and_audit(stack: Option<&'static str>, rows: &'static [HeadEta
|
||||
|
||||
#[test]
|
||||
#[serial_test::serial]
|
||||
fn legacy_head_etag_wire_preserves_typed_values_and_audit() {
|
||||
fn gateway_head_etag_wire_preserves_typed_values_and_audit() {
|
||||
head_etag_wire_and_audit(None, VALID_HEAD_ETAGS);
|
||||
}
|
||||
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
#[test]
|
||||
#[serial_test::serial]
|
||||
fn gateway_head_etag_wire_preserves_typed_values_and_audit() {
|
||||
head_etag_wire_and_audit(Some("gateway"), VALID_HEAD_ETAGS);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial_test::serial]
|
||||
fn legacy_head_invalid_etag_is_rejected_after_audit() {
|
||||
head_etag_wire_and_audit(None, INVALID_HEAD_ETAGS);
|
||||
}
|
||||
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
#[test]
|
||||
#[serial_test::serial]
|
||||
fn gateway_head_invalid_etag_is_rejected_after_audit() {
|
||||
head_etag_wire_and_audit(Some("gateway"), INVALID_HEAD_ETAGS);
|
||||
head_etag_wire_and_audit(None, INVALID_HEAD_ETAGS);
|
||||
}
|
||||
|
||||
async fn head_test_server() -> crate::embedded::RustFSServer {
|
||||
@@ -372,11 +358,10 @@ async fn head_wire_response(
|
||||
http::Response::from_parts(parts, body)
|
||||
}
|
||||
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
#[test]
|
||||
#[serial_test::serial]
|
||||
fn gateway_head_authorization_uses_the_request_bound_context() {
|
||||
temp_env::with_var("RUSTFS_S3_STACK", Some("gateway"), || {
|
||||
temp_env::with_var(crate::config::RETIRED_S3_STACK_SELECTOR, None::<&str>, || {
|
||||
crate::app::gating_test_env::run_large_stack_test("head-gateway-authorization", || async {
|
||||
use crate::app::storage_api::test::contract::bucket::{BucketOperations as _, MakeBucketOptions};
|
||||
use crate::app::storage_api::test::contract::object::ObjectIO as _;
|
||||
@@ -430,7 +415,7 @@ fn gateway_head_authorization_uses_the_request_bound_context() {
|
||||
}
|
||||
|
||||
fn head_conditional_headers_preserve_stored_facts(stack: Option<&'static str>) {
|
||||
temp_env::with_var("RUSTFS_S3_STACK", stack, || {
|
||||
temp_env::with_var(crate::config::RETIRED_S3_STACK_SELECTOR, stack, || {
|
||||
crate::app::gating_test_env::run_large_stack_test("head-conditional-headers", || async {
|
||||
use crate::app::storage_api::test::contract::bucket::{BucketOperations as _, MakeBucketOptions};
|
||||
use crate::app::storage_api::test::contract::object::{ObjectIO as _, ObjectOperations as _};
|
||||
@@ -504,13 +489,6 @@ fn head_conditional_headers_preserve_stored_facts(stack: Option<&'static str>) {
|
||||
|
||||
#[test]
|
||||
#[serial_test::serial]
|
||||
fn legacy_head_conditional_headers_preserve_stored_facts() {
|
||||
fn gateway_head_conditional_headers_preserve_stored_facts() {
|
||||
head_conditional_headers_preserve_stored_facts(None);
|
||||
}
|
||||
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
#[test]
|
||||
#[serial_test::serial]
|
||||
fn gateway_head_conditional_headers_preserve_stored_facts() {
|
||||
head_conditional_headers_preserve_stored_facts(Some("gateway"));
|
||||
}
|
||||
|
||||
@@ -230,15 +230,12 @@ mod get;
|
||||
mod get_response;
|
||||
pub(crate) use get_response::{GetObjectBody, GetObjectFields, GetObjectOutputFacts};
|
||||
mod head;
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
pub(crate) use head::ResponseEtag;
|
||||
pub(crate) use head::{HeadObjectFields, HeadObjectOutputFacts};
|
||||
mod internal_put;
|
||||
mod native_body;
|
||||
mod on_demand_migration_put;
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
pub(crate) mod post_body;
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
pub(crate) mod post_headers;
|
||||
mod put;
|
||||
mod put_input;
|
||||
|
||||
@@ -4384,7 +4384,6 @@ mod tests {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
async fn gateway_post_archive_is_refused_before_body_on_both_internal_paths() {
|
||||
for direct_extract in [false, true] {
|
||||
let (body, polls) = PollCountingBody::streaming_blob();
|
||||
|
||||
@@ -25,7 +25,6 @@ pub(crate) struct PutObjectWriteInput {
|
||||
pub(crate) bucket: String,
|
||||
pub(crate) key: String,
|
||||
pub(crate) body: Option<Body>,
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
pub(crate) post_archive: Option<super::post_body::PreflightedPostArchive>,
|
||||
pub(crate) frame_trailers: Option<std::sync::Arc<super::native_body::FrameTrailers>>,
|
||||
pub(crate) trailing_headers: Option<SharedTrailerSource>,
|
||||
@@ -83,7 +82,6 @@ pub(crate) struct PutObjectWriteOutput {
|
||||
|
||||
impl PutObjectWriteInput {
|
||||
/// Gateway frames publish to the same source that checksum readers observe.
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
pub(crate) fn capture_frame_trailers(&mut self) {
|
||||
let trailers = std::sync::Arc::new(super::native_body::FrameTrailers::default());
|
||||
self.frame_trailers = Some(trailers.clone());
|
||||
|
||||
@@ -27,7 +27,6 @@ use crate::app::storage_api::object_usecase::helper::OperationHelper;
|
||||
use crate::app::storage_api::object_usecase::options::get_opts;
|
||||
use crate::error::ApiError;
|
||||
use http::{HeaderMap, StatusCode};
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
use rustfs_gateway_types::dto::{GetObjectAclInput, PutObjectAclInput};
|
||||
use rustfs_gateway_types::dto::{GetObjectAclOutput, Grant, Grantee, Permission, PutObjectAclOutput, Type};
|
||||
use rustfs_s3_ops::S3Operation;
|
||||
@@ -40,7 +39,6 @@ impl ObjectMetaUsecase {
|
||||
///
|
||||
/// `InternalError` before the store is up; the store's refusal (`NoSuchKey`, `NoSuchVersion`,
|
||||
/// `NoSuchBucket`) when the object does not exist.
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
pub async fn execute_get_object_acl(
|
||||
&self,
|
||||
envelope: RequestEnvelope,
|
||||
@@ -72,7 +70,6 @@ impl ObjectMetaUsecase {
|
||||
///
|
||||
/// `MethodNotAllowed` for a Veeam SOSAPI system object; `InternalError` before the store is up;
|
||||
/// the store's refusal when the object does not exist; `NotImplemented` for XML grants.
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
pub async fn execute_put_object_acl(
|
||||
&self,
|
||||
envelope: RequestEnvelope,
|
||||
|
||||
@@ -34,7 +34,6 @@ use crate::app::storage_api::object_usecase::helper::OperationHelper;
|
||||
use crate::app::storage_api::object_usecase::options::get_opts;
|
||||
use crate::app::storage_api::object_usecase::{StorageObjectOptions as ObjectOptions, parse_object_lock_legal_hold_native};
|
||||
use crate::error::ApiError;
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
use rustfs_gateway_types::dto::GetObjectLegalHoldInput;
|
||||
use rustfs_gateway_types::dto::{GetObjectLegalHoldOutput, ObjectLockLegalHold, Status};
|
||||
use rustfs_gateway_types::dto::{PutObjectLegalHoldOutput, RequestCharged};
|
||||
@@ -158,7 +157,6 @@ impl ObjectMetaUsecase {
|
||||
/// `MethodNotAllowed` for a Veeam SOSAPI system object; `InternalError` before the store is up
|
||||
/// or when the object cannot be read; `NoSuchBucket`; the Object Lock refusal of a bucket
|
||||
/// without Object Lock.
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
pub async fn execute_get_object_legal_hold(
|
||||
&self,
|
||||
envelope: RequestEnvelope,
|
||||
|
||||
@@ -37,7 +37,6 @@ use crate::app::storage_api::object_usecase::helper::OperationHelper;
|
||||
use crate::app::storage_api::object_usecase::options::get_opts;
|
||||
use crate::app::storage_api::object_usecase::{StorageObjectOptions as ObjectOptions, parse_object_lock_retention_native};
|
||||
use crate::error::ApiError;
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
use rustfs_gateway_types::dto::GetObjectRetentionInput;
|
||||
use rustfs_gateway_types::dto::{GetObjectRetentionOutput, Mode, ObjectLockRetention};
|
||||
use rustfs_gateway_types::dto::{PutObjectRetentionOutput, RequestCharged};
|
||||
@@ -178,7 +177,6 @@ impl ObjectMetaUsecase {
|
||||
/// `MethodNotAllowed` for a Veeam SOSAPI system object; `InternalError` before the store is up,
|
||||
/// when the object cannot be read, or for a stored date outside the answerable range; the
|
||||
/// Object Lock refusal of a bucket without Object Lock.
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
pub async fn execute_get_object_retention(
|
||||
&self,
|
||||
envelope: RequestEnvelope,
|
||||
|
||||
@@ -38,9 +38,7 @@ use crate::error::ApiError;
|
||||
use http::{HeaderMap, StatusCode};
|
||||
use metrics::{counter, histogram};
|
||||
use rustfs_gateway_types::cors_tagging::PersistedTag;
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
use rustfs_gateway_types::dto::PutObjectTaggingInput;
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
use rustfs_gateway_types::dto::{DeleteObjectTaggingInput, GetObjectTaggingInput};
|
||||
use rustfs_gateway_types::dto::{DeleteObjectTaggingOutput, GetObjectTaggingOutput, PutObjectTaggingOutput, Tag};
|
||||
use rustfs_s3_ops::S3Operation;
|
||||
@@ -67,7 +65,6 @@ impl ObjectMetaUsecase {
|
||||
/// `MethodNotAllowed` for a Veeam SOSAPI system object or a named delete marker; `NoSuchKey` for
|
||||
/// a missing object or a current delete marker; `NoSuchVersion` for a missing named version;
|
||||
/// `InvalidArgument` for a malformed version id; `InternalError` before the store is up.
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
pub async fn execute_get_object_tagging(
|
||||
&self,
|
||||
envelope: RequestEnvelope,
|
||||
@@ -170,7 +167,6 @@ impl ObjectMetaUsecase {
|
||||
///
|
||||
/// Returns `InvalidTag` for an invalid tag set, a refusal for reserved objects, or the
|
||||
/// storage error when the tags cannot be written.
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
pub async fn execute_put_object_tagging(
|
||||
&self,
|
||||
envelope: RequestEnvelope,
|
||||
@@ -296,7 +292,6 @@ impl ObjectMetaUsecase {
|
||||
///
|
||||
/// `MethodNotAllowed` for a Veeam SOSAPI system object; `InvalidRequest` for a reserved table
|
||||
/// catalog object; `InternalError` before the store is up; the store's refusal otherwise.
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
pub async fn execute_delete_object_tagging(
|
||||
&self,
|
||||
envelope: RequestEnvelope,
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
//! NOT responsible for: authorization (there is none: the answer is the same for every caller).
|
||||
//! Upstream: both edges. Downstream: none.
|
||||
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
use rustfs_gateway_types::dto::GetObjectTorrentInput;
|
||||
use rustfs_gateway_types::dto::GetObjectTorrentOutput;
|
||||
use rustfs_s3_types::{S3Error, S3ErrorCode, S3Result};
|
||||
@@ -29,7 +28,6 @@ use rustfs_s3_types::{S3Error, S3ErrorCode, S3Result};
|
||||
/// # Errors
|
||||
///
|
||||
/// Always `NoSuchKey`.
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
pub(crate) fn execute_get_object_torrent(_input: GetObjectTorrentInput) -> S3Result<GetObjectTorrentOutput> {
|
||||
answer_get_object_torrent()
|
||||
}
|
||||
|
||||
@@ -22,8 +22,6 @@ pub(crate) use crate::runtime_sources::{
|
||||
current_notification_system_for_context, current_object_data_cache_handle_for_context,
|
||||
current_object_store_handle_for_context,
|
||||
};
|
||||
#[cfg(test)]
|
||||
pub(crate) use crate::runtime_sources::{IamInterface, KmsInterface};
|
||||
use rustfs_s3select_api::request::SelectObjectContentInput;
|
||||
use rustfs_s3select_api::{QueryResult, server::dbms::DatabaseManagerSystem};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -68,7 +68,6 @@ pub(crate) fn select_input_from_s3s(
|
||||
}
|
||||
|
||||
/// Moves the gateway's flat request into the shape the query engine reads.
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
pub(crate) fn select_input_from_gateway(
|
||||
input: rustfs_gateway_types::dto::SelectObjectContentInput,
|
||||
) -> engine::SelectObjectContentInput {
|
||||
|
||||
@@ -1601,7 +1601,6 @@ pub(crate) mod concurrency {
|
||||
}
|
||||
|
||||
pub(crate) mod compression {
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
pub(crate) use crate::storage::storage_api::ecstore_compression::DISK_COMPRESSION_EXCLUDED_CONTENT_TYPES;
|
||||
pub(crate) use crate::storage::storage_api::ecstore_compression::{
|
||||
MIN_DISK_COMPRESSIBLE_SIZE, is_disk_compressible, is_multipart_disk_compression_enabled,
|
||||
@@ -1871,12 +1870,10 @@ pub(crate) mod multipart_usecase {
|
||||
}
|
||||
|
||||
pub(crate) mod multipart {
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
pub(crate) use super::super::super::storage_contracts::multipart::ListPartsOwner;
|
||||
pub(crate) use super::super::super::storage_contracts::{
|
||||
CompletePart, ListMultipartsInfo, ListPartsInfo, MultipartInfo, MultipartOperations, MultipartUploadResult,
|
||||
};
|
||||
#[cfg(any(feature = "gateway-stack", test))]
|
||||
pub(crate) use super::super::super::storage_contracts::{MultipartAbortAuthorization, MultipartOwner};
|
||||
pub(crate) use crate::storage::storage_api::s3_api_consumer::multipart::contract::multipart::MAX_MULTIPART_PART_NUMBER;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,557 @@
|
||||
// Copyright 2024 RustFS Team
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Static website hosting: which requests a website host claims, and how they are answered.
|
||||
//!
|
||||
//! Responsible for: [`WebsiteHost`], the one copy of the website rules both S3 stacks serve —
|
||||
//! the `Host` that selects a bucket, the index and error documents, the redirect rules and the
|
||||
//! object's own redirect location — read anonymously through the owned GetObject and HeadObject
|
||||
//! authorization and use cases, marking each GetObject with `WebsiteRead` so it reports the
|
||||
//! object's redirect location.
|
||||
//! NOT responsible for: where the stack mounts the host (`server/stack.rs`), or any object read
|
||||
//! itself (the use cases).
|
||||
//! Upstream: the gateway stack's website service. Downstream: the
|
||||
//! owned GetObject and HeadObject authorization and use cases, and the bucket's website
|
||||
//! configuration.
|
||||
|
||||
use crate::app::object_usecase::{DefaultObjectUsecase, GetObjectBody, GetObjectFields, GetObjectOutputFacts, HeadObjectFields};
|
||||
use crate::app::runtime_sources::ServerContextSlot;
|
||||
use crate::app::storage_api::s3::dto::{
|
||||
ETagCondition, GetObjectInput, Range, Timestamp as WireTimestamp, TimestampFormat as WireFormat,
|
||||
};
|
||||
use crate::app::{Answered, RequestEnvelope, RequestHead};
|
||||
use crate::storage::access::access_owned::object_read::{authorize_get_object, authorize_head_object};
|
||||
use crate::storage::req_info::ReqInfo;
|
||||
use crate::storage::request_markers::WebsiteRead;
|
||||
use crate::storage::{get_bucket_website_config_for_store, validate_website_configuration};
|
||||
use http::header::{CONTENT_TYPE, HOST, HeaderName};
|
||||
use http::{Extensions, HeaderMap, HeaderValue, Method, Response, StatusCode, Uri};
|
||||
use rustfs_gateway_stream::Body;
|
||||
use rustfs_gateway_types::TimestampFormat;
|
||||
use rustfs_gateway_types::persistence::{PersistedErrorDocument, PersistedRoutingRule as RoutingRule};
|
||||
use rustfs_io_metrics::record_s3_op;
|
||||
use rustfs_s3_ops::S3Operation;
|
||||
use rustfs_s3_types::{S3Error, S3ErrorCode, S3Result};
|
||||
use std::sync::Arc;
|
||||
|
||||
/// An answer of the website host.
|
||||
pub(crate) type WebsiteResponse = Response<Body>;
|
||||
|
||||
/// The headers a website read drops before a lookup that must not be conditional or ranged.
|
||||
const CONDITIONAL_HEADERS: [HeaderName; 5] = [
|
||||
http::header::RANGE,
|
||||
http::header::IF_MATCH,
|
||||
http::header::IF_NONE_MATCH,
|
||||
http::header::IF_MODIFIED_SINCE,
|
||||
http::header::IF_UNMODIFIED_SINCE,
|
||||
];
|
||||
|
||||
/// The website host of one server: the configured website domains, the scheme its redirects
|
||||
/// default to, and the server whose buckets it serves.
|
||||
pub(crate) struct WebsiteHost {
|
||||
domains: Vec<String>,
|
||||
scheme: &'static str,
|
||||
server_ctx: Arc<ServerContextSlot>,
|
||||
}
|
||||
|
||||
impl WebsiteHost {
|
||||
/// The host for `domains`, or `None` when no website domain is configured.
|
||||
pub(crate) fn new(domains: Vec<String>, scheme: &'static str, server_ctx: Arc<ServerContextSlot>) -> Option<Self> {
|
||||
(!domains.is_empty()).then_some(Self {
|
||||
domains,
|
||||
scheme,
|
||||
server_ctx,
|
||||
})
|
||||
}
|
||||
|
||||
/// Whether the request's `Host` is a website domain, so this host answers it.
|
||||
pub(crate) fn claims(&self, uri: &Uri, headers: &HeaderMap) -> bool {
|
||||
website_target(uri, headers, &self.domains).is_some()
|
||||
}
|
||||
|
||||
/// Answers one claimed request anonymously. Every failure is a website error page with the
|
||||
/// failure's status, never an S3 error document.
|
||||
pub(crate) async fn answer(&self, method: Method, uri: Uri, headers: HeaderMap, extensions: Extensions) -> WebsiteResponse {
|
||||
let head = method == Method::HEAD;
|
||||
let Some(target) = website_target(&uri, &headers, &self.domains) else {
|
||||
return website_error(StatusCode::NOT_FOUND, head);
|
||||
};
|
||||
let request = WebsiteRequest {
|
||||
method,
|
||||
uri,
|
||||
headers,
|
||||
extensions,
|
||||
server_ctx: Arc::clone(&self.server_ctx),
|
||||
};
|
||||
// The reads are large futures; boxed, a website request does not grow the caller's stack.
|
||||
match Box::pin(serve(&request, target, self.scheme)).await {
|
||||
Ok(response) => response,
|
||||
Err(err) => website_error(err.status_code().unwrap_or(StatusCode::INTERNAL_SERVER_ERROR), head),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct WebsiteTarget {
|
||||
bucket: String,
|
||||
key: String,
|
||||
trailing_slash: bool,
|
||||
invalid_path: bool,
|
||||
}
|
||||
|
||||
fn website_target(uri: &Uri, headers: &HeaderMap, domains: &[String]) -> Option<WebsiteTarget> {
|
||||
if domains.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let host_header = headers.get(HOST)?.to_str().ok()?;
|
||||
let authority = host_header.parse::<http::uri::Authority>().ok()?;
|
||||
let request_host = authority.host().trim_end_matches('.').to_ascii_lowercase();
|
||||
let bucket = domains.iter().find_map(|domain| {
|
||||
if request_host == *domain {
|
||||
return Some(String::new());
|
||||
}
|
||||
request_host.strip_suffix(&format!(".{domain}")).map(str::to_owned)
|
||||
})?;
|
||||
let raw_path = uri.path();
|
||||
let decoded = urlencoding::decode(raw_path);
|
||||
let invalid_path = decoded.is_err();
|
||||
let decoded = decoded.unwrap_or_default();
|
||||
let path = decoded.trim_start_matches('/');
|
||||
Some(WebsiteTarget {
|
||||
bucket,
|
||||
key: path.to_owned(),
|
||||
trailing_slash: path.is_empty() || path.ends_with('/'),
|
||||
invalid_path,
|
||||
})
|
||||
}
|
||||
|
||||
/// One website request as the reads it makes see it.
|
||||
struct WebsiteRequest {
|
||||
method: Method,
|
||||
uri: Uri,
|
||||
headers: HeaderMap,
|
||||
extensions: Extensions,
|
||||
server_ctx: Arc<ServerContextSlot>,
|
||||
}
|
||||
|
||||
impl WebsiteRequest {
|
||||
fn head(&self) -> bool {
|
||||
self.method == Method::HEAD
|
||||
}
|
||||
|
||||
/// An anonymous read of `bucket/key`: no credentials and no owner, whatever the request carried.
|
||||
fn envelope(&self, method: Method, headers: HeaderMap, bucket: &str, key: &str, website_read: bool) -> RequestEnvelope {
|
||||
let mut extensions = self.extensions.clone();
|
||||
extensions.insert(Arc::clone(&self.server_ctx));
|
||||
let mut req_info = extensions.remove::<ReqInfo>().unwrap_or_default();
|
||||
req_info.cred = None;
|
||||
req_info.is_owner = false;
|
||||
req_info.bucket = Some(bucket.to_owned());
|
||||
req_info.object = Some(key.to_owned());
|
||||
req_info.version_id = None;
|
||||
extensions.insert(req_info);
|
||||
if website_read {
|
||||
extensions.insert(WebsiteRead);
|
||||
}
|
||||
let head = RequestHead {
|
||||
method,
|
||||
uri: self.uri.clone(),
|
||||
headers,
|
||||
credentials: None,
|
||||
region: None,
|
||||
service: None,
|
||||
};
|
||||
RequestEnvelope::from_parts(head, extensions)
|
||||
}
|
||||
|
||||
fn usecase(&self) -> DefaultObjectUsecase {
|
||||
DefaultObjectUsecase::with_context(self.server_ctx.app_context())
|
||||
}
|
||||
|
||||
/// GetObject of `bucket/key`, with the request's range and conditions when `apply_conditions`.
|
||||
async fn get_object(&self, bucket: &str, key: &str, apply_conditions: bool) -> S3Result<Answered<GetObjectOutputFacts>> {
|
||||
let (range, headers) = if apply_conditions {
|
||||
(validated_conditions(&self.headers)?, self.headers.clone())
|
||||
} else {
|
||||
(None, without_conditions(&self.headers))
|
||||
};
|
||||
let mut envelope = self.envelope(Method::GET, headers, bucket, key, true);
|
||||
authorize_get_object(&self.server_ctx, &mut envelope, bucket, key, None).await?;
|
||||
record_s3_op(S3Operation::GetObject);
|
||||
let fields = GetObjectFields::from_s3s(GetObjectInput {
|
||||
bucket: bucket.to_owned(),
|
||||
key: key.to_owned(),
|
||||
range,
|
||||
..Default::default()
|
||||
});
|
||||
Box::pin(self.usecase().execute_get_object_fields(envelope, fields)).await
|
||||
}
|
||||
|
||||
/// The redirect location HeadObject reports for `bucket/key`, read unconditionally.
|
||||
async fn head_redirect(&self, bucket: &str, key: &str) -> S3Result<Option<String>> {
|
||||
let mut envelope = self.envelope(Method::HEAD, without_conditions(&self.headers), bucket, key, false);
|
||||
authorize_head_object(&self.server_ctx, &mut envelope, bucket, key, None).await?;
|
||||
record_s3_op(S3Operation::HeadObject);
|
||||
let fields = HeadObjectFields {
|
||||
bucket: bucket.to_owned(),
|
||||
key: key.to_owned(),
|
||||
version_id: None,
|
||||
part_number: None,
|
||||
range: None,
|
||||
sse_customer_key: None,
|
||||
sse_customer_key_md5: None,
|
||||
};
|
||||
let answered = Box::pin(self.usecase().execute_head_object_fields(envelope, fields)).await?;
|
||||
Ok(answered.output.dto.website_redirect_location)
|
||||
}
|
||||
}
|
||||
|
||||
fn header_text(headers: &HeaderMap, name: HeaderName) -> S3Result<Option<String>> {
|
||||
headers
|
||||
.get(name)
|
||||
.map(|value| {
|
||||
value
|
||||
.to_str()
|
||||
.map(str::to_owned)
|
||||
.map_err(|_| S3Error::new(S3ErrorCode::InvalidArgument))
|
||||
})
|
||||
.transpose()
|
||||
}
|
||||
|
||||
/// The range a conditional read asks for, after refusing a malformed range or condition the
|
||||
/// way the S3 GetObject decoder refuses it.
|
||||
fn validated_conditions(headers: &HeaderMap) -> S3Result<Option<Range>> {
|
||||
let range = header_text(headers, http::header::RANGE)?
|
||||
.map(|value| Range::parse(&value).map_err(|_| S3Error::new(S3ErrorCode::InvalidRange)))
|
||||
.transpose()?;
|
||||
for name in [http::header::IF_MATCH, http::header::IF_NONE_MATCH] {
|
||||
if let Some(value) = headers.get(name) {
|
||||
ETagCondition::parse_http_header(value.as_bytes()).map_err(|_| S3Error::new(S3ErrorCode::InvalidArgument))?;
|
||||
}
|
||||
}
|
||||
for name in [http::header::IF_MODIFIED_SINCE, http::header::IF_UNMODIFIED_SINCE] {
|
||||
if let Some(value) = header_text(headers, name)? {
|
||||
WireTimestamp::parse(WireFormat::HttpDate, &value).map_err(|_| S3Error::new(S3ErrorCode::InvalidArgument))?;
|
||||
}
|
||||
}
|
||||
Ok(range)
|
||||
}
|
||||
|
||||
fn without_conditions(headers: &HeaderMap) -> HeaderMap {
|
||||
let mut headers = headers.clone();
|
||||
for name in CONDITIONAL_HEADERS {
|
||||
headers.remove(name);
|
||||
}
|
||||
headers
|
||||
}
|
||||
|
||||
async fn serve(req: &WebsiteRequest, target: WebsiteTarget, website_scheme: &'static str) -> S3Result<WebsiteResponse> {
|
||||
if !matches!(req.method, Method::GET | Method::HEAD) {
|
||||
return Ok(website_error(StatusCode::METHOD_NOT_ALLOWED, req.head()));
|
||||
}
|
||||
if target.invalid_path {
|
||||
return Ok(website_error(StatusCode::BAD_REQUEST, req.head()));
|
||||
}
|
||||
if target.bucket.is_empty() || target.bucket.starts_with('.') || target.bucket.ends_with('.') || target.bucket.contains("..")
|
||||
{
|
||||
return Ok(website_error(StatusCode::NOT_FOUND, req.head()));
|
||||
}
|
||||
|
||||
let store = req
|
||||
.server_ctx
|
||||
.installed_object_store()
|
||||
.ok_or_else(|| S3Error::with_message(S3ErrorCode::InternalError, "website object store unavailable"))?;
|
||||
let config = match get_bucket_website_config_for_store(&store, &target.bucket).await {
|
||||
Ok(config) => config,
|
||||
Err(crate::storage::StorageError::ConfigNotFound | crate::storage::StorageError::BucketNotFound(_)) => {
|
||||
return Ok(website_error(StatusCode::NOT_FOUND, req.head()));
|
||||
}
|
||||
Err(err) => return Err(crate::error::ApiError::from(err).into()),
|
||||
};
|
||||
if validate_website_configuration(&config).is_err() {
|
||||
return Ok(website_error(StatusCode::INTERNAL_SERVER_ERROR, req.head()));
|
||||
}
|
||||
|
||||
if let Some(redirect) = config.redirect_all_requests_to.as_ref() {
|
||||
return website_redirect(
|
||||
&req.uri,
|
||||
&req.headers,
|
||||
redirect.host_name.as_str(),
|
||||
redirect.protocol.as_deref(),
|
||||
&target.key,
|
||||
StatusCode::MOVED_PERMANENTLY,
|
||||
website_scheme,
|
||||
);
|
||||
}
|
||||
|
||||
let index_suffix = config
|
||||
.index_document
|
||||
.as_ref()
|
||||
.map(|doc| doc.suffix.as_str())
|
||||
.unwrap_or_default();
|
||||
let key = if target.key.is_empty() || target.trailing_slash {
|
||||
format!("{}{index_suffix}", target.key)
|
||||
} else {
|
||||
target.key.clone()
|
||||
};
|
||||
|
||||
let rules = config.routing_rules.as_deref().unwrap_or_default();
|
||||
// A rule requiring a status cannot be evaluated until the object lookup completes.
|
||||
for rule in rules {
|
||||
if rule
|
||||
.condition
|
||||
.as_ref()
|
||||
.and_then(|condition| condition.http_error_code_returned_equals.as_ref())
|
||||
.is_some()
|
||||
{
|
||||
break;
|
||||
}
|
||||
if website_rule_matches(rule, &target.key, StatusCode::OK) {
|
||||
return website_rule_redirect(req, rule, &target.key, website_scheme);
|
||||
}
|
||||
}
|
||||
|
||||
let response = req.get_object(&target.bucket, &key, true).await;
|
||||
if let Err(err) = &response
|
||||
&& matches!(
|
||||
err.code(),
|
||||
S3ErrorCode::NotModified | S3ErrorCode::PreconditionFailed | S3ErrorCode::InvalidRange
|
||||
)
|
||||
&& let Ok(Some(location)) = req.head_redirect(&target.bucket, &key).await
|
||||
{
|
||||
return website_location(location, StatusCode::MOVED_PERMANENTLY);
|
||||
}
|
||||
let status = match &response {
|
||||
Ok(_) => StatusCode::OK,
|
||||
Err(err) => err.status_code().unwrap_or(StatusCode::INTERNAL_SERVER_ERROR),
|
||||
};
|
||||
if status == StatusCode::NOT_FOUND && !target.trailing_slash && !target.key.is_empty() {
|
||||
let index_key = format!("{}/{index_suffix}", target.key);
|
||||
match req.get_object(&target.bucket, &index_key, false).await {
|
||||
Ok(_) => return website_relative_redirect(&req.uri, &format!("/{}/", target.key), StatusCode::FOUND),
|
||||
Err(err)
|
||||
if matches!(
|
||||
err.code(),
|
||||
S3ErrorCode::NoSuchKey | S3ErrorCode::NoSuchVersion | S3ErrorCode::AccessDenied
|
||||
) => {}
|
||||
Err(err) => return Err(err),
|
||||
}
|
||||
}
|
||||
if let Some(rule) = rules.iter().find(|rule| website_rule_matches(rule, &target.key, status)) {
|
||||
return website_rule_redirect(req, rule, &target.key, website_scheme);
|
||||
}
|
||||
match response {
|
||||
Ok(response) => {
|
||||
if let Some(location) = response.output.dto.website_redirect_location.clone() {
|
||||
return website_location(location, StatusCode::MOVED_PERMANENTLY);
|
||||
}
|
||||
response_to_website(response, req.head())
|
||||
}
|
||||
Err(err) if matches!(err.code(), S3ErrorCode::NoSuchKey | S3ErrorCode::NoSuchVersion) => {
|
||||
website_error_with_document(req, &target.bucket, config.error_document.as_ref(), StatusCode::NOT_FOUND).await
|
||||
}
|
||||
Err(err) if err.code() == &S3ErrorCode::NotModified => Ok(website_not_modified(&err)),
|
||||
Err(_) if status.is_client_error() => {
|
||||
website_error_with_document(req, &target.bucket, config.error_document.as_ref(), status).await
|
||||
}
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
|
||||
/// The object's page: its representation headers, and its body unless the request is `HEAD`.
|
||||
fn response_to_website(response: Answered<GetObjectOutputFacts>, head: bool) -> S3Result<WebsiteResponse> {
|
||||
let Answered { output, mut headers, .. } = response;
|
||||
let GetObjectOutputFacts { dto, etag, body } = output;
|
||||
insert_website_header(&mut headers, http::header::CONTENT_TYPE, dto.content_type.as_deref())?;
|
||||
insert_website_header(
|
||||
&mut headers,
|
||||
http::header::CONTENT_LENGTH,
|
||||
dto.content_length.map(|length| length.to_string()).as_deref(),
|
||||
)?;
|
||||
insert_website_header(&mut headers, http::header::CONTENT_RANGE, dto.content_range.as_deref())?;
|
||||
let etag = etag.map(|tag| {
|
||||
if tag.weak {
|
||||
format!("W/\"{}\"", tag.opaque)
|
||||
} else {
|
||||
format!("\"{}\"", tag.opaque)
|
||||
}
|
||||
});
|
||||
insert_website_header(&mut headers, http::header::ETAG, etag.as_deref())?;
|
||||
insert_website_header(&mut headers, http::header::CACHE_CONTROL, dto.cache_control.as_deref())?;
|
||||
insert_website_header(&mut headers, http::header::CONTENT_ENCODING, dto.content_encoding.as_deref())?;
|
||||
insert_website_header(&mut headers, http::header::CONTENT_LANGUAGE, dto.content_language.as_deref())?;
|
||||
insert_website_header(&mut headers, http::header::CONTENT_DISPOSITION, dto.content_disposition.as_deref())?;
|
||||
let last_modified = dto
|
||||
.last_modified
|
||||
.map(|at| at.render(TimestampFormat::HttpDate).map_err(S3Error::internal_error))
|
||||
.transpose()?;
|
||||
insert_website_header(&mut headers, http::header::LAST_MODIFIED, last_modified.as_deref())?;
|
||||
let body = match body {
|
||||
_ if head => Body::empty(),
|
||||
None => Body::empty(),
|
||||
Some(GetObjectBody::Bytes(bytes)) => Body::from_bytes(bytes),
|
||||
Some(GetObjectBody::Stream(stream)) => Body::from_stream(stream).map_err(S3Error::internal_error)?,
|
||||
};
|
||||
let status = if dto.content_range.is_some() {
|
||||
StatusCode::PARTIAL_CONTENT
|
||||
} else {
|
||||
StatusCode::OK
|
||||
};
|
||||
Ok(answer(status, headers, body))
|
||||
}
|
||||
|
||||
fn answer(status: StatusCode, headers: HeaderMap, body: Body) -> WebsiteResponse {
|
||||
let mut response = Response::new(body);
|
||||
*response.status_mut() = status;
|
||||
*response.headers_mut() = headers;
|
||||
response
|
||||
}
|
||||
|
||||
fn insert_website_header(headers: &mut HeaderMap, name: HeaderName, value: Option<&str>) -> S3Result<()> {
|
||||
if let Some(value) = value {
|
||||
headers.insert(name, HeaderValue::from_str(value).map_err(S3Error::internal_error)?);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn website_error_with_document(
|
||||
req: &WebsiteRequest,
|
||||
bucket: &str,
|
||||
error_document: Option<&PersistedErrorDocument>,
|
||||
status: StatusCode,
|
||||
) -> S3Result<WebsiteResponse> {
|
||||
let Some(error_document) = error_document else {
|
||||
return Ok(website_error(status, req.head()));
|
||||
};
|
||||
match req.get_object(bucket, error_document.key.as_str(), false).await {
|
||||
Ok(response) => {
|
||||
let mut output = response_to_website(response, req.head())?;
|
||||
*output.status_mut() = status;
|
||||
Ok(output)
|
||||
}
|
||||
Err(err)
|
||||
if matches!(
|
||||
err.code(),
|
||||
S3ErrorCode::NoSuchKey | S3ErrorCode::NoSuchVersion | S3ErrorCode::AccessDenied
|
||||
) =>
|
||||
{
|
||||
Ok(website_error(status, req.head()))
|
||||
}
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
|
||||
fn website_error(status: StatusCode, head: bool) -> WebsiteResponse {
|
||||
let message = status.canonical_reason().unwrap_or("Error");
|
||||
let body = format!("<html><body>{message}</body></html>");
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert(CONTENT_TYPE, HeaderValue::from_static("text/html; charset=utf-8"));
|
||||
answer(status, headers, if head { Body::empty() } else { Body::from_bytes(body.into()) })
|
||||
}
|
||||
|
||||
fn website_not_modified(error: &S3Error) -> WebsiteResponse {
|
||||
let mut headers = error.headers().cloned().unwrap_or_default();
|
||||
headers.remove(http::header::CONTENT_LENGTH);
|
||||
headers.remove(http::header::CONTENT_TYPE);
|
||||
headers.remove(http::header::TRANSFER_ENCODING);
|
||||
answer(StatusCode::NOT_MODIFIED, headers, Body::empty())
|
||||
}
|
||||
|
||||
fn website_location(location: String, status: StatusCode) -> S3Result<WebsiteResponse> {
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert(
|
||||
http::header::LOCATION,
|
||||
HeaderValue::try_from(location)
|
||||
.map_err(|_| S3Error::with_message(S3ErrorCode::InternalError, "invalid website redirect location"))?,
|
||||
);
|
||||
Ok(answer(status, headers, Body::empty()))
|
||||
}
|
||||
|
||||
fn website_relative_redirect(uri: &Uri, path: &str, status: StatusCode) -> S3Result<WebsiteResponse> {
|
||||
let mut url = url::Url::parse("http://localhost/").map_err(S3Error::internal_error)?;
|
||||
url.set_path(path);
|
||||
url.set_query(uri.query());
|
||||
let location = match url.query() {
|
||||
Some(query) => format!("{}?{query}", url.path()),
|
||||
None => url.path().to_owned(),
|
||||
};
|
||||
website_location(location, status)
|
||||
}
|
||||
|
||||
fn website_redirect(
|
||||
uri: &Uri,
|
||||
headers: &HeaderMap,
|
||||
host: &str,
|
||||
protocol: Option<&str>,
|
||||
key: &str,
|
||||
status: StatusCode,
|
||||
website_scheme: &str,
|
||||
) -> S3Result<WebsiteResponse> {
|
||||
let scheme = protocol.unwrap_or(website_scheme);
|
||||
let host = if host.is_empty() {
|
||||
headers.get(HOST).and_then(|h| h.to_str().ok()).unwrap_or_default()
|
||||
} else {
|
||||
host
|
||||
};
|
||||
let mut url = url::Url::parse(&format!("{scheme}://{host}/")).map_err(S3Error::internal_error)?;
|
||||
url.set_path(&format!("/{key}"));
|
||||
url.set_query(uri.query());
|
||||
website_location(url.into(), status)
|
||||
}
|
||||
|
||||
fn website_rule_matches(rule: &RoutingRule, key: &str, status: StatusCode) -> bool {
|
||||
let Some(condition) = rule.condition.as_ref() else { return true };
|
||||
condition
|
||||
.key_prefix_equals
|
||||
.as_ref()
|
||||
.is_none_or(|prefix| key.starts_with(prefix))
|
||||
&& condition
|
||||
.http_error_code_returned_equals
|
||||
.as_ref()
|
||||
.is_none_or(|code| code == status.as_str())
|
||||
}
|
||||
|
||||
fn website_rule_redirect(req: &WebsiteRequest, rule: &RoutingRule, key: &str, website_scheme: &str) -> S3Result<WebsiteResponse> {
|
||||
let redirect = &rule.redirect;
|
||||
let key = if let Some(replace) = &redirect.replace_key_with {
|
||||
replace.clone()
|
||||
} else if let Some(replace) = &redirect.replace_key_prefix_with {
|
||||
let prefix = rule
|
||||
.condition
|
||||
.as_ref()
|
||||
.and_then(|condition| condition.key_prefix_equals.as_deref())
|
||||
.unwrap_or_default();
|
||||
format!("{replace}{}", key.strip_prefix(prefix).unwrap_or(key))
|
||||
} else {
|
||||
key.to_owned()
|
||||
};
|
||||
let status = redirect
|
||||
.http_redirect_code
|
||||
.as_deref()
|
||||
.and_then(|code| code.parse::<u16>().ok())
|
||||
.and_then(|code| StatusCode::from_u16(code).ok())
|
||||
.unwrap_or(StatusCode::MOVED_PERMANENTLY);
|
||||
website_redirect(
|
||||
&req.uri,
|
||||
&req.headers,
|
||||
redirect.host_name.as_deref().unwrap_or_default(),
|
||||
redirect.protocol.as_deref(),
|
||||
&key,
|
||||
status,
|
||||
website_scheme,
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
@@ -0,0 +1,463 @@
|
||||
// Copyright 2024 RustFS Team
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! The website rules, and the host answering real buckets as both stacks serve them.
|
||||
|
||||
use super::*;
|
||||
use crate::app::storage_api::bucket_usecase::contract::bucket::{BucketOperations as _, MakeBucketOptions};
|
||||
use crate::app::storage_api::object_usecase::contract::object::ObjectIO as _;
|
||||
use crate::app::storage_api::object_usecase::{StorageObjectOptions, StoragePutObjReader};
|
||||
use crate::app::storage_api::test::ECStore;
|
||||
use http_body_util::BodyExt;
|
||||
use rustfs_gateway_types::persistence::{
|
||||
PersistedRedirect as Redirect, PersistedRoutingRule as RoutingRule, PersistedRoutingRuleCondition as Condition,
|
||||
};
|
||||
use serial_test::serial;
|
||||
|
||||
fn uri(value: &str) -> Uri {
|
||||
value.parse().expect("test URI should parse")
|
||||
}
|
||||
|
||||
fn host(value: &str) -> HeaderMap {
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert(HOST, value.parse().expect("valid host"));
|
||||
headers
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn website_host_is_isolated_from_s3_host_and_keeps_directory_suffix() {
|
||||
let domains = vec!["example.com".to_owned()];
|
||||
let mut headers = host("share.example.com:9000");
|
||||
let target = website_target(&uri("/docs/"), &headers, &domains).expect("website host matches");
|
||||
assert_eq!(target.bucket, "share");
|
||||
assert_eq!(target.key, "docs/");
|
||||
assert!(target.trailing_slash);
|
||||
headers.insert(HOST, "s3.other.test".parse().expect("valid host"));
|
||||
assert!(website_target(&uri("/share/docs/"), &headers, &domains).is_none());
|
||||
headers.insert(HOST, "my.bucket.example.com".parse().expect("valid host"));
|
||||
assert_eq!(
|
||||
website_target(&uri("/"), &headers, &domains)
|
||||
.expect("dotted bucket host matches")
|
||||
.bucket,
|
||||
"my.bucket"
|
||||
);
|
||||
headers.insert(HOST, "example.com".parse().expect("valid host"));
|
||||
assert_eq!(
|
||||
website_target(&uri("/share/key"), &headers, &domains)
|
||||
.expect("base domain is reserved")
|
||||
.bucket,
|
||||
""
|
||||
);
|
||||
headers.insert(HOST, "share.example.com".parse().expect("valid host"));
|
||||
assert!(
|
||||
website_target(&uri("/%FF"), &headers, &domains)
|
||||
.expect("invalid path stays in website route")
|
||||
.invalid_path
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn website_host_claims_only_its_domains_and_nothing_without_one() {
|
||||
let server_ctx = ServerContextSlot::new();
|
||||
assert!(WebsiteHost::new(Vec::new(), "http", Arc::clone(&server_ctx)).is_none());
|
||||
let website = WebsiteHost::new(vec!["website.test".to_owned()], "http", server_ctx).expect("a configured domain");
|
||||
for claimed in [
|
||||
"website.test",
|
||||
"bucket.website.test",
|
||||
"BUCKET.Website.Test.",
|
||||
"bucket.website.test:9000",
|
||||
] {
|
||||
assert!(website.claims(&uri("/key"), &host(claimed)), "{claimed}");
|
||||
}
|
||||
for unclaimed in [
|
||||
"localhost",
|
||||
"website.test.evil",
|
||||
"bucketwebsite.test",
|
||||
"s3.example.test",
|
||||
"a b",
|
||||
] {
|
||||
assert!(!website.claims(&uri("/key"), &host(unclaimed)), "{unclaimed}");
|
||||
}
|
||||
assert!(!website.claims(&uri("/key"), &HeaderMap::new()), "no Host");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn website_redirect_encodes_path_and_preserves_query() {
|
||||
let target = uri("/old?download=1");
|
||||
let headers = host("site.example.com");
|
||||
let redirect = website_redirect(
|
||||
&target,
|
||||
&headers,
|
||||
"new.example.com",
|
||||
Some("https"),
|
||||
"new path/#one",
|
||||
StatusCode::MOVED_PERMANENTLY,
|
||||
"http",
|
||||
)
|
||||
.expect("valid redirect");
|
||||
assert_eq!(
|
||||
redirect.headers()[http::header::LOCATION],
|
||||
"https://new.example.com/new%20path/%23one?download=1"
|
||||
);
|
||||
let directory = website_relative_redirect(&target, "/new path/", StatusCode::FOUND).expect("valid directory redirect");
|
||||
assert_eq!(directory.headers()[http::header::LOCATION], "/new%20path/?download=1");
|
||||
let secure = website_redirect(&target, &headers, "new.example.com", None, "key", StatusCode::MOVED_PERMANENTLY, "https")
|
||||
.expect("TLS listener default scheme");
|
||||
assert_eq!(secure.headers()[http::header::LOCATION], "https://new.example.com/key?download=1");
|
||||
let same_host = website_redirect(&target, &headers, "", None, "key", StatusCode::MOVED_PERMANENTLY, "http")
|
||||
.expect("an empty host name keeps the request's host");
|
||||
assert_eq!(same_host.headers()[http::header::LOCATION], "http://site.example.com/key?download=1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn website_rules_choose_first_match_after_object_status_is_known() {
|
||||
let error_rule = RoutingRule {
|
||||
condition: Some(Condition {
|
||||
http_error_code_returned_equals: Some("404".to_owned()),
|
||||
key_prefix_equals: None,
|
||||
}),
|
||||
redirect: Redirect::default(),
|
||||
};
|
||||
let prefix_rule = RoutingRule {
|
||||
condition: Some(Condition {
|
||||
http_error_code_returned_equals: None,
|
||||
key_prefix_equals: Some("docs/".to_owned()),
|
||||
}),
|
||||
redirect: Redirect::default(),
|
||||
};
|
||||
let rules = [error_rule, prefix_rule];
|
||||
assert_eq!(
|
||||
rules
|
||||
.iter()
|
||||
.position(|rule| website_rule_matches(rule, "docs/missing", StatusCode::NOT_FOUND)),
|
||||
Some(0)
|
||||
);
|
||||
assert_eq!(
|
||||
rules
|
||||
.iter()
|
||||
.position(|rule| website_rule_matches(rule, "docs/existing", StatusCode::OK)),
|
||||
Some(1)
|
||||
);
|
||||
assert_eq!(
|
||||
rules
|
||||
.iter()
|
||||
.position(|rule| website_rule_matches(rule, "other", StatusCode::FORBIDDEN)),
|
||||
None
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn website_304_preserves_cache_headers_without_content() {
|
||||
let mut error = S3Error::new(S3ErrorCode::NotModified);
|
||||
let mut headers = HeaderMap::new();
|
||||
for (name, value) in [
|
||||
("etag", "\"abc\""),
|
||||
("cache-control", "max-age=60"),
|
||||
("expires", "Tue, 14 Nov 2023 22:13:20 GMT"),
|
||||
("content-length", "123"),
|
||||
("content-type", "application/xml"),
|
||||
("transfer-encoding", "chunked"),
|
||||
] {
|
||||
headers.insert(name, HeaderValue::from_static(value));
|
||||
}
|
||||
error.set_headers(headers);
|
||||
let response = website_not_modified(&error);
|
||||
assert_eq!(response.status(), StatusCode::NOT_MODIFIED);
|
||||
assert_eq!(response.headers()["etag"], "\"abc\"");
|
||||
assert_eq!(response.headers()["cache-control"], "max-age=60");
|
||||
assert!(response.headers().contains_key("expires"));
|
||||
for dropped in ["content-length", "content-type", "transfer-encoding"] {
|
||||
assert!(!response.headers().contains_key(dropped), "{dropped}");
|
||||
}
|
||||
assert!(
|
||||
response
|
||||
.into_body()
|
||||
.collect()
|
||||
.await
|
||||
.expect("empty website body")
|
||||
.to_bytes()
|
||||
.is_empty()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn website_conditions_are_refused_as_the_s3_decoder_refuses_them() {
|
||||
let refused = |name: &'static str, value: &'static str| {
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert(name, HeaderValue::from_static(value));
|
||||
validated_conditions(&headers).expect_err(value).code().clone()
|
||||
};
|
||||
assert_eq!(refused("range", "bytes=5-1"), S3ErrorCode::InvalidRange);
|
||||
assert_eq!(refused("range", "bytes=0-1,3-4"), S3ErrorCode::InvalidRange);
|
||||
assert_eq!(refused("range", "items=0-1"), S3ErrorCode::InvalidRange);
|
||||
assert_eq!(refused("if-modified-since", "yesterday"), S3ErrorCode::InvalidArgument);
|
||||
assert_eq!(refused("if-unmodified-since", "2024-01-01"), S3ErrorCode::InvalidArgument);
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert("range", HeaderValue::from_static("bytes=2-"));
|
||||
headers.insert("if-none-match", HeaderValue::from_static("*"));
|
||||
headers.insert("if-modified-since", HeaderValue::from_static("Tue, 14 Nov 2023 22:13:20 GMT"));
|
||||
assert!(matches!(
|
||||
validated_conditions(&headers).expect("well-formed conditions"),
|
||||
Some(Range::Int { first: 2, last: None })
|
||||
));
|
||||
let stripped = without_conditions(&headers);
|
||||
assert!(stripped.is_empty(), "{stripped:?}");
|
||||
}
|
||||
|
||||
/// A bucket served as a website, as `website_hosting_test` builds it.
|
||||
struct Site {
|
||||
website: WebsiteHost,
|
||||
bucket: String,
|
||||
}
|
||||
|
||||
const DOMAIN: &str = "website.test";
|
||||
const PUBLIC_READ: &str = "public";
|
||||
|
||||
async fn put(store: &ECStore, bucket: &str, key: &str, body: &str, redirect: Option<&str>) {
|
||||
let mut options = StorageObjectOptions::default();
|
||||
if let Some(location) = redirect {
|
||||
options
|
||||
.user_defined
|
||||
.insert(rustfs_utils::http::AMZ_WEBSITE_REDIRECT_LOCATION.to_owned(), location.to_owned());
|
||||
}
|
||||
store
|
||||
.put_object(bucket, key, &mut StoragePutObjReader::from_vec(body.as_bytes().to_vec()), &options)
|
||||
.await
|
||||
.expect("seed a website object");
|
||||
}
|
||||
|
||||
/// A fresh bucket holding the website pages, with `website` as its website configuration and,
|
||||
/// when `policy` is `PUBLIC_READ`, the public-read policy that denies `private.txt`.
|
||||
async fn site(website: Option<&str>, policy: &str) -> Site {
|
||||
let store = crate::app::gating_test_env::shared_gating_ecstore().await;
|
||||
let server_ctx = ServerContextSlot::new();
|
||||
assert!(server_ctx.install(crate::app::gating_test_env::shared_gating_ambient().await));
|
||||
let bucket = format!("website-{}", uuid::Uuid::new_v4());
|
||||
store
|
||||
.make_bucket(&bucket, &MakeBucketOptions::default())
|
||||
.await
|
||||
.expect("create the website bucket");
|
||||
for (key, body) in [
|
||||
("index.html", "home"),
|
||||
("404.html", "error page"),
|
||||
("docs", "ordinary object"),
|
||||
("section/index.html", "section page"),
|
||||
("private.txt", "private"),
|
||||
] {
|
||||
put(store.as_ref(), &bucket, key, body, None).await;
|
||||
}
|
||||
put(store.as_ref(), &bucket, "move", "ordinary redirect object", Some("/new-page")).await;
|
||||
if let Some(website) = website {
|
||||
store
|
||||
.update_bucket_metadata_config(
|
||||
&bucket,
|
||||
crate::storage::storage_api::ecstore_bucket::metadata::BUCKET_WEBSITE_CONFIG,
|
||||
website.as_bytes().to_vec(),
|
||||
)
|
||||
.await
|
||||
.expect("store the website configuration");
|
||||
}
|
||||
if policy == PUBLIC_READ {
|
||||
let policy = serde_json::json!({
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{"Effect":"Allow","Principal":"*","Action":"s3:GetObject","Resource":format!("arn:aws:s3:::{bucket}/*")},
|
||||
{"Effect":"Deny","Principal":"*","Action":"s3:GetObject","Resource":format!("arn:aws:s3:::{bucket}/private.txt")}
|
||||
]
|
||||
});
|
||||
store
|
||||
.update_bucket_metadata_config(
|
||||
&bucket,
|
||||
crate::storage::storage_api::ecstore_bucket::metadata::BUCKET_POLICY_CONFIG,
|
||||
serde_json::to_vec(&policy).expect("policy JSON"),
|
||||
)
|
||||
.await
|
||||
.expect("store the public-read policy");
|
||||
}
|
||||
let website = WebsiteHost::new(vec![DOMAIN.to_owned()], "http", server_ctx).expect("a website domain");
|
||||
Site { website, bucket }
|
||||
}
|
||||
|
||||
const INDEX_AND_ERROR: &str = "<WebsiteConfiguration><IndexDocument><Suffix>index.html</Suffix></IndexDocument><ErrorDocument><Key>404.html</Key></ErrorDocument></WebsiteConfiguration>";
|
||||
|
||||
/// Status, `Location`, and body of one website request.
|
||||
struct Page {
|
||||
status: StatusCode,
|
||||
location: Option<String>,
|
||||
body: String,
|
||||
}
|
||||
|
||||
impl Site {
|
||||
async fn ask(&self, method: Method, path: &str, extra: &[(&'static str, &'static str)]) -> Page {
|
||||
self.ask_host(&format!("{}.{DOMAIN}", self.bucket), method, path, extra).await
|
||||
}
|
||||
|
||||
async fn ask_host(&self, host_name: &str, method: Method, path: &str, extra: &[(&'static str, &'static str)]) -> Page {
|
||||
let mut headers = host(host_name);
|
||||
for (name, value) in extra {
|
||||
headers.insert(*name, HeaderValue::from_static(value));
|
||||
}
|
||||
let response = self.website.answer(method, uri(path), headers, Extensions::new()).await;
|
||||
let status = response.status();
|
||||
let location = response
|
||||
.headers()
|
||||
.get(http::header::LOCATION)
|
||||
.map(|value| value.to_str().expect("an ASCII location").to_owned());
|
||||
let body = response.into_body().collect().await.expect("an in-memory body").to_bytes();
|
||||
Page {
|
||||
status,
|
||||
location,
|
||||
body: String::from_utf8_lossy(&body).into_owned(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn website_host_serves_pages_documents_and_redirects_anonymously() {
|
||||
let site = site(Some(INDEX_AND_ERROR), PUBLIC_READ).await;
|
||||
|
||||
let home = site.ask(Method::GET, "/", &[]).await;
|
||||
assert_eq!((home.status, home.body.as_str()), (StatusCode::OK, "home"));
|
||||
let head = site.ask(Method::HEAD, "/", &[]).await;
|
||||
assert_eq!((head.status, head.body.as_str()), (StatusCode::OK, ""));
|
||||
let object = site.ask(Method::GET, "/docs", &[]).await;
|
||||
assert_eq!((object.status, object.body.as_str()), (StatusCode::OK, "ordinary object"));
|
||||
let section = site.ask(Method::GET, "/section/", &[]).await;
|
||||
assert_eq!((section.status, section.body.as_str()), (StatusCode::OK, "section page"));
|
||||
|
||||
let missing = site.ask(Method::GET, "/missing", &[]).await;
|
||||
assert_eq!((missing.status, missing.body.as_str()), (StatusCode::NOT_FOUND, "error page"));
|
||||
let denied = site.ask(Method::GET, "/private.txt", &[]).await;
|
||||
assert_eq!((denied.status, denied.body.as_str()), (StatusCode::FORBIDDEN, "error page"));
|
||||
let head_missing = site.ask(Method::HEAD, "/missing", &[]).await;
|
||||
assert_eq!((head_missing.status, head_missing.body.as_str()), (StatusCode::NOT_FOUND, ""));
|
||||
let directory = site.ask(Method::GET, "/section?x=1", &[]).await;
|
||||
assert_eq!(directory.status, StatusCode::FOUND);
|
||||
assert_eq!(directory.location.as_deref(), Some("/section/?x=1"));
|
||||
let redirect = site.ask(Method::GET, "/move", &[]).await;
|
||||
assert_eq!(redirect.status, StatusCode::MOVED_PERMANENTLY);
|
||||
assert_eq!(redirect.location.as_deref(), Some("/new-page"));
|
||||
for condition in [("if-none-match", "*"), ("range", "bytes=999999-")] {
|
||||
let redirected = site.ask(Method::GET, "/move", &[condition]).await;
|
||||
assert_eq!(redirected.status, StatusCode::MOVED_PERMANENTLY, "{condition:?}");
|
||||
assert_eq!(redirected.location.as_deref(), Some("/new-page"), "{condition:?}");
|
||||
}
|
||||
let unsatisfiable = site.ask(Method::GET, "/index.html", &[("range", "bytes=999999-")]).await;
|
||||
// A client error is answered by the error document, under the error's own status.
|
||||
assert_eq!(
|
||||
(unsatisfiable.status, unsatisfiable.body.as_str()),
|
||||
(StatusCode::RANGE_NOT_SATISFIABLE, "error page")
|
||||
);
|
||||
let ranged = site.ask(Method::GET, "/index.html", &[("range", "bytes=1-2")]).await;
|
||||
assert_eq!((ranged.status, ranged.body.as_str()), (StatusCode::PARTIAL_CONTENT, "om"));
|
||||
let malformed = site
|
||||
.ask(Method::GET, "/index.html", &[("if-modified-since", "yesterday")])
|
||||
.await;
|
||||
assert_eq!(malformed.status, StatusCode::BAD_REQUEST);
|
||||
assert!(!malformed.body.contains("<Error>"), "{}", malformed.body);
|
||||
let post = site.ask(Method::POST, "/", &[]).await;
|
||||
assert_eq!(post.status, StatusCode::METHOD_NOT_ALLOWED);
|
||||
let base_domain = site
|
||||
.ask_host(DOMAIN, Method::GET, &format!("/{}/index.html", site.bucket), &[])
|
||||
.await;
|
||||
assert_eq!(base_domain.status, StatusCode::NOT_FOUND);
|
||||
assert!(!base_domain.body.contains("<Error>"), "{}", base_domain.body);
|
||||
let no_bucket = site
|
||||
.ask_host(&format!("absent-{}.{DOMAIN}", site.bucket), Method::GET, "/", &[])
|
||||
.await;
|
||||
assert_eq!(no_bucket.status, StatusCode::NOT_FOUND);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn website_host_refuses_what_the_bucket_does_not_serve() {
|
||||
// No website configuration: the bucket is not a website, whatever its policy.
|
||||
let unconfigured = site(None, PUBLIC_READ).await;
|
||||
let page = unconfigured.ask(Method::GET, "/", &[]).await;
|
||||
assert_eq!(page.status, StatusCode::NOT_FOUND);
|
||||
assert_eq!(page.body, "<html><body>Not Found</body></html>");
|
||||
|
||||
// A website without a public-read policy is read as the anonymous caller it is: the index and
|
||||
// the error document are both refused, so the page is the plain refusal.
|
||||
let private = site(Some(INDEX_AND_ERROR), "none").await;
|
||||
for path in ["/", "/index.html", "/docs", "/missing"] {
|
||||
let page = private.ask(Method::GET, path, &[]).await;
|
||||
assert_eq!(page.status, StatusCode::FORBIDDEN, "{path}");
|
||||
assert_eq!(page.body, "<html><body>Forbidden</body></html>", "{path}");
|
||||
}
|
||||
// Whatever caller and ownership the request arrived with, a website read is anonymous.
|
||||
let mut owner = Extensions::new();
|
||||
owner.insert(ReqInfo {
|
||||
cred: Some(rustfs_credentials::Credentials {
|
||||
access_key: "website-owner".to_owned(),
|
||||
..Default::default()
|
||||
}),
|
||||
is_owner: true,
|
||||
..ReqInfo::default()
|
||||
});
|
||||
let host_name = format!("{}.{DOMAIN}", private.bucket);
|
||||
let response = private.website.answer(Method::GET, uri("/"), host(&host_name), owner).await;
|
||||
assert_eq!(
|
||||
response.status(),
|
||||
StatusCode::FORBIDDEN,
|
||||
"an owner's request facts must not reach the read"
|
||||
);
|
||||
// A redirect location is only reported to a read the bucket allows.
|
||||
let hidden = private.ask(Method::GET, "/move", &[]).await;
|
||||
assert_eq!((hidden.status, hidden.location), (StatusCode::FORBIDDEN, None));
|
||||
|
||||
// An index document that does not exist is answered by the error document's status.
|
||||
let no_index = site(
|
||||
Some("<WebsiteConfiguration><IndexDocument><Suffix>absent.html</Suffix></IndexDocument></WebsiteConfiguration>"),
|
||||
PUBLIC_READ,
|
||||
)
|
||||
.await;
|
||||
let page = no_index.ask(Method::GET, "/", &[]).await;
|
||||
assert_eq!(page.status, StatusCode::NOT_FOUND);
|
||||
assert_eq!(page.body, "<html><body>Not Found</body></html>");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn website_host_applies_routing_rules_and_redirect_all() {
|
||||
let rules = "<WebsiteConfiguration><IndexDocument><Suffix>index.html</Suffix></IndexDocument><RoutingRules>\
|
||||
<RoutingRule><Condition><HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals></Condition><Redirect><ReplaceKeyWith>missing-page</ReplaceKeyWith></Redirect></RoutingRule>\
|
||||
<RoutingRule><Condition><KeyPrefixEquals>docs/</KeyPrefixEquals></Condition><Redirect><ReplaceKeyWith>docs-page</ReplaceKeyWith></Redirect></RoutingRule>\
|
||||
<RoutingRule><Condition><HttpErrorCodeReturnedEquals>416</HttpErrorCodeReturnedEquals></Condition><Redirect><ReplaceKeyWith>range-error</ReplaceKeyWith></Redirect></RoutingRule>\
|
||||
</RoutingRules></WebsiteConfiguration>";
|
||||
let site = site(Some(rules), PUBLIC_READ).await;
|
||||
let host_name = format!("{}.{DOMAIN}", site.bucket);
|
||||
let rule = site.ask(Method::GET, "/docs/missing", &[]).await;
|
||||
assert_eq!(rule.status, StatusCode::MOVED_PERMANENTLY);
|
||||
assert_eq!(rule.location, Some(format!("http://{host_name}/missing-page")));
|
||||
let ranged = site.ask(Method::GET, "/index.html", &[("range", "bytes=999999-")]).await;
|
||||
assert_eq!(ranged.status, StatusCode::MOVED_PERMANENTLY);
|
||||
assert_eq!(ranged.location, Some(format!("http://{host_name}/range-error")));
|
||||
let served = site.ask(Method::GET, "/index.html", &[]).await;
|
||||
assert_eq!((served.status, served.body.as_str()), (StatusCode::OK, "home"));
|
||||
|
||||
let all = site_redirecting_all().await;
|
||||
let page = all.ask(Method::GET, "/a%20b?x=1", &[]).await;
|
||||
assert_eq!(page.status, StatusCode::MOVED_PERMANENTLY);
|
||||
assert_eq!(page.location.as_deref(), Some("http://destination.test/a%20b?x=1"));
|
||||
}
|
||||
|
||||
async fn site_redirecting_all() -> Site {
|
||||
site(
|
||||
Some("<WebsiteConfiguration><RedirectAllRequestsTo><HostName>destination.test</HostName></RedirectAllRequestsTo></WebsiteConfiguration>"),
|
||||
"none",
|
||||
)
|
||||
.await
|
||||
}
|
||||
@@ -162,6 +162,7 @@ impl IAMAuth {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn with_server_context(
|
||||
ak: impl Into<String>,
|
||||
sk: impl Into<SecretKey>,
|
||||
|
||||
@@ -25,70 +25,35 @@ use rustfs_config::{
|
||||
use rustfs_credentials::{DEFAULT_ACCESS_KEY, DEFAULT_SECRET_KEY, Masked};
|
||||
use rustfs_policy::auth::{is_access_key_valid, is_secret_key_valid};
|
||||
use std::collections::HashSet;
|
||||
use std::fmt;
|
||||
use std::io::{Error, ErrorKind};
|
||||
use std::str::FromStr;
|
||||
use std::sync::{Mutex, OnceLock};
|
||||
|
||||
pub(crate) const LEGACY_ENV_RUSTFS_ROOT_USER: &str = "RUSTFS_ROOT_USER";
|
||||
pub(crate) const LEGACY_ENV_RUSTFS_ROOT_PASSWORD: &str = "RUSTFS_ROOT_PASSWORD";
|
||||
static LEGACY_CREDENTIAL_WARNED_KEYS: OnceLock<Mutex<HashSet<String>>> = OnceLock::new();
|
||||
|
||||
/// Development-only selector between the s3s-based S3 stack and the gateway
|
||||
/// stack while both coexist on the integration branch (rustfs/backlog#2734).
|
||||
/// It is removed when the gateway stack becomes the only one.
|
||||
const ENV_RUSTFS_S3_STACK: &str = "RUSTFS_S3_STACK";
|
||||
/// The selector between the s3s-based S3 stack and the gateway stack while both
|
||||
/// existed (rustfs/backlog#2734). The gateway stack is the only one now, so a set
|
||||
/// selector, whatever its value, refuses startup rather than being ignored.
|
||||
pub const RETIRED_S3_STACK_SELECTOR: &str = "RUSTFS_S3_STACK";
|
||||
|
||||
/// The S3 protocol stack that serves requests.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub enum S3Stack {
|
||||
/// The s3s-based stack every release ships today.
|
||||
#[default]
|
||||
Legacy,
|
||||
/// The rustfs-gateway stack under construction.
|
||||
Gateway,
|
||||
}
|
||||
|
||||
/// A `RUSTFS_S3_STACK` value other than the exact names `legacy` and `gateway`.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct InvalidS3Stack {
|
||||
value: String,
|
||||
}
|
||||
|
||||
impl fmt::Display for InvalidS3Stack {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, r#"{ENV_RUSTFS_S3_STACK} must be "legacy" or "gateway", got {:?}"#, self.value)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for InvalidS3Stack {}
|
||||
|
||||
impl FromStr for S3Stack {
|
||||
type Err = InvalidS3Stack;
|
||||
|
||||
fn from_str(value: &str) -> Result<Self, Self::Err> {
|
||||
// Exact names only: a near miss must refuse startup rather than fall
|
||||
// back to a stack the operator did not ask for.
|
||||
match value {
|
||||
"legacy" => Ok(Self::Legacy),
|
||||
"gateway" => Ok(Self::Gateway),
|
||||
_ => Err(InvalidS3Stack { value: value.to_owned() }),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl S3Stack {
|
||||
/// Unset selects the default; a set but invalid value, including an empty
|
||||
/// one, is a startup error.
|
||||
pub(crate) fn from_env() -> std::io::Result<Self> {
|
||||
match std::env::var_os(ENV_RUSTFS_S3_STACK) {
|
||||
None => Ok(Self::default()),
|
||||
Some(value) => value
|
||||
.to_string_lossy()
|
||||
.parse()
|
||||
.map_err(|err| std::io::Error::new(std::io::ErrorKind::InvalidInput, err)),
|
||||
}
|
||||
/// Refuses startup when the retired S3 stack selector is set to any value,
|
||||
/// the empty string included.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// `InvalidInput` naming the variable and this release when it is set.
|
||||
pub(crate) fn refuse_retired_s3_stack_selector() -> std::io::Result<()> {
|
||||
if std::env::var_os(RETIRED_S3_STACK_SELECTOR).is_none() {
|
||||
return Ok(());
|
||||
}
|
||||
Err(Error::new(
|
||||
ErrorKind::InvalidInput,
|
||||
format!(
|
||||
"{RETIRED_S3_STACK_SELECTOR} is no longer supported; the gateway stack is the only S3 stack since {}",
|
||||
env!("CARGO_PKG_VERSION")
|
||||
),
|
||||
))
|
||||
}
|
||||
|
||||
fn warn_legacy_credential_env_once(legacy_key: &str, canonical_key: &str) {
|
||||
@@ -209,9 +174,6 @@ pub struct Config {
|
||||
|
||||
/// Workload profile for adaptive buffer sizing
|
||||
pub buffer_profile: String,
|
||||
|
||||
/// S3 protocol stack selected by `RUSTFS_S3_STACK`
|
||||
pub s3_stack: S3Stack,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
@@ -243,7 +205,6 @@ impl Config {
|
||||
kms_allow_insecure_dev_defaults: false,
|
||||
buffer_profile_disable: false,
|
||||
buffer_profile: "GeneralPurpose".to_string(),
|
||||
s3_stack: S3Stack::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,7 +269,7 @@ impl Config {
|
||||
|
||||
// Region is optional, but if not set, we should default to "us-east-1" for signing compatibility with AWS S3 clients
|
||||
let region = region.or_else(|| Some(RUSTFS_REGION.to_string()));
|
||||
let s3_stack = S3Stack::from_env()?;
|
||||
refuse_retired_s3_stack_selector()?;
|
||||
|
||||
Ok(Config {
|
||||
volumes,
|
||||
@@ -333,7 +294,6 @@ impl Config {
|
||||
kms_allow_insecure_dev_defaults,
|
||||
buffer_profile_disable,
|
||||
buffer_profile,
|
||||
s3_stack,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -377,7 +337,6 @@ impl std::fmt::Debug for Config {
|
||||
.field("kms_allow_insecure_dev_defaults", &self.kms_allow_insecure_dev_defaults)
|
||||
.field("buffer_profile_disable", &self.buffer_profile_disable)
|
||||
.field("buffer_profile", &self.buffer_profile)
|
||||
.field("s3_stack", &self.s3_stack)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#[allow(unsafe_op_in_unsafe_fn)]
|
||||
mod tests {
|
||||
use crate::config::cli::{InspectCommands, default_server_opts};
|
||||
use crate::config::{CommandResult, Config, Opt, S3Stack, TlsCommands};
|
||||
use crate::config::{CommandResult, Config, Opt, RETIRED_S3_STACK_SELECTOR, TlsCommands};
|
||||
use crate::storage_api::config_test::DisksLayout;
|
||||
use rustfs_config::{DEFAULT_CONSOLE_ADDRESS, DEFAULT_CONSOLE_ENABLE, DEFAULT_OBS_ENDPOINT, RUSTFS_REGION};
|
||||
use rustfs_credentials::{DEFAULT_ACCESS_KEY, DEFAULT_SECRET_KEY};
|
||||
@@ -945,60 +945,32 @@ mod tests {
|
||||
});
|
||||
}
|
||||
|
||||
/// Resolves the server configuration with `RUSTFS_S3_STACK` set to `value`
|
||||
/// (`None` removes it), so each case starts from a known environment.
|
||||
fn config_with_s3_stack(value: Option<&str>) -> std::io::Result<Config> {
|
||||
temp_env::with_var("RUSTFS_S3_STACK", value, || Config::from_opt(Opt::parse_from(["rustfs", "/data/vol1"])))
|
||||
}
|
||||
|
||||
fn assert_s3_stack_rejected(value: &str) {
|
||||
let err = match config_with_s3_stack(Some(value)) {
|
||||
Ok(config) => panic!("RUSTFS_S3_STACK={value:?} must refuse startup, got {:?}", config.s3_stack),
|
||||
Err(err) => err,
|
||||
};
|
||||
assert_eq!(err.kind(), std::io::ErrorKind::InvalidInput);
|
||||
assert_eq!(
|
||||
err.to_string(),
|
||||
format!(r#"RUSTFS_S3_STACK must be "legacy" or "gateway", got "{value}""#)
|
||||
);
|
||||
/// Resolves the server configuration with the retired stack selector set to
|
||||
/// `value` (`None` removes it), so each case starts from a known environment.
|
||||
fn config_with_retired_stack_selector(value: Option<&str>) -> std::io::Result<Config> {
|
||||
temp_env::with_var(RETIRED_S3_STACK_SELECTOR, value, || {
|
||||
Config::from_opt(Opt::parse_from(["rustfs", "/data/vol1"]))
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn s3_stack_unset_selects_legacy() {
|
||||
let config = config_with_s3_stack(None).expect("unset RUSTFS_S3_STACK should parse");
|
||||
assert_eq!(config.s3_stack, S3Stack::Legacy);
|
||||
fn an_unset_stack_selector_starts() {
|
||||
config_with_retired_stack_selector(None).expect("an unset selector must not refuse startup");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn s3_stack_legacy_selects_legacy() {
|
||||
let config = config_with_s3_stack(Some("legacy")).expect("RUSTFS_S3_STACK=legacy should parse");
|
||||
assert_eq!(config.s3_stack, S3Stack::Legacy);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn s3_stack_gateway_selects_gateway() {
|
||||
let config = config_with_s3_stack(Some("gateway")).expect("RUSTFS_S3_STACK=gateway should parse");
|
||||
assert_eq!(config.s3_stack, S3Stack::Gateway);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn s3_stack_rejects_capitalized_gateway() {
|
||||
assert_s3_stack_rejected("Gateway");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn s3_stack_rejects_both() {
|
||||
assert_s3_stack_rejected("both");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn s3_stack_rejects_empty_value() {
|
||||
assert_s3_stack_rejected("");
|
||||
fn a_set_stack_selector_refuses_startup_whatever_its_value() {
|
||||
for value in ["gateway", "legacy", "", "Gateway", "both"] {
|
||||
let err = match config_with_retired_stack_selector(Some(value)) {
|
||||
Ok(_) => panic!("{RETIRED_S3_STACK_SELECTOR}={value:?} must refuse startup"),
|
||||
Err(err) => err,
|
||||
};
|
||||
assert_eq!(err.kind(), std::io::ErrorKind::InvalidInput, "{value:?}");
|
||||
let message = err.to_string();
|
||||
assert!(message.starts_with(RETIRED_S3_STACK_SELECTOR), "{value:?}: {message}");
|
||||
assert!(message.contains(env!("CARGO_PKG_VERSION")), "{value:?}: {message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,9 @@ pub use cli::{ConnectTopCaptureOpts, ConnectTopCommands};
|
||||
pub use cli::{DiagnoseFormat, DiagnoseOpts};
|
||||
pub use cli::{InspectBucketMetaOpts, InspectCommands, InspectOpts};
|
||||
pub use cli::{TlsCommands, TlsInspectOpts, TlsOpts};
|
||||
pub use config_struct::{Config, InvalidS3Stack, S3Stack};
|
||||
pub use config_struct::Config;
|
||||
pub use config_struct::RETIRED_S3_STACK_SELECTOR;
|
||||
pub(crate) use config_struct::refuse_retired_s3_stack_selector;
|
||||
pub use info::execute_info;
|
||||
pub use opt::Opt;
|
||||
pub(crate) use snapshot::get_config_snapshot;
|
||||
|
||||
@@ -427,7 +427,6 @@ impl Drop for RustFSServer {
|
||||
|
||||
/// The S3 operations a server on the gateway stack serves. It answers every other operation
|
||||
/// `501 NotImplemented`.
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
pub fn gateway_operations() -> Vec<&'static str> {
|
||||
crate::server::gateway_operations()
|
||||
}
|
||||
|
||||
+5
-4
@@ -180,7 +180,7 @@ enum BucketNotificationLookup {
|
||||
Configured(rustfs_gateway_types::persistence::PersistedNotificationConfiguration),
|
||||
Missing,
|
||||
/// Stored bytes cannot be parsed. Deterministic, so a retry cannot help,
|
||||
/// and reading it as missing would clear the bucket's rules.
|
||||
/// and registration must not treat it as a readable empty configuration.
|
||||
Unreadable,
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ fn classify_bucket_notification_lookup(
|
||||
subsystem = LOG_SUBSYSTEM_NOTIFICATION,
|
||||
bucket = %bucket,
|
||||
error = %err,
|
||||
"Bucket notification configuration is unreadable; leaving its rules unchanged"
|
||||
"Bucket notification configuration is unreadable; skipping rule registration"
|
||||
);
|
||||
Ok(BucketNotificationLookup::Unreadable)
|
||||
}
|
||||
@@ -210,8 +210,9 @@ fn classify_bucket_notification_lookup(
|
||||
}
|
||||
|
||||
/// Apply one bucket's persisted notification rules. An unreadable config is
|
||||
/// isolated to its bucket: it neither aborts setup for the other buckets nor
|
||||
/// clears the bucket's rules as if it had none.
|
||||
/// isolated to its bucket and does not abort setup for the other buckets.
|
||||
/// Metadata-bound server dispatch independently suppresses external delivery
|
||||
/// for unreadable snapshots rather than retaining an old subscription.
|
||||
async fn apply_bucket_notification_configuration(bucket: &str, region: &str) -> Result<bool, NotificationError> {
|
||||
match classify_bucket_notification_lookup(bucket, get_bucket_notification_config(bucket).await)? {
|
||||
BucketNotificationLookup::Unreadable => Ok(false),
|
||||
|
||||
@@ -227,7 +227,6 @@ pub(super) fn put_input(input: dto::PutObjectInput) -> S3Result<crate::app::obje
|
||||
bucket: input.bucket.as_str().to_owned(),
|
||||
key: input.key.as_str().to_owned(),
|
||||
body: input.body.map(|body| body.into_body()),
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
post_archive: None,
|
||||
trailing_headers: None,
|
||||
frame_trailers: None,
|
||||
|
||||
@@ -79,6 +79,9 @@ fn mark_bucket_notification_rules_reconciled() {
|
||||
}
|
||||
|
||||
fn should_reconcile_bucket_notification_rules(runtime_changed: bool, notify_enabled: bool) -> bool {
|
||||
// Dispatch follows store-owned metadata snapshots, including the periodic
|
||||
// metadata refresh that repairs lost peer signals. Startup validation need
|
||||
// not rescan all buckets on every five-second target-runtime tick.
|
||||
notify_enabled && (runtime_changed || !are_bucket_notification_rules_reconciled())
|
||||
}
|
||||
|
||||
@@ -186,6 +189,7 @@ async fn reconcile_event_notifier_from_store_unlocked(
|
||||
let result = async {
|
||||
validate_notify_module_env().map_err(NotificationError::Initialization)?;
|
||||
let system = ensure_live_events_initialized();
|
||||
system.bind_bucket_metadata_source(&store);
|
||||
let transition_system = system.clone();
|
||||
let transition_store = store.clone();
|
||||
let transition = with_refreshed_notify_module_state_from(store.clone(), move |resolution| async move {
|
||||
@@ -353,6 +357,8 @@ where
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
system.bind_bucket_metadata_source(&store);
|
||||
|
||||
refresh_persisted_module_switches_from(store.clone())
|
||||
.await
|
||||
.map_err(|err| NotificationError::Initialization(format!("failed to refresh notify module switch: {err}")))?;
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
// Copyright 2024 RustFS Team
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! RustFS's two metadata listings on the gateway stack: `GET /{bucket}?list-type=2&metadata=true`
|
||||
//! and `GET /{bucket}?versions&metadata=true` (rustfs/gateway#1588).
|
||||
//!
|
||||
//! Responsible for: [`dialect`], the two rows of the gateway's RustFS dialect that select them
|
||||
//! ahead of the standard listings, and [`register`], their handler: the shared access phase, the
|
||||
//! listing authorization and the listing answer both stacks share (`app/metadata_listing.rs`).
|
||||
//! NOT responsible for: authenticating the caller (the gateway), the listing rules (the shared
|
||||
//! module), or the assembly (`server/gateway_stack.rs`).
|
||||
//! Upstream: the gateway's dispatch. Downstream: `app/metadata_listing.rs`.
|
||||
|
||||
use super::{access, handler_error};
|
||||
use crate::app::metadata_listing::{self, MetadataListing};
|
||||
use crate::runtime_sources::ServerContextSlot;
|
||||
use rustfs_gateway::{Handler, HandlerResult, Req, Resp, ServiceBuilder};
|
||||
use rustfs_gateway_core::dialect::{Dialect, DialectError, DialectOverlay, DialectRoute, OverlayRow};
|
||||
use rustfs_gateway_core::route::ShadowingDecl;
|
||||
use rustfs_gateway_dialect_rustfs_admin::ops::list_object_versions_with_metadata::{
|
||||
self as versions, ListObjectVersionsWithMetadata,
|
||||
};
|
||||
use rustfs_gateway_dialect_rustfs_admin::ops::list_objects_v2_with_metadata::{self as objects, ListObjectsV2WithMetadata};
|
||||
use rustfs_gateway_dialect_rustfs_admin::{AdminResponse, ExtensionOperation};
|
||||
use rustfs_s3_types::{S3Result, s3_error};
|
||||
use std::sync::{Arc, OnceLock};
|
||||
|
||||
/// The two operations, as the gateway names them.
|
||||
pub(crate) const NAMES: [&str; 2] = [versions::NAME, objects::NAME];
|
||||
|
||||
static ROWS: [OverlayRow; 2] = [versions::OVERLAY_ROW, objects::OVERLAY_ROW];
|
||||
|
||||
static RECORD: DialectOverlay = DialectOverlay {
|
||||
name: "rustfs-metadata-listings",
|
||||
vendor: "rustfs",
|
||||
operations: &ROWS,
|
||||
claims: &[],
|
||||
};
|
||||
|
||||
/// The dialect carrying the two listings' rows, as the gateway's RustFS dialect declares them.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// What the gateway refuses in the record or the declarations.
|
||||
pub(crate) fn dialect() -> Result<Dialect, Vec<DialectError>> {
|
||||
static VERSIONS: OnceLock<Vec<ShadowingDecl>> = OnceLock::new();
|
||||
static OBJECTS: OnceLock<Vec<ShadowingDecl>> = OnceLock::new();
|
||||
Dialect::assemble(&RECORD)
|
||||
.declare::<ListObjectVersionsWithMetadata>(on_the_s3_table(ListObjectVersionsWithMetadata::ROUTE, &VERSIONS))
|
||||
.declare::<ListObjectsV2WithMetadata>(on_the_s3_table(ListObjectsV2WithMetadata::ROUTE, &OBJECTS))
|
||||
.build()
|
||||
}
|
||||
|
||||
/// `route` as the S3 table carries it: the same row, declaring the overlaps with the standard
|
||||
/// operations and the other listing it stands in front of. The admin router's extension rows it
|
||||
/// also shadows in the
|
||||
/// gateway's one-table dialect are served by the control-plane host, not by this table, and a
|
||||
/// declaration naming an operation the table does not hold is refused as stale.
|
||||
fn on_the_s3_table(route: DialectRoute, shadows: &'static OnceLock<Vec<ShadowingDecl>>) -> DialectRoute {
|
||||
let shadows = shadows.get_or_init(|| {
|
||||
route
|
||||
.shadows
|
||||
.iter()
|
||||
.filter(|decl| !decl.shadowed.starts_with("rustfs:") || NAMES.contains(&decl.shadowed))
|
||||
.copied()
|
||||
.collect()
|
||||
});
|
||||
DialectRoute { shadows, ..route }
|
||||
}
|
||||
|
||||
/// Registers the handler of both listings on `builder`.
|
||||
pub(crate) fn register(builder: ServiceBuilder, server_ctx: &Arc<ServerContextSlot>) -> ServiceBuilder {
|
||||
let listings = Arc::new(Listings {
|
||||
server_ctx: Arc::clone(server_ctx),
|
||||
});
|
||||
builder
|
||||
.register::<ListObjectVersionsWithMetadata, _>(Arc::clone(&listings))
|
||||
.register::<ListObjectsV2WithMetadata, _>(listings)
|
||||
}
|
||||
|
||||
/// One metadata listing operation and the listing it is.
|
||||
trait Listing: ExtensionOperation<Input = ()> {
|
||||
const LISTING: MetadataListing;
|
||||
}
|
||||
|
||||
impl Listing for ListObjectVersionsWithMetadata {
|
||||
const LISTING: MetadataListing = MetadataListing::ListObjectVersions;
|
||||
}
|
||||
|
||||
impl Listing for ListObjectsV2WithMetadata {
|
||||
const LISTING: MetadataListing = MetadataListing::ListObjectsV2;
|
||||
}
|
||||
|
||||
struct Listings {
|
||||
server_ctx: Arc<ServerContextSlot>,
|
||||
}
|
||||
|
||||
impl Listings {
|
||||
/// The access phase every gateway operation runs, then the listing check and the listing.
|
||||
async fn serve<O: Listing>(&self, request: Req<O>) -> S3Result<Resp<O>> {
|
||||
let mut envelope = access::admit(&self.server_ctx, request.context()).await?;
|
||||
let bucket = request
|
||||
.context()
|
||||
.bucket()
|
||||
.ok_or_else(|| s3_error!(InternalError, "the listing names no bucket"))?
|
||||
.as_str()
|
||||
.to_owned();
|
||||
metadata_listing::authorize(&mut envelope, O::LISTING, &bucket).await?;
|
||||
let body = metadata_listing::answer(&envelope, O::LISTING, bucket).await?;
|
||||
Ok(Resp::new(AdminResponse::bytes("application/xml", body)))
|
||||
}
|
||||
}
|
||||
|
||||
impl<O: Listing> Handler<O> for Listings {
|
||||
async fn call(&self, request: Req<O>) -> HandlerResult<O> {
|
||||
self.serve(request).await.map_err(handler_error)
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,7 @@ mod bucket_core;
|
||||
mod bucket_replication_lifecycle;
|
||||
mod lifecycle_input;
|
||||
mod listing_multipart;
|
||||
pub(crate) mod metadata_listing;
|
||||
mod object_commit;
|
||||
mod object_meta;
|
||||
mod object_misc;
|
||||
|
||||
@@ -47,11 +47,6 @@
|
||||
//! the answer is that id for every bucket, with no lookup: a missing bucket is the handler's own
|
||||
//! `NoSuchBucket`.
|
||||
|
||||
// The stack is under construction, so a build without debug assertions must not carry it. The
|
||||
// message is checked by `scripts/check_connect_release_boundary.py`.
|
||||
#[cfg(not(debug_assertions))]
|
||||
compile_error!("gateway-stack is restricted to debug builds");
|
||||
|
||||
mod admin;
|
||||
mod control_plane;
|
||||
|
||||
@@ -60,17 +55,17 @@ pub(crate) static CONFIG_HANDLER_CALLS: std::sync::atomic::AtomicUsize = std::sy
|
||||
|
||||
use crate::app::dto_values::owner;
|
||||
use crate::runtime_sources::{ServerContextSlot, current_action_credentials};
|
||||
use crate::server::gateway_handlers::{GatewayBackend, OPERATIONS, OperationTable, register, serves};
|
||||
use crate::server::gateway_handlers::{GatewayBackend, OPERATIONS, OperationTable, metadata_listing, register, serves};
|
||||
use crate::server::ssec_transport::{is_secure_transport, require_tls};
|
||||
use crate::shared_types::{NativeTlsTransport, RemoteAddr};
|
||||
use crate::storage_api::server::http::request_context::RequestContext;
|
||||
use http::{Extensions, Request, Response};
|
||||
use rustfs_config::RUSTFS_REGION;
|
||||
use rustfs_gateway::{
|
||||
AssemblyError, Authorizer, BoxFuture, BucketName, BucketOwnerError, BucketOwnerSource, ClientAddr,
|
||||
AssemblyError, Authorizer, BoxFuture, BucketName, BucketOwnerError, BucketOwnerSource, ClientAddr, ConnectionIntent,
|
||||
DEFAULT_MAX_BUFFERED_BODY_BYTES, Decision, HandlerDeadlineClass, HandlerDeadlineConfig, MintedTraces,
|
||||
PlaintextCustomerKeyAck, RegionSet, RequestBodyDeadlineConfig, ServiceBuilder, ServiceConfig, SigV4Authenticator, SseConfig,
|
||||
TransportSecurity, UnreadBodyDrain, decide_with,
|
||||
TransportSecurity, connection_intent_of, decide_with,
|
||||
};
|
||||
use rustfs_gateway_adapter::{
|
||||
IamCredentials, IamKeyLookup, KeystoneEstablished, KeystoneVerifier, RequestIdCarrier, RootCredentials, RootCredentialsError,
|
||||
@@ -150,9 +145,11 @@ pub(crate) enum GatewayAssemblyError {
|
||||
AdminOverlayMissing,
|
||||
#[error("the native admin dialect refused its assembly: {0:?}")]
|
||||
AdminDialect(Vec<rustfs_gateway_core::dialect::DialectError>),
|
||||
#[error("the metadata listing dialect refused its assembly: {0:?}")]
|
||||
MetadataListingDialect(Vec<rustfs_gateway_core::dialect::DialectError>),
|
||||
#[error("RUSTFS_KEYSTONE_ENABLE configuration is invalid: {0}")]
|
||||
KeystoneConfig(rustfs_keystone::KeystoneError),
|
||||
#[error("RUSTFS_KEYSTONE_ENABLE requires an initialized Keystone provider on RUSTFS_S3_STACK=gateway")]
|
||||
#[error("RUSTFS_KEYSTONE_ENABLE requires an initialized Keystone provider before the gateway stack is assembled")]
|
||||
KeystoneNotInitialized,
|
||||
#[error("the Keystone header claim is invalid")]
|
||||
KeystoneClaim,
|
||||
@@ -203,17 +200,37 @@ impl GatewayStack {
|
||||
control_plane::assemble(assembly, iam, root, router)
|
||||
}
|
||||
|
||||
/// The stack as [`GatewayStack::assemble`] configures it, admitting every caller to the
|
||||
/// handlers `register` adds instead of RustFS's: for tests of the host layers around it.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn assemble_serving(
|
||||
assembly: GatewayAssembly,
|
||||
register: impl FnOnce(ServiceBuilder) -> ServiceBuilder,
|
||||
) -> Result<Self, GatewayAssemblyError> {
|
||||
let iam = Arc::new(ServerIam {
|
||||
server_ctx: Arc::clone(&assembly.server_ctx),
|
||||
});
|
||||
let root = Arc::new(live_root(Arc::clone(&assembly.server_ctx)));
|
||||
let builder = Self::configured_builder(&assembly, iam, root, decide_with(|_| Decision::Allow), std::convert::identity)?;
|
||||
let service = register(builder).build().map_err(GatewayAssemblyError::Service)?;
|
||||
Ok(Self {
|
||||
service,
|
||||
keystone_auth: assembly.keystone_auth,
|
||||
control_plane: false,
|
||||
})
|
||||
}
|
||||
|
||||
fn assemble_with(
|
||||
assembly: GatewayAssembly,
|
||||
iam: Arc<dyn IamKeyLookup>,
|
||||
root: Arc<dyn RootSource>,
|
||||
authorizer: impl Authorizer,
|
||||
) -> Result<Self, GatewayAssemblyError> {
|
||||
let builder = Self::configured_builder(&assembly, iam, root, authorizer, std::convert::identity)?;
|
||||
let listings = metadata_listing::dialect().map_err(GatewayAssemblyError::MetadataListingDialect)?;
|
||||
let builder = Self::configured_builder(&assembly, iam, root, authorizer, std::convert::identity)?.dialect(&listings);
|
||||
let backend = Arc::new(GatewayBackend::new(Arc::clone(&assembly.server_ctx)));
|
||||
let service = register(OPERATIONS, builder, &backend)
|
||||
.build()
|
||||
.map_err(GatewayAssemblyError::Service)?;
|
||||
let builder = metadata_listing::register(register(OPERATIONS, builder, &backend), &assembly.server_ctx);
|
||||
let service = builder.build().map_err(GatewayAssemblyError::Service)?;
|
||||
Ok(Self {
|
||||
service,
|
||||
keystone_auth: assembly.keystone_auth,
|
||||
@@ -246,8 +263,6 @@ impl GatewayStack {
|
||||
// Shipped RustFS authorizes before it judges an SSE header; the handler entry answers
|
||||
// the refusal once authorization succeeds.
|
||||
.defer_encryption_header_refusals_to_handlers()
|
||||
// Keep the profile's inner drain aligned with the host's configured idle bound.
|
||||
.drain_unread_request_bodies(UnreadBodyDrain::with_idle_timeout(assembly.body_read_timeout))
|
||||
.authenticator(authenticator(SigV4Authenticator::new(credentials, regions).rustfs_profile()))
|
||||
.authorizer(authorizer)
|
||||
.bucket_owner_source(ReportedOwner(owner().id.map(Arc::from)))
|
||||
@@ -308,26 +323,35 @@ impl GatewayStack {
|
||||
(None, _) => true,
|
||||
};
|
||||
attach_host_facts(extensions);
|
||||
let mut service = self.service.clone();
|
||||
// `Connection` is an HTTP/1 header; HTTP/2 and HTTP/3 forbid it and end only the stream.
|
||||
let http1 = request.version() < http::Version::HTTP_2;
|
||||
let service = self.service.clone();
|
||||
async move {
|
||||
if !valid {
|
||||
let mut response = Response::new(rustfs_gateway::Body::empty());
|
||||
*response.status_mut() = http::StatusCode::FORBIDDEN;
|
||||
return response;
|
||||
}
|
||||
match tower::Service::call(&mut service, request).await {
|
||||
Ok(response) => response,
|
||||
Err(never) => match never {},
|
||||
// The service's own entry, not its tower adapter: the adapter reads a body the handler
|
||||
// left unread in a detached task of its own, which takes the body away from
|
||||
// `EarlyResponseBodyService`, the drain the HTTP/1-2 shutdown accounting owns. The
|
||||
// adapter's connection verdict is kept.
|
||||
let mut response = service.call(request).await;
|
||||
if http1 && connection_intent_of(&response).is_some_and(ConnectionIntent::must_close) {
|
||||
response
|
||||
.headers_mut()
|
||||
.insert(http::header::CONNECTION, http::HeaderValue::from_static("close"));
|
||||
}
|
||||
response
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The early gate over `table`: an operation it serves is allowed on to its handler, which decides;
|
||||
/// every other operation is denied.
|
||||
/// The early gate over `table` and the two metadata listings: an operation it serves is allowed on
|
||||
/// to its handler, which decides; every other operation is denied.
|
||||
fn early_gate(table: OperationTable) -> impl Authorizer {
|
||||
decide_with(move |request| {
|
||||
if serves(table, request.operation) {
|
||||
if serves(table, request.operation) || metadata_listing::NAMES.contains(&request.operation) {
|
||||
Decision::Allow
|
||||
} else {
|
||||
Decision::Deny
|
||||
|
||||
@@ -114,9 +114,8 @@ impl<O: Operation<Output = WireResponse>> Handler<O> for Capture {
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn native_admin_envelope_preserves_raw_alias_host_facts_and_optional_req_info() {
|
||||
let captured = Arc::new(Mutex::new(Vec::new()));
|
||||
/// The native admin host as production configures it, with a [`Capture`] on every registered operation.
|
||||
fn capturing_stack(captured: &Arc<Mutex<Vec<serde_json::Value>>>) -> GatewayStack {
|
||||
let builder = GatewayStack::configured_builder(
|
||||
&assembly(),
|
||||
Arc::new(ScriptedIam { ready: true }),
|
||||
@@ -125,24 +124,30 @@ async fn native_admin_envelope_preserves_raw_alias_host_facts_and_optional_req_i
|
||||
std::convert::identity,
|
||||
)
|
||||
.unwrap();
|
||||
let stack = GatewayStack {
|
||||
GatewayStack {
|
||||
keystone_auth: None,
|
||||
control_plane: false,
|
||||
service: builder
|
||||
.host_resolver(PathStyleOnly)
|
||||
.dialect(&dialect().unwrap())
|
||||
.register::<GetIcebergConfig, _>(Arc::new(Capture(captured.clone())))
|
||||
.register::<GetV3Datausageinfo, _>(Arc::new(Capture(captured.clone())))
|
||||
.register::<GetV4PluginsCatalog, _>(Arc::new(Capture(captured.clone())))
|
||||
.register::<GetV4ExtensionsCatalog, _>(Arc::new(Capture(captured.clone())))
|
||||
.register::<GetV3ModuleSwitches, _>(Arc::new(Capture(captured.clone())))
|
||||
.register::<GetV3Info, _>(Arc::new(Capture(captured.clone())))
|
||||
.register::<GetV3Storageinfo, _>(Arc::new(Capture(captured.clone())))
|
||||
.register::<GetV4RuntimeCapabilities, _>(Arc::new(Capture(captured.clone())))
|
||||
.register::<GetV3ObjectDataCacheStats, _>(Arc::new(Capture(captured.clone())))
|
||||
.register::<GetIcebergConfig, _>(Arc::new(Capture(Arc::clone(captured))))
|
||||
.register::<GetV3Datausageinfo, _>(Arc::new(Capture(Arc::clone(captured))))
|
||||
.register::<GetV4PluginsCatalog, _>(Arc::new(Capture(Arc::clone(captured))))
|
||||
.register::<GetV4ExtensionsCatalog, _>(Arc::new(Capture(Arc::clone(captured))))
|
||||
.register::<GetV3ModuleSwitches, _>(Arc::new(Capture(Arc::clone(captured))))
|
||||
.register::<GetV3Info, _>(Arc::new(Capture(Arc::clone(captured))))
|
||||
.register::<GetV3Storageinfo, _>(Arc::new(Capture(Arc::clone(captured))))
|
||||
.register::<GetV4RuntimeCapabilities, _>(Arc::new(Capture(Arc::clone(captured))))
|
||||
.register::<GetV3ObjectDataCacheStats, _>(Arc::new(Capture(Arc::clone(captured))))
|
||||
.build()
|
||||
.unwrap(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn native_admin_envelope_preserves_raw_alias_host_facts_and_optional_req_info() {
|
||||
let captured = Arc::new(Mutex::new(Vec::new()));
|
||||
let stack = capturing_stack(&captured);
|
||||
let paths = [
|
||||
"/iceberg/v1/config",
|
||||
"/_iceberg/v1/config",
|
||||
@@ -227,3 +232,41 @@ async fn native_admin_authenticated_request_refuses_an_uninstalled_server_contex
|
||||
assert!(body.contains("<Message>server context is not ready</Message>"), "{body}");
|
||||
}
|
||||
}
|
||||
|
||||
/// GHSA-xm99-m3gq-83g8 on the native admin host: a signed request replayed with an `x-amz-*`
|
||||
/// header its signature does not name is refused before any handler, and the same request without
|
||||
/// the header is served (the control, which proves the refusal is the header's).
|
||||
#[tokio::test]
|
||||
async fn native_admin_refuses_an_unsigned_amz_header_before_any_handler() {
|
||||
let captured = Arc::new(Mutex::new(Vec::new()));
|
||||
let stack = capturing_stack(&captured);
|
||||
let signed = || {
|
||||
let mut request =
|
||||
signed_request(Signed::Header, Method::GET, "/rustfs/admin/v3/info", "", ROOT_ACCESS_KEY, ROOT_SECRET_KEY);
|
||||
request.extensions_mut().insert(Some(RemoteAddr(SocketAddr::from(PEER))));
|
||||
request
|
||||
.extensions_mut()
|
||||
.insert(ClientInfo::direct(SocketAddr::from((CLIENT, 42000))));
|
||||
request.extensions_mut().insert(request_context(REQUEST_ID));
|
||||
request
|
||||
};
|
||||
|
||||
let control = stack.call(signed()).await;
|
||||
assert_eq!(control.status(), StatusCode::OK);
|
||||
assert_eq!(captured.lock().unwrap().len(), 1, "the control reached the handler");
|
||||
|
||||
for (name, value) in [
|
||||
("x-amz-copy-source", "/private-bucket/source"),
|
||||
("x-amz-meta-user", "mallory"),
|
||||
] {
|
||||
let mut request = signed();
|
||||
request.headers_mut().insert(name, http::HeaderValue::from_static(value));
|
||||
let response = stack.call(request).await;
|
||||
assert_eq!(response.status(), StatusCode::FORBIDDEN, "{name}");
|
||||
let body = response.into_body().collect().await.unwrap().to_bytes();
|
||||
let body = String::from_utf8_lossy(&body);
|
||||
assert!(body.contains("<Code>AccessDenied</Code>"), "{name}: {body}");
|
||||
assert!(body.contains("not signed"), "{name}: {body}");
|
||||
}
|
||||
assert_eq!(captured.lock().unwrap().len(), 1, "a refused request reached a handler");
|
||||
}
|
||||
|
||||
@@ -149,7 +149,8 @@ fn the_assembled_stack_registers_exactly_the_table() {
|
||||
let stack = GatewayStack::assemble(assembly()).expect("the stack assembles");
|
||||
|
||||
let registered: std::collections::BTreeSet<&str> = stack.service.operations().collect();
|
||||
assert_eq!(registered, rows(OPERATIONS).map(|row| row.name).collect());
|
||||
let table = rows(OPERATIONS).map(|row| row.name);
|
||||
assert_eq!(registered, table.chain(metadata_listing::NAMES).collect());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -263,7 +264,7 @@ fn keystone_enabled_requires_an_initialized_provider_and_names_both_settings() {
|
||||
.expect("the provider must be initialized before assembly");
|
||||
assert!(matches!(error, GatewayAssemblyError::KeystoneNotInitialized));
|
||||
let message = error.to_string();
|
||||
for named in ["RUSTFS_S3_STACK=gateway", "RUSTFS_KEYSTONE_ENABLE"] {
|
||||
for named in ["gateway stack", "RUSTFS_KEYSTONE_ENABLE"] {
|
||||
assert!(message.contains(named), "{named} is missing from: {message}");
|
||||
}
|
||||
},
|
||||
@@ -308,40 +309,29 @@ fn a_disabled_body_read_timeout_lifts_the_idle_bound_instead_of_arming_zero() {
|
||||
assert_eq!(deadlines.first_byte(), NO_DEADLINE);
|
||||
}
|
||||
|
||||
#[tokio::test(start_paused = true)]
|
||||
async fn rejected_http1_body_uses_the_assembled_drain_timeout() {
|
||||
/// The stack hands a body its answer left unread back to the host when it answers: dropping it is
|
||||
/// what moves it into `EarlyResponseBodyService`, whose drain the HTTP/1-2 shutdown accounting
|
||||
/// owns. A drain of the stack's own would hold it here, in a task nothing accounts for. The
|
||||
/// configured idle bound of the host's drain is `server::http`'s
|
||||
/// `gateway_rejected_http1_body_uses_the_configured_drain_timeout`.
|
||||
#[tokio::test]
|
||||
async fn rejected_http1_body_is_released_to_the_host_drain() {
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
for timeout in [Duration::from_secs(1), Duration::ZERO] {
|
||||
let stack = GatewayStack::assemble_with(
|
||||
GatewayAssembly {
|
||||
body_read_timeout: timeout,
|
||||
..assembly()
|
||||
},
|
||||
Arc::new(ScriptedIam { ready: true }),
|
||||
root().source(),
|
||||
early_gate(OPERATIONS),
|
||||
)
|
||||
.expect("the stack assembles");
|
||||
let dropped = Arc::new(AtomicBool::new(false));
|
||||
let request = signed_with_a_wrong_signature(request(Method::PUT, "/test-bucket/test-key"), ROOT_ACCESS_KEY)
|
||||
.version(http::Version::HTTP_11)
|
||||
.body(StalledBody(Arc::clone(&dropped)))
|
||||
.expect("request");
|
||||
let response = stack.call(request).await;
|
||||
assert_eq!(response.status(), StatusCode::FORBIDDEN);
|
||||
assert_eq!(response.headers().get(http::header::CONNECTION).expect("connection header"), "close");
|
||||
tokio::task::yield_now().await;
|
||||
assert!(!dropped.load(Ordering::SeqCst), "the drain should retain the stalled body");
|
||||
let elapsed = if timeout.is_zero() { 301 } else { 2 };
|
||||
tokio::time::advance(Duration::from_secs(elapsed)).await;
|
||||
tokio::task::yield_now().await;
|
||||
assert_eq!(
|
||||
dropped.load(Ordering::SeqCst),
|
||||
!timeout.is_zero(),
|
||||
"the configured timeout must govern the gateway drain"
|
||||
);
|
||||
}
|
||||
let stack =
|
||||
GatewayStack::assemble_with(assembly(), Arc::new(ScriptedIam { ready: true }), root().source(), early_gate(OPERATIONS))
|
||||
.expect("the stack assembles");
|
||||
let dropped = Arc::new(AtomicBool::new(false));
|
||||
let request = signed_with_a_wrong_signature(request(Method::PUT, "/test-bucket/test-key"), ROOT_ACCESS_KEY)
|
||||
.version(http::Version::HTTP_11)
|
||||
.body(StalledBody(Arc::clone(&dropped)))
|
||||
.expect("request");
|
||||
let response = stack.call(request).await;
|
||||
assert_eq!(response.status(), StatusCode::FORBIDDEN);
|
||||
assert!(
|
||||
dropped.load(Ordering::SeqCst),
|
||||
"the stack must release the unread body to the host when it answers"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -485,3 +485,29 @@ async fn a_presented_credential_on_an_anonymous_class_is_never_served_as_anonymo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// GHSA-xm99-m3gq-83g8 on the control-plane host: a signed request replayed with an `x-amz-*`
|
||||
/// header its signature does not name is refused before any handler, and the same request without
|
||||
/// the header is served (the control, which proves the refusal is the header's).
|
||||
#[tokio::test]
|
||||
#[serial_test::serial]
|
||||
async fn an_unsigned_amz_header_is_refused_before_any_control_plane_handler() {
|
||||
for (path, query) in [("/rustfs/admin/v3/probe", ""), ("/missing-bucket", "replication-metrics=")] {
|
||||
let ((status, body), seen) = served(signed(Method::GET, path, query)).await;
|
||||
assert_eq!((status, body.as_str()), (StatusCode::OK, "probe"), "control {path}?{query}");
|
||||
assert_eq!(seen.len(), 1, "the control reached the handler: {path}?{query}");
|
||||
|
||||
for (name, value) in [
|
||||
("x-amz-copy-source", "/private-bucket/source"),
|
||||
("x-amz-meta-user", "mallory"),
|
||||
] {
|
||||
let mut request = signed(Method::GET, path, query);
|
||||
request.headers_mut().insert(name, http::HeaderValue::from_static(value));
|
||||
let ((status, body), seen) = served(request).await;
|
||||
assert_eq!(status, StatusCode::FORBIDDEN, "{name} {path}?{query}: {body}");
|
||||
assert!(body.contains("<Code>AccessDenied</Code>"), "{name} {path}?{query}: {body}");
|
||||
assert!(body.contains("not signed"), "{name} {path}?{query}: {body}");
|
||||
assert!(seen.is_empty(), "{name} {path}?{query} reached a handler: {seen:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -507,56 +507,34 @@ async fn keystone_stack_discards_stale_established_and_owned_payloads() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn keystone_outer_validation_precedes_non_s3_refusal_and_legacy_stays_selected() {
|
||||
use crate::config::S3Stack;
|
||||
use crate::server::stack::select_stack;
|
||||
for stack in [S3Stack::Gateway, S3Stack::Legacy] {
|
||||
let stub = KeystoneStub::new();
|
||||
for (method, path) in [
|
||||
(Method::GET, "/rustfs/admin/v3/info"),
|
||||
(Method::POST, "/?Action=AssumeRole&Version=2011-06-15"),
|
||||
] {
|
||||
for header in ["x-auth-token", "x-storage-token"] {
|
||||
for (token, expected) in [
|
||||
("invalid", StatusCode::UNAUTHORIZED),
|
||||
(
|
||||
"admin",
|
||||
if stack == S3Stack::Gateway {
|
||||
StatusCode::FORBIDDEN
|
||||
} else {
|
||||
StatusCode::OK
|
||||
},
|
||||
),
|
||||
] {
|
||||
let legacy = tower::service_fn(|_request: Request<Empty<Bytes>>| async {
|
||||
Ok::<_, std::convert::Infallible>(Response::new(http_body_util::Full::new(Bytes::from_static(b"legacy"))))
|
||||
});
|
||||
let gateway = tower::service_fn(|_request: Request<Empty<Bytes>>| async {
|
||||
Ok::<_, std::convert::Infallible>(Response::new(http_body_util::Full::new(Bytes::from_static(
|
||||
b"gateway",
|
||||
))))
|
||||
});
|
||||
let edge = select_stack(stack, legacy, || Ok::<_, std::convert::Infallible>(gateway)).unwrap();
|
||||
let mut builder = request(method.clone(), path).header(header, token);
|
||||
if method == Method::POST {
|
||||
builder = builder.header(http::header::CONTENT_TYPE, "application/x-www-form-urlencoded");
|
||||
}
|
||||
let request = builder.body(Empty::new()).unwrap();
|
||||
let response = KeystoneAuthLayer::new(Some(Arc::clone(&stub.provider)))
|
||||
.layer(edge)
|
||||
.oneshot(request)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(response.status(), expected, "{stack:?} {header} {token} {path}");
|
||||
let body = response.into_body().collect().await.unwrap().to_bytes();
|
||||
if expected == StatusCode::OK {
|
||||
assert_eq!(body, "legacy");
|
||||
}
|
||||
async fn keystone_outer_validation_precedes_non_s3_refusal() {
|
||||
use crate::server::stack::S3StackService;
|
||||
let stub = KeystoneStub::new();
|
||||
for (method, path) in [
|
||||
(Method::GET, "/rustfs/admin/v3/info"),
|
||||
(Method::POST, "/?Action=AssumeRole&Version=2011-06-15"),
|
||||
] {
|
||||
for header in ["x-auth-token", "x-storage-token"] {
|
||||
for (token, expected) in [("invalid", StatusCode::UNAUTHORIZED), ("admin", StatusCode::FORBIDDEN)] {
|
||||
let gateway = tower::service_fn(|_request: Request<Empty<Bytes>>| async {
|
||||
Ok::<_, std::convert::Infallible>(Response::new(http_body_util::Full::new(Bytes::from_static(b"gateway"))))
|
||||
});
|
||||
let edge = S3StackService::new(gateway);
|
||||
let mut builder = request(method.clone(), path).header(header, token);
|
||||
if method == Method::POST {
|
||||
builder = builder.header(http::header::CONTENT_TYPE, "application/x-www-form-urlencoded");
|
||||
}
|
||||
let request = builder.body(Empty::new()).unwrap();
|
||||
let response = KeystoneAuthLayer::new(Some(Arc::clone(&stub.provider)))
|
||||
.layer(edge)
|
||||
.oneshot(request)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(response.status(), expected, "{header} {token} {path}");
|
||||
}
|
||||
}
|
||||
stub.finish();
|
||||
}
|
||||
stub.finish();
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
@@ -11,15 +11,15 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//! The gateway stack answers, without any of RustFS's tower patch layers, what those layers make
|
||||
//! The gateway stack answers, without any of RustFS's tower patch layers, what those layers made
|
||||
//! the legacy stack answer (rustfs/backlog#2771, the six layers ruled "replace by the gateway").
|
||||
//! Five of them are deleted; `EmptyBodyContentLengthCompatLayer` keeps its admin and console halves.
|
||||
//!
|
||||
//! Responsible for: the fixture the per-layer modules share, a stack assembled by the production
|
||||
//! builder whose handlers are probes. Nothing in front of [`GatewayStack::call`] runs here, so
|
||||
//! every answer below is the gateway's alone: the layers are installed by `server/http.rs` and
|
||||
//! the other harnesses of this crate drive the stack through them.
|
||||
//! every answer below is the gateway's alone.
|
||||
//! NOT responsible for: S3 behaviour behind the handlers (the probes answer an empty output).
|
||||
//! Upstream: `server/legacy_compat`, whose unit tests state what each layer answers. Downstream:
|
||||
//! Upstream: the deleted layers, whose answers each module states. Downstream:
|
||||
//! `GatewayStack::configured_builder`.
|
||||
|
||||
use super::*;
|
||||
|
||||
+387
-466
File diff suppressed because it is too large
Load Diff
@@ -19,7 +19,6 @@ use super::*;
|
||||
use crate::admin::operation::{AdminRequest, AdminResponse, Operation as OwnedOperation};
|
||||
use crate::admin::router::{AdminOperation, S3Router};
|
||||
use crate::server::gateway_handlers::test_support::{signed_body_request, signed_session_request};
|
||||
use crate::server::stack::select_stack;
|
||||
use http_body_util::Full;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
@@ -29,46 +28,15 @@ use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
/// the path alone.
|
||||
const HOST: &str = "localhost:9000";
|
||||
|
||||
/// The legacy service, counting every request it is handed.
|
||||
#[derive(Clone)]
|
||||
struct Recorded(crate::server::http::S3Service, Arc<AtomicUsize>);
|
||||
type Edge = crate::server::stack::S3StackService<GatewayEdgeService>;
|
||||
|
||||
impl<B> Service<HttpRequest<B>> for Recorded
|
||||
where
|
||||
crate::server::http::S3Service: Service<HttpRequest<B>>,
|
||||
{
|
||||
type Response = <crate::server::http::S3Service as Service<HttpRequest<B>>>::Response;
|
||||
type Error = <crate::server::http::S3Service as Service<HttpRequest<B>>>::Error;
|
||||
type Future = <crate::server::http::S3Service as Service<HttpRequest<B>>>::Future;
|
||||
|
||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<std::result::Result<(), Self::Error>> {
|
||||
Service::<HttpRequest<B>>::poll_ready(&mut self.0, cx)
|
||||
}
|
||||
|
||||
fn call(&mut self, request: HttpRequest<B>) -> Self::Future {
|
||||
self.1.fetch_add(1, Ordering::SeqCst);
|
||||
Service::call(&mut self.0, request)
|
||||
}
|
||||
}
|
||||
|
||||
type Edge = crate::server::stack::S3StackService<Recorded, GatewayEdgeService>;
|
||||
|
||||
/// The gateway selection over `router`, with a legacy service that records every call.
|
||||
fn edge(
|
||||
slot: &Arc<ServerContextSlot>,
|
||||
legacy: crate::server::http::S3Service,
|
||||
router: S3Router<AdminOperation>,
|
||||
) -> (Edge, Arc<AtomicUsize>) {
|
||||
let calls = Arc::new(AtomicUsize::new(0));
|
||||
let gateway =
|
||||
|| Ok::<_, std::convert::Infallible>(GatewayEdgeService(GatewayStack::assemble(assembly(slot.clone())).unwrap()));
|
||||
let service = select_stack(config::S3Stack::Gateway, Recorded(legacy, Arc::clone(&calls)), gateway)
|
||||
.unwrap()
|
||||
/// The gateway stack over `router`.
|
||||
fn edge(slot: &Arc<ServerContextSlot>, router: S3Router<AdminOperation>) -> Edge {
|
||||
crate::server::stack::S3StackService::new(GatewayEdgeService(GatewayStack::assemble(assembly(slot.clone())).unwrap()))
|
||||
.with_native_admin(Some(GatewayEdgeService(GatewayStack::assemble_admin(assembly(slot.clone())).unwrap())))
|
||||
.with_control_plane(Some(GatewayEdgeService(
|
||||
GatewayStack::assemble_control_plane(assembly(slot.clone()), Arc::new(router)).unwrap(),
|
||||
)));
|
||||
(service, calls)
|
||||
)))
|
||||
}
|
||||
|
||||
fn anonymous(method: Method, target: &str, content_type: Option<&str>, body: &'static str) -> HttpRequest<Full<Bytes>> {
|
||||
@@ -105,7 +73,7 @@ enum Compare {
|
||||
async fn every_control_plane_class_answers_as_legacy_and_never_reaches_it() {
|
||||
let (_env, slot, legacy) = admin_fixture().await;
|
||||
let router = crate::admin::make_admin_router(false, slot.clone()).unwrap();
|
||||
let (edge, legacy_calls) = edge(&slot, legacy.clone(), router);
|
||||
let edge = edge(&slot, router);
|
||||
let mut failures = Vec::new();
|
||||
let iam = slot.installed_app_context().unwrap().iam().handle();
|
||||
iam.create_user(
|
||||
@@ -522,11 +490,6 @@ async fn every_control_plane_class_answers_as_legacy_and_never_reaches_it() {
|
||||
failures.push(format!("tampered body: {} {:?}", refused.0, refusal(&refused.2)));
|
||||
}
|
||||
|
||||
assert_eq!(
|
||||
legacy_calls.load(Ordering::SeqCst),
|
||||
0,
|
||||
"a gateway-stack request reached the legacy service"
|
||||
);
|
||||
assert!(failures.is_empty(), "{}", failures.join("\n"));
|
||||
}
|
||||
|
||||
@@ -641,11 +604,11 @@ async fn a_custom_code_without_a_status_is_answered_by_both_stacks_alike() {
|
||||
.unwrap();
|
||||
router
|
||||
};
|
||||
let mut legacy = crate::server::http::S3ServiceBuilder::new(UnusedS3);
|
||||
let mut legacy = S3ServiceBuilder::new(UnusedS3);
|
||||
legacy.set_auth(crate::auth::IAMAuth::with_server_context(ROOT, ROOT_SECRET, slot.clone()));
|
||||
legacy.set_route(router(&slot));
|
||||
let legacy = legacy.build();
|
||||
let (edge, _) = edge(&slot, legacy.clone(), router(&slot));
|
||||
let edge = edge(&slot, router(&slot));
|
||||
let request =
|
||||
|| signed_as(Method::GET, "/rustfs/admin/v3/statusless", "", ROOT, ROOT_SECRET, Signed::Header).map(|_| Full::default());
|
||||
|
||||
@@ -662,11 +625,11 @@ async fn a_custom_code_without_a_status_is_answered_by_both_stacks_alike() {
|
||||
#[serial_test::serial]
|
||||
async fn the_handler_sees_the_caller_the_legacy_stack_hands_it() {
|
||||
let (_env, slot, _) = admin_fixture().await;
|
||||
let mut legacy = crate::server::http::S3ServiceBuilder::new(UnusedS3);
|
||||
let mut legacy = S3ServiceBuilder::new(UnusedS3);
|
||||
legacy.set_auth(crate::auth::IAMAuth::with_server_context(ROOT, ROOT_SECRET, slot.clone()));
|
||||
legacy.set_route(probe_router(&slot));
|
||||
let legacy = legacy.build();
|
||||
let (edge, legacy_calls) = edge(&slot, legacy.clone(), probe_router(&slot));
|
||||
let edge = edge(&slot, probe_router(&slot));
|
||||
let claims = std::collections::HashMap::from([
|
||||
("exp".to_owned(), serde_json::json!(chrono::Utc::now().timestamp() + 900)),
|
||||
("parent".to_owned(), serde_json::json!(ROOT)),
|
||||
@@ -730,15 +693,14 @@ async fn the_handler_sees_the_caller_the_legacy_stack_hands_it() {
|
||||
assert!(pair[0].contains(&format!("key=Some({:?})", session.access_key)), "{pair:?}");
|
||||
assert!(pair[0].contains(&format!("token=Some({token:?})")), "{pair:?}");
|
||||
}
|
||||
assert_eq!(legacy_calls.load(Ordering::SeqCst), 0);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial_test::serial]
|
||||
async fn the_console_listener_isolates_its_routes_in_front_of_the_control_plane_host() {
|
||||
let (_env, slot, legacy) = admin_fixture().await;
|
||||
let (_env, slot, _) = admin_fixture().await;
|
||||
let router = crate::admin::make_admin_router(false, slot.clone()).unwrap();
|
||||
let (edge, legacy_calls) = edge(&slot, legacy, router);
|
||||
let edge = edge(&slot, router);
|
||||
let reached = Arc::new(AtomicUsize::new(0));
|
||||
let counted = {
|
||||
let reached = Arc::clone(&reached);
|
||||
@@ -767,5 +729,4 @@ async fn the_console_listener_isolates_its_routes_in_front_of_the_control_plane_
|
||||
let (status, _, body) = answer(console.clone(), signed("/rustfs/admin/v3/list-users", "")).await;
|
||||
assert_eq!(status, StatusCode::OK, "{:?}", refusal(&body));
|
||||
assert_eq!(reached.load(Ordering::SeqCst), 1, "the admin route did not reach the control-plane host");
|
||||
assert_eq!(legacy_calls.load(Ordering::SeqCst), 0);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,576 @@
|
||||
// Copyright 2024 RustFS Team
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! The two request classes the retired legacy metadata route claimed, website hosts and
|
||||
//! `metadata=true` listings, sent to the gateway stack over a real store, IAM and signatures.
|
||||
//!
|
||||
//! The case tables are the ones the legacy-versus-gateway comparison ran before the legacy stack
|
||||
//! was removed; each expected status is the one both stacks agreed on then. Table isolation is
|
||||
//! observed on the listing a caller receives, because the listing use case filters only when the
|
||||
//! authorization attached the table snapshot, and it fails open when nothing was attached.
|
||||
|
||||
use super::*;
|
||||
use crate::app::storage_api::bucket_usecase::contract::bucket::{BucketOperations as _, MakeBucketOptions};
|
||||
use crate::app::storage_api::object_usecase::contract::object::ObjectIO as _;
|
||||
use crate::app::storage_api::object_usecase::{StorageObjectOptions, StoragePutObjReader};
|
||||
use crate::table_catalog::{
|
||||
ConfiguredTableCatalogStore, EcStoreTableCatalogObjectBackend, NamespaceEntry, TABLE_BUCKET_CATALOG_TYPE,
|
||||
TABLE_BUCKET_MARKER_CONFIG, TABLE_CATALOG_ENTRY_VERSION, TableBucketEntry, TableCatalogBackingMode, TableCatalogEntryState,
|
||||
TableCatalogStore, TableEntry,
|
||||
};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
const WEBSITE_DOMAIN: &str = "website.test";
|
||||
const S3_HOST: &str = "localhost:9000";
|
||||
const BUCKET: &str = "parity-site";
|
||||
const EMPTY: &str = "parity-empty";
|
||||
const TABLES: &str = "parity-tables";
|
||||
|
||||
/// The gateway stack over a store holding the website bucket, an empty bucket and a table bucket,
|
||||
/// with two IAM users: `list-allowed` may list buckets and versions, `list-none` has no policy.
|
||||
async fn stack() -> (rustfs_test_utils::TestECStoreEnv, S3EdgeService) {
|
||||
let env = rustfs_test_utils::TestECStoreEnv::builder()
|
||||
.prefix("metadata_route_gateway")
|
||||
.disk_count(1)
|
||||
.init_bucket_metadata(true)
|
||||
.build()
|
||||
.await;
|
||||
ObjectStore::new(env.ecstore.clone())
|
||||
.save_iam_config(serde_json::json!({"version":1}), format!("{}/format.json", *IAM_CONFIG_PREFIX))
|
||||
.await
|
||||
.unwrap();
|
||||
let iam = rustfs_iam::build_iam_sys(env.ecstore.clone()).await.unwrap();
|
||||
for (key, actions) in [
|
||||
("list-allowed", Some(vec!["s3:ListBucket", "s3:ListBucketVersions"])),
|
||||
("list-none", None),
|
||||
] {
|
||||
iam.create_user(
|
||||
key,
|
||||
&AddOrUpdateUserReq {
|
||||
secret_key: USER_SECRET.to_owned(),
|
||||
policy: None,
|
||||
status: AccountStatus::Enabled,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
if let Some(actions) = actions {
|
||||
let document =
|
||||
serde_json::json!({"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":actions,"Resource":"*"}]});
|
||||
iam.set_policy(key, Policy::parse_config(&serde_json::to_vec(&document).unwrap()).unwrap())
|
||||
.await
|
||||
.unwrap();
|
||||
iam.policy_db_set(key, UserType::Reg, false, key).await.unwrap();
|
||||
}
|
||||
}
|
||||
let context = Arc::new(AppContext::with_default_interfaces(
|
||||
env.ecstore.clone(),
|
||||
iam,
|
||||
Arc::new(rustfs_kms::KmsServiceManager::new()),
|
||||
));
|
||||
assert!(context.publish_action_credentials(rustfs_credentials::Credentials {
|
||||
access_key: ROOT.to_owned(),
|
||||
secret_key: ROOT_SECRET.to_owned(),
|
||||
status: "on".to_owned(),
|
||||
..Default::default()
|
||||
}));
|
||||
publish_test_app_context(context.clone());
|
||||
let slot = ServerContextSlot::new();
|
||||
assert!(slot.install(context));
|
||||
|
||||
let store = env.ecstore.clone();
|
||||
for bucket in [BUCKET, EMPTY] {
|
||||
store.make_bucket(bucket, &MakeBucketOptions::default()).await.unwrap();
|
||||
}
|
||||
for (key, body, redirect) in [
|
||||
("index.html", "home", None),
|
||||
("404.html", "error page", None),
|
||||
("docs", "ordinary object", None),
|
||||
("section/index.html", "section page", None),
|
||||
("private.txt", "private", None),
|
||||
("move", "ordinary redirect object", Some("/new-page")),
|
||||
("a b/c", "encoded key", None),
|
||||
] {
|
||||
let mut options = StorageObjectOptions::default();
|
||||
options
|
||||
.user_defined
|
||||
.insert("x-amz-meta-project".to_owned(), "alpha".to_owned());
|
||||
if let Some(location) = redirect {
|
||||
options
|
||||
.user_defined
|
||||
.insert(rustfs_utils::http::AMZ_WEBSITE_REDIRECT_LOCATION.to_owned(), location.to_owned());
|
||||
}
|
||||
store
|
||||
.put_object(BUCKET, key, &mut StoragePutObjReader::from_vec(body.as_bytes().to_vec()), &options)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
let website = "<WebsiteConfiguration><IndexDocument><Suffix>index.html</Suffix></IndexDocument><ErrorDocument><Key>404.html</Key></ErrorDocument></WebsiteConfiguration>";
|
||||
store
|
||||
.update_bucket_metadata_config(
|
||||
BUCKET,
|
||||
crate::app::storage_api::bucket::metadata::BUCKET_WEBSITE_CONFIG,
|
||||
website.as_bytes().to_vec(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
let policy = serde_json::json!({"Version": "2012-10-17", "Statement": [
|
||||
{"Effect":"Allow","Principal":"*","Action":"s3:GetObject","Resource":format!("arn:aws:s3:::{BUCKET}/*")},
|
||||
{"Effect":"Deny","Principal":"*","Action":"s3:GetObject","Resource":format!("arn:aws:s3:::{BUCKET}/private.txt")}
|
||||
]});
|
||||
store
|
||||
.update_bucket_metadata_config(
|
||||
BUCKET,
|
||||
crate::app::storage_api::bucket::metadata::BUCKET_POLICY_CONFIG,
|
||||
serde_json::to_vec(&policy).unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
seed_table_bucket(&env).await;
|
||||
|
||||
let mut config = config::Config::new("127.0.0.1:9001", Vec::new());
|
||||
config.console_enable = false;
|
||||
let website = crate::app::website::WebsiteHost::new(vec![WEBSITE_DOMAIN.to_owned()], "http", slot.clone());
|
||||
let edge = assemble_s3_stack(&config, website, assembly(slot)).unwrap();
|
||||
(env, edge)
|
||||
}
|
||||
|
||||
/// `TABLES`: a table bucket whose catalog owns the `tables/table-id/` warehouse prefix, with an
|
||||
/// ordinary key, a warehouse key and a reserved catalog key, and a policy that lets anyone list.
|
||||
async fn seed_table_bucket(env: &rustfs_test_utils::TestECStoreEnv) {
|
||||
let store = &env.ecstore;
|
||||
store.make_bucket(TABLES, &MakeBucketOptions::default()).await.unwrap();
|
||||
store
|
||||
.update_bucket_metadata_config(
|
||||
TABLES,
|
||||
TABLE_BUCKET_MARKER_CONFIG,
|
||||
crate::table_catalog::table_bucket_marker_json().unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
let policy = serde_json::json!({"Version": "2012-10-17", "Statement": [{
|
||||
"Effect": "Allow", "Principal": {"AWS": "*"},
|
||||
"Action": ["s3:ListBucket", "s3:ListBucketVersions"], "Resource": format!("arn:aws:s3:::{TABLES}")
|
||||
}]});
|
||||
store
|
||||
.update_bucket_metadata_config(
|
||||
TABLES,
|
||||
crate::app::storage_api::bucket::metadata::BUCKET_POLICY_CONFIG,
|
||||
serde_json::to_vec(&policy).unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
let catalog = ConfiguredTableCatalogStore::new_for_test(
|
||||
EcStoreTableCatalogObjectBackend::new(Arc::clone(store)),
|
||||
TableCatalogBackingMode::from_env().unwrap(),
|
||||
);
|
||||
catalog
|
||||
.put_table_bucket(TableBucketEntry {
|
||||
version: TABLE_CATALOG_ENTRY_VERSION,
|
||||
table_bucket: TABLES.to_owned(),
|
||||
catalog_type: TABLE_BUCKET_CATALOG_TYPE.to_owned(),
|
||||
warehouse_root: format!("s3://{TABLES}/"),
|
||||
state: TableCatalogEntryState::Active,
|
||||
properties: BTreeMap::new(),
|
||||
active_rename_id: None,
|
||||
created_at: None,
|
||||
updated_at: None,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
catalog
|
||||
.create_namespace(NamespaceEntry {
|
||||
version: TABLE_CATALOG_ENTRY_VERSION,
|
||||
table_bucket: TABLES.to_owned(),
|
||||
namespace: "sales".to_owned(),
|
||||
namespace_id: "sales".to_owned(),
|
||||
state: TableCatalogEntryState::Active,
|
||||
properties: BTreeMap::new(),
|
||||
created_at: None,
|
||||
updated_at: None,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
catalog
|
||||
.create_table(TableEntry {
|
||||
version: TABLE_CATALOG_ENTRY_VERSION,
|
||||
table_bucket: TABLES.to_owned(),
|
||||
namespace: "sales".to_owned(),
|
||||
table: "orders".to_owned(),
|
||||
table_id: "table-id".to_owned(),
|
||||
table_uuid: uuid::Uuid::new_v4().to_string(),
|
||||
format: "ICEBERG".to_owned(),
|
||||
format_version: 2,
|
||||
warehouse_location: format!("s3://{TABLES}/tables/table-id"),
|
||||
metadata_location: format!("s3://{TABLES}/tables/table-id/metadata.json"),
|
||||
version_token: "v1".to_owned(),
|
||||
generation: 1,
|
||||
state: TableCatalogEntryState::Active,
|
||||
properties: BTreeMap::new(),
|
||||
created_at: None,
|
||||
updated_at: None,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
for key in ["ordinary.txt", "tables/table-id/data.parquet", ".rustfs-table/private.json"] {
|
||||
store
|
||||
.put_object(
|
||||
TABLES,
|
||||
key,
|
||||
&mut StoragePutObjReader::from_vec(b"private metadata".to_vec()),
|
||||
&StorageObjectOptions::default(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn website_request(
|
||||
method: Method,
|
||||
path: &str,
|
||||
host: &str,
|
||||
extra: Option<(&'static str, &'static str)>,
|
||||
) -> HttpRequest<Empty<Bytes>> {
|
||||
let mut builder = HttpRequest::builder()
|
||||
.method(method)
|
||||
.uri(path)
|
||||
.header(http::header::HOST, host)
|
||||
.header("x-request-id", REQUEST_ID);
|
||||
if let Some((name, value)) = extra {
|
||||
builder = builder.header(name, value);
|
||||
}
|
||||
builder.body(Empty::new()).unwrap()
|
||||
}
|
||||
|
||||
fn signed_listing(bucket: &str, query: &str, key: &str, secret: &str) -> HttpRequest<Empty<Bytes>> {
|
||||
signed(&format!("/{bucket}"), query, S3_HOST, key, secret, Signed::Header)
|
||||
}
|
||||
|
||||
/// The `<Key>` of every entry a listing document names, in order.
|
||||
fn keys(body: &[u8]) -> Vec<String> {
|
||||
let text = String::from_utf8_lossy(body);
|
||||
text.split("<Key>")
|
||||
.skip(1)
|
||||
.filter_map(|tail| tail.split_once("</Key>").map(|(key, _)| key.to_owned()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// One website request: method, path, host, an extra header, and the status the website answers.
|
||||
type WebsiteCase<'a> = (Method, &'a str, String, Option<(&'static str, &'static str)>, StatusCode);
|
||||
|
||||
/// One listing request: its label, the request, the status it is answered with and the error code, if any.
|
||||
type ListingCase = (&'static str, HttpRequest<Empty<Bytes>>, StatusCode, Option<&'static str>);
|
||||
|
||||
#[tokio::test]
|
||||
#[serial_test::serial]
|
||||
async fn website_host_answers_each_request_class_with_the_status_the_legacy_table_recorded() {
|
||||
let (_env, edge) = stack().await;
|
||||
let site = format!("{BUCKET}.{WEBSITE_DOMAIN}");
|
||||
let path_style = format!("/{BUCKET}/index.html");
|
||||
let cases: Vec<WebsiteCase<'_>> = vec![
|
||||
(Method::GET, "/", site.clone(), None, StatusCode::OK),
|
||||
(Method::HEAD, "/", site.clone(), None, StatusCode::OK),
|
||||
(Method::GET, "/docs", site.clone(), None, StatusCode::OK),
|
||||
(
|
||||
Method::GET,
|
||||
"/index.html",
|
||||
site.clone(),
|
||||
Some(("range", "bytes=1-2")),
|
||||
StatusCode::PARTIAL_CONTENT,
|
||||
),
|
||||
(Method::GET, "/missing", site.clone(), None, StatusCode::NOT_FOUND),
|
||||
(Method::HEAD, "/missing", site.clone(), None, StatusCode::NOT_FOUND),
|
||||
// The bucket policy denies everyone this object: a private object is not served.
|
||||
(Method::GET, "/private.txt", site.clone(), None, StatusCode::FORBIDDEN),
|
||||
(Method::GET, "/section?x=1", site.clone(), None, StatusCode::FOUND),
|
||||
(Method::GET, "/move", site.clone(), None, StatusCode::MOVED_PERMANENTLY),
|
||||
(
|
||||
Method::GET,
|
||||
"/move",
|
||||
site.clone(),
|
||||
Some(("if-none-match", "*")),
|
||||
StatusCode::MOVED_PERMANENTLY,
|
||||
),
|
||||
(
|
||||
Method::GET,
|
||||
"/index.html",
|
||||
site.clone(),
|
||||
Some(("range", "bytes=999999-")),
|
||||
StatusCode::RANGE_NOT_SATISFIABLE,
|
||||
),
|
||||
(
|
||||
Method::GET,
|
||||
"/index.html",
|
||||
site.clone(),
|
||||
Some(("if-modified-since", "yesterday")),
|
||||
StatusCode::BAD_REQUEST,
|
||||
),
|
||||
(
|
||||
Method::GET,
|
||||
"/index.html",
|
||||
site.clone(),
|
||||
Some(("if-none-match", "*")),
|
||||
StatusCode::NOT_MODIFIED,
|
||||
),
|
||||
// A website host serves reads only.
|
||||
(Method::POST, "/", site.clone(), None, StatusCode::METHOD_NOT_ALLOWED),
|
||||
(Method::PUT, "/index.html", site.clone(), None, StatusCode::METHOD_NOT_ALLOWED),
|
||||
(Method::DELETE, "/index.html", site.clone(), None, StatusCode::METHOD_NOT_ALLOWED),
|
||||
(Method::GET, "/rustfs/admin/v3/info", site.clone(), None, StatusCode::NOT_FOUND),
|
||||
(Method::GET, "/", format!("{EMPTY}.{WEBSITE_DOMAIN}"), None, StatusCode::NOT_FOUND),
|
||||
(Method::GET, "/", format!("absent.{WEBSITE_DOMAIN}"), None, StatusCode::NOT_FOUND),
|
||||
(Method::GET, path_style.as_str(), WEBSITE_DOMAIN.to_owned(), None, StatusCode::NOT_FOUND),
|
||||
];
|
||||
let mut failures = Vec::new();
|
||||
for (method, path, host, extra, status) in &cases {
|
||||
let (got, _, body) = answer(edge.clone(), website_request(method.clone(), path, host, *extra)).await;
|
||||
if got != *status {
|
||||
failures.push(format!(
|
||||
"website {method} {host}{path} {extra:?}: want {status}, got {got} {}",
|
||||
String::from_utf8_lossy(&body)
|
||||
));
|
||||
}
|
||||
}
|
||||
assert!(failures.is_empty(), "{}", failures.join("\n"));
|
||||
|
||||
// The website's own content, not just its status.
|
||||
let (_, _, home) = answer(edge.clone(), website_request(Method::GET, "/", &site, None)).await;
|
||||
assert_eq!(home, "home");
|
||||
let (_, _, missing) = answer(edge.clone(), website_request(Method::GET, "/missing", &site, None)).await;
|
||||
assert_eq!(missing, "error page");
|
||||
let (_, _, private) = answer(edge.clone(), website_request(Method::GET, "/private.txt", &site, None)).await;
|
||||
assert!(
|
||||
!String::from_utf8_lossy(&private).contains("private"),
|
||||
"the denied object's content was served: {private:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// A malformed path and a SigV4 `Authorization` header sent to a website host.
|
||||
///
|
||||
/// `/%zz` is not an encoding the key decoder refuses, so it names the key `%zz`: the website
|
||||
/// answers its `404` error document. A bad `Authorization` header neither refuses nor widens a
|
||||
/// read: the website service never reads it (`200`; the legacy S3 service refused it with `400
|
||||
/// InvalidRequest` before routing, the one difference the comparison recorded).
|
||||
#[tokio::test]
|
||||
#[serial_test::serial]
|
||||
async fn website_host_answers_a_malformed_path_and_ignores_an_authorization_header() {
|
||||
let (_env, edge) = stack().await;
|
||||
let site = format!("{BUCKET}.{WEBSITE_DOMAIN}");
|
||||
let bad_auth = Some(("authorization", "AWS4-HMAC-SHA256 Credential=nobody/20200101/us-east-1/s3/aws4_request"));
|
||||
|
||||
let (status, _, body) = answer(edge.clone(), website_request(Method::GET, "/%zz", &site, None)).await;
|
||||
assert_eq!((status, body.as_ref()), (StatusCode::NOT_FOUND, b"error page".as_slice()));
|
||||
|
||||
let (status, _, body) = answer(edge.clone(), website_request(Method::GET, "/index.html", &site, bad_auth)).await;
|
||||
assert_eq!((status, body.as_ref()), (StatusCode::OK, b"home".as_slice()));
|
||||
|
||||
// The header cannot widen a read either: the denied object stays denied under a bad header.
|
||||
let (status, _, _) = answer(edge.clone(), website_request(Method::GET, "/private.txt", &site, bad_auth)).await;
|
||||
assert_eq!(status, StatusCode::FORBIDDEN);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial_test::serial]
|
||||
async fn metadata_listings_follow_the_callers_iam_policy() {
|
||||
let (_env, edge) = stack().await;
|
||||
let anonymous = |query: &'static str| move || website_request(Method::GET, &format!("/{BUCKET}?{query}"), S3_HOST, None);
|
||||
let cases: Vec<ListingCase> = vec![
|
||||
(
|
||||
"root v2",
|
||||
signed_listing(BUCKET, "list-type=2&metadata=true", ROOT, ROOT_SECRET),
|
||||
StatusCode::OK,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"root versions",
|
||||
signed_listing(BUCKET, "metadata=true&versions=", ROOT, ROOT_SECRET),
|
||||
StatusCode::OK,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"empty bucket",
|
||||
signed_listing(EMPTY, "list-type=2&metadata=true", ROOT, ROOT_SECRET),
|
||||
StatusCode::OK,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"first page",
|
||||
signed_listing(BUCKET, "list-type=2&max-keys=2&metadata=true", ROOT, ROOT_SECRET),
|
||||
StatusCode::OK,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"url encoding",
|
||||
signed_listing(BUCKET, "encoding-type=url&list-type=2&metadata=true&prefix=a", ROOT, ROOT_SECRET),
|
||||
StatusCode::OK,
|
||||
None,
|
||||
),
|
||||
// rustfs#4845: a signed user is resolved to its IAM policy, not evaluated as anonymous.
|
||||
(
|
||||
"listing user v2",
|
||||
signed_listing(BUCKET, "list-type=2&metadata=true", "list-allowed", USER_SECRET),
|
||||
StatusCode::OK,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"listing user versions",
|
||||
signed_listing(BUCKET, "metadata=true&versions=", "list-allowed", USER_SECRET),
|
||||
StatusCode::OK,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"bad encoding",
|
||||
signed_listing(BUCKET, "encoding-type=xml&list-type=2&metadata=true", ROOT, ROOT_SECRET),
|
||||
StatusCode::BAD_REQUEST,
|
||||
Some("InvalidArgument"),
|
||||
),
|
||||
(
|
||||
"bad token",
|
||||
signed_listing(BUCKET, "continuation-token=%25%25&list-type=2&metadata=true", ROOT, ROOT_SECRET),
|
||||
StatusCode::BAD_REQUEST,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"bad max-keys",
|
||||
signed_listing(BUCKET, "list-type=2&max-keys=ten&metadata=true", ROOT, ROOT_SECRET),
|
||||
StatusCode::BAD_REQUEST,
|
||||
Some("InvalidArgument"),
|
||||
),
|
||||
(
|
||||
"no policy user v2",
|
||||
signed_listing(BUCKET, "list-type=2&metadata=true", "list-none", USER_SECRET),
|
||||
StatusCode::FORBIDDEN,
|
||||
Some("AccessDenied"),
|
||||
),
|
||||
(
|
||||
"no policy user versions",
|
||||
signed_listing(BUCKET, "metadata=true&versions=", "list-none", USER_SECRET),
|
||||
StatusCode::FORBIDDEN,
|
||||
Some("AccessDenied"),
|
||||
),
|
||||
(
|
||||
"missing bucket",
|
||||
signed_listing("parity-absent", "list-type=2&metadata=true", ROOT, ROOT_SECRET),
|
||||
StatusCode::NOT_FOUND,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"anonymous v2",
|
||||
anonymous("list-type=2&metadata=true")(),
|
||||
StatusCode::FORBIDDEN,
|
||||
Some("AccessDenied"),
|
||||
),
|
||||
(
|
||||
"anonymous versions",
|
||||
anonymous("versions&metadata=true")(),
|
||||
StatusCode::FORBIDDEN,
|
||||
Some("AccessDenied"),
|
||||
),
|
||||
];
|
||||
let mut failures = Vec::new();
|
||||
for (label, request, status, code) in cases {
|
||||
let (got, _, body) = answer(edge.clone(), request).await;
|
||||
if got != status {
|
||||
failures.push(format!("listing {label}: want {status}, got {got} {}", String::from_utf8_lossy(&body)));
|
||||
} else if let Some(code) = code
|
||||
&& refusal(&body).0 != code
|
||||
{
|
||||
failures.push(format!("listing {label}: want code {code}, got {:?}", refusal(&body)));
|
||||
}
|
||||
}
|
||||
assert!(failures.is_empty(), "{}", failures.join("\n"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial_test::serial]
|
||||
async fn metadata_listing_documents_carry_the_extension_and_the_callers_read_rights() {
|
||||
let (_env, edge) = stack().await;
|
||||
let (_, _, root) = answer(edge.clone(), signed_listing(BUCKET, "list-type=2&metadata=true", ROOT, ROOT_SECRET)).await;
|
||||
let text = String::from_utf8_lossy(&root);
|
||||
for part in [
|
||||
"<ListBucketResult",
|
||||
"<UserMetadata>",
|
||||
"<project>alpha</project>",
|
||||
"<Internal>",
|
||||
] {
|
||||
assert!(text.contains(part), "the listing lacks {part}: {text}");
|
||||
}
|
||||
// The bucket policy denies everyone `private.txt`: its entry carries no metadata, while the
|
||||
// entries the policy lets everyone read do.
|
||||
let (_, _, user) = answer(
|
||||
edge.clone(),
|
||||
signed_listing(BUCKET, "list-type=2&metadata=true", "list-allowed", USER_SECRET),
|
||||
)
|
||||
.await;
|
||||
let listed = String::from_utf8_lossy(&user).into_owned();
|
||||
let entry = |key: &str| {
|
||||
listed
|
||||
.split("<Contents>")
|
||||
.find(|entry| entry.contains(&format!("<Key>{key}</Key>")))
|
||||
.unwrap_or_default()
|
||||
.to_owned()
|
||||
};
|
||||
assert!(
|
||||
!entry("private.txt").contains("<UserMetadata>") && entry("docs").contains("<UserMetadata>"),
|
||||
"the listing's metadata ignores what the caller may read: {listed}"
|
||||
);
|
||||
// A first page of two names a continuation token, and the second page accepts it.
|
||||
let (_, _, first) = answer(
|
||||
edge.clone(),
|
||||
signed_listing(BUCKET, "list-type=2&max-keys=2&metadata=true", ROOT, ROOT_SECRET),
|
||||
)
|
||||
.await;
|
||||
let first = String::from_utf8_lossy(&first).into_owned();
|
||||
let token = first
|
||||
.split_once("<NextContinuationToken>")
|
||||
.and_then(|(_, tail)| tail.split_once('<'))
|
||||
.map(|(token, _)| token.to_owned())
|
||||
.unwrap_or_else(|| panic!("the first page has no continuation token: {first}"));
|
||||
let query = format!("continuation-token={}&list-type=2&metadata=true", urlencoding::encode(&token));
|
||||
let (status, _, second) = answer(edge, signed_listing(BUCKET, &query, ROOT, ROOT_SECRET)).await;
|
||||
assert_eq!(status, StatusCode::OK, "{}", String::from_utf8_lossy(&second));
|
||||
assert!(String::from_utf8_lossy(&second).contains("<ContinuationToken>"));
|
||||
}
|
||||
|
||||
/// The gateway handler's listing authorization attaches the table snapshot, so a caller without
|
||||
/// table access never receives a warehouse or catalog key. Without the snapshot the use case lists
|
||||
/// the bucket unfiltered, so the filtering is observed on what the caller receives.
|
||||
#[tokio::test]
|
||||
#[serial_test::serial]
|
||||
async fn a_metadata_listing_of_a_table_bucket_hides_the_keys_the_caller_has_no_table_access_to() {
|
||||
let (_env, edge) = stack().await;
|
||||
for query in ["list-type=2&metadata=true", "metadata=true&versions="] {
|
||||
let anonymous = website_request(Method::GET, &format!("/{TABLES}?{query}"), S3_HOST, None);
|
||||
for (caller, request, visible) in [
|
||||
// No table-metadata right: the ordinary key only, never the warehouse or catalog keys.
|
||||
("anonymous", anonymous, vec!["ordinary.txt"]),
|
||||
(
|
||||
"listing user",
|
||||
signed_listing(TABLES, query, "list-allowed", USER_SECRET),
|
||||
vec!["ordinary.txt"],
|
||||
),
|
||||
// The owner may read table data, so the control shows the filter is selective: the
|
||||
// warehouse key is listed, the reserved catalog prefix still is not.
|
||||
(
|
||||
"root",
|
||||
signed_listing(TABLES, query, ROOT, ROOT_SECRET),
|
||||
vec!["ordinary.txt", "tables/table-id/data.parquet"],
|
||||
),
|
||||
] {
|
||||
let (status, _, body) = answer(edge.clone(), request).await;
|
||||
assert_eq!(status, StatusCode::OK, "{caller} {query}: {}", String::from_utf8_lossy(&body));
|
||||
assert_eq!(keys(&body), visible, "{caller} {query}: {}", String::from_utf8_lossy(&body));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1858,24 +1858,11 @@ pub(in crate::server) mod tests {
|
||||
let prefix = crate::server::console_prefix();
|
||||
let console_uri = format!("{prefix}/index.html").parse().expect("console URI");
|
||||
assert!(is_empty_body_console_path(&Method::GET, &console_uri));
|
||||
let request = HttpRequest::builder()
|
||||
.uri(format!("{prefix}/index.html?attributes"))
|
||||
.body(())
|
||||
.expect("console attributes request");
|
||||
assert!(!is_object_attributes_request(&request));
|
||||
let s3_request = HttpRequest::builder()
|
||||
.uri("/bucket/object?attributes")
|
||||
.body(())
|
||||
.expect("S3 attributes request");
|
||||
assert!(is_object_attributes_request(&s3_request));
|
||||
}
|
||||
|
||||
use super::*;
|
||||
use crate::server::CONSOLE_PREFIX;
|
||||
use crate::server::legacy_compat::{
|
||||
IcebergRestErrorCompatLayer, MAX_XML_COMPAT_BODY_BYTES, ObjectAttributesEtagFixLayer, S3ErrorMessageCompatLayer,
|
||||
is_empty_body_console_path, is_object_attributes_request,
|
||||
};
|
||||
use crate::server::legacy_compat::{IcebergRestErrorCompatLayer, MAX_XML_COMPAT_BODY_BYTES, is_empty_body_console_path};
|
||||
use futures::future::{Ready, ready};
|
||||
use http::Request;
|
||||
use http_body_util::Empty;
|
||||
@@ -3990,23 +3977,18 @@ pub(in crate::server) mod tests {
|
||||
}
|
||||
}
|
||||
for length in [None, Some(MAX_XML_COMPAT_BODY_BYTES + 1)] {
|
||||
for (layer, path, status) in [
|
||||
(0, "/bucket/object", StatusCode::FORBIDDEN),
|
||||
(1, "/iceberg/v1/warehouse/namespaces/ns/tables/table", StatusCode::FORBIDDEN),
|
||||
(2, "/bucket/object?attributes", StatusCode::OK),
|
||||
] {
|
||||
for (path, status) in [("/iceberg/v1/warehouse/namespaces/ns/tables/table", StatusCode::FORBIDDEN)] {
|
||||
let inner = StreamingXmlResponse { length, status };
|
||||
let request = Request::builder()
|
||||
.method(Method::GET)
|
||||
.uri(path)
|
||||
.body(())
|
||||
.expect("XML request");
|
||||
let response = match layer {
|
||||
0 => S3ErrorMessageCompatLayer.layer(inner).call(request).await,
|
||||
1 => IcebergRestErrorCompatLayer.layer(inner).call(request).await,
|
||||
_ => ObjectAttributesEtagFixLayer.layer(inner).call(request).await,
|
||||
}
|
||||
.expect("stream passed through");
|
||||
let response = IcebergRestErrorCompatLayer
|
||||
.layer(inner)
|
||||
.call(request)
|
||||
.await
|
||||
.expect("stream passed through");
|
||||
assert_eq!(response.status(), status);
|
||||
assert_eq!(response.headers()[http::header::CONTENT_TYPE], "application/xml");
|
||||
}
|
||||
|
||||
@@ -1,191 +0,0 @@
|
||||
// Copyright 2024 RustFS Team
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//! `DoubleSlashListBucketsCompatLayer`: an s3s compatibility patch, installed
|
||||
//! by `server::http::external_service_stack!` and pinned there by
|
||||
//! `stack_census`.
|
||||
//!
|
||||
//! Patches: s3s reads `GET //` as an empty bucket name and refuses it with
|
||||
//! `InvalidBucketName` before routing, where MinIO routes it to `ListBuckets`
|
||||
//! (rustfs/backlog#601). Introduced in rustfs/rustfs#4336.
|
||||
//! Replaced by: the gateway route table, in which `//` and `/` both name
|
||||
//! `ListBuckets` (gateway `docs/middleware.md`, "The nine RustFS tower patch
|
||||
//! layers", row 3).
|
||||
//! Removed by: T2.12 (rustfs/backlog#2771).
|
||||
|
||||
use http::{Method, Request as HttpRequest, Response, Uri};
|
||||
use std::task::{Context, Poll};
|
||||
use tower::{Layer, Service};
|
||||
|
||||
/// Rewrites the request-target of a root-level double-slash `GET //` to `GET /`
|
||||
/// so it routes to `ListBuckets`, matching MinIO browser compatibility.
|
||||
///
|
||||
/// The AWS S3 browser client (SigV4) concatenates the endpoint with a leading
|
||||
/// slash and emits `GET //` for `ListBuckets`. The `s3s` path parser strips the
|
||||
/// single leading slash and then treats the remaining `/` as an empty bucket
|
||||
/// name, rejecting the request with `InvalidBucketName` before it is routed.
|
||||
/// MinIO's `api-router.go` registers an explicit `//` route to `ListBuckets`;
|
||||
/// this layer reproduces that behavior by collapsing the path to `/` up front.
|
||||
///
|
||||
/// The rewrite is intentionally limited to a path that is exactly `//` (optionally
|
||||
/// followed by a query string). It never touches bucket/object requests, so object
|
||||
/// keys with embedded or leading slashes are unaffected (those are normalized by
|
||||
/// `s3s` via `normalize_forward_slash_path`).
|
||||
#[derive(Clone)]
|
||||
pub struct DoubleSlashListBucketsCompatLayer;
|
||||
|
||||
impl<S> Layer<S> for DoubleSlashListBucketsCompatLayer {
|
||||
type Service = DoubleSlashListBucketsCompatService<S>;
|
||||
|
||||
fn layer(&self, inner: S) -> Self::Service {
|
||||
DoubleSlashListBucketsCompatService { inner }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct DoubleSlashListBucketsCompatService<S> {
|
||||
inner: S,
|
||||
}
|
||||
|
||||
impl<S, ReqBody, ResBody> Service<HttpRequest<ReqBody>> for DoubleSlashListBucketsCompatService<S>
|
||||
where
|
||||
S: Service<HttpRequest<ReqBody>, Response = Response<ResBody>> + Clone + Send + 'static,
|
||||
S::Future: Send + 'static,
|
||||
ReqBody: Send + 'static,
|
||||
ResBody: Send + 'static,
|
||||
{
|
||||
type Response = Response<ResBody>;
|
||||
type Error = S::Error;
|
||||
type Future = S::Future;
|
||||
|
||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
self.inner.poll_ready(cx)
|
||||
}
|
||||
|
||||
fn call(&mut self, mut req: HttpRequest<ReqBody>) -> Self::Future {
|
||||
if req.method() == Method::GET
|
||||
&& let Some(rewritten) = rewrite_double_slash_root(req.uri())
|
||||
{
|
||||
*req.uri_mut() = rewritten;
|
||||
}
|
||||
self.inner.call(req)
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the `/`-rooted URI when `uri` has a request-target path of exactly `//`.
|
||||
///
|
||||
/// Returns `None` for every other path so the rewrite is confined to the
|
||||
/// root-level double-slash case.
|
||||
fn rewrite_double_slash_root(uri: &Uri) -> Option<Uri> {
|
||||
if uri.path() != "//" {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut parts = uri.clone().into_parts();
|
||||
let path_and_query = match uri.query() {
|
||||
Some(query) => format!("/?{query}"),
|
||||
None => "/".to_string(),
|
||||
};
|
||||
parts.path_and_query = Some(path_and_query.parse().ok()?);
|
||||
Uri::from_parts(parts).ok()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use bytes::Bytes;
|
||||
use futures::future::{Ready, ready};
|
||||
use http::Request;
|
||||
use http_body_util::Full;
|
||||
use std::convert::Infallible;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
|
||||
#[test]
|
||||
fn rewrite_double_slash_root_only_matches_exact_double_slash() {
|
||||
// Exactly `//` is rewritten to `/` (query preserved).
|
||||
assert_eq!(
|
||||
rewrite_double_slash_root(&Uri::from_static("//")).map(|u| u.to_string()),
|
||||
Some("/".to_string())
|
||||
);
|
||||
assert_eq!(
|
||||
rewrite_double_slash_root(&Uri::from_static("//?x-id=ListBuckets")).map(|u| u.to_string()),
|
||||
Some("/?x-id=ListBuckets".to_string())
|
||||
);
|
||||
|
||||
// Everything else is left untouched.
|
||||
assert_eq!(rewrite_double_slash_root(&Uri::from_static("/")), None);
|
||||
assert_eq!(rewrite_double_slash_root(&Uri::from_static("//bucket")), None);
|
||||
assert_eq!(rewrite_double_slash_root(&Uri::from_static("/bucket")), None);
|
||||
assert_eq!(rewrite_double_slash_root(&Uri::from_static("/bucket//key")), None);
|
||||
assert_eq!(rewrite_double_slash_root(&Uri::from_static("///")), None);
|
||||
}
|
||||
|
||||
/// Inner service that records the request-target path it received and
|
||||
/// returns an empty response, so the layer's URI rewrite can be observed.
|
||||
#[derive(Clone, Default)]
|
||||
struct UriCaptureService {
|
||||
path: Arc<Mutex<Option<String>>>,
|
||||
}
|
||||
|
||||
impl<B> Service<Request<B>> for UriCaptureService {
|
||||
type Response = Response<Full<Bytes>>;
|
||||
type Error = Infallible;
|
||||
type Future = Ready<Result<Self::Response, Self::Error>>;
|
||||
|
||||
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
Poll::Ready(Ok(()))
|
||||
}
|
||||
|
||||
fn call(&mut self, req: Request<B>) -> Self::Future {
|
||||
*self.path.lock().expect("path lock") = Some(req.uri().path().to_string());
|
||||
ready(Ok(Response::new(Full::from(Bytes::new()))))
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn double_slash_compat_layer_rewrites_get_double_slash() {
|
||||
let inner = UriCaptureService::default();
|
||||
let seen = inner.path.clone();
|
||||
let mut service = DoubleSlashListBucketsCompatLayer.layer(inner);
|
||||
|
||||
let observe = |seen: &Arc<Mutex<Option<String>>>| seen.lock().expect("path lock").clone();
|
||||
|
||||
// `GET //` becomes `GET /`.
|
||||
let req = Request::builder()
|
||||
.method(Method::GET)
|
||||
.uri("//")
|
||||
.body(Full::<Bytes>::from(Bytes::new()))
|
||||
.expect("request");
|
||||
service.call(req).await.expect("response");
|
||||
assert_eq!(observe(&seen).as_deref(), Some("/"));
|
||||
|
||||
// Non-GET `//` is not rewritten.
|
||||
let req = Request::builder()
|
||||
.method(Method::PUT)
|
||||
.uri("//")
|
||||
.body(Full::<Bytes>::from(Bytes::new()))
|
||||
.expect("request");
|
||||
service.call(req).await.expect("response");
|
||||
assert_eq!(observe(&seen).as_deref(), Some("//"));
|
||||
|
||||
// `GET //bucket` is not rewritten.
|
||||
let req = Request::builder()
|
||||
.method(Method::GET)
|
||||
.uri("//bucket")
|
||||
.body(Full::<Bytes>::from(Bytes::new()))
|
||||
.expect("request");
|
||||
service.call(req).await.expect("response");
|
||||
assert_eq!(observe(&seen).as_deref(), Some("//bucket"));
|
||||
}
|
||||
}
|
||||
@@ -15,16 +15,16 @@
|
||||
//! by `server::http::external_service_stack!` (in both the external and the
|
||||
//! internode lane) and pinned there by `stack_census`.
|
||||
//!
|
||||
//! Patches: s3s wants a `Content-Length` before it validates a request, while
|
||||
//! some clients omit the header on routes whose request never carries a body.
|
||||
//! Introduced in rustfs/rustfs#2888.
|
||||
//! Replaced by: a gateway `StageFilter::on_wire` (gateway `docs/middleware.md`,
|
||||
//! "Level 2: `StageFilter`"; "The nine RustFS tower patch layers", row 5).
|
||||
//! Removed by: T2.12 (rustfs/backlog#2771).
|
||||
//! Patches: some clients omit `Content-Length` on admin and console routes whose
|
||||
//! request never carries a body, while the handlers behind them validate a
|
||||
//! length. Introduced in rustfs/rustfs#2888 for the s3s edge.
|
||||
//! The S3 half is gone: the gateway stack leaves the bodies of bodyless S3
|
||||
//! operations unread (`server::gateway_stack::tests::legacy_layers`).
|
||||
//! The admin and console halves, and the internode lane, stay until their
|
||||
//! hosts stop needing a length.
|
||||
|
||||
use crate::admin::console::is_console_path;
|
||||
use crate::server::is_admin_path;
|
||||
use crate::server::layer::ConditionalCorsLayer;
|
||||
use http::{HeaderValue, Method, Request as HttpRequest, Response};
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
@@ -94,11 +94,7 @@ fn should_force_zero_content_length_for_empty_body_route<B>(req: &HttpRequest<B>
|
||||
return false;
|
||||
}
|
||||
|
||||
if is_empty_body_console_path(req.method(), req.uri()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
is_empty_body_s3_path(req.method(), req.uri())
|
||||
is_empty_body_console_path(req.method(), req.uri())
|
||||
}
|
||||
|
||||
fn is_empty_body_admin_path(method: &Method, uri: &http::Uri) -> bool {
|
||||
@@ -150,10 +146,6 @@ fn is_heal_status_query(path: &str, query: Option<&str>) -> bool {
|
||||
})
|
||||
}
|
||||
|
||||
fn is_empty_body_s3_path(method: &Method, uri: &http::Uri) -> bool {
|
||||
matches!(*method, Method::GET | Method::HEAD | Method::DELETE) && ConditionalCorsLayer::is_s3_path(uri.path())
|
||||
}
|
||||
|
||||
pub(in crate::server) fn is_empty_body_console_path(method: &Method, uri: &http::Uri) -> bool {
|
||||
matches!(*method, Method::GET | Method::HEAD) && is_console_path(uri.path())
|
||||
}
|
||||
@@ -260,7 +252,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn s3_empty_body_get_without_content_length_is_normalized() {
|
||||
fn s3_empty_body_get_without_content_length_is_left_to_the_gateway() {
|
||||
let paths = [
|
||||
"/?x-id=ListBuckets",
|
||||
"/",
|
||||
@@ -274,21 +266,21 @@ mod tests {
|
||||
let request = Request::builder().method(Method::GET).uri(path).body(()).expect("request");
|
||||
|
||||
assert!(
|
||||
should_force_zero_content_length_for_empty_body_route(&request),
|
||||
"{path} should force Content-Length: 0"
|
||||
!should_force_zero_content_length_for_empty_body_route(&request),
|
||||
"{path} must pass through unchanged"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn s3_empty_body_head_without_content_length_is_normalized() {
|
||||
fn s3_empty_body_head_without_content_length_is_left_to_the_gateway() {
|
||||
let request = Request::builder()
|
||||
.method(Method::HEAD)
|
||||
.uri("/bucket/object.txt")
|
||||
.body(())
|
||||
.expect("request");
|
||||
|
||||
assert!(should_force_zero_content_length_for_empty_body_route(&request));
|
||||
assert!(!should_force_zero_content_length_for_empty_body_route(&request));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -342,8 +334,8 @@ mod tests {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn empty_body_layer_inserts_zero_content_length_for_s3_and_console_get() {
|
||||
for path in ["/?x-id=ListBuckets".to_string(), format!("{CONSOLE_PREFIX}/index.html")] {
|
||||
async fn empty_body_layer_inserts_zero_content_length_for_console_get() {
|
||||
for path in [format!("{CONSOLE_PREFIX}/index.html")] {
|
||||
let capture = HeaderCaptureService::default();
|
||||
let headers = capture.headers();
|
||||
let mut service = EmptyBodyContentLengthCompatLayer.layer(capture);
|
||||
@@ -470,18 +462,18 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn s3_delete_object_version_without_content_length_is_normalized() {
|
||||
fn s3_delete_object_version_without_content_length_is_left_to_the_gateway() {
|
||||
let request = Request::builder()
|
||||
.method(Method::DELETE)
|
||||
.uri("/bucket/object.txt?versionId=3HL4kqtJlcpXrof3Gj0OmxJnVBH40Nrjfkd")
|
||||
.body(())
|
||||
.expect("request");
|
||||
|
||||
assert!(should_force_zero_content_length_for_empty_body_route(&request));
|
||||
assert!(!should_force_zero_content_length_for_empty_body_route(&request));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn empty_body_layer_inserts_zero_content_length_for_s3_delete_object_version() {
|
||||
async fn empty_body_layer_leaves_an_s3_delete_object_version_unchanged() {
|
||||
let capture = HeaderCaptureService::default();
|
||||
let headers = capture.headers();
|
||||
let mut service = EmptyBodyContentLengthCompatLayer.layer(capture);
|
||||
@@ -494,7 +486,7 @@ mod tests {
|
||||
let _ = service.call(request).await.expect("service call");
|
||||
|
||||
let headers = headers.lock().expect("captured headers").take().expect("captured headers");
|
||||
assert_eq!(headers.get(http::header::CONTENT_LENGTH).unwrap(), "0");
|
||||
assert!(headers.get(http::header::CONTENT_LENGTH).is_none());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -550,25 +542,25 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn s3_delete_bucket_without_content_length_is_normalized() {
|
||||
fn s3_delete_bucket_without_content_length_is_left_to_the_gateway() {
|
||||
let request = Request::builder()
|
||||
.method(Method::DELETE)
|
||||
.uri("/bucket")
|
||||
.body(())
|
||||
.expect("request");
|
||||
|
||||
assert!(should_force_zero_content_length_for_empty_body_route(&request));
|
||||
assert!(!should_force_zero_content_length_for_empty_body_route(&request));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn s3_delete_object_without_version_id_is_normalized() {
|
||||
fn s3_delete_object_without_version_id_is_left_to_the_gateway() {
|
||||
let request = Request::builder()
|
||||
.method(Method::DELETE)
|
||||
.uri("/bucket/object")
|
||||
.body(())
|
||||
.expect("request");
|
||||
|
||||
assert!(should_force_zero_content_length_for_empty_body_route(&request));
|
||||
assert!(!should_force_zero_content_length_for_empty_body_route(&request));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -32,14 +32,14 @@
|
||||
//! | --- | --- |
|
||||
//! | `BodylessStatusFixLayer` | the gateway response invariants (row 1) |
|
||||
//! | `HeadRequestBodyFixLayer` | the same invariants on the refusal path (row 2) |
|
||||
//! | `DoubleSlashListBucketsCompatLayer` | the route table: `//` and `/` both name `ListBuckets` (row 3) |
|
||||
//! | `VirtualHostStyleHintLayer` | `HostResolver`'s diagnostic (row 4) |
|
||||
//! | `EmptyBodyContentLengthCompatLayer` | `StageFilter::on_wire` (row 5) |
|
||||
//! | `S3ErrorMessageCompatLayer` | the dialect error-render policy, `StageFilter::on_response` as the escape hatch (row 6) |
|
||||
//! | `ObjectAttributesEtagFixLayer` | the quirk table (`q-mpu-attributes-etag-0036`), `OpLayer<GetObjectAttributes>` to override (row 7) |
|
||||
//! | `EmptyBodyContentLengthCompatLayer` | its S3 half by `StageFilter::on_wire` (row 5); its admin, console and internode halves stay |
|
||||
//! | `StsQueryApiCompatLayer` | STS extension operations behind a `QueryPresent` route predicate (row 8) |
|
||||
//! | `IcebergRestErrorCompatLayer` | the `rustfs` dialect's claimed table-catalog surface (gateway ADR-0031) |
|
||||
//! | `SigV4HeaderGuardLayer` | `rustfs-gateway-sig` signed-header enforcement (`SignedHeaderSet::parse_and_enforce`) |
|
||||
//!
|
||||
//! The layers the gateway stack replaces outright are gone: `DoubleSlashListBucketsCompatLayer`,
|
||||
//! `VirtualHostStyleHintLayer`, `S3ErrorMessageCompatLayer`, `ObjectAttributesEtagFixLayer` and
|
||||
//! `SigV4HeaderGuardLayer`. `server::gateway_stack::tests::legacy_layers` pins what each of them
|
||||
//! made the legacy stack answer against the gateway stack alone.
|
||||
//!
|
||||
//! `ConditionalCorsLayer` (row 9) is outside the list rustfs/backlog#2787
|
||||
//! moves and stays in `server/layer.rs`.
|
||||
@@ -49,31 +49,19 @@
|
||||
//! fixed-response fixture shared by the response-rewriting layers' tests.
|
||||
|
||||
mod bodyless_status_fix;
|
||||
mod double_slash_list_buckets_compat;
|
||||
mod empty_body_content_length_compat;
|
||||
mod head_request_body_fix;
|
||||
mod iceberg_rest_error_compat;
|
||||
mod object_attributes_etag_fix;
|
||||
mod s3_error_message_compat;
|
||||
mod sigv4_header_guard;
|
||||
mod sts_query_api_compat;
|
||||
mod virtual_host_style_hint;
|
||||
|
||||
pub(crate) use bodyless_status_fix::BodylessStatusFixLayer;
|
||||
pub(crate) use double_slash_list_buckets_compat::DoubleSlashListBucketsCompatLayer;
|
||||
pub(crate) use empty_body_content_length_compat::EmptyBodyContentLengthCompatLayer;
|
||||
pub(crate) use head_request_body_fix::HeadRequestBodyFixLayer;
|
||||
pub(crate) use iceberg_rest_error_compat::IcebergRestErrorCompatLayer;
|
||||
pub(crate) use object_attributes_etag_fix::ObjectAttributesEtagFixLayer;
|
||||
pub(crate) use s3_error_message_compat::S3ErrorMessageCompatLayer;
|
||||
pub(crate) use sigv4_header_guard::SigV4HeaderGuardLayer;
|
||||
pub(crate) use sts_query_api_compat::{StsQueryApiCompatLayer, StsQueryRequest};
|
||||
pub(crate) use virtual_host_style_hint::VirtualHostStyleHintLayer;
|
||||
|
||||
#[cfg(test)]
|
||||
pub(super) use empty_body_content_length_compat::is_empty_body_console_path;
|
||||
#[cfg(test)]
|
||||
pub(super) use object_attributes_etag_fix::is_object_attributes_request;
|
||||
|
||||
use http::HeaderMap;
|
||||
use http_body::Body;
|
||||
|
||||
@@ -1,285 +0,0 @@
|
||||
// Copyright 2024 RustFS Team
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//! `ObjectAttributesEtagFixLayer`: an s3s compatibility patch, installed by
|
||||
//! `server::http::external_service_stack!` and pinned there by `stack_census`.
|
||||
//!
|
||||
//! Patches: s3s renders the `GetObjectAttributes` `<ETag>` quoted, unlike every
|
||||
//! other operation, so the layer parses the response XML to strip the quotes.
|
||||
//! Introduced in rustfs/rustfs#2002.
|
||||
//! Replaced by: the gateway quirk table (`q-mpu-attributes-etag-0036`) first,
|
||||
//! with `OpLayer<GetObjectAttributes>` to override (gateway
|
||||
//! `docs/middleware.md`, "Level 3: `OpLayer<O>`"; "The nine RustFS tower patch
|
||||
//! layers", row 7).
|
||||
//! Removed by: T2.12 (rustfs/backlog#2771).
|
||||
|
||||
use super::{is_xml_compat_body, is_xml_response};
|
||||
use crate::server::hybrid::HybridBody;
|
||||
use crate::server::{
|
||||
ADMIN_PREFIX, MINIO_ADMIN_PREFIX, MINIO_ADMIN_V3_PREFIX, RPC_PREFIX, RUSTFS_ADMIN_PREFIX, console_prefix, has_path_prefix,
|
||||
is_table_catalog_path,
|
||||
};
|
||||
use bytes::Bytes;
|
||||
use http::{Method, Request as HttpRequest, Response};
|
||||
use http_body::Body;
|
||||
use http_body_util::BodyExt;
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
use tower::{Layer, Service};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ObjectAttributesEtagFixLayer;
|
||||
|
||||
impl<S> Layer<S> for ObjectAttributesEtagFixLayer {
|
||||
type Service = ObjectAttributesEtagFixService<S>;
|
||||
|
||||
fn layer(&self, inner: S) -> Self::Service {
|
||||
ObjectAttributesEtagFixService { inner }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ObjectAttributesEtagFixService<S> {
|
||||
inner: S,
|
||||
}
|
||||
|
||||
impl<S, ReqBody, RestBody, GrpcBody> Service<HttpRequest<ReqBody>> for ObjectAttributesEtagFixService<S>
|
||||
where
|
||||
S: Service<HttpRequest<ReqBody>, Response = Response<HybridBody<RestBody, GrpcBody>>> + Clone + Send + 'static,
|
||||
S::Future: Send + 'static,
|
||||
S::Error: Send + 'static,
|
||||
ReqBody: Send + 'static,
|
||||
RestBody: Body<Data = Bytes> + From<Bytes> + Send + 'static,
|
||||
RestBody::Error: Into<S::Error> + Send + 'static,
|
||||
GrpcBody: Send + 'static,
|
||||
{
|
||||
type Response = Response<HybridBody<RestBody, GrpcBody>>;
|
||||
type Error = S::Error;
|
||||
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
|
||||
|
||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
self.inner.poll_ready(cx)
|
||||
}
|
||||
|
||||
fn call(&mut self, req: HttpRequest<ReqBody>) -> Self::Future {
|
||||
let is_target = is_object_attributes_request(&req);
|
||||
let mut inner = self.inner.clone();
|
||||
|
||||
Box::pin(async move {
|
||||
let response = inner.call(req).await?;
|
||||
if !is_target || !response.status().is_success() || !is_xml_response(response.headers()) {
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
let (parts, body) = response.into_parts();
|
||||
|
||||
let response = match body {
|
||||
HybridBody::Rest { rest_body } if !is_xml_compat_body(&rest_body) => {
|
||||
Response::from_parts(parts, HybridBody::Rest { rest_body })
|
||||
}
|
||||
HybridBody::Rest { rest_body } => {
|
||||
let rest_body = fix_object_attributes_etag_in_xml(rest_body).await.map_err(Into::into)?;
|
||||
|
||||
let mut parts = parts;
|
||||
parts.headers.remove(http::header::CONTENT_LENGTH);
|
||||
|
||||
Response::from_parts(parts, HybridBody::Rest { rest_body })
|
||||
}
|
||||
HybridBody::Grpc {
|
||||
grpc_body,
|
||||
first_frame_started,
|
||||
body_started,
|
||||
first_frame_recorded,
|
||||
} => Response::from_parts(
|
||||
parts,
|
||||
HybridBody::Grpc {
|
||||
grpc_body,
|
||||
first_frame_started,
|
||||
body_started,
|
||||
first_frame_recorded,
|
||||
},
|
||||
),
|
||||
};
|
||||
|
||||
Ok(response)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async fn fix_object_attributes_etag_in_xml<RestBody>(body: RestBody) -> Result<RestBody, RestBody::Error>
|
||||
where
|
||||
RestBody: Body<Data = Bytes> + From<Bytes>,
|
||||
{
|
||||
let bytes = BodyExt::collect(body).await?.to_bytes();
|
||||
let xml = String::from_utf8(bytes.to_vec()).unwrap_or_else(|_| String::from_utf8_lossy(&bytes).into_owned());
|
||||
let fixed = strip_quotes_from_first_etag(xml);
|
||||
Ok(RestBody::from(Bytes::from(fixed)))
|
||||
}
|
||||
|
||||
fn strip_quotes_from_first_etag(xml: String) -> String {
|
||||
let Some(start) = xml.find("<ETag>") else {
|
||||
return xml;
|
||||
};
|
||||
let value_start = start + "<ETag>".len();
|
||||
let value_rest = &xml[value_start..];
|
||||
let Some(end_offset) = value_rest.find("</ETag>") else {
|
||||
return xml;
|
||||
};
|
||||
let value_end = value_start + end_offset;
|
||||
let raw = &xml[value_start..value_end];
|
||||
|
||||
let Some(trimmed) = raw.strip_prefix('"').and_then(|v| v.strip_suffix('"')) else {
|
||||
return xml;
|
||||
};
|
||||
|
||||
let mut fixed = String::with_capacity(xml.len() - 2);
|
||||
fixed.push_str(&xml[..value_start]);
|
||||
fixed.push_str(trimmed);
|
||||
fixed.push_str(&xml[value_end..]);
|
||||
fixed
|
||||
}
|
||||
|
||||
pub(in crate::server) fn is_object_attributes_request<B>(req: &HttpRequest<B>) -> bool {
|
||||
if req.method() != Method::GET {
|
||||
return false;
|
||||
}
|
||||
|
||||
let path = req.uri().path();
|
||||
if has_path_prefix(path, ADMIN_PREFIX)
|
||||
|| has_path_prefix(path, MINIO_ADMIN_PREFIX)
|
||||
|| has_path_prefix(path, RUSTFS_ADMIN_PREFIX)
|
||||
|| has_path_prefix(path, MINIO_ADMIN_V3_PREFIX)
|
||||
|| is_table_catalog_path(path)
|
||||
|| has_path_prefix(path, console_prefix())
|
||||
|| has_path_prefix(path, RPC_PREFIX)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
let has_object_attributes_query = req.uri().query().is_some_and(|query| {
|
||||
query.split('&').any(|part| {
|
||||
let (name, _value) = part.split_once('=').unwrap_or((part, ""));
|
||||
matches!(
|
||||
name.to_ascii_lowercase().as_str(),
|
||||
"attributes" | "object-attributes" | "x-amz-object-attributes"
|
||||
)
|
||||
})
|
||||
});
|
||||
let has_object_attributes_header = req
|
||||
.headers()
|
||||
.get(http::header::HeaderName::from_static("x-amz-object-attributes"))
|
||||
.is_some();
|
||||
|
||||
has_object_attributes_query || has_object_attributes_header
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::server::legacy_compat::test_support::{FixedHybridResponse, collect_hybrid_response};
|
||||
use http::Request;
|
||||
use http::StatusCode;
|
||||
use http_body_util::Full;
|
||||
|
||||
#[test]
|
||||
fn test_strip_quotes_from_first_etag_removes_quotes() {
|
||||
let input = String::from("<GetObjectAttributesOutput><ETag>\"abc\"</ETag></GetObjectAttributesOutput>");
|
||||
let output = strip_quotes_from_first_etag(input);
|
||||
|
||||
assert_eq!(output, "<GetObjectAttributesOutput><ETag>abc</ETag></GetObjectAttributesOutput>");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_strip_quotes_from_first_etag_keeps_non_quoted_value() {
|
||||
let input = String::from("<GetObjectAttributesOutput><ETag>abc</ETag></GetObjectAttributesOutput>");
|
||||
let output = strip_quotes_from_first_etag(input.clone());
|
||||
|
||||
assert_eq!(output, input);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_strip_quotes_from_first_etag_only_first_occurrence() {
|
||||
let input =
|
||||
String::from("<GetObjectAttributesOutput><ETag>\"first\"</ETag><ETag>\"second\"</ETag></GetObjectAttributesOutput>");
|
||||
let output = strip_quotes_from_first_etag(input);
|
||||
|
||||
assert_eq!(
|
||||
output,
|
||||
"<GetObjectAttributesOutput><ETag>first</ETag><ETag>\"second\"</ETag></GetObjectAttributesOutput>"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_fix_object_attributes_etag_in_xml() {
|
||||
let body = Full::from(Bytes::from(
|
||||
"<GetObjectAttributesOutput><ETag>\"abc\"</ETag><Checksum>CRC32C</Checksum></GetObjectAttributesOutput>",
|
||||
));
|
||||
let fixed = fix_object_attributes_etag_in_xml(body).await.unwrap();
|
||||
let bytes = BodyExt::collect(fixed).await.unwrap().to_bytes();
|
||||
|
||||
assert_eq!(
|
||||
bytes,
|
||||
Bytes::from_static(
|
||||
b"<GetObjectAttributesOutput><ETag>abc</ETag><Checksum>CRC32C</Checksum></GetObjectAttributesOutput>",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn object_attributes_etag_fix_rewrites_target_response() {
|
||||
let mut service = ObjectAttributesEtagFixLayer.layer(FixedHybridResponse {
|
||||
status: StatusCode::OK,
|
||||
body: Bytes::from_static(b"<GetObjectAttributesOutput><ETag>\"abc\"</ETag></GetObjectAttributesOutput>"),
|
||||
content_type: "application/xml",
|
||||
});
|
||||
let request = Request::builder()
|
||||
.method(Method::GET)
|
||||
.uri("/bucket/object?attributes")
|
||||
.body(())
|
||||
.expect("request");
|
||||
|
||||
let response = service.call(request).await.expect("service response");
|
||||
let (_status, headers, body) = collect_hybrid_response(response).await;
|
||||
|
||||
assert!(headers.get(http::header::CONTENT_LENGTH).is_none());
|
||||
assert!(body.contains("<ETag>abc</ETag>"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn object_attributes_etag_fix_leaves_regular_get_unchanged() {
|
||||
let input = Bytes::from_static(b"<GetObjectAttributesOutput><ETag>\"abc\"</ETag></GetObjectAttributesOutput>");
|
||||
let mut service = ObjectAttributesEtagFixLayer.layer(FixedHybridResponse {
|
||||
status: StatusCode::OK,
|
||||
body: input.clone(),
|
||||
content_type: "application/xml",
|
||||
});
|
||||
let request = Request::builder()
|
||||
.method(Method::GET)
|
||||
.uri("/bucket/object")
|
||||
.body(())
|
||||
.expect("request");
|
||||
|
||||
let response = service.call(request).await.expect("service response");
|
||||
let (_status, headers, body) = collect_hybrid_response(response).await;
|
||||
|
||||
let expected_len = input.len().to_string();
|
||||
assert_eq!(
|
||||
headers
|
||||
.get(http::header::CONTENT_LENGTH)
|
||||
.and_then(|value| value.to_str().ok()),
|
||||
Some(expected_len.as_str())
|
||||
);
|
||||
assert_eq!(body.as_bytes(), input.as_ref());
|
||||
}
|
||||
}
|
||||
@@ -1,236 +0,0 @@
|
||||
// Copyright 2024 RustFS Team
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//! `S3ErrorMessageCompatLayer`: an s3s compatibility patch, installed by
|
||||
//! `server::http::external_service_stack!` and pinned there by `stack_census`.
|
||||
//!
|
||||
//! Patches: s3s renders `SignatureDoesNotMatch` without the `<Message>`
|
||||
//! element that MinIO and AWS clients (the GitLab registry among them) expect.
|
||||
//! Introduced in rustfs/rustfs#2596.
|
||||
//! Replaced by: the gateway dialect's error-render policy first, with
|
||||
//! `StageFilter::on_response` as the per-message escape hatch (gateway
|
||||
//! `docs/middleware.md`, "The nine RustFS tower patch layers", row 6).
|
||||
//! Removed by: T2.12 (rustfs/backlog#2771).
|
||||
|
||||
use super::{StsQueryRequest, is_xml_compat_body, is_xml_response};
|
||||
use crate::error::ApiError;
|
||||
use crate::server::hybrid::HybridBody;
|
||||
use crate::storage_api::server::legacy_compat::S3ErrorCode;
|
||||
use bytes::Bytes;
|
||||
use http::{Method, Request as HttpRequest, Response, StatusCode};
|
||||
use http_body::Body;
|
||||
use http_body_util::BodyExt;
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
use tower::{Layer, Service};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct S3ErrorMessageCompatLayer;
|
||||
|
||||
impl<S> Layer<S> for S3ErrorMessageCompatLayer {
|
||||
type Service = S3ErrorMessageCompatService<S>;
|
||||
|
||||
fn layer(&self, inner: S) -> Self::Service {
|
||||
S3ErrorMessageCompatService { inner }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct S3ErrorMessageCompatService<S> {
|
||||
inner: S,
|
||||
}
|
||||
|
||||
impl<S, ReqBody, RestBody, GrpcBody> Service<HttpRequest<ReqBody>> for S3ErrorMessageCompatService<S>
|
||||
where
|
||||
S: Service<HttpRequest<ReqBody>, Response = Response<HybridBody<RestBody, GrpcBody>>> + Clone + Send + 'static,
|
||||
S::Future: Send + 'static,
|
||||
S::Error: Send + 'static,
|
||||
ReqBody: Send + 'static,
|
||||
RestBody: Body<Data = Bytes> + From<Bytes> + Send + 'static,
|
||||
RestBody::Error: Into<S::Error> + Send + 'static,
|
||||
GrpcBody: Send + 'static,
|
||||
{
|
||||
type Response = Response<HybridBody<RestBody, GrpcBody>>;
|
||||
type Error = S::Error;
|
||||
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
|
||||
|
||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
self.inner.poll_ready(cx)
|
||||
}
|
||||
|
||||
fn call(&mut self, req: HttpRequest<ReqBody>) -> Self::Future {
|
||||
let is_sts_query =
|
||||
req.method() == Method::POST && req.uri().path() == "/" && req.extensions().get::<StsQueryRequest>().is_some();
|
||||
let mut inner = self.inner.clone();
|
||||
|
||||
Box::pin(async move {
|
||||
let response = inner.call(req).await?;
|
||||
if is_sts_query || response.status() != StatusCode::FORBIDDEN || !is_xml_response(response.headers()) {
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
let (parts, body) = response.into_parts();
|
||||
|
||||
let response = match body {
|
||||
HybridBody::Rest { rest_body } if !is_xml_compat_body(&rest_body) => {
|
||||
Response::from_parts(parts, HybridBody::Rest { rest_body })
|
||||
}
|
||||
HybridBody::Rest { rest_body } => {
|
||||
let (rest_body, changed) = fix_s3_error_message_in_xml(rest_body).await.map_err(Into::into)?;
|
||||
let mut parts = parts;
|
||||
if changed {
|
||||
parts.headers.remove(http::header::CONTENT_LENGTH);
|
||||
}
|
||||
Response::from_parts(parts, HybridBody::Rest { rest_body })
|
||||
}
|
||||
HybridBody::Grpc {
|
||||
grpc_body,
|
||||
first_frame_started,
|
||||
body_started,
|
||||
first_frame_recorded,
|
||||
} => Response::from_parts(
|
||||
parts,
|
||||
HybridBody::Grpc {
|
||||
grpc_body,
|
||||
first_frame_started,
|
||||
body_started,
|
||||
first_frame_recorded,
|
||||
},
|
||||
),
|
||||
};
|
||||
|
||||
Ok(response)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async fn fix_s3_error_message_in_xml<RestBody>(body: RestBody) -> Result<(RestBody, bool), RestBody::Error>
|
||||
where
|
||||
RestBody: Body<Data = Bytes> + From<Bytes>,
|
||||
{
|
||||
let bytes = BodyExt::collect(body).await?.to_bytes();
|
||||
let xml = String::from_utf8(bytes.to_vec()).unwrap_or_else(|_| String::from_utf8_lossy(&bytes).into_owned());
|
||||
let (fixed, changed) = insert_missing_signature_error_message(xml);
|
||||
Ok((RestBody::from(Bytes::from(fixed)), changed))
|
||||
}
|
||||
|
||||
fn insert_missing_signature_error_message(mut xml: String) -> (String, bool) {
|
||||
if !xml.contains("<Code>SignatureDoesNotMatch</Code>") || xml.contains("<Message>") {
|
||||
return (xml, false);
|
||||
}
|
||||
|
||||
let Some(code_end) = xml.find("</Code>") else {
|
||||
return (xml, false);
|
||||
};
|
||||
|
||||
let message = ApiError::error_code_to_message(&S3ErrorCode::SignatureDoesNotMatch);
|
||||
xml.insert_str(code_end + "</Code>".len(), &format!("<Message>{message}</Message>"));
|
||||
(xml, true)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::server::legacy_compat::test_support::{FixedHybridResponse, collect_hybrid_response};
|
||||
use http::Request;
|
||||
use http_body_util::Full;
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_fix_s3_error_message_in_xml_reports_changed_body() {
|
||||
let body = Full::from(Bytes::from_static(b"<Error><Code>SignatureDoesNotMatch</Code></Error>"));
|
||||
|
||||
let (fixed, changed) = fix_s3_error_message_in_xml(body).await.unwrap();
|
||||
let bytes = BodyExt::collect(fixed).await.unwrap().to_bytes();
|
||||
|
||||
assert!(changed);
|
||||
assert!(bytes.starts_with(b"<Error><Code>SignatureDoesNotMatch</Code><Message>"));
|
||||
assert!(bytes.ends_with(b"</Message></Error>"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_fix_s3_error_message_in_xml_reports_unchanged_body() {
|
||||
let input = Bytes::from_static(b"<Error><Code>AccessDenied</Code></Error>");
|
||||
let body = Full::from(input.clone());
|
||||
|
||||
let (fixed, changed) = fix_s3_error_message_in_xml(body).await.unwrap();
|
||||
let bytes = BodyExt::collect(fixed).await.unwrap().to_bytes();
|
||||
|
||||
assert!(!changed);
|
||||
assert_eq!(bytes, input);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn s3_error_message_compat_fixes_regular_forbidden_xml() {
|
||||
let body = Bytes::from_static(b"<Error><Code>SignatureDoesNotMatch</Code></Error>");
|
||||
let mut service = S3ErrorMessageCompatLayer.layer(FixedHybridResponse {
|
||||
status: StatusCode::FORBIDDEN,
|
||||
body,
|
||||
content_type: "application/xml",
|
||||
});
|
||||
let request = Request::builder()
|
||||
.method(Method::GET)
|
||||
.uri("/bucket/object")
|
||||
.body(())
|
||||
.expect("request");
|
||||
|
||||
let response = service.call(request).await.expect("service response");
|
||||
let (status, headers, body) = collect_hybrid_response(response).await;
|
||||
|
||||
assert_eq!(status, StatusCode::FORBIDDEN);
|
||||
assert!(headers.get(http::header::CONTENT_LENGTH).is_none());
|
||||
assert!(body.contains("<Message>"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn s3_error_message_compat_leaves_sts_query_response_unchanged() {
|
||||
let input = Bytes::from_static(b"<Error><Code>SignatureDoesNotMatch</Code></Error>");
|
||||
let mut service = S3ErrorMessageCompatLayer.layer(FixedHybridResponse {
|
||||
status: StatusCode::FORBIDDEN,
|
||||
body: input.clone(),
|
||||
content_type: "application/xml",
|
||||
});
|
||||
let mut request = Request::builder().method(Method::POST).uri("/").body(()).expect("request");
|
||||
request.extensions_mut().insert(StsQueryRequest);
|
||||
|
||||
let response = service.call(request).await.expect("service response");
|
||||
let (_status, headers, body) = collect_hybrid_response(response).await;
|
||||
|
||||
let expected_len = input.len().to_string();
|
||||
assert_eq!(
|
||||
headers
|
||||
.get(http::header::CONTENT_LENGTH)
|
||||
.and_then(|value| value.to_str().ok()),
|
||||
Some(expected_len.as_str())
|
||||
);
|
||||
assert_eq!(body.as_bytes(), input.as_ref());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_insert_missing_signature_error_message() {
|
||||
let (fixed, changed) =
|
||||
insert_missing_signature_error_message("<Error><Code>SignatureDoesNotMatch</Code></Error>".to_string());
|
||||
|
||||
assert!(changed);
|
||||
assert!(fixed.contains("<Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided."));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_insert_missing_signature_error_message_preserves_existing_message() {
|
||||
let input = "<Error><Code>SignatureDoesNotMatch</Code><Message>custom</Message></Error>".to_string();
|
||||
let (fixed, changed) = insert_missing_signature_error_message(input.clone());
|
||||
|
||||
assert!(!changed);
|
||||
assert_eq!(fixed, input);
|
||||
}
|
||||
}
|
||||
@@ -1,509 +0,0 @@
|
||||
// Copyright 2024 RustFS Team
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//! `SigV4HeaderGuardLayer`: an s3s compatibility patch, installed by
|
||||
//! `server::http::external_service_stack!` and pinned there by `stack_census`.
|
||||
//!
|
||||
//! Patches: s3s verifies the algorithm token before RustFS's access layer runs,
|
||||
//! so the GHSA-xm99-m3gq-83g8 / GHSA-g8w9-qw9q-fghr rulings on unsigned
|
||||
//! `x-amz-*` headers have to be applied in front of s3s. Introduced in
|
||||
//! rustfs/rustfs#7796.
|
||||
//! Replaced by: the gateway's own SigV4 verifier, whose signed-header
|
||||
//! enforcement (`SignedHeaderSet::parse_and_enforce` in
|
||||
//! `crates/sig/src/signed_headers.rs`) refuses any `x-amz-*` header absent
|
||||
//! from `SignedHeaders` for header and query authentication alike (gateway
|
||||
//! `docs/security-model.md`). This layer is not one of the nine rows of
|
||||
//! `docs/middleware.md`.
|
||||
//! Removed by: T2.12 (rustfs/backlog#2771).
|
||||
|
||||
use super::xml_escape;
|
||||
use crate::server::hybrid::HybridBody;
|
||||
use crate::storage_api::server::legacy_compat::S3Error;
|
||||
use bytes::Bytes;
|
||||
use http::{Request as HttpRequest, Response, StatusCode};
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
use tower::{Layer, Service};
|
||||
|
||||
/// GHSA-xm99-m3gq-83g8 / GHSA-g8w9-qw9q-fghr: enforce the SigV4 unsigned
|
||||
/// `x-amz-*` header rules ahead of s3s dispatch.
|
||||
///
|
||||
/// s3s verifies the claimed algorithm as the first step of its own signature
|
||||
/// flow and answers a swapped algorithm token with `501 NotImplemented` before
|
||||
/// RustFS's access layer (`S3Access::check`) ever runs, so the `AccessDenied`
|
||||
/// rulings of [`crate::auth::reject_unsigned_amz_headers_on_sigv4_request`]
|
||||
/// must be applied here, in front of s3s. Rejections carry the same S3 error
|
||||
/// document the access layer would have produced.
|
||||
#[derive(Clone, Default)]
|
||||
pub struct SigV4HeaderGuardLayer;
|
||||
|
||||
impl<S> Layer<S> for SigV4HeaderGuardLayer {
|
||||
type Service = SigV4HeaderGuardService<S>;
|
||||
|
||||
fn layer(&self, inner: S) -> Self::Service {
|
||||
SigV4HeaderGuardService { inner }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SigV4HeaderGuardService<S> {
|
||||
inner: S,
|
||||
}
|
||||
|
||||
impl<S, ReqBody, RestBody, GrpcBody> Service<HttpRequest<ReqBody>> for SigV4HeaderGuardService<S>
|
||||
where
|
||||
S: Service<HttpRequest<ReqBody>, Response = Response<HybridBody<RestBody, GrpcBody>>> + Clone + Send + 'static,
|
||||
S::Future: Send + 'static,
|
||||
ReqBody: Send + 'static,
|
||||
RestBody: From<Bytes> + Send + 'static,
|
||||
GrpcBody: Send + 'static,
|
||||
{
|
||||
type Response = Response<HybridBody<RestBody, GrpcBody>>;
|
||||
type Error = S::Error;
|
||||
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
|
||||
|
||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
self.inner.poll_ready(cx)
|
||||
}
|
||||
|
||||
fn call(&mut self, req: HttpRequest<ReqBody>) -> Self::Future {
|
||||
match crate::auth::reject_unsigned_amz_headers_on_sigv4_request(req.headers(), req.uri().query()) {
|
||||
Ok(()) => {}
|
||||
Err(error) => {
|
||||
let version = req.version();
|
||||
return Box::pin(async move { Ok(sigv4_header_guard_rejection(version, error)) });
|
||||
}
|
||||
}
|
||||
let mut inner = self.inner.clone();
|
||||
Box::pin(async move { inner.call(req).await })
|
||||
}
|
||||
}
|
||||
|
||||
/// Serialize a header-guard rejection as the S3 error document the access
|
||||
/// layer would have produced for the same rule violation.
|
||||
fn sigv4_header_guard_rejection<RestBody, GrpcBody>(
|
||||
version: http::Version,
|
||||
error: S3Error,
|
||||
) -> Response<HybridBody<RestBody, GrpcBody>>
|
||||
where
|
||||
RestBody: From<Bytes>,
|
||||
{
|
||||
let status = error.status_code().unwrap_or(StatusCode::FORBIDDEN);
|
||||
let message = error.message().unwrap_or_default().to_owned();
|
||||
let body = format!(
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
|
||||
<Error><Code>{code}</Code><Message>{message}</Message></Error>",
|
||||
code = xml_escape(error.code().as_str()),
|
||||
message = xml_escape(&message),
|
||||
);
|
||||
|
||||
let mut builder = Response::builder()
|
||||
.status(status)
|
||||
.header(http::header::CONTENT_TYPE, "application/xml");
|
||||
// This short-circuit path does not drain the request body. For HTTP/1.x, signal
|
||||
// connection close so an undrained body cannot disrupt keep-alive reuse. `Connection`
|
||||
// is a forbidden header in HTTP/2+, so it is only set for HTTP/1.x.
|
||||
if !matches!(version, http::Version::HTTP_2 | http::Version::HTTP_3) {
|
||||
builder = builder.header(http::header::CONNECTION, "close");
|
||||
}
|
||||
builder
|
||||
.body(HybridBody::Rest {
|
||||
rest_body: RestBody::from(Bytes::from(body)),
|
||||
})
|
||||
.expect("failed to build SigV4 header guard rejection response")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::server::layer::tests::CountingHybridService;
|
||||
use http::Method;
|
||||
use http::Request;
|
||||
use http_body_util::{BodyExt, Full};
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
#[tokio::test]
|
||||
async fn sigv4_header_guard_layer_rejects_swapped_algorithm_token_with_access_denied() {
|
||||
let inner = CountingHybridService::default();
|
||||
let calls = inner.calls();
|
||||
let mut service = SigV4HeaderGuardLayer.layer(inner);
|
||||
|
||||
let response = service
|
||||
.call(
|
||||
Request::builder()
|
||||
.method(Method::PUT)
|
||||
.uri("/xm99-private-source/target")
|
||||
.header(
|
||||
"authorization",
|
||||
"OTHER Credential=rustfsadmin/20260914/us-east-1/s3/aws4_request, \
|
||||
SignedHeaders=host;x-amz-content-sha256;x-amz-date, \
|
||||
Signature=00e997a1db4d3b6ee6c26d3f7d3f3fb3b6ee6c26d3f7d3f3fb3b6ee6c26d3f7d",
|
||||
)
|
||||
.header("x-amz-date", "20260914T000000Z")
|
||||
.header("x-amz-content-sha256", "UNSIGNED-PAYLOAD")
|
||||
.header("x-amz-copy-source", "/negative-sigv4-bucket/source")
|
||||
.body(Full::<Bytes>::from(Bytes::new()))
|
||||
.expect("request"),
|
||||
)
|
||||
.await
|
||||
.expect("guard response");
|
||||
|
||||
// The swapped token must be answered with the access-layer ruling
|
||||
// instead of s3s's algorithm 501.
|
||||
assert_eq!(response.status(), StatusCode::FORBIDDEN);
|
||||
assert_eq!(calls.load(Ordering::SeqCst), 0);
|
||||
let body = BodyExt::collect(response.into_body()).await.expect("body").to_bytes();
|
||||
let body = String::from_utf8(body.to_vec()).expect("utf8 body");
|
||||
assert!(body.contains("<Code>AccessDenied</Code>"), "body: {body}");
|
||||
assert!(body.contains("Unsupported SigV4 authorization algorithm"), "body: {body}");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn sigv4_header_guard_layer_rejects_unsigned_copy_source_header() {
|
||||
let inner = CountingHybridService::default();
|
||||
let calls = inner.calls();
|
||||
let mut service = SigV4HeaderGuardLayer.layer(inner);
|
||||
|
||||
let response = service
|
||||
.call(
|
||||
Request::builder()
|
||||
.method(Method::PUT)
|
||||
.uri("/xm99-private-source/target")
|
||||
.header(
|
||||
"authorization",
|
||||
"AWS4-HMAC-SHA256 Credential=rustfsadmin/20260914/us-east-1/s3/aws4_request, \
|
||||
SignedHeaders=host;x-amz-content-sha256;x-amz-date, \
|
||||
Signature=00e997a1db4d3b6ee6c26d3f7d3f3fb3b6ee6c26d3f7d3f3fb3b6ee6c26d3f7d",
|
||||
)
|
||||
.header("x-amz-date", "20260914T000000Z")
|
||||
.header("x-amz-content-sha256", "UNSIGNED-PAYLOAD")
|
||||
.header("x-amz-copy-source", "/negative-sigv4-bucket/source")
|
||||
.body(Full::<Bytes>::from(Bytes::new()))
|
||||
.expect("request"),
|
||||
)
|
||||
.await
|
||||
.expect("guard response");
|
||||
|
||||
assert_eq!(response.status(), StatusCode::FORBIDDEN);
|
||||
assert_eq!(calls.load(Ordering::SeqCst), 0);
|
||||
let body = BodyExt::collect(response.into_body()).await.expect("body").to_bytes();
|
||||
let body = String::from_utf8(body.to_vec()).expect("utf8 body");
|
||||
assert!(body.contains("<Code>AccessDenied</Code>"), "body: {body}");
|
||||
assert!(
|
||||
body.contains("There were headers present in the request which were not signed"),
|
||||
"body: {body}"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn sigv4_header_guard_layer_passes_unsigned_and_signed_envelope_requests_through() {
|
||||
let inner = CountingHybridService::default();
|
||||
let calls = inner.calls();
|
||||
let mut service = SigV4HeaderGuardLayer.layer(inner);
|
||||
|
||||
// Anonymous request: no Authorization header, no presigned query.
|
||||
let response = service
|
||||
.call(
|
||||
Request::builder()
|
||||
.method(Method::GET)
|
||||
.uri("/bucket/key")
|
||||
.body(Full::<Bytes>::from(Bytes::new()))
|
||||
.expect("request"),
|
||||
)
|
||||
.await
|
||||
.expect("inner response");
|
||||
assert_eq!(response.status(), StatusCode::IM_A_TEAPOT);
|
||||
assert_eq!(calls.load(Ordering::SeqCst), 1);
|
||||
|
||||
// Header-signed request whose only x-amz-* headers are the signed envelope.
|
||||
let response = service
|
||||
.call(
|
||||
Request::builder()
|
||||
.method(Method::PUT)
|
||||
.uri("/bucket/key")
|
||||
.header(
|
||||
"authorization",
|
||||
"AWS4-HMAC-SHA256 Credential=rustfsadmin/20260914/us-east-1/s3/aws4_request, \
|
||||
SignedHeaders=host;x-amz-content-sha256;x-amz-date, \
|
||||
Signature=00e997a1db4d3b6ee6c26d3f7d3f3fb3b6ee6c26d3f7d3f3fb3b6ee6c26d3f7d",
|
||||
)
|
||||
.header("x-amz-date", "20260914T000000Z")
|
||||
.header("x-amz-content-sha256", "UNSIGNED-PAYLOAD")
|
||||
.body(Full::<Bytes>::from(Bytes::new()))
|
||||
.expect("request"),
|
||||
)
|
||||
.await
|
||||
.expect("inner response");
|
||||
assert_eq!(response.status(), StatusCode::IM_A_TEAPOT);
|
||||
assert_eq!(calls.load(Ordering::SeqCst), 2);
|
||||
}
|
||||
|
||||
use crate::auth::{hoist_signed_query_params, reject_unsigned_amz_headers_on_presigned_request};
|
||||
use crate::storage_api::server::legacy_compat::S3ErrorCode;
|
||||
use http::header::HeaderName;
|
||||
use http::{HeaderMap, HeaderValue};
|
||||
|
||||
/// A SigV4 presigned query: the presigner moved the request's `x-amz-*`
|
||||
/// headers into it and every parameter is covered by the signature.
|
||||
fn presigned_query(extra: &str) -> String {
|
||||
let mut query =
|
||||
String::from("X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKID%2F20260101%2Fus-east-1%2Fs3%2Faws4_request");
|
||||
query.push_str("&X-Amz-Date=20260101T000000Z&X-Amz-Expires=300&X-Amz-SignedHeaders=host&X-Amz-Signature=deadbeef");
|
||||
query.push('&');
|
||||
query.push_str(extra);
|
||||
query
|
||||
}
|
||||
|
||||
fn hoist(uri_query: &str) -> Result<http::Request<()>, S3Error> {
|
||||
let mut req = Request::builder()
|
||||
.method(Method::PUT)
|
||||
.uri(format!("/bucket/key?{uri_query}"))
|
||||
.body(())
|
||||
.expect("request");
|
||||
let hoisted_query = req.uri().query().map(str::to_owned);
|
||||
hoist_signed_query_params(req.headers_mut(), hoisted_query.as_deref())?;
|
||||
Ok(req)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hoist_restores_presigned_query_metadata_as_headers() {
|
||||
let req = hoist(&presigned_query("x-amz-meta-user-id=u1&x-amz-tagging=project%3Drustfs")).expect("hoist");
|
||||
assert_eq!(req.headers().get("x-amz-meta-user-id").and_then(|v| v.to_str().ok()), Some("u1"));
|
||||
assert!(req.headers().get("x-amz-tagging").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hoist_leaves_typed_request_properties_unchanged() {
|
||||
for name in [
|
||||
"x-amz-object-lock-legal-hold",
|
||||
"x-amz-object-lock-mode",
|
||||
"x-amz-object-lock-retain-until-date",
|
||||
"x-amz-server-side-encryption",
|
||||
"x-amz-storage-class",
|
||||
"x-amz-copy-source",
|
||||
"x-amz-content-sha256",
|
||||
"x-amz-tagging",
|
||||
] {
|
||||
let req = hoist(&presigned_query(&format!("{name}=value"))).expect("metadata hoist");
|
||||
assert!(!req.headers().contains_key(name), "typed property must keep its original path: {name}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hoist_normalizes_parameter_names_like_header_names() {
|
||||
let req = hoist(&presigned_query("X-Amz-Meta-User-Id=u1")).expect("hoist");
|
||||
assert_eq!(req.headers().get("x-amz-meta-user-id").and_then(|v| v.to_str().ok()), Some("u1"));
|
||||
// `HeaderName` is lowercase, so the stored key is the normalized one.
|
||||
assert_eq!(req.headers().keys().map(|name| name.as_str()).collect::<Vec<_>>(), ["x-amz-meta-user-id"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hoist_never_overwrites_a_header_the_client_sent() {
|
||||
let mut req = Request::builder()
|
||||
.method(Method::PUT)
|
||||
.uri(format!("/bucket/key?{}", presigned_query("x-amz-meta-user-id=from-query")))
|
||||
.header("x-amz-meta-user-id", "from-header")
|
||||
.body(())
|
||||
.expect("request");
|
||||
let hoisted_query = req.uri().query().map(str::to_owned);
|
||||
hoist_signed_query_params(req.headers_mut(), hoisted_query.as_deref()).expect("hoist");
|
||||
assert_eq!(req.headers().get("x-amz-meta-user-id").and_then(|v| v.to_str().ok()), Some("from-header"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hoist_skips_sigv4_auth_params_and_non_amz_parameters() {
|
||||
let req = hoist(&presigned_query("versionId=3&x-amz-security-token=token")).expect("hoist");
|
||||
assert!(req.headers().get("x-amz-algorithm").is_none());
|
||||
assert!(req.headers().get("x-amz-credential").is_none());
|
||||
assert!(req.headers().get("x-amz-signature").is_none());
|
||||
assert!(req.headers().get("x-amz-security-token").is_none());
|
||||
assert!(req.headers().get("versionId").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hoist_ignores_a_sigv2_upload_that_only_claims_sigv4_markers() {
|
||||
// The SigV2 string-to-sign does not cover arbitrary query parameters,
|
||||
// so appending the SigV4 presign markers leaves the original signature
|
||||
// valid while making the query look signed. A URL holder must not be
|
||||
// able to turn on archive extraction that way.
|
||||
let mut query = String::from("AWSAccessKeyId=AKID&Expires=1893456000&Signature=deadbeef");
|
||||
query.push_str("&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKID&X-Amz-Signature=deadbeef");
|
||||
query.push_str("&x-amz-meta-snowball-auto-extract=true&x-amz-meta-user-id=u1");
|
||||
let req = hoist(&query).expect("hoist");
|
||||
assert!(req.headers().get("x-amz-meta-snowball-auto-extract").is_none());
|
||||
assert!(req.headers().get("x-amz-meta-user-id").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hoist_requires_the_complete_presign_marker_set() {
|
||||
// A lone marker is not a presigned request; `X-Amz-Signature` alone is
|
||||
// what the unsigned-header guard keys on, not proof of presigning.
|
||||
let req = hoist("X-Amz-Signature=deadbeef&x-amz-meta-user-id=u1").expect("hoist");
|
||||
assert!(req.headers().get("x-amz-meta-user-id").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hoist_preserves_an_explicit_false_extraction_header() {
|
||||
// Header precedence: a client that says `false` in a header must not be
|
||||
// overruled by the hoisted form of the same key.
|
||||
let mut req = Request::builder()
|
||||
.method(Method::PUT)
|
||||
.uri(format!("/bucket/key?{}", presigned_query("x-amz-meta-snowball-auto-extract=true")))
|
||||
.header("x-amz-meta-snowball-auto-extract", "false")
|
||||
.body(())
|
||||
.expect("request");
|
||||
let hoisted_query = req.uri().query().map(str::to_owned);
|
||||
hoist_signed_query_params(req.headers_mut(), hoisted_query.as_deref()).expect("hoist");
|
||||
assert_eq!(
|
||||
req.headers()
|
||||
.get("x-amz-meta-snowball-auto-extract")
|
||||
.and_then(|v| v.to_str().ok()),
|
||||
Some("false")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hoist_ignores_a_query_the_signature_does_not_cover() {
|
||||
// SigV2 signs headers plus a fixed subresource list, not arbitrary
|
||||
// query parameters; honoring them would widen a presigned upload.
|
||||
let req = hoist("AWSAccessKeyId=AKID&Signature=deadbeef&x-amz-meta-user-id=u1").expect("hoist");
|
||||
assert!(req.headers().get("x-amz-meta-user-id").is_none());
|
||||
|
||||
// Anonymous: no signature at all.
|
||||
let req = hoist("x-amz-meta-user-id=u1").expect("hoist");
|
||||
assert!(req.headers().get("x-amz-meta-user-id").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hoist_restores_params_on_a_header_signed_sigv4_request() {
|
||||
let mut req = Request::builder()
|
||||
.method(Method::PUT)
|
||||
.uri("/bucket/key?x-amz-meta-user-id=u1")
|
||||
.header(
|
||||
"authorization",
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/s3/aws4_request, SignedHeaders=host, Signature=deadbeef",
|
||||
)
|
||||
.body(())
|
||||
.expect("request");
|
||||
let hoisted_query = req.uri().query().map(str::to_owned);
|
||||
hoist_signed_query_params(req.headers_mut(), hoisted_query.as_deref()).expect("hoist");
|
||||
assert_eq!(req.headers().get("x-amz-meta-user-id").and_then(|v| v.to_str().ok()), Some("u1"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hoist_rejects_names_and_values_that_could_not_be_headers() {
|
||||
// A stored control character would make the read path fail every
|
||||
// HeadObject of that object.
|
||||
let err = hoist(&presigned_query("x-amz-meta-user-id=a%0d%0ab")).expect_err("control char");
|
||||
assert_eq!(err.code(), &S3ErrorCode::InvalidArgument);
|
||||
|
||||
let err = hoist(&presigned_query("x-amz-meta-bad%20key=v")).expect_err("bad name");
|
||||
assert_eq!(err.code(), &S3ErrorCode::InvalidArgument);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hoist_rejects_duplicate_parameters_after_name_normalization() {
|
||||
let err = hoist(&presigned_query("x-amz-meta-User-Id=1&x-amz-meta-user-id=2")).expect_err("duplicate");
|
||||
assert_eq!(err.code(), &S3ErrorCode::InvalidArgument);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hoisted_metadata_matches_the_header_path_exactly() {
|
||||
let req = hoist(&presigned_query("x-amz-meta-user-id=u1&x-amz-meta-content-type=custom")).expect("hoist");
|
||||
let mut from_query = HeaderMap::new();
|
||||
for name in ["x-amz-meta-user-id", "x-amz-meta-content-type"] {
|
||||
from_query.insert(HeaderName::from_static(name), req.headers().get(name).expect("hoisted header").clone());
|
||||
}
|
||||
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert("x-amz-meta-user-id", HeaderValue::from_static("u1"));
|
||||
headers.insert("x-amz-meta-content-type", HeaderValue::from_static("custom"));
|
||||
assert_eq!(from_query, headers);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn hoist_then_guard_accepts_a_valid_metadata_bearing_presigned_put() {
|
||||
// The AWS SDK presigner emits `SignedHeaders=host` and moves
|
||||
// `x-amz-content-sha256` and `x-amz-meta-*` into the query. Only the
|
||||
// metadata is restored as headers; the digest keeps its dedicated
|
||||
// query verification path. The guard accepts the signed metadata.
|
||||
let inner = CountingHybridService::default();
|
||||
let calls = inner.calls();
|
||||
let mut service = SigV4HeaderGuardLayer.layer(inner);
|
||||
|
||||
let mut query =
|
||||
String::from("X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKID%2F20261103%2Fus-east-1%2Fs3%2Faws4_request");
|
||||
query.push_str("&X-Amz-Date=20261103T000000Z&X-Amz-Expires=300&X-Amz-SignedHeaders=host&X-Amz-Signature=deadbeef");
|
||||
query.push_str("&x-amz-content-sha256=UNSIGNED-PAYLOAD&x-amz-meta-user-id=u1");
|
||||
|
||||
let mut request = Request::builder()
|
||||
.method(Method::PUT)
|
||||
.uri(format!("/repro/bucket/meta-query.csv?{query}"))
|
||||
.header("content-type", "text/csv")
|
||||
.body(Full::<Bytes>::from(Bytes::new()))
|
||||
.expect("request");
|
||||
// The authorization boundary hoists the signed query properties before
|
||||
// the handler and before RustFS's own unsigned-header guard re-runs.
|
||||
let hoisted_query = request.uri().query().map(str::to_owned);
|
||||
hoist_signed_query_params(request.headers_mut(), hoisted_query.as_deref()).expect("hoist");
|
||||
|
||||
let response = service.call(request).await.expect("inner response");
|
||||
|
||||
let status = response.status();
|
||||
let body = BodyExt::collect(response.into_body()).await.expect("body").to_bytes();
|
||||
let body = String::from_utf8(body.to_vec()).expect("utf8 body");
|
||||
assert_eq!(calls.load(Ordering::SeqCst), 1, "status={status} body={body}");
|
||||
assert_eq!(status, StatusCode::IM_A_TEAPOT, "body={body}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hoist_rejects_a_control_character_value_with_invalid_argument() {
|
||||
let err = hoist(&presigned_query("x-amz-meta-user-id=a%0d%0ab")).expect_err("control char");
|
||||
assert_eq!(err.code(), &S3ErrorCode::InvalidArgument);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn sigv4_header_guard_accepts_a_header_that_matches_a_signed_query_value() {
|
||||
// The hoist layer restores `?x-amz-meta-user-id=u1` as a header before
|
||||
// the access boundary re-runs this rule; the value it carries is the one
|
||||
// the signature covers.
|
||||
let uri = format!("/bucket/key?{}", presigned_query("x-amz-meta-user-id=u1"));
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert("x-amz-meta-user-id", HeaderValue::from_static("u1"));
|
||||
assert!(reject_unsigned_amz_headers_on_presigned_request(&headers, Some(uri.split('?').nth(1).unwrap())).is_ok());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn sigv4_header_guard_still_rejects_an_unsigned_header() {
|
||||
let uri = format!("/bucket/key?{}", presigned_query("x-amz-meta-user-id=u1"));
|
||||
let query = uri.split('?').nth(1).unwrap();
|
||||
|
||||
// Same name, different value: the signer did not authorize it.
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert("x-amz-meta-user-id", HeaderValue::from_static("evil"));
|
||||
assert!(reject_unsigned_amz_headers_on_presigned_request(&headers, Some(query)).is_err());
|
||||
|
||||
// No such parameter at all.
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert("x-amz-meta-other", HeaderValue::from_static("v"));
|
||||
assert!(reject_unsigned_amz_headers_on_presigned_request(&headers, Some(query)).is_err());
|
||||
|
||||
// Multi-valued: the hoist layer never produces one, and the extra value
|
||||
// is unsigned.
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.append("x-amz-meta-user-id", HeaderValue::from_static("u1"));
|
||||
headers.append("x-amz-meta-user-id", HeaderValue::from_static("evil"));
|
||||
assert!(reject_unsigned_amz_headers_on_presigned_request(&headers, Some(query)).is_err());
|
||||
}
|
||||
}
|
||||
@@ -1,342 +0,0 @@
|
||||
// Copyright 2024 RustFS Team
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//! `VirtualHostStyleHintLayer`: an s3s compatibility patch, installed by
|
||||
//! `server::http::external_service_stack!` when no server domain is
|
||||
//! configured, and pinned there by `stack_census`.
|
||||
//!
|
||||
//! Patches: with no domain configured, s3s parses a virtual-hosted-style
|
||||
//! `PUT /` as path-style with an empty bucket and answers an unreadable `501`.
|
||||
//! Introduced in rustfs/rustfs#3442.
|
||||
//! Replaced by: the gateway `HostResolver`'s diagnostic, which replaces the
|
||||
//! message and nothing else (gateway `docs/middleware.md`, "The nine RustFS
|
||||
//! tower patch layers", row 4).
|
||||
//! Removed by: T2.12 (rustfs/backlog#2771).
|
||||
|
||||
use super::xml_escape;
|
||||
use crate::server::hybrid::HybridBody;
|
||||
use crate::server::layer::{LOG_COMPONENT_SERVER, LOG_SUBSYSTEM_HTTP};
|
||||
use bytes::Bytes;
|
||||
use http::{HeaderMap, Method, Request as HttpRequest, Response, StatusCode, Uri};
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
use tower::{Layer, Service};
|
||||
use tracing::debug;
|
||||
|
||||
/// Structured-log event emitted when a virtual-hosted-style request cannot be
|
||||
/// routed because no server domain is configured.
|
||||
const VIRTUAL_HOST_STYLE_UNROUTABLE_EVENT: &str = "virtual_host_style_unroutable";
|
||||
|
||||
/// Detects S3 requests that can only be virtual-hosted-style yet cannot be routed
|
||||
/// because no server domain is configured (`RUSTFS_SERVER_DOMAINS` unset).
|
||||
///
|
||||
/// Without a configured domain, s3s parses every request as path-style, so a
|
||||
/// virtual-hosted-style `PUT /` (the AWS SDK / Terraform default for `CreateBucket`)
|
||||
/// arrives with an empty bucket and fails with an opaque `501 NotImplemented`.
|
||||
///
|
||||
/// Only the service root (`/`) with a method that has no path-style equivalent
|
||||
/// (`PUT`/`DELETE`) and a DNS-style host (not an IP/socket address, and dotted like
|
||||
/// `bucket.example.com`) is matched. The host is read from the `Host` header
|
||||
/// (HTTP/1.1) or the request URI authority (HTTP/2 `:authority`). Such requests
|
||||
/// already fail today, so returning a clearer error never changes the outcome of a
|
||||
/// routable request. Returns the request host (without port) when matched.
|
||||
fn unroutable_virtual_host_target(method: &Method, uri: &Uri, headers: &HeaderMap) -> Option<String> {
|
||||
if *method != Method::PUT && *method != Method::DELETE {
|
||||
return None;
|
||||
}
|
||||
if uri.path() != "/" {
|
||||
return None;
|
||||
}
|
||||
|
||||
// `Host` is set for HTTP/1.1; HTTP/2 carries the host in the URI authority.
|
||||
let raw_authority = match headers.get(http::header::HOST).and_then(|value| value.to_str().ok()) {
|
||||
Some(value) => value,
|
||||
None => uri.authority().map(|authority| authority.as_str())?,
|
||||
};
|
||||
if raw_authority.is_empty() {
|
||||
return None;
|
||||
}
|
||||
// IP / socket-address hosts always use path-style addressing in s3s.
|
||||
if rustfs_utils::is_socket_addr(raw_authority) {
|
||||
return None;
|
||||
}
|
||||
// Parse as an Authority to split host/port robustly (e.g. bracketed IPv6) rather
|
||||
// than slicing on `:`.
|
||||
let authority = raw_authority.parse::<http::uri::Authority>().ok()?;
|
||||
let host = authority.host();
|
||||
// Require a dotted DNS name (the shape of a virtual-hosted bucket subdomain).
|
||||
if !host.contains('.') || host.starts_with('.') || host.ends_with('.') {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(host.to_owned())
|
||||
}
|
||||
|
||||
fn build_virtual_host_hint_response<RestBody, GrpcBody>(
|
||||
version: http::Version,
|
||||
host: &str,
|
||||
resource: &str,
|
||||
) -> Response<HybridBody<RestBody, GrpcBody>>
|
||||
where
|
||||
RestBody: From<Bytes>,
|
||||
{
|
||||
let message = format!(
|
||||
"Virtual-hosted-style request for host '{host}' could not be routed because no server domain is \
|
||||
configured. Set RUSTFS_SERVER_DOMAINS to the S3 endpoint domain your buckets are addressed under \
|
||||
(for example RUSTFS_SERVER_DOMAINS=s3.example.com, so that bucket.s3.example.com routes to bucket \
|
||||
'bucket'), or configure your S3 client to use path-style addressing (AWS SDK: force_path_style=true; \
|
||||
Terraform aws provider: s3_use_path_style = true)."
|
||||
);
|
||||
let body = format!(
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
|
||||
<Error><Code>NotImplemented</Code><Message>{message}</Message><Resource>{resource}</Resource></Error>",
|
||||
message = xml_escape(&message),
|
||||
resource = xml_escape(resource),
|
||||
);
|
||||
|
||||
let mut builder = Response::builder()
|
||||
.status(StatusCode::NOT_IMPLEMENTED)
|
||||
.header(http::header::CONTENT_TYPE, "application/xml");
|
||||
// This short-circuit path does not drain the request body. For HTTP/1.x, signal
|
||||
// connection close so an undrained body cannot disrupt keep-alive reuse. `Connection`
|
||||
// is a forbidden header in HTTP/2+, so it is only set for HTTP/1.x.
|
||||
if !matches!(version, http::Version::HTTP_2 | http::Version::HTTP_3) {
|
||||
builder = builder.header(http::header::CONNECTION, "close");
|
||||
}
|
||||
builder
|
||||
.body(HybridBody::Rest {
|
||||
rest_body: RestBody::from(Bytes::from(body)),
|
||||
})
|
||||
.expect("failed to build virtual-host hint response")
|
||||
}
|
||||
|
||||
/// Returns an actionable error for virtual-hosted-style S3 requests that cannot be
|
||||
/// routed because `RUSTFS_SERVER_DOMAINS` is not configured. See
|
||||
/// [`unroutable_virtual_host_target`]. The layer is only installed when no server
|
||||
/// domain is configured, so it is a pure pass-through for every routable request.
|
||||
#[derive(Clone)]
|
||||
pub struct VirtualHostStyleHintLayer;
|
||||
|
||||
impl<S> Layer<S> for VirtualHostStyleHintLayer {
|
||||
type Service = VirtualHostStyleHintService<S>;
|
||||
|
||||
fn layer(&self, inner: S) -> Self::Service {
|
||||
VirtualHostStyleHintService { inner }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct VirtualHostStyleHintService<S> {
|
||||
inner: S,
|
||||
}
|
||||
|
||||
impl<S, ReqBody, RestBody, GrpcBody> Service<HttpRequest<ReqBody>> for VirtualHostStyleHintService<S>
|
||||
where
|
||||
S: Service<HttpRequest<ReqBody>, Response = Response<HybridBody<RestBody, GrpcBody>>> + Clone + Send + 'static,
|
||||
S::Future: Send + 'static,
|
||||
ReqBody: Send + 'static,
|
||||
RestBody: From<Bytes> + Send + 'static,
|
||||
GrpcBody: Send + 'static,
|
||||
{
|
||||
type Response = Response<HybridBody<RestBody, GrpcBody>>;
|
||||
type Error = S::Error;
|
||||
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
|
||||
|
||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
self.inner.poll_ready(cx)
|
||||
}
|
||||
|
||||
fn call(&mut self, req: HttpRequest<ReqBody>) -> Self::Future {
|
||||
if let Some(host) = unroutable_virtual_host_target(req.method(), req.uri(), req.headers()) {
|
||||
let resource = req.uri().path().to_owned();
|
||||
let version = req.version();
|
||||
debug!(
|
||||
event = VIRTUAL_HOST_STYLE_UNROUTABLE_EVENT,
|
||||
component = LOG_COMPONENT_SERVER,
|
||||
subsystem = LOG_SUBSYSTEM_HTTP,
|
||||
host = %host,
|
||||
method = %req.method(),
|
||||
"Rejected virtual-hosted-style request: no server domain configured (set RUSTFS_SERVER_DOMAINS or use path-style)"
|
||||
);
|
||||
return Box::pin(async move { Ok(build_virtual_host_hint_response(version, &host, &resource)) });
|
||||
}
|
||||
|
||||
let mut inner = self.inner.clone();
|
||||
Box::pin(async move { inner.call(req).await })
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::server::layer::tests::CountingHybridService;
|
||||
use http::HeaderValue;
|
||||
use http::Request;
|
||||
use http_body_util::{BodyExt, Full};
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
#[test]
|
||||
fn unroutable_virtual_host_target_matches_service_root_writes() {
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert(http::header::HOST, HeaderValue::from_static("my-bucket.s3.example.com"));
|
||||
assert_eq!(
|
||||
unroutable_virtual_host_target(&Method::PUT, &Uri::from_static("/"), &headers),
|
||||
Some("my-bucket.s3.example.com".to_owned())
|
||||
);
|
||||
assert_eq!(
|
||||
unroutable_virtual_host_target(&Method::DELETE, &Uri::from_static("/"), &headers),
|
||||
Some("my-bucket.s3.example.com".to_owned())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unroutable_virtual_host_target_strips_port() {
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert(http::header::HOST, HeaderValue::from_static("bucket.localhost:9000"));
|
||||
assert_eq!(
|
||||
unroutable_virtual_host_target(&Method::PUT, &Uri::from_static("/"), &headers),
|
||||
Some("bucket.localhost".to_owned())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unroutable_virtual_host_target_uses_uri_authority_when_host_header_absent() {
|
||||
// HTTP/2 clients carry the host in the URI authority (`:authority`) rather than a Host header.
|
||||
let uri = Uri::from_static("https://my-bucket.s3.example.com/");
|
||||
assert_eq!(
|
||||
unroutable_virtual_host_target(&Method::PUT, &uri, &HeaderMap::new()),
|
||||
Some("my-bucket.s3.example.com".to_owned())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unroutable_virtual_host_target_ignores_non_matching_requests() {
|
||||
let mut vhost = HeaderMap::new();
|
||||
vhost.insert(http::header::HOST, HeaderValue::from_static("bucket.s3.example.com"));
|
||||
// Path-style request carries the bucket in the path.
|
||||
assert_eq!(unroutable_virtual_host_target(&Method::PUT, &Uri::from_static("/bucket"), &vhost), None);
|
||||
// GET / is ListBuckets, a valid path-style service call.
|
||||
assert_eq!(unroutable_virtual_host_target(&Method::GET, &Uri::from_static("/"), &vhost), None);
|
||||
|
||||
// IP / socket-address hosts always use path-style addressing.
|
||||
let mut ip = HeaderMap::new();
|
||||
ip.insert(http::header::HOST, HeaderValue::from_static("127.0.0.1:9000"));
|
||||
assert_eq!(unroutable_virtual_host_target(&Method::PUT, &Uri::from_static("/"), &ip), None);
|
||||
|
||||
// Bracketed IPv6 authority (with port) is a socket address, not a bucket subdomain.
|
||||
let mut ipv6 = HeaderMap::new();
|
||||
ipv6.insert(http::header::HOST, HeaderValue::from_static("[::1]:9000"));
|
||||
assert_eq!(unroutable_virtual_host_target(&Method::PUT, &Uri::from_static("/"), &ipv6), None);
|
||||
|
||||
// Bare single-label hosts are not virtual-hosted bucket subdomains.
|
||||
let mut bare = HeaderMap::new();
|
||||
bare.insert(http::header::HOST, HeaderValue::from_static("localhost:9000"));
|
||||
assert_eq!(unroutable_virtual_host_target(&Method::PUT, &Uri::from_static("/"), &bare), None);
|
||||
|
||||
// Trailing-dot FQDN is not matched (avoids suggesting a domain with a trailing dot).
|
||||
let mut fqdn = HeaderMap::new();
|
||||
fqdn.insert(http::header::HOST, HeaderValue::from_static("bucket.example.com."));
|
||||
assert_eq!(unroutable_virtual_host_target(&Method::PUT, &Uri::from_static("/"), &fqdn), None);
|
||||
|
||||
// Missing Host header and no URI authority.
|
||||
assert_eq!(
|
||||
unroutable_virtual_host_target(&Method::PUT, &Uri::from_static("/"), &HeaderMap::new()),
|
||||
None
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn build_virtual_host_hint_response_is_actionable() {
|
||||
let response: Response<HybridBody<Full<Bytes>, Full<Bytes>>> =
|
||||
build_virtual_host_hint_response(http::Version::HTTP_11, "my-bucket.s3.example.com", "/");
|
||||
assert_eq!(response.status(), StatusCode::NOT_IMPLEMENTED);
|
||||
assert_eq!(
|
||||
response
|
||||
.headers()
|
||||
.get(http::header::CONTENT_TYPE)
|
||||
.and_then(|value| value.to_str().ok()),
|
||||
Some("application/xml")
|
||||
);
|
||||
// HTTP/1.x error responses close the connection (the request body is not drained).
|
||||
assert_eq!(
|
||||
response
|
||||
.headers()
|
||||
.get(http::header::CONNECTION)
|
||||
.and_then(|value| value.to_str().ok()),
|
||||
Some("close")
|
||||
);
|
||||
|
||||
// `Connection` is forbidden in HTTP/2, so it must not be set there.
|
||||
let h2_response: Response<HybridBody<Full<Bytes>, Full<Bytes>>> =
|
||||
build_virtual_host_hint_response(http::Version::HTTP_2, "my-bucket.s3.example.com", "/");
|
||||
assert!(h2_response.headers().get(http::header::CONNECTION).is_none());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn virtual_host_style_hint_layer_short_circuits_unroutable_put() {
|
||||
let inner = CountingHybridService::default();
|
||||
let calls = inner.calls();
|
||||
let mut service = VirtualHostStyleHintLayer.layer(inner);
|
||||
|
||||
let response = service
|
||||
.call(
|
||||
Request::builder()
|
||||
.method(Method::PUT)
|
||||
.uri("/")
|
||||
.header(http::header::HOST, "my-bucket.s3.example.com")
|
||||
.body(Full::<Bytes>::from(Bytes::new()))
|
||||
.expect("request"),
|
||||
)
|
||||
.await
|
||||
.expect("hint response");
|
||||
|
||||
assert_eq!(response.status(), StatusCode::NOT_IMPLEMENTED);
|
||||
assert_eq!(calls.load(Ordering::SeqCst), 0);
|
||||
assert_eq!(
|
||||
response
|
||||
.headers()
|
||||
.get(http::header::CONNECTION)
|
||||
.and_then(|value| value.to_str().ok()),
|
||||
Some("close")
|
||||
);
|
||||
|
||||
let body = BodyExt::collect(response.into_body()).await.expect("body").to_bytes();
|
||||
let body = String::from_utf8(body.to_vec()).expect("utf8 body");
|
||||
assert!(body.contains("RUSTFS_SERVER_DOMAINS=s3.example.com"));
|
||||
assert!(body.contains("s3_use_path_style"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn virtual_host_style_hint_layer_passes_through_path_style() {
|
||||
let inner = CountingHybridService::default();
|
||||
let calls = inner.calls();
|
||||
let mut service = VirtualHostStyleHintLayer.layer(inner);
|
||||
|
||||
let response = service
|
||||
.call(
|
||||
Request::builder()
|
||||
.method(Method::PUT)
|
||||
.uri("/my-bucket")
|
||||
.header(http::header::HOST, "s3.example.com")
|
||||
.body(Full::<Bytes>::from(Bytes::new()))
|
||||
.expect("request"),
|
||||
)
|
||||
.await
|
||||
.expect("inner response");
|
||||
|
||||
// Path-style request reaches the inner service unchanged.
|
||||
assert_eq!(response.status(), StatusCode::IM_A_TEAPOT);
|
||||
assert_eq!(calls.load(Ordering::SeqCst), 1);
|
||||
}
|
||||
}
|
||||
@@ -16,9 +16,7 @@ mod audit;
|
||||
mod compress;
|
||||
pub mod cors;
|
||||
mod event;
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
mod gateway_handlers;
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
mod gateway_stack;
|
||||
mod health;
|
||||
mod http;
|
||||
@@ -26,6 +24,7 @@ mod hybrid;
|
||||
mod layer;
|
||||
mod legacy_compat;
|
||||
mod module_switch;
|
||||
mod post_object_location;
|
||||
mod prefix;
|
||||
pub mod rate_limit;
|
||||
mod readiness;
|
||||
@@ -33,7 +32,6 @@ mod runtime;
|
||||
pub(crate) mod runtime_sources;
|
||||
mod service_state;
|
||||
mod ssec_transport;
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
mod stack;
|
||||
pub mod tls_material;
|
||||
pub(crate) mod tls_publish;
|
||||
@@ -83,7 +81,6 @@ pub use layer::s3_http_request_guard;
|
||||
pub(crate) use layer::{RequestContextLayer, is_control_plane_route, is_sts_query_request};
|
||||
|
||||
/// The S3 operations the gateway stack serves.
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
pub(crate) fn gateway_operations() -> Vec<&'static str> {
|
||||
gateway_handlers::rows(gateway_handlers::OPERATIONS)
|
||||
.map(|row| row.name)
|
||||
|
||||
@@ -0,0 +1,397 @@
|
||||
// Copyright 2026 RustFS Team
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! POST Object `PostResponse` Location rewrite for AWS-compatible absolute URIs.
|
||||
//!
|
||||
//! Both protocol stacks currently emit a relative, unencoded path
|
||||
//! (`/{bucket}/{raw-key}`) when `success_action_status=201`. The s3s serializer
|
||||
//! hard-codes that spelling, and the gateway's RustFS-profile POST forms path
|
||||
//! does the same. This layer rebuilds `<Location>` from the response's `<Bucket>`
|
||||
//! and `<Key>` plus the request's host, scheme, and addressing style.
|
||||
//!
|
||||
//! Encoding follows RFC 3986 path rules (spaces as `%20`, `/` left as a
|
||||
//! separator, uppercase hex), matching MinIO's `getObjectLocation` and the
|
||||
//! gateway's non-legacy POST serializer. `<Key>` is left unchanged.
|
||||
|
||||
use crate::server::hybrid::HybridBody;
|
||||
use crate::server::legacy_compat::MAX_XML_COMPAT_BODY_BYTES;
|
||||
use crate::server::rate_limit::virtual_host_bucket;
|
||||
use bytes::Bytes;
|
||||
use http::{HeaderMap, Method, Request as HttpRequest, Response, StatusCode, Uri, header};
|
||||
use http_body::Body;
|
||||
use http_body_util::BodyExt;
|
||||
use rustfs_utils::http::get_source_scheme;
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
use std::task::{Context, Poll};
|
||||
use tower::{Layer, Service};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct PostObjectLocationFixLayer {
|
||||
vh_domain_hosts: Arc<[String]>,
|
||||
connection_is_tls: bool,
|
||||
}
|
||||
|
||||
impl PostObjectLocationFixLayer {
|
||||
pub fn new(vh_domain_hosts: Arc<[String]>, connection_is_tls: bool) -> Self {
|
||||
Self {
|
||||
vh_domain_hosts,
|
||||
connection_is_tls,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> Layer<S> for PostObjectLocationFixLayer {
|
||||
type Service = PostObjectLocationFixService<S>;
|
||||
|
||||
fn layer(&self, inner: S) -> Self::Service {
|
||||
PostObjectLocationFixService {
|
||||
inner,
|
||||
vh_domain_hosts: self.vh_domain_hosts.clone(),
|
||||
connection_is_tls: self.connection_is_tls,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct PostObjectLocationFixService<S> {
|
||||
inner: S,
|
||||
vh_domain_hosts: Arc<[String]>,
|
||||
connection_is_tls: bool,
|
||||
}
|
||||
|
||||
impl<S, ReqBody, RestBody, GrpcBody> Service<HttpRequest<ReqBody>> for PostObjectLocationFixService<S>
|
||||
where
|
||||
S: Service<HttpRequest<ReqBody>, Response = Response<HybridBody<RestBody, GrpcBody>>> + Clone + Send + 'static,
|
||||
S::Future: Send + 'static,
|
||||
S::Error: Send + 'static,
|
||||
ReqBody: Send + 'static,
|
||||
RestBody: Body<Data = Bytes> + From<Bytes> + Send + 'static,
|
||||
RestBody::Error: Into<S::Error> + Send + 'static,
|
||||
GrpcBody: Send + 'static,
|
||||
{
|
||||
type Response = Response<HybridBody<RestBody, GrpcBody>>;
|
||||
type Error = S::Error;
|
||||
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
|
||||
|
||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
self.inner.poll_ready(cx)
|
||||
}
|
||||
|
||||
fn call(&mut self, req: HttpRequest<ReqBody>) -> Self::Future {
|
||||
let should_inspect = req.method() == Method::POST;
|
||||
let scheme = request_scheme(req.headers(), req.uri(), self.connection_is_tls);
|
||||
let host = request_host(req.headers(), req.uri()).map(str::to_owned);
|
||||
let virtual_hosted_bucket = virtual_host_bucket(&req, &self.vh_domain_hosts).map(str::to_owned);
|
||||
let mut inner = self.inner.clone();
|
||||
|
||||
Box::pin(async move {
|
||||
let response = inner.call(req).await?;
|
||||
if !should_inspect || response.status() != StatusCode::CREATED || !is_xml_content_type(response.headers()) {
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
let (parts, body) = response.into_parts();
|
||||
let response = match body {
|
||||
HybridBody::Rest { rest_body } if !is_bounded_xml_body(&rest_body) => {
|
||||
Response::from_parts(parts, HybridBody::Rest { rest_body })
|
||||
}
|
||||
HybridBody::Rest { rest_body } => {
|
||||
let rest_body = rewrite_location_body(rest_body, &scheme, host.as_deref(), virtual_hosted_bucket.as_deref())
|
||||
.await
|
||||
.map_err(Into::into)?;
|
||||
let mut parts = parts;
|
||||
parts.headers.remove(header::CONTENT_LENGTH);
|
||||
Response::from_parts(parts, HybridBody::Rest { rest_body })
|
||||
}
|
||||
HybridBody::Grpc {
|
||||
grpc_body,
|
||||
first_frame_started,
|
||||
body_started,
|
||||
first_frame_recorded,
|
||||
} => Response::from_parts(
|
||||
parts,
|
||||
HybridBody::Grpc {
|
||||
grpc_body,
|
||||
first_frame_started,
|
||||
body_started,
|
||||
first_frame_recorded,
|
||||
},
|
||||
),
|
||||
};
|
||||
Ok(response)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async fn rewrite_location_body<RestBody>(
|
||||
body: RestBody,
|
||||
scheme: &str,
|
||||
host: Option<&str>,
|
||||
virtual_hosted_bucket: Option<&str>,
|
||||
) -> Result<RestBody, RestBody::Error>
|
||||
where
|
||||
RestBody: Body<Data = Bytes> + From<Bytes>,
|
||||
{
|
||||
let bytes = BodyExt::collect(body).await?.to_bytes();
|
||||
let xml = String::from_utf8(bytes.to_vec()).unwrap_or_else(|_| String::from_utf8_lossy(&bytes).into_owned());
|
||||
match rewrite_post_response_location(&xml, scheme, host, virtual_hosted_bucket) {
|
||||
Some(fixed) => Ok(RestBody::from(Bytes::from(fixed))),
|
||||
None => Ok(RestBody::from(Bytes::from(xml))),
|
||||
}
|
||||
}
|
||||
|
||||
fn is_bounded_xml_body<B: Body>(body: &B) -> bool {
|
||||
body.size_hint()
|
||||
.upper()
|
||||
.is_some_and(|length| length <= MAX_XML_COMPAT_BODY_BYTES)
|
||||
}
|
||||
|
||||
fn is_xml_content_type(headers: &HeaderMap) -> bool {
|
||||
let is_xml = headers
|
||||
.get(header::CONTENT_TYPE)
|
||||
.and_then(|value| value.to_str().ok())
|
||||
.map(|content_type| content_type.to_ascii_lowercase().contains("xml"))
|
||||
.unwrap_or(false);
|
||||
if !is_xml {
|
||||
return false;
|
||||
}
|
||||
match headers.get(header::CONTENT_ENCODING).and_then(|value| value.to_str().ok()) {
|
||||
Some(encoding) => encoding.trim().is_empty() || encoding.eq_ignore_ascii_case("identity"),
|
||||
None => true,
|
||||
}
|
||||
}
|
||||
|
||||
fn request_scheme(headers: &HeaderMap, uri: &Uri, connection_is_tls: bool) -> String {
|
||||
get_source_scheme(headers)
|
||||
.and_then(|value| {
|
||||
value
|
||||
.split(',')
|
||||
.next()
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty())
|
||||
.map(str::to_owned)
|
||||
})
|
||||
.or_else(|| uri.scheme_str().map(str::to_owned))
|
||||
.or_else(|| connection_is_tls.then(|| "https".to_string()))
|
||||
.unwrap_or_else(|| "http".to_string())
|
||||
.to_ascii_lowercase()
|
||||
}
|
||||
|
||||
fn request_host<'a>(headers: &'a HeaderMap, uri: &'a Uri) -> Option<&'a str> {
|
||||
uri.authority().map(|authority| authority.as_str()).or_else(|| {
|
||||
headers
|
||||
.get(header::HOST)
|
||||
.and_then(|value| value.to_str().ok())
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty())
|
||||
})
|
||||
}
|
||||
|
||||
/// Absolute object URI for a POST Object `PostResponse` `<Location>`.
|
||||
///
|
||||
/// Path-style requests include the bucket in the path. Virtual-hosted requests
|
||||
/// already carry the bucket in the host, so only the encoded key remains.
|
||||
/// When no host is available the encoded path is returned without a scheme.
|
||||
pub(crate) fn post_object_location(scheme: &str, host: Option<&str>, bucket: &str, key: &str, virtual_hosted: bool) -> String {
|
||||
let mut path = String::new();
|
||||
path.push('/');
|
||||
if !virtual_hosted {
|
||||
path.push_str(bucket);
|
||||
path.push('/');
|
||||
}
|
||||
push_encoded_object_path(&mut path, key.as_bytes());
|
||||
|
||||
match host.map(str::trim).filter(|value| !value.is_empty()) {
|
||||
Some(host) => format!("{scheme}://{host}{path}"),
|
||||
None => path,
|
||||
}
|
||||
}
|
||||
|
||||
fn push_encoded_object_path(out: &mut String, bytes: &[u8]) {
|
||||
for &byte in bytes {
|
||||
if byte.is_ascii_alphanumeric() || matches!(byte, b'-' | b'_' | b'.' | b'~' | b'/') {
|
||||
out.push(char::from(byte));
|
||||
} else {
|
||||
out.push('%');
|
||||
out.push(char::from(hex_digit(byte >> 4)));
|
||||
out.push(char::from(hex_digit(byte & 0x0f)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const fn hex_digit(nibble: u8) -> u8 {
|
||||
match nibble {
|
||||
0..=9 => b'0' + nibble,
|
||||
10..=15 => b'A' + nibble - 10,
|
||||
_ => b'?',
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn rewrite_post_response_location(
|
||||
xml: &str,
|
||||
scheme: &str,
|
||||
host: Option<&str>,
|
||||
virtual_hosted_bucket: Option<&str>,
|
||||
) -> Option<String> {
|
||||
if !xml.contains("<PostResponse") {
|
||||
return None;
|
||||
}
|
||||
let bucket = xml_unescape(xml_element(xml, "Bucket")?);
|
||||
let key = xml_unescape(xml_element(xml, "Key")?);
|
||||
let virtual_hosted = virtual_hosted_bucket.is_some_and(|name| name.eq_ignore_ascii_case(&bucket));
|
||||
let location = xml_escape(&post_object_location(scheme, host, &bucket, &key, virtual_hosted));
|
||||
let (start, end) = xml_element_span(xml, "Location")?;
|
||||
if xml[start..end] == location {
|
||||
return None;
|
||||
}
|
||||
let mut fixed = String::with_capacity(xml.len() - (end - start) + location.len());
|
||||
fixed.push_str(&xml[..start]);
|
||||
fixed.push_str(&location);
|
||||
fixed.push_str(&xml[end..]);
|
||||
Some(fixed)
|
||||
}
|
||||
|
||||
fn xml_element<'a>(xml: &'a str, name: &str) -> Option<&'a str> {
|
||||
let (start, end) = xml_element_span(xml, name)?;
|
||||
Some(&xml[start..end])
|
||||
}
|
||||
|
||||
fn xml_element_span(xml: &str, name: &str) -> Option<(usize, usize)> {
|
||||
let open = format!("<{name}>");
|
||||
let close = format!("</{name}>");
|
||||
let start = xml.find(&open)? + open.len();
|
||||
let end = start + xml[start..].find(&close)?;
|
||||
Some((start, end))
|
||||
}
|
||||
|
||||
fn xml_escape(value: &str) -> String {
|
||||
let mut escaped = String::with_capacity(value.len());
|
||||
for ch in value.chars() {
|
||||
match ch {
|
||||
'&' => escaped.push_str("&"),
|
||||
'<' => escaped.push_str("<"),
|
||||
'>' => escaped.push_str(">"),
|
||||
'"' => escaped.push_str("""),
|
||||
'\'' => escaped.push_str("'"),
|
||||
_ => escaped.push(ch),
|
||||
}
|
||||
}
|
||||
escaped
|
||||
}
|
||||
|
||||
fn xml_unescape(value: &str) -> String {
|
||||
value
|
||||
.replace("&", "&")
|
||||
.replace("<", "<")
|
||||
.replace(">", ">")
|
||||
.replace(""", "\"")
|
||||
.replace("'", "'")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn encodes_reserved_and_unicode_key_characters_in_an_absolute_path_style_url() {
|
||||
let location = post_object_location("http", Some("s3.rustfs.localhost:9000"), "my-bucket", "test/a+b c%d.txt", false);
|
||||
assert_eq!(location, "http://s3.rustfs.localhost:9000/my-bucket/test/a%2Bb%20c%25d.txt");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn virtual_host_omits_the_bucket_from_the_path() {
|
||||
let location =
|
||||
post_object_location("https", Some("my-bucket.s3.rustfs.localhost:9000"), "my-bucket", "test/a+b c%d.txt", true);
|
||||
assert_eq!(location, "https://my-bucket.s3.rustfs.localhost:9000/test/a%2Bb%20c%25d.txt");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leaves_unreserved_characters_and_slashes_in_the_key() {
|
||||
let location = post_object_location("http", Some("host.example:9000"), "bucket", "a-b_c.d~e/photo.jpg", false);
|
||||
assert_eq!(location, "http://host.example:9000/bucket/a-b_c.d~e/photo.jpg");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn percent_encodes_ampersand_question_hash_and_utf8() {
|
||||
let location = post_object_location("http", Some("host"), "bucket", "naïve/a&b?c#d.txt", false);
|
||||
assert_eq!(location, "http://host/bucket/na%C3%AFve/a%26b%3Fc%23d.txt");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn falls_back_to_an_encoded_path_when_the_host_is_missing() {
|
||||
assert_eq!(
|
||||
post_object_location("http", None, "bucket", "dir/file name.txt", false),
|
||||
"/bucket/dir/file%20name.txt"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uses_x_forwarded_proto_and_host_header_when_rewriting_xml() {
|
||||
let xml = concat!(
|
||||
r#"<?xml version="1.0" encoding="UTF-8"?>"#,
|
||||
"<PostResponse>",
|
||||
"<Location>/my-bucket/test/a+b c%d.txt</Location>",
|
||||
"<Bucket>my-bucket</Bucket>",
|
||||
"<Key>test/a+b c%d.txt</Key>",
|
||||
r#"<ETag>9dd4e461268c8034f5c8564e155c67a6</ETag>"#,
|
||||
"</PostResponse>"
|
||||
);
|
||||
let rewritten = rewrite_post_response_location(xml, "https", Some("s3.example:9000"), None).unwrap();
|
||||
assert!(
|
||||
rewritten.contains("<Location>https://s3.example:9000/my-bucket/test/a%2Bb%20c%25d.txt</Location>"),
|
||||
"{rewritten}"
|
||||
);
|
||||
assert!(rewritten.contains("<Key>test/a+b c%d.txt</Key>"), "{rewritten}");
|
||||
assert!(rewritten.contains("<Bucket>my-bucket</Bucket>"), "{rewritten}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unescapes_xml_entities_in_the_stored_key_before_encoding() {
|
||||
let xml = concat!(
|
||||
"<PostResponse>",
|
||||
"<Location>/example-bucket/uploads/a b&résumé?.txt</Location>",
|
||||
"<Bucket>example-bucket</Bucket>",
|
||||
"<Key>uploads/a b&résumé?.txt</Key>",
|
||||
"<ETag>storage-etag</ETag>",
|
||||
"</PostResponse>"
|
||||
);
|
||||
let rewritten = rewrite_post_response_location(xml, "http", Some("host.invalid"), None).unwrap();
|
||||
assert!(
|
||||
rewritten.contains("<Location>http://host.invalid/example-bucket/uploads/a%20b%26r%C3%A9sum%C3%A9%3F.txt</Location>"),
|
||||
"{rewritten}"
|
||||
);
|
||||
assert!(rewritten.contains("<Key>uploads/a b&résumé?.txt</Key>"), "{rewritten}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leaves_non_post_response_xml_unchanged() {
|
||||
let xml = "<CompleteMultipartUploadResult><Location>/bucket/key</Location></CompleteMultipartUploadResult>";
|
||||
assert_eq!(rewrite_post_response_location(xml, "http", Some("host"), None), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn request_scheme_prefers_forwarded_proto() {
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert("x-forwarded-proto", http::HeaderValue::from_static("https,http"));
|
||||
assert_eq!(request_scheme(&headers, &Uri::from_static("http://ignored/bucket"), false), "https");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn request_scheme_falls_back_to_a_tls_connection() {
|
||||
assert_eq!(request_scheme(&HeaderMap::new(), &Uri::from_static("/bucket"), true), "https");
|
||||
assert_eq!(request_scheme(&HeaderMap::new(), &Uri::from_static("/bucket"), false), "http");
|
||||
}
|
||||
}
|
||||
+193
-224
@@ -12,118 +12,104 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! The S3 protocol stack one server runs, selected once at startup (rustfs/backlog#2734 T2.5).
|
||||
//! The S3 protocol stack one server runs (rustfs/backlog#2734 T2.5).
|
||||
//!
|
||||
//! Responsible for: [`S3StackService`], the service mounted where the legacy S3 service used to
|
||||
//! be, and [`select_stack`], the only place a stack is chosen. The whole stack is one or the
|
||||
//! other: no request is routed between stacks by its operation, and a request the gateway stack
|
||||
//! refuses is answered by that refusal and never retried on the legacy stack. With the gateway
|
||||
//! selected, console static requests and signed system-status reads use their native
|
||||
//! services and every other route the admin router claims goes to the control-plane host; the
|
||||
//! gateway selection holds no legacy service at all.
|
||||
//! NOT responsible for: assembling either stack (`server/http.rs` builds the legacy service,
|
||||
//! `server/gateway_stack.rs` the gateway one), or the middleware around them.
|
||||
//! Upstream: `server/http.rs`. Downstream: the native console, legacy S3 service, gateway stack
|
||||
//! and its control-plane host.
|
||||
//! Responsible for: [`S3StackService`], the service mounted under the middleware. A request to a
|
||||
//! website host is answered by the website service before any other routing; console static
|
||||
//! requests and signed system-status reads use their native services; every other route the
|
||||
//! admin router claims goes to the control-plane host, and every remaining request is the gateway
|
||||
//! S3 service's.
|
||||
//! NOT responsible for: assembling the stack (`server/gateway_stack.rs`), or the middleware around
|
||||
//! it (`server/http.rs`).
|
||||
//! Upstream: `server/http.rs`. Downstream: the native website and console, the gateway stack and
|
||||
//! its control-plane host.
|
||||
//!
|
||||
//! This file names no stack's types: it is generic over the services with one response
|
||||
//! type, so `server/http.rs` decides what they are and how their bodies meet.
|
||||
|
||||
use crate::admin::router::{claims_native_admin_route, claims_native_console_route, claims_route};
|
||||
use crate::config::S3Stack;
|
||||
use http::Request;
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
use std::task::{Context, Poll, ready};
|
||||
use tower::Service;
|
||||
|
||||
/// The S3 service of one server: the legacy stack, or the gateway stack with its control-plane
|
||||
/// services. The gateway selection holds no legacy service, so none of its requests can reach one.
|
||||
/// The S3 service of one server: the gateway stack with its website and control-plane services.
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct S3StackService<L, G, C = G> {
|
||||
stack: Stack<L, G, C>,
|
||||
pub(crate) struct S3StackService<G, C = G, W = G> {
|
||||
services: GatewayServices<G, C, W>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
enum Stack<L, G, C> {
|
||||
Legacy(L),
|
||||
Gateway(GatewayServices<G, C>),
|
||||
}
|
||||
/// Whether a request's target and `Host` select the service it is paired with.
|
||||
pub(crate) type HostClaim = Arc<dyn Fn(&http::Uri, &http::HeaderMap) -> bool + Send + Sync>;
|
||||
|
||||
/// The gateway selection: the S3 service and the hosts of the routes the admin router claims.
|
||||
/// The gateway S3 service, the website host, and the hosts of the routes the admin router claims.
|
||||
#[derive(Clone)]
|
||||
struct GatewayServices<G, C> {
|
||||
struct GatewayServices<G, C, W> {
|
||||
s3: G,
|
||||
native_website: Option<(HostClaim, W)>,
|
||||
native_console: Option<C>,
|
||||
native_admin: Option<G>,
|
||||
control_plane: Option<G>,
|
||||
}
|
||||
|
||||
impl<L, G, C> S3StackService<L, G, C> {
|
||||
/// Attaches the console service used only by the gateway selection.
|
||||
pub(crate) fn with_native_console<N>(self, native_console: Option<N>) -> S3StackService<L, G, N> {
|
||||
let stack = match self.stack {
|
||||
Stack::Legacy(legacy) => Stack::Legacy(legacy),
|
||||
Stack::Gateway(services) => Stack::Gateway(GatewayServices {
|
||||
s3: services.s3,
|
||||
native_console,
|
||||
native_admin: services.native_admin,
|
||||
control_plane: services.control_plane,
|
||||
}),
|
||||
};
|
||||
S3StackService { stack }
|
||||
}
|
||||
|
||||
/// Attaches the signed admin service used only by the gateway selection.
|
||||
pub(crate) fn with_native_admin(mut self, native_admin: Option<G>) -> Self {
|
||||
if let Stack::Gateway(services) = &mut self.stack {
|
||||
services.native_admin = native_admin;
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
/// Attaches the host of every other claimed route, used only by the gateway selection.
|
||||
pub(crate) fn with_control_plane(mut self, control_plane: Option<G>) -> Self {
|
||||
if let Stack::Gateway(services) = &mut self.stack {
|
||||
services.control_plane = control_plane;
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
/// The stack this service was built with, as the startup line names it: read from the service
|
||||
/// that answers, never from the configuration that asked for it.
|
||||
pub(crate) fn assembled(&self) -> &'static str {
|
||||
match self.stack {
|
||||
Stack::Gateway(_) => "gateway",
|
||||
Stack::Legacy(_) => "legacy",
|
||||
impl<G> S3StackService<G> {
|
||||
/// The stack around the gateway S3 service `s3`, with no other host attached yet.
|
||||
pub(crate) fn new(s3: G) -> Self {
|
||||
Self {
|
||||
services: GatewayServices {
|
||||
s3,
|
||||
native_website: None,
|
||||
native_console: None,
|
||||
native_admin: None,
|
||||
control_plane: None,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Builds the service for the selected stack.
|
||||
///
|
||||
/// `assemble_gateway` runs only when the gateway stack is selected, and its failure is the
|
||||
/// failure of the whole selection: the caller refuses to start. The legacy service is dropped
|
||||
/// when the gateway is selected.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Whatever `assemble_gateway` refused with. The legacy stack is never substituted.
|
||||
pub(crate) fn select_stack<L, G, E>(
|
||||
stack: S3Stack,
|
||||
legacy: L,
|
||||
assemble_gateway: impl FnOnce() -> Result<G, E>,
|
||||
) -> Result<S3StackService<L, G>, E> {
|
||||
let stack = match stack {
|
||||
S3Stack::Legacy => Stack::Legacy(legacy),
|
||||
S3Stack::Gateway => Stack::Gateway(GatewayServices {
|
||||
s3: assemble_gateway()?,
|
||||
native_console: None,
|
||||
native_admin: None,
|
||||
control_plane: None,
|
||||
}),
|
||||
};
|
||||
Ok(S3StackService { stack })
|
||||
impl<G, C, W> S3StackService<G, C, W> {
|
||||
/// Attaches the native console service.
|
||||
pub(crate) fn with_native_console<N>(self, native_console: Option<N>) -> S3StackService<G, N, W> {
|
||||
let services = self.services;
|
||||
S3StackService {
|
||||
services: GatewayServices {
|
||||
s3: services.s3,
|
||||
native_website: services.native_website,
|
||||
native_console,
|
||||
native_admin: services.native_admin,
|
||||
control_plane: services.control_plane,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Attaches the website service: every request `claim` selects goes to it before any other
|
||||
/// routing.
|
||||
pub(crate) fn with_native_website<N>(self, native_website: Option<(HostClaim, N)>) -> S3StackService<G, C, N> {
|
||||
let services = self.services;
|
||||
S3StackService {
|
||||
services: GatewayServices {
|
||||
s3: services.s3,
|
||||
native_website,
|
||||
native_console: services.native_console,
|
||||
native_admin: services.native_admin,
|
||||
control_plane: services.control_plane,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Attaches the signed admin service.
|
||||
pub(crate) fn with_native_admin(mut self, native_admin: Option<G>) -> Self {
|
||||
self.services.native_admin = native_admin;
|
||||
self
|
||||
}
|
||||
|
||||
/// Attaches the host of every other claimed route.
|
||||
pub(crate) fn with_control_plane(mut self, control_plane: Option<G>) -> Self {
|
||||
self.services.control_plane = control_plane;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
type Answer<R, E> = Pin<Box<dyn Future<Output = Result<http::Response<R>, E>> + Send>>;
|
||||
@@ -137,15 +123,22 @@ fn bare<R: Default, E>(status: http::StatusCode) -> Answer<R, E> {
|
||||
})
|
||||
}
|
||||
|
||||
impl<G, C> GatewayServices<G, C> {
|
||||
impl<G, C, W> GatewayServices<G, C, W> {
|
||||
fn call<B, R, E>(&mut self, request: Request<B>) -> Answer<R, E>
|
||||
where
|
||||
G: Service<Request<B>, Response = http::Response<R>, Error = E>,
|
||||
C: Service<Request<B>, Response = http::Response<R>, Error = E>,
|
||||
W: Service<Request<B>, Response = http::Response<R>, Error = E>,
|
||||
G::Future: Send + 'static,
|
||||
C::Future: Send + 'static,
|
||||
W::Future: Send + 'static,
|
||||
R: Default,
|
||||
{
|
||||
if let Some((claim, website)) = &mut self.native_website
|
||||
&& claim(request.uri(), request.headers())
|
||||
{
|
||||
return Box::pin(website.call(request));
|
||||
}
|
||||
let claimed = claims_route(request.method(), request.uri(), request.headers());
|
||||
if claimed && (request.headers().contains_key("x-auth-token") || request.headers().contains_key("x-storage-token")) {
|
||||
return bare(http::StatusCode::FORBIDDEN);
|
||||
@@ -171,14 +164,14 @@ impl<G, C> GatewayServices<G, C> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<L, G, C, B, R, E> Service<Request<B>> for S3StackService<L, G, C>
|
||||
impl<G, C, W, B, R, E> Service<Request<B>> for S3StackService<G, C, W>
|
||||
where
|
||||
L: Service<Request<B>, Response = http::Response<R>, Error = E>,
|
||||
G: Service<Request<B>, Response = http::Response<R>, Error = E>,
|
||||
C: Service<Request<B>, Response = http::Response<R>, Error = E>,
|
||||
L::Future: Send + 'static,
|
||||
W: Service<Request<B>, Response = http::Response<R>, Error = E>,
|
||||
G::Future: Send + 'static,
|
||||
C::Future: Send + 'static,
|
||||
W::Future: Send + 'static,
|
||||
R: Default,
|
||||
{
|
||||
type Response = http::Response<R>;
|
||||
@@ -186,29 +179,25 @@ where
|
||||
type Future = Answer<R, E>;
|
||||
|
||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
match &mut self.stack {
|
||||
Stack::Legacy(legacy) => legacy.poll_ready(cx),
|
||||
Stack::Gateway(services) => {
|
||||
ready!(services.s3.poll_ready(cx))?;
|
||||
for host in [&mut services.native_admin, &mut services.control_plane]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
{
|
||||
ready!(host.poll_ready(cx))?;
|
||||
}
|
||||
if let Some(console) = &mut services.native_console {
|
||||
ready!(console.poll_ready(cx))?;
|
||||
}
|
||||
Poll::Ready(Ok(()))
|
||||
}
|
||||
let services = &mut self.services;
|
||||
ready!(services.s3.poll_ready(cx))?;
|
||||
for host in [&mut services.native_admin, &mut services.control_plane]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
{
|
||||
ready!(host.poll_ready(cx))?;
|
||||
}
|
||||
if let Some(console) = &mut services.native_console {
|
||||
ready!(console.poll_ready(cx))?;
|
||||
}
|
||||
if let Some((_, website)) = &mut services.native_website {
|
||||
ready!(website.poll_ready(cx))?;
|
||||
}
|
||||
Poll::Ready(Ok(()))
|
||||
}
|
||||
|
||||
fn call(&mut self, request: Request<B>) -> Self::Future {
|
||||
match &mut self.stack {
|
||||
Stack::Legacy(legacy) => Box::pin(legacy.call(request)),
|
||||
Stack::Gateway(services) => services.call(request),
|
||||
}
|
||||
self.services.call(request)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,42 +241,12 @@ mod tests {
|
||||
}
|
||||
|
||||
fn gateway_stack() -> S3StackService<Named, Named> {
|
||||
select_stack(S3Stack::Gateway, Named("legacy"), || Ok::<_, Infallible>(Named("gateway")))
|
||||
.expect("assembles")
|
||||
.with_control_plane(Some(Named("control-plane")))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_gateway_assembly_failure_fails_the_selection_instead_of_falling_back() {
|
||||
let selection = select_stack::<_, Named, _>(S3Stack::Gateway, Named("legacy"), || Err("the assembly was refused"));
|
||||
|
||||
assert_eq!(selection.err(), Some("the assembly was refused"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_legacy_selection_never_assembles_a_gateway() {
|
||||
let service = select_stack::<_, Named, &str>(S3Stack::Legacy, Named("legacy"), || {
|
||||
panic!("the legacy stack must not assemble the gateway")
|
||||
})
|
||||
.expect("legacy needs no assembly");
|
||||
|
||||
assert_eq!(service.assembled(), "legacy");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn the_legacy_stack_answers_every_request_itself() {
|
||||
let mut service = select_stack(S3Stack::Legacy, Named("legacy"), || Ok::<_, Infallible>(Named("gateway")))
|
||||
.expect("legacy needs no assembly");
|
||||
|
||||
for target in ["/", "/bucket/key", "/rustfs/admin/v3/info", "/health"] {
|
||||
assert_eq!(answered_by(&mut service, request(Method::GET, target)).await, "legacy", "{target}");
|
||||
}
|
||||
S3StackService::new(Named("gateway")).with_control_plane(Some(Named("control-plane")))
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn the_gateway_stack_answers_every_s3_request_whatever_the_operation() {
|
||||
let mut service = gateway_stack();
|
||||
assert_eq!(service.assembled(), "gateway");
|
||||
|
||||
for (method, target) in [
|
||||
(Method::GET, "/"),
|
||||
@@ -351,8 +310,7 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_gateway_selection_without_its_host_answers_a_claimed_route_itself() {
|
||||
let mut service =
|
||||
select_stack(S3Stack::Gateway, Named("legacy"), || Ok::<_, Infallible>(Named("gateway"))).expect("assembles");
|
||||
let mut service = S3StackService::new(Named("gateway"));
|
||||
let response = service
|
||||
.call(request(Method::PUT, "/rustfs/admin/v3/add-user"))
|
||||
.await
|
||||
@@ -382,11 +340,11 @@ mod tests {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn gateway_keystone_tokens_are_refused_before_non_s3_legacy_dispatch() {
|
||||
async fn gateway_keystone_tokens_are_refused_before_non_s3_dispatch() {
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
let console_path = format!("{}/index.html", crate::server::console_prefix());
|
||||
for stack in [S3Stack::Gateway, S3Stack::Legacy] {
|
||||
{
|
||||
for (method, target) in [
|
||||
(Method::GET, "/rustfs/admin/v3/info"),
|
||||
(Method::GET, "/minio/admin/v3/info"),
|
||||
@@ -401,15 +359,10 @@ mod tests {
|
||||
(Method::GET, console_path.as_str()),
|
||||
] {
|
||||
for header in [None, Some("x-auth-token"), Some("x-storage-token")] {
|
||||
let legacy_calls = Arc::new(AtomicUsize::new(0));
|
||||
let gateway_calls = Arc::new(AtomicUsize::new(0));
|
||||
let console_calls = Arc::new(AtomicUsize::new(0));
|
||||
let admin_calls = Arc::new(AtomicUsize::new(0));
|
||||
let control_calls = Arc::new(AtomicUsize::new(0));
|
||||
let legacy = Counting {
|
||||
name: "legacy",
|
||||
calls: Arc::clone(&legacy_calls),
|
||||
};
|
||||
let gateway = Counting {
|
||||
name: "gateway",
|
||||
calls: Arc::clone(&gateway_calls),
|
||||
@@ -426,8 +379,7 @@ mod tests {
|
||||
name: "control-plane",
|
||||
calls: Arc::clone(&control_calls),
|
||||
};
|
||||
let mut service = select_stack(stack, legacy, || Ok::<_, Infallible>(gateway))
|
||||
.unwrap()
|
||||
let mut service = S3StackService::new(gateway)
|
||||
.with_native_console(Some(console))
|
||||
.with_native_admin(Some(admin))
|
||||
.with_control_plane(Some(control));
|
||||
@@ -441,46 +393,30 @@ mod tests {
|
||||
request.headers_mut().insert(header, "validated-token".parse().unwrap());
|
||||
}
|
||||
let response = service.call(request).await.unwrap();
|
||||
if stack == S3Stack::Gateway && header.is_some() {
|
||||
if header.is_some() {
|
||||
assert_eq!(response.status(), StatusCode::FORBIDDEN, "{target} {header:?}");
|
||||
assert_eq!(legacy_calls.load(Ordering::SeqCst), 0, "refused request reached legacy");
|
||||
assert_eq!(console_calls.load(Ordering::SeqCst), 0, "refused request reached native console");
|
||||
assert_eq!(admin_calls.load(Ordering::SeqCst), 0, "refused request reached native admin");
|
||||
assert_eq!(control_calls.load(Ordering::SeqCst), 0, "refused request reached the control plane");
|
||||
} else if stack == S3Stack::Gateway && target == console_path {
|
||||
} else if target == console_path {
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
assert_eq!(response.body(), &"console");
|
||||
assert_eq!(legacy_calls.load(Ordering::SeqCst), 0);
|
||||
assert_eq!(console_calls.load(Ordering::SeqCst), 1);
|
||||
} else if stack == S3Stack::Gateway
|
||||
&& (target.starts_with("/rustfs/admin/") || target.starts_with("/minio/admin/"))
|
||||
{
|
||||
} else if target.starts_with("/rustfs/admin/") || target.starts_with("/minio/admin/") {
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
assert_eq!(response.body(), &"admin");
|
||||
assert_eq!(legacy_calls.load(Ordering::SeqCst), 0);
|
||||
assert_eq!(console_calls.load(Ordering::SeqCst), 0);
|
||||
} else if stack == S3Stack::Gateway {
|
||||
} else {
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
assert_eq!(response.body(), &"control-plane");
|
||||
assert_eq!(control_calls.load(Ordering::SeqCst), 1);
|
||||
assert_eq!(console_calls.load(Ordering::SeqCst), 0);
|
||||
} else {
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
assert_eq!(response.body(), &"legacy");
|
||||
assert_eq!(legacy_calls.load(Ordering::SeqCst), 1);
|
||||
assert_eq!(console_calls.load(Ordering::SeqCst), 0);
|
||||
assert_eq!(control_calls.load(Ordering::SeqCst), 0);
|
||||
}
|
||||
if stack == S3Stack::Gateway {
|
||||
assert_eq!(legacy_calls.load(Ordering::SeqCst), 0, "a gateway request reached legacy");
|
||||
}
|
||||
assert_eq!(gateway_calls.load(Ordering::SeqCst), 0, "non-S3 request reached gateway");
|
||||
assert_eq!(
|
||||
admin_calls.load(Ordering::SeqCst),
|
||||
usize::from(
|
||||
stack == S3Stack::Gateway
|
||||
&& header.is_none()
|
||||
&& (target.starts_with("/rustfs/admin/") || target.starts_with("/minio/admin/"))
|
||||
header.is_none() && (target.starts_with("/rustfs/admin/") || target.starts_with("/minio/admin/"))
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -523,23 +459,17 @@ mod tests {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn no_request_of_any_class_reaches_the_legacy_service_on_the_gateway_stack() {
|
||||
async fn every_request_class_reaches_one_gateway_service() {
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
let counter = |name| Counting {
|
||||
name,
|
||||
calls: Arc::new(AtomicUsize::new(0)),
|
||||
};
|
||||
let (legacy, gateway, console, admin, control) = (
|
||||
counter("legacy"),
|
||||
counter("gateway"),
|
||||
counter("console"),
|
||||
counter("admin"),
|
||||
counter("control-plane"),
|
||||
);
|
||||
let calls = [&legacy, &gateway, &console, &admin, &control].map(|service| Arc::clone(&service.calls));
|
||||
let mut service = select_stack(S3Stack::Gateway, legacy, || Ok::<_, Infallible>(gateway))
|
||||
.unwrap()
|
||||
let (gateway, console, admin, control) =
|
||||
(counter("gateway"), counter("console"), counter("admin"), counter("control-plane"));
|
||||
let calls = [&gateway, &console, &admin, &control].map(|service| Arc::clone(&service.calls));
|
||||
let mut service = S3StackService::new(gateway)
|
||||
.with_native_console(Some(console))
|
||||
.with_native_admin(Some(admin))
|
||||
.with_control_plane(Some(control));
|
||||
@@ -549,8 +479,7 @@ mod tests {
|
||||
service.call(request).await.unwrap();
|
||||
}
|
||||
|
||||
let [legacy, gateway, console, admin, control] = calls.map(|calls| calls.load(Ordering::SeqCst));
|
||||
assert_eq!(legacy, 0, "a gateway-stack request reached the legacy service");
|
||||
let [gateway, console, admin, control] = calls.map(|calls| calls.load(Ordering::SeqCst));
|
||||
assert!(
|
||||
gateway > 0 && console > 0 && admin > 0 && control > 0,
|
||||
"{gateway} {console} {admin} {control}"
|
||||
@@ -559,42 +488,6 @@ mod tests {
|
||||
assert_eq!(gateway + console + admin + control, count - 1);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn no_request_of_any_class_reaches_a_gateway_service_on_the_legacy_stack() {
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
let counter = |name| Counting {
|
||||
name,
|
||||
calls: Arc::new(AtomicUsize::new(0)),
|
||||
};
|
||||
let (legacy, gateway, console, admin, control) = (
|
||||
counter("legacy"),
|
||||
counter("gateway"),
|
||||
counter("console"),
|
||||
counter("admin"),
|
||||
counter("control-plane"),
|
||||
);
|
||||
let calls = [&legacy, &gateway, &console, &admin, &control].map(|service| Arc::clone(&service.calls));
|
||||
let mut service = select_stack(S3Stack::Legacy, legacy, || Ok::<_, Infallible>(gateway))
|
||||
.unwrap()
|
||||
.with_native_console(Some(console))
|
||||
.with_native_admin(Some(admin))
|
||||
.with_control_plane(Some(control));
|
||||
let requests = every_request_class();
|
||||
let count = requests.len();
|
||||
for request in requests {
|
||||
service.call(request).await.unwrap();
|
||||
}
|
||||
|
||||
let [legacy, gateway, console, admin, control] = calls.map(|calls| calls.load(Ordering::SeqCst));
|
||||
assert_eq!(
|
||||
[gateway, console, admin, control],
|
||||
[0; 4],
|
||||
"a legacy-stack request reached a gateway service"
|
||||
);
|
||||
assert_eq!(legacy, count);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn an_sts_form_post_goes_to_the_control_plane_and_a_plain_post_does_not() {
|
||||
let mut service = gateway_stack();
|
||||
@@ -608,6 +501,86 @@ mod tests {
|
||||
assert_eq!(answered_by(&mut service, sts).await, "control-plane");
|
||||
assert_eq!(answered_by(&mut service, request(Method::POST, "/")).await, "gateway");
|
||||
}
|
||||
/// A gateway stack whose website host claims every request to `*.website.test`.
|
||||
fn gateway_stack_with_website() -> S3StackService<Named, Named, Named> {
|
||||
let claim: HostClaim = Arc::new(|_uri: &http::Uri, headers: &http::HeaderMap| {
|
||||
headers
|
||||
.get(http::header::HOST)
|
||||
.and_then(|host| host.to_str().ok())
|
||||
.is_some_and(|host| host.ends_with(".website.test"))
|
||||
});
|
||||
gateway_stack()
|
||||
.with_native_admin(Some(Named("admin")))
|
||||
.with_native_console(Some(Named("console")))
|
||||
.with_native_website(Some((claim, Named("website"))))
|
||||
}
|
||||
|
||||
fn to_host(method: Method, target: &str, host: &str, extra: Option<(&'static str, &'static str)>) -> Request<()> {
|
||||
let mut builder = Request::builder().method(method).uri(target).header(http::header::HOST, host);
|
||||
if let Some((name, value)) = extra {
|
||||
builder = builder.header(name, value);
|
||||
}
|
||||
builder.body(()).expect("static request")
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_website_host_is_answered_by_the_website_service_before_any_other_route() {
|
||||
let mut service = gateway_stack_with_website();
|
||||
let console = format!("{}/index.html", crate::server::console_prefix());
|
||||
for (method, target, extra) in [
|
||||
(Method::GET, "/", None),
|
||||
(Method::HEAD, "/index.html", None),
|
||||
(Method::POST, "/", Some(("content-type", "application/x-www-form-urlencoded"))),
|
||||
(Method::GET, "/rustfs/admin/v3/info", None),
|
||||
(Method::GET, "/rustfs/admin/v3/info", Some(("x-auth-token", "token"))),
|
||||
(Method::GET, "/rustfs/admin/v3/datausageinfo", None),
|
||||
(Method::GET, "/health", None),
|
||||
(Method::GET, "/profile/cpu", None),
|
||||
(Method::GET, "/bucket?replication-metrics", None),
|
||||
(Method::GET, "/bucket?list-type=2&metadata=true", None),
|
||||
(Method::GET, console.as_str(), None),
|
||||
(Method::PUT, "/bucket/key", None),
|
||||
] {
|
||||
let request = to_host(method.clone(), target, "site.website.test", extra);
|
||||
assert_eq!(answered_by_any(&mut service, request).await, "website", "{method} {target} {extra:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_request_to_any_other_host_never_reaches_the_website_service() {
|
||||
let mut service = gateway_stack_with_website();
|
||||
let console = format!("{}/index.html", crate::server::console_prefix());
|
||||
for (method, target, host, expected) in [
|
||||
(Method::GET, "/", "localhost", "gateway"),
|
||||
(Method::GET, "/bucket/key", "website.test.example", "gateway"),
|
||||
(Method::GET, "/bucket?list-type=2&metadata=true", "localhost", "gateway"),
|
||||
(Method::GET, "/rustfs/admin/v3/info", "localhost", "admin"),
|
||||
(Method::GET, "/health", "localhost", "control-plane"),
|
||||
(Method::GET, "/bucket?replication-metrics", "s3.example.test", "control-plane"),
|
||||
(Method::GET, console.as_str(), "localhost", "console"),
|
||||
] {
|
||||
let request = to_host(method.clone(), target, host, None);
|
||||
assert_eq!(answered_by_any(&mut service, request).await, expected, "{method} {host} {target}");
|
||||
}
|
||||
let refused = service
|
||||
.call(to_host(Method::GET, "/health", "localhost", Some(("x-auth-token", "token"))))
|
||||
.await
|
||||
.expect("infallible");
|
||||
assert_eq!(refused.status(), StatusCode::FORBIDDEN, "a Keystone token on a claimed route");
|
||||
}
|
||||
|
||||
async fn answered_by_any<C, W>(service: &mut S3StackService<Named, C, W>, request: Request<()>) -> &'static str
|
||||
where
|
||||
C: Service<Request<()>, Response = Response<&'static str>, Error = Infallible>,
|
||||
W: Service<Request<()>, Response = Response<&'static str>, Error = Infallible>,
|
||||
C::Future: Send + 'static,
|
||||
W::Future: Send + 'static,
|
||||
{
|
||||
let response = service.call(request).await.expect("infallible");
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
response.into_body()
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn native_admin_selection_is_exact_and_host_independent() {
|
||||
let mut service = gateway_stack().with_native_admin(Some(Named("admin")));
|
||||
@@ -699,9 +672,5 @@ mod tests {
|
||||
};
|
||||
assert_eq!(answered_by(&mut service, request(method, target)).await, expected, "{target}");
|
||||
}
|
||||
let mut legacy = select_stack(S3Stack::Legacy, Named("legacy"), || Ok::<_, Infallible>(Named("gateway")))
|
||||
.unwrap()
|
||||
.with_native_admin(Some(Named("admin")));
|
||||
assert_eq!(answered_by(&mut legacy, request(Method::GET, "/rustfs/admin/v3/info")).await, "legacy");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
use crate::{
|
||||
config::{Config, S3Stack},
|
||||
config::Config,
|
||||
server::{ServiceState, ServiceStateManager, ShutdownHandle, start_http_server},
|
||||
startup_runtime_sources,
|
||||
storage_api::server::http::ServerContextSlot,
|
||||
@@ -41,8 +41,6 @@ const EVENT_SERVER_STARTING: &str = "server_starting";
|
||||
const EVENT_ACTION_CREDENTIALS_INITIALIZED: &str = "action_credentials_initialized";
|
||||
const EVENT_ACTION_CREDENTIALS_INITIALIZATION_FAILED: &str = "action_credentials_initialization_failed";
|
||||
const DEFAULT_CREDENTIALS_WARNING_MESSAGE: &str = "Detected default root credentials; set RUSTFS_ACCESS_KEY and RUSTFS_SECRET_KEY to non-default values for production deployments";
|
||||
#[cfg(not(feature = "gateway-stack"))]
|
||||
const GATEWAY_STACK_NOT_BUILT: &str = "RUSTFS_S3_STACK=gateway needs a binary built with the `gateway-stack` feature, which no release build enables (rustfs/backlog#2734)";
|
||||
|
||||
pub(crate) struct StartupListenContext {
|
||||
pub(crate) readiness: Arc<GlobalReadiness>,
|
||||
@@ -95,7 +93,7 @@ pub(crate) async fn init_startup_listen_context(
|
||||
config: &Config,
|
||||
instance_ctx: &Arc<InstanceContext>,
|
||||
) -> Result<StartupListenContext> {
|
||||
refuse_unbuilt_stack(config.s3_stack)?;
|
||||
crate::config::refuse_retired_s3_stack_selector()?;
|
||||
crate::server::init_console_prefix()?;
|
||||
log_sanitized_server_config(config);
|
||||
let readiness = Arc::new(GlobalReadiness::new());
|
||||
@@ -130,7 +128,6 @@ pub(crate) async fn init_startup_listen_context(
|
||||
ip = %server_addr.ip(),
|
||||
port = %server_port,
|
||||
version = %crate::version::get_version(),
|
||||
s3_stack = ?config.s3_stack,
|
||||
"Starting RustFS server"
|
||||
);
|
||||
|
||||
@@ -145,18 +142,6 @@ pub(crate) async fn init_startup_listen_context(
|
||||
})
|
||||
}
|
||||
|
||||
/// Refuses a selected S3 stack this binary cannot serve, before any listener or storage exists.
|
||||
/// The selection is never replaced by another stack.
|
||||
fn refuse_unbuilt_stack(stack: S3Stack) -> Result<()> {
|
||||
match stack {
|
||||
S3Stack::Legacy => Ok(()),
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
S3Stack::Gateway => Ok(()),
|
||||
#[cfg(not(feature = "gateway-stack"))]
|
||||
S3Stack::Gateway => Err(Error::new(ErrorKind::Unsupported, GATEWAY_STACK_NOT_BUILT)),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn prepare_embedded_startup_config(
|
||||
address: String,
|
||||
access_key: String,
|
||||
@@ -186,10 +171,8 @@ pub(crate) async fn prepare_embedded_startup_config(
|
||||
config.secret_key = secret_key.clone();
|
||||
config.region = Some(region.clone());
|
||||
config.console_enable = false;
|
||||
// The stack is selected for the whole process, so an embedded server reads the same variable
|
||||
// the binary does.
|
||||
config.s3_stack = S3Stack::from_env()?;
|
||||
refuse_unbuilt_stack(config.s3_stack)?;
|
||||
// An embedded server refuses the retired stack selector the same way the binary does.
|
||||
crate::config::refuse_retired_s3_stack_selector()?;
|
||||
|
||||
Ok(EmbeddedStartupConfig {
|
||||
config,
|
||||
@@ -579,26 +562,6 @@ mod tests {
|
||||
));
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "gateway-stack"))]
|
||||
#[test]
|
||||
fn a_binary_without_the_gateway_stack_refuses_to_select_it() {
|
||||
let err = super::refuse_unbuilt_stack(crate::config::S3Stack::Gateway).expect_err("the gateway stack is not built");
|
||||
|
||||
assert_eq!(err.kind(), std::io::ErrorKind::Unsupported);
|
||||
assert!(err.to_string().contains("gateway-stack"), "{err}");
|
||||
}
|
||||
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
#[test]
|
||||
fn a_binary_with_the_gateway_stack_accepts_its_selection() {
|
||||
super::refuse_unbuilt_stack(crate::config::S3Stack::Gateway).expect("the gateway stack is built");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_legacy_stack_is_always_selectable() {
|
||||
super::refuse_unbuilt_stack(crate::config::S3Stack::Legacy).expect("legacy is the default stack");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn init_startup_listen_context_rejects_console_s3_port_conflict() {
|
||||
let mut config = Config::new("127.0.0.1:9001", vec!["/tmp/rustfs-data".to_string()]);
|
||||
|
||||
@@ -16,7 +16,7 @@ use super::access_owned::listing_multipart::{
|
||||
authorize_bucket_listing, authorize_list_multipart_uploads, authorize_list_objects_v2, authorize_list_parts,
|
||||
};
|
||||
use super::access_owned::object_misc::{authorize_delete_object, authorize_delete_objects};
|
||||
// `app::metadata_route` and the legacy-edge files still import the owned shapes through this path.
|
||||
// The legacy-edge files still import the owned shapes through this path.
|
||||
#[cfg(test)]
|
||||
use super::ECStore;
|
||||
#[cfg(test)]
|
||||
@@ -31,18 +31,11 @@ use crate::auth::facts::AuthzTarget;
|
||||
use crate::auth::facts::{AuthzFacts, AuthzPrincipal, build_args, build_conditions};
|
||||
use crate::auth::{get_request_auth_type_with_query, get_session_token, reject_unsigned_amz_headers_on_sigv4_request};
|
||||
use crate::shared_types::RemoteAddr;
|
||||
#[cfg(test)]
|
||||
pub(crate) use crate::storage::authorization_actions::{
|
||||
complete_multipart_upload_authorize_action, delete_object_authorize_action, list_parts_authorize_action,
|
||||
post_object_authorize_action, versioned_read_action, versioned_tagging_action,
|
||||
};
|
||||
// `app::metadata_route` still imports this path.
|
||||
use crate::storage::authorization::ObjectTagConditions;
|
||||
#[cfg(test)]
|
||||
use crate::storage::authorization::TableDataPlaneListCursorPosition;
|
||||
#[cfg(test)]
|
||||
use crate::storage::authorization::capture_odm_read_generation;
|
||||
pub(crate) use crate::storage::authorization::req_info_mut;
|
||||
#[cfg(test)]
|
||||
use crate::storage::authorization::{AMZ_WRITE_OFFSET_BYTES_HEADER, replication_request_authorized, request_context_from_req};
|
||||
use crate::storage::authorization::{AccessMarkers, AuthorizationRequest, VerifiedSignature, admit_operation, resolve_req_info};
|
||||
@@ -89,6 +82,11 @@ use crate::storage::authorization::{
|
||||
use crate::storage::authorization::{
|
||||
has_write_offset_bytes_header, request_object_store, set_requested_object_lock_retain_until,
|
||||
};
|
||||
#[cfg(test)]
|
||||
pub(crate) use crate::storage::authorization_actions::{
|
||||
complete_multipart_upload_authorize_action, delete_object_authorize_action, list_parts_authorize_action,
|
||||
post_object_authorize_action, versioned_read_action, versioned_tagging_action,
|
||||
};
|
||||
use crate::storage::denial_audit::DenialAuditor;
|
||||
use crate::storage::helper::DenialScope;
|
||||
pub(crate) use crate::storage::req_info::ReqInfo;
|
||||
@@ -3143,7 +3141,6 @@ mod tests {
|
||||
assert_eq!(conditions.get("object-lock-legal-hold"), Some(&vec!["ON".to_string()]));
|
||||
}
|
||||
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
#[test]
|
||||
fn gateway_post_policy_projects_effective_write_conditions() {
|
||||
use super::access_owned::object_write::{PostObjectFormPolicy, PostObjectPolicyFields};
|
||||
|
||||
@@ -185,7 +185,7 @@ impl PostObjectFormPolicy {
|
||||
Ok(Self(values))
|
||||
}
|
||||
|
||||
#[cfg(all(test, feature = "gateway-stack"))]
|
||||
#[cfg(test)]
|
||||
pub(crate) fn with_metadata(mut self, metadata: &[(String, String)]) -> S3Result<Self> {
|
||||
for (name, value) in metadata {
|
||||
let name = HeaderName::from_bytes(format!("x-amz-meta-{name}").as_bytes()).map_err(|_| invalid_post_form_field())?;
|
||||
@@ -206,7 +206,6 @@ impl PostObjectFormPolicy {
|
||||
req.install_post_object_policy_headers(PostObjectPolicyHeaders(headers));
|
||||
}
|
||||
|
||||
#[cfg(feature = "gateway-stack")]
|
||||
pub(crate) fn install_gateway<R: AuthorizationRequest + ?Sized>(mut self, req: &mut R) {
|
||||
for (name, value) in &mut self.0 {
|
||||
match name.as_str() {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user