Verify signed OPNsense kernel probes on the service account and retain exactly-once evidence
Rust development slice / linux (push) Failing after 13s
Rust development slice / linux (push) Failing after 13s
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
"""Provision the first service-account probe on an existing development installation.
|
||||
Run as root in FreeBSD with the operator-confirmed tenant/asset/agent UUIDs and
|
||||
enrollment/assignment generations. Fetch only the public signing pin as discovery.
|
||||
"""
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import uuid
|
||||
|
||||
|
||||
def main():
|
||||
if os.geteuid() or len(sys.argv)!=6:
|
||||
raise SystemExit('pin-probe.py TENANT ASSET AGENT ENROLLMENT_GENERATION ASSIGNMENT_VERSION')
|
||||
tenant,asset,agent = (str(uuid.UUID(s)) for s in sys.argv[1:4])
|
||||
enroll,assignment = map(int,sys.argv[4:])
|
||||
if min(enroll,assignment)<1:
|
||||
raise ValueError('invalid generation')
|
||||
# Device-owned inputs are opened only after dropping privileges.
|
||||
source = """
|
||||
import hashlib,http.client,json,ssl
|
||||
from pathlib import Path
|
||||
p=Path('/var/db/discovery-agent')
|
||||
i=json.loads((p/'identity.json').read_bytes())
|
||||
ctx=ssl.create_default_context(cafile='/usr/local/etc/discovery-agent/ca.pem')
|
||||
ctx.load_cert_chain(p/'device.pem',p/'device.key')
|
||||
c=http.client.HTTPSConnection('discovery.ease-technologies.de',context=ctx,timeout=10)
|
||||
c.request('GET','/api/v1/job-signing-key')
|
||||
r=c.getresponse()
|
||||
if r.status!=200:raise ValueError('device trust endpoint rejected')
|
||||
print(json.dumps([i['agent_id'],i['asset_id'],json.loads(r.read(4097))]))
|
||||
"""
|
||||
current,bound_asset,k=json.loads(subprocess.check_output(
|
||||
['su','-m','discovery','-c','/usr/local/bin/python3 -I -'],input=source.encode(),timeout=15))
|
||||
key = k['public_key_hex']
|
||||
if (current,bound_asset)!=(agent,asset) or not re.fullmatch('[a-f0-9]{64}',key) or (
|
||||
k['algorithm'],k['schema_version'],k['key_id'])!=('Ed25519',1,hashlib.sha256(bytes.fromhex(key)).hexdigest()):
|
||||
raise ValueError('conflicting device or signing key')
|
||||
payload=dict(agent_id=agent,asset_id=asset,tenant_id=tenant,enrollment_generation=enroll,
|
||||
assignment_version=assignment,public_key_hex=key)
|
||||
p=Path('/usr/local/etc/discovery-agent/job-binding.json')
|
||||
try:
|
||||
with p.open('x') as f:
|
||||
os.fchmod(f.fileno(),0o444); json.dump(payload,f); f.flush(); os.fsync(f.fileno())
|
||||
except FileExistsError:
|
||||
if p.is_symlink() or json.loads(p.read_bytes())!=payload: raise ValueError('existing binding differs')
|
||||
|
||||
|
||||
if __name__=='__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user