Repository navigation
Expand file tree
/
Copy pathCaddyfile
More file actions
66 lines (57 loc) · 2.65 KB
/
Copy pathCaddyfile
File metadata and controls
66 lines (57 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# stackledger behind Caddy and oauth2-proxy: a fictitious example (Northwind, example.org).
# The recipe, with the oauth2-proxy flags, is in docs/hosting.md.
#
# One site, one audience: every request is authenticated first, by oauth2-proxy at 127.0.0.1:4180.
# Only the group `readers` in X-Auth-Request-Groups counts: whoever is in it sees everything, so
# put in it only the people who may see costs and contracts. Anyone else gets 403. An address of
# the old two-site layout (/full, /full/...) redirects to the same path at the root, after the
# check, so a reader's old links and bookmarks keep working. A request without a session is sent
# to the sign-in page. When oauth2-proxy cannot be reached, Caddy answers 502 and serves nothing
# (it fails closed).
#
# /srv/stackledger/publish holds the site files from stackledger build (everything except the
# .stackledger-build marker): index.html, the page folders, renewals.ics, _headers and robots.txt.
# Tested by test/integration/hosting-caddy.test.ts.
catalogue.example.org {
root * /srv/stackledger/publish
# oauth2-proxy's own pages: sign-in, callback, sign-out.
handle /oauth2/* {
reverse_proxy 127.0.0.1:4180 {
header_up X-Real-IP {remote_host}
header_up X-Forwarded-Uri {uri}
}
}
handle {
# route keeps the order below as written.
route {
# Drop any groups header the client sent: only oauth2-proxy's answer counts.
request_header -X-Auth-Request-Groups
forward_auth 127.0.0.1:4180 {
uri /oauth2/auth
copy_headers X-Auth-Request-Groups X-Auth-Request-Email
@signed_out status 401
handle_response @signed_out {
redir * /oauth2/sign_in?rd={scheme}://{host}{uri} 302
}
}
# oauth2-proxy sends the groups as a comma-separated list.
@refused not header_regexp X-Auth-Request-Groups (^|,)\s*readers\s*(,|$)
respond @refused 403
# Old two-site addresses: /full and /full/<path> are now /<path>. A path that starts with a
# second slash does not match, so the target can never be //other-host.
@old path_regexp old ^/full(?:/([^/].*)?)?$
redir @old /{re.old.1} 301
# The same headers stackledger writes into _headers, which Caddy does not read.
header {
Content-Security-Policy "default-src 'none'; script-src 'self'; style-src 'self'; img-src 'self' data:; font-src 'self'; connect-src 'none'; object-src 'none'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'"
X-Content-Type-Options nosniff
Referrer-Policy no-referrer
X-Robots-Tag "noindex, nofollow"
Permissions-Policy "camera=(), microphone=(), geolocation=()"
}
@calendar path *.ics
header @calendar Content-Type "text/calendar; charset=utf-8"
file_server
}
}
}