forked from mtusi2026/mtusi2026lab4
Implement lab4 private S3 attachments, safe reconciliation and defense guide
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Run committed solution from a real local clone, new credentials and volumes."""
|
||||
import json,os,socket,subprocess,tempfile,uuid
|
||||
from pathlib import Path
|
||||
ROOT=Path(__file__).resolve().parents[1]
|
||||
lab=json.loads((ROOT/'lab.json').read_text())['number']
|
||||
project='verify-lab'+str(lab)+'-'+uuid.uuid4().hex[:10]
|
||||
with socket.socket() as sock:sock.bind(('127.0.0.1',0));port=sock.getsockname()[1]
|
||||
with tempfile.TemporaryDirectory(prefix=project+'-') as directory:
|
||||
clone=Path(directory)/'repo';subprocess.run(['git','clone','--no-hardlinks',str(ROOT),str(clone)],check=True)
|
||||
env=dict(os.environ,COMPOSE_PROJECT_NAME=project,APP_PORT=str(port),API_REPLICAS='2',SESSION_TTL_SECONDS='3600')
|
||||
def run(*args):subprocess.run(args,cwd=clone,env=env,check=True)
|
||||
def snapshots():
|
||||
ids=subprocess.check_output(['docker','compose','ps','-q'],cwd=clone,env=env,text=True).splitlines()
|
||||
result={}
|
||||
for id in ids:
|
||||
item=json.loads(subprocess.check_output(['docker','inspect',id],text=True))[0]
|
||||
service=item['Config']['Labels']['com.docker.compose.service']
|
||||
if service in ['api','postgres','valkey','s3']:result[item['Name']]={'service':service,'started_at':item['State']['StartedAt'],'image_id':item['Image'],'user':item['Config'].get('User',''),'pid1':item['Path']}
|
||||
return result
|
||||
try:
|
||||
run('make','up');run('make','check');run('make','test','BASE_URL=http://localhost:'+str(port))
|
||||
before=snapshots();run('make','test-persistence','ACTION_SCRIPT=scripts/restart.sh','BASE_URL=http://localhost:'+str(port));after=snapshots()
|
||||
for name,item in before.items():assert after[name]['started_at']!=item['started_at'],name+' was not restarted'
|
||||
for item in after.values():
|
||||
if item['service']=='api':assert item['user']=='10001:10001' and item['pid1']=='/usr/local/bin/messenger'
|
||||
(ROOT/'evidence/persistence-processes.json').write_text(json.dumps({'scope':'disposable real clean clone','before':before,'after':after},indent=2)+'\n')
|
||||
print('PASS: real clean clone, fresh secrets/volumes, smoke, same-session persistence, actual store/API restart, non-root PID1')
|
||||
finally:
|
||||
# Only this unique synthetic project, never the working lab volumes.
|
||||
run('docker','compose','down','-v','--remove-orphans')
|
||||
Reference in New Issue
Block a user