From 8c4e65a6b5cf14dc0335674cfe8018c1825987e1 Mon Sep 17 00:00:00 2001 From: Tim Burke Date: 2021年9月23日 10:31:42 -0700 Subject: [PATCH] staticweb: Work with prefix-based tempurls Note that there's a bit of a privilege escalation as prefix-based tempurls can now be used to perform listings -- but only on containers with staticweb enabled. Since having staticweb enabled was previously pretty useless unless the container was both public and publicly-listable, I think it's probably fine. This also allows tempurls to be used at the container level, but only for staticweb responses. Change-Id: I7949185fdd3b64b882df01d54a8bc158ce2d7032 --- swift/common/middleware/staticweb.py | 53 ++++- swift/common/middleware/tempurl.py | 219 +++++++++++------- test/functional/test_staticweb.py | 214 +++++++++++++++++ test/functional/test_tempurl.py | 41 ++-- test/unit/common/middleware/test_staticweb.py | 66 ++++++ test/unit/common/middleware/test_tempurl.py | 103 +++++--- 6 files changed, 550 insertions(+), 146 deletions(-) diff --git a/swift/common/middleware/staticweb.py b/swift/common/middleware/staticweb.py index df52bb0ebd..7770af208f 100644 --- a/swift/common/middleware/staticweb.py +++ b/swift/common/middleware/staticweb.py @@ -59,7 +59,8 @@ requests for paths not found. For pseudo paths that have no , this middleware can serve HTML file listings if you set the ``X-Container-Meta-Web-Listings: true`` metadata item -on the container. +on the container. Note that the listing must be authorized; you may want a +container ACL like ``X-Container-Read: .r:*,.rlistings``. If listings are enabled, the listings can have a custom style sheet by setting the X-Container-Meta-Web-Listings-CSS header. For instance, setting @@ -68,6 +69,17 @@ the .../listing.css style sheet. If you "view source" in your browser on a listing page, you will see the well defined document structure that can be styled. +Additionally, prefix-based :ref:`tempurl` parameters may be used to authorize +requests instead of making the whole container publicly readable. This gives +clients dynamic discoverability of the objects available within that prefix. + +.. note:: + + ``temp_url_prefix`` values should typically end with a slash (``/``) when + used with StaticWeb. StaticWeb's redirects will not carry over any TempURL + parameters, as they likely indicate that the user created an overly-broad + TempURL. + By default, the listings will be rendered with a label of "Listing of /v1/account/container/path". This can be altered by setting a ``X-Container-Meta-Web-Listings-Label: