test: accept bounded cloud logs and equal UI HTTP MCP evidence
Rust development slice / linux (push) Failing after 6s

This commit is contained in:
2026-11-13 17:56:24 +01:00
parent 2ab5fe0f0e
commit b6586f904b
9 changed files with 177 additions and 9 deletions
+46
View File
@@ -0,0 +1,46 @@
// Read only through actual UI clicks; inspect its normal HTTP response.
const fs = require('node:fs');
const path = require('node:path');
const assert = require('node:assert/strict');
const { chromium } = require('../../web/node_modules/playwright');
const root = path.resolve(__dirname, '../..');
function privateJson(file) {
const s = fs.lstatSync(file);
assert(s.isFile() && !s.isSymbolicLink() && s.uid === process.getuid() && (s.mode & 0o777) === 0o600 && s.size <= 1048576);
return JSON.parse(fs.readFileSync(file, 'utf8'));
}
(async () => {
const file = path.resolve(process.argv[2]); const expected = privateJson(file);
assert.equal(expected.profile, 'dev/test'); assert.equal(expected.case, 'query_logs');
const login = privateJson(path.join(root, 'credentials/server-browser-login.json'));
const browsers = path.join(root, 'web/node_modules/.cache/playwright-browsers');
const version = fs.readdirSync(browsers).find(x => /^chromium-/.test(x));
const executablePath = ['chrome-linux/chrome', 'chrome-linux64/chrome'].map(x => path.join(browsers, version, x)).find(x => fs.existsSync(x));
const browser = await chromium.launch({ headless: true, executablePath,
env: { ...process.env, HOME: path.join(root, 'web/node_modules/.cache/cloud-acceptance/home') } });
try {
const page = await browser.newPage({ ignoreHTTPSErrors: false });
await page.goto('https://localhost:18443/');
await page.getByLabel('Benutzername').fill(login.username);
await page.getByLabel('Passwort', { exact: true }).fill(login.password);
const sessionResponse = page.waitForResponse(r => new URL(r.url()).pathname === '/auth/session' && r.status() === 200);
await page.getByRole('button', { name: 'Anmelden', exact: true }).click();
const session = await (await sessionResponse).json();
assert(session.testsimulation === true && session.principal === 'simulated-testprincipal-a');
await page.getByRole('status').filter({ hasText: 'SIMULIERT' }).waitFor();
assert.equal(await page.getByLabel('Mandant', { exact: true }).inputValue(), expected.tenant_id);
await page.getByRole('button', { name: expected.operation_id, exact: true }).click();
const op = page.locator('section').filter({ has: page.getByRole('heading', { name: 'Antrag / Ausführung ' + expected.operation_id, exact: true }) });
const response = page.waitForResponse(r => new URL(r.url()).pathname === `/api/v1/tenants/${expected.tenant_id}/jobs/${expected.job_id}` && r.status() === 200);
await op.getByRole('button', { name: 'Job ' + expected.job_id + ' · succeeded', exact: true }).click();
const http = await (await response).json();
const detail = page.locator('article').filter({ has: page.getByRole('heading', { name: 'Job ' + expected.job_id, exact: true }) });
await detail.locator('pre').waitFor();
const rendered = JSON.parse(await detail.locator('pre').innerText());
assert.deepEqual(http, expected.result); assert.deepEqual(rendered, expected.result);
const observation = JSON.parse(Buffer.from(rendered.result.stdout).toString('utf8'));
assert.equal(observation.data.unit, 'rmm-mvp-test.service'); assert.equal(observation.data.json_lines.length, 4);
fs.writeFileSync(path.join(path.dirname(file), 'read-evidence.json'), JSON.stringify({ verified: true, http, rendered }), { mode: 0o600, flag: 'wx' });
await page.getByRole('button', { name: 'Abmelden', exact: true }).click();
} finally { await browser.close(); }
})().catch(error => { console.log('CLOUD_LOG_READ_INCOMPLETE:' + error.constructor.name); process.exitCode = 1; });
+1 -1
View File
@@ -10,7 +10,7 @@ import sys
sys.path.insert(0,str(Path(__file__).resolve().parents[1]))
import cloud_mvp_acceptance as cloud
CASES=('service_setup','service_start','service_stop','apt_native_install','apt_native_update','ensure_package','apply_updates')
CASES=('service_setup','service_start','service_stop','query_logs','apt_native_install','apt_native_update','ensure_package','apply_updates')
def run(file,prepare=False):
+71
View File
@@ -0,0 +1,71 @@
#!/usr/bin/env python3
"""Bounded root log acceptance for the one harmless cloud test unit."""
import datetime as dt
import hashlib
import json
import os
import subprocess
import sys
import uuid
import cloud_apt_retry as apt
import cloud_root_policy
cloud=apt.cloud
def open_policy(payload):
import datetime as dt
p=Path('/opt/rust-discovery/devstate/root-policy/policy.json')
require(not p.is_symlink() and p.stat().st_uid==10001 and p.stat().st_mode&0o777==0o600,'safe existing policy')
old=p.read_bytes()
require(hashlib.sha256(old).hexdigest()==payload['previous_sha256'] and
dt.datetime.fromisoformat(json.loads(old)['expires_at'])<dt.datetime.now(dt.timezone.utc),'known closed policy')
policy=payload['policy'];scope=policy['scopes'][0]
require(policy['schema_version']==1 and policy['profile']=='development' and len(policy['scopes'])==1 and
dt.datetime.now(dt.timezone.utc)<dt.datetime.fromisoformat(policy['expires_at'])<=dt.datetime.now(dt.timezone.utc)+dt.timedelta(minutes=16) and
not scope['allowed_services'] and not scope['allow_root_scripts'] and not scope['allow_reboot'] and 'apt' not in scope and
scope['principals']==['simulated-testprincipal-a'] and
scope['root_logs']==dict(schema_version=1,allowed_units=['rmm-mvp-test.service'],sensitive_units=[]),'one test-unit read policy only')
backup=p.parents[1]/('root-policy-bootstrap-'+str(uuid.UUID(payload['id'])));backup.mkdir(mode=0o700)
def create(path,data,uid=0):
fd=os.open(path,os.O_WRONLY|os.O_CREAT|os.O_EXCL|os.O_NOFOLLOW,0o600)
with os.fdopen(fd,'wb') as f:f.write(data);f.flush();os.fsync(f.fileno());os.fchown(f.fileno(),uid,uid)
create(backup/'previous-policy.json',old)
next_path=p.with_suffix('.logs-next');create(next_path,json.dumps(policy).encode(),10001);os.replace(next_path,p)
return dict(policy_sha256=hashlib.sha256(p.read_bytes()).hexdigest(),backup=str(backup),approvals_created=False)
def main():
os.umask(0o077);m=cloud.contract
require=cloud.require
require(apt.prior.evidence('gate')['unresolved']==0,'no unresolved cloud attempts')
installed=m.protected_json(cloud.ROOT/'devstate/remote-vm.json');identity=installed['identity']
import cloud_root_evidence
peers=cloud.bootstrap.rpc('linux-vm.conf',cloud_root_evidence.inspect_helpers,dict(identity,tenant_id=cloud.TENANT,general_only=True))
require(peers['ledger']['faults']==0,'fault-free shared ledger')
binding=peers['general']['identity']
scope={k:binding[k] for k in ('tenant_id','asset_id','agent_id','enrollment_generation','assignment_version')}
scope.update(principals=['simulated-testprincipal-a'],helper_policy_sha256=peers['general']['policy_sha256'],
acceptance_evidence_id='cloud-general-readiness:bounded-testunit-logs',allowed_services=[],allow_root_scripts=False,allow_reboot=False,
root_logs=dict(schema_version=1,allowed_units=['rmm-mvp-test.service'],sensitive_units=[]))
policy=dict(schema_version=1,profile='development',expires_at=(m.now()+dt.timedelta(minutes=15)).isoformat(),scopes=[scope])
folder=cloud.ROOT/'devstate/cloud-logs';folder.mkdir(mode=0o700,exist_ok=True)
previous=m.protected_json(apt.STATE/'policy-closed.json')
record=cloud.bootstrap.rpc('server.conf',open_policy,dict(id=str(uuid.uuid4()),previous_sha256=previous['policy_sha256'],policy=policy))
m.write_private(folder/'policy-open.json',dict(record,policy=policy))
process=subprocess.run([sys.executable,str(cloud.ROOT/'deploy/cloud_root_acceptance.py'),'--case','query_logs'],capture_output=True,timeout=600)
# The child intentionally prints only public contract statuses.
print(process.stdout.decode(),end='')
closed=cloud.bootstrap.rpc('server.conf',cloud_root_policy.close_policy,dict(expected_sha256=record['policy_sha256'],backup=record['backup']))
m.write_private(folder/'policy-closed.json',closed)
require(process.returncode==0,'bounded log acceptance incomplete; preserve original case')
print('PASS cloud bounded log collection; test-only read policy closed')
if __name__=='__main__':
try:main()
except Exception as error:
message=str(error)
print(message if message.startswith('remote bootstrap incomplete: ') else 'CLOUD_LOG_ACCEPTANCE_INCOMPLETE:'+type(error).__name__)
raise SystemExit(2) from None
+1 -1
View File
@@ -136,7 +136,7 @@ class Backend:
return bootstrap.rpc('server.conf',server,dict(kind='http',path='/mcp',method='POST',headers=self.headers,body=body,principal=self.principal))
def call(self,name,args):
contract.require(name in ('tenants.list','inventory.get_device','operations.plan','operations.submit','jobs.get','jobs.cancel'),'tool_allowlist')
contract.require(name in ('tenants.list','inventory.get_device','logs.query','operations.plan','operations.submit','jobs.get','jobs.cancel'),'tool_allowlist')
self.sequence+=1
response=self.request(dict(jsonrpc='2.0',id=self.sequence,method='tools/call',params=dict(name=name,arguments=args)))
data=response.get('data',{}) or {}
+19 -1
View File
@@ -34,7 +34,8 @@ def main():
m.require(observed['sync_ready'] and not observed['restore_blocked'],'signed sync required')
device=backend.call('inventory.get_device',dict(tenant_id=cloud.TENANT,asset_id=identity['asset_id']))
m.require(device['presence']=='online' and device['agent_id']==identity['agent_id'],'online cloud VM required')
peers=cloud.bootstrap.rpc('linux-vm.conf',cloud_root_evidence.inspect_helpers,{k:settings[k] for k in ('tenant_id','asset_id','agent_id')})
peers=cloud.bootstrap.rpc('linux-vm.conf',cloud_root_evidence.inspect_helpers,dict(
{k:settings[k] for k in ('tenant_id','asset_id','agent_id')},general_only=name=='query_logs'))
m.require(peers['ledger']['integrity']=='ok' and peers['ledger']['faults']==0,'healthy shared helper ledger required')
if name in adapters.APT_CASES:
apt_peer=peers['apt'];recipe=adapters.RECIPES[name]
@@ -42,6 +43,16 @@ def main():
else recipe in apt_peer['accepted_recipes'],'actual native bootstrap/acceptance gate required')
planning=adapters.planning_from_device(device) if name in adapters.APT_CASES else None
request=m.case_input(name,settings,planning=planning)
if name=='query_logs':
import datetime as dt
# Query only the already approved harmless unit's stored start/stop
# interval. No extra service mutation is needed to manufacture logs.
prior=m.protected_json(cloud.ROOT/'devstate/cloud-root/cases/service_stop/checkpoint.json')
prior_payload=prior['job']['payload']
m.require(prior['verified'] and prior_payload['agent_id']==identity['agent_id'],'same VM test-unit history')
moment=m.timestamp(prior_payload['not_before'])
request['parameters'].update(execution_identity='root',since=(moment-dt.timedelta(minutes=1)).isoformat(),
until=(moment+dt.timedelta(minutes=4)).isoformat())
m.require({'rmm.sync.v1','helper.root.v1','root:'+request['action'],request['action']}<=set(device['capabilities']),'native root capability required')
folder=cloud.ROOT/'devstate/cloud-root/cases'/name
if not args.resume_prepared:folder.mkdir(mode=0o700,parents=True,exist_ok=False)
@@ -83,6 +94,13 @@ def main():
m.require(result['state']=='succeeded' and result['result']['evidence']['postconditions_passed'],'native success/postcondition required; no retry')
if name=='service_setup':
m.require(result['result']['exit_code']==0 and bytes(result['result']['stdout'])==b'RMM test unit prepared\n','exact root script result')
if name=='query_logs':
observation=json.loads(bytes(result['result']['stdout']))
checkpoint['log_observation']=observation;save()
m.require(observation['quality']=='valid' and observation['source_id']=='/usr/bin/journalctl' and
isinstance(observation.get('data',{}).get('json_lines'),list) and
0<len(observation['data']['json_lines'])<=50,'bounded actual test-unit journal observation')
m.require(len(bytes(result['result']['stdout']))<=65536,'bounded serialized log output')
if name in adapters.APT_CASES:
apt=result['result']['evidence']['apt'];manifest=request['parameters']['apt_manifest']
package=manifest['resolved_apt_transaction']['packages'][0]
+4 -3
View File
@@ -3,12 +3,13 @@
def inspect_helpers(payload):
import sqlite3
program=r'''import json,os,socket,struct,uuid
program=r'''import json,os,socket,struct,uuid,sys
from pathlib import Path
result={}
for kind,pin_path,socket_path in (
('general','/etc/rmm-remote/general-helper-proof.json','/run/rmm-helper-cloud/control.sock'),
('apt','/etc/rmm-remote/apt-helper-proof.json','/run/rmm-apt-helper/helper.sock')):
if kind=='apt' and sys.argv[1]=='general':continue
pin_path=Path(pin_path);socket_path=Path(socket_path)
for path in list(pin_path.parents)+[pin_path]+list(socket_path.parents):
meta=path.lstat();assert not path.is_symlink() and meta.st_uid==0 and meta.st_mode&0o022==0
@@ -30,10 +31,10 @@ for kind,pin_path,socket_path in (
assert response['schema_version']==1 and response['challenge']==challenge and response['identity']==pin['identity'] and response['profile']==pin['profile']
assert response[field]==pin[field] and response['ledger_inode'] and response['lock_inode']
result[kind]=response
assert all(result['general'][k]==result['apt'][k] for k in ('ledger_device','ledger_inode','lock_device','lock_inode'))
if 'apt' in result:assert all(result['general'][k]==result['apt'][k] for k in ('ledger_device','ledger_inode','lock_device','lock_inode'))
print(json.dumps(result))
'''
process=subprocess.run(['/usr/sbin/runuser','-u','rmm-agent','--','/usr/bin/python3','-I','-c',program],capture_output=True,check=True,timeout=25)
process=subprocess.run(['/usr/sbin/runuser','-u','rmm-agent','--','/usr/bin/python3','-I','-c',program,'general' if payload.get('general_only') is True else 'both'],capture_output=True,check=True,timeout=25)
result=json.loads(process.stdout)
for peer in result.values():
require(all(peer['identity'][key]==payload[key] for key in ('tenant_id','asset_id','agent_id')),'helper target identity drift')