swift/swift/common
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
..
middleware s3api: Stop propagating storage policy to sub-requests 2023-11-14 15:09:18 +00:00
ring ring: Centralize device normalization 2023-04-26 15:35:58 -07:00
utils slo: refactor GET/HEAD response handling 2023-11-10 15:26:28 -06:00
__init__.py Start using Hacking 2013-07-15 11:41:58 +02:00
base_storage_server.py Allow replication servers to handle all request methods 2020-07-23 09:11:07 -07:00
bufferedhttp.py bufferedhttp: Tolerate socket being None 2021-06-28 16:16:27 -07:00
constraints.py Deprecate per-service auto_create_account_prefix 2020-01-05 09:53:30 -06:00
container_sync_realms.py Drop more translations 2023-05-24 13:58:24 -07:00
daemon.py systemd: Send STOPPING/RELOADING notifications 2023-10-16 15:44:06 -07:00
db.py CI: test under py311 2023-06-22 17:28:12 -07:00
db_auditor.py db_auditor: remove logging translation 2022-11-16 18:26:25 +00:00
db_replicator.py Drop more translations 2023-05-24 13:58:24 -07:00
digest.py formpost: deprecate sha1 signatures 2022-07-26 10:39:58 +10:00
direct_client.py direct_client: support extra request params for direct_get_container. 2023-08-17 11:57:22 -07:00
error_limiter.py Proxy: add metrics related to error limiter. 2022-11-14 17:08:17 -08:00
exceptions.py Refactor db auditors into a db_auditor base class 2021-04-09 12:01:21 +10:00
header_key_dict.py py3: Fix s3api header casing 2019-11-20 12:14:35 -08:00
http.py s3api: Better handle 498/429 responses 2019-12-05 09:42:33 -08:00
http_protocol.py wsgi: bad request syntax response missing txn-id 2023-08-21 16:53:56 -07:00
internal_client.py InternalClient: error if allow_modify_pipeline is True 2023-04-14 10:46:45 +01:00
linkat.py pep8: Turn on E305 2020-04-03 21:22:38 +02:00
manager.py Add a swift-reload command 2023-10-16 15:44:06 -07:00
memcached.py proxy: emit metric when updating namespaces memcache set fails 2023-10-26 18:15:08 +01:00
recon.py recon: refactor common recon names into a common location 2021-06-29 15:22:57 -07:00
registry.py Add docs for registry module 2022-02-10 11:17:06 -08:00
request_helpers.py slo: refactor GET/HEAD response handling 2023-11-10 15:26:28 -06:00
splice.py pep8: Turn on E305 2020-04-03 21:22:38 +02:00
storage_policy.py Add ring_ip option to object services 2022-06-02 16:31:29 -05:00
swob.py slo: refactor GET/HEAD response handling 2023-11-10 15:26:28 -06:00
wsgi.py systemd: Send STOPPING/RELOADING notifications 2023-10-16 15:44:06 -07:00