Skip to content

armgit / AiSOC

Public Imported from GitHub
0

Open-source AI Security Operations Center: alert fusion, LLM-agent triage, MITRE ATT&CK investigation, and a replayable decision ledger for every agent step. Self-hostable, runs with no API keys, MIT licensed. Ships an MCP server for Claude, Cursor and Continue.

fix(auth): demo login that actually works on the public demo

Beenu Arora2f4fbae7a81a
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 000000000..0442993b6
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,83 @@
+# AiSOC monorepo .dockerignore
+# Keeps the build context small for `flyctl deploy --config infra/fly/web/fly.toml`
+# (run from repo root). The web Dockerfile only needs apps/web, packages/, and
+# a handful of root config files (package.json, pnpm-workspace.yaml, pnpm-lock,
+# turbo.json, tsconfig.base.json). Everything else is dead weight and pushed
+# the context past 1.6GB on uncached deploys.
+#
+# Each service Docker build context is its own service directory (per
+# infra/fly/fly-demo-deploy.sh), so excluding services/ here only affects the
+# web build, which doesn't need them.
+
+# ─── VCS / agent state ────────────────────────────────────────────────────────
+.git
+.github
+.gitignore
+.gitattributes
+.cursor
+.claude
+.vscode
+.idea
+.husky
+agent-transcripts/
+terminals/
+*.log
+
+# ─── Node / build artifacts (will be reinstalled inside the image) ────────────
+**/node_modules
+**/.next
+**/.turbo
+**/dist
+**/build
+**/.nyc_output
+**/coverage-final.json
+**/.cache
+**/.parcel-cache
+**/.eslintcache
+**/.tsbuildinfo
+**/*.tsbuildinfo
+
+# ─── Python (services/*) — excluded from the web build entirely ───────────────
+services/
+**/__pycache__
+**/*.pyc
+**/*.pyo
+**/.venv
+**/venv
+**/.pytest_cache
+**/.mypy_cache
+**/.ruff_cache
+
+# ─── Other top-level monorepo dirs the web app does not need ──────────────────
+infra/
+detections/
+marketplace/
+plugins/
+docs/
+apps/docs
+ops/
+scripts/
+tests/
+e2e/
+benchmarks/
+
+# ─── Local env / secrets (never bake into images) ─────────────────────────────
+.env
+.env.*
+!.env.example
+*.pem
+*.key
+*.crt
+
+# ─── OS / editor cruft ────────────────────────────────────────────────────────
+.DS_Store
+Thumbs.db
+*.swp
+*.swo
+
+# ─── Misc generated assets ────────────────────────────────────────────────────
+*.tar
+*.tar.gz
+*.zip
+tmp/
+temp/
diff --git a/apps/web/src/app/login/page.tsx b/apps/web/src/app/login/page.tsx
new file mode 100644
index 000000000..0414d534a
--- /dev/null
+++ b/apps/web/src/app/login/page.tsx
@@ -0,0 +1,244 @@
+'use client';
+
+/**
+ * Desktop console login.
+ *
+ * Email + password against ``POST /api/v1/auth/login`` for the open-source
+ * console. The mobile responder PWA at ``/responder/login`` uses passkeys; this
+ * page is the desktop counterpart and the link target from the responder login
+ * footer ("Sign in on desktop").
+ *
+ * Demo credentials live in `services/api/app/api/v1/dev_auth.py`:
+ * [email protected] / aisoc-demo
+ */
+
+import Link from 'next/link';
+import { useRouter, useSearchParams } from 'next/navigation';
+import { Suspense, useEffect, useState } from 'react';
+import { authApi } from '@/lib/api';
+
+type Phase = 'idle' | 'pending' | 'success' | 'error';
+
+export const dynamic = 'force-dynamic';
+
+const DEMO_EMAIL = '[email protected]';
+const DEMO_PASSWORD = 'aisoc-demo';
+
+function LoginInner() {
+ const router = useRouter();
+ const search = useSearchParams();
+ const next = search?.get('next') || '/dashboard';
+
+ const [email, setEmail] = useState('');
+ const [password, setPassword] = useState('');
+ const [phase, setPhase] = useState<Phase>('idle');
+ const [error, setError] = useState<string | null>(null);
+
+ useEffect(() => {
+ if (authApi.isAuthenticated()) {
+ router.replace(next);
+ }
+ }, [next, router]);
+
+ const submit = async (event: React.FormEvent) => {
+ event.preventDefault();
+ if (phase === 'pending') return;
+ setPhase('pending');
+ setError(null);
+
+ try {
+ await authApi.login(email.trim(), password);
+ setPhase('success');
+ router.replace(next);
+ } catch (err) {
+ console.error('[login] failed', err);
+ setPhase('error');
+ const message = err instanceof Error ? err.message : 'Login failed.';
+ // Map the common 401 to something a human understands.
+ if (/401|incorrect/i.test(message)) {
+ setError('Email or password incorrect.');
+ } else {
+ setError(message);
+ }
+ }
+ };
+
+ const useDemo = () => {
+ setEmail(DEMO_EMAIL);
+ setPassword(DEMO_PASSWORD);
+ };
+
+ return (
+ <div className="min-h-screen bg-zinc-950 text-zinc-100 antialiased flex flex-col">
+ <div className="flex-1 flex items-center justify-center px-6 py-16">
+ <div className="w-full max-w-md">
+ {/* Brand */}
+ <div className="flex flex-col items-center text-center mb-10">
+ <Link
+ href="/"
+ className="w-14 h-14 rounded-2xl bg-indigo-600 flex items-center justify-center mb-5 hover:bg-indigo-500 transition"
+ aria-label="Back to AiSOC home"
+ >
+ <svg
+ className="w-8 h-8 text-white"
+ fill="none"
+ viewBox="0 0 24 24"
+ stroke="currentColor"
+ >
+ <path
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth={1.75}
+ d="M9 12.75L11.25 15 15 9.75m-3-7.036A11.959 11.959 0 013.598 6 11.99 11.99 0 003 9.749c0 5.592 3.824 10.29 9 11.623 5.176-1.332 9-6.03 9-11.622 0-1.31-.21-2.571-.598-3.751h-.152c-3.196 0-6.1-1.248-8.25-3.285z"
+ />
+ </svg>
+ </Link>
+ <h1 className="text-2xl font-semibold tracking-tight">
+ Sign in to AiSOC
+ </h1>
+ <p className="text-sm text-zinc-400 mt-2 leading-relaxed">
+ Open-source AI SOC console. Use the demo credentials below or
+ your own tenant&rsquo;s account.
+ </p>
+ </div>
+
+ {/* Demo banner */}
+ <div className="mb-6 rounded-xl border border-indigo-500/30 bg-indigo-500/5 px-4 py-3 text-sm">
+ <div className="flex items-start justify-between gap-3">
+ <div>
+ <p className="font-medium text-indigo-300">Public demo</p>
+ <p className="text-xs text-zinc-400 mt-0.5">
+ <code className="text-zinc-300">[email protected]</code> /{' '}
+ <code className="text-zinc-300">aisoc-demo</code>
+ </p>
+ </div>
+ <button
+ type="button"
+ onClick={useDemo}
+ className="shrink-0 rounded-lg border border-indigo-500/40 bg-indigo-500/10 px-3 py-1.5 text-xs font-medium text-indigo-200 hover:bg-indigo-500/20 transition"
+ >
+ Use demo
+ </button>
+ </div>
+ </div>
+
+ {/* Form */}
+ <form onSubmit={submit} className="space-y-4" noValidate>
+ <label className="block">
+ <span className="block text-xs uppercase tracking-wider text-zinc-500 mb-2">
+ Email
+ </span>
+ <input
+ type="email"
+ autoComplete="username"
+ inputMode="email"
+ autoCapitalize="off"
+ spellCheck={false}
+ placeholder="[email protected]"
+ value={email}
+ onChange={(e) => setEmail(e.target.value)}
+ disabled={phase === 'pending'}
+ required
+ className="w-full bg-zinc-900 border border-zinc-800 rounded-xl px-4 py-3 text-sm text-zinc-100 placeholder:text-zinc-600 focus:outline-none focus:ring-2 focus:ring-indigo-500/50 focus:border-indigo-500/50 disabled:opacity-60"
+ />
+ </label>
+
+ <label className="block">
+ <span className="block text-xs uppercase tracking-wider text-zinc-500 mb-2">
+ Password
+ </span>
+ <input
+ type="password"
+ autoComplete="current-password"
+ placeholder="••••••••"
+ value={password}
+ onChange={(e) => setPassword(e.target.value)}
+ disabled={phase === 'pending'}
+ required
+ className="w-full bg-zinc-900 border border-zinc-800 rounded-xl px-4 py-3 text-sm text-zinc-100 placeholder:text-zinc-600 focus:outline-none focus:ring-2 focus:ring-indigo-500/50 focus:border-indigo-500/50 disabled:opacity-60"
+ />
+ </label>
+
+ <button
+ type="submit"
+ disabled={phase === 'pending' || !email || !password}
+ className="w-full bg-indigo-500 hover:bg-indigo-400 active:bg-indigo-600 text-white font-medium rounded-xl py-3 px-4 transition flex items-center justify-center gap-2 disabled:bg-zinc-800 disabled:text-zinc-500"
+ >
+ {phase === 'pending' ? (
+ <>
+ <svg
+ className="w-4 h-4 animate-spin"
+ fill="none"
+ viewBox="0 0 24 24"
+ >
+ <circle
+ className="opacity-25"
+ cx="12"
+ cy="12"
+ r="10"
+ stroke="currentColor"
+ strokeWidth="3"
+ />
+ <path
+ className="opacity-90"
+ fill="currentColor"
+ d="M4 12a8 8 0 018-8v4a4 4 0 00-4 4H4z"
+ />
+ </svg>
+ <span>Signing in…</span>
+ </>
+ ) : (
+ <span>Sign in</span>
+ )}
+ </button>
+
+ {error ? (
+ <div
+ role="alert"
+ className="rounded-lg border border-red-500/40 bg-red-500/10 px-3 py-2.5 text-xs text-red-300"
+ >
+ {error}
+ </div>
+ ) : null}
+ </form>
+
+ {/* Footer hints */}
+ <div className="mt-8 space-y-3 text-center">
+ <p className="text-xs text-zinc-500">
+ On a phone?{' '}
+ <Link
+ href="/responder/login"
+ className="text-indigo-400 hover:text-indigo-300 underline-offset-2 hover:underline"
+ >
+ Use the responder PWA
+ </Link>{' '}
+ with passkeys.
+ </p>
+ <p className="text-[11px] text-zinc-600">
+ <Link
+ href="/"
+ className="hover:text-zinc-400 underline-offset-2 hover:underline"
+ >
+ ← Back to tryaisoc.com
+ </Link>
+ </p>
+ </div>
+ </div>
+ </div>
+
+ <div className="px-6 pb-[max(1rem,env(safe-area-inset-bottom))] pt-4 text-center">
+ <p className="text-[10px] text-zinc-700 uppercase tracking-widest">
+ AiSOC · MIT-licensed · Open-source AI SOC
+ </p>
+ </div>
+ </div>
+ );
+}
+
+export default function LoginPage() {
+ return (
+ <Suspense fallback={null}>
+ <LoginInner />
+ </Suspense>
+ );
+}
diff --git a/apps/web/src/lib/api.ts b/apps/web/src/lib/api.ts
index 460160572..a901d131e 100644
--- a/apps/web/src/lib/api.ts
+++ b/apps/web/src/lib/api.ts
@@ -177,6 +177,106 @@ async function request<T>(path: string, options: FetchOptions = {}): Promise<T>
return (await response.json()) as T;
}
+// ─── Auth ────────────────────────────────────────────────────────────────────
+
+export const AUTH_TOKEN_KEY = 'aisoc.responder.accessToken';
+export const AUTH_REFRESH_KEY = 'aisoc.responder.refreshToken';
+export const AUTH_USER_KEY = 'aisoc.responder.user';
+
+export interface AuthUser {
+ id: string;
+ email: string;
+ username?: string | null;
+ role: string;
+ tenant_id: string;
+ is_active?: boolean;
+}
+
+export interface TokenResponse {
+ access_token: string;
+ refresh_token: string;
+ token_type: string;
+ expires_in: number;
+}
+
+export interface LoginResult extends TokenResponse {
+ user: AuthUser;
+}
+
+function persistAuth(tokens: TokenResponse, user: AuthUser): void {
+ if (typeof window === 'undefined') return;
+ try {
+ window.localStorage.setItem(AUTH_TOKEN_KEY, tokens.access_token);
+ if (tokens.refresh_token) {
+ window.localStorage.setItem(AUTH_REFRESH_KEY, tokens.refresh_token);
+ }
+ window.localStorage.setItem(AUTH_USER_KEY, JSON.stringify(user));
+ } catch {
+ /* localStorage unavailable; ignore */
+ }
+}
+
+export const authApi = {
+ /**
+ * Email + password login against ``POST /api/v1/auth/login``.
+ *
+ * The backend returns access + refresh tokens only, so we follow up with
+ * ``GET /api/v1/auth/me`` to fetch the user record. On success, persist
+ * everything under the same localStorage keys the responder PWA uses
+ * (``aisoc.responder.accessToken`` etc.) so the existing ``request()``
+ * helper attaches the JWT automatically and a single login covers desktop
+ * + mobile.
+ */
+ async login(email: string, password: string): Promise<LoginResult> {
+ const tokens = await request<TokenResponse>('/api/v1/auth/login', {
+ method: 'POST',
+ body: JSON.stringify({ email, password }),
+ });
+ // Stash the access token now so the `me` request flows through the
+ // standard `Authorization: Bearer …` path in `request()`.
+ if (typeof window !== 'undefined') {
+ try {
+ window.localStorage.setItem(AUTH_TOKEN_KEY, tokens.access_token);
+ } catch {
+ /* ignore */
+ }
+ }
+ const user = await request<AuthUser>('/api/v1/auth/me');
+ persistAuth(tokens, user);
+ return { ...tokens, user };
+ },
+
+ logout(): void {
+ if (typeof window === 'undefined') return;
+ try {
+ window.localStorage.removeItem(AUTH_TOKEN_KEY);
+ window.localStorage.removeItem(AUTH_REFRESH_KEY);
+ window.localStorage.removeItem(AUTH_USER_KEY);
+ } catch {
+ /* ignore */
+ }
+ },
+
+ currentUser(): AuthUser | null {
+ if (typeof window === 'undefined') return null;
+ try {
+ const raw = window.localStorage.getItem(AUTH_USER_KEY);
+ return raw ? (JSON.parse(raw) as AuthUser) : null;
+ } catch {
+ return null;
+ }
+ },
+
+ isAuthenticated(): boolean {
+ if (typeof window === 'undefined') return false;
+ try {
+ return Boolean(window.localStorage.getItem(AUTH_TOKEN_KEY));
+ } catch {
+ return false;
+ }
+ },
+};
+
// ─── Alerts ─────────────────────────────────────────────────────────────────
export type AlertSeverity = 'critical' | 'high' | 'medium' | 'low' | 'info';
diff --git a/services/api/app/api/v1/dev_auth.py b/services/api/app/api/v1/dev_auth.py
index 816a17879..b6c993049 100644
--- a/services/api/app/api/v1/dev_auth.py
+++ b/services/api/app/api/v1/dev_auth.py
@@ -20,7 +20,10 @@ import uuid
# Deterministic demo IDs — kept in sync with seed_demo.py
DEMO_TENANT_ID: uuid.UUID = uuid.UUID("00000000-0000-0000-0000-000000000001")
DEMO_USER_ID: uuid.UUID = uuid.UUID("00000000-0000-0000-0000-000000000002")
-DEMO_USER_EMAIL: str = "[email protected]"
+# Use a real TLD (not `.local`, which is reserved for mDNS and rejected by
+# pydantic ``EmailStr``). Deterministic, public-demo-only credentials.
+DEMO_USER_EMAIL: str = "[email protected]"
+DEMO_USER_PASSWORD: str = "aisoc-demo"
DEMO_USER_ROLE: str = "admin"
_DEV_ENVS = {"development", "dev", "local", "demo"}
diff --git a/services/api/app/scripts/seed_demo.py b/services/api/app/scripts/seed_demo.py
index 4afee9986..9ce00b0c9 100644
--- a/services/api/app/scripts/seed_demo.py
+++ b/services/api/app/scripts/seed_demo.py
@@ -8,7 +8,7 @@ Run this from the host (the API container has the package on its PYTHONPATH):
The seed is idempotent — running it twice produces the same dataset and never
duplicates rows. Demo IDs are kept in sync with `app/api/v1/dev_auth.py` so the
-auth bypass and the seeded data agree on who "[email protected]" is.
+auth bypass and the seeded data agree on who "[email protected]" is.
"""
from __future__ import annotations
@@ -392,16 +392,32 @@ async def _ensure_tenant(session) -> Tenant:
async def _ensure_user(session, tenant: Tenant) -> User:
+ """Upsert the demo user.
+
+ If the deterministic demo user already exists from a previous seed (with a
+ stale email like the old ``[email protected]``, or a different password),
+ bring it back into sync rather than skipping. This keeps re-seeds idempotent
+ *and* self-healing against drift introduced by previous schema decisions.
+ """
result = await session.execute(select(User).where(User.id == DEMO_USER_ID))
user = result.scalar_one_or_none()
- if user:
+ hashed = get_password_hash("aisoc-demo")
+ if user is not None:
+ user.tenant_id = tenant.id
+ user.email = DEMO_USER_EMAIL
+ user.username = "demo"
+ user.hashed_password = hashed
+ user.role = DEMO_USER_ROLE
+ user.is_active = True
+ user.is_verified = True
+ await session.flush()
return user
user = User(
id=DEMO_USER_ID,
tenant_id=tenant.id,
email=DEMO_USER_EMAIL,
username="demo",
- hashed_password=get_password_hash("aisoc-demo"),
+ hashed_password=hashed,
role=DEMO_USER_ROLE,
is_active=True,
is_verified=True,