Isolate PMO credential from existing differently owned credentials directory
Deploy Canina / deploy (push) Successful in 4m30s
Deploy Canina / deploy (push) Successful in 4m30s
This commit is contained in:
1 parent
7485c89e9b
commit
ba0aa5ee4e
4 files changed
+8
-6
No files matched your search
@@ -59,7 +59,7 @@ def submit(home, commit, proposal, *, endpoint=ENDPOINT, timeout=15):
|
||||
topic, criteria = proposal['researchTopic'], proposal['acceptanceCriteria']
|
||||
if not isinstance(topic, str) or not topic.strip() or len(topic) > 180 or not isinstance(criteria, list) or not 1 <= len(criteria) <= 10 or any(not isinstance(v, str) or not v.strip() or len(v) > 500 for v in criteria):
|
||||
raise ValueError('Invalid proposal')
|
||||
token = private_read(home/'credentials/editorial-pmo-token').decode('ascii')
|
||||
token = private_read(home/'editorial-v4/credentials/editorial-pmo-token').decode('ascii')
|
||||
if not re.fullmatch('[A-Za-z0-9_-]{64}', token): raise ValueError('Invalid credential')
|
||||
directory = safe(home/'editorial-v4/client-state')
|
||||
directory.mkdir(mode=0o700, parents=True, exist_ok=True)
|
||||
|
||||
@@ -32,8 +32,8 @@ class ClientTests(unittest.TestCase):
|
||||
thread = threading.Thread(target=server.serve_forever, daemon=True); thread.start()
|
||||
try:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
home = Path(tmp); (home/'credentials').mkdir(mode=0o700)
|
||||
token = home/'credentials/editorial-pmo-token'; token.write_text('x'*64); token.chmod(0o400)
|
||||
home = Path(tmp); (home/'editorial-v4/credentials').mkdir(mode=0o700, parents=True)
|
||||
token = home/'editorial-v4/credentials/editorial-pmo-token'; token.write_text('x'*64); token.chmod(0o400)
|
||||
proposal = {'researchTopic':'Owner supplied topic', 'acceptanceCriteria':['Cite dated sources']}
|
||||
endpoint = 'http://127.0.0.1:%s/api/internal/prepare-worker/editorial-proposals' % server.server_port
|
||||
a = c.submit(home, 'a'*40, proposal, endpoint=endpoint)
|
||||
|
||||
@@ -70,7 +70,7 @@ def install(home, payload):
|
||||
for profile in PROFILES:
|
||||
skill=home/f'profiles/{profile}/skills/canina-editorial-v4/SKILL.md'
|
||||
if not skill.is_file() or 'name: canina-editorial-v4' not in skill.read_text():raise ValueError('Skill discovery failed')
|
||||
credentials=safe(home/'credentials');credentials.mkdir(mode=0o700,exist_ok=True)
|
||||
credentials=safe(home/'editorial-v4/credentials');credentials.mkdir(mode=0o700,exist_ok=True)
|
||||
st=credentials.stat()
|
||||
if st.st_uid!=os.getuid() or stat.S_IMODE(st.st_mode) not in (0o700,0o755):raise ValueError('Runtime-owned non-writable credentials directory required')
|
||||
token=safe(credentials/'editorial-pmo-token')
|
||||
|
||||
@@ -18,10 +18,12 @@ class ProvisionTests(unittest.TestCase):
|
||||
m=load('editorial',ROOT/'provision-editorial-runtime.py')
|
||||
with tempfile.TemporaryDirectory() as t:
|
||||
home=Path(t); sentinel=home/'config.yaml';sentinel.write_text('unchanged')
|
||||
credentials=home/'credentials'; credentials.mkdir(); credentials.chmod(0o755)
|
||||
os.chown(credentials,10000,10000)
|
||||
payload=m.package(BUNDLE,'a'*40)
|
||||
a=m.install(home,payload);b=m.install(home,payload)
|
||||
self.assertEqual(a,b);self.assertEqual(sentinel.read_text(),'unchanged')
|
||||
self.assertEqual((home/'credentials/editorial-pmo-token').stat().st_mode & 0o777,0o400)
|
||||
self.assertEqual((home/'editorial-v4/credentials/editorial-pmo-token').stat().st_mode & 0o777,0o400)
|
||||
self.assertEqual(a['files'],19)
|
||||
grants={'grants':[{'id':'ci','role':'STAGE_CI','credentialSha256':'c'*64},{'id':'worker','role':'WORKFLOW_WORKER','credentialSha256':'d'*64}], 'workerIds':['worker'],'stageCiIds':['ci'],'artifactBaseUrl':'https://stageapi.canina.ir/api/internal/prepare-worker/artifacts'}
|
||||
updated=m.add_grant(grants,a['credentialSha256'])
|
||||
@@ -29,7 +31,7 @@ class ProvisionTests(unittest.TestCase):
|
||||
self.assertEqual(m.add_grant(updated,a['credentialSha256']),updated)
|
||||
with self.assertRaises(ValueError):m.add_grant(updated,'e'*64)
|
||||
self.assertEqual(grants['workerIds'],['worker'])
|
||||
(home/'credentials/editorial-pmo-token').chmod(0o644)
|
||||
(home/'editorial-v4/credentials/editorial-pmo-token').chmod(0o644)
|
||||
with self.assertRaises(ValueError):m.install(home,payload)
|
||||
|
||||
if __name__=='__main__':unittest.main()
|
||||
Reference in new issue
Block a user