feat: accept native Windows passive client and tenant-safe inventory migration
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
@@ -12,6 +12,7 @@ import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
sys.path.insert(0, str(ROOT / 'deploy'))
|
||||
@@ -44,7 +45,7 @@ def powershell(script, payload=None, timeout=60, remote_signed=False):
|
||||
UPLOAD = r'''
|
||||
$ErrorActionPreference='Stop'
|
||||
$p=([Console]::In.ReadLine() | ConvertFrom-Json)
|
||||
if ($p.name -notmatch '^((rmm-agent-windows|windows-tests-(lib|bin))\.exe|Install-PassiveClient\.ps1)$') {throw 'Artifact allowlist'}
|
||||
if ($p.name -notmatch '^((rmm-agent-windows|windows-tests-(lib|bin|acl))\.exe|Install-PassiveClient\.ps1|PassiveStateProbe\.exe)$') {throw 'Artifact allowlist'}
|
||||
$root='C:\ProgramData\RustDiscoveryBootstrap'
|
||||
if (!(Test-Path -LiteralPath $root)) {
|
||||
New-Item -ItemType Directory -Path $root | Out-Null
|
||||
@@ -67,7 +68,7 @@ if (Test-Path -LiteralPath $path) {throw 'Artifact already exists'}
|
||||
VERIFY_UPLOAD = r'''
|
||||
$ErrorActionPreference='Stop'
|
||||
$p=([Console]::In.ReadLine() | ConvertFrom-Json)
|
||||
if ($p.sha256 -notmatch '^[0-9a-f]{64}$' -or $p.name -notmatch '^((rmm-agent-windows|windows-tests-(lib|bin))\.exe|Install-PassiveClient\.ps1)$') {throw 'Artifact allowlist'}
|
||||
if ($p.sha256 -notmatch '^[0-9a-f]{64}$' -or $p.name -notmatch '^((rmm-agent-windows|windows-tests-(lib|bin|acl))\.exe|Install-PassiveClient\.ps1|PassiveStateProbe\.exe)$') {throw 'Artifact allowlist'}
|
||||
$path='C:\ProgramData\RustDiscoveryBootstrap\'+$p.sha256+'\'+$p.name
|
||||
$hash=(Get-FileHash -LiteralPath $path -Algorithm SHA256).Hash.ToLowerInvariant()
|
||||
if ($hash -cne $p.sha256) {throw 'Artifact hash'}
|
||||
@@ -84,18 +85,7 @@ $probe=$raw | ConvertFrom-Json
|
||||
$os=Get-CimInstance Win32_OperatingSystem -Property Caption,Version,OSArchitecture
|
||||
[pscustomobject]@{probe=$probe;os_caption=$os.Caption;os_version=$os.Version;architecture=$os.OSArchitecture;native_execution=$true} | ConvertTo-Json -Depth 8 -Compress
|
||||
'''
|
||||
TEST = r'''
|
||||
$ErrorActionPreference='Stop'
|
||||
$p=([Console]::In.ReadLine() | ConvertFrom-Json)
|
||||
if ($p.kind -notin @('lib','bin')) {throw 'Test allowlist'}
|
||||
if ($p.sha256 -notmatch '^[0-9a-f]{64}$') {throw 'Artifact hash format'}
|
||||
$path='C:\ProgramData\RustDiscoveryBootstrap\'+$p.sha256+'\windows-tests-'+$p.kind+'.exe'
|
||||
$out=& $path --test-threads=1 2>&1
|
||||
$code=$LASTEXITCODE
|
||||
$summary=@($out | Where-Object {"$_" -match '^test result: '})
|
||||
if (!$summary) {throw 'No native test summary'}
|
||||
[pscustomobject]@{exit_code=$code;native_execution=$true;summary=($summary -join ' ')} | ConvertTo-Json -Compress
|
||||
'''
|
||||
|
||||
|
||||
|
||||
def record(name, evidence):
|
||||
@@ -131,12 +121,12 @@ def upload(path, name):
|
||||
|
||||
def main():
|
||||
parser=argparse.ArgumentParser()
|
||||
parser.add_argument('action',choices=['upload-agent','upload-lib-tests','upload-bin-tests','upload-installer','install','install-after-nonstart','probe','test-lib','test-bin'])
|
||||
parser.add_argument('action',choices=['upload-agent','upload-lib-tests','upload-bin-tests','upload-acl-tests','upload-installer','upload-state-probe','install','install-after-nonstart','passive-acceptance','probe','test-lib','test-bin','test-acl'])
|
||||
parser.add_argument('--artifact',type=Path)
|
||||
args=parser.parse_args()
|
||||
if args.action.startswith('upload-'):
|
||||
if args.artifact is None: parser.error('--artifact required')
|
||||
name={'upload-agent':'rmm-agent-windows.exe','upload-lib-tests':'windows-tests-lib.exe','upload-bin-tests':'windows-tests-bin.exe','upload-installer':'Install-PassiveClient.ps1'}[args.action]
|
||||
name={'upload-agent':'rmm-agent-windows.exe','upload-lib-tests':'windows-tests-lib.exe','upload-bin-tests':'windows-tests-bin.exe','upload-acl-tests':'windows-tests-acl.exe','upload-installer':'Install-PassiveClient.ps1','upload-state-probe':'PassiveStateProbe.exe'}[args.action]
|
||||
result=upload(args.artifact,name)
|
||||
print(json.dumps(result))
|
||||
elif args.action in ('install','install-after-nonstart'):
|
||||
@@ -156,6 +146,35 @@ def main():
|
||||
record(checkpoint+'.enrollment-token-hash.json',{'token_sha256':hashlib.sha256(material['token'].encode()).hexdigest(),'one_use':True})
|
||||
result=powershell(script,{'sha256':artifact['sha256'],'token':material['token'],'ca':material['ca']},timeout=90,remote_signed=args.action=='install-after-nonstart')
|
||||
record('installed.json',result);print(json.dumps(result))
|
||||
elif args.action=='passive-acceptance':
|
||||
import cloud_mvp_acceptance as cloud
|
||||
import remote_client_bootstrap as bootstrap
|
||||
identity=contract.protected_json(EVIDENCE/'service-initial-state.json')['identity']
|
||||
backend=cloud.Backend()
|
||||
first=backend.call('inventory.get_device',{'tenant_id':cloud.TENANT,'asset_id':identity['asset_id']})
|
||||
contract.require(first['presence']=='online' and first['source_id']=='windows.base' and first['inventory'] is not None,'native_windows_inventory_required')
|
||||
contract.require(set(first['capabilities'])=={'windows.base/1','heartbeat/1'} and first['inventory']['root_available_inodes'] is None,'honest_passive_capabilities')
|
||||
deadline=time.monotonic()+75
|
||||
while True:
|
||||
current=backend.call('inventory.get_device',{'tenant_id':cloud.TENANT,'asset_id':identity['asset_id']})
|
||||
if current['last_contact_at']!=first['last_contact_at']:break
|
||||
contract.require(time.monotonic()<deadline,'second_fresh_heartbeat_missing')
|
||||
time.sleep(2)
|
||||
contract.require(current['agent_id']==identity['agent_id'] and current['presence']=='online' and current['observed_at']==first['observed_at'],'same_persisted_identity_and_inventory')
|
||||
foreign=cloud.Backend('b')
|
||||
denied=[]
|
||||
for tenant in (cloud.TENANT,'22222222-2222-4222-8222-222222222222'):
|
||||
foreign.sequence+=1
|
||||
response=foreign.request({'jsonrpc':'2.0','id':foreign.sequence,'method':'tools/call','params':{'name':'inventory.get_device','arguments':{'tenant_id':tenant,'asset_id':identity['asset_id']}}})
|
||||
data=response.get('data',{})
|
||||
result=data.get('result',{})
|
||||
contract.require('error' in data or result.get('isError'),'foreign_windows_inventory_must_be_denied')
|
||||
denied.append({'tenant':tenant,'denied':True})
|
||||
gate=bootstrap.rpc('server.conf',cloud.server,{'kind':'gate','tenant_id':cloud.TENANT,'agent_id':identity['agent_id']})
|
||||
contract.require(gate=={'jobs':0,'outbox':0,'permits':0,'unresolved':0},'passive_agent_zero_jobs_required')
|
||||
report={'first':first,'second':current,'foreign_denied':denied,'gate':gate,'native_windows':True,'server':'discovery.ease-technologies.de','no_jobs_or_approvals':True}
|
||||
record('passive-acceptance.json',report)
|
||||
print(json.dumps({'native_windows':True,'source_id':current['source_id'],'two_fresh_heartbeats':True,'foreign_denied':len(denied),'gate':gate,'same_identity':True}))
|
||||
elif args.action=='probe':
|
||||
artifact=contract.protected_json(EVIDENCE/'rmm-agent-windows.exe.latest.json')
|
||||
result=powershell(PROBE,{'sha256':artifact['sha256']},timeout=60);record('native-probe-'+artifact['sha256']+'.json',result)
|
||||
@@ -163,7 +182,12 @@ def main():
|
||||
else:
|
||||
kind=args.action.removeprefix('test-')
|
||||
artifact=contract.protected_json(EVIDENCE/('windows-tests-'+kind+'.exe.latest.json'))
|
||||
result=powershell(TEST,{'kind':kind,'sha256':artifact['sha256']},timeout=120)
|
||||
access=contract.protected_json(ROOT/'credentials/windows-dev-access.json')
|
||||
command=REMOTE+'\\'+artifact['sha256']+'\\windows-tests-'+kind+'.exe --test-threads=1'
|
||||
native=subprocess.run(access['ssh_prefix']+[command],capture_output=True,timeout=60)
|
||||
summary=[line for line in native.stdout.decode('utf-8',errors='replace').splitlines() if line.startswith('test result: ')]
|
||||
contract.require(len(summary)==1,'native_test_summary_required')
|
||||
result={'exit_code':native.returncode,'native_execution':True,'artifact_sha256':artifact['sha256'],'summary':summary[0]}
|
||||
record(args.action+'.json',result);print(json.dumps(result))
|
||||
if result['exit_code']!=0:raise RuntimeError('NATIVE_WINDOWS_TEST_FAILED')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user