feat: add approval bound full maintenance script console and executors
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
@@ -0,0 +1,198 @@
|
||||
# Explizite Hostwartung mit full_maintenance_v1
|
||||
|
||||
Stand 2026-11-14, Spezifikation1.20. Die Batch-Skriptkonsole und der unabhängig
|
||||
geprüfte Fullhelper-Binärpinfix sind lokal implementiert und neu quellqualifiziert.
|
||||
Kein FullMaintenanceprofil wurde durch diese Dateien auf einem Ziel installiert,
|
||||
kein RMM-Job ausgeführt oder genehmigt. Cloud-Linux-VM zuerst, Windowsgast separat;
|
||||
Notebook ausschließlich Entwicklung.
|
||||
|
||||
## Aktueller korrigierter lokaler Nachweis
|
||||
|
||||
Der neue eigenständige Pack liegt privat unter
|
||||
`devstate/script-console-qualification/run-29461892-343f-42f4-b469-88703535425e/`.
|
||||
Manifest-SHA256:
|
||||
`ddd1a78d1cd289b02b1f98572f9652171ec00be84e01ce099fd722d689bcaacd`.
|
||||
158 vollständige Compiler-/Include-/Fixture-/Deploymentinputs vor/nach identisch.
|
||||
Sourcearchiv-SHA256:
|
||||
`fcb57f69ad81ea4acde15af6022d5c2da32f5699ebd39886c530c77882b369cc`.
|
||||
|
||||
Tatsächlich ausgeführt: Formatprüfung, Linux-Workspace-Alltargets-Clippy mit
|
||||
`-D warnings`,285 lokale Tests bestanden (5DB-Fälle zunächst ausgelassen), danach
|
||||
sämtliche45 Serververträge inklusive dieser5 gegen frisches isoliertes PostgreSQL
|
||||
bestanden (0ignored). Windows-GNU-Alltargets-Clippy mit -Dwarnings im Default-
|
||||
und SYSTEM-Helperprofil bestanden. Kein geänderter Test unterdrückt; die neue
|
||||
Imageprüfung führt auch bei nicht vertrauenswürdigem Dateibesitz echte
|
||||
Verweigerungsassertions aus, keinen stillen Early-return-Skip.
|
||||
|
||||
Neue tatsächliche Linux-Unitlisten: Domain22, Linuxruntime16, Helperpolicy6,
|
||||
Serververträge45. Auf Cloud-Linux ohne isolierte DB erwartet:84PASS und5explizite
|
||||
DBignored; diese5 sind separat im lokalen45er-DB-Lauf tatsächlich bestanden.
|
||||
Alle vier vollständigen Listen müssen vor irgendeinem Unitstart geprüft sein.
|
||||
Linux-Release-Helper SHA256
|
||||
`79442727c3ba31cda02a8bc0e67481f14db9f39fc07520a880a90b64f10f1eaf`;
|
||||
Agent `0a7ad6eefaefda79ee80b6a41b2df904e9e7f50ae6ebeed01b98c25b6ce5c06f`;
|
||||
Server `610017637a9f9e55a6cb3cd8264937b953996af84e86dd49f2ea00c8e59739cd`.
|
||||
Keine dieser neuen Binaries ist durch den Builder auf einem Ziel installiert.
|
||||
Native Cloud-Linux-/Windows-Units, Erhaltungsbootstrap und WebUI-genehmigter
|
||||
FullMaintenancejob bleiben ausdrücklich offen.
|
||||
|
||||
## Frühere lokale Nachweise und der danach behobene Binärpinbefund
|
||||
|
||||
Das eingefrorene Paket liegt ausschließlich privat unter
|
||||
`devstate/script-console-qualification/run-de34d47c-985e-460c-b18c-3f0d1b3fd315/`.
|
||||
Manifest-SHA256:
|
||||
`60a50262f9f8d85c11eb58e1a9e0f6e03be6cd5db7a59bc1745fb7d9dc8a6f65`.
|
||||
157 Compiler-, Include-, Fixture- und Deploymentinputs wurden vor/nach dem
|
||||
vollständigen Lauf identisch geprüft. `reviewed-sources.tar.gz`:
|
||||
`ef822b2e2ec6f8ad3d828f0923b2aa886d462fba328affb61bd80e98acf2c357`.
|
||||
|
||||
Tatsächlich lokal ausgeführt: Formatprüfung; Linux-Workspace-Clippy mit allen
|
||||
Targets und `-D warnings`; Workspace284PASS bei fünf zunächst ausgelassenen
|
||||
DB-Fällen; anschließend sämtliche45 Servertests mit `--include-ignored` in
|
||||
frischem isoliertem PostgreSQL17.6:45PASS,0ignored. DB ohne veröffentlichten Port,
|
||||
Netzwerknamespace ausschließlich intern, frische Rollen/Migrationen, danach
|
||||
entfernt. Keine Produktionsdatenbank. Windows-GNU-Alltargets-Clippy separat im
|
||||
Default- und SYSTEM-Helperprofil jeweils bestanden; keine native Windowsausführung.
|
||||
Linux-Releasebinaries und vier native Linux-Testprogramme dieses früheren
|
||||
Quellenstands sind gebaut/gehasht, noch nicht auf der Cloud-VM ausgeführt oder
|
||||
installiert. **Nachträglicher unabhängiger Reviewblocker:** Dieser Pack bindet
|
||||
noch nicht den tatsächlichen laufenden Linux-Fullhelpercodehash. Er berechtigt
|
||||
keine Fullprofilaktivierung. Der danach separat geprüfte und im neuen Pack qualifizierte enge Corefix ergänzt ausschließlich
|
||||
im Fullprofil tatsächliches gehaltenes `/proc/self/exe`, geschützten Binärpin,
|
||||
authentisierte Probe, zusätzliche Binärcapability und zentrale Hashprüfung.
|
||||
General/APT lassen neue Metadaten vollständig aus. Der neue lokale Stand steht
|
||||
oben; dieser alte Pack bleibt ausdrücklich der ursprüngliche Beleg.
|
||||
|
||||
Die ersten Packvorbereitungen erzeugten kein qualifiziertes Manifest: Der erste
|
||||
before/after-Schutz bemerkte die währenddessen vervollständigte Builderinputliste;
|
||||
der zweite hielt bei PostgreSQLs temporärer Initialisierungsphase an. Der finale
|
||||
oben genannte Lauf wartet auf den endgültigen TCP-Endpunkt und besteht vollständig.
|
||||
Diese Vorbereitungsläufe werden nicht zu bestandenen Abnahmen umgedeutet.
|
||||
|
||||
## Separater Linux-first-Unitrunner
|
||||
|
||||
Der Runner `deploy/script_console_acceptance.py` ist separat reviewbar und kein
|
||||
Teil der158 eingefrorenen Compilerinputs; er baut und verändert diese nicht.
|
||||
Er ist ausdrücklich auf den neuen Pack29461892 und dessen Manifestddd1a78d…
|
||||
gebunden; bei veränderten Compilerinputs wird ein neuer Start verweigert. Die
|
||||
ursprüngliche Vorbereitung für Packde34 bleibt ein früherer, nie ausgeführter
|
||||
Runnerstand. Die jetzigen Counts beruhen auf den tatsächlich erzeugten Listen.
|
||||
Runnerquellhash:
|
||||
`2b3ba8d548d18627643a9f73c9a4f7bacce4ac2cd5495745c6760d088e078145`.
|
||||
Supportquellen werden vor Import und jedem Zielaufruf inklusive Readback exakt
|
||||
geprüft und in Intent/Payload/Result gebunden: Runtime-Bootstraphelper
|
||||
`833ad8806c90a19342aa6fbc71c33e81975caffb1746550e9b0fbdca7fa0c7ab`,
|
||||
Zugangsparser
|
||||
`5c8107ea9151a9f498b2530cdc61c1a7a6d745aff853a9b05710f3395838c0dd`.
|
||||
Der finale Readback verlangt product_state_writes, rmm_jobs,
|
||||
capabilities_activated und approvals ausdrücklich jeweils false.
|
||||
Er verwendet ausschließlich den vorhandenen strikten Bootstraptransport und
|
||||
`credentials/linux-vm.conf` im ursprünglichen Hauptcheckout, ausschließlich als root auf der festgelegten Linux-Test-VM, mit vorhandenem
|
||||
SSH-Key und strenger Hostprüfung. Keine
|
||||
Zugangsdatenkopie ins Scriptworktree, keine alternative IP oder Passwortfallback.
|
||||
|
||||
**Geplant, noch nicht ausgeführt:**
|
||||
|
||||
```bash
|
||||
python3 deploy/script_console_acceptance.py execute-linux
|
||||
```
|
||||
|
||||
Es entstehen nur neue private Scratchdateien unter
|
||||
`/var/lib/rmm-script-console-contracts/<case-id>/`. Erst werden alle vier exakten
|
||||
ELF-Hashes und vollständigen Listen geprüft; kein Unitstart vor dem gesamten
|
||||
Listenbeleg. Danach feste Testargumente, geleerte Umgebung, eigenes TMPDIR,
|
||||
eigener Netzwerknamespace und CPU-/Speicher-/Dateilimits. Erwartet werden84PASS
|
||||
und fünf ausdrücklich ausgelassene DB-Fälle auf der VM ohne DB; dieselben fünf
|
||||
DB-Verträge sind bereits im isolierten lokalen45er-Lauf belegt. Keine Installation,
|
||||
Enrollment-, Dienst-, Policy-, Paket-, Schlüssel-, Journal- oder Capabilityänderung.
|
||||
|
||||
Bei verlorenem Ergebnis ausschließlich denselben ursprünglichen Fall lesen:
|
||||
|
||||
```bash
|
||||
python3 deploy/script_console_acceptance.py read-linux --case <urspruengliche-case-id>
|
||||
```
|
||||
|
||||
Readback erzeugt keinen zweiten Remote-Start. Ein vorhandener Create-once-
|
||||
Startmarker erlaubt kein erneutes `run`; Teilergebnisse bleiben erhalten. Ein
|
||||
unvollständiger/fehlender Beleg ist keine bestandene Abnahme und wird nicht blind
|
||||
wiederholt. Native Units sind keine RMM-Dienst-/WebUI-/FullMaintenanceabnahme.
|
||||
|
||||
## Bootstrapvorbereitung nach gesondertem Erhaltungsreview
|
||||
|
||||
Die folgenden Schritte sind nur geplant. Aktuelle Cloudbelege, Geräte-/Boot-/
|
||||
Journalidentitäten, Inodes, Verbrauchszeilen und Dienstzustände werden vor einer
|
||||
Änderung durch den verantwortlichen Rootprozess unabhängig gegengeprüft. Die
|
||||
bisherigen General-/APT-Units und Pins sowie deren Historie bleiben erhalten;
|
||||
keine Ledgerkopie, kein Reset und kein stilles Öffnen alter Scopes.
|
||||
|
||||
Die neue Unit ist `deploy/linux/rmm-full-maintenance-helper.service` mit eigenem
|
||||
Runtimeverzeichnis `/run/rmm-helper-maintenance`. Sie verweist auf
|
||||
`/etc/rmm-remote/helper-full-maintenance.json`. Diese Konfiguration erhält exakt
|
||||
die bestehende provisionierte öffentliche Bindingidentität und dieselben
|
||||
Root-Sharedledger-/Lockdateien; neue Auswahl:
|
||||
|
||||
```json
|
||||
{
|
||||
"profile": "full_maintenance_v1",
|
||||
"allowed_services": [],
|
||||
"allow_reboot": false,
|
||||
"allow_root_scripts": true,
|
||||
"allowed_script_profiles": ["full_maintenance_v1"],
|
||||
"helper_binary_sha256": "<tatsaechlicher SHA256 der qualifizierten laufenden Helperbinary>"
|
||||
}
|
||||
```
|
||||
|
||||
Das ist ein Ausschnitt, keine vollständige einsatzfähige Konfiguration. Socket,
|
||||
Agent-UID/GID, Zustandspfad und bestehendes Binding müssen aus dem tatsächlich
|
||||
geprüften Bestand kommen. Kein `apt_provider`. `allow_reboot=false` verweigert
|
||||
nur die typisierte Rebootaction; genehmigter Rootcode besitzt volle Hostautorität.
|
||||
|
||||
Der separat geschützte Policy-Pin bindet Profil `full_maintenance_v1`, bestehende
|
||||
Identität, tatsächlichen lokalen Policyhash und unabhängig beobachteten
|
||||
laufenden Binärhash. Das neue Fullprofil benötigt Schema2 im Pin; der Helper
|
||||
kann diesen nach selbst geprüftem Rootimage mit dem ausdrücklich getrennten
|
||||
Bootstrapmodus `--inspect-full-maintenance-profile` ausgeben. Generalpin
|
||||
Schema1 bleibt unverändert. Agentumgebung ausschließlich
|
||||
additiv um `RMM_FULL_MAINTENANCE_HELPER_SOCKET` und
|
||||
`RMM_FULL_MAINTENANCE_POLICY_FILE` ergänzen. Kein Fallback auf General/APT und
|
||||
keine Änderung deren bestehender Umgebung. Die zentrale Rootpolicy braucht
|
||||
Schema2 und einen ausdrücklich begrenzten Scope mit neuen exakten Helperpins
|
||||
sowie `allowed_script_profiles=["full_maintenance_v1"]`. Aktuelle Rechte beider
|
||||
Planakteure, Helper-Sync, TrustedClock, ursprünglicher Grant und Einmalverbrauch
|
||||
bleiben zusätzlich erforderlich. Eine Policy ist keine Jobgenehmigung.
|
||||
|
||||
Vor Installation werden zusammengesetzte systemd-Unit und etwaige Drop-ins
|
||||
geprüft: Vollwartung darf keine General-Sandbox erben, die Hostdateisystem oder
|
||||
Netzwerk unerwartet sperrt. Dienst- und Binärwechsel nur mit qualifizierten
|
||||
Artefakten und explizitem Erhaltungsplan. Insbesondere darf eine neue allgemeine
|
||||
Helperbinary nicht still die alten APT-Codepins überschreiben/öffnen. Gegebenenfalls
|
||||
eigenen qualifizierten Binärpfad für die neue FullMaintenanceunit wählen und die
|
||||
bestehenden Providerpfade unverändert erhalten. Native Erhaltung und Sync nachweisen,
|
||||
bevor neue Capabilities/Scopes geöffnet werden.
|
||||
|
||||
Erster tatsächlicher FullMaintenancejob nur nach bereitgestellter WebUI und
|
||||
expliziter Genehmigung der unveränderlichen Skript-/Profil-/Ziel-/Rechtebytes.
|
||||
Abgestimmter Scope: harmlose Identität/stdout/stderr und kontrollierte lesende
|
||||
Dateisystem-/Netzwerkbeobachtung; kein Betriebssystemupdate oder Neustart. Volle
|
||||
Hostautorität wird sichtbar erklärt; kein Sandbox-, No-Reboot- oder Rollbackversprechen.
|
||||
Windows-SYSTEM folgt nach eigenem Clock-/Pipe-/Profilnachweis. Die vorhandene
|
||||
PipeV2-Datei ist unverändert SHA256
|
||||
`ce525dab23f2e4faa2c9816280c1a5a8b40e56d0e63a350256e83b2df1d9229d`;
|
||||
ursprüngliche native Pipebelege werden nicht als Belege der neuen Runtime ausgegeben.
|
||||
|
||||
## Anschließend auf der tatsächlichen Cloud-Linux-VM bestanden
|
||||
|
||||
Root führte ausschließlich den korrigierten Pack29461892 nativ aus: Fall
|
||||
`7b61ce46-7913-492b-9c6b-414a0c2b6ffc`, **84PASS,5explizite DBignored**.
|
||||
Die vier vollständigen tatsächlichen Listen wurden vor irgendeinem Unitstart
|
||||
exakt geprüft; anschließend liefen alle vier festen ELFs im eigenen Scratch,
|
||||
mit geleerter Umgebung, Netzwerknamespace und Ressourcenlimits. Die5DB-Verträge
|
||||
bleiben diesem VM-Lauf ausdrücklich nicht zugerechnet; sie sind im separaten
|
||||
isolierten45er-PostgreSQL-Lauf belegt. Kein stiller Testskip oder Produktjob.
|
||||
|
||||
Beleg `passed-e214cd9b-21ac-48ce-82dc-d10364329d04.json`, SHA256
|
||||
`a831a70a3cf76a3e8a9bf5820dcca7100d2ef9860dd9388539fe9c13f949f470`.
|
||||
Keine Agent-/Helperinstallation, Änderung bestehender Dienste/Policies/PKI/
|
||||
Datenbanken, veröffentlichte Capability oder WebUI-Genehmigung durch diesen
|
||||
Unitlauf. Der oben ursprünglich geplante Unitaufruf ist damit abgeschlossen;
|
||||
Bootstrap, tatsächlicher FullMaintenancejob und Windowsabnahme bleiben offen.
|
||||
@@ -0,0 +1,31 @@
|
||||
[Unit]
|
||||
Description=RMM explicitly approved full host maintenance script helper
|
||||
After=time-sync.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
# Deliberate full host authority for separately approved full_maintenance_v1
|
||||
# scripts. This is NOT a sandbox and cannot promise no reboot or agent changes.
|
||||
User=root
|
||||
Group=rmm-agent
|
||||
StateDirectory=rmm-helper
|
||||
StateDirectoryMode=0700
|
||||
RuntimeDirectory=rmm-helper-maintenance
|
||||
RuntimeDirectoryMode=0750
|
||||
UMask=0077
|
||||
Environment=RMM_HELPER_CONFIG=/etc/rmm-remote/helper-full-maintenance.json
|
||||
ExecStart=/usr/local/libexec/rmm-privileged-helper
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
# Retain the host filesystem, network, home paths, capabilities and syscalls.
|
||||
# General/APT units keep their existing restrictions. No inherited hardening
|
||||
# drop-in may silently contradict this profile; inspect merged unit predeploy.
|
||||
PrivateTmp=false
|
||||
PrivateNetwork=false
|
||||
ProtectSystem=false
|
||||
ProtectHome=false
|
||||
NoNewPrivileges=false
|
||||
KillMode=control-group
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,251 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Fixed frozen Linux unit pack: prepare/run once, same-case readback only.
|
||||
|
||||
Uses existing strict bootstrap transport. No agent installation, RMM job,
|
||||
approval, policy, package, service or device-identity change.
|
||||
"""
|
||||
import argparse
|
||||
import base64
|
||||
import hashlib
|
||||
import inspect
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
import uuid
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
SUPPORT_FILES = {
|
||||
'deploy/windows_msi_runtime_acceptance.py': '833ad8806c90a19342aa6fbc71c33e81975caffb1746550e9b0fbdca7fa0c7ab',
|
||||
'deploy/vm_access_check.py': '5c8107ea9151a9f498b2530cdc61c1a7a6d745aff853a9b05710f3395838c0dd',
|
||||
}
|
||||
|
||||
def verify_support():
|
||||
for name, digest in SUPPORT_FILES.items():
|
||||
path=ROOT/name
|
||||
if path.is_symlink() or hashlib.sha256(path.read_bytes()).hexdigest()!=digest:
|
||||
raise RuntimeError("Pinned bootstrap support source changed")
|
||||
|
||||
# Check helpers before import and again before every target call/readback.
|
||||
verify_support()
|
||||
import windows_msi_runtime_acceptance as support
|
||||
if Path(support.__file__).resolve()!=ROOT/'deploy/windows_msi_runtime_acceptance.py' or Path(support.access.__file__).resolve()!=ROOT/'deploy/vm_access_check.py':
|
||||
raise RuntimeError("Unexpected bootstrap support module origin")
|
||||
PACK = ROOT / 'devstate/script-console-qualification/run-29461892-343f-42f4-b469-88703535425e'
|
||||
MANIFEST_SHA = 'ddd1a78d1cd289b02b1f98572f9652171ec00be84e01ce099fd722d689bcaacd'
|
||||
STATE = ROOT / 'devstate/script-console-native'
|
||||
REMOTE = '/var/lib/rmm-script-console-contracts'
|
||||
PROFILE = 'script-console-linux-units-v1'
|
||||
KINDS = ('domain-tests', 'linux-runtime-tests', 'helper-policy-tests', 'server-contract-tests')
|
||||
COUNTS = {'domain-tests': (22, 0), 'linux-runtime-tests': (16, 0),
|
||||
'helper-policy-tests': (6, 0), 'server-contract-tests': (40, 5)}
|
||||
|
||||
|
||||
def require(value, code):
|
||||
if not value:
|
||||
raise RuntimeError(code)
|
||||
|
||||
|
||||
def native_case(p):
|
||||
import base64
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import resource
|
||||
import stat
|
||||
import subprocess
|
||||
import uuid
|
||||
kinds = ('domain-tests', 'linux-runtime-tests', 'helper-policy-tests', 'server-contract-tests')
|
||||
counts = {'domain-tests': (22, 0), 'linux-runtime-tests': (16, 0),
|
||||
'helper-policy-tests': (6, 0), 'server-contract-tests': (40, 5)}
|
||||
ident = str(uuid.UUID(p['id']))
|
||||
require(ident == p['id'] and p['action'] in ('prepare', 'run', 'read')
|
||||
and p['profile'] == 'script-console-linux-units-v1', 'fixed unit case')
|
||||
require(os.geteuid() == 0 and os.uname().machine == 'x86_64'
|
||||
and set(p['artifacts']) == set(kinds), 'fixed Linux bootstrap qualification')
|
||||
root = Path('/var/lib/rmm-script-console-contracts')
|
||||
|
||||
def safe(path, directory):
|
||||
s = path.lstat()
|
||||
require(not stat.S_ISLNK(s.st_mode) and s.st_uid == 0
|
||||
and stat.S_IMODE(s.st_mode) == (0o700 if directory else 0o600)
|
||||
and (stat.S_ISDIR(s.st_mode) if directory else stat.S_ISREG(s.st_mode) and s.st_nlink == 1),
|
||||
'private fixed unit path')
|
||||
|
||||
def write(path, value):
|
||||
fd = os.open(path, os.O_CREAT | os.O_EXCL | os.O_WRONLY | os.O_NOFOLLOW, 0o600)
|
||||
with os.fdopen(fd, 'w') as out:
|
||||
json.dump(value, out); out.flush(); os.fsync(out.fileno())
|
||||
|
||||
os.umask(0o077)
|
||||
case = root / ident
|
||||
if p['action'] == 'read' and not case.exists():
|
||||
return dict(id=ident, status='remote_case_absent')
|
||||
if p['action'] == 'prepare':
|
||||
if not root.exists():
|
||||
root.mkdir(mode=0o700)
|
||||
safe(root, True); case.mkdir(mode=0o700); write(case / 'intent.json', p)
|
||||
return dict(id=ident, prepared=True)
|
||||
safe(root, True); safe(case, True); safe(case / 'intent.json', False)
|
||||
original = json.loads((case / 'intent.json').read_bytes())
|
||||
require({k: v for k, v in p.items() if k != 'action'} ==
|
||||
{k: v for k, v in original.items() if k != 'action'}, 'original complete intent')
|
||||
if p['action'] == 'read':
|
||||
if not (case / 'result.json').exists():
|
||||
partial = {}
|
||||
for kind in kinds:
|
||||
for suffix in ('-list.json', '-result.json'):
|
||||
path = case / (kind + suffix)
|
||||
if path.exists():
|
||||
safe(path, False); require(path.stat().st_size <= 3 * 1024 * 1024, 'bounded partial receipt')
|
||||
partial[kind + suffix] = json.loads(path.read_bytes())
|
||||
return dict(id=ident, status='started_without_result' if (case / 'started.json').exists() else 'prepared_without_start',
|
||||
all_lists_verified=(case / 'all-lists-verified.json').exists(),
|
||||
tests_started=(case / 'tests-started.json').exists(), partial=partial)
|
||||
safe(case / 'result.json', False)
|
||||
require((case / 'result.json').stat().st_size <= 12 * 1024 * 1024, 'bounded final receipt')
|
||||
return json.loads((case / 'result.json').read_bytes())
|
||||
write(case / 'started.json', dict(manifest_sha256=p['manifest_sha256'], execute_once=True))
|
||||
temp = case / 'tmp'; temp.mkdir(mode=0o700)
|
||||
env = {'PATH': '/usr/sbin:/usr/bin:/sbin:/bin', 'LANG': 'C.UTF-8', 'LC_ALL': 'C.UTF-8',
|
||||
'TMPDIR': str(temp), 'RUST_BACKTRACE': '0'}
|
||||
|
||||
def limits():
|
||||
resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
|
||||
resource.setrlimit(resource.RLIMIT_CPU, (30, 30))
|
||||
resource.setrlimit(resource.RLIMIT_FSIZE, (16 * 1024 * 1024, 16 * 1024 * 1024))
|
||||
resource.setrlimit(resource.RLIMIT_AS, (768 * 1024 * 1024, 768 * 1024 * 1024))
|
||||
|
||||
require(subprocess.run(['/usr/bin/unshare', '--net', '--', '/usr/bin/true'], env=env,
|
||||
capture_output=True, timeout=3).returncode == 0, 'network namespace required')
|
||||
listings = {}
|
||||
for kind in kinds:
|
||||
binary = case / kind; safe(binary, False)
|
||||
raw = binary.read_bytes()
|
||||
require(len(raw) == p['artifacts'][kind]['bytes'] and len(raw) <= 64 * 1024 * 1024
|
||||
and hashlib.sha256(raw).hexdigest() == p['artifacts'][kind]['sha256']
|
||||
and raw[:6] == b'\x7fELF\x02\x01' and raw[18:20] == b'\x3e\0', 'exact Linux x64 ELF')
|
||||
binary.chmod(0o500)
|
||||
listed = subprocess.run(['/usr/bin/unshare', '--net', '--', str(binary), '--list', '--format', 'terse'],
|
||||
cwd=case, env=env, capture_output=True, timeout=8, preexec_fn=limits)
|
||||
require(listed.returncode == 0 and len(listed.stdout) <= 65536 and len(listed.stderr) <= 65536,
|
||||
'bounded actual listing')
|
||||
actual = sorted(line[:-6] for line in listed.stdout.decode().splitlines() if line.endswith(': test'))
|
||||
write(case / (kind + '-list.json'), dict(names=actual, exit_code=listed.returncode,
|
||||
sha256=p['artifacts'][kind]['sha256'], stdout_b64=base64.b64encode(listed.stdout).decode(),
|
||||
stderr_b64=base64.b64encode(listed.stderr).decode()))
|
||||
require(all(not line.strip() or re.fullmatch(r'[A-Za-z0-9_:]+: test', line)
|
||||
for line in listed.stdout.decode().splitlines())
|
||||
and actual == p['names'][kind] and len(actual) == sum(counts[kind]),
|
||||
'all exact lists BEFORE any unit execution')
|
||||
listings[kind] = actual
|
||||
write(case / 'all-lists-verified.json', dict(all_lists_before_any_tests=True, manifest_sha256=p['manifest_sha256']))
|
||||
write(case / 'tests-started.json', dict(execute_tests_once=True))
|
||||
reports = {}
|
||||
for kind in kinds:
|
||||
timed = False
|
||||
with (case / (kind + '-stdout.bin')).open('xb') as out, (case / (kind + '-stderr.bin')).open('xb') as err:
|
||||
try:
|
||||
code = subprocess.run(['/usr/bin/unshare', '--net', '--', str(case / kind), '--test-threads=1'],
|
||||
cwd=case, env=env, stdin=subprocess.DEVNULL, stdout=out, stderr=err,
|
||||
timeout=45, preexec_fn=limits).returncode
|
||||
except subprocess.TimeoutExpired:
|
||||
timed = True; code = None
|
||||
out.flush(); err.flush(); os.fsync(out.fileno()); os.fsync(err.fileno())
|
||||
raw, errors = [(case / (kind + '-' + stream + '.bin')).read_bytes() for stream in ('stdout', 'stderr')]
|
||||
require(len(raw) <= 1048576 and len(errors) <= 1048576, 'bounded native output')
|
||||
reports[kind] = dict(sha256=p['artifacts'][kind]['sha256'], names=listings[kind], exit_code=code,
|
||||
timed_out=timed, stdout_b64=base64.b64encode(raw).decode(), stderr_b64=base64.b64encode(errors).decode())
|
||||
write(case / (kind + '-result.json'), reports[kind])
|
||||
passed, ignored = counts[kind]
|
||||
require(code == 0 and not timed and re.search(
|
||||
rf'test result: ok\. {passed} passed; 0 failed; {ignored} ignored;', raw.decode()),
|
||||
'exact native pass/ignored count; no retry')
|
||||
value = dict(id=ident, platform='linux', profile=p['profile'], manifest_sha256=p['manifest_sha256'],
|
||||
runner_sha256=p['runner_sha256'], support_files=p['support_files'], reports=reports, all_lists_before_any_tests=True,
|
||||
network_namespace=True, environment_cleared=True, product_state_writes=False, rmm_jobs=False,
|
||||
capabilities_activated=False, approvals=False, passed=84, ignored_database_cases=5)
|
||||
write(case / 'result.json', value)
|
||||
return value
|
||||
|
||||
|
||||
def rpc(prefix, payload, folder):
|
||||
verify_support()
|
||||
code = inspect.getsource(require) + '\n' + inspect.getsource(native_case)
|
||||
code += '\ntry:\n print(__import__("json").dumps(native_case(' + repr(payload) + ')))\nexcept Exception as e:\n print(__import__("json").dumps(dict(bootstrap_error=True,error_class=type(e).__name__)))\n'
|
||||
return support.transport(prefix, 'python3 -', code.encode(), folder, timeout=230)
|
||||
|
||||
|
||||
def run(case_id=None):
|
||||
import os
|
||||
verify_support()
|
||||
os.umask(0o077); STATE.mkdir(mode=0o700, parents=True, exist_ok=True)
|
||||
support.private(STATE, True); support.private(PACK, True)
|
||||
manifest = support.load(PACK / 'manifest.json')
|
||||
require(support.sha(PACK / 'manifest.json') == MANIFEST_SHA
|
||||
and manifest['source_before_after_equal'] is True
|
||||
and manifest['type'] == 'rmm.script-console.local-source-qualification', 'frozen original qualification')
|
||||
if case_id is None:
|
||||
require(all(support.sha(ROOT / name) == digest for name, digest in manifest['source_files'].items()), 'new attempt uses exact frozen source')
|
||||
case_id = str(uuid.uuid4()); folder = STATE / case_id; folder.mkdir(mode=0o700)
|
||||
names = {}; artifacts = {}
|
||||
for kind in KINDS:
|
||||
artifact = PACK / kind; support.private(artifact)
|
||||
require(support.sha(artifact) == manifest['artifacts'][kind]['sha256'], 'original ELF bytes')
|
||||
log = PACK / (kind + '-list.log'); support.private(log)
|
||||
require(support.sha(log) == manifest['checks'][kind + '-list']['log_sha256'], 'original actual list')
|
||||
names[kind] = sorted(line[:-6] for line in log.read_text().splitlines() if line.endswith(': test'))
|
||||
require(len(names[kind]) == sum(COUNTS[kind]), 'fixed original test count')
|
||||
artifacts[kind] = {key: manifest['artifacts'][kind][key] for key in ('sha256', 'bytes')}
|
||||
payload = dict(id=case_id, profile=PROFILE, manifest_sha256=MANIFEST_SHA,
|
||||
runner_sha256=support.sha(__file__), support_files=SUPPORT_FILES, names=names, artifacts=artifacts)
|
||||
support.save(folder / 'intent.json', payload)
|
||||
support.save(folder / 'started-local.json', dict(create_once=True, no_retry=True))
|
||||
prefix = support.access_settings(support.ACCESS_ROOT, 'linux')
|
||||
require(rpc(prefix, dict(payload, action='prepare'), folder) == dict(id=case_id, prepared=True), 'fresh fixed case prepared')
|
||||
for kind in KINDS:
|
||||
support.upload(prefix, dict(path=str(PACK / kind), **artifacts[kind]), REMOTE + '/' + case_id + '/' + kind, folder, kind)
|
||||
action = 'run'
|
||||
else:
|
||||
require(str(uuid.UUID(case_id)) == case_id, 'original canonical case id')
|
||||
folder = STATE / case_id; support.private(folder, True)
|
||||
payload = support.load(folder / 'intent.json'); support.load(folder / 'started-local.json')
|
||||
require(payload['id'] == case_id and payload['manifest_sha256'] == MANIFEST_SHA
|
||||
and payload['runner_sha256'] == support.sha(__file__)
|
||||
and payload['support_files'] == SUPPORT_FILES, 'immutable original readback only')
|
||||
prefix = support.access_settings(support.ACCESS_ROOT, 'linux')
|
||||
action = 'read'
|
||||
value = rpc(prefix, dict(payload, action=action), folder)
|
||||
support.save(folder / ('readback-' + str(uuid.uuid4()) + '.json'), value)
|
||||
if value.get('status'):
|
||||
require(action == 'read', 'only same-case readback can report incomplete state')
|
||||
print(json.dumps(dict(case_id=case_id, verified=False, status=value['status'], retry_allowed=False)))
|
||||
return
|
||||
require(value['id'] == case_id and value['manifest_sha256'] == MANIFEST_SHA
|
||||
and value['runner_sha256'] == payload['runner_sha256'] and value['passed'] == 84
|
||||
and value['ignored_database_cases'] == 5 and value['all_lists_before_any_tests'] is True
|
||||
and value['network_namespace'] is True and value['environment_cleared'] is True
|
||||
and value['support_files'] == SUPPORT_FILES
|
||||
and all(value.get(flag) is False for flag in ('product_state_writes','rmm_jobs','capabilities_activated','approvals'))
|
||||
and set(value['reports']) == set(KINDS), 'complete native receipt')
|
||||
for kind in KINDS:
|
||||
item = value['reports'][kind]; passed, ignored = COUNTS[kind]
|
||||
require(item['names'] == payload['names'][kind] and item['sha256'] == payload['artifacts'][kind]['sha256']
|
||||
and item['exit_code'] == 0 and item['timed_out'] is False
|
||||
and re.search(rf'test result: ok\. {passed} passed; 0 failed; {ignored} ignored;',
|
||||
base64.b64decode(item['stdout_b64'], validate=True).decode()), 'each original native result')
|
||||
proof = dict(verified=True, case_id=case_id, manifest_sha256=MANIFEST_SHA, native=value,
|
||||
native_services_or_rmm_job_acceptance=False)
|
||||
path = folder / ('passed-' + str(uuid.uuid4()) + '.json'); support.save(path, proof)
|
||||
print(json.dumps(dict(case_id=case_id, verified=True, proof=str(path), sha256=support.sha(path), passed=84,
|
||||
ignored_database_cases=5, rmm_jobs=False, retry_allowed=False)))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('mode', choices=('execute-linux', 'read-linux'))
|
||||
parser.add_argument('--case')
|
||||
args = parser.parse_args()
|
||||
require((args.mode == 'read-linux') == (args.case is not None), 'read needs original case; execute always new case')
|
||||
run(args.case)
|
||||
@@ -0,0 +1,152 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Offline source qualification and Linux delivery pack. No SSH or deployment.
|
||||
|
||||
This tool never enrolls an agent, starts a daemon, edits a policy or approves a
|
||||
job. Linux/Windows VM execution and full-profile activation remain separate.
|
||||
"""
|
||||
import datetime as dt
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import tarfile
|
||||
import time
|
||||
import uuid
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
LINUX_IMAGE = 'sha256:9a76ad3744ebfdddae96ca10001ce8291c1b332fb54c8df5eea0e8e999ac6fc6'
|
||||
WINDOWS_IMAGE = 'sha256:1b2fd985d2c1fcc3545ace602405dc68fa899201bd8a73fa319ff96377203fa9'
|
||||
POSTGRES_IMAGE = 'sha256:567d5d704a3e5a4864393b623a0d50eb1b5a4ad134cdac7cf19555cb2d8ffe9e'
|
||||
|
||||
|
||||
def sha(path):
|
||||
return hashlib.sha256(Path(path).read_bytes()).hexdigest()
|
||||
|
||||
|
||||
def inputs():
|
||||
paths = [ROOT / p for p in ('Cargo.toml', 'Cargo.lock', 'rust-toolchain.toml',
|
||||
'tests/backend_root_logs.rs', 'tests/script_console/codec-golden.json',
|
||||
'tests/apt_transaction/fixtures/planning-canonical.json',
|
||||
'tools/apt-transaction/apt_transaction.py', 'tools/apt-transaction/hook',
|
||||
'deploy/linux/rmm-apt-helper.service',
|
||||
'deploy/linux/rmm-full-maintenance-helper.service', 'deploy/script_console_build.py')]
|
||||
paths += [p for p in (ROOT / 'crates').rglob('*')
|
||||
if p.is_file() and p.suffix in ('.rs', '.toml', '.c', '.h', '.idl', '.sql')]
|
||||
paths += [p for p in (ROOT / 'tests').rglob('*.rs')]
|
||||
paths += [p for p in (ROOT / 'migrations').rglob('*.sql')]
|
||||
paths += [p for p in (ROOT / 'proto').rglob('*') if p.is_file() and p.suffix == '.proto']
|
||||
for path in paths:
|
||||
if path.is_symlink():
|
||||
raise RuntimeError('Symlink compiler input refused: ' + str(path.relative_to(ROOT)))
|
||||
return {str(p.relative_to(ROOT)): sha(p) for p in sorted(set(paths))}
|
||||
|
||||
|
||||
def main():
|
||||
os.umask(0o077)
|
||||
state = ROOT / 'devstate/script-console-qualification'
|
||||
state.mkdir(mode=0o700, parents=True, exist_ok=True)
|
||||
out = state / ('run-' + str(uuid.uuid4()))
|
||||
out.mkdir(mode=0o700)
|
||||
frozen = inputs()
|
||||
checks = {}
|
||||
|
||||
def command(label, args):
|
||||
result = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, check=False)
|
||||
log = out / (label + '.log')
|
||||
log.write_bytes(result.stdout)
|
||||
checks[label] = {'exit_code': result.returncode, 'log_sha256': sha(log)}
|
||||
if result.returncode:
|
||||
raise RuntimeError(label + ' failed; inspect private log ' + str(log))
|
||||
return result.stdout
|
||||
|
||||
def cargo(label, image, *args):
|
||||
target = ROOT / ('devstate/script-console-windows-target' if image == WINDOWS_IMAGE else 'devstate/script-console-target')
|
||||
target.mkdir(mode=0o700, exist_ok=True)
|
||||
return command(label, ['docker', 'run', '--rm', '--network', 'none', '--read-only',
|
||||
'--tmpfs', '/tmp:rw,size=512m', '-v', str(ROOT) + ':/src:ro', '-v', str(target) + ':/target',
|
||||
'-e', 'CARGO_TARGET_DIR=/target', '--entrypoint', 'cargo', image, *args])
|
||||
|
||||
common = ['--manifest-path', '/src/Cargo.toml', '--locked', '--offline']
|
||||
cargo('format', LINUX_IMAGE, 'fmt', '--manifest-path', '/src/Cargo.toml', '--all', '--check')
|
||||
cargo('linux-clippy', LINUX_IMAGE, 'clippy', *common, '--workspace', '--all-targets', '--', '-D', 'warnings')
|
||||
cargo('linux-tests', LINUX_IMAGE, 'test', *common, '--workspace', '--all-targets')
|
||||
# Existing ignored DB contracts use their own fresh PostgreSQL, internal
|
||||
# network namespace only. No published port, production URL or real device.
|
||||
pg_name='rmm-script-contract-'+uuid.uuid4().hex[:12]
|
||||
command('postgres-start',['docker','run','-d','--network','none','--name',pg_name,'-e','POSTGRES_HOST_AUTH_METHOD=trust',POSTGRES_IMAGE])
|
||||
try:
|
||||
for _ in range(100):
|
||||
ready=subprocess.run(['docker','exec',pg_name,'pg_isready','-h','127.0.0.1','-U','postgres'],capture_output=True)
|
||||
if ready.returncode == 0: break
|
||||
time.sleep(.2)
|
||||
else: raise RuntimeError('Isolated PostgreSQL did not become ready')
|
||||
sql='CREATE ROLE rmm_app LOGIN NOINHERIT NOSUPERUSER NOBYPASSRLS;\n'+''.join(p.read_text()+'\n' for p in sorted((ROOT/'migrations').glob('*.sql')))
|
||||
result=subprocess.run(['docker','exec','-i',pg_name,'psql','-X','-qAt','-v','ON_ERROR_STOP=1','-U','postgres'],input=sql.encode(),capture_output=True)
|
||||
(out/'postgres-migrations.log').write_bytes(result.stdout+result.stderr)
|
||||
if result.returncode: raise RuntimeError('Isolated migrations failed')
|
||||
command('postgres-contracts',['docker','run','--rm','--network','container:'+pg_name,'--read-only','--tmpfs','/tmp:rw,size=512m','-v',str(ROOT)+':/src:ro','-v',str(ROOT/'devstate/script-console-target')+':/target','-e','CARGO_TARGET_DIR=/target','-e','RMM_TEST_REPAIR_ADMIN_URL=postgres://postgres@127.0.0.1/postgres','-e','RMM_TEST_REPAIR_APP_URL=postgres://rmm_app@127.0.0.1/postgres','--entrypoint','cargo',LINUX_IMAGE,'test',*common,'-p','rmm-server','--bin','rmm-server','--','--include-ignored','--test-threads=1'])
|
||||
finally:
|
||||
command('postgres-remove',['docker','rm','-f',pg_name])
|
||||
for feature in ('default', 'system-helper'):
|
||||
cargo('windows-' + feature + '-clippy', WINDOWS_IMAGE, 'clippy', *common,
|
||||
'--target', 'x86_64-pc-windows-gnu', '-p', 'rmm-agent-windows', '--all-targets',
|
||||
*(['--features', 'system-helper'] if feature == 'system-helper' else []), '--', '-D', 'warnings')
|
||||
raw = cargo('linux-unit-link', LINUX_IMAGE, 'test', *common, '--workspace', '--all-targets',
|
||||
'--target', 'x86_64-unknown-linux-gnu', '--release', '--no-run', '--message-format=json')
|
||||
selected = {'rmm_domain': 'domain-tests', 'rmm_agent_linux': 'linux-runtime-tests',
|
||||
'rmm-privileged-helper': 'helper-policy-tests', 'rmm-server': 'server-contract-tests'}
|
||||
artifacts = {}
|
||||
for line in raw.splitlines():
|
||||
try:
|
||||
value = json.loads(line)
|
||||
except ValueError:
|
||||
continue
|
||||
target = value.get('target', {})
|
||||
name = target.get('name')
|
||||
if (value.get('reason') == 'compiler-artifact' and value.get('executable')
|
||||
and value.get('profile', {}).get('test') and name in selected
|
||||
and target.get('kind') in (['lib'], ['bin'])):
|
||||
label = selected[name]
|
||||
if label in artifacts:
|
||||
raise RuntimeError('Duplicate selected test artifact: ' + label)
|
||||
source = ROOT / 'devstate/script-console-target' / Path(value['executable']).relative_to('/target')
|
||||
artifact = out / label
|
||||
shutil.copyfile(source, artifact)
|
||||
artifacts[label] = {'sha256': sha(artifact), 'bytes': artifact.stat().st_size,
|
||||
'native_linux_executed': False, 'native_windows_executed': False}
|
||||
if set(artifacts) != set(selected.values()):
|
||||
raise RuntimeError('Incomplete Linux unit artifact set')
|
||||
for label in artifacts:
|
||||
command(label + '-list', ['docker', 'run', '--rm', '--network', 'none', '--read-only',
|
||||
'--tmpfs', '/tmp:rw,exec,size=128m', '-v', str(out / label) + ':/unit:ro',
|
||||
'--entrypoint', 'python3', LINUX_IMAGE, '-c',
|
||||
'import shutil,os,subprocess;shutil.copyfile("/unit","/tmp/unit");os.chmod("/tmp/unit",0o500);subprocess.run(["/tmp/unit","--list","--format","terse"],check=True,cwd="/tmp")'])
|
||||
cargo('linux-binary-link', LINUX_IMAGE, 'build', *common, '--release',
|
||||
'--target', 'x86_64-unknown-linux-gnu', '-p', 'rmm-agent', '-p', 'rmm-privileged-helper', '-p', 'rmm-server', '--bins')
|
||||
for name in ('rmm-agent', 'rmm-privileged-helper', 'rmm-server'):
|
||||
artifact = out / name
|
||||
shutil.copyfile(ROOT / 'devstate/script-console-target/x86_64-unknown-linux-gnu/release' / name, artifact)
|
||||
artifacts[name] = {'sha256': sha(artifact), 'bytes': artifact.stat().st_size,
|
||||
'installed': False, 'native_executed': False}
|
||||
if inputs() != frozen:
|
||||
raise RuntimeError('Compiler/deployment inputs changed during qualification; no deployable manifest')
|
||||
archive = out / 'reviewed-sources.tar.gz'
|
||||
with tarfile.open(archive, 'w:gz') as tar:
|
||||
for name in frozen:
|
||||
tar.add(ROOT / name, arcname=name, recursive=False)
|
||||
manifest = {'schema_version': 1, 'type': 'rmm.script-console.local-source-qualification',
|
||||
'created_at': dt.datetime.now(dt.timezone.utc).isoformat(), 'profile': 'full_maintenance_v1',
|
||||
'images': {'linux': LINUX_IMAGE, 'windows_cross': WINDOWS_IMAGE, 'isolated_postgres': POSTGRES_IMAGE}, 'source_files': frozen,
|
||||
'source_before_after_equal': True, 'checks': checks, 'artifacts': artifacts,
|
||||
'source_archive_sha256': sha(archive), 'native_linux_executed': False,
|
||||
'native_windows_executed': False, 'target_state_writes': False, 'rmm_jobs': False,
|
||||
'capabilities_activated': False, 'approvals': False}
|
||||
path = out / 'manifest.json'
|
||||
path.write_text(json.dumps(manifest, indent=2) + '\n')
|
||||
print(json.dumps({'manifest': str(path), 'sha256': sha(path), 'native_executed': False}))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user