Add M9.8f dev session route design, disabled with fail-closed policy
ADR-0087 records the maintainer's route (void.aeternalisgames.com:7400 via a dedicated internal MetalLB VIP to the evolution-dev region pod, TLS end to end, CIDR-limited) and operator-opened windows enforced by evo-server. The route is a kustomize component included nowhere; the policy check encodes its shape and refuses enabling until VIP/CIDR, the dev quota and --session-window exist, with a 20-case self-test in the CI deploy stage. The base listener stays loopback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+120
-12
@@ -24,8 +24,14 @@ environment-isolation or World0-protection invariant is broken:
|
||||
required; upgrade-rehearsal flags never appear in a deployed workload;
|
||||
- the Pods the backup and barrier scripts generate (rendered with --print-manifest)
|
||||
keep the database-tool security contract: non-root 10001 with fsGroup 10001 so
|
||||
the 0440 Secret files are readable, no token, read-only root, no escalation.
|
||||
the 0440 Secret files are readable, no token, read-only root, no escalation;
|
||||
- the dev session route (ADR-0087): loopback listener everywhere except the
|
||||
evolution-dev route component; that component is the only LoadBalancer and the
|
||||
only Service on the session port, narrowly shaped, and it cannot be enabled while
|
||||
markers are unresolved or before server-enforced session windows exist.
|
||||
"""
|
||||
import ipaddress
|
||||
import re
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
@@ -55,7 +61,15 @@ for base, _, files in os.walk(os.path.join(ROOT, 'deploy')):
|
||||
path = os.path.join(base, name)
|
||||
manifests[os.path.relpath(path, ROOT).replace(os.sep, '/')] = documents(path)
|
||||
objects = [(p, d) for p, ds in manifests.items() for d in ds
|
||||
if 'kind' in d and d['kind'] != 'Kustomization']
|
||||
if 'kind' in d and d['kind'] not in ('Kustomization', 'Component')]
|
||||
# Files used as kustomize patches hold partial objects (checked only for what they set).
|
||||
patch_files = set()
|
||||
for p, ds in manifests.items():
|
||||
if p.endswith('kustomization.yaml') and ds:
|
||||
for entry in ds[0].get('patches', []):
|
||||
target = entry.get('path') if isinstance(entry, dict) else entry
|
||||
if target:
|
||||
patch_files.add(os.path.normpath(os.path.join(os.path.dirname(p), target)).replace(os.sep, '/'))
|
||||
|
||||
# Secrets and service-account tokens.
|
||||
for path, doc in objects:
|
||||
@@ -84,6 +98,21 @@ check(dns.get('policyTypes') == ['Egress'] and set(dns_ports) == {53} and len(dn
|
||||
quota = base.get('ResourceQuota/aevolution-quota', {}).get('spec', {}).get('hard', {})
|
||||
check(quota.get('services.loadbalancers') == '0' and quota.get('services.nodeports') == '0',
|
||||
'quota must forbid LoadBalancer and NodePort services')
|
||||
# ADR-0087: only the dev overlay may raise LoadBalancers, to exactly one, and only
|
||||
# together with the session route; node ports stay forbidden everywhere.
|
||||
ROUTE = 'deploy/kubernetes/region/dev-session-route/'
|
||||
route_users = sorted(p for p, ds in manifests.items() if p.endswith('kustomization.yaml') and ds
|
||||
and any('dev-session-route' in str(e) for e in ds[0].get('resources', []) + ds[0].get('components', [])))
|
||||
route_enabled = route_users == ['deploy/kubernetes/region/dev/kustomization.yaml']
|
||||
check(route_users in ([], ['deploy/kubernetes/region/dev/kustomization.yaml']),
|
||||
f'only region/dev may include the dev session route: {route_users}')
|
||||
for path, doc in objects:
|
||||
if doc['kind'] == 'ResourceQuota' and path != f'{platform}/base/quota.yaml':
|
||||
hard = doc.get('spec', {}).get('hard', {})
|
||||
check(hard.get('services.nodeports', '0') == '0', f'{path}: node ports stay forbidden')
|
||||
allowed = ('0', '1') if path.startswith(f'{platform}/dev/') and route_enabled else ('0',)
|
||||
check(hard.get('services.loadbalancers', '0') in allowed,
|
||||
f'{path}: LoadBalancers only in evolution-dev, at most one, with the session route')
|
||||
for env in ('dev', 'stage', 'world0'):
|
||||
k = f'{platform}/{env}/kustomization.yaml'
|
||||
ns_path = f'{platform}/{env}/namespace.yaml'
|
||||
@@ -212,7 +241,7 @@ for path, doc in objects:
|
||||
for path, doc in objects:
|
||||
# Overlay patches (region-values.yaml) are partial objects; the base is complete.
|
||||
if (doc['kind'] == 'Deployment' and doc['metadata'].get('name') == 'evo-region'
|
||||
and not path.endswith('region-values.yaml')):
|
||||
and path not in patch_files):
|
||||
spec = doc['spec']
|
||||
pod = spec['template']['spec']
|
||||
container = pod['containers'][0]
|
||||
@@ -238,22 +267,101 @@ for path, doc in objects:
|
||||
# M9.7 (ADR-0083): dev sessions are a drill-time override as well.
|
||||
if variable.get('name') == 'REGION_SESSION':
|
||||
check(variable.get('value') == '', f'{path}: dev sessions are never enabled in Git')
|
||||
# M9.7 (ADR-0083): the session listener is loopback-only (kubectl port-forward), and its
|
||||
# Secret is optional, 0440 and never exposed through a Service port.
|
||||
# M9.7 (ADR-0083) and M9.8f (ADR-0087): the session listener is loopback (kubectl
|
||||
# port-forward) everywhere except the evolution-dev route component; its Secret is
|
||||
# optional and 0440; only that component's Service exposes the session port.
|
||||
for path, doc in objects:
|
||||
if path.startswith('deploy/kubernetes/region/') and doc['kind'] == 'Deployment' and not path.endswith('region-values.yaml'):
|
||||
if path.startswith('deploy/kubernetes/region/') and doc['kind'] == 'Deployment':
|
||||
pod = doc['spec']['template']['spec']
|
||||
for container in pod.get('containers', []):
|
||||
for variable in container.get('env', []):
|
||||
if variable.get('name') == 'REGION_SESSION_LISTEN':
|
||||
expected = '0.0.0.0:7400' if path.startswith(ROUTE) else '127.0.0.1:7400'
|
||||
check(variable.get('value') == expected,
|
||||
f'{path}: REGION_SESSION_LISTEN must be {expected} here')
|
||||
if path in patch_files:
|
||||
continue
|
||||
script = ' '.join(pod['containers'][0].get('args', []))
|
||||
check('--session-listen 127.0.0.1:' in script and '0.0.0.0:7400' not in script,
|
||||
f'{path}: the session listener binds loopback only')
|
||||
check('--session-listen "$REGION_SESSION_LISTEN"' in script and '0.0.0.0' not in script.replace('--ops-listen 0.0.0.0:9100', ''),
|
||||
f'{path}: the session listener address comes only from REGION_SESSION_LISTEN')
|
||||
for volume in pod.get('volumes', []):
|
||||
if volume.get('secret', {}).get('secretName') == 'evolution-dev-session':
|
||||
check(volume['secret'].get('optional') is True and volume['secret'].get('defaultMode') == 0o440,
|
||||
f'{path}: the dev session Secret is optional and 0440')
|
||||
route_ranges = []
|
||||
for path, doc in objects:
|
||||
if doc['kind'] == 'Service':
|
||||
for port in doc['spec'].get('ports', []):
|
||||
check(port.get('port') != 7400 and port.get('targetPort') not in (7400, 'session'),
|
||||
f'{path}: the dev session port is never exposed by a Service')
|
||||
spec = doc['spec']
|
||||
session_port = any(port.get('port') == 7400 or port.get('targetPort') in (7400, 'session')
|
||||
for port in spec.get('ports', []))
|
||||
is_route = path == ROUTE + 'service.yaml' and doc['metadata'].get('name') == 'evo-region-session'
|
||||
if not is_route:
|
||||
check(not session_port, f'{path}: only the dev session route Service may expose the session port')
|
||||
check(spec.get('type', 'ClusterIP') == 'ClusterIP',
|
||||
f'{path}: {spec.get("type")} Services are forbidden (ADR-0069)')
|
||||
continue
|
||||
route_ranges = spec.get('loadBalancerSourceRanges', [])
|
||||
check(spec.get('type') == 'LoadBalancer' and spec.get('externalTrafficPolicy') == 'Local'
|
||||
and spec.get('allocateLoadBalancerNodePorts') is False,
|
||||
f'{path}: the route is a LoadBalancer with Local traffic policy and no node ports')
|
||||
check(spec.get('ports') == [{'name': 'session', 'port': 7400, 'targetPort': 'session', 'protocol': 'TCP'}],
|
||||
f'{path}: the route exposes exactly TCP 7400')
|
||||
check(spec.get('selector') == {'app.kubernetes.io/name': 'evo-region'},
|
||||
f'{path}: the route selects only the region pod')
|
||||
annotations = doc['metadata'].get('annotations', {})
|
||||
check(set(annotations) == {'metallb.io/loadBalancerIPs'},
|
||||
f'{path}: only a pinned MetalLB address annotation (no PROXY protocol or sharing)')
|
||||
vip = annotations.get('metallb.io/loadBalancerIPs', '')
|
||||
check(len(route_ranges) >= 1, f'{path}: loadBalancerSourceRanges must name the permitted CIDRs')
|
||||
if not vip.startswith('REPLACE'):
|
||||
try:
|
||||
check(ipaddress.ip_address(vip).is_private, f'{path}: the VIP must be an internal address')
|
||||
except ValueError:
|
||||
check(False, f'{path}: the VIP must be one IP address')
|
||||
for cidr in route_ranges:
|
||||
if cidr.startswith('REPLACE'):
|
||||
continue
|
||||
try:
|
||||
network = ipaddress.ip_network(cidr)
|
||||
check(network.is_private and network.prefixlen >= (16 if network.version == 4 else 48),
|
||||
f'{path}: {cidr} must be a private range no wider than /16 (IPv6 /48)')
|
||||
except ValueError:
|
||||
check(False, f'{path}: {cidr} is not a CIDR')
|
||||
if doc['kind'] == 'Ingress':
|
||||
text = yaml.safe_dump(doc)
|
||||
check('7400' not in text and 'session' not in text,
|
||||
f'{path}: the dev session is raw TCP, never an Ingress (ADR-0087)')
|
||||
policies = [(p, d) for p, d in objects if p.startswith(ROUTE) and d['kind'] == 'NetworkPolicy']
|
||||
check(len(policies) == 1, f'{ROUTE}: exactly one session ingress policy')
|
||||
for path, doc in policies:
|
||||
spec = doc['spec']
|
||||
rules = spec.get('ingress', [])
|
||||
blocks = [peer.get('ipBlock', {}) for rule in rules for peer in rule.get('from', [])]
|
||||
check(spec.get('podSelector') == {'matchLabels': {'app.kubernetes.io/name': 'evo-region'}}
|
||||
and spec.get('policyTypes') == ['Ingress'] and len(rules) == 1
|
||||
and rules[0].get('ports') == [{'protocol': 'TCP', 'port': 7400}],
|
||||
f'{path}: the session policy admits only TCP 7400 to the region pod')
|
||||
check(all(set(b) == {'cidr'} for b in blocks) and len(blocks) == len(rules[0].get('from', []))
|
||||
and sorted(b.get('cidr') for b in blocks) == sorted(route_ranges),
|
||||
f'{path}: the session policy admits exactly the Service source ranges')
|
||||
for path, doc in objects:
|
||||
if path.startswith(ROUTE):
|
||||
check(doc.get('metadata', {}).get('namespace') in (None, 'evolution-dev'),
|
||||
f'{path}: the session route belongs to evolution-dev only')
|
||||
# Enabling the route fails closed until its values are real and the server enforces
|
||||
# operator-opened windows itself (expiry survives restarts; ADR-0087).
|
||||
if route_enabled:
|
||||
for name in os.listdir(os.path.join(ROOT, ROUTE)):
|
||||
with open(os.path.join(ROOT, ROUTE, name), encoding='utf-8') as handle:
|
||||
check('REPLACE' not in handle.read(), f'{ROUTE}{name}: unresolved REPLACE marker with the route enabled')
|
||||
base_script = ' '.join(' '.join(c.get('args', [])) for p, d in objects
|
||||
if p == 'deploy/kubernetes/region/base/deployment.yaml' and d['kind'] == 'Deployment'
|
||||
for c in d['spec']['template']['spec']['containers'])
|
||||
check('--session-window' in base_script,
|
||||
'the dev session route needs server-enforced session windows (--session-window, ADR-0087)')
|
||||
dev_quota = [d.get('spec', {}).get('hard', {}).get('services.loadbalancers') for p, d in objects
|
||||
if d['kind'] == 'ResourceQuota' and p.startswith(f'{platform}/dev/')]
|
||||
check(dev_quota == ['1'], 'the dev quota must allow exactly one LoadBalancer for the route')
|
||||
for env in ('dev', 'stage'):
|
||||
overlay = f'deploy/kubernetes/region/{env}/'
|
||||
images = manifests.get(overlay + 'kustomization.yaml', [{}])[0].get('images', [])
|
||||
@@ -311,7 +419,7 @@ for directory, _, files in os.walk(os.path.join(ROOT, 'deploy', 'kubernetes')):
|
||||
# M8.9 scheduling (ADR-0076). Node-local volumes pin their pods: added CPU does not
|
||||
# make the objects volume portable. Compute is a preference so one node still works.
|
||||
for path, doc in objects:
|
||||
if doc['kind'] not in workload_kinds or path.endswith('region-values.yaml'):
|
||||
if doc['kind'] not in workload_kinds or path in patch_files:
|
||||
continue
|
||||
spec = doc.get('spec', {})
|
||||
pod = spec.get('jobTemplate', {}).get('spec', {}).get('template', {}).get('spec') \
|
||||
|
||||
Reference in New Issue
Block a user