[verified] Enforce delegation adoption at runtime consumers
This commit is contained in:
@@ -21,10 +21,16 @@ def read_json(p):
|
||||
return x
|
||||
|
||||
def read_json_any(p):
|
||||
b=Path(p).read_bytes()
|
||||
if len(b)>MAX: raise Bad("input too large")
|
||||
try: return json.loads(b)
|
||||
except Exception as e: raise Bad("invalid json") from e
|
||||
repo_root = Path(__file__).resolve().parents[6]
|
||||
if str(repo_root) not in sys.path:
|
||||
sys.path.insert(0, str(repo_root))
|
||||
try:
|
||||
from harness.lib.delegation_evidence import _json_file
|
||||
value = _json_file(str(p))
|
||||
except Exception as e:
|
||||
raise Bad("invalid json") from e
|
||||
if not isinstance(value, dict): raise Bad("object required")
|
||||
return value
|
||||
|
||||
def text(x, name, pattern=None, maxlen=4096):
|
||||
if not isinstance(x,str) or not x or len(x)>maxlen or "\r" in x or "\n" in x or x.rstrip()!=x: raise Bad(f"invalid {name}")
|
||||
@@ -83,7 +89,17 @@ def atomic(path,data):
|
||||
if os.path.exists(tmp): os.unlink(tmp)
|
||||
|
||||
def do_render(a):
|
||||
d,vals,fs,ex,cs,ar=canon(read_json(a.input))
|
||||
raw = read_json(a.input)
|
||||
declaration = {"mode": "none"} if a.no_delegated_evidence else read_json_any(a.delegation_adoption)
|
||||
try:
|
||||
repo_root = Path(__file__).resolve().parents[6]
|
||||
if str(repo_root) not in sys.path:
|
||||
sys.path.insert(0, str(repo_root))
|
||||
from harness.lib.delegation_adoption import require_adoption
|
||||
require_adoption(declaration, expected_source={"kind": "git_tree", "revision": raw.get("final_head")}, expected_stage="implementation-delivery")
|
||||
except Exception:
|
||||
raise Bad("delegation adoption rejected") from None
|
||||
d,vals,fs,ex,cs,ar=canon(raw)
|
||||
body=render_body(d,vals,fs,ex,cs,ar); bb=body.encode()
|
||||
rh=hashlib.sha256(bb).hexdigest()
|
||||
corr=hashlib.sha256("\0".join([d['owner'],d['repository'],vals['issue'],vals['pr'],vals['review'],d['reviewed_head'],d['final_head'],d['contract_sha256']]).encode()).hexdigest()
|
||||
@@ -137,6 +153,7 @@ def do_verify(a):
|
||||
def main():
|
||||
p=argparse.ArgumentParser(); sp=p.add_subparsers(dest="cmd",required=True)
|
||||
r=sp.add_parser("render"); r.add_argument("--input",required=True); r.add_argument("--comment",required=True); r.add_argument("--expected",required=True)
|
||||
adoption=r.add_mutually_exclusive_group(required=True); adoption.add_argument("--no-delegated-evidence",action="store_true"); adoption.add_argument("--delegation-adoption")
|
||||
v=sp.add_parser("verify"); v.add_argument("--expected",required=True); v.add_argument("--pr-readback",required=True); v.add_argument("--comments-readback",required=True); v.add_argument("--identity-readback",required=True); v.add_argument("--action",choices=("create","reuse"),required=True); v.add_argument("--baseline-count",type=int,required=True); v.add_argument("--output",required=True)
|
||||
args=p.parse_args()
|
||||
try: do_render(args) if args.cmd=="render" else do_verify(args)
|
||||
|
||||
Reference in New Issue
Block a user