Skip to content

Promote foss-sandbox to foss-main: corporate-id, SSO UX, org provisioning - #35

Merged
UsamaSadiq merged 17 commits into
foss-mainfrom
foss-sandbox
Jul 20, 2026
Merged

Promote foss-sandbox to foss-main: corporate-id, SSO UX, org provisioning#35
UsamaSadiq merged 17 commits into
foss-mainfrom
foss-sandbox

Conversation

@UsamaSadiq

Copy link
Copy Markdown
Collaborator

Description

Promotes foss-sandbox changes to production. Key changes:

  • Corporate-ID check in ProxyAuth middleware (Layer 2): decodes X-Auth-Request-Access-Token header and validates custom:corporate_id against SMB_CORPORATE_ID env var. Returns 403 on mismatch. Closes the Bearer token bypass that skips mpass-auth-proxy.
  • Auto-provision org-space LiteLLM key on first SMB admin login
  • Hide download UI when SSO auth is active
  • Fix blank display name on SSO callback (hard redirect instead of client-side)
  • Performance: skip org-space DB lookup when mPass token absent; skip org provisioning on non-mPass logins
  • CI fixes: ruff-format, biome auto-fixes, libreadline-dev for TS quality job
  • Standardized PR template

Testing

  • Verified corporate-id enforcement on staging with matching and mismatching IDs
  • Confirmed backward compatibility when SMB_CORPORATE_ID is empty
  • SSO login flow tested end-to-end on staging

hunzlahmalik and others added 17 commits June 3, 2026 11:06
…min login

Extend the existing per-user Askii LiteLLM auto-provisioning so the shared
SMB/Organization search space also gets a key automatically, the first time
its is_owner admin logs in. The whole team then has AI features in the shared
space with no manual config.

Mirrors the personal flow as a direct analogue:
- New SearchSpace.litellm_auto_provisioned_at one-shot marker (migration
  moneta_002), the SearchSpace-scoped counterpart of the per-user marker.
- ensure_org_litellm_keys / ensure_org_litellm_keys_for_admin in
  litellm_provisioning.py: find the SMB space by name, gate on is_owner
  (is_search_space_owner), mint a fresh Askii key, wire the 4 SearchSpace LLM
  FKs, stamp the marker -- all under a begin_nested() SAVEPOINT with
  SELECT ... FOR UPDATE for exactly-once under concurrent logins.
- Reuses should_auto_provision / _provision_via_askii / _build_config_rows
  unchanged; personal path untouched.
- smb_auto_join: extracted reusable find_smb_search_space(session) +
  _smb_workspace_slug(); auto_join now reuses them.
- on_after_login wires the org call after the personal one, reading the mPass
  token once and committing the two steps on independent boundaries.

Best-effort + retry: any failure (transient Askii error, missing token, no SMB
space yet, not-yet-admin) leaves the marker NULL and retries on the admin's
next login. One-shot once stamped.

Tests: 21 new org cases (core + wrapper) + updated on_after_login commit tests
+ new org-wiring test. 52 passing; ruff clean; alembic single head
(143 -> moneta_001 -> moneta_002).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Address Copilot review on #29: ensure_org_litellm_keys_for_admin did the SMB
space lookup + ownership query before discovering it had no mPass access token
to mint with. Return early on a None token (after the feature gate, before any
DB round-trip) — provisioning can't succeed without it anyway, and non-mPass
logins (fastapi-users JWT, Google OAuth, dev hitting the backend directly) hit
this every request. The core ensure_org_litellm_keys keeps its own None-token
check as defense-in-depth; the marker stays NULL so the admin's next mPass
login retries. Adds a wrapper test asserting no DB calls when the token is None.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Resolves F821 ruff errors on lines 883, 893, 942 where SECRET was used
but never imported into app.py (it lives in app.users).
Suppress the DownloadButton on the hero section and the download CTA
in the sidebar user profile when isSSOAuth() is true, so managed/SSO
deployments don't surface desktop-download prompts.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Address Copilot review on #29: on_after_login ran the org provisioning call
and a second COMMIT even when access_token was None. The org wrapper now
early-returns without DB work in that case, so the commit was an empty no-op on
a hook that fires on every authenticated request. Guard the org call + commit
on `access_token is not None` (fastapi-users JWT, Google OAuth, dev-direct
flows reach this hook without an mPass token). Behavior-preserving — org
provisioning cannot run without the token anyway. Adds a hook test asserting
the org step is skipped and only the personal step commits when no token.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- ruff-format: reformat surfsense_backend/app/app.py (trailing newline
  after the new SECRET import)
- biome check --write: fix import ordering and formatting violations
  across 28 files in surfsense_web/ (atoms, components/ui, components/
  tool-ui, lib/apis, svgr.d.ts) — these pre-existing issues caused the
  TypeScript/JavaScript Quality check to fail on every PR
Extract downloadAllowed = !isDesktop && !isSSOAuth() and apply it to
all four download surfaces, including the two profile dropdown items
that were missed in the original commit.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@rocicorp/zero-sqlite3 requires readline/readline.h to compile its
native extension. The GitHub Actions Ubuntu runner doesn't include
libreadline-dev by default, causing pnpm install to fail with a gyp
build error before biome can even run.
…y name

Soft navigation (router.replace) preserved the React tree after the SSO
cookie handoff, leaving currentUserAtom stuck with enabled:false for the
entire session. A full page reload ensures the token is in localStorage
before any atom evaluates.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…oning

feat(surfsense): auto-provision org-space LiteLLM key on first SMB admin login
chore(ci): diagnose failing checks — fix SECRET import
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
feat(web): hide download UI when SSO auth is active
…first-login

fix(surfsense): use hard redirect on SSO callback to fix blank display name
Add corporate_id check to ProxyAuth middleware
@UsamaSadiq
UsamaSadiq merged commit e419cb9 into foss-main Jul 20, 2026
4 of 9 checks passed
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.

3 participants