Skip to content

factory: an organization's people sign in with a username and password (E9) - #2646

Merged
santoshkumarradha merged 10 commits into
work/teamsfrom
w2/e9-password
Nov 16, 2026
Merged

santoshkumarradha merged 10 commits into
work/teamsfrom
w2/e9-password

Conversation

@santoshkumarradha

@santoshkumarradha santoshkumarradha commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Do not merge before the independent security review. The binding contract in ~/work/teams-wave/PASSWORD.md ("SECURITY ARCHITECTURE — BINDING") requires that review.

An organization server now takes a username and password by default, with GitHub as the second way in. Two password people can claim, invite, join, share a workstream, read it, sign out, and sign back in, with no GitHub anywhere.

How it meets the binding section

  • Hashing. argon2id (golang.org/x/crypto/argon2) with OWASP params m=47104,t=1,p=1, a 16-byte salt and a 32-byte key, stored as a PHC string.
    • A weaker stored hash is rehashed on the next sign-in.
    • At most 4 hashes run at once; a request waits 3 s for a slot, then gets 429.
    • The PHC decoder bounds every field before allocating anything (fuzzed).
  • Policy. Passwords are NFKC-normalized. Length is 12 characters to 256 bytes, with no truncation.
    • Refused if on the embedded common list: SecLists NCSC 100k, MIT, entries of 12+ characters, 8.7 KB gz, LICENSE alongside.
    • Refused if it contains the username.
    • The refusal sentence names the rule.
  • Enumeration and timing. Unknown, wrong and removed accounts get the same 401 sentence. Unknown names are verified against a dummy hash; a test asserts equal argon2 runs.
  • Throttle. golang.org/x/time/rate keyed by username and by the IP from the existing resolveClient trusted-proxy resolver.
    • Exponential backoff from 30 s up to 15 min, forgiven after 15 min of quiet. Nothing is locked for good.
    • At most 10,000 keys; recovered keys are evicted first.
    • The 429 says "Too many tries. Wait a few minutes."
  • Links.
    • Atomic consumption: an invitation or operator link is used up in the same lockRows critical section that creates the account, with a compensating rollback if the second write fails. A race test sends 8 goroutines at one link and exactly 1 joins.
    • Reset links last 1 h, are single use, operator only, for password people only, and audited. They are stored in accounts.json, so a reset secret can never be a bearer token.
  • Sessions. These reuse the server's access sessions (≥256-bit crypto/rand, stored only as SHA-256, compared in constant time). Idle life is 30 days and absolute life is 90.
    • A password change ends the person's other sessions.
    • A reset ends all of them.
    • Sign-out revokes the session on the server.
  • Transport. Routes are JSON only (no HTML forms), with DisallowUnknownFields, an 8 KiB cap and Cache-Control: no-store. They are refused over plain HTTP unless the request is on loopback or behind a trusted proxy that reports HTTPS. Password routes are kept out of the idempotency replay cache.
  • Audit. Record kind account_changed with verbs: signed up, signed in, refused sign-ins, changed password, made password reset link, reset password.
  • Secrets. The engine registers every password with redact and trace on arrival. Leak tests push a known password through every path, then grep answers, log, record rows and every file under the store (server), plus every wire line and redact (engine).
  • Dependencies. Only golang.org/x/*: crypto and text were already direct; x/time moves from indirect to direct.

Wire

Documented in docs/design/app-v3/PROTOCOL.md and in PASSWORD.md's new "As built" section.

  • New methods: factory.access_sign_up, access_reset, password_sign_in and password_change, behind the hello word factory_password.
  • New fields: sign_in, sign_in_kind, people/member kind, access kind/reason.
  • New link kind: link_create takes kind:"reset".

Behavior changes and open points

  • invite_available is no longer gated on GitHub.
  • A GitHub login equal to a password handle is refused at the device flow.
  • Not applied to password sign-ups: config.Team, the GitHub allowlist. The link is the gate.
  • Unchanged: job visibility is still gated on repo grants. A password person is judged like a GitHub person with no grants, and a test asserts the answers are identical.
  • Out of scope: codeaf runner join still signs in with GitHub only, and there is no TOTP, WebAuthn, email recovery or SSO.

Evidence

  • Serve, tokens, appwire and engine password tests pass, including a 20 s fuzz of the PHC decoder.
  • Manual gates pass.
  • The live run used the real bin/codeaf factory serve on a temporary home: operator claim, a short password refused with password_short, invite, second sign-up, the reused invite answering used_up, workstream returning 404 before the share and readable by both after, both signed out (401), the same sentence for a wrong and an unknown user, a form body answered 415, both signed back in and reading, people kind = password. No password appeared in the server log or any file under the home.
  • --new-operator-link still prints a fresh link.

santoshkumarradha and others added 5 commits November 15, 2026 20:36
…d (E9)

A team server takes a username and password by default, with GitHub as the
second way in. An account is made through the operator link or an
invitation, consuming the link in the same locked write that makes the
account. Passwords are argon2id (OWASP 46 MiB, t=1, p=1) in PHC strings,
NFKC-normalized, 12 characters to 256 bytes, checked against an embedded
common-password list and the username. Sign-in is throttled per username
and per resolved client address with decaying backoff; unknown, wrong and
removed accounts get one sentence and the same hashing cost. Sessions reuse
the server's access sessions: 30 days idle, 90 days absolute, ended by a
password change, a reset or a sign-out. The operator can make a one-hour,
single-use reset link for a password person. Password routes are JSON only,
strictly decoded, 8 KiB, no-store, and refused over plain HTTP except on
loopback or behind a trusted HTTPS proxy. Every account change is audited
and no password reaches a log, record, file or answer.

The engine serves factory.access_sign_up, access_reset, password_sign_in
and password_change behind the hello word factory_password, holding every
session the way access sign-in does.

Assisted-by: CodeAF
Co-Authored-By: CodeAF <[email protected]>
Assisted-by: CodeAF
Co-Authored-By: CodeAF <[email protected]>
H1 A session carries the password generation it was made under; a change
   or a reset moves the generation, and mintSession re-reads it under the
   session lock, so no session made with an old password outlives the change.
H2 A link made for one GitHub login takes no password and offers none.
H3 A try spends its throttle tokens on entry and gets them back only for a
   right password; one sign-in of a username is verified at a time.
M1 Backoff is keyed by (username, address); a looser per-username ceiling
   skips addresses the person signed in from before, so a stranger cannot
   keep the owner out.
M2 A username already named anywhere on the server (a GitHub login that ever
   signed in, a share, a team, an owner, a driver, a job, the record) is taken.
L1 IPv6 counts by /64; a backing-off key is never evicted, a full set refuses.
L2 A transparent rehash compares and swaps on the hash it verified; a change
   compares on the generation.
L3 The common list is NCSC 100k plus xato-net's top million and famous
   passphrases, compared by letters and digits: about 486,000 entries.
L4 A GitHub sign-in checks the name again under joinMu before its session is
   stored, and remembers the handle for good.
L5 accounts.json is cached by mtime and size; a read error refuses the
   request and keeps the session.
L6 Typed passwords are passing secrets: at least 8 bytes, the latest 64 kept.

Assisted-by: CodeAF
Co-Authored-By: CodeAF <[email protected]>
santoshkumarradha and others added 5 commits November 15, 2026 22:22
…second review)

M1: every sign-up, reset, change and sign-in without one hands the machine a
device token (256-bit, kept server-side as SHA-256 in accounts.json, bound to
the person and the password generation, 180 days, 16 per person, revoked by a
change, reset or removal, surviving a restart). A try with a valid token
skips the username's ceiling and counts by the device and its address. The
engine keeps the token beside the session through factory.sessions_take and
factory.session_restore and presents it on later sign-ins. The in-memory
trusted addresses are gone. A new machine during an attack uses the
operator's reset link, which is never throttled.

M-new: the changing session is valid at gen+1 before the write, so concurrent
requests never sign it out. L-a: refunds are hand-counted credit. L-b: a full
set logs once a minute. L-c: punctuation, keyboard runs and few-character
passwords are common. L-d: a hash waits up to 500 ms for a slot.

POST /v1/me/password answers 200 {device_token}.

Assisted-by: CodeAF
Co-Authored-By: CodeAF <[email protected]>
Assisted-by: CodeAF
Co-Authored-By: CodeAF <[email protected]>
/v1/me and the password sign-in answer said github_signed_in true for a
password person. It is now true only for a GitHub sign-in; sign_in_kind
"password" says a password person signed in, and the engine's can_sign_out
reads either.

Assisted-by: CodeAF
Co-Authored-By: CodeAF <[email protected]>
… use is pushed out (re-review #2)

N1: a device token is made only on want_device; the engine asks only while
the app's core says factory.sessions_store {can_keep: true} (unsaid is
false). A device is marked used at every sign-in with it, and a person's
sixteen live devices are never evicted: past that a sign-in succeeds with no
new token, said once in the log. N2: a signed-in password change counts per
session, not against the username's ceiling. N3: a trusted pair is keyed by
device and address, so a stolen token used elsewhere backs off only itself.

Assisted-by: CodeAF
Co-Authored-By: CodeAF <[email protected]>
…y address (re-check 3)

F1: a password change counts in one bucket per session with no address in
the key, so a stolen session spread over 30 addresses gets 10 current
passwords checked, not 300. F2: a device token keeps its (device, address)
pair bucket and also has a ceiling of 100 across every address; past it the
try counts as untrusted, so a stolen token from 30 addresses gets 100 trusted
checks plus the username's ceiling, not 300. F3: the concurrent-guess test
asserts the real bound, the username's ceiling.

Assisted-by: CodeAF
Co-Authored-By: CodeAF <[email protected]>
@santoshkumarradha
santoshkumarradha merged commit d274ba1 into work/teams Nov 16, 2026
1 check passed
@santoshkumarradha
santoshkumarradha deleted the w2/e9-password branch November 16, 2026 04:47
ZeroPoint95 pushed a commit that referenced this pull request Nov 24, 2026
…d (E9) (#2646)

* factory: an organization's people sign in with a username and password (E9)

A team server takes a username and password by default, with GitHub as the
second way in. An account is made through the operator link or an
invitation, consuming the link in the same locked write that makes the
account. Passwords are argon2id (OWASP 46 MiB, t=1, p=1) in PHC strings,
NFKC-normalized, 12 characters to 256 bytes, checked against an embedded
common-password list and the username. Sign-in is throttled per username
and per resolved client address with decaying backoff; unknown, wrong and
removed accounts get one sentence and the same hashing cost. Sessions reuse
the server's access sessions: 30 days idle, 90 days absolute, ended by a
password change, a reset or a sign-out. The operator can make a one-hour,
single-use reset link for a password person. Password routes are JSON only,
strictly decoded, 8 KiB, no-store, and refused over plain HTTP except on
loopback or behind a trusted HTTPS proxy. Every account change is audited
and no password reaches a log, record, file or answer.

The engine serves factory.access_sign_up, access_reset, password_sign_in
and password_change behind the hello word factory_password, holding every
session the way access sign-in does.

Assisted-by: CodeAF
Co-Authored-By: CodeAF <[email protected]>

* changes: name #2646 in its entry

Assisted-by: CodeAF
Co-Authored-By: CodeAF <[email protected]>

* changes: end each claim of #2646's entry in a full stop

Assisted-by: CodeAF
Co-Authored-By: CodeAF <[email protected]>

* engine: read the sign-in cache under a deferred unlock

Assisted-by: CodeAF
Co-Authored-By: CodeAF <[email protected]>

* factory: close the security review's findings on password sign-in

H1 A session carries the password generation it was made under; a change
   or a reset moves the generation, and mintSession re-reads it under the
   session lock, so no session made with an old password outlives the change.
H2 A link made for one GitHub login takes no password and offers none.
H3 A try spends its throttle tokens on entry and gets them back only for a
   right password; one sign-in of a username is verified at a time.
M1 Backoff is keyed by (username, address); a looser per-username ceiling
   skips addresses the person signed in from before, so a stranger cannot
   keep the owner out.
M2 A username already named anywhere on the server (a GitHub login that ever
   signed in, a share, a team, an owner, a driver, a job, the record) is taken.
L1 IPv6 counts by /64; a backing-off key is never evicted, a full set refuses.
L2 A transparent rehash compares and swaps on the hash it verified; a change
   compares on the generation.
L3 The common list is NCSC 100k plus xato-net's top million and famous
   passphrases, compared by letters and digits: about 486,000 entries.
L4 A GitHub sign-in checks the name again under joinMu before its session is
   stored, and remembers the handle for good.
L5 accounts.json is cached by mtime and size; a read error refuses the
   request and keeps the session.
L6 Typed passwords are passing secrets: at least 8 bytes, the latest 64 kept.

Assisted-by: CodeAF
Co-Authored-By: CodeAF <[email protected]>

* factory: trust a person's own machines against a stranger's guesses (second review)

M1: every sign-up, reset, change and sign-in without one hands the machine a
device token (256-bit, kept server-side as SHA-256 in accounts.json, bound to
the person and the password generation, 180 days, 16 per person, revoked by a
change, reset or removal, surviving a restart). A try with a valid token
skips the username's ceiling and counts by the device and its address. The
engine keeps the token beside the session through factory.sessions_take and
factory.session_restore and presents it on later sign-ins. The in-memory
trusted addresses are gone. A new machine during an attack uses the
operator's reset link, which is never throttled.

M-new: the changing session is valid at gen+1 before the write, so concurrent
requests never sign it out. L-a: refunds are hand-counted credit. L-b: a full
set logs once a minute. L-c: punctuation, keyboard runs and few-character
passwords are common. L-d: a hash waits up to 500 ms for a slot.

POST /v1/me/password answers 200 {device_token}.

Assisted-by: CodeAF
Co-Authored-By: CodeAF <[email protected]>

* factory: a password person is not said to have signed in with GitHub

/v1/me and the password sign-in answer said github_signed_in true for a
password person. It is now true only for a GitHub sign-in; sign_in_kind
"password" says a password person signed in, and the engine's can_sign_out
reads either.

Assisted-by: CodeAF
Co-Authored-By: CodeAF <[email protected]>

* factory: a device token only when the client can keep it, and none in use is pushed out (re-review #2)

N1: a device token is made only on want_device; the engine asks only while
the app's core says factory.sessions_store {can_keep: true} (unsaid is
false). A device is marked used at every sign-in with it, and a person's
sixteen live devices are never evicted: past that a sign-in succeeds with no
new token, said once in the log. N2: a signed-in password change counts per
session, not against the username's ceiling. N3: a trusted pair is keyed by
device and address, so a stolen token used elsewhere backs off only itself.

Assisted-by: CodeAF
Co-Authored-By: CodeAF <[email protected]>

* factory: one session's or one device's guesses are capped across every address (re-check 3)

F1: a password change counts in one bucket per session with no address in
the key, so a stolen session spread over 30 addresses gets 10 current
passwords checked, not 300. F2: a device token keeps its (device, address)
pair bucket and also has a ceiling of 100 across every address; past it the
try counts as untrusted, so a stolen token from 30 addresses gets 100 trusted
checks plus the username's ceiling, not 300. F3: the concurrent-guess test
asserts the real bound, the username's ceiling.

Assisted-by: CodeAF
Co-Authored-By: CodeAF <[email protected]>

---------

Co-authored-by: CodeAF <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant