fix(nodes): validate renewal hooks and record five-node acceptance
This commit is contained in:
1 parent
6b0ac99d19
commit
d085e211b3
6 files changed
+119
-17
No files matched your search
@@ -73,19 +73,31 @@ class SiteAdapter:
|
||||
owned=bool(owner and json.loads(owner).get('request_sha256')==n['request_sha256'])
|
||||
script=r"""from pathlib import Path
|
||||
import re
|
||||
def hook_options(path):
|
||||
for line in path.read_text().splitlines():
|
||||
match=re.match(r'^\s*([A-Za-z0-9_-]+)\s*=(.*)$',line)
|
||||
if match:
|
||||
key=match.group(1).lower().replace('-','_')
|
||||
if key.endswith('_hook'):yield key,match.group(2).strip()
|
||||
for name in ['/etc/letsencrypt/cli.ini','/root/.config/letsencrypt/cli.ini']:
|
||||
p=Path(name)
|
||||
if p.exists():
|
||||
for line in p.read_text().splitlines():
|
||||
if re.match(r'^\s*(pre[-_]hook|post[-_]hook|deploy[-_]hook)\s*=\s*\S',line):raise SystemExit(2)
|
||||
if p.exists() and any(value for key,value in hook_options(p)):raise SystemExit(2)
|
||||
# Both normal and Snap directory hooks need an explicit independent review.
|
||||
for name in ['/etc/letsencrypt/renewal-hooks','/var/snap/certbot/common/letsencrypt/renewal-hooks']:
|
||||
p=Path(name)
|
||||
if p.is_symlink() or (p.exists() and any(x.is_file() or x.is_symlink() for x in p.rglob('*'))):raise SystemExit(6)
|
||||
domain=DOMAIN
|
||||
paths=[Path('/etc/letsencrypt')/kind/domain for kind in ['live','archive']]+[Path('/etc/letsencrypt/renewal')/(domain+'.conf')]
|
||||
if not OWNED and any(p.exists() or p.is_symlink() for p in paths):raise SystemExit(3)
|
||||
p=paths[-1]
|
||||
if p.exists():
|
||||
for line in p.read_text().splitlines():
|
||||
if re.match(r'^\s*(pre_hook|post_hook)\s*=\s*\S',line):raise SystemExit(4)
|
||||
if re.match(r'^\s*deploy_hook\s*=',line) and line.split('=',1)[1].strip()!=HOOK:raise SystemExit(5)
|
||||
seen_hook=False
|
||||
for key,value in hook_options(p):
|
||||
if key in ('deploy_hook','renew_hook'):
|
||||
if seen_hook:raise SystemExit(5)
|
||||
seen_hook=True
|
||||
if value!=HOOK:raise SystemExit(5)
|
||||
elif value:raise SystemExit(4)
|
||||
"""
|
||||
prefix='DOMAIN='+repr(n['tls_domain'])+';OWNED='+repr(owned)+';HOOK='+repr('/bin/sh '+self.ctx['node_root']+'/renew-node.sh')+'\n'
|
||||
execute(node,"python3 - <<'DPLCERTGATE'\n"+prefix+script+"\nDPLCERTGATE")
|
||||
|
||||
Reference in new issue
Block a user