BareProxy Request Signing Plugin: Signed Requests to Backends and Expiring Signed URLs
Status: built, number 6 of 21 in BareProxy’s build order, and out in BareProxy 0.8.0 as signing.wasm on the releases page. Its manual, with code to check signatures and make links, is the README in the code repository.
Signing solves two different problems at the edge, and the plugin handles both, with one kind of signature: HMAC-SHA256, keyed with a secret from its config.
Proof That a Request Came Through the Proxy
An app behind a proxy trusts headers the proxy adds: the client’s address, the logged-in user from an auth gate, the country from geo rules. If anyone can reach the app directly, anyone can send those headers too. The usual answer is a private network, which isn’t always there.
The plugin signs each request it lets through: a timestamp, the method, the path and the headers you choose, keyed with a secret the app shares. The app checks the signature in a few lines, and a request that didn’t come through BareProxy, or was changed on the way, fails the check. Signature headers a client sends itself are thrown away first, so they can’t be faked.
One detail took some care. The app doesn’t always see the path the visitor asked for: BareProxy cleans paths up, and a route can strip a prefix, so /api/orders reaches the app as /orders. The plugin passes the path it signed in a header of its own, so the check never breaks on that.
Links That Expire
The other direction: a private file, a download for a paying customer, a preview link for a client. A signed link carries an expiry time and a signature in its query string, and only works until then. The plugin checks it before the request goes anywhere, and answers 403 to a link that was changed or has run out. A script makes the links with the same key; the manual has a one-line recipe for a shell and a few lines of Python.
Keys can be changed without breaking links already sent: list the new key and the old one, and take the old one off when its links have run out.
Here is a config:
plugin sign /etc/bareproxy/plugins/signing.wasm
config /etc/bareproxy/plugins/sign.conf
site files.example.com
use sign
route /private/* -> files /var/www/private
route /* -> app
And the plugin’s own:
# sign.conf
key app 3f9c2a7e5b1d4c8f9a0b6e2d7c4f1a8b3e5d9c0f2a7b6e1d4c8f3a9b2e7d5c1f
sign key app
sign-headers x-country x-user
links key app
link-path /private/
Keys live in the plugin’s config file. Changing one is a config change, which plan lists and rollback can undo. Every refused link carries a note in the request’s record saying why: a missing link, a changed one, one made with another key, or one that expired, and how long ago.
The whole program is on the plugins page.