Organize device inventory by customer and restrict token access to its audience

This commit is contained in:
2026-11-17 21:55:24 +01:00
parent aeb9adc649
commit 0afaca1d64
39 changed files with 1950 additions and 225 deletions
+2
View File
@@ -19,6 +19,8 @@ test('dev/test browser simulation: login → fixed plan → pending → explicit
await expect(page.getByRole('status')).toContainText('SIMULIERT');
await expect(page.getByRole('status')).toContainText('kein menschlicher Produktions-Freigabenachweis');
await page.getByRole('checkbox', { name: `Ziel ${asset}`, exact: true }).check();
await page.getByRole('link', { name: 'Aufträge', exact: true }).click();
await page.getByRole('link', { name: 'Auftrag planen', exact: true }).click();
await page.getByLabel('Exakte UTF-8 Skriptbytes', { exact: false }).fill("printf '%s\\n' 'Hello World'\n");
await page.getByLabel('Erwartete stdout-Ausgabe', { exact: false }).fill('Hello World\n');
await page.getByLabel('Begründung', { exact: true }).fill('Dev/test browser simulation · Hello World');
+1 -1
View File
@@ -17,6 +17,6 @@ test('real TLS login follows announced configuration and restores session withou
if (!config.dev_login_enabled) { await expect(page.locator('input[type="password"]')).toHaveCount(0); return; }
await expect(page.getByText('DEV/TEST · SIMULIERTER TESTPRINCIPAL', { exact: false })).toBeVisible();
await login(page); await page.reload(); await expect(page.getByRole('status')).toContainText('SIMULIERT');
await expect(page.getByRole('heading', { name: 'Mitgliedschaft und Ausführungsstopp' })).toBeVisible();
await expect(page.getByRole('heading', { name: 'Geräte', exact: true })).toBeVisible();
await page.getByRole('button', { name: 'Abmelden', exact: true }).click(); await expect(page.getByRole('button', { name: 'Anmelden', exact: true })).toBeVisible();
});
+5
View File
@@ -7,10 +7,15 @@ test('real dev browser membership/catalog read and administrative controls stay
page.on('request', r => { if (r.method() === 'POST' && !['/auth/dev/login', '/auth/logout'].includes(new URL(r.url()).pathname)) mutations++; });
const catalog = page.waitForResponse(r => new URL(r.url()).pathname.endsWith('/package-recipes'));
await test.step('management:login-banner', async () => { await login(page); await expect(page.getByRole('status')).toContainText('SIMULIERT'); });
await page.getByRole('link', {name:'Verwaltung',exact:true}).click();
await page.getByRole('link', {name:'Paketkataloge',exact:true}).click();
await test.step('management:catalog-response', async () => { expect((await catalog).status()).toBe(200); });
await test.step('management:catalog-heading', async () => { await expect(page.getByRole('heading', { name: 'Unveränderlicher Paketkatalog und Artefakte' })).toBeVisible(); });
await page.getByRole('link', {name:'Rechte & Ausführungsstopp',exact:true}).click();
await test.step('management:membership-heading', async () => { await expect(page.getByRole('heading', { name: 'Mitgliedschaft und Ausführungsstopp' })).toBeVisible(); });
await test.step('management:unknown-stop', async () => { await expect(page.getByText('unknown — kein lesender Stopstatus-Endpunkt angekündigt', { exact: false })).toBeVisible(); });
await page.getByRole('link', {name:'Aufträge',exact:true}).click();
await page.getByRole('link', {name:'Auftrag planen',exact:true}).click();
await test.step('management:action-option', async () => { await expect(page.getByLabel('Aktion', { exact: true }).locator('option[value="apt_native_acceptance"]')).toHaveCount(1); });
await test.step('management:select-native', async () => { await page.getByLabel('Aktion', { exact: true }).selectOption('apt_native_acceptance'); });
await test.step('management:native-hint', async () => { await expect(page.getByText('NUR SIMULIERTE DEV/TEST-NATIVABNAHME.', { exact: false })).toBeVisible(); });
+5 -2
View File
@@ -34,8 +34,10 @@ test('simulated human prepares root request through UI only, without approving',
const session = object(await (await sessionResponse).json());
expect(session.testsimulation).toBe(true); expect(session.principal).toBe(expected.expected_principal);
expect(session.approval_origin).toBe('dev_test_browser_simulation');
await expect(page.getByLabel('Mandant', { exact: true })).toHaveValue(text(expected.tenant_id));
await page.getByRole('combobox', { name: 'Kunde', exact: true }).selectOption(text(expected.tenant_id));
await page.getByRole('checkbox', { name: `Ziel ${text(expected.asset_id)}`, exact: true }).check();
await page.getByRole('link', { name: 'Aufträge', exact: true }).click();
await page.getByRole('link', { name: 'Auftrag planen', exact: true }).click();
await page.getByLabel('Aktion', { exact: true }).selectOption(text(request.action));
if (request.action === 'run_script') {
const variants = params.variants;
@@ -93,8 +95,9 @@ test('one opted-in immutable dev/test action: inspect all fixed bytes → UI cli
expect(session.testsimulation).toBe(true);
expect(session.approval_origin).toBe('dev_test_browser_simulation');
expect(session.principal).toBe(expected.expected_principal);
await expect(page.getByLabel('Mandant', { exact: true })).toHaveValue(text(expected.tenant_id));
await page.getByRole('combobox', { name: 'Kunde', exact: true }).selectOption(text(expected.tenant_id));
const operation = text(expected.operation_id);
await page.getByRole('link', { name: 'Aufträge', exact: true }).click();
await page.getByRole('button', { name: operation, exact: true }).click();
const op = page.locator('section').filter({ has: page.getByRole('heading', { name: `Antrag / Ausführung ${operation}`, exact: true }) });
await expect(op.locator('p.warning')).toContainText('Antrag: pending_approval');
+3 -1
View File
@@ -17,11 +17,13 @@ test('real TLS UI: login, tenant, fixed preview, pending, reload, CSRF denial an
let authorizationRequests = 0;
page.on('request', r => { if (new URL(r.url()).pathname.endsWith('/authorizations')) authorizationRequests++; });
await login(page);
await expect(page.getByLabel('Mandant', { exact: true })).not.toHaveValue('');
await expect(page.getByRole('heading', { name: 'Geräte', exact: true })).toBeVisible();
const cookies = await context.cookies();
const authCookie = cookies.find(c => c.name === '__Host-rmm_session');
expect(authCookie?.httpOnly).toBe(true); expect(authCookie?.secure).toBe(true); expect(authCookie?.sameSite).toBe('Strict');
await page.getByRole('checkbox', { name: `Ziel ${asset}`, exact: true }).check();
await page.getByRole('link', { name: 'Aufträge', exact: true }).click();
await page.getByRole('link', { name: 'Auftrag planen', exact: true }).click();
await page.getByLabel('Exakte UTF-8 Skriptbytes', { exact: false }).fill("printf '%s\\n' 'Hello World'\n");
await page.getByLabel('Erwartete stdout-Ausgabe', { exact: false }).fill('Hello World\n');
await page.getByLabel('Begründung', { exact: true }).fill('Authenticated synthetic local fixture · pending-only browser contract; do not execute');
+1
View File
@@ -8,6 +8,7 @@ test('preserved real VM: pending fixed Hello World → UI click → confirmed re
const operation = process.env.RMM_E2E_OPERATION_ID;
if (!asset || !operation) throw new Error('Fixed VM asset and existing pending operation required');
await login(page);
await page.getByRole('link', { name: 'Aufträge', exact: true }).click();
await page.getByRole('button', { name: operation, exact: true }).click();
const op = page.locator('section').filter({ has: page.getByRole('heading', { name: `Antrag / Ausführung ${operation}`, exact: true }) });
await expect(op.locator('p.warning')).toContainText('Antrag: pending_approval');
+60
View File
@@ -0,0 +1,60 @@
-- Disposable PostgreSQL integration. Browser authentication is exercised separately.
BEGIN;
SELECT set_config('app.tenant_id','11111111-1111-4111-8111-111111111111',true);
INSERT INTO memberships(tenant_id,principal,kind,permissions) VALUES
('11111111-1111-4111-8111-111111111111','local:11112222-3333-4444-aaaa-000000000001','human',
ARRAY['tokens:manage','inventory:read','operations:read','operations:plan']);
SELECT provision_customer_admin('11111111-1111-4111-8111-111111111111','local:11112222-3333-4444-aaaa-000000000001');
SET ROLE rmm_app;
DO $$
DECLARE
a constant uuid:='11111111-1111-4111-8111-111111111111';
b constant uuid:='22222222-2222-4222-8222-222222222222';
c uuid:=gen_random_uuid();
actor text:='local:11112222-3333-4444-aaaa-000000000001';
selected_id uuid:=gen_random_uuid();
both_id uuid:=gen_random_uuid();
all_id uuid:=gen_random_uuid();
selected_member text:='mcp:'||selected_id::text;
all_member text:='mcp:'||all_id::text;
scopes text[]:=ARRAY['inventory:read'];
BEGIN
IF has_function_privilege(current_user,'provision_customer_admin(uuid,text)','EXECUTE')
OR has_table_privilege(current_user,'customer_member_index','SELECT')
OR has_table_privilege(current_user,'customer_admins','INSERT')
OR has_function_privilege(current_user,'mcp_effective_scopes(text,uuid)','EXECUTE') THEN
RAISE EXCEPTION 'application credentials can alter the customer boundary';
END IF;
BEGIN
PERFORM issue_customer_token('simulated-testprincipal-a',gen_random_uuid(),'forbidden',repeat('f',64),scopes,now()+interval '1 day',true,ARRAY[]::uuid[]);
RAISE EXCEPTION 'simulated identity minted a global token';
EXCEPTION WHEN insufficient_privilege THEN NULL; END;
BEGIN
PERFORM manage_customer('simulated-testprincipal-a',gen_random_uuid(),'Forbidden',true);
RAISE EXCEPTION 'simulated identity created a customer';
EXCEPTION WHEN insufficient_privilege THEN NULL; END;
PERFORM issue_customer_token(actor,selected_id,'Only B',repeat('1',64),scopes,now()+interval '1 day',false,ARRAY[b]);
PERFORM issue_customer_token(actor,both_id,'A+B',repeat('2',64),scopes,now()+interval '1 day',false,ARRAY[a,b]);
PERFORM issue_customer_token(actor,all_id,'Global',repeat('3',64),scopes,now()+interval '1 day',true,ARRAY[]::uuid[]);
IF mcp_credential_customers(repeat('1',64))<>ARRAY[b] OR mcp_principal_permission(selected_member,'inventory:read')
OR NOT mcp_principal_permission(all_member,'inventory:read') THEN RAISE EXCEPTION 'unexpected issuing-customer visibility'; END IF;
PERFORM manage_customer(actor,c,'New customer',true);
PERFORM manage_customer(actor,c,'Renamed customer',false);
IF cardinality(mcp_credential_customers(repeat('2',64)))<>2 OR c=ANY(mcp_credential_customers(repeat('2',64)))
OR NOT c=ANY(mcp_credential_customers(repeat('3',64))) THEN RAISE EXCEPTION 'invalid future customer discovery'; END IF;
PERFORM set_config('app.tenant_id',c::text,true);
IF NOT mcp_principal_permission(all_member,'inventory:read') OR mcp_principal_permission(all_member,'operations:plan')
OR mcp_principal_permission(selected_member,'inventory:read') OR current_setting('app.tenant_id')<>c::text
OR (SELECT name FROM tenants) <> 'Renamed customer'
OR NOT EXISTS(SELECT 1 FROM tenant_limits)
OR NOT EXISTS(SELECT 1 FROM script_revisions)
THEN RAISE EXCEPTION 'invalid new customer contents/permissions'; END IF;
PERFORM set_config('app.tenant_id',b::text,true);
IF NOT mcp_principal_permission(selected_member,'inventory:read') THEN RAISE EXCEPTION 'selected customer denied'; END IF;
PERFORM set_config('app.tenant_id',a::text,true);
PERFORM revoke_mcp_token(actor,all_id,gen_random_uuid());
PERFORM set_config('app.tenant_id',c::text,true);
IF cardinality(mcp_credential_customers(repeat('3',64)))<>0 OR cardinality(mcp_current_scopes(all_member))<>0
THEN RAISE EXCEPTION 'revocation failed in foreign customer'; END IF;
END $$;
ROLLBACK;
+3 -1
View File
@@ -39,6 +39,8 @@ def main():
ALTER SCHEMA public OWNER TO rmm_migrator;""")
for path in sorted((ROOT / "migrations").glob("*.sql")):
sql("rmm_migrator", path.read_text())
sql("postgres", (ROOT / "tests/customer_access.sql").read_text())
print("PASS selected, global and future customer grants, role boundaries, revocation and tenant context")
test_command = [
"docker", "run", "--rm", "--network", "container:" + name,
"--read-only", "--tmpfs", "/tmp:rw,size=512m",
@@ -50,7 +52,7 @@ def main():
"--entrypoint", "cargo", "rust-discovery-windows-tls-full:local",
"test", "--locked", "--offline", "-p", "rmm-server",
]
for test_filter in ("local_auth::tests", "mcp_tokens::tests"):
for test_filter in ("local_auth::tests", "mcp_tokens::tests", "devices::tests"):
output = command([*test_command, test_filter, "--", "--include-ignored", "--nocapture"], timeout=300)
print(output.decode())
print("PASS all migrations under NOSUPERUSER/NOBYPASSRLS owner; local MFA and MCP tests in isolated PostgreSQL")