Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

portal: default sessions to 7 days rolling, 30 days absolute (#1025)

Regan Bell4610c14160a4
diff --git a/cli/templates/fly/portal.toml b/cli/templates/fly/portal.toml
index 595d687cb..a864d708e 100644
--- a/cli/templates/fly/portal.toml
+++ b/cli/templates/fly/portal.toml
@@ -17,7 +17,6 @@ primary_region = "sjc"
OIDC_SCOPES = "openid email profile"
OIDC_PRINCIPAL_CLAIM = "email"
OIDC_ALLOWED_EMAIL_DOMAIN = "example.com"
- PORTAL_SESSION_TTL_S = "28800"
[http_service]
internal_port = 8080
diff --git a/deploy/portal/fly.toml b/deploy/portal/fly.toml
index 595d687cb..a864d708e 100644
--- a/deploy/portal/fly.toml
+++ b/deploy/portal/fly.toml
@@ -17,7 +17,6 @@ primary_region = "sjc"
OIDC_SCOPES = "openid email profile"
OIDC_PRINCIPAL_CLAIM = "email"
OIDC_ALLOWED_EMAIL_DOMAIN = "example.com"
- PORTAL_SESSION_TTL_S = "28800"
[http_service]
internal_port = 8080
diff --git a/plugins/portal/README.md b/plugins/portal/README.md
index 96dc114ad..2a10fb838 100644
--- a/plugins/portal/README.md
+++ b/plugins/portal/README.md
@@ -25,8 +25,8 @@ surfaces, and it does **not** import the core.
signature and payload (`nonce`/`aud`/`iss`/`sub`/timestamps and, for Slack, the `team_id`
workspace pin) against the configured HTTPS JWKS, then reads
the subject from userinfo. The verified `sub` **is** the core principal id. It mints a
- signed `portal_session` cookie (`{sub, org, auth, exp}`, HMAC, 8h sliding lifetime with a
- 24h absolute maximum by default).
+ signed `portal_session` cookie (`{sub, org, auth, exp}`, HMAC, 7-day sliding lifetime with a
+ 30-day absolute maximum by default).
3. **Proxy** — every other path requires a valid session. The portal picks the upstream by the
**exact first path segment**, strips the prefix, and proxies to the private upstream,
synthesizing the surface cookie for compatibility and attaching a short-lived signed portal
@@ -161,7 +161,7 @@ Non-secret (`[env]`): `PORT` (8097 local / 8080 image), `PORTAL_PUBLIC_URL`, `CO
`CORE_ORG_ID`, `WEB_UI_UPSTREAM`, `ADMIN_UPSTREAM`,
`OIDC_AUTH_ENDPOINT` / `OIDC_TOKEN_ENDPOINT` / `OIDC_USERINFO_ENDPOINT` / `OIDC_ISSUER` /
`OIDC_JWKS_URI` / `OIDC_SCOPES` / `OIDC_CLIENT_ID`, `PORTAL_EXPECTED_TEAM_ID`,
-`PORTAL_SESSION_TTL_S`, `PORTAL_SESSION_MAX_TTL_S`. `PORTAL_SESSION_MAX_TTL_S` caps a session's total life from authentication; it defaults to the larger of one day and `PORTAL_SESSION_TTL_S`, and boot fails if it is set below the TTL.
+`PORTAL_SESSION_TTL_S`, `PORTAL_SESSION_MAX_TTL_S`. `PORTAL_SESSION_MAX_TTL_S` caps a session's total life from authentication; it defaults to the larger of 30 days and `PORTAL_SESSION_TTL_S`, and boot fails if it is set below the TTL.
There is no `PORTAL_ADMIN_PRINCIPALS` — admin
access is derived from the core (see the security model above).
For local development only, `PORTAL_LOCAL_AUTH_BYPASS=1` mints a local session as
diff --git a/plugins/portal/src/index.ts b/plugins/portal/src/index.ts
index 579ba3b6c..667bc4063 100644
--- a/plugins/portal/src/index.ts
+++ b/plugins/portal/src/index.ts
@@ -62,8 +62,8 @@ import {
const PORT = portFromEnv(8097);
const PUBLIC_URL = (process.env.PORTAL_PUBLIC_URL ?? `http://localhost:${PORT}`).replace(/\/$/, "");
const SESSION_SECRET = process.env.PORTAL_SESSION_SECRET;
-const SESSION_TTL_S = Number(process.env.PORTAL_SESSION_TTL_S ?? 28800);
-const SESSION_MAX_TTL_S = Number(process.env.PORTAL_SESSION_MAX_TTL_S ?? Math.max(86400, SESSION_TTL_S));
+const SESSION_TTL_S = Number(process.env.PORTAL_SESSION_TTL_S ?? 604800);
+const SESSION_MAX_TTL_S = Number(process.env.PORTAL_SESSION_MAX_TTL_S ?? Math.max(2592000, SESSION_TTL_S));
const SESSION_RENEW_AFTER_S = Math.floor(SESSION_TTL_S / 2);
const APPS_DOMAIN = process.env.PORTAL_APPS_DOMAIN || process.env.DEPLOY_APPS_DOMAIN || undefined;
const COOKIE_DOMAIN =
diff --git a/plugins/portal/test/entry.test.ts b/plugins/portal/test/entry.test.ts
index 033d347b7..3e7e78654 100644
--- a/plugins/portal/test/entry.test.ts
+++ b/plugins/portal/test/entry.test.ts
@@ -141,7 +141,7 @@ test("a session TTL above the default max ceiling still boots, but a contradicto
OIDC_CLIENT_ID: "client-id",
OIDC_CLIENT_SECRET: "client-secret",
OIDC_ALLOWED_EMAILS: "[email protected]",
- PORTAL_SESSION_TTL_S: "604800",
+ PORTAL_SESSION_TTL_S: "5184000",
};
delete baseEnv.PORTAL_SESSION_MAX_TTL_S;
diff --git a/plugins/portal/test/local-auth-bypass.test.ts b/plugins/portal/test/local-auth-bypass.test.ts
index 22597a4e8..e84b54177 100644
--- a/plugins/portal/test/local-auth-bypass.test.ts
+++ b/plugins/portal/test/local-auth-bypass.test.ts
@@ -38,7 +38,7 @@ test("local auth bypass signs in loopback portal requests without OIDC", async (
const login = await fetch(`${base}/auth/login?returnTo=/admin/`, { redirect: "manual" });
assert.equal(login.status, 302);
assert.equal(login.headers.get("location"), "/admin/");
- assert.match(login.headers.get("set-cookie") ?? "", /portal_session=/);
+ assert.match(login.headers.get("set-cookie") ?? "", /portal_session=[^,]*Max-Age=604800\b/);
const admin = await fetch(`${base}/admin/api/me`);
assert.equal(admin.status, 200);
diff --git a/plugins/portal/test/playground.test.ts b/plugins/portal/test/playground.test.ts
index 95fd7d72f..94ead793e 100644
--- a/plugins/portal/test/playground.test.ts
+++ b/plugins/portal/test/playground.test.ts
@@ -42,6 +42,8 @@ process.env.ADMIN_UPSTREAM = upstreamUrl;
process.env.CORE_API_URL = upstreamUrl;
process.env.PORTAL_PLAYGROUND = "1";
process.env.PORTAL_PLAYGROUND_MINTS_PER_IP = "3";
+const SESSION_TTL_S = 28800;
+process.env.PORTAL_SESSION_TTL_S = String(SESSION_TTL_S);
delete process.env.PORTAL_LOCAL_AUTH_BYPASS;
const { server, mintBucketOf } = await import("../src/index.ts");
@@ -108,9 +110,9 @@ test("sliding renewal preserves the anon flag", async () => {
org: process.env.CORE_ORG_ID ?? "acme",
name: "Guest",
anon: true,
- auth: now - 15000,
- iat: now - 15000,
- exp: now + 13800,
+ auth: now - SESSION_TTL_S / 2 - 600,
+ iat: now - SESSION_TTL_S / 2 - 600,
+ exp: now + SESSION_TTL_S / 2 - 600,
};
const res = await fetch(`${base}/`, {
headers: { ...HTML, cookie: `portal_session=${encodeURIComponent(seal(aged, key))}` },
diff --git a/plugins/portal/test/router.test.ts b/plugins/portal/test/router.test.ts
index 555e65190..8f1e0b434 100644
--- a/plugins/portal/test/router.test.ts
+++ b/plugins/portal/test/router.test.ts
@@ -95,6 +95,8 @@ process.env.CORE_SIGNING_SECRET = "router-test-core-secret";
process.env.WEB_UI_UPSTREAM = upstreamUrl;
process.env.ADMIN_UPSTREAM = upstreamUrl;
process.env.CORE_API_URL = upstreamUrl;
+const SESSION_TTL_S = 28800;
+process.env.PORTAL_SESSION_TTL_S = String(SESSION_TTL_S);
const { server } = await import("../src/index.ts");
const { deriveKey, seal, open } = await import("../src/session.ts");
@@ -105,7 +107,7 @@ const sessionKey = deriveKey("router-test-portal-secret", "portal.session.v1");
function sessionCookie(sub: string, ageS = 0): string {
const now = Math.floor(Date.now() / 1000);
const iat = now - ageS;
- return `portal_session=${encodeURIComponent(seal({ k: "session", sub, org: "acme", iat, exp: iat + 28800 }, sessionKey))}`;
+ return `portal_session=${encodeURIComponent(seal({ k: "session", sub, org: "acme", iat, exp: iat + SESSION_TTL_S }, sessionKey))}`;
}
test.after(() => {
@@ -561,10 +563,13 @@ test("sliding renewal: a fresh session is NOT re-stamped, an aged one is re-issu
const setCookie = aged.headers.get("set-cookie") ?? "";
const m = setCookie.match(/portal_session=([^;]+)/);
assert.ok(m, "an aged session is re-stamped through the proxy");
- assert.match(setCookie, /Max-Age=28800/, "the renewed cookie carries a full TTL");
+ assert.match(setCookie, new RegExp(`Max-Age=${SESSION_TTL_S}\\b`), "the renewed cookie carries a full TTL");
const claims = open(decodeURIComponent(m![1] ?? ""), sessionKey) as { sub: string; exp: number } | null;
assert.equal(claims?.sub, "U1", "the renewed cookie is valid and preserves the sub");
- assert.ok((claims?.exp ?? 0) > Math.floor(Date.now() / 1000) + 28000, "exp is pushed out to ~now + full TTL");
+ assert.ok(
+ (claims?.exp ?? 0) > Math.floor(Date.now() / 1000) + SESSION_TTL_S - 800,
+ "exp is pushed out to ~now + full TTL",
+ );
});
test("admin-status probe is memoized within the TTL (one round-trip per sub)", async () => {