fix(orchestration): provision explicit Stage owner Gate1 review access
Preserve independent proposer checks, canonical Admin UUID allowlist and deny ordinary admins. Revalidate pinned owner in read-only CI preflight; expose server-advertised card decisions and distinguish reservation from unknown real cost. Verified backend 42 HTTP/service/config tests and build; admin 18 relevant tests, app tsc and Vite build; 3 CI config tests and bash syntax.
This commit is contained in:
1 parent
bfb1841370
commit
dfe5162832
11 files changed
+172
-11
No files matched your search
@@ -5,6 +5,7 @@ stage_runtime_provision() {
|
||||
[ "${GITHUB_ACTIONS:-${GITEA_ACTIONS:-}}" = true ]
|
||||
[ "${STAGE_PROVISION_ENABLED:-}" = true ]
|
||||
export DEPLOY_SHA STAGE_PROVISION_APPROVED_SHA="$DEPLOY_SHA" CI=true
|
||||
PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -s scripts -p test_stage_owner_review.py
|
||||
PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -s infra/hermes-editorial/tests
|
||||
PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -s scripts -p test_editorial_provision.py
|
||||
PYTHONDONTWRITEBYTECODE=1 python3 - <<'PY'
|
||||
@@ -59,11 +60,14 @@ root=Path('/opt/services/canina/stage-runtime')
|
||||
query="""const {PrismaClient}=require('@prisma/client');const p=new PrismaClient();
|
||||
(async()=>{try{const rows=await p.$transaction(async tx=>{
|
||||
await tx.$executeRawUnsafe('SET TRANSACTION READ ONLY');
|
||||
return tx.$queryRawUnsafe(\"SELECT id::text FROM users WHERE lower(replace(replace(role::text, '_', ''), '-', '')) IN ('admin','superadmin') ORDER BY id LIMIT 1001\");
|
||||
return tx.$queryRawUnsafe(\"SELECT id::text, role::text FROM users WHERE lower(replace(replace(role::text, '_', ''), '-', '')) IN ('admin','superadmin') ORDER BY id LIMIT 1001\");
|
||||
});process.stdout.write(JSON.stringify(rows));}catch{process.exitCode=1;}finally{await p.$disconnect();}})();"""
|
||||
rows=json.loads(docker('exec','-w','/app','canino_backend_stage','node','-e',query))
|
||||
if not 1<=len(rows)<=1000 or any(not isinstance(r,dict) or set(r)!={'id'} or not isinstance(r['id'],str) or not re.fullmatch('[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}',r['id']) for r in rows):
|
||||
if not 1<=len(rows)<=1000 or any(not isinstance(r,dict) or set(r)!={'id','role'} or not isinstance(r['id'],str) or not re.fullmatch('[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}',r['id']) for r in rows):
|
||||
raise ValueError('Verified admin subjects required')
|
||||
spec=importlib.util.spec_from_file_location('owner','scripts/stage-owner-review.py')
|
||||
owner=importlib.util.module_from_spec(spec);spec.loader.exec_module(owner)
|
||||
owner_ids=owner.verified_owner_ids(rows)
|
||||
m.provision(root,uid,gid)
|
||||
spec=importlib.util.spec_from_file_location('editorial','scripts/provision-editorial-runtime.py')
|
||||
editorial=importlib.util.module_from_spec(spec);spec.loader.exec_module(editorial)
|
||||
@@ -74,7 +78,7 @@ dest=root/'snapshots'/capture
|
||||
m.export_snapshot(db,dest,'default',uid,gid)
|
||||
grants=root/'snapshots'/(capture+'-grants.json')
|
||||
m.write_private(grants,json.dumps({r['id']:['default'] for r in rows}),uid,gid)
|
||||
Path('.stage-runtime.json').write_text(json.dumps({'snapshot':str(dest),'grants':str(grants)}))
|
||||
Path('.stage-runtime.json').write_text(json.dumps({'snapshot':str(dest),'grants':str(grants),'ownerReviewerIds':owner_ids}))
|
||||
print('Stage projected snapshot captured; existing admin grants verified; no executor started')
|
||||
PY
|
||||
}
|
||||
@@ -93,6 +97,14 @@ from pathlib import Path
|
||||
p=Path('.stage-runtime-merged.json');c=json.loads(p.read_text())
|
||||
b=c['services']['backend_stage']
|
||||
b.setdefault('environment',{})['CANINA_RUNTIME_READ_ENABLED']='true'
|
||||
owner_ids=json.loads(Path('.stage-runtime.json').read_text())['ownerReviewerIds']
|
||||
spec_path=Path('scripts/stage-owner-review.py')
|
||||
import importlib.util
|
||||
spec=importlib.util.spec_from_file_location('owner',spec_path)
|
||||
owner=importlib.util.module_from_spec(spec);spec.loader.exec_module(owner)
|
||||
assert owner_ids==[owner.STAGE_OWNER_SUBJECT], 'Explicit verified owner required'
|
||||
b['environment']['CANINA_ENV']='staging'
|
||||
b['environment']['CANINA_WORKFLOW_OWNER_REVIEWER_IDS']=','.join(owner_ids)
|
||||
b.setdefault('networks',{})['traefik_public']=None
|
||||
b.setdefault('labels',{})['traefik.docker.network']='traefik_public'
|
||||
c['secrets']['hermes_runtime_grants']['file']=json.loads(Path('.stage-runtime.json').read_text())['grants']
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
# Stage-only named grant: explicit user-authorized owner, not discovery of all admins.
|
||||
# Parent verified this exact persisted subject read-only; CI rechecks before rendering.
|
||||
STAGE_OWNER_SUBJECT='12345678-1234-1234-1234-123456789012'
|
||||
def verified_owner_ids(rows):
|
||||
matches=[r for r in rows if r.get('id')==STAGE_OWNER_SUBJECT]
|
||||
if len(matches)!=1 or matches[0].get('role','').lower().replace('_','').replace('-','')!='admin':
|
||||
raise ValueError('Pinned Stage owner must exist with Admin role')
|
||||
return [STAGE_OWNER_SUBJECT]
|
||||
@@ -0,0 +1,32 @@
|
||||
import importlib.util
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
spec=importlib.util.spec_from_file_location('owner',Path(__file__).with_name('stage-owner-review.py'))
|
||||
owner=importlib.util.module_from_spec(spec);spec.loader.exec_module(owner)
|
||||
class OwnerReviewTests(unittest.TestCase):
|
||||
def test_verified_pinned_admin_only(self):
|
||||
self.assertEqual(owner.verified_owner_ids([{'id':owner.STAGE_OWNER_SUBJECT,'role':'ADMIN'},{'id':'other','role':'ADMIN'}]),[owner.STAGE_OWNER_SUBJECT])
|
||||
def test_missing_wrong_role_denied(self):
|
||||
for rows in [[],[{'id':'other','role':'ADMIN'}],[{'id':owner.STAGE_OWNER_SUBJECT,'role':'SUPER_ADMIN'}],[{'id':owner.STAGE_OWNER_SUBJECT,'role':'User_PetOwner'}]]:
|
||||
with self.subTest(rows=rows),self.assertRaises(ValueError):owner.verified_owner_ids(rows)
|
||||
|
||||
def test_actual_ci_render_sets_only_pinned_backend_reviewer(self):
|
||||
import json, os, tempfile, subprocess
|
||||
script=Path(__file__).with_name('rollout-stage.sh').read_text()
|
||||
render=script.split('stage_runtime_render() {',1)[1].split("python3 - <<'PY'",1)[1].split('\nPY',1)[0]
|
||||
with tempfile.TemporaryDirectory(dir=Path(__file__).parent.parent) as d:
|
||||
root=Path(d);(root/'scripts').mkdir()
|
||||
(root/'scripts/stage-owner-review.py').write_text(Path(__file__).with_name('stage-owner-review.py').read_text())
|
||||
compose={'services':{'db_stage':{},'redis_stage':{},'frontend_stage':{},'backend_stage':{},'runtime-inventory':{}},'secrets':{'hermes_runtime_grants':{}},'networks':{'hermes_inventory_backend':{'internal':True},'traefik_public':{'external':True}}}
|
||||
def write(ids):
|
||||
(root/'.stage-runtime-merged.json').write_text(json.dumps(compose))
|
||||
(root/'.stage-runtime.json').write_text(json.dumps({'grants':'/verified/grants','ownerReviewerIds':ids}))
|
||||
write([owner.STAGE_OWNER_SUBJECT])
|
||||
subprocess.run(['python3','-c',render],cwd=root,check=True,env={**os.environ,'PYTHONDONTWRITEBYTECODE':'1'})
|
||||
result=json.loads((root/'.stage-compose.json').read_text())
|
||||
self.assertEqual(result['services']['backend_stage']['environment']['CANINA_WORKFLOW_OWNER_REVIEWER_IDS'],owner.STAGE_OWNER_SUBJECT)
|
||||
self.assertEqual(result['services']['backend_stage']['environment']['CANINA_ENV'],'staging')
|
||||
self.assertNotIn('environment',result['services']['frontend_stage'])
|
||||
write(['another-admin'])
|
||||
rejected=subprocess.run(['python3','-c',render],cwd=root,capture_output=True)
|
||||
self.assertNotEqual(rejected.returncode,0)
|
||||
Reference in new issue
Block a user