authoravatarclover caruso<git@paperclover.net>2026-10-17 04:40:02-07:00
committeravatarclover caruso<git@paperclover.net>2026-10-21 02:52:29-07:00
logb73fb93bbf37ad4de7502141fec2d1c1ff4f27fd
tree0d9e83b8ae2d5b373226ffef28c7e45fb4218ce6
parent129b355b89c28ac75a69758310ca0e2f0a6b7d7c
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

Keep public mirror history and operational files private


4 files changed, 29 insertions(+), 6 deletions(-)

service/copyparty/copyparty.conf+2
......@@ -55,5 +55,7 @@
5555 r: *
5656 A: snow
5757 flags:
58 md_hist: n
59 zip_who: 2
5860 chmod_f: 664
5961 chmod_d: 775
tools/router-zig-test.py+22-3
......@@ -51,8 +51,8 @@ def main():
5151 port = listener.getsockname()[1]
5252 lines = ['{', ' admin off', ' auto_https off', '}']
5353 with patch.dict(os.environ, {'SNOWGLOBE_STATE': temporary}):
54 for host, service in [('prod.localhost', 'copyparty'), ('paired.localhost', paired), ('unpaired.localhost', 'copyparty-preview-ffffffff')]:
55 lines += [f'http://{host}:{port} {{', *router.zig_mirror_routes(service, routes), ' handle {', ' respond 204', ' }', '}']
54 for host, service in [('prod.localhost', 'copyparty'), ('paired.localhost', paired), ('unpaired.localhost', 'copyparty-preview-ffffffff'), ('missing.localhost', 'copyparty')]:
55 lines += [f'http://{host}:{port} {{', *router.zig_mirror_routes(service, {} if host == 'missing.localhost' else routes), ' handle {', ' respond 204', ' }', '}']
5656 conf = root / 'Caddyfile'
5757 conf.write_text('\n'.join(lines))
5858 validated = subprocess.run([str(args.caddy), 'validate', '--config', str(conf), '--adapter', 'caddyfile'], capture_output=True, text=True)
......@@ -89,9 +89,28 @@ def main():
8989 for path in ['/mirrors/zig/', '/mirrors/zig/releases/', '/mirrors/zig/dev/', '/mirrors/zig/releases/zig-0.0.0.tar.xz',
9090 '/mirrors/zig/preadme.md', '/mirrors/zig/not-zig.zip']:
9191 assert request(host, path) == (204, b'')
92 for path in ['/mirrors/zig/.hist/preadme.md', '/mirrors/zig/.mirror-locks/file', '/mirrors/.secret',
93 '/mirrors/zig/nested/.secret/file', '/mirrors/zig/%2ehist/file', '/mirrors/zig/%2Ehist/file',
94 '/mirrors/zig%2f.hist/file', '/mirrors/zig%2F.hist/file', '//mirrors///zig//.hist/file',
95 '/mirrors/zig/normal/../.hist/file', '/before/../mirrors/zig/.hist/file',
96 '/mirrors/zig/?doc=.secret', '/mirrors/zig/?DOC=%2esecret',
97 '/mirrors/zig/?doc=readme.md&DOC=.secret', '/mirrors/zig/?DOC=.secret&doc=readme.md',
98 '/mirrors/zig/?doc=%2Esecret', '/mirrors/zig/?x=1&DoC=.secret']:
99 count = len(Mirror.requests)
100 assert request(host, path) == (404, b''), path
101 assert request(host, path, method='HEAD') == (404, b''), path
102 assert len(Mirror.requests) == count
103 for path in ['/media/zig/.hist/preadme.md', '/media/?doc=.secret', '/.static/copyparty.css',
104 '/mirrors/zig/?download=1', '/mirrors/zig/?x=doc=readme.md',
105 '/mirrors/zig/?doc=preadme.md', '/mirrors/zig/?doc=regular.zip',
106 '/mirrors/zig/?DOC=visible.md', '/mirrors/zig/?doc', '/mirrors/zig/?x=1&DoC=visible.md']:
107 assert request(host, path) == (204, b''), path
92108 assert request(host, archive, method='POST') == (204, b'')
93109 count = len(Mirror.requests)
94 assert request('unpaired.localhost', archive) == (503, b'')
110 for host in ['unpaired.localhost', 'missing.localhost']:
111 assert request(host, archive) == (503, b'')
112 assert request(host, '/mirrors/zig/.hist/file') == (404, b'')
113 assert request(host, '/mirrors/zig/?DOC=.secret') == (404, b'')
95114 assert len(Mirror.requests) == count
96115 finally:
97116 caddy.terminate()
tools/router.py+4-2
......@@ -119,7 +119,9 @@ def zig_mirror_routes(service, routes):
119119 mirror = None
120120 upstreams = set().union(*(route["upstreams"] for route in routes.values() if mirror in route["services"]))
121121 pattern = r"^/mirrors/zig/zig[^/]*\.(?:tar\.xz|zip)(?:\.minisig)?$"
122 lines = [" @zig_mirror {", " method GET HEAD", f" path_regexp zig_mirror {pattern}", " }",
122 lines = [" @mirror_private expression `path_regexp('^/+mirrors(?:/+[^/]*)*/+[.]') || (path_regexp('^/+mirrors(?:/|$)') && {http.request.uri.query}.matches('(?i)(^|&)doc=(?:[.]|%2e)'))`",
123 " handle @mirror_private {", " respond 404", " }",
124 " @zig_mirror {", " method GET HEAD", f" path_regexp zig_mirror {pattern}", " }",
123125 " handle @zig_mirror {"]
124126 if upstreams:
125127 if any(not re.fullmatch(r"127\.0\.0\.1:[0-9]+|\[::1\]:[0-9]+", upstream) for upstream in upstreams):
......@@ -349,7 +351,7 @@ def render(token):
349351 continue
350352 lines += [" tracing {", f" span {service}", " span_attributes {",
351353 f" snowglobe.service {service}", " snowglobe.kind edge", " }", " }"]
352 if (service == "copyparty" and "zig-mirror" in internal_services) or re.fullmatch(r"copyparty-preview-[0-9a-f]{8}", service):
354 if service == "copyparty" or re.fullmatch(r"copyparty-preview-[0-9a-f]{8}", service):
353355 lines += zig_mirror_routes(service, routes)
354356 manifest = os.path.join(ROUTE_DIR, service + ".json")
355357 assets = {}
tools/zig-mirror.md+1-1
......@@ -49,7 +49,7 @@ group. Run the mirror image's `verify` command against the copied destination
4949before publishing it. A disposable container can bind that exact subtree
5050read-only. The checksum and authenticity passes may run concurrently with
5151bounded CPU/I/O to reuse the filesystem cache. Both must finish successfully.
52Retain old `.hist` metadata privately; anonymous users lack dot-file permission.
52Retain old `.hist` metadata privately; verify that public URLs cannot fetch it.
5353
5454Promote the reviewed configuration through `tools/deploy.py prod`. Do not replace
5555containers by hand. Confirm anonymous GET/HEAD/Range on flat and nested URLs,