Coach: der Test-Lauf laeuft, und CI kann die Jobs ueberhaupt erreichen
Drei Sachen, die nie gelaufen sind, weil die CI fuer die api noch nicht existierte. canDropPrivileges faellt unter Linux zu, solange der Prozess nicht root ist und kein `coach`-User im Image steht. Ein CI-Runner ist Linux, laeuft als normaler User und hat keinen `coach` — also hat dort jedes enqueue() refused, und acht Tests waeren mit dem neuen api-Job rot geworden. Die Suite pinnt das Urteil jetzt selbst, statt es vom Host zu erben; der Test, dem die Verweigerung selbst gehoert, pinnt die Gegenrichtung und laeuft damit erstmals wirklich (vorher sprang er auf jedem Host raus, auf dem der Drop zufaellig klappte — und rief require() in einem ESM-Modul auf). testRun() griff auf ein `job`, das in seinem Scope nicht existiert: ReferenceError bei jedem Klick auf "Test the Coach", und weil der Wurf vor dem try lag, blieb jedes Mal ein Temp-Verzeichnis liegen. Ohne Nutzer gibt es kein Profil, das zahlt — im Instance-Modus ist das der gebundene Credential, im Profile-Modus niemand. Danach antwortete die Fixture auf den Test-Prompt mit einem ganzen Trainingsplan, weil ohne Payload-Fence auf 'create' geraten wird. Genau dieser fehlende Fence unterscheidet den Rundlauf von einem echten Job. Dazu zwei Kleinigkeiten: /api/coach/disclosure verriet den Provider an Nicht-Angemeldete, und der Poll, der ein Proposal verfallen laesst, lieferte als einziger kein cap-Feld zurueck.
This commit is contained in:
1 parent
7be3978476
commit
de7f25cbe7
5 files changed
+55
-9
No files matched your search
@@ -42,8 +42,18 @@ export function unprivilegedIds() {
|
||||
* So on Linux it fails closed: no drop, no job. Elsewhere (a developer's macOS laptop, where
|
||||
* there is no `coach` user and no container boundary either) it stays permissive, because the
|
||||
* alternative is that the test suite and local development simply stop working.
|
||||
*
|
||||
* "Elsewhere" does not include CI, which is Linux, runs as an ordinary user and has no `coach`
|
||||
* user — so the honest answer there is `false`, and every test that needs to reach the code
|
||||
* behind the drop has to say so explicitly. That is what the seam below is for: the suite sets
|
||||
* the verdict it wants to test against, including the refusal itself, instead of inheriting
|
||||
* whatever the host it happens to run on would have said.
|
||||
*/
|
||||
let forced = null;
|
||||
/** Test-only. Pass a verdict to pin it, or null to go back to asking the host. */
|
||||
export function forcePrivilegeVerdict(v) { forced = v; }
|
||||
export function canDropPrivileges() {
|
||||
if (forced) return forced;
|
||||
if (process.platform !== 'linux') return { ok: true, dropped: false, why: 'not linux — development host' };
|
||||
if (unprivilegedIds()) return { ok: true, dropped: true, why: null };
|
||||
if (process.getuid && process.getuid() !== 0) {
|
||||
|
||||
@@ -32,6 +32,13 @@ if (MODE === 'invalid') { process.stdout.write('I am afraid I cannot do that.\n'
|
||||
const isRepair = /REPAIR REQUEST/i.test(prompt);
|
||||
if (MODE === 'invalid-then-valid' && !isRepair) { process.stdout.write('{"changes": "not an array"}\n'); process.exit(0); }
|
||||
|
||||
// The admin card's "Test the Coach": a prompt with no payload attached, asking for one small
|
||||
// object back. A real provider answers that from the prompt alone, so the fixture does too —
|
||||
// otherwise the single button that proves the runtime works is the one thing the shipped
|
||||
// provider cannot do. Every genuine job embeds its payload in a fence (see buildPrompt), so
|
||||
// the absence of one is what distinguishes the two.
|
||||
if (!/```json/.test(prompt)) out({ coach_contract: 1, ok: true });
|
||||
|
||||
// The payload the server built is embedded in the prompt between fences; pull it back out so
|
||||
// the answer references ids that actually exist.
|
||||
function payload() {
|
||||
|
||||
+8
-2
@@ -90,7 +90,9 @@ export function status(uid) {
|
||||
const rec = readUser(uid);
|
||||
if (rec.pending && rec.pending.expiresAt && rec.pending.expiresAt < Date.now()) {
|
||||
archive(uid, rec, 'expired');
|
||||
return { job: null, pending: null };
|
||||
// Same shape as every other answer: the poll that happens to be the one which expires a
|
||||
// proposal must not be the one where the client's cap readout goes undefined.
|
||||
return { job: null, pending: null, cap: capState(uid) };
|
||||
}
|
||||
return {
|
||||
job: rec.current ? { id: rec.current.id, kind: rec.current.kind, state: rec.current.state, startedAt: rec.current.startedAt } : null,
|
||||
@@ -359,8 +361,12 @@ export async function testRun() {
|
||||
const adapter = adapterFor(cfg.provider);
|
||||
if (!adapter) return { ok: false, error: 'no provider configured' };
|
||||
const jobDir = fs.mkdtempSync(path.join(os.tmpdir(), 'coach-test-'));
|
||||
const env = cfgStore.jobEnv(jobDir, cfgStore.credentialFor(job.uid));
|
||||
try {
|
||||
// No user asked for this, so there is no profile whose account is being spent. In instance
|
||||
// mode that is the bound profile's credential — the one the round-trip is meant to prove —
|
||||
// and in per-profile mode it is nobody's, which is the honest answer: an admin cannot test
|
||||
// a credential that belongs to a profile.
|
||||
const env = cfgStore.jobEnv(jobDir, cfgStore.credentialFor(cfg.boundUid));
|
||||
const ids = unprivilegedIds();
|
||||
if (ids) fs.chownSync(jobDir, ids.uid, ids.gid);
|
||||
const check = await adapter.check(cfg, env);
|
||||
|
||||
+4
-1
@@ -41,8 +41,11 @@ export function coachRoutes({ json, readBody, readSession, requireAdmin }) {
|
||||
/* ------------------------------ user ------------------------------ */
|
||||
|
||||
// What the consent screen has to disclose, straight from the module that builds payloads,
|
||||
// so the screen cannot drift from what actually leaves (FR-09).
|
||||
// so the screen cannot drift from what actually leaves (FR-09). Signed in only: the screen
|
||||
// that reads it sits behind a session anyway, and on an invite-only instance which provider
|
||||
// this box is wired to is nobody's business who has not been let in.
|
||||
'GET /api/coach/disclosure': async (req, res) => {
|
||||
if (!readSession(req)) return json(res, 401, { error: 'not signed in' });
|
||||
const cfg = cfgStore.load();
|
||||
json(res, 200, {
|
||||
provider: cfg.provider,
|
||||
|
||||
Reference in new issue
Block a user