diff --git a/roles/test-e2e-playwright/files/personas/utils/keycloak.js b/roles/test-e2e-playwright/files/personas/utils/keycloak.js index ff499b5a67..fe834b8c7d 100644 --- a/roles/test-e2e-playwright/files/personas/utils/keycloak.js +++ b/roles/test-e2e-playwright/files/personas/utils/keycloak.js @@ -1,6 +1,10 @@ /** * Keycloak OIDC login helpers. * + * `isAuthChain(url)` + * Whether a URL belongs to the oauth2-proxy / Keycloak redirect + * chain rather than the application itself. + * * `performKeycloakLoginForm(target, username, password)` * Fills the Keycloak login form on `target` (a `Page` OR a * `FrameLocator`) and clicks sign-in. Tolerates both the @@ -178,8 +182,13 @@ async function performKeycloakLoginExpectingDenial(page, username, password, can return finalUrl; } +function isAuthChain(url) { + return /\/oauth2\/|\/realms\/|\/protocol\/openid-connect\//.test(url || ""); +} + module.exports = { OIDC_LOGIN_READY_FLAG, + isAuthChain, performKeycloakLoginForm, performKeycloakLogin, clickOidcLoginLink, diff --git a/roles/test-e2e-playwright/files/personas/utils/s3.js b/roles/test-e2e-playwright/files/personas/utils/s3.js new file mode 100644 index 0000000000..3e0d8bba44 --- /dev/null +++ b/roles/test-e2e-playwright/files/personas/utils/s3.js @@ -0,0 +1,145 @@ +/** + * Minimal path-style S3 client for role specs: SigV4 signing plus + * ListObjectsV2, on node:crypto alone. + * + * Contract: + * sign({method, host, path, region, accessKey, secretKey, query, payload}) + * -> header object to merge into the request + * canonicalQuery(query) + * -> the query string the signature commits to; build the request URL + * from THIS, never from URLSearchParams, which emits "+" for a space + * where SigV4 requires "%20" + * listObjects(request, {baseUrl, bucket, region, accessKey, secretKey}) + * -> Map across every continuation page + * + * The signing algorithm is pinned by + * tests/unit/python/roles/web-svc-seaweedfs/test_sigv4.py, which holds the + * same vectors for the engine-side Python signer. + */ + +const crypto = require("node:crypto"); + +const ALGORITHM = "AWS4-HMAC-SHA256"; +const SERVICE = "s3"; +const SIGNED_HEADERS = "host;x-amz-content-sha256;x-amz-date"; +const PAGE_LIMIT = 1000; +const MAX_PAGES = 64; + +function rfc3986(value) { + return encodeURIComponent(value).replace( + /[!'()*]/g, + (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`, + ); +} + +function canonicalQuery(query) { + const entries = Object.entries(query || {}); + if (entries.length === 0) { + return ""; + } + return entries + .map(([name, value]) => [rfc3986(name), rfc3986(String(value))]) + .sort((a, b) => (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0)) + .map(([name, value]) => `${name}=${value}`) + .join("&"); +} + +function hmac(key, message) { + return crypto.createHmac("sha256", key).update(message, "utf8").digest(); +} + +function sign({ method, host, path, region, accessKey, secretKey, query, payload = "", now }) { + const stamp = (now || new Date()).toISOString().replace(/[-:]|\.\d{3}/g, ""); + const amzDate = `${stamp.slice(0, 15)}Z`; + const dateStamp = amzDate.slice(0, 8); + const payloadHash = crypto.createHash("sha256").update(payload).digest("hex"); + + const canonicalRequest = [ + method, + path, + canonicalQuery(query), + `host:${host}\nx-amz-content-sha256:${payloadHash}\nx-amz-date:${amzDate}\n`, + SIGNED_HEADERS, + payloadHash, + ].join("\n"); + + const scope = `${dateStamp}/${region}/${SERVICE}/aws4_request`; + const toSign = [ + ALGORITHM, + amzDate, + scope, + crypto.createHash("sha256").update(canonicalRequest, "utf8").digest("hex"), + ].join("\n"); + + let key = hmac(`AWS4${secretKey}`, dateStamp); + key = hmac(key, region); + key = hmac(key, SERVICE); + key = hmac(key, "aws4_request"); + const signature = crypto.createHmac("sha256", key).update(toSign, "utf8").digest("hex"); + + return { + "x-amz-content-sha256": payloadHash, + "x-amz-date": amzDate, + Authorization: + `${ALGORITHM} Credential=${accessKey}/${scope}, ` + + `SignedHeaders=${SIGNED_HEADERS}, Signature=${signature}`, + }; +} + +function parseListing(xml) { + const objects = new Map(); + for (const block of xml.split("").slice(1)) { + const key = (block.match(/([\s\S]*?)<\/Key>/) || [])[1]; + if (!key) { + continue; + } + const etag = (block.match(/([\s\S]*?)<\/ETag>/) || [])[1] || ""; + const modified = (block.match(/([\s\S]*?)<\/LastModified>/) || [])[1] || ""; + objects.set(key, `${etag}|${modified}`); + } + const truncated = /\s*true\s*<\/IsTruncated>/i.test(xml); + const token = (xml.match(/([\s\S]*?)<\/NextContinuationToken>/) || [])[1]; + return { objects, next: truncated ? token || "" : "" }; +} + +async function listObjects(request, { baseUrl, bucket, region, accessKey, secretKey }) { + const url = new URL(baseUrl); + const host = url.host; + const path = `/${bucket}`; + const all = new Map(); + let token = ""; + + for (let page = 0; page < MAX_PAGES; page += 1) { + const query = { "list-type": "2", "max-keys": String(PAGE_LIMIT) }; + if (token) { + query["continuation-token"] = token; + } + const headers = sign({ + method: "GET", + host, + path, + region, + accessKey, + secretKey, + query, + }); + const res = await request.get(`${url.origin}${path}?${canonicalQuery(query)}`, { headers }); + if (!res.ok()) { + throw new Error( + `S3 ListObjectsV2 on '${bucket}' answered ${res.status()} — ` + + "the object store rejected the consumer identity or the bucket is absent", + ); + } + const { objects, next } = parseListing(await res.text()); + for (const [key, version] of objects) { + all.set(key, version); + } + if (!next) { + return all; + } + token = next; + } + throw new Error(`S3 ListObjectsV2 on '${bucket}' did not terminate within ${MAX_PAGES} pages`); +} + +module.exports = { canonicalQuery, listObjects, parseListing, sign }; diff --git a/roles/test-e2e-playwright/files/personas/utils/seaweedfs.js b/roles/test-e2e-playwright/files/personas/utils/seaweedfs.js index b5f50a283e..d5b7f0b096 100644 --- a/roles/test-e2e-playwright/files/personas/utils/seaweedfs.js +++ b/roles/test-e2e-playwright/files/personas/utils/seaweedfs.js @@ -7,173 +7,92 @@ * that upload lands as one or more new objects in the consumer's bucket. * `runSeaweedfsStorageCheck` then proves the write reached SeaweedFS: * - * 1. Count the objects already in the consumer's bucket through the - * oauth2-gated Filer UI (administrator session, isolated context). - * 2. Run the app-specific `action(page)` in the test's own browser context - * so the application's user session never collides with the admin one. - * 3. Re-count through the Filer UI and assert the bucket grew — the - * uploaded document is now stored in SeaweedFS for that app. + * 1. List the consumer's bucket over the S3 API, signed with that + * consumer's own identity. + * 2. Run the app-specific `action(page)`. + * 3. Re-list and assert the bucket grew — the uploaded document is now + * stored in SeaweedFS for that app. * - * The Filer UI count is read from the Filer's own JSON listing (the endpoint - * the UI renders), walked recursively so a write into any prefix is seen, - * regardless of how the application namespaces its objects. + * The listing goes to the storage engine directly (roles/web-svc-seaweedfs), + * not to the Filer UI: the Filer moved to roles/web-app-seaweedfs-console, + * which a node may legitimately not deploy. Signing with the consumer's own + * access key rather than the administrator's additionally proves that the + * per-consumer identity in the engine's s3.json reaches its own bucket. * * Inputs come from the consumer's rendered `templates/playwright.env.j2` * (dedicated keys so the check never depends on a role's own login-var - * naming): SEAWEEDFS_FILER_URL, SEAWEEDFS_APP_BUCKET, - * SEAWEEDFS_ADMIN_USERNAME, SEAWEEDFS_ADMIN_PASSWORD. + * naming): SEAWEEDFS_S3_URL, SEAWEEDFS_REGION, SEAWEEDFS_APP_BUCKET, + * SEAWEEDFS_APP_ACCESS_KEY, SEAWEEDFS_APP_SECRET_KEY. */ const { expect } = require("@playwright/test"); const { resolveTimeout } = require("../../timeouts"); -const { performKeycloakLoginForm } = require("./keycloak"); +const { listObjects } = require("./s3"); const { decodeDotenvQuotedValue, normalizeBaseUrl } = require("./dotenv"); -const DIR_MODE_BIT = 0x80000000; -const LISTING_PAGE_LIMIT = 10_000; -const WALK_BUDGET = 4_000; - -function isAuthChain(url) { - return /\/oauth2\/|\/realms\/|\/protocol\/openid-connect\//.test(url || ""); -} - function seaweedfsEnv() { return { - filerUrl: normalizeBaseUrl(process.env.SEAWEEDFS_FILER_URL || ""), + s3Url: normalizeBaseUrl(process.env.SEAWEEDFS_S3_URL || ""), + region: decodeDotenvQuotedValue(process.env.SEAWEEDFS_REGION || ""), bucket: decodeDotenvQuotedValue(process.env.SEAWEEDFS_APP_BUCKET || ""), - adminUsername: decodeDotenvQuotedValue(process.env.SEAWEEDFS_ADMIN_USERNAME || ""), - adminPassword: decodeDotenvQuotedValue(process.env.SEAWEEDFS_ADMIN_PASSWORD || ""), + accessKey: decodeDotenvQuotedValue(process.env.SEAWEEDFS_APP_ACCESS_KEY || ""), + secretKey: decodeDotenvQuotedValue(process.env.SEAWEEDFS_APP_SECRET_KEY || ""), }; } -async function adminLoginFiler(page, env) { - // Authenticate at the Filer root: the oauth2-proxy post-login redirect lands - // on "/", so logging in via a deep path would drop us back at the root. - await page.goto(env.filerUrl, { waitUntil: "domcontentloaded" }); - if (isAuthChain(page.url())) { - await performKeycloakLoginForm(page, env.adminUsername, env.adminPassword); - await page.waitForLoadState("networkidle", { timeout: resolveTimeout(15_000) }).catch(() => {}); - } - expect( - isAuthChain(page.url()), - "administrator must reach the SeaweedFS Filer UI without staying in the auth chain", - ).toBe(false); -} - -async function listDirFiles(page, filerUrl, dirPath, files, budget) { - if (budget.remaining <= 0) { - return; - } - budget.remaining -= 1; - - let lastFileName = ""; - for (;;) { - const sep = dirPath.includes("?") ? "&" : "?"; - const query = `limit=${LISTING_PAGE_LIMIT}${lastFileName ? `&lastFileName=${encodeURIComponent(lastFileName)}` : ""}`; - const res = await page.request.get(`${filerUrl}${dirPath}${sep}${query}`, { - headers: { Accept: "application/json" }, - }); - if (!res.ok()) { - return; - } - const json = await res.json().catch(() => null); - const entries = json && Array.isArray(json.Entries) ? json.Entries : []; - for (const entry of entries) { - const fullPath = entry && entry.FullPath ? String(entry.FullPath) : ""; - if (!fullPath) { - continue; - } - const isDir = (Number(entry.Mode) & DIR_MODE_BIT) !== 0; - if (isDir) { - await listDirFiles(page, filerUrl, `${fullPath}/`, files, budget); - } else { - files.set(fullPath, String(entry.Mtime || entry.Md5 || "")); - } - } - if (!json || !json.ShouldDisplayLoadMore || !json.LastFileName) { - return; - } - lastFileName = String(json.LastFileName); - } -} - -async function collectBucketObjects(adminPage, env) { - const files = new Map(); - await listDirFiles(adminPage, env.filerUrl, `/buckets/${env.bucket}/`, files, { - remaining: WALK_BUDGET, +async function collectBucketObjects(request, env) { + return listObjects(request, { + baseUrl: env.s3Url, + bucket: env.bucket, + region: env.region, + accessKey: env.accessKey, + secretKey: env.secretKey, }); - return files; -} - -async function countBucketObjects(adminPage, env) { - return (await collectBucketObjects(adminPage, env)).size; -} - -async function adminCountBucketObjects(browser, env) { - const context = await browser.newContext({ ignoreHTTPSErrors: true }); - try { - const page = await context.newPage(); - await adminLoginFiler(page, env); - return await countBucketObjects(page, env); - } finally { - await context.close(); - } } async function runSeaweedfsStorageCheck(page, browser, { action, label = "the application upload", overrides = {}, pollDeadlineMs = 60_000, expectInPlaceOverwrite = false } = {}) { const env = { ...seaweedfsEnv(), ...overrides }; - expect(env.filerUrl, "SEAWEEDFS_FILER_URL must be set").toBeTruthy(); + expect(env.s3Url, "SEAWEEDFS_S3_URL must be set").toBeTruthy(); + expect(env.region, "SEAWEEDFS_REGION must be set").toBeTruthy(); expect(env.bucket, "SEAWEEDFS_APP_BUCKET must be set").toBeTruthy(); + expect(env.accessKey, "SEAWEEDFS_APP_ACCESS_KEY must be set").toBeTruthy(); + expect(env.secretKey, "SEAWEEDFS_APP_SECRET_KEY must be set").toBeTruthy(); expect(typeof action, "runSeaweedfsStorageCheck requires an `action(page)` callback").toBe("function"); - // Log the administrator into the Filer once in a dedicated context, then - // reuse that authenticated session for every object count. Re-authenticating - // per count (new context + Keycloak round-trip) is slow enough to blow the - // per-test timeout while polling, so the session is established a single time. - const adminContext = await browser.newContext({ ignoreHTTPSErrors: true }); - try { - const adminPage = await adminContext.newPage(); - await adminLoginFiler(adminPage, env); + const before = await collectBucketObjects(page.request, env); - const before = await collectBucketObjects(adminPage, env); + await action(page); - await action(page); - - // Default: require a NEW object key. This stays immune to background - // workers (PeerTube transcode, Pixelfed media jobs) that rewrite EXISTING - // objects during the poll window. Single-slot consumers that overwrite one - // fixed key in place (e.g. a tenant logo) opt in via expectInPlaceOverwrite - // to also accept a changed mtime on an existing key. - const deadline = Date.now() + pollDeadlineMs; - let after = before; - let newObjects = []; - for (;;) { - after = await collectBucketObjects(adminPage, env); - newObjects = [...after.keys()].filter( - (path) => - !before.has(path) || - (expectInPlaceOverwrite && before.get(path) !== after.get(path)), - ); - if (newObjects.length > 0 || Date.now() >= deadline) { - break; - } - await page.waitForTimeout(resolveTimeout(2_000)); + // Default: require a NEW object key. This stays immune to background + // workers (PeerTube transcode, Pixelfed media jobs) that rewrite EXISTING + // objects during the poll window. Single-slot consumers that overwrite one + // fixed key in place (e.g. a tenant logo) opt in via expectInPlaceOverwrite + // to also accept a changed ETag on an existing key. + const deadline = Date.now() + pollDeadlineMs; + let after = before; + let newObjects = []; + for (;;) { + after = await collectBucketObjects(page.request, env); + newObjects = [...after.keys()].filter( + (key) => + !before.has(key) || + (expectInPlaceOverwrite && before.get(key) !== after.get(key)), + ); + if (newObjects.length > 0 || Date.now() >= deadline) { + break; } - - expect( - newObjects.length, - `${label} must write at least one ${expectInPlaceOverwrite ? "new or changed" : "new"} object to the SeaweedFS bucket '${env.bucket}' ` + - `(objects before: ${before.size}, after: ${after.size}, matched: ${newObjects.length})`, - ).toBeGreaterThan(0); - } finally { - await adminContext.close(); + await page.waitForTimeout(resolveTimeout(2_000)); } + + expect( + newObjects.length, + `${label} must write at least one ${expectInPlaceOverwrite ? "new or changed" : "new"} object to the SeaweedFS bucket '${env.bucket}' ` + + `(objects before: ${before.size}, after: ${after.size}, matched: ${newObjects.length})`, + ).toBeGreaterThan(0); } module.exports = { runSeaweedfsStorageCheck, - adminCountBucketObjects, - adminLoginFiler, + collectBucketObjects, seaweedfsEnv, - isAuthChain, }; diff --git a/roles/web-app-akaunting/templates/playwright.env.j2 b/roles/web-app-akaunting/templates/playwright.env.j2 index 21dbf2a6ba..f34c38e897 100644 --- a/roles/web-app-akaunting/templates/playwright.env.j2 +++ b/roles/web-app-akaunting/templates/playwright.env.j2 @@ -35,13 +35,15 @@ PERSONA_ADMINISTRATOR_BLOCKED=true # nocheck: persona-block-rationale — meta/services.yml `sso.oauth2.allowed_groups` lists only the web-app-akaunting administrator RBAC group, so biber is rejected at the oauth2-proxy; and without OIDC auto-provisioning no Akaunting account exists for biber behind it either (see TODO.md). PERSONA_BIBER_BLOCKED=true -SEAWEEDFS_ADMIN_PASSWORD={{ lookup('users', 'administrator').password | dotenv_quote }} - -SEAWEEDFS_ADMIN_USERNAME={{ lookup('users', 'administrator').username | dotenv_quote }} +SEAWEEDFS_APP_ACCESS_KEY={{ lookup('objstore', application_id, 'access_key') | dotenv_quote }} SEAWEEDFS_APP_BUCKET={{ lookup('objstore', application_id, 'bucket') | dotenv_quote }} -SEAWEEDFS_FILER_URL={{ lookup('canonical_url', 'web-app-seaweedfs', 'filer', consumer=application_id) | dotenv_quote }} +SEAWEEDFS_APP_SECRET_KEY={{ lookup('objstore', application_id, 'secret_key') | dotenv_quote }} + +SEAWEEDFS_REGION={{ lookup('config', 'web-svc-seaweedfs', 'services.seaweedfs.region') }} + +SEAWEEDFS_S3_URL={{ lookup('canonical_url', 'web-svc-seaweedfs', 'api', consumer=application_id) | dotenv_quote }} SEAWEEDFS_SERVICE_ENABLED={{ lookup('config', application_id, 'services.seaweedfs.enabled') | string | lower }} diff --git a/roles/web-app-baserow/templates/playwright.env.j2 b/roles/web-app-baserow/templates/playwright.env.j2 index 3116d31c9c..987b1f35d5 100644 --- a/roles/web-app-baserow/templates/playwright.env.j2 +++ b/roles/web-app-baserow/templates/playwright.env.j2 @@ -33,13 +33,15 @@ PERSONA_ADMINISTRATOR_BLOCKED={{ 'false' if (lookup('config', application_id, 's # nocheck: persona-block-rationale — meta/services.yml `sso.oauth2.allowed_groups` contains only the web-app-baserow administrator RBAC group, so biber is denied at the oauth2-proxy; with SSO off nothing provisions a Baserow account for biber either — tasks/01_manager_ops.yml seeds the superuser and nobody else. PERSONA_BIBER_BLOCKED=true -SEAWEEDFS_ADMIN_PASSWORD={{ lookup('users', 'administrator').password | dotenv_quote }} - -SEAWEEDFS_ADMIN_USERNAME={{ lookup('users', 'administrator').username | dotenv_quote }} +SEAWEEDFS_APP_ACCESS_KEY={{ lookup('objstore', application_id, 'access_key') | dotenv_quote }} SEAWEEDFS_APP_BUCKET={{ lookup('objstore', application_id, 'bucket') | dotenv_quote }} -SEAWEEDFS_FILER_URL={{ lookup('canonical_url', 'web-app-seaweedfs', 'filer', consumer=application_id) | dotenv_quote }} +SEAWEEDFS_APP_SECRET_KEY={{ lookup('objstore', application_id, 'secret_key') | dotenv_quote }} + +SEAWEEDFS_REGION={{ lookup('config', 'web-svc-seaweedfs', 'services.seaweedfs.region') }} + +SEAWEEDFS_S3_URL={{ lookup('canonical_url', 'web-svc-seaweedfs', 'api', consumer=application_id) | dotenv_quote }} SEAWEEDFS_SERVICE_ENABLED={{ lookup('config', application_id, 'services.seaweedfs.enabled') | string | lower }} diff --git a/roles/web-app-bookwyrm/templates/playwright.env.j2 b/roles/web-app-bookwyrm/templates/playwright.env.j2 index 9f9d912721..e0cd72f39b 100644 --- a/roles/web-app-bookwyrm/templates/playwright.env.j2 +++ b/roles/web-app-bookwyrm/templates/playwright.env.j2 @@ -28,13 +28,15 @@ PERSONA_ADMINISTRATOR_BLOCKED=true # nocheck: persona-block-rationale — BookWyrm's logout sits in an icon-only avatar dropdown with no accessible name, so the shared in-app-logout helper cannot match it; the header-bridge login itself works (files/sso/header_auth.py). PERSONA_BIBER_BLOCKED=true -SEAWEEDFS_ADMIN_PASSWORD={{ lookup('users', 'administrator').password | dotenv_quote }} - -SEAWEEDFS_ADMIN_USERNAME={{ lookup('users', 'administrator').username | dotenv_quote }} +SEAWEEDFS_APP_ACCESS_KEY={{ lookup('objstore', application_id, 'access_key') | dotenv_quote }} SEAWEEDFS_APP_BUCKET={{ lookup('objstore', application_id, 'bucket') | dotenv_quote }} -SEAWEEDFS_FILER_URL={{ lookup('canonical_url', 'web-app-seaweedfs', 'filer', consumer=application_id) | dotenv_quote }} +SEAWEEDFS_APP_SECRET_KEY={{ lookup('objstore', application_id, 'secret_key') | dotenv_quote }} + +SEAWEEDFS_REGION={{ lookup('config', 'web-svc-seaweedfs', 'services.seaweedfs.region') }} + +SEAWEEDFS_S3_URL={{ lookup('canonical_url', 'web-svc-seaweedfs', 'api', consumer=application_id) | dotenv_quote }} SEAWEEDFS_SERVICE_ENABLED={{ lookup('config', application_id, 'services.seaweedfs.enabled') | string | lower }} diff --git a/roles/web-app-decidim/templates/playwright.env.j2 b/roles/web-app-decidim/templates/playwright.env.j2 index d5e5402e78..519c11f9da 100644 --- a/roles/web-app-decidim/templates/playwright.env.j2 +++ b/roles/web-app-decidim/templates/playwright.env.j2 @@ -32,13 +32,15 @@ PERSONA_ADMINISTRATOR_BLOCKED=true # nocheck: persona-block-rationale — biber's Keycloak login works (the role's own "biber can log in via OIDC and log out" test proves it), but Decidim's sign-out is a `data-method` link inside the account dropdown that the shared in-app-logout helper cannot drive; files/playwright/playwright.spec.js navigates to `/users/sign_out` directly instead of clicking it. PERSONA_BIBER_BLOCKED=true -SEAWEEDFS_ADMIN_PASSWORD={{ lookup('users', 'administrator').password | dotenv_quote }} - -SEAWEEDFS_ADMIN_USERNAME={{ lookup('users', 'administrator').username | dotenv_quote }} +SEAWEEDFS_APP_ACCESS_KEY={{ lookup('objstore', application_id, 'access_key') | dotenv_quote }} SEAWEEDFS_APP_BUCKET={{ lookup('objstore', application_id, 'bucket') | dotenv_quote }} -SEAWEEDFS_FILER_URL={{ lookup('canonical_url', 'web-app-seaweedfs', 'filer', consumer=application_id) | dotenv_quote }} +SEAWEEDFS_APP_SECRET_KEY={{ lookup('objstore', application_id, 'secret_key') | dotenv_quote }} + +SEAWEEDFS_REGION={{ lookup('config', 'web-svc-seaweedfs', 'services.seaweedfs.region') }} + +SEAWEEDFS_S3_URL={{ lookup('canonical_url', 'web-svc-seaweedfs', 'api', consumer=application_id) | dotenv_quote }} SEAWEEDFS_SERVICE_ENABLED={{ lookup('config', application_id, 'services.seaweedfs.enabled') | string | lower }} diff --git a/roles/web-app-fider/templates/playwright.env.j2 b/roles/web-app-fider/templates/playwright.env.j2 index 13f1ae762e..09c6504932 100644 --- a/roles/web-app-fider/templates/playwright.env.j2 +++ b/roles/web-app-fider/templates/playwright.env.j2 @@ -34,13 +34,15 @@ PERSONA_ADMINISTRATOR_BLOCKED=true # nocheck: persona-block-rationale — see PERSONA_ADMINISTRATOR_BLOCKED above; covered by this role's own "fider: biber sso login as regular user" scenario. PERSONA_BIBER_BLOCKED=true -SEAWEEDFS_ADMIN_PASSWORD={{ lookup('users', 'administrator').password | dotenv_quote }} - -SEAWEEDFS_ADMIN_USERNAME={{ lookup('users', 'administrator').username | dotenv_quote }} +SEAWEEDFS_APP_ACCESS_KEY={{ lookup('objstore', application_id, 'access_key') | dotenv_quote }} SEAWEEDFS_APP_BUCKET={{ lookup('objstore', application_id, 'bucket') | dotenv_quote }} -SEAWEEDFS_FILER_URL={{ lookup('canonical_url', 'web-app-seaweedfs', 'filer', consumer=application_id) | dotenv_quote }} +SEAWEEDFS_APP_SECRET_KEY={{ lookup('objstore', application_id, 'secret_key') | dotenv_quote }} + +SEAWEEDFS_REGION={{ lookup('config', 'web-svc-seaweedfs', 'services.seaweedfs.region') }} + +SEAWEEDFS_S3_URL={{ lookup('canonical_url', 'web-svc-seaweedfs', 'api', consumer=application_id) | dotenv_quote }} SEAWEEDFS_SERVICE_ENABLED={{ lookup('config', application_id, 'services.seaweedfs.enabled') | string | lower }} diff --git a/roles/web-app-mastodon/templates/playwright.env.j2 b/roles/web-app-mastodon/templates/playwright.env.j2 index 652d18ee1e..1385ef9351 100644 --- a/roles/web-app-mastodon/templates/playwright.env.j2 +++ b/roles/web-app-mastodon/templates/playwright.env.j2 @@ -37,13 +37,15 @@ POSTGRES_SERVICE_ENABLED={{ lookup('config', application_id, 'services.postgres. # nocheck: playwright-service-gate — Sidekiq queue and session store behind every authenticated scenario; it has no browser-visible surface of its own REDIS_SERVICE_ENABLED={{ lookup('config', application_id, 'services.redis.enabled') | string | lower }} -SEAWEEDFS_ADMIN_PASSWORD={{ lookup('users', 'administrator').password | dotenv_quote }} - -SEAWEEDFS_ADMIN_USERNAME={{ lookup('users', 'administrator').username | dotenv_quote }} +SEAWEEDFS_APP_ACCESS_KEY={{ lookup('objstore', application_id, 'access_key') | dotenv_quote }} SEAWEEDFS_APP_BUCKET={{ lookup('objstore', application_id, 'bucket') | dotenv_quote }} -SEAWEEDFS_FILER_URL={{ lookup('canonical_url', 'web-app-seaweedfs', 'filer', consumer=application_id) | dotenv_quote }} +SEAWEEDFS_APP_SECRET_KEY={{ lookup('objstore', application_id, 'secret_key') | dotenv_quote }} + +SEAWEEDFS_REGION={{ lookup('config', 'web-svc-seaweedfs', 'services.seaweedfs.region') }} + +SEAWEEDFS_S3_URL={{ lookup('canonical_url', 'web-svc-seaweedfs', 'api', consumer=application_id) | dotenv_quote }} SEAWEEDFS_SERVICE_ENABLED={{ lookup('config', application_id, 'services.seaweedfs.enabled') | string | lower }} diff --git a/roles/web-app-matrix/templates/playwright.env.j2 b/roles/web-app-matrix/templates/playwright.env.j2 index 5438b6172c..0529e2984f 100644 --- a/roles/web-app-matrix/templates/playwright.env.j2 +++ b/roles/web-app-matrix/templates/playwright.env.j2 @@ -46,18 +46,18 @@ MATRIX_SERVER_NAME={{ MATRIX_SERVER_NAME | dotenv_quote }} OIDC_ISSUER_URL={{ OIDC.CLIENT.ISSUER_URL | dotenv_quote }} -SEAWEEDFS_ADMIN_PASSWORD={{ MATRIX_ADMINISTRATOR_PASSWORD | dotenv_quote }} - -SEAWEEDFS_ADMIN_USERNAME={{ MATRIX_ADMINISTRATOR_USERNAME | dotenv_quote }} +SEAWEEDFS_APP_ACCESS_KEY={{ lookup('objstore', application_id, 'access_key') | dotenv_quote }} SEAWEEDFS_APP_BUCKET={{ lookup('objstore', application_id, 'bucket') | dotenv_quote }} -SEAWEEDFS_FILER_URL={{ lookup('canonical_url', 'web-app-seaweedfs', 'filer', consumer=application_id) | dotenv_quote }} +SEAWEEDFS_APP_SECRET_KEY={{ lookup('objstore', application_id, 'secret_key') | dotenv_quote }} + +SEAWEEDFS_REGION={{ lookup('config', 'web-svc-seaweedfs', 'services.seaweedfs.region') }} + +SEAWEEDFS_S3_URL={{ lookup('canonical_url', 'web-svc-seaweedfs', 'api', consumer=application_id) | dotenv_quote }} SEAWEEDFS_SERVICE_ENABLED={{ lookup('config', application_id, 'services.seaweedfs.enabled') | string | lower }} -SEAWEEDFS_FRONTEND_SERVICE_ENABLED={{ lookup('config', 'web-app-seaweedfs', 'services.frontend.enabled', false) | string | lower }} - SSO_SERVICE_ENABLED={{ lookup('config', application_id, 'services.sso.enabled') | string | lower }} {% for bridge in MATRIX_BRIDGES | default([], true) %} diff --git a/roles/web-app-mattermost/templates/playwright.env.j2 b/roles/web-app-mattermost/templates/playwright.env.j2 index 4f807ed924..4114d0ad43 100644 --- a/roles/web-app-mattermost/templates/playwright.env.j2 +++ b/roles/web-app-mattermost/templates/playwright.env.j2 @@ -42,13 +42,15 @@ PERSONA_ADMINISTRATOR_BLOCKED=true # nocheck: persona-block-rationale — see PERSONA_ADMINISTRATOR_BLOCKED above. PERSONA_BIBER_BLOCKED=true -SEAWEEDFS_ADMIN_PASSWORD={{ lookup('users', 'administrator').password | dotenv_quote }} - -SEAWEEDFS_ADMIN_USERNAME={{ lookup('users', 'administrator').username | dotenv_quote }} +SEAWEEDFS_APP_ACCESS_KEY={{ lookup('objstore', application_id, 'access_key') | dotenv_quote }} SEAWEEDFS_APP_BUCKET={{ lookup('objstore', application_id, 'bucket') | dotenv_quote }} -SEAWEEDFS_FILER_URL={{ lookup('canonical_url', 'web-app-seaweedfs', 'filer', consumer=application_id) | dotenv_quote }} +SEAWEEDFS_APP_SECRET_KEY={{ lookup('objstore', application_id, 'secret_key') | dotenv_quote }} + +SEAWEEDFS_REGION={{ lookup('config', 'web-svc-seaweedfs', 'services.seaweedfs.region') }} + +SEAWEEDFS_S3_URL={{ lookup('canonical_url', 'web-svc-seaweedfs', 'api', consumer=application_id) | dotenv_quote }} SEAWEEDFS_SERVICE_ENABLED={{ lookup('config', application_id, 'services.seaweedfs.enabled') | string | lower }} diff --git a/roles/web-app-nextcloud/templates/playwright.env.j2 b/roles/web-app-nextcloud/templates/playwright.env.j2 index 5b6893c67c..082f982584 100644 --- a/roles/web-app-nextcloud/templates/playwright.env.j2 +++ b/roles/web-app-nextcloud/templates/playwright.env.j2 @@ -65,13 +65,15 @@ PERSONA_ADMINISTRATOR_BLOCKED=true # nocheck: persona-block-rationale — Nextcloud's login surface has three shapes depending on the variant (native / oidc_login / sociallogin, files/playwright/_shared.js:19-23) and the #firstrunwizard modal intercepts pointer events on the user menu the generic logout must click (files/playwright/_shared.js:160-175), so biber's chain is driven by files/playwright/test-login-biber-oidc.js and test-login-biber-ldap.js (see README "Persona contract opt-outs"). PERSONA_BIBER_BLOCKED=true -SEAWEEDFS_ADMIN_PASSWORD={{ lookup('users', 'administrator').password | dotenv_quote }} - -SEAWEEDFS_ADMIN_USERNAME={{ lookup('users', 'administrator').username | dotenv_quote }} +SEAWEEDFS_APP_ACCESS_KEY={{ lookup('objstore', application_id, 'access_key') | dotenv_quote }} SEAWEEDFS_APP_BUCKET={{ lookup('objstore', application_id, 'bucket') | dotenv_quote }} -SEAWEEDFS_FILER_URL={{ lookup('canonical_url', 'web-app-seaweedfs', 'filer', consumer=application_id) | dotenv_quote }} +SEAWEEDFS_APP_SECRET_KEY={{ lookup('objstore', application_id, 'secret_key') | dotenv_quote }} + +SEAWEEDFS_REGION={{ lookup('config', 'web-svc-seaweedfs', 'services.seaweedfs.region') }} + +SEAWEEDFS_S3_URL={{ lookup('canonical_url', 'web-svc-seaweedfs', 'api', consumer=application_id) | dotenv_quote }} SEAWEEDFS_SERVICE_ENABLED={{ lookup('config', application_id, 'services.seaweedfs.enabled') | string | lower }} diff --git a/roles/web-app-openwebui/templates/playwright.env.j2 b/roles/web-app-openwebui/templates/playwright.env.j2 index c89ebb65ce..93f8aefdbc 100644 --- a/roles/web-app-openwebui/templates/playwright.env.j2 +++ b/roles/web-app-openwebui/templates/playwright.env.j2 @@ -64,13 +64,15 @@ OIDC_ISSUER_URL={{ OIDC.CLIENT.ISSUER_URL | dotenv_quote }} OPENWEBUI_BASE_URL={{ lookup('tls', application_id, 'url.base') | dotenv_quote }} -SEAWEEDFS_ADMIN_PASSWORD={{ lookup('users', 'administrator').password | dotenv_quote }} - -SEAWEEDFS_ADMIN_USERNAME={{ lookup('users', 'administrator').username | dotenv_quote }} +SEAWEEDFS_APP_ACCESS_KEY={{ lookup('objstore', application_id, 'access_key') | dotenv_quote }} SEAWEEDFS_APP_BUCKET={{ lookup('objstore', application_id, 'bucket') | dotenv_quote }} -SEAWEEDFS_FILER_URL={{ lookup('canonical_url', 'web-app-seaweedfs', 'filer', consumer=application_id) | dotenv_quote }} +SEAWEEDFS_APP_SECRET_KEY={{ lookup('objstore', application_id, 'secret_key') | dotenv_quote }} + +SEAWEEDFS_REGION={{ lookup('config', 'web-svc-seaweedfs', 'services.seaweedfs.region') }} + +SEAWEEDFS_S3_URL={{ lookup('canonical_url', 'web-svc-seaweedfs', 'api', consumer=application_id) | dotenv_quote }} SEAWEEDFS_SERVICE_ENABLED={{ lookup('config', application_id, 'services.seaweedfs.enabled') | string | lower }} diff --git a/roles/web-app-peertube/templates/playwright.env.j2 b/roles/web-app-peertube/templates/playwright.env.j2 index c32420acf7..40442c9f10 100644 --- a/roles/web-app-peertube/templates/playwright.env.j2 +++ b/roles/web-app-peertube/templates/playwright.env.j2 @@ -27,13 +27,15 @@ OIDC_ISSUER_URL={{ OIDC.CLIENT.ISSUER_URL | dotenv_quote }} PEERTUBE_BASE_URL={{ lookup('tls', application_id, 'url.base') | dotenv_quote }} -SEAWEEDFS_ADMIN_PASSWORD={{ lookup('users', 'administrator').password | dotenv_quote }} - -SEAWEEDFS_ADMIN_USERNAME={{ lookup('users', 'administrator').username | dotenv_quote }} +SEAWEEDFS_APP_ACCESS_KEY={{ lookup('objstore', application_id, 'access_key') | dotenv_quote }} SEAWEEDFS_APP_BUCKET={{ lookup('objstore', application_id, 'bucket') | dotenv_quote }} -SEAWEEDFS_FILER_URL={{ lookup('canonical_url', 'web-app-seaweedfs', 'filer', consumer=application_id) | dotenv_quote }} +SEAWEEDFS_APP_SECRET_KEY={{ lookup('objstore', application_id, 'secret_key') | dotenv_quote }} + +SEAWEEDFS_REGION={{ lookup('config', 'web-svc-seaweedfs', 'services.seaweedfs.region') }} + +SEAWEEDFS_S3_URL={{ lookup('canonical_url', 'web-svc-seaweedfs', 'api', consumer=application_id) | dotenv_quote }} SEAWEEDFS_SERVICE_ENABLED={{ lookup('config', application_id, 'services.seaweedfs.enabled') | string | lower }} diff --git a/roles/web-app-penpot/templates/playwright.env.j2 b/roles/web-app-penpot/templates/playwright.env.j2 index 63726c0376..1c53abe03b 100644 --- a/roles/web-app-penpot/templates/playwright.env.j2 +++ b/roles/web-app-penpot/templates/playwright.env.j2 @@ -20,9 +20,10 @@ PERSONA_ADMINISTRATOR_BLOCKED=true # nocheck: persona-block-rationale — see PERSONA_ADMINISTRATOR_BLOCKED above; biber's auth is covered by files/playwright/test-login-oidc-biber.js and test-login-ldap-biber.js (see README "Testing"). PERSONA_BIBER_BLOCKED=true -SEAWEEDFS_ADMIN_PASSWORD={{ lookup('users', 'administrator').password | dotenv_quote }} -SEAWEEDFS_ADMIN_USERNAME={{ lookup('users', 'administrator').username | dotenv_quote }} +SEAWEEDFS_APP_ACCESS_KEY={{ lookup('objstore', application_id, 'access_key') | dotenv_quote }} SEAWEEDFS_APP_BUCKET={{ lookup('objstore', application_id, 'bucket') | dotenv_quote }} -SEAWEEDFS_FILER_URL={{ lookup('canonical_url', 'web-app-seaweedfs', 'filer', consumer=application_id) | dotenv_quote }} +SEAWEEDFS_APP_SECRET_KEY={{ lookup('objstore', application_id, 'secret_key') | dotenv_quote }} +SEAWEEDFS_REGION={{ lookup('config', 'web-svc-seaweedfs', 'services.seaweedfs.region') }} +SEAWEEDFS_S3_URL={{ lookup('canonical_url', 'web-svc-seaweedfs', 'api', consumer=application_id) | dotenv_quote }} SEAWEEDFS_SERVICE_ENABLED={{ lookup('config', application_id, 'services.seaweedfs.enabled') | string | lower }} SSO_SERVICE_ENABLED={{ lookup('config', application_id, 'services.sso.enabled') | string | lower }} diff --git a/roles/web-app-pixelfed/templates/playwright.env.j2 b/roles/web-app-pixelfed/templates/playwright.env.j2 index df0ab60782..6a3bc63a70 100644 --- a/roles/web-app-pixelfed/templates/playwright.env.j2 +++ b/roles/web-app-pixelfed/templates/playwright.env.j2 @@ -42,13 +42,15 @@ PERSONA_BIBER_BLOCKED=true PIXELFED_BASE_URL={{ lookup('tls', 'web-app-pixelfed', 'url.base') | dotenv_quote }} -SEAWEEDFS_ADMIN_PASSWORD={{ lookup('users', 'administrator').password | dotenv_quote }} - -SEAWEEDFS_ADMIN_USERNAME={{ lookup('users', 'administrator').username | dotenv_quote }} +SEAWEEDFS_APP_ACCESS_KEY={{ lookup('objstore', application_id, 'access_key') | dotenv_quote }} SEAWEEDFS_APP_BUCKET={{ lookup('objstore', application_id, 'bucket') | dotenv_quote }} -SEAWEEDFS_FILER_URL={{ lookup('canonical_url', 'web-app-seaweedfs', 'filer', consumer=application_id) | dotenv_quote }} +SEAWEEDFS_APP_SECRET_KEY={{ lookup('objstore', application_id, 'secret_key') | dotenv_quote }} + +SEAWEEDFS_REGION={{ lookup('config', 'web-svc-seaweedfs', 'services.seaweedfs.region') }} + +SEAWEEDFS_S3_URL={{ lookup('canonical_url', 'web-svc-seaweedfs', 'api', consumer=application_id) | dotenv_quote }} SEAWEEDFS_SERVICE_ENABLED={{ lookup('config', application_id, 'services.seaweedfs.enabled') | string | lower }} diff --git a/roles/web-app-taiga/templates/playwright.env.j2 b/roles/web-app-taiga/templates/playwright.env.j2 index 3eec6c1d79..2bf447cf49 100644 --- a/roles/web-app-taiga/templates/playwright.env.j2 +++ b/roles/web-app-taiga/templates/playwright.env.j2 @@ -38,13 +38,15 @@ PERSONA_ADMINISTRATOR_BLOCKED=true # nocheck: persona-block-rationale — see PERSONA_ADMINISTRATOR_BLOCKED above; Taiga's AngularJS shell additionally exposes logout only through ng-click / tg-nav / ui-sref directives (files/playwright/_shared.js:81-90) that the generic inAppLogout helper cannot activate. PERSONA_BIBER_BLOCKED=true -SEAWEEDFS_ADMIN_PASSWORD={{ lookup('users', 'administrator').password | dotenv_quote }} - -SEAWEEDFS_ADMIN_USERNAME={{ lookup('users', 'administrator').username | dotenv_quote }} +SEAWEEDFS_APP_ACCESS_KEY={{ lookup('objstore', application_id, 'access_key') | dotenv_quote }} SEAWEEDFS_APP_BUCKET={{ lookup('objstore', application_id, 'bucket') | dotenv_quote }} -SEAWEEDFS_FILER_URL={{ lookup('canonical_url', 'web-app-seaweedfs', 'filer', consumer=application_id) | dotenv_quote }} +SEAWEEDFS_APP_SECRET_KEY={{ lookup('objstore', application_id, 'secret_key') | dotenv_quote }} + +SEAWEEDFS_REGION={{ lookup('config', 'web-svc-seaweedfs', 'services.seaweedfs.region') }} + +SEAWEEDFS_S3_URL={{ lookup('canonical_url', 'web-svc-seaweedfs', 'api', consumer=application_id) | dotenv_quote }} SEAWEEDFS_SERVICE_ENABLED={{ lookup('config', application_id, 'services.seaweedfs.enabled') | string | lower }} diff --git a/tests/unit/javascript/roles/test-e2e-playwright/files/s3.test.js b/tests/unit/javascript/roles/test-e2e-playwright/files/s3.test.js new file mode 100644 index 0000000000..e7bf599ea3 --- /dev/null +++ b/tests/unit/javascript/roles/test-e2e-playwright/files/s3.test.js @@ -0,0 +1,159 @@ +const test = require("node:test"); +const assert = require("node:assert/strict"); +const path = require("node:path"); + +const s3 = require( + path.join( + __dirname, + "..", "..", "..", "..", "..", "..", + "roles", "test-e2e-playwright", "files", "personas", "utils", "s3.js", + ), +); + +const ACCESS_KEY = "AKIAIOSFODNN7EXAMPLE"; +const SECRET_KEY = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"; +const REGION = "us-east-1"; +const STAMP = new Date(Date.UTC(2013, 4, 24, 0, 0, 0)); + +const VECTORS = [ + { + method: "GET", + host: "seaweedfs:8333", + path: "/", + query: null, + payload: "", + signature: "741e224559611fe6adfe50315e98fec09bdb9a52da21c86b77ee676d98e00dd1", + }, + { + method: "GET", + host: "seaweedfs:8333", + path: "/matrix", + query: { "list-type": "2", "max-keys": "1" }, + payload: "", + signature: "eee845a1bf4fa9439b3e9a3fe61ab440e0560036caacb71cc871c079fd4ad7b5", + }, + { + method: "PUT", + host: "seaweedfs:8333", + path: "/infinito-engine-check-abc", + query: null, + payload: "", + signature: "53e844ed6b237bdf9329204161e0c80a0f699c4032b4862f5ce4cb52ec737464", + }, + { + method: "DELETE", + host: "127.0.0.1:8085", + path: "/bucket/infinito-engine-check/xyz", + query: null, + payload: "", + signature: "fb4f99e695b2c37135b9b2a92ebcb5436c6deabd9bd6e876cd6b5d4eae00b0b0", + }, + { + method: "GET", + host: "host.example:8333", + path: "/b/k", + query: { a: "1", B: "2", c: "x y" }, + payload: "body", + signature: "6cf8880d3c0baa47750aa5b0736a2b10459546b2f583643689200c01e067e8ec", + }, +]; + +function signatureOf(vector) { + const headers = s3.sign({ + method: vector.method, + host: vector.host, + path: vector.path, + region: REGION, + accessKey: ACCESS_KEY, + secretKey: SECRET_KEY, + query: vector.query, + payload: vector.payload, + now: STAMP, + }); + return headers.Authorization.split("Signature=")[1]; +} + +test("signatures match the reference implementation", () => { + for (const vector of VECTORS) { + assert.equal(signatureOf(vector), vector.signature, `${vector.method} ${vector.path}`); + } +}); + +test("the node signer agrees with the python engine probe", () => { + const fs = require("node:fs"); + const pinned = path.join( + __dirname, + "..", "..", "..", "..", "..", "..", + "tests", "unit", "python", "roles", "web-svc-seaweedfs", "test_sigv4.py", + ); + const python = fs.readFileSync(pinned, "utf8"); + for (const vector of VECTORS) { + assert.ok( + python.includes(vector.signature), + `${vector.signature} must also be pinned in test_sigv4.py so the two signers cannot drift apart`, + ); + } +}); + +test("a changed secret changes the signature", () => { + const headers = s3.sign({ + method: "GET", + host: "seaweedfs:8333", + path: "/", + region: REGION, + accessKey: ACCESS_KEY, + secretKey: `${SECRET_KEY}x`, + payload: "", + now: STAMP, + }); + assert.ok(!headers.Authorization.includes(VECTORS[0].signature)); +}); + +test("a space encodes as %20, not +", () => { + assert.equal(s3.canonicalQuery({ c: "x y" }), "c=x%20y"); +}); + +test("the secret never reaches the returned headers", () => { + const headers = s3.sign({ + method: "GET", + host: "seaweedfs:8333", + path: "/", + region: REGION, + accessKey: ACCESS_KEY, + secretKey: SECRET_KEY, + payload: "", + now: STAMP, + }); + assert.ok(!Object.values(headers).join("").includes(SECRET_KEY)); +}); + +test("a truncated listing reports its continuation token", () => { + const xml = [ + "", + "a/1"e1"2026-01-01T00:00:00Z", + "b/2"e2"2026-01-02T00:00:00Z", + "true", + "tok-42", + "", + ].join(""); + const { objects, next } = s3.parseListing(xml); + assert.deepEqual([...objects.keys()], ["a/1", "b/2"]); + assert.notEqual(objects.get("a/1"), objects.get("b/2")); + assert.equal(next, "tok-42"); +}); + +test("a complete listing reports no continuation", () => { + const xml = + "onlyfalse"; + const { objects, next } = s3.parseListing(xml); + assert.deepEqual([...objects.keys()], ["only"]); + assert.equal(next, ""); +}); + +test("an empty listing yields no objects", () => { + const { objects, next } = s3.parseListing( + "false", + ); + assert.equal(objects.size, 0); + assert.equal(next, ""); +});