31 lines
1.3 KiB
Python
31 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Execute the sandbox isolation exercises on the Pimox host."""
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
|
|
|
|
def main():
|
|
directory = Path(__file__).resolve().parent
|
|
helper = (directory / 'network-sandbox-verify-host.py').read_text()
|
|
script = (directory / 'network-sandbox-isolation-host.py').read_text()
|
|
payload = ('import types\nverify = types.ModuleType("sandbox_verify")\n'
|
|
+ 'exec(compile(' + repr(helper) + ', "sandbox_verify", "exec"), verify.__dict__)\n'
|
|
+ script).encode()
|
|
host = os.environ.get('LAB_PIMOX_HOST', '192.168.100.80')
|
|
user = os.environ.get('LAB_PIMOX_USER', 'jv')
|
|
key = os.environ.get('LAB_PIMOX_SSH_KEY_PATH', '/home/jv/.ssh/id_ed25519')
|
|
try:
|
|
return subprocess.run(['ssh', '-T', '-i', key, '-o', 'BatchMode=yes',
|
|
'-o', 'IdentitiesOnly=yes', '-o', 'ConnectTimeout=10',
|
|
'-o', 'StrictHostKeyChecking=accept-new', f'{user}@{host}',
|
|
'sudo -n python3 -'], input=payload, timeout=120).returncode
|
|
except (OSError, subprocess.SubprocessError) as exc:
|
|
print(f'Sandbox isolation exercises failed: {exc}', file=sys.stderr)
|
|
return 1
|
|
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(main())
|