Repository navigation
rgw/swift: send WWW-Authenticate on 401 Unauthorized - #73209
RaminNietzsche wants to merge 1 commit into
Conversation
|
jenkins test make check |
RFC 9110 RGW audit — series contextThis PR is one focused change from an RFC 9110 conformance review of RGW (S3, Swift, Admin, STS). Each PR is meant to review and merge on its own; there is no batch dependency unless called out below.
Same audit, already tracked on other PRs (not part of this series authorship):
Follow-ups from the audit not opened yet: T4d Shared repro script and sample output: https://gist.github.com/RaminNietzsche/818ad8dd6b8d8093560183cd09d2b169 ( This PR (T6): §15.5.2 — Swift-protocol 401 responses must include |
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
92a62aa to
15718d5
Compare
|
jenkins test make check |
|
jenkins test make |
15718d5 to
d4fca2d
Compare
|
@Doracly Please take a look. |
|
jenkins test make check |
d4fca2d to
9c0b146
Compare
|
Pushed
Verified in a test environment: |
|
jenkins test make check |
Doracly
left a comment
There was a problem hiding this comment.
Thanks! The realm needs changes, see inline. Also, the TODO in set_req_state_err() asks to keep Swift special cases out of shared code like dump_errno(). Adding the header from the Swift handler's error path would also give you the account without parsing the URI.
9c0b146 to
e957f7d
Compare
|
Pushed review fix jenkins test make check |
|
jenkins test make check |
There was a problem hiding this comment.
The workunit fails for me on vstart with rgw_swift_account_in_url=true: a bad token gets a 401 without WWW-Authenticate (same with the default config). Only /auth/1.0 sends it.
$ curl -si -H 'X-Auth-Token: bogus' http://localhost:8000/swift/v1/AUTH_nobody | grep -iE '^HTTP|www-auth'
HTTP/1.1 401 Unauthorized
A failed token check never reaches the op's send_response(); rgw_process.cc goes through abort_early(), which uses the shared dump_errno(). The Swift handlers' error_handler() is called from there first and could write the response instead.
Tests, required:
- A regression test for the realm encoding: with a bad token,
/swift/v1/AUTH_a%0d%0aX-Injected:%20ymust not return anX-Injectedheader.
Tests, optional:
- A
KEY_account keeps its prefix in the realm. - The
rgw swift account in urloverride inrgw/verify/tasks/applies to the whole verify job, since that directory has a+. Setting it from the workunit withceph config setand removing it afterwards keeps it local, and allows checkingSwift realm="unknown"with the default config too.
Doracly review (2026-11-13) — fix pushed (
|
a701c56 to
e9b74d0
Compare
CI:
|
|
Rebased on current This still has the Doracly follow-ups: Could you take another look when you have time? jenkins test make check |
e9b74d0 to
e8e237d
Compare
Doracly
left a comment
There was a problem hiding this comment.
Thanks for squashing and for the tests. Blocking: handling the 401 in RGWHandler_REST_SWIFT::error_handler() drops CORS headers and misses FormPost; see my comment there, and the workunit comment on tests for both. The workunit cleanup matters less, but I'd like it addressed here as well.
I'm picky about this on purpose: the Swift code in RGW has collected many small leftovers over the years, and I follow the boy scouts' rule of leaving a place tidier than you found it.
| int RGWHandler_REST_SWIFT::error_handler(int err_no, std::string *error_content, | ||
| optional_yield y) | ||
| { | ||
| if (!s->err.http_ret || s->err.http_ret == 200) { | ||
| set_req_state_err(s, err_no); | ||
| } | ||
| if (s->err.http_ret == 401) { | ||
| dump_swift_status(s); | ||
| end_header(s, nullptr); | ||
| return 0; | ||
| } | ||
| return err_no; | ||
| } |
There was a problem hiding this comment.
Handling the 401 here has two gaps, both visible on vstart:
end_header(s, nullptr)drops the CORS headers thatabort_early()adds withend_header(s, op): an anonymous GET withOriginon a container with CORS rules gets noAccess-Control-Allow-Origin.RGWFormPost::error_handler()doesn't call this handler, so a FormPost with a bad signature gets no challenge.
Adding only the header and returning err_no keeps CORS, but then a DLO with unreadable segments gets the header twice, via send_response_data_error().
This takes back my 11-09 and 11-13 advice, which you followed; sorry about that...:-( Since init_from_header() now saves the account, the realm doesn't need the handler. One check in dump_status() in rgw_rest.cc, which writes every status line, should cover all paths; dump_trans_id() there already has a Swift branch. Above dump_status():
static void dump_swift_www_authenticate(req_state *s)
{
const std::string& account = s->init_state.swift_account_realm;
const std::string realm = url_encode(account.empty() ? "unknown" : account);
dump_header(s, "WWW-Authenticate", "Swift realm=\"" + realm + '"');
}and at its end:
if (s->prot_flags & RGW_REST_SWIFT && status == 401) {
dump_swift_www_authenticate(s);
}Then dump_swift_status(), dump_swift_www_authenticate() and swift_www_authenticate_realm() in rgw_rest_swift.cc and the error_handler() changes can go, and the 27 call sites go back to dump_errno(). The source change shrinks to +14 lines. On vstart this passes the workunit and fixes all three cases above.
There was a problem hiding this comment.
Thanks for walking this back through dump_status() — that is much cleaner. Tip 78354c0804a drops the Swift error_handler() override and dump_swift_status() entirely; the challenge now comes from one place in rgw_rest.cc (dump_status(), using init_state.swift_account_realm + url_encode). All Swift call sites are back on dump_errno() so CORS from end_header(s, op) is preserved on the anonymous Origin 401 path, and FormPost bad-signature 401s pick up the header without a special handler.
I prepared a small vstart repro script (ceph-local-dev/scripts/repro-73209-vstart.sh on the fork) for the CORS and FormPost cases; my staging test cluster did not finish an radosgw rebuild today (cmake/librdkafka), so I have not pasted green before/after logs here yet. The post-fix code path matches what you described on vstart; I will re-run locally as soon as the build is green and can post numbers if useful.
Appreciate the careful review — happy to adjust anything I missed.
| headers={'X-Auth-User': 'test:tester', 'X-Auth-Key': 'wrong'}, | ||
| verify=False, | ||
| ) | ||
| assert_swift_challenge(r) |
There was a problem hiding this comment.
Please add the two cases this version gets wrong:
- a FormPost with a bad signature gets a 401 with
WWW-Authenticate; - an anonymous GET with
Originon a container with CORS rules gets a 401 withWWW-AuthenticateandAccess-Control-Allow-Origin.
Both need a container, so a Swift user; test_rgw_orphan_list.sh creates one with radosgw-admin user create --subuser=test:tester --key-type=swift.
There was a problem hiding this comment.
78354c0804a extends qa/workunits/rgw/test-swift-www-authenticate.py with both cases you asked for: anonymous GET with Origin on a container that has CORS rules (expects WWW-Authenticate and Access-Control-Allow-Origin), and FormPost with a bad signature (expects 401 + challenge). Setup uses a Swift subuser via radosgw-admin as in test_rgw_orphan_list.sh.
| def assert_swift_challenge(resp, realm_substring=None): | ||
| if resp.status_code != 401: | ||
| print('FAILED: expected 401, got %d' % resp.status_code) | ||
| sys.exit(1) | ||
| auth = resp.headers.get('WWW-Authenticate') or resp.headers.get('www-authenticate') | ||
| if not auth: | ||
| print('FAILED: missing WWW-Authenticate on 401') | ||
| sys.exit(1) | ||
| if 'Swift realm=' not in auth: | ||
| print('FAILED: WWW-Authenticate lacks Swift challenge: %r' % auth) | ||
| sys.exit(1) | ||
| if realm_substring is not None and realm_substring not in auth: | ||
| print('FAILED: expected realm containing %r in %r' % (realm_substring, auth)) | ||
| sys.exit(1) | ||
|
|
||
|
|
||
| def assert_no_crlf_injected_header(resp): | ||
| if 'X-Injected' in resp.headers: | ||
| print('FAILED: CRLF realm must not inject response headers: %r' % dict(resp.headers)) | ||
| sys.exit(1) |
There was a problem hiding this comment.
This can be shorter, stricter and faster:
requestsheaders are case-insensitive, so the second lookup isn't needed.- Comparing the whole header, e.g. with
'Swift realm="KEY_tester"', checks the realm exactly instead of by substring, and plainasserts can replace the print/exit pairs. - The bad-token cases fit in two tables of path and expected challenge, one per config. A default-config row for
/swift/v1/AUTH_nobodywould check that a container named like an account doesn't become the realm, which nothing tests yet. - The fixed 5 s waits make the test slow when the config change arrives quickly and fail when it takes longer. Polling one case every 0.1 s until its challenge changes, with a timeout, avoids both; the wait after
rmthen also makes sure later workunits see the default again.
There was a problem hiding this comment.
Same commit: workunit now uses a single WWW-Authenticate lookup, exact challenge strings, case tables for bad-token paths (including default-config /swift/v1/AUTH_nobody → unknown), and polling after ceph config set/rm instead of fixed 5 s sleeps.
0d3f7d2 to
78354c0
Compare
|
@Doracly — thank you for the time and care on this series of reviews. I do not want to miss anything useful in your notes; the goal is a smaller, correct diff, not a large one. Update (fork tip vstart repro: before applying the refactor I used a manual script for (A) anonymous GET + Happy to push further tweaks. Thanks again. |
78354c0 to
ab7ae31
Compare
|
vstart repro on a test cluster (
Case A matches your CORS/ |
Emit the Swift WWW-Authenticate challenge from dump_status() for every Swift 401 so CORS headers from end_header(s, op) stay intact and FormPost failures get the challenge without a handler-specific path. Keep the account realm from URL parsing in init_state.swift_account_realm and extend the workunit with CORS, FormPost, and stricter challenge checks. Signed-off-by: ramin.najarbashi <[email protected]>
ab7ae31 to
4208dba
Compare
Summary
WWW-Authenticateon HTTP 401 for Swift-protocol requests (RFC 9110 §15.5.2).Swift realm="AUTH_…"from the account in the URL (orunknown); optionalKeystone uri="…"whenrgw_keystone_urlis set.qa/workunits/rgw/test-swift-www-authenticate.pyfor vstart repro.Fixes: https://tracker.ceph.com/issues/82242
Repro gist (T6): https://gist.github.com/RaminNietzsche/818ad8dd6b8d8093560183cd09d2b169
Test plan
jenkins test make checkqa/workunits/rgw/test-swift-www-authenticate.pyrgw-rfc9110-repro.pySwift T6 cases showWWW-AuthenticateChecklist