Files
pages/deploy/kubernetes/exhibition/root-storage-check.yaml.example
T
Anya Tokugawa 4a863fe63c chore(exhibition): preserve deployment and synthetic demo tooling
Separate one-time bootstrap, historical deployment examples and local validation. Document final hostname and historical status; exclude credentials and runtime data.
2026-11-30 23:14:24 +09:00

104 lines
4.6 KiB
Plaintext

# Isolated root initialization followed by a non-root storage test.
# Does not inspect or change existing data or the PVC root permissions.
apiVersion: batch/v1
kind: Job
metadata:
name: pageswiki-root-storage-check
spec:
backoffLimit: 0
activeDeadlineSeconds: 120
ttlSecondsAfterFinished: 3600
template:
spec:
restartPolicy: Never
automountServiceAccountToken: false
securityContext:
runAsUser: 0
runAsGroup: 0
seccompProfile:
type: RuntimeDefault
containers:
- name: check
image: python:3.13-alpine
command: [python3, -u, -c]
args:
- |
import hashlib, json, os, pathlib, tempfile
mount = None
for line in pathlib.Path('/proc/self/mountinfo').read_text().splitlines():
before, after = line.split(' - ', 1)
fields, detail = before.split(), after.split()
if fields[4] == '/check':
mount = (detail[0], set(fields[5].split(',')) | set(detail[2].split(',')))
if mount is None:
raise RuntimeError('PVC mount not found')
fs, options = mount
if fs in ('nfs', 'nfs4') and ('hard' not in options or options & {'soft', 'softerr', 'softreval'}):
raise RuntimeError('NFS hard mount required')
root = pathlib.Path(tempfile.mkdtemp(prefix='.pageswiki-root-check-', dir='/check'))
print(json.dumps({'stage': 'created', 'directory': root.name, 'filesystem': fs, 'hard_mount': 'hard' in options}))
try:
os.chown(root, 10001, 10001)
pid = os.fork()
if pid == 0:
try:
os.setgroups([])
os.setgid(10001)
os.setuid(10001)
directory = os.open(root, os.O_RDONLY | os.O_DIRECTORY)
payload = b'PagesWiki isolated non-root storage verification\n'
try:
with (root / 'source').open('xb') as f:
f.write(payload)
f.flush()
os.fsync(f.fileno())
os.link(root / 'source', root / 'published')
try:
os.link(root / 'source', root / 'published')
except FileExistsError:
pass
else:
raise RuntimeError('no-replace publication failed')
os.rename(root / 'source', root / 'renamed')
os.fsync(directory)
for name in ('published', 'renamed'):
if hashlib.sha256((root / name).read_bytes()).digest() != hashlib.sha256(payload).digest():
raise RuntimeError('readback mismatch')
print(json.dumps({'result': 'passed', 'process_uid': os.getuid(), 'process_gid': os.getgid(), 'server_durability': 'not verified'}))
finally:
for name in ('source', 'published', 'renamed'):
(root / name).unlink(missing_ok=True)
os.fsync(directory)
os.close(directory)
except BaseException:
import traceback
traceback.print_exc()
os._exit(1)
os._exit(0)
_, status = os.waitpid(pid, 0)
if os.waitstatus_to_exitcode(status) != 0:
raise RuntimeError('non-root storage verification failed')
finally:
# Only remove the empty directory created by this process.
root.rmdir()
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: [ALL]
add: [CHOWN, SETUID, SETGID]
resources:
requests:
cpu: 100m
memory: 64Mi
limits:
cpu: 250m
memory: 128Mi
volumeMounts:
- name: data
mountPath: /check
volumes:
- name: data
persistentVolumeClaim:
claimName: pageswiki-data