mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-12-05 09:18:53 +00:00
fix(roles): restore the verified pass code the design-only commits stripped
The design commits of Mastodon (8009e0909c), Jenkins (3de420ea18) and Jellyfin (14d6e457e1) left out code their passes had verified, to keep the commits free of credential logic. That was wrong where the code works on its own and nothing replaces it: Mastodon: files/ruby/admin_password.rb and the converge task in tasks/05_administrator.yml set the administrator's password after the tootctl create, passing the value as -e MASTODON_ADMIN_PASSWORD plus the task's environment; the create task drops tootctl's "New password:" line before Ansible registers the output. Without them no native password exists with sso off, and the design spec's sign-in fails there. README.md, TODO.md and the persona note in templates/playwright.env.j2 return to the pass wording. Jenkins: files/playwright/test-design.js again scrambles the local administrator's password, re-applies the CasC configuration and expects the inventory password back, then signs in fresh. Jellyfin: files/playwright/test-login-native-administrator.js again checks that the server refuses a random password and accepts ADMIN_NATIVE_PASSWORD through /Users/AuthenticateByName. Every file equals the state the passes verified (backup snapshot 72-batch29). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
8009e0909c
commit
7ca6537830
7 files changed
+118
-11
No files matched your search
@@ -1,6 +1,10 @@
|
||||
const { randomUUID } = require("node:crypto");
|
||||
const { test, expect } = require("@playwright/test");
|
||||
const { apiFetchOnion } = require("./personas");
|
||||
const { resolveTimeout } = require("./timeouts");
|
||||
|
||||
const CLIENT = 'MediaBrowser Client="playwright", Device="spec", DeviceId="infinito-spec", Version="1.0.0"';
|
||||
|
||||
exports.register = function (shared) {
|
||||
test("administrator: native local login (break-glass) lands on the Jellyfin home", async ({ page }) => {
|
||||
test.setTimeout(resolveTimeout(60_000));
|
||||
@@ -13,4 +17,15 @@ exports.register = function (shared) {
|
||||
|
||||
await shared.logout(page, "administrator-native");
|
||||
});
|
||||
|
||||
test("administrator: the server takes the password of the administrator user and refuses any other", async ({ page }) => {
|
||||
const authenticate = (password) =>
|
||||
apiFetchOnion(page.request, `${shared.env.jellyfinBaseUrl}/Users/AuthenticateByName`, {
|
||||
method: "POST",
|
||||
headers: { "X-Emby-Authorization": CLIENT },
|
||||
data: { Username: shared.env.adminUsername, Pw: password },
|
||||
});
|
||||
expect((await authenticate(randomUUID())).ok(), "a password other than the administrator's must be refused").toBe(false);
|
||||
expect((await authenticate(shared.env.adminNativePassword)).status(), "the password of the administrator user must sign in").toBe(200);
|
||||
});
|
||||
};
|
||||
@@ -18,6 +18,7 @@ const oidcIssuerUrl = normalizeBaseUrl(process.env.OIDC_ISSUER_URL || "");
|
||||
const adminUsername = decodeDotenvQuotedValue(process.env.ADMIN_USERNAME);
|
||||
const adminPassword = decodeDotenvQuotedValue(process.env.ADMIN_PASSWORD);
|
||||
const ssoEnabled = process.env.SSO_SERVICE_ENABLED === "true";
|
||||
const ldapEnabled = process.env.LDAP_SERVICE_ENABLED === "true";
|
||||
const brandingUrl = decodeDotenvQuotedValue(process.env.DESIGN_BRANDING_URL || "");
|
||||
const faviconUrl = decodeDotenvQuotedValue(process.env.DESIGN_FAVICON_URL || "");
|
||||
const iconUrl = decodeDotenvQuotedValue(process.env.DESIGN_ICON_URL || "");
|
||||
@@ -26,6 +27,7 @@ const title = decodeDotenvQuotedValue(process.env.DESIGN_TITLE || "");
|
||||
|
||||
const MODES = ["light", "dark"];
|
||||
const NO_SIGN_IN_PAGE = "with sso on the oic-auth realm sends /login to Keycloak, so Jenkins never renders its own sign-in page";
|
||||
const NO_LOCAL_REALM = "with sso or ldap on, casc.yaml selects the oic or ldap realm and holds no local account";
|
||||
const USERNAME = "#j_username";
|
||||
const PASSWORD = "#j_password";
|
||||
const SUBMIT = "button[name='Submit']";
|
||||
@@ -149,6 +151,23 @@ async function signIn(page) {
|
||||
await expect(page.locator(HEADER)).toBeVisible({ timeout: resolveTimeout(60_000) });
|
||||
}
|
||||
|
||||
/**
|
||||
* Args:
|
||||
* page: signed-in Playwright page on a Jenkins document; the request carries the page's session and crumb.
|
||||
* script: Groovy source for the script console.
|
||||
*/
|
||||
async function runGroovy(page, script) {
|
||||
return page.evaluate(async (source) => {
|
||||
const head = document.head.dataset;
|
||||
const response = await fetch("/scriptText", {
|
||||
method: "POST",
|
||||
headers: { [head.crumbHeader]: head.crumbValue, "Content-Type": "application/x-www-form-urlencoded" },
|
||||
body: new URLSearchParams({ script: source }).toString(),
|
||||
});
|
||||
return { status: response.status, text: (await response.text()).trim() };
|
||||
}, script);
|
||||
}
|
||||
|
||||
function freestyle(command) {
|
||||
return `<?xml version='1.1' encoding='UTF-8'?><project><description>Seeded for the corporate design review.</description><keepDependencies>false</keepDependencies><properties/><scm class="hudson.scm.NullSCM"/><canRoam>true</canRoam><disabled>false</disabled><triggers/><concurrentBuild>false</concurrentBuild><builders><hudson.tasks.Shell><command>${command}</command></hudson.tasks.Shell></builders><publishers/><buildWrappers/></project>`;
|
||||
}
|
||||
@@ -371,6 +390,39 @@ test("design: the header and the sign-in page show the generated logo and the co
|
||||
}
|
||||
});
|
||||
|
||||
test("administrator: CasC sets the inventory password on the existing local account", async ({ page, browser }) => {
|
||||
test.skip(ssoEnabled || ldapEnabled, NO_LOCAL_REALM);
|
||||
await signIn(page);
|
||||
const scramble = await runGroovy(
|
||||
page,
|
||||
[
|
||||
"def details = hudson.security.HudsonPrivateSecurityRealm.Details",
|
||||
`def user = hudson.model.User.getById(${JSON.stringify(adminUsername)}, false)`,
|
||||
"def saved = user.getProperty(details)",
|
||||
"def scrambled = details.fromPlainPassword(UUID.randomUUID().toString())",
|
||||
"user.addProperty(scrambled)",
|
||||
"try {",
|
||||
" io.jenkins.plugins.casc.ConfigurationAsCode.get().configure()",
|
||||
"} finally {",
|
||||
" if (user.getProperty(details).is(scrambled)) {",
|
||||
" user.addProperty(saved)",
|
||||
" print('kept')",
|
||||
" } else {",
|
||||
" print('reapplied')",
|
||||
" }",
|
||||
"}",
|
||||
].join("\n"),
|
||||
);
|
||||
expect(scramble.status, "the script console must accept the administrator").toBe(200);
|
||||
expect(scramble.text, "re-applying casc.yaml must replace a password that differs from the inventory").toBe("reapplied");
|
||||
const context = await browser.newContext({ ignoreHTTPSErrors: true });
|
||||
try {
|
||||
await signIn(await context.newPage());
|
||||
} finally {
|
||||
await context.close();
|
||||
}
|
||||
});
|
||||
|
||||
test("design: gallery of sign-in, dashboard, jobs, builds and administration", async ({ page }) => {
|
||||
skipUnlessServiceEnabled("design");
|
||||
test.skip(!galleryEnabled(), "INFINITO_PLAYWRIGHT_KEEP is not true");
|
||||
|
||||
@@ -128,7 +128,7 @@ docker run --rm -it \
|
||||
|
||||
## Persona contract opt-outs
|
||||
|
||||
[`tasks/05_administrator.yml`](./tasks/05_administrator.yml) creates the account with `tootctl accounts create` and never sets or captures a password, so `ADMIN_PASSWORD` — the Keycloak secret — cannot drive Mastodon's native `/auth/sign_in`; `biber` has no Mastodon account at all, since the OIDC sign-in ([`templates/env.j2`](./templates/env.j2)) is the only path that would create one. In the `services.sso.enabled: false` matrix variants that path is removed, so [`templates/playwright.env.j2`](./templates/playwright.env.j2) renders `PERSONA_BIBER_BLOCKED=true` and `PERSONA_ADMINISTRATOR_BLOCKED=true`. The SeaweedFS companion scenario ([`files/playwright/test-seaweedfs.js`](./files/playwright/test-seaweedfs.js)) drives the same admin journey and skips on the same flag.
|
||||
[`tasks/05_administrator.yml`](./tasks/05_administrator.yml) creates the account with `tootctl accounts create` and converges its password to the platform administrator's, but the shared native login fills `ADMIN_USERNAME` while Mastodon's `/auth/sign_in` only accepts the e-mail, so the administrator persona cannot drive it; `biber` has no Mastodon account at all, since the OIDC sign-in ([`templates/env.j2`](./templates/env.j2)) is the only path that would create one. In the `services.sso.enabled: false` matrix variants that path is removed, so [`templates/playwright.env.j2`](./templates/playwright.env.j2) renders `PERSONA_BIBER_BLOCKED=true` and `PERSONA_ADMINISTRATOR_BLOCKED=true`. The SeaweedFS companion scenario ([`files/playwright/test-seaweedfs.js`](./files/playwright/test-seaweedfs.js)) drives the same admin journey and skips on the same flag.
|
||||
|
||||
## Credits
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
# Todos
|
||||
|
||||
- The image pin `v4.6.2` in `meta/services.yml` (`mastodon` and `streaming`) is stale: upstream released `v4.6.9` on the 4.6 line and `v4.7.3` (2026-10-01). A bump to 4.7 may rename the semantic `--color-*` tokens that `templates/custom.css.j2` maps; the design spec catches that. Options: bump to `v4.6.9` now, or to `v4.7.3` together with a check of the token names in `app/javascript/styles/mastodon/theme/`.
|
||||
- With `sso` off nothing provisions a password Mastodon's own `/auth/sign_in` accepts: `tasks/05_administrator.yml` creates the administrator with `tootctl accounts create`, which generates a password nobody keeps, so the administrator persona stays blocked and the native sign-in of `files/playwright/test-design.js` (e-mail `ADMIN_EMAIL`, password `ADMIN_PASSWORD`) fails in the sso-off variants. The form also takes the e-mail, not the username the shared persona flow types. Options: converge the administrator password in a task after the create (a `rails runner` script that checks `valid_password?` and updates on a mismatch, the value passed as `-e NAME` plus `environment:`), and set `ADMIN_NATIVE_USERNAME` to the administrator's e-mail so the shared flow fills the right field.
|
||||
- `tootctl accounts create` prints the generated password (`New password: …`) to stdout, which the create task in `tasks/05_administrator.yml` registers; its `no_log` follows `MASK_CREDENTIALS_IN_LOGS`, which local deploys disable, so a run with `-v` prints the administrator's working password. Option: drop the `New password:` line in the pipe before Ansible registers the output.
|
||||
- The persona flows stay blocked with `sso` off because the shared native login fills `ADMIN_USERNAME`, while Mastodon's `/auth/sign_in` only accepts the e-mail. Option: teach the shared native login to fill `ADMIN_EMAIL` into an e-mail field and unblock the administrator persona.
|
||||
- `tasks/05_administrator.yml` "Unblock the administrator username" reports changed on every deploy (measured 2026-10-11 in the baseline deploy and four consecutive role syncs; the baseline printed "Unblocked 1 username block(s) for administrator"), so a username block for the administrator is recreated between runs. Options: find what recreates the block and stop it, or make the unblock idempotent by not recreating it.
|
||||
@@ -0,0 +1,13 @@
|
||||
# frozen_string_literal: true
|
||||
# nocheck: mirrored-unit-test - runs in `rails runner` against Mastodon's
|
||||
# live Account and Devise models; nothing here is callable in isolation
|
||||
|
||||
username = ENV.fetch("MASTODON_ADMIN_USERNAME")
|
||||
password = ENV.fetch("MASTODON_ADMIN_PASSWORD")
|
||||
user = Account.find_local!(username).user
|
||||
if user.valid_password?(password)
|
||||
puts "PASSWORD_UNCHANGED"
|
||||
else
|
||||
user.update!(password: password, password_confirmation: password)
|
||||
puts "PASSWORD_CHANGED"
|
||||
end
|
||||
@@ -10,11 +10,14 @@
|
||||
register: mastodon_unblock
|
||||
changed_when: "'Unblocked 0 ' not in mastodon_unblock.stdout"
|
||||
- name: 📁 Create admin account via tootctl
|
||||
ansible.builtin.shell: > # nocheck: container-exec-resolver runtime-resolved CID, delegated to the hosting node
|
||||
container exec -u root {{ MASTODON_LOCAL_CID | quote }} bash -c
|
||||
"bin/tootctl accounts create {{ lookup('users', 'administrator').username }}
|
||||
--email {{ lookup('users', 'administrator').email }}
|
||||
--confirmed --role Owner"
|
||||
ansible.builtin.shell: |
|
||||
set -o pipefail
|
||||
# nocheck: container-exec-resolver runtime-resolved CID, delegated to the hosting node
|
||||
container exec -u root {{ MASTODON_LOCAL_CID | quote }} bash -c \
|
||||
"bin/tootctl accounts create {{ lookup('users', 'administrator').username }} --email {{ lookup('users', 'administrator').email }} --confirmed --role Owner" 2>&1 \
|
||||
| sed -e '/^New password:/d'
|
||||
args:
|
||||
executable: /bin/bash
|
||||
register: tootctl_create
|
||||
changed_when: tootctl_create.rc == 0
|
||||
failed_when: false
|
||||
@@ -22,10 +25,35 @@
|
||||
- name: 🛑 Refuse a tootctl error other than the account already existing
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- tootctl_create.rc == 0 or 'taken' in tootctl_create.stdout | lower or 'taken' in tootctl_create.stderr | lower
|
||||
- tootctl_create.rc == 0 or 'taken' in tootctl_create.stdout | lower
|
||||
fail_msg: >-
|
||||
bin/tootctl accounts create exited {{ tootctl_create.rc }} for the administrator
|
||||
account without reporting the name as taken: {{ tootctl_create.stderr }}
|
||||
account without reporting the name as taken: {{ tootctl_create.stdout }}
|
||||
- name: 🔑 Converge the administrator password of {{ application_id }}
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- container
|
||||
- exec
|
||||
- -i
|
||||
- -e
|
||||
- "MASTODON_ADMIN_USERNAME={{ lookup('users', 'administrator').username }}"
|
||||
- -e
|
||||
- MASTODON_ADMIN_PASSWORD
|
||||
- "{{ MASTODON_LOCAL_CID }}" # nocheck: container-exec-resolver runtime-resolved CID, delegated to the hosting node
|
||||
- bundle
|
||||
- exec
|
||||
- rails
|
||||
- runner
|
||||
- "-"
|
||||
stdin: "{{ lookup('file', 'ruby/admin_password.rb') }}"
|
||||
environment:
|
||||
MASTODON_ADMIN_PASSWORD: "{{ lookup('users', 'administrator').password }}"
|
||||
register: mastodon_admin_password
|
||||
no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
|
||||
changed_when: "'PASSWORD_CHANGED' in mastodon_admin_password.stdout"
|
||||
failed_when: >-
|
||||
mastodon_admin_password.rc != 0
|
||||
or ('PASSWORD_CHANGED' not in mastodon_admin_password.stdout and 'PASSWORD_UNCHANGED' not in mastodon_admin_password.stdout)
|
||||
- name: 👍 Approve the administrator account in Mastodon
|
||||
ansible.builtin.shell: > # nocheck: container-exec-resolver runtime-resolved CID, delegated to the hosting node
|
||||
container exec -u root {{ MASTODON_LOCAL_CID | quote }} bash -c "bin/tootctl accounts modify {{ lookup('users', 'administrator').username }} --approve"
|
||||
|
||||
@@ -32,7 +32,7 @@ MATOMO_BASE_URL={{ lookup('tls', 'web-app-matomo', 'url.base') | dotenv_quote }}
|
||||
|
||||
MATOMO_SERVICE_ENABLED={{ lookup('config', application_id, 'services.matomo.enabled') | string | lower }}
|
||||
|
||||
# nocheck: persona-block-rationale — tasks/05_administrator.yml creates the account with `tootctl accounts create` and never sets or captures a password, so ADMIN_PASSWORD (the Keycloak secret) cannot drive Mastodon's native /auth/sign_in once the sso: false variants remove the OIDC chain (see README "Persona contract opt-outs").
|
||||
# nocheck: persona-block-rationale — the shared persona flow fills ADMIN_USERNAME into the native form, but Mastodon's /auth/sign_in only accepts the e-mail in user[email], so the journey cannot sign in once the sso: false variants remove the OIDC chain; the design spec signs in natively with ADMIN_EMAIL instead.
|
||||
PERSONA_ADMINISTRATOR_BLOCKED={{ 'false' if (lookup('config', application_id, 'services.sso.enabled') | bool) else 'true' }}
|
||||
|
||||
# nocheck: persona-block-rationale — no Mastodon account is provisioned for biber; the OIDC sign-in (templates/env.j2:61-72) is the only path that would create one, and the sso: false variants remove it (see README "Persona contract opt-outs").
|
||||
|
||||
Reference in new issue
Block a user