Merge commit 'b0dda75809a7efa2dd8ae3dc910dab23db9cfb61' into migration-operator-authorisation-evidence

This commit is contained in:
Mark Gregory
2026-11-28 10:08:14 +00:00
2 changed files with 11 additions and 4 deletions
+2 -2
View File
@@ -1,10 +1,10 @@
"""Local operator identity and scoped migration approval policy.""" """Local operator identity and scoped migration approval policy."""
import hmac import hmac
import os
from dataclasses import dataclass from dataclasses import dataclass
from datetime import datetime from datetime import datetime
from os import geteuid
from core.approval import ( from core.approval import (
ApprovalError, ApprovalError,
@@ -46,7 +46,7 @@ class OperatorApprovalPolicy:
self._key = sealing_key self._key = sealing_key
def authorise(self, approval, operation, now): def authorise(self, approval, operation, now):
uid = os.geteuid() uid = geteuid()
principal = approval["approver"] principal = approval["approver"]
validate_approver(principal) validate_approver(principal)
context = approval["context"] context = approval["context"]
+9 -2
View File
@@ -82,9 +82,16 @@ class ApprovalStoreTests(unittest.TestCase):
self.identifier = self.approval["approval_id"] self.identifier = self.approval["approval_id"]
self.uid = os.geteuid()
if self.uid == 0:
self.uid = 1000
identity = patch("core.operator_approval.geteuid", return_value=self.uid)
identity.start()
self.addCleanup(identity.stop)
self.key = os.urandom(32) self.key = os.urandom(32)
self.grants = [ self.grants = [
OperatorGrant(os.geteuid(), "operator", operation, self.base["site"], OperatorGrant(self.uid, "operator", operation, self.base["site"],
self.base["revision"], self.now + timedelta(days=2)) self.base["revision"], self.now + timedelta(days=2))
for operation in ("issue", "execute") for operation in ("issue", "execute")
] ]
@@ -481,7 +488,7 @@ class ApprovalStoreTests(unittest.TestCase):
self.assertFalse(self.store.approval_path(self.identifier).exists()) self.assertFalse(self.store.approval_path(self.identifier).exists())
def test_unrecognised_os_identity_denies_issuance(self): def test_unrecognised_os_identity_denies_issuance(self):
other_account = [replace(grant, uid=os.geteuid() + 1) for grant in self.grants] other_account = [replace(grant, uid=self.uid + 1) for grant in self.grants]
self.store.operator_policy = OperatorApprovalPolicy(other_account, sealing_key=self.key) self.store.operator_policy = OperatorApprovalPolicy(other_account, sealing_key=self.key)
with self.assertRaisesRegex(ApprovalStoreError, "not authorised"): with self.assertRaisesRegex(ApprovalStoreError, "not authorised"):
self.save() self.save()