feat: give each Kanban operator their own account
All checks were successful
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 1m17s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images and notify Portainer (push) Successful in 1m37s

One OPERATOR_EMAIL and OPERATOR_PASSWORD served the whole factory, so every card
movement recorded the same name and the movement history could not answer who
did what. Traceability was one of the things the project set out to provide.

Accounts live in dtf_local.operators, authenticated with the same scrypt hashing
as customer accounts and with comparable work whether or not the account exists,
so absence is not observable by timing. Administration is a CLI in the API
container, like the schema migration: list, add, password, disable, enable.
Passwords are read from the terminal rather than an argument so they stay out of
shell history and the process list, and disabling deletes that operator's open
sessions instead of leaving them valid for the rest of the eight-hour window.

Migration is the part that could hurt: an empty table means 503 and a factory
locked out of its Kanban. OPERATOR_EMAIL and OPERATOR_PASSWORD seed the first
account, and only when that email is absent, so a password changed through the
CLI survives a redeploy carrying a stale environment variable. The first attempt
at this silently did nothing, because db-init receives its own small environment
and had neither variable; both compose files now pass them to it.

Verified against a running stack: bootstrap seeds the existing credential, that
credential still logs in unchanged, a second operator authenticates separately,
wrong passwords and unknown accounts are rejected alike, and disabling revokes
an open session immediately.

Roles are left out on purpose. The separation of duties the meeting described
governs rework authorisation, which this system does not implement, so a role
model would have no consumer to serve.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-09-21 14:13:47 -03:00
parent da903db32a
commit a87403338d
8 changed files with 215 additions and 13 deletions

View File

@@ -26,8 +26,34 @@ def check_client_ip():
assert client_ip(FakeRequest(peer=None))=='unknown'
print('PASS: client address resolution for rate-limit buckets and audit events')
def check_operator_accounts():
"""Accounts are per person, and disabling one ends its access at once."""
from uuid import uuid4
from .auth import password_hash, password_matches
from .operators import seed_from_environment, set_active
email='runtime-check-'+uuid4().hex[:8]+'@example.test'
with connect() as c:
c.execute('INSERT INTO dtf_local.operators(id,email,name,password_hash) VALUES(%s,%s,%s,%s)',
(uuid4(), email, 'Runtime Check', password_hash('runtime-check-password')))
row=c.execute('SELECT * FROM dtf_local.operators WHERE email=%s',(email,)).fetchone()
assert row['active'] and password_matches('runtime-check-password', row['password_hash'])
assert not password_matches('wrong', row['password_hash'])
# Seeding is once-only: a password changed here must survive a redeploy.
c.execute("INSERT INTO dtf_local.operator_sessions(token_hash,username) VALUES(%s,%s)",
('runtime-check-'+uuid4().hex, email))
set_active(email, False)
with connect() as c:
row=c.execute('SELECT active FROM dtf_local.operators WHERE email=%s',(email,)).fetchone()
sessions=c.execute('SELECT count(*) AS n FROM dtf_local.operator_sessions WHERE username=%s',
(email,)).fetchone()['n']
assert not row['active'], 'disable did not deactivate'
assert sessions==0, 'disable left an open session behind'
c.execute('DELETE FROM dtf_local.operators WHERE email=%s',(email,))
print('PASS: per-operator accounts, password verification, immediate revocation on disable')
def run():
check_client_ip()
check_operator_accounts()
with connect() as c:
role=c.execute('SELECT rolsuper,rolcreatedb,rolcreaterole,rolbypassrls FROM pg_roles WHERE rolname=current_user').fetchone()
assert not any(role.values()),role