已关闭
[WEB-02] Implement the Go Telegram OIDC BFF and YDB web-session store #31
urandon创建于  8月4日关闭于  8月10日
urandon
urandon成员
8月4日 创建

Parent

Outcome

Implement a Go BFF that authenticates users with Telegram OIDC, resolves internal memberships and issues revocable first-party web sessions.

Estimate

  • 8 SP / 5 engineering days
  • Risk: high

Scope

  • Add cmd/web-bff with health/readiness/version and structured redacted logging.
  • Implement OIDC Authorization Code + PKCE, state/nonce challenges, server-side token exchange and JWKS validation.
  • Load the Telegram OIDC client secret from Lockbox/environment injection without writing it to Terraform state, argv, images or logs.
  • Add YDB migrations and repository operations for randomly sharded login challenges and hashed opaque web sessions with TTL.
  • Resolve Telegram sub through canonical external identity and tenant membership records.
  • Implement /auth/telegram/start, callback, logout, /api/web/v1/me, tenant listing and validated active-tenant selection.
  • Add Secure HttpOnly __Host- cookie, CSRF/Origin enforcement, session rotation, idle/absolute expiry and revocation.
  • Add a local-only Go OIDC fixture with fixed JWKS that refuses cloud modes.

Verification

  • Invalid state, PKCE, signature, issuer, audience, expiry and nonce fail closed.
  • One-time challenge consumption is concurrency-safe.
  • Session fixation/replay, logout and membership-version revocation tests pass.
  • Two-user/two-tenant tests prove no tenant selection or session-ID crossover.
  • Secret/token/cookie values are absent from logs and error responses.
  • YDB access paths are point/bounded operations with no monotonic hot key.

Acceptance criteria

  • An existing Telegram-bound user receives only authorized tenant memberships.
  • An unknown Telegram identity gets a deterministic 403 recovery response and no implicit tenant.
  • Every authenticated product operation obtains tenant identity from the resolved server session.
  • The production binary and image contain no Python or Node runtime.

Non-goals

  • Canonical session/history endpoints.
  • Svelte screens.
  • Telegram update ingestion or message delivery.
likedislike
urandonurandon成员
8月5日 关联了pull request:WEB-01: define authenticated WebUI contracts
urandonurandon成员
8月5日 关联了pull request:WEB-02: implement Telegram OIDC BFF and YDB sessions
urandon
urandon成员
8月5日 评论:

Implementation update — Telegram OIDC BFF and YDB Web sessions

Implementation is ready in MR !22, branch ai/web-02-oidc-bff, commit 0608460.

Implemented

  • A Go same-origin Web BFF with health/version endpoints, Telegram login start/callback, logout, current identity, membership list, and active-tenant rotation.
  • Telegram OIDC Authorization Code + PKCE S256, browser-bound one-time state, nonce, exact redirect URI, server-side Basic-auth token exchange, exact production endpoint pinning, RS256-only JWT verification, and bounded JWKS caching/refresh.
  • Secure first-party __Host- cookies, exact-Origin plus session-bound CSRF validation, 12-hour sliding idle lifetime, seven-day absolute lifetime, revocation, and mandatory session/CSRF rotation when changing tenants.
  • A deterministic Go-only Telegram-shaped OIDC fixture that generates an ephemeral RSA key and refuses every environment except exact local.
  • Seven YDB migrations for immutable external identities, reverse identity lookup, tenant memberships, invitations, OIDC login challenges, Web sessions, and the audited development-bootstrap ledger.
  • Automatic YDB size/load partitioning on the new tables. Stable hashed leading buckets distribute pre-authentication and session point lookups; they do not impose a physical partition count.
  • Telegram ingestion now atomically materializes the same external identity and owner membership used by Web login. Telegram proves the external identity; active Sessionless membership remains the authorization source.
  • An operator-only make web-bootstrap command that requires exact cloud-dev, an existing external identity, operator/reason metadata, stdin typed confirmation, metadata/environment YDB credentials, idempotent exact grants, and a redacted audit event.
  • Updated README, development, Web-auth/threat-model, YDB state-store, and partitioning documentation. Public text is English-only.

Verification

Local:

  • make ci passed: generate, vet, race tests, all 13 binaries, and foundation integration tests.
  • The full login/switch/logout flow passed 50 consecutive race-enabled runs.
  • Wrong PKCE, untrusted signing key, endpoint override, code replay, unknown membership, CSRF, old-session replay, and authentication-material log-redaction negatives passed.
  • git diff --check and public Cyrillic scan passed.

Mirrored GitHub Actions run #65 is green for the exact commit 0608460:

  • Go verification — success;
  • YDB schema and state store — success, including applying all 55 migrations twice and running concurrent challenge/bootstrap/identity/session isolation tests;
  • Local multi-service stand — success, including stop/restart persistence;
  • Terraform environments — success;
  • Runtime images — success, including the distroless Go Web BFF image.

During verification, a probabilistic login defect was found and fixed: unprefixed base64url secrets could begin with _ or -, violating the opaque-ID contract and randomly rejecting a callback. Typed alphabetic prefixes now make the invariant deterministic; the 50-run regression is green.

Issue #31 remains open until MR !22 is merged.

likedislike
urandonurandon成员
8月10日 关闭了 issue
urandon
urandon成员
8月10日 评论:

Completion report — merged

WEB-02 was merged through MR !22 into main as commit 2aa2c7f.

The requested review fixes are included:

  • the documented routes now match the executable /auth/logout and /api/web/v1/... contract;
  • web-bff listens on the documented WEB_PORT with a non-conflicting 8083 default;
  • login failures and CSRF rejections are synchronously persisted as redacted YDB security-audit events, including pre-authentication failures without a resolved tenant.

The mirrored branch run passed Go/race verification, Terraform validation, repeatable YDB migrations and integration tests, the local multi-service stand, and runtime image builds: GitHub Actions run #66.

Issue closure was performed automatically by the merged MR.

likedislike
urandon
urandon成员
8月10日 评论:

Merged-main verification is complete: GitHub Actions CI run #67 passed for main commit 2aa2c7f (Go verification, YDB schema/state store, local multi-service stand, Terraform validation, and runtime images). WEB-02 remains closed.

likedislike
urandon
urandon成员
23 天前 评论:

Обработал оба замечания в cd3a4c2.

P1 (comment 185229856): SnapshotBuilder теперь вызывает event.Validate и сверяет tenant/session с запросом до sequence check и blobs.Open. Regression TestSnapshotBuilderRejectsCrossSessionEventBeforeOpeningPayload проверяет, что same-tenant event другой session отклонён до чтения payload.

P2 (comment 185229860): snapshot creation подключён к production reconciler после успешных publish и outbox acknowledge. Политика явная и bounded: SNAPSHOT_INTERVAL_EVENTS=128, SNAPSHOT_MAX_VERSIONS=32, build ограничен LIMIT_CONTEXT_EVENTS/BYTES. Ошибка maintenance наблюдается и логируется, но не ломает dispatch; canonical replay остаётся correctness path. Добавлены local/cloud S3 wiring и storage.editor для scheduler service account.

Проверки: make test; make ydb-integration; make compose-config; make e2e-local; make ci; make terraform-ci.

likedislike
urandonurandon成员
15 天前 添加了label:mvpsecuritywebui
urandonurandon成员
15 天前 关联了里程碑:MVP — Authenticated WebUI (#29)