Connect passive signed release checks to compatible Linux inventory
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { expect, it, vi } from 'vitest';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { CatalogCheckNotice } from './catalog-check';
|
||||
|
||||
it('shows actual check time separately from later inventory cache reading without actions or requests', () => {
|
||||
const fetch = vi.fn(); vi.stubGlobal('fetch', fetch);
|
||||
try {
|
||||
const device = { inventory: JSON.parse(readFileSync(new URL('../../tests/agent_update/catalog-check-inventory.json', import.meta.url),'utf8')) };
|
||||
const html = renderToStaticMarkup(<CatalogCheckNotice device={device}/>);
|
||||
for (const expected of ['2026-11-15T10:00:00Z', '2026-11-15T12:00:00Z', '0.1.8', 'available', 'keine Installation']) expect(html).toContain(expected);
|
||||
expect(html).not.toMatch(/<(button|form|input|script)\b/); expect(fetch).not.toHaveBeenCalled();
|
||||
device.inventory.observations[0]!.data.candidate.version = '<script>approve()</script>';
|
||||
expect(renderToStaticMarkup(<CatalogCheckNotice device={device}/>)).toContain('role="alert"');
|
||||
expect(renderToStaticMarkup(<CatalogCheckNotice device={{inventory:{}}}/>)).toBe('');
|
||||
} finally { vi.unstubAllGlobals(); }
|
||||
});
|
||||
@@ -0,0 +1,28 @@
|
||||
import type { RecordValue } from './api';
|
||||
|
||||
function object(value: unknown): RecordValue | null { return value !== null && typeof value === 'object' && !Array.isArray(value) ? value as RecordValue : null; }
|
||||
const exact = (value: RecordValue, keys: string[]) => Object.keys(value).every(key => keys.includes(key));
|
||||
const date = (value: unknown): value is string => typeof value === 'string' && value.length <= 40 && Number.isFinite(Date.parse(value));
|
||||
const positive = (value: unknown) => Number.isSafeInteger(value) && Number(value) > 0;
|
||||
export function CatalogCheckNotice({ device }: { device: unknown }) {
|
||||
const inventory = object(object(device)?.inventory), entries = inventory?.observations;
|
||||
if (!Array.isArray(entries)) return null;
|
||||
const matches = entries.map(object).filter(entry => entry?.scope === 'linux.agent_update.catalog');
|
||||
if (!matches.length) return null;
|
||||
const invalid = <p role="alert">Gespeicherter Releasekatalogcheck ist ungültig; kein Updatebeleg.</p>;
|
||||
if (matches.length !== 1) return invalid;
|
||||
const entry = matches[0]!, report = object(entry.data);
|
||||
if (!report || entry.source_id !== 'agent:cached-release-catalog-v1' || entry.completeness !== 'complete' || entry.truncated !== false || !date(entry.observed_at)
|
||||
|| !exact(report, ['schema_version', 'source_id', 'checked_at', 'status', 'candidate']) || report.schema_version !== 1 || report.source_id !== 'mtls:release-catalog-v1'
|
||||
|| !date(report.checked_at) || Date.parse(report.checked_at) > Date.parse(entry.observed_at) + 1000) return invalid;
|
||||
const status = report.status, candidate = object(report.candidate), available = status === 'available' || status === 'current';
|
||||
if (!(available || status === 'not_configured' || status === 'unavailable') || entry.quality !== (available ? 'valid' : status === 'not_configured' ? 'unknown' : 'error')) return invalid;
|
||||
if (available ? !candidate || !exact(candidate, ['release_id', 'release_sequence', 'version', 'manifest_sha256', 'keyring_generation'])
|
||||
|| typeof candidate.release_id !== 'string' || !/^[a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}$/.test(candidate.release_id)
|
||||
|| !positive(candidate.release_sequence) || !positive(candidate.keyring_generation) || typeof candidate.version !== 'string' || !/^[A-Za-z0-9.+_-]{1,64}$/.test(candidate.version)
|
||||
|| typeof candidate.manifest_sha256 !== 'string' || !/^[a-f0-9]{64}$/.test(candidate.manifest_sha256) : Object.hasOwn(report, 'candidate')) return invalid;
|
||||
return <aside aria-label="Gespeicherter Releasekatalogcheck"><h4>Passiver Releasekatalogcheck</h4>
|
||||
<p>Status: {String(status)} · geprüft: <time>{report.checked_at}</time></p><p>Cache im Inventar gelesen: <time>{entry.observed_at}</time></p>
|
||||
{candidate && <p>Release: {String(candidate.version)} · Sequenz {String(candidate.release_sequence)}<br/>Manifest SHA-256: <code>{String(candidate.manifest_sha256)}</code></p>}
|
||||
<p>Katalogmetadaten; keine Installation oder Ausführungserlaubnis.</p></aside>;
|
||||
}
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
import { CatalogCheckNotice } from './catalog-check';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import { actions, Action, ApiError, authConfig, approvalBlockers, expectedStdout, objectId, page, Page, PlanInput, pretty, record, RecordValue, request, session, Session, stringField, tenant, tenantPath, validateInput, windowsPowerShellRemoteSignedProfile, fullMaintenanceScriptProfile } from './api';
|
||||
@@ -97,7 +98,7 @@ function Devices({ tenantId, auth, selected, setSelected }: { tenantId: string;
|
||||
return <section><h2>Geräte und gespeichertes Inventar</h2><p>Präsenz, Datenfrische und fachliche Gesundheit sind unabhängig. „unreachable“ bedeutet nicht „ausgeschaltet“.</p><ErrorBox error={list.error}/>
|
||||
{!list.data ? <p>Lade Geräte …</p> : <><PageStatus data={list.data}/><div className="table"><table><thead><tr><th>Fest auswählen</th><th>Gerät / Asset-ID</th><th>Präsenz / Gesundheit</th><th>Quelle / Qualität</th><th>Erhebung / Alter / Empfang</th></tr></thead><tbody>{list.data.items.map(d => { const id = objectId(d, 'asset'); return <tr key={id}><td><input aria-label={`Ziel ${id}`} type="checkbox" checked={selected.includes(id)} onChange={e => setSelected(e.target.checked ? [...selected, id] : selected.filter(v => v !== id))}/></td><td><button className="link" onClick={() => setAsset(id)}>{typeof d.hostname === 'string' ? d.hostname : id}</button><small>{id}</small></td><td>{stringField(d, 'presence')} / {stringField(d, 'health')}<small>Kontakt: {stringField(d, 'last_contact_at')}</small></td><td>{stringField(d, 'source_id')} / {stringField(d, 'quality')}<small>{stringField(d, 'completeness')}</small></td><td>{stringField(d, 'observed_at')}<small>Alter: <Age value={d.observed_at}/> · empfangen: {stringField(d, 'received_at')}</small></td></tr>; })}</tbody></table></div>{!list.data.items.length && <p>Keine sichtbaren Geräte in diesem Listenabschnitt.</p>}<button disabled={!cursor} onClick={() => setCursor(null)}>Erste Seite</button> <button disabled={!list.data.next_cursor} onClick={() => setCursor(list.data?.next_cursor ?? null)}>Nächste Seite</button></>}
|
||||
<p>Fester Auswahlsnapshot ({selected.length}): {selected.join(', ') || 'keine Ziele'}</p>
|
||||
{asset && <article><h3>Inventardetail {asset}</h3><ErrorBox error={detail.error}/>{detail.data && <JsonView value={detail.data} label="Inventar, Capabilities, Metriken, Dienste, Software, Updates, Logs und Quellen (soweit geliefert)"/>}<AdminControl auth={auth} path={tenantPath(tenantId, `/devices/${encodeURIComponent(asset)}/revocation`)} permission="devices:revoke" title="Geräteidentität widerrufen" warning="ACHTUNG: Widerruf unterbricht die Geräteverwaltung und sperrt neue Starts. Kein Entfernen aus einer Liste, kein Rollback. Wiederaufnahme erfordert einen gesonderten sicheren Enrollment-/Recoveryprozess." done={detail.reload}/></article>}
|
||||
{asset && <article><h3>Inventardetail {asset}</h3><ErrorBox error={detail.error}/>{detail.data && <><CatalogCheckNotice device={detail.data}/><JsonView value={detail.data} label="Inventar, Capabilities, Metriken, Dienste, Software, Updates, Logs und Quellen (soweit geliefert)"/></>}<AdminControl auth={auth} path={tenantPath(tenantId, `/devices/${encodeURIComponent(asset)}/revocation`)} permission="devices:revoke" title="Geräteidentität widerrufen" warning="ACHTUNG: Widerruf unterbricht die Geräteverwaltung und sperrt neue Starts. Kein Entfernen aus einer Liste, kein Rollback. Wiederaufnahme erfordert einen gesonderten sicheren Enrollment-/Recoveryprozess." done={detail.reload}/></article>}
|
||||
</section>;
|
||||
}
|
||||
const initialParameters: Record<Action, RecordValue> = {
|
||||
|
||||
Reference in New Issue
Block a user