Keep legacy Windows starter worker pins outside official GNU enrollments
This commit is contained in:
@@ -23,6 +23,11 @@ struct TenantPins { current: Pin, previous: Vec<Previous> }
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub(super) struct UpdaterQuery { platform: Platform, sha256: Option<String> }
|
||||
|
||||
fn official_windows(platform: Platform) -> bool {
|
||||
platform == Platform::WindowsGnuX64
|
||||
&& std::env::var_os("RMM_AGENT_UPDATE_WINDOWS_GNU_OFFICIAL_KEYRING_FILE").is_some()
|
||||
}
|
||||
|
||||
async fn config(s: &crate::State, platform: Platform, tenant: Uuid, wanted: Option<&str>) -> Result<Config, Error> {
|
||||
let slot = match platform {
|
||||
Platform::LinuxX64 => "RMM_AGENT_BOOTSTRAP_LINUX_FILE",
|
||||
@@ -45,8 +50,8 @@ async fn config(s: &crate::State, platform: Platform, tenant: Uuid, wanted: Opti
|
||||
config.updater_bytes = selected.bytes;
|
||||
} else {
|
||||
let mut tx = rmm_persistence::tenant_tx(&s.pool, tenant).await?;
|
||||
let pin = sqlx::query("SELECT sha256,size_bytes FROM customer_starter_workers WHERE platform=$1")
|
||||
.bind(platform_name(platform)).fetch_optional(&mut *tx).await?;
|
||||
let pin = sqlx::query("SELECT sha256,size_bytes FROM customer_starter_workers WHERE platform=$1 AND official_windows=$2")
|
||||
.bind(platform_name(platform)).bind(official_windows(platform)).fetch_optional(&mut *tx).await?;
|
||||
tx.commit().await?;
|
||||
if let Some(pin) = pin {
|
||||
config.updater_sha256 = pin.get("sha256");
|
||||
|
||||
@@ -42,9 +42,7 @@ pub(super) async fn publish_missing(
|
||||
if exists {
|
||||
continue;
|
||||
}
|
||||
let path = if platform == Platform::WindowsGnuX64
|
||||
&& std::env::var_os("RMM_AGENT_UPDATE_WINDOWS_GNU_OFFICIAL_KEYRING_FILE").is_some()
|
||||
{
|
||||
let path = if official_windows(platform) {
|
||||
distribution.join(format!("{name}-official.json"))
|
||||
} else {
|
||||
distribution.join(format!("{name}.json"))
|
||||
@@ -135,11 +133,12 @@ pub(super) async fn publish_missing(
|
||||
.bind(tenant).bind(manifest.release_id).bind(name).bind(i64::try_from(manifest.release_sequence).map_err(|_|invalid())?)
|
||||
.bind(hash(&package.envelope.decode().map_err(|_|invalid())?.payload_bytes)).bind(hash(&raw)).bind(raw)
|
||||
.bind(a.artifact_id).bind(&a.sha256).bind(a.bytes as i64).bind(h.artifact_id).bind(&h.sha256).bind(h.bytes as i64).execute(&mut **tx).await?;
|
||||
sqlx::query("INSERT INTO customer_starter_workers VALUES($1,$2,$3,$4)")
|
||||
sqlx::query("INSERT INTO customer_starter_workers(tenant_id,platform,sha256,size_bytes,official_windows) VALUES($1,$2,$3,$4,$5)")
|
||||
.bind(tenant)
|
||||
.bind(name)
|
||||
.bind(package.worker.sha256)
|
||||
.bind(package.worker.bytes as i64)
|
||||
.bind(official_windows(platform))
|
||||
.execute(&mut **tx)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
-- Older GNU starter rows identify development workers. Keep their historical
|
||||
-- pin out of an official enrollment after a catalog switches signing trust.
|
||||
ALTER TABLE customer_starter_workers
|
||||
ADD COLUMN official_windows boolean NOT NULL DEFAULT false;
|
||||
@@ -29,11 +29,11 @@ def publish(tenant, platform, release, official_windows=False, *, root=Path('/op
|
||||
sql = """SELECT json_build_object('envelope',convert_from(envelope,'UTF8')::json,
|
||||
'agent',agent_sha256,'agent_size',agent_bytes,'helper',helper_sha256,'helper_size',helper_bytes,
|
||||
'starter_worker',(SELECT json_build_object('sha256',sha256,'bytes',size_bytes)
|
||||
FROM customer_starter_workers WHERE tenant_id=:'customer' AND platform=:'platform'))
|
||||
FROM customer_starter_workers WHERE tenant_id=:'customer' AND platform=:'platform' AND official_windows=:'official'::boolean))
|
||||
FROM agent_update_releases WHERE tenant_id=:'customer' AND platform=:'platform' AND release_id=:'release';"""
|
||||
raw = subprocess.check_output(['docker','exec','-i',database_container,
|
||||
'psql','-XqtA','-v','ON_ERROR_STOP=1','-U','postgres','-d','rmm','-v','customer='+tenant,
|
||||
'-v','platform='+platform,'-v','release='+release],input=sql.encode())
|
||||
'-v','platform='+platform,'-v','official='+str(official_windows),'-v','release='+release],input=sql.encode())
|
||||
if not raw.strip():
|
||||
raise ValueError('Selected release is missing from the source customer catalog')
|
||||
row = json.loads(raw)
|
||||
|
||||
Reference in New Issue
Block a user