|
|
|
@@ -32,7 +32,6 @@ TIMER = 'rmm-discovery-update.timer'
|
|
|
|
|
HELPER = 'rmm-discovery-managed-script-helper.service'
|
|
|
|
|
HELPER_SOCKET = Path('/run/rmm-discovery-script-helper/control.sock')
|
|
|
|
|
OLD_HELPER_CONFIG = Path('/etc/rmm-discovery-managed-scripts')
|
|
|
|
|
PLATFORM = 'x86_64-unknown-linux-gnu'
|
|
|
|
|
MAX_BINARY = 256 * 1024 * 1024
|
|
|
|
|
UNIT_DIR = Path('/etc/systemd/system')
|
|
|
|
|
|
|
|
|
@@ -42,6 +41,13 @@ def require(condition, message):
|
|
|
|
|
raise ValueError(message)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def release_platform():
|
|
|
|
|
machine = platform.machine()
|
|
|
|
|
require(platform.system() == 'Linux' and machine in ('x86_64', 'aarch64'),
|
|
|
|
|
'Linux x86-64 or ARM64 required')
|
|
|
|
|
return machine + '-unknown-linux-gnu'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def origin(value):
|
|
|
|
|
parsed = urlsplit(value)
|
|
|
|
|
require(parsed.scheme == 'https' and parsed.hostname and parsed.username is None
|
|
|
|
@@ -151,7 +157,9 @@ def pair(folder, doc, source, updater):
|
|
|
|
|
manifest = doc['manifest']
|
|
|
|
|
release_id = canonical_id(manifest['release_id'])
|
|
|
|
|
prefix = '/agent/v1/bootstrap/releases' if source else '/agent/v1/releases'
|
|
|
|
|
suffix = '?platform=' + PLATFORM if source else ''
|
|
|
|
|
target = release_platform()
|
|
|
|
|
require(manifest['platform'] == target, 'release architecture differs from this device')
|
|
|
|
|
suffix = '?platform=' + target if source else ''
|
|
|
|
|
save(folder / 'envelope.json', doc['release_envelope'])
|
|
|
|
|
for artifact, role in zip(manifest['artifacts'], ('agent', 'helper'), strict=True):
|
|
|
|
|
require(artifact['role'] == role, 'incorrect artifact role')
|
|
|
|
@@ -481,7 +489,7 @@ def save_token(base, token, gid):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def install(base, token_file, enable_admin_scripts=False):
|
|
|
|
|
require(platform.machine() == 'x86_64', 'Linux x86-64 required')
|
|
|
|
|
target = release_platform()
|
|
|
|
|
base = origin(base)
|
|
|
|
|
if ROOT.exists():
|
|
|
|
|
config = read(ROOT / 'config.json')
|
|
|
|
@@ -491,7 +499,7 @@ def install(base, token_file, enable_admin_scripts=False):
|
|
|
|
|
token = enrollment_token(token_file)
|
|
|
|
|
with tempfile.TemporaryDirectory() as work:
|
|
|
|
|
metadata = Path(work) / 'bootstrap.json'
|
|
|
|
|
remote((base, token), '/agent/v1/bootstrap/current?platform=' + PLATFORM, metadata)
|
|
|
|
|
remote((base, token), '/agent/v1/bootstrap/current?platform=' + target, metadata)
|
|
|
|
|
require(read(metadata)['tenant_id'] == config['tenant'], 'different enrollment tenant')
|
|
|
|
|
save_token(ROOT, token, pwd.getpwnam('rmm-discovery').pw_gid)
|
|
|
|
|
# An operator rerunning the HTTPS installer can update the lifecycle
|
|
|
|
@@ -524,7 +532,7 @@ def install(base, token_file, enable_admin_scripts=False):
|
|
|
|
|
with tempfile.TemporaryDirectory(prefix='.rmm-', dir=ROOT.parent) as work:
|
|
|
|
|
staging = Path(work) / 'installation'
|
|
|
|
|
staging.mkdir()
|
|
|
|
|
remote((base, token), '/agent/v1/bootstrap/current?platform=' + PLATFORM, staging / 'bootstrap.json')
|
|
|
|
|
remote((base, token), '/agent/v1/bootstrap/current?platform=' + target, staging / 'bootstrap.json')
|
|
|
|
|
doc = read(staging / 'bootstrap.json')
|
|
|
|
|
require(doc['schema_version'] == 1, 'unknown bootstrap profile')
|
|
|
|
|
save(staging / 'keyring.json', doc['keyring'])
|
|
|
|
@@ -532,7 +540,7 @@ def install(base, token_file, enable_admin_scripts=False):
|
|
|
|
|
save(staging / 'config.json', {'bootstrap': base, 'gateway': origin(doc['gateway_origin']),
|
|
|
|
|
'tenant': canonical_id(doc['tenant_id'])})
|
|
|
|
|
updater = staging / 'updater'
|
|
|
|
|
remote((base, token), '/agent/v1/bootstrap/updater?platform=' + PLATFORM + '&sha256=' + doc['updater']['sha256'], updater, doc['updater'])
|
|
|
|
|
remote((base, token), '/agent/v1/bootstrap/updater?platform=' + target + '&sha256=' + doc['updater']['sha256'], updater, doc['updater'])
|
|
|
|
|
updater.chmod(0o755)
|
|
|
|
|
releases = staging / 'releases'
|
|
|
|
|
releases.mkdir()
|
|
|
|
@@ -599,6 +607,7 @@ def revert(intent, report_failure=True):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update():
|
|
|
|
|
target = release_platform()
|
|
|
|
|
with (ROOT / 'release.lock').open('rb') as lock:
|
|
|
|
|
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
|
|
|
|
pending = ROOT / 'pending.json'
|
|
|
|
@@ -608,7 +617,7 @@ def update():
|
|
|
|
|
with tempfile.TemporaryDirectory(prefix='.incoming-', dir=ROOT / 'releases') as work:
|
|
|
|
|
staging = Path(work) / 'generation'
|
|
|
|
|
staging.mkdir()
|
|
|
|
|
remote(None, '/agent/v1/releases/current?platform=' + PLATFORM, staging / 'current.json')
|
|
|
|
|
remote(None, '/agent/v1/releases/current?platform=' + target, staging / 'current.json')
|
|
|
|
|
response = read(staging / 'current.json')
|
|
|
|
|
if response['status'] == 'not_configured':
|
|
|
|
|
return
|
|
|
|
|