Skip to content

Latest commit

 

History

History
55 lines (42 loc) · 2.62 KB

access.md

File metadata and controls

55 lines (42 loc) · 2.62 KB

Restrict access to an app

Proxy applies these rules to each route, including when you run Proxy standalone. In this example, the public site stays open while the admin app requires a connection from the office or VPN and a user name and password.

Set the rules in the site files

Each object below is one site file in data/sites, named after its id (for example data/sites/admin.json) and saved without the id field. Proxy applies a saved file by itself.

[
  {
    "id": "website",
    "hosts": ["www.example.com"],
    "target": "http://website:8000",
    "cert": "auto"
  },
  {
    "id": "admin",
    "hosts": ["admin.example.com"],
    "target": "http://admin:8000",
    "cert": "auto",
    "allow": ["10.42.0.0/16", "2001:db8:42::/48"],
    "deny": ["10.42.0.18"],
    "auth": [
      { "user": "ana", "hash": "REPLACE_WITH_GENERATED_HASH" }
    ],
    "headers": {
      "X-Frame-Options": "SAMEORIGIN"
    }
  }
]

Replace the example networks with the source addresses Proxy sees. Both lists accept individual IPv4 and IPv6 addresses and CIDR ranges. An empty or omitted allow lets any address through the list check. deny takes priority when an address matches both lists. Proxy uses the address of the connecting peer, so behind another proxy the rules see that proxy's address.

For Compose, mount the data folder as shown in the complete example.

Generate a password hash

From an Proxy source checkout, run this in Bash. The password is entered without echo and passed to Node through stdin.

IFS= read -rs -p 'App password: ' PROXY_PASSWORD
printf '\n'
printf '%s' "$PROXY_PASSWORD" | node -e 'const fs = require("node:fs"); console.log(require("./lib/guard").hash(fs.readFileSync(0, "utf8")))'
unset PROXY_PASSWORD

Paste the resulting hash into the route in place of REPLACE_WITH_GENERATED_HASH. Add one entry per user. Omit auth to use only the IP rules. Serve routes with passwords over HTTPS. Proxy verifies the password and removes the Basic credentials before forwarding to the app.

Check the result

From an address outside the allowed ranges, the admin route returns 403. From an allowed address without credentials, it returns 401 and prompts the browser for a login. With the correct credentials, it serves the app and adds X-Frame-Options when the app has not set that header. IP and password checks also apply to WebSocket upgrades to the app.

Allow public HTTP for the ACME HTTP challenge when using cert: auto. Proxy answers that challenge itself. To serve a site only on internal DNS with a certificate, use a custom certificate that covers the internal name.