Spaces:
Running

fsanyoto commited on
Commit
28e7910
·
verified ·
1 Parent(s): 3df8d29

Deploy AIOS web (React glide grid + FastAPI slice)

Browse files
RELEASES.json CHANGED
@@ -1,4 +1,4 @@
1
  {
2
- "current": "0760473a8c",
3
  "releases": []
4
  }
 
1
  {
2
+ "current": "0ac94038d8",
3
  "releases": []
4
  }
VERSION CHANGED
@@ -1 +1 @@
1
- 0760473a8c
 
1
+ 0ac94038d8
api/routes_admin.py CHANGED
@@ -35,6 +35,7 @@ from copy import deepcopy
35
 
36
  from fastapi import APIRouter, Body, Depends, HTTPException, Query, Response
37
 
 
38
  import core.platform_admin as platform_admin # wave 19 R3 — the /settings chrome flag
39
  import core.registry as registry
40
  import core.schema_overlay as schema_overlay # W46-T36 / C1 - the overlay merge + R12 wall
@@ -517,6 +518,11 @@ def reset_mfa(username: str, session: Session = Depends(admin_gate)):
517
  # the lost phone's sessions died when the store did not persist that change.
518
  raise err(503, "store_unavailable", "the reset did not persist - outstanding sessions were NOT "
519
  "revoked")
 
 
 
 
 
520
  return Response(status_code=204)
521
 
522
 
 
35
 
36
  from fastapi import APIRouter, Body, Depends, HTTPException, Query, Response
37
 
38
+ import core.audit as audit
39
  import core.platform_admin as platform_admin # wave 19 R3 — the /settings chrome flag
40
  import core.registry as registry
41
  import core.schema_overlay as schema_overlay # W46-T36 / C1 - the overlay merge + R12 wall
 
518
  # the lost phone's sessions died when the store did not persist that change.
519
  raise err(503, "store_unavailable", "the reset did not persist - outstanding sessions were NOT "
520
  "revoked")
521
+ try:
522
+ audit.record("auth.mfa_reset", _tenant_of(session.user), session.user["username"],
523
+ {"subject": uname})
524
+ except audit.AuditRefused as exc:
525
+ print(f"[aios-api] {exc}")
526
  return Response(status_code=204)
527
 
528
 
platform/core/audit.py CHANGED
@@ -14,7 +14,7 @@ from core import account_rows, freeze_notice, platform_admin
14
 
15
  AUDIT_KINDS = frozenset({
16
  "auth.login", "auth.login_failed", "auth.lockout", "auth.mfa_enrolled",
17
- "auth.mfa_failed", "auth.logout", "admin.grant", "credential.added",
18
  "credential.rotated", "credential.revoked", "amazon.access", "amazon.sync", "amazon.throttled",
19
  "amazon.authorization_lost", "amazon.deletion_scheduled", "amazon.personal_read", "data.purge", "data.restore",
20
  "config.changed", "customer.personal_read",
 
14
 
15
  AUDIT_KINDS = frozenset({
16
  "auth.login", "auth.login_failed", "auth.lockout", "auth.mfa_enrolled",
17
+ "auth.mfa_failed", "auth.mfa_reset", "auth.logout", "admin.grant", "credential.added",
18
  "credential.rotated", "credential.revoked", "amazon.access", "amazon.sync", "amazon.throttled",
19
  "amazon.authorization_lost", "amazon.deletion_scheduled", "amazon.personal_read", "data.purge", "data.restore",
20
  "config.changed", "customer.personal_read",
web/public/AIOS_DEPLOY_RECEIPT CHANGED
@@ -1 +1 @@
1
- 21ede243d30191f67fdabc0ee2bd7c6f68680fba9346d71c1628977eb842a7a2
 
1
+ b88b37157da3b9d81f9118e611c291411e40db798361f7838fdf75217461809b
web/src/settings/PermsEditor.tsx CHANGED
@@ -61,6 +61,7 @@ import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react
61
  import { TOAST_EVENT, UNAUTHORIZED_EVENT } from "../apiContract";
62
  // ⭐ W37-T05 — the shared in-flight label; see `ui/Busy.tsx` for why it is a component.
63
  import { Busy } from "../ui/Busy";
 
64
  // ⭐ The per-database list is ONE component, shared with `manage-agent` (owner
65
  // item 10: "the same exact layout"). The filter/hide panels are mounted THERE
66
  // now, which is why `filter-kit` is no longer imported here.
@@ -76,6 +77,7 @@ import {
76
  patchUser,
77
  putConnectorGrants,
78
  putUserPerms,
 
79
  setPassword,
80
  } from "./settingsApi";
81
  import type { AdminUser, ConnectorKind } from "./settingsApi";
@@ -100,7 +102,7 @@ type Load =
100
  | { phase: "ready"; payload: PermsPayload };
101
 
102
  /** What the confirm step is asking about. `null` = nothing is being confirmed. */
103
- type Ask = null | { kind: "save" } | { kind: "discard" };
104
 
105
  function showRefusal(text: string) {
106
  window.dispatchEvent(new CustomEvent(TOAST_EVENT, { detail: { text, tone: "error" } }));
@@ -245,11 +247,13 @@ export function PermsEditor({
245
  const [connDraft, setConnDraft] = useState<string[]>([]);
246
  const requestScope = useRef<AbortController | null>(null);
247
  const actionGeneration = useRef(0);
 
248
 
249
  useLayoutEffect(() => {
250
  // Each identity owns an irreversible token, captured before each request.
251
  const scope = new AbortController();
252
  requestScope.current = scope;
 
253
  const invalidate = () => { scope.abort(); setPw(""); };
254
  window.addEventListener(UNAUTHORIZED_EVENT, invalidate);
255
  window.addEventListener("aios:signed-out", invalidate);
@@ -459,6 +463,7 @@ export function PermsEditor({
459
  // ⭐ W47-T19 — the copy dialog was the innermost thing Escape used to arbitrate and it is
460
  // deleted, so the confirm below is the innermost thing left. Nothing else about this
461
  // arbitration changed, and the order of the three survivors is still load-bearing.
 
462
  if (askRef.current) {
463
  e.stopPropagation();
464
  setAsk(null);
@@ -495,11 +500,15 @@ export function PermsEditor({
495
  // nothing appears to happen. One module fits today; the second one does not.
496
  const confirmRef = useRef<HTMLDivElement | null>(null);
497
  useEffect(() => {
498
- if (!ask) return;
 
499
  confirmRef.current?.scrollIntoView({ block: "center" });
500
  // Focus follows the question, so Enter answers it and a screen reader is
501
  // taken to the alert rather than left where the pointer was.
502
  confirmRef.current?.querySelector<HTMLButtonElement>("button")?.focus();
 
 
 
503
  }, [ask]);
504
 
505
  /**
@@ -618,6 +627,29 @@ export function PermsEditor({
618
  [username, onSaved]
619
  );
620
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
621
  /**
622
  * ⭐ W40-T14 — WHO THIS PAGE IS ABOUT, plus whatever just happened, held ONCE. Both returns
623
  * below render it: the account page and the per-database room are the same room with a
@@ -1098,23 +1130,25 @@ export function PermsEditor({
1098
  type="button"
1099
  className="set-secondary"
1100
  disabled={busy || pw.length === 0}
1101
- onClick={() => {
1102
- const request = requestScope.current?.signal;
1103
- if (!request || request.aborted) return;
1104
- const generation = actionGeneration.current;
1105
- void setPassword(username, pw).then((r) => {
1106
- if (request.aborted || generation !== actionGeneration.current) return;
1107
- if (r.ok) {
1108
- setPw("");
1109
- setSaid(`Password reset; ${username} was signed out.`);
1110
- } else {
1111
- showRefusal(r.message);
1112
- }
1113
- });
1114
- }}
1115
  >
1116
  <Busy busy={busy} idle="Reset password" doing="Resetting" />
1117
  </button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1118
  </div>
1119
  {/* Still said plainly BEFORE the click, only now under the control rather than over
1120
  it. Resetting a password bumps the session epoch, which signs the person out of
@@ -1181,7 +1215,18 @@ export function PermsEditor({
1181
  {anyDirty ? <span className="set-help set-perm-dirty">Unsaved changes</span> : null}
1182
  </div>
1183
 
1184
- {ask ? (
 
 
 
 
 
 
 
 
 
 
 
1185
  <div className="set-confirm-wrap">
1186
  <div
1187
  ref={confirmRef}
@@ -1214,17 +1259,8 @@ export function PermsEditor({
1214
  </>
1215
  )}
1216
  <div className="set-actions">
1217
- {/* ⭐ W47-T19 — THREE BRANCH-OWNED BUTTONS RATHER THAN ONE BUTTON WITH THREE
1218
- TERNARIES INSIDE IT. Each branch renders the whole control, so the label, the
1219
- in-flight words and the handler travel together and a reader sees one complete
1220
- button per answer. The save branches read `saveLabel`, so this dialog says
1221
- exactly what the bar behind it said.
1222
- ⛔ AND IT IS WHAT KEEPS `verify_ui.py`'s NC t05-bare ABLE TO FIRE: that control
1223
- strips the `<Busy>` element off the "Save access" spelling and requires the check
1224
- to go red. Fold these back into one `<button>` and the surviving `<Busy>` in the
1225
- other branch hides the stripped one from the check, which then passes over a bare
1226
- label and the negative control silently tests nothing. */}
1227
- {ask.kind !== "save" ? (
1228
  <button
1229
  type="button"
1230
  className="set-primary"
 
61
  import { TOAST_EVENT, UNAUTHORIZED_EVENT } from "../apiContract";
62
  // ⭐ W37-T05 — the shared in-flight label; see `ui/Busy.tsx` for why it is a component.
63
  import { Busy } from "../ui/Busy";
64
+ import { ConfirmDialog } from "../ui/ConfirmDialog";
65
  // ⭐ The per-database list is ONE component, shared with `manage-agent` (owner
66
  // item 10: "the same exact layout"). The filter/hide panels are mounted THERE
67
  // now, which is why `filter-kit` is no longer imported here.
 
77
  patchUser,
78
  putConnectorGrants,
79
  putUserPerms,
80
+ resetMfa,
81
  setPassword,
82
  } from "./settingsApi";
83
  import type { AdminUser, ConnectorKind } from "./settingsApi";
 
102
  | { phase: "ready"; payload: PermsPayload };
103
 
104
  /** What the confirm step is asking about. `null` = nothing is being confirmed. */
105
+ type Ask = null | { kind: "save" } | { kind: "discard" } | { kind: "reset-mfa" };
106
 
107
  function showRefusal(text: string) {
108
  window.dispatchEvent(new CustomEvent(TOAST_EVENT, { detail: { text, tone: "error" } }));
 
247
  const [connDraft, setConnDraft] = useState<string[]>([]);
248
  const requestScope = useRef<AbortController | null>(null);
249
  const actionGeneration = useRef(0);
250
+ const resetInFlight = useRef<AbortSignal | null>(null);
251
 
252
  useLayoutEffect(() => {
253
  // Each identity owns an irreversible token, captured before each request.
254
  const scope = new AbortController();
255
  requestScope.current = scope;
256
+ setAsk(null);
257
  const invalidate = () => { scope.abort(); setPw(""); };
258
  window.addEventListener(UNAUTHORIZED_EVENT, invalidate);
259
  window.addEventListener("aios:signed-out", invalidate);
 
463
  // ⭐ W47-T19 — the copy dialog was the innermost thing Escape used to arbitrate and it is
464
  // deleted, so the confirm below is the innermost thing left. Nothing else about this
465
  // arbitration changed, and the order of the three survivors is still load-bearing.
466
+ if (askRef.current?.kind === "reset-mfa") return;
467
  if (askRef.current) {
468
  e.stopPropagation();
469
  setAsk(null);
 
500
  // nothing appears to happen. One module fits today; the second one does not.
501
  const confirmRef = useRef<HTMLDivElement | null>(null);
502
  useEffect(() => {
503
+ if (!ask || ask.kind === "reset-mfa") return;
504
+ const opener = document.activeElement;
505
  confirmRef.current?.scrollIntoView({ block: "center" });
506
  // Focus follows the question, so Enter answers it and a screen reader is
507
  // taken to the alert rather than left where the pointer was.
508
  confirmRef.current?.querySelector<HTMLButtonElement>("button")?.focus();
509
+ return () => {
510
+ if (opener instanceof HTMLElement && opener.isConnected) opener.focus();
511
+ };
512
  }, [ask]);
513
 
514
  /**
 
627
  [username, onSaved]
628
  );
629
 
630
+ const resetSignIn = async (kind: "password" | "mfa") => {
631
+ const request = requestScope.current?.signal;
632
+ if (!request || request.aborted || busy || resetInFlight.current === request) return;
633
+ const generation = actionGeneration.current;
634
+ resetInFlight.current = request;
635
+ setBusy(true);
636
+ const r = await (kind === "password" ? setPassword(username, pw) : resetMfa(username));
637
+ if (resetInFlight.current === request) resetInFlight.current = null;
638
+ if (request.aborted || generation !== actionGeneration.current) return;
639
+ setBusy(false);
640
+ if (kind === "mfa") setAsk((current) => current?.kind === "reset-mfa" ? null : current);
641
+ if (!r.ok) {
642
+ showRefusal(r.message);
643
+ return;
644
+ }
645
+ if (kind === "password") setPw("");
646
+ const message = kind === "password"
647
+ ? `Password reset; ${username} was signed out.`
648
+ : `${username} was signed out and sets up the authenticator app at next sign in`;
649
+ setSaid(message);
650
+ if (kind === "mfa") onSaved(message);
651
+ };
652
+
653
  /**
654
  * ⭐ W40-T14 — WHO THIS PAGE IS ABOUT, plus whatever just happened, held ONCE. Both returns
655
  * below render it: the account page and the per-database room are the same room with a
 
1130
  type="button"
1131
  className="set-secondary"
1132
  disabled={busy || pw.length === 0}
1133
+ onClick={() => void resetSignIn("password")}
 
 
 
 
 
 
 
 
 
 
 
 
 
1134
  >
1135
  <Busy busy={busy} idle="Reset password" doing="Resetting" />
1136
  </button>
1137
+ <div className="set-field">
1138
+ <span className="set-help">
1139
+ {user.mfaEnrolled
1140
+ ? `Authenticator app set up${user.mfaEnrolledAt ? ` ${new Date(user.mfaEnrolledAt).toLocaleDateString()}` : ""}`
1141
+ : "Authenticator app not set up"}
1142
+ </span>
1143
+ <button
1144
+ type="button"
1145
+ className="set-secondary"
1146
+ disabled={busy}
1147
+ onClick={() => setAsk({ kind: "reset-mfa" })}
1148
+ >
1149
+ <Busy busy={busy} idle="Reset two step sign in" doing="Resetting" />
1150
+ </button>
1151
+ </div>
1152
  </div>
1153
  {/* Still said plainly BEFORE the click, only now under the control rather than over
1154
  it. Resetting a password bumps the session epoch, which signs the person out of
 
1215
  {anyDirty ? <span className="set-help set-perm-dirty">Unsaved changes</span> : null}
1216
  </div>
1217
 
1218
+ <ConfirmDialog
1219
+ open={ask?.kind === "reset-mfa"}
1220
+ title="Reset two step sign in"
1221
+ body={`This signs ${username} out everywhere. They scan a new QR code at their next sign in.`}
1222
+ confirmLabel="Reset two step sign in"
1223
+ cancelLabel="Keep editing"
1224
+ tone="destructive"
1225
+ busy={busy}
1226
+ onConfirm={() => void resetSignIn("mfa")}
1227
+ onCancel={() => setAsk(null)}
1228
+ />
1229
+ {ask && ask.kind !== "reset-mfa" ? (
1230
  <div className="set-confirm-wrap">
1231
  <div
1232
  ref={confirmRef}
 
1259
  </>
1260
  )}
1261
  <div className="set-actions">
1262
+ {/* Save access keeps its own control so the busy-label negative control detects a missing Busy. */}
1263
+ {ask.kind === "discard" ? (
 
 
 
 
 
 
 
 
 
1264
  <button
1265
  type="button"
1266
  className="set-primary"
web/src/settings/SecurityPane.tsx CHANGED
@@ -176,6 +176,7 @@ const EVENT_LABELS: Record<string, string> = {
176
  "auth.lockout": "Account locked",
177
  "auth.mfa_enrolled": "Two-step sign-in set up",
178
  "auth.mfa_failed": "Two-step sign-in failed",
 
179
  "auth.logout": "Signed out",
180
  "admin.grant": "Access changed",
181
  "credential.added": "Credential added",
 
176
  "auth.lockout": "Account locked",
177
  "auth.mfa_enrolled": "Two-step sign-in set up",
178
  "auth.mfa_failed": "Two-step sign-in failed",
179
+ "auth.mfa_reset": "Authenticator app reset",
180
  "auth.logout": "Signed out",
181
  "admin.grant": "Access changed",
182
  "credential.added": "Credential added",
web/src/settings/SettingsModal.tsx CHANGED
@@ -243,7 +243,7 @@ function UsersPane({ user, readOnly }: { user: SessionUser; readOnly: boolean })
243
  const [open, setOpen] = useState<string | null>(null);
244
 
245
  const reload = useCallback(() => {
246
- setUsers(null);
247
  setError("");
248
  setDenied(false);
249
  void listUsers().then((r) => {
 
243
  const [open, setOpen] = useState<string | null>(null);
244
 
245
  const reload = useCallback(() => {
246
+ // Keep the current editor and its success message mounted during roster refresh.
247
  setError("");
248
  setDenied(false);
249
  void listUsers().then((r) => {
web/src/settings/settingsApi.ts CHANGED
@@ -32,6 +32,8 @@ export interface AdminUser {
32
  /** `'all'` or the granted registry keys. ⚠ `[]` READS as unrestricted. */
33
  modules: string[] | "all";
34
  active: boolean;
 
 
35
  epoch?: number;
36
  /**
37
  * ⭢ REQUESTED OF S1, ADDITIVE, NOT YET SERVED (wave 15). One sentence per
@@ -368,6 +370,12 @@ export function setPassword(username: string, password: string): Promise<ApiResu
368
  });
369
  }
370
 
 
 
 
 
 
 
371
  // --- wave 15, C-PERM: the per-module permission record ----------------------
372
  //
373
  // ⛔ ADMIN-ONLY AND FAIL-CLOSED AT THE SERVER. These two calls are exactly as
 
32
  /** `'all'` or the granted registry keys. ⚠ `[]` READS as unrestricted. */
33
  modules: string[] | "all";
34
  active: boolean;
35
+ mfaEnrolled: boolean;
36
+ mfaEnrolledAt: string | null;
37
  epoch?: number;
38
  /**
39
  * ⭢ REQUESTED OF S1, ADDITIVE, NOT YET SERVED (wave 15). One sentence per
 
370
  });
371
  }
372
 
373
+ export function resetMfa(username: string): Promise<ApiResult<void>> {
374
+ return call<void>(`/admin/users/${encodeURIComponent(username)}/mfa/reset`, {
375
+ method: "POST",
376
+ });
377
+ }
378
+
379
  // --- wave 15, C-PERM: the per-module permission record ----------------------
380
  //
381
  // ⛔ ADMIN-ONLY AND FAIL-CLOSED AT THE SERVER. These two calls are exactly as