swift/swift/common/middleware/s3api
Alistair Coles 60c04f116b s3api: Stop propagating storage policy to sub-requests
The proxy_logging middleware needs an X-Backend-Storage-Policy-Index
header to populate the storage policy field in logs, and will look in
both request and response headers to find it.

Previously, the s3api middleware would indiscriminately copy the
X-Backend-Storage-Policy-Index from swift backend requests into the
S3Request headers [1]. This works for logging but causes the header
to leak between backend requests [2] and break mixed policy
multipart uploads. This patch sets the X-Backend-Storage-Policy-Index
header on s3api responses rather than requests.

Additionally, the middleware now looks for the
X-Backend-Storage-Policy-Index header in the swift backend request
*and* response headers, in the same way that proxy_logging would
(preferring a response header over a request header). This means that
a policy index is now logged for bucket requests, which only have
X-Backend-Storage-Policy-Index header in their response headers.

The s3api adds the value from the *final* backend request/response
pair to its response headers. Returning the policy index from the
final backend request/response is consistent with swift.backend_path
being set to that backend request's path i.e. proxy_logging will log
the correct policy index for the logged path.

The FakeSwift helper no longer looks in registered object responses
for an X-Backend-Storage-Policy-Index header to update an object
request. Real Swift object responses do not have an
X-Backend-Storage-Policy-Index header. By default, FakeSwift will now
update *all* object requests with an X-Backend-Storage-Policy-Index as
follows:

  - If a matching container HEAD response has been registered then
    any X-Backend-Storage-Policy-Index found with that is used.
  - Otherwise the default policy index is used.

Furthermore, FakeSwift now adds the X-Backend-Storage-Policy-Index
header to the request *after* the request has been captured. Tests
using FakeSwift.calls_wth_headers() to make assertions about captured
headers no longer need to make allowance for the header that FakeSwift
added.

Co-Authored-By: Clay Gerrard <clay.gerrard@gmail.com>
Closes-Bug: #2038459
[1] Related-Change: I5fe5ab31d6b2d9f7b6ecb3bfa246433a78e54808
[2] Related-Change: I40b252446b3a1294a5ca8b531f224ce9c16f9aba
Change-Id: I2793e335a08ad373c49cbbe6759d4e97cc420867
2023-11-14 15:09:18 +00:00
..
controllers s3api: Stop propagating storage policy to sub-requests 2023-11-14 15:09:18 +00:00
schema s3api: Make the 'Quiet' key value case insensitive 2022-03-24 20:22:21 +01:00
__init__.py Import swift3 into swift repo as s3api middleware 2018-04-27 15:53:57 +09:00
acl_handlers.py Do not fetch content of container/object to retrieve S3 ACLs 2022-01-13 15:04:36 +01:00
acl_utils.py s3api: Add best-effort support for more canned ACLs 2022-05-31 10:01:18 -07:00
etree.py Switch from pkg_resources to importlib 2023-01-31 15:41:48 -08:00
exception.py s3api errors for unsupported headers x-delete-at, x-delete-after 2022-12-01 13:21:01 -08:00
s3api.py s3api: Stop propagating storage policy to sub-requests 2023-11-14 15:09:18 +00:00
s3request.py s3api: Stop propagating storage policy to sub-requests 2023-11-14 15:09:18 +00:00
s3response.py Include accept-ranges header in s3api response 2023-10-13 16:39:09 +00:00
s3token.py s3token: Only replace access_key_id in account 2022-05-31 11:24:56 -07:00
subresource.py s3api: Make grentee types case insensitive 2022-06-20 18:52:09 +02:00
utils.py Round s3api listing LastModified to integer resolution 2022-05-10 11:26:27 +01:00