authenik8-core 1.0.38 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +105 -0
- package/README.md +48 -236
- package/THREAT_MODEL.md +162 -0
- package/dist/agent/agentIdentity.d.ts +68 -0
- package/dist/agent/agentIdentity.d.ts.map +1 -0
- package/dist/agent/agentIdentity.js +435 -0
- package/dist/agent/agentIdentity.js.map +1 -0
- package/dist/agent/types.d.ts +83 -0
- package/dist/agent/types.d.ts.map +1 -0
- package/dist/{oauth/brain → agent}/types.js.map +1 -1
- package/dist/audit/auditDispatcher.d.ts +13 -0
- package/dist/audit/auditDispatcher.d.ts.map +1 -0
- package/dist/audit/auditDispatcher.js +212 -0
- package/dist/audit/auditDispatcher.js.map +1 -0
- package/dist/audit/types.d.ts +40 -0
- package/dist/audit/types.d.ts.map +1 -0
- package/dist/{oauth/identity → audit}/types.js.map +1 -1
- package/dist/auth/guestModeService.d.ts +6 -4
- package/dist/auth/guestModeService.d.ts.map +1 -1
- package/dist/auth/guestModeService.js +27 -20
- package/dist/auth/guestModeService.js.map +1 -1
- package/dist/auth/jwk.d.ts +49 -0
- package/dist/auth/jwk.d.ts.map +1 -0
- package/dist/auth/jwk.js +319 -0
- package/dist/auth/jwk.js.map +1 -0
- package/dist/auth/jwtAuth.d.ts +60 -16
- package/dist/auth/jwtAuth.d.ts.map +1 -1
- package/dist/auth/jwtAuth.js +273 -59
- package/dist/auth/jwtAuth.js.map +1 -1
- package/dist/auth/refreshService.d.ts +40 -15
- package/dist/auth/refreshService.d.ts.map +1 -1
- package/dist/auth/refreshService.js +288 -51
- package/dist/auth/refreshService.js.map +1 -1
- package/dist/auth/requestIdentity.d.ts +4 -0
- package/dist/auth/requestIdentity.d.ts.map +1 -0
- package/dist/auth/requestIdentity.js +16 -0
- package/dist/auth/requestIdentity.js.map +1 -0
- package/dist/auth/sessionStore.d.ts +35 -0
- package/dist/auth/sessionStore.d.ts.map +1 -0
- package/dist/auth/sessionStore.js +174 -0
- package/dist/auth/sessionStore.js.map +1 -0
- package/dist/auth/tokenFingerprint.d.ts +3 -0
- package/dist/auth/tokenFingerprint.d.ts.map +1 -0
- package/dist/auth/tokenFingerprint.js +13 -0
- package/dist/auth/tokenFingerprint.js.map +1 -0
- package/dist/authorization/authorizationService.d.ts +22 -0
- package/dist/authorization/authorizationService.d.ts.map +1 -0
- package/dist/authorization/authorizationService.js +132 -0
- package/dist/authorization/authorizationService.js.map +1 -0
- package/dist/authorization/types.d.ts +10 -0
- package/dist/authorization/types.d.ts.map +1 -0
- package/dist/{types/admin.js → authorization/types.js} +1 -1
- package/dist/authorization/types.js.map +1 -0
- package/dist/createAuthenik8.d.ts.map +1 -1
- package/dist/createAuthenik8.js +144 -65
- package/dist/createAuthenik8.js.map +1 -1
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/dist/middleware/adminService.d.ts +10 -3
- package/dist/middleware/adminService.d.ts.map +1 -1
- package/dist/middleware/adminService.js +25 -44
- package/dist/middleware/adminService.js.map +1 -1
- package/dist/oauth/adapters/memoryAdapter.d.ts +4 -19
- package/dist/oauth/adapters/memoryAdapter.d.ts.map +1 -1
- package/dist/oauth/adapters/memoryAdapter.js +47 -17
- package/dist/oauth/adapters/memoryAdapter.js.map +1 -1
- package/dist/oauth/adapters/redisAdapter.d.ts +2 -21
- package/dist/oauth/adapters/redisAdapter.d.ts.map +1 -1
- package/dist/oauth/adapters/redisAdapter.js +163 -84
- package/dist/oauth/adapters/redisAdapter.js.map +1 -1
- package/dist/oauth/brain/identityEngine.d.ts +13 -14
- package/dist/oauth/brain/identityEngine.d.ts.map +1 -1
- package/dist/oauth/brain/identityEngine.js +160 -74
- package/dist/oauth/brain/identityEngine.js.map +1 -1
- package/dist/oauth/brain/identityPolicy.d.ts +7 -4
- package/dist/oauth/brain/identityPolicy.d.ts.map +1 -1
- package/dist/oauth/brain/identityPolicy.js +15 -2
- package/dist/oauth/brain/identityPolicy.js.map +1 -1
- package/dist/oauth/callback.d.ts +3 -0
- package/dist/oauth/callback.d.ts.map +1 -0
- package/dist/oauth/callback.js +21 -0
- package/dist/oauth/callback.js.map +1 -0
- package/dist/oauth/core.d.ts +19 -17
- package/dist/oauth/core.d.ts.map +1 -1
- package/dist/oauth/core.js +73 -2
- package/dist/oauth/core.js.map +1 -1
- package/dist/oauth/identityValidation.d.ts +14 -0
- package/dist/oauth/identityValidation.d.ts.map +1 -0
- package/dist/oauth/identityValidation.js +90 -0
- package/dist/oauth/identityValidation.js.map +1 -0
- package/dist/oauth/providerSecurity.d.ts +13 -0
- package/dist/oauth/providerSecurity.d.ts.map +1 -0
- package/dist/oauth/providerSecurity.js +100 -0
- package/dist/oauth/providerSecurity.js.map +1 -0
- package/dist/oauth/providers/github.d.ts +5 -10
- package/dist/oauth/providers/github.d.ts.map +1 -1
- package/dist/oauth/providers/github.js +147 -64
- package/dist/oauth/providers/github.js.map +1 -1
- package/dist/oauth/providers/google.d.ts +6 -10
- package/dist/oauth/providers/google.d.ts.map +1 -1
- package/dist/oauth/providers/google.js +133 -71
- package/dist/oauth/providers/google.js.map +1 -1
- package/dist/oauth/state.d.ts +9 -0
- package/dist/oauth/state.d.ts.map +1 -0
- package/dist/oauth/state.js +55 -0
- package/dist/oauth/state.js.map +1 -0
- package/dist/oauth/types.d.ts +122 -1
- package/dist/oauth/types.d.ts.map +1 -1
- package/dist/redis/keyNamespace.d.ts +4 -0
- package/dist/redis/keyNamespace.d.ts.map +1 -0
- package/dist/redis/keyNamespace.js +34 -0
- package/dist/redis/keyNamespace.js.map +1 -0
- package/dist/redis/redisService.d.ts +2 -1
- package/dist/redis/redisService.d.ts.map +1 -1
- package/dist/redis/redisService.js +62 -34
- package/dist/redis/redisService.js.map +1 -1
- package/dist/risk/redisSessionRiskStore.d.ts +13 -0
- package/dist/risk/redisSessionRiskStore.d.ts.map +1 -0
- package/dist/risk/redisSessionRiskStore.js +29 -0
- package/dist/risk/redisSessionRiskStore.js.map +1 -0
- package/dist/risk/sessionRiskService.d.ts +31 -0
- package/dist/risk/sessionRiskService.d.ts.map +1 -0
- package/dist/risk/sessionRiskService.js +311 -0
- package/dist/risk/sessionRiskService.js.map +1 -0
- package/dist/risk/types.d.ts +50 -0
- package/dist/risk/types.d.ts.map +1 -0
- package/dist/{types/storage.js → risk/types.js} +1 -1
- package/dist/risk/types.js.map +1 -0
- package/dist/security/ipService.d.ts +27 -17
- package/dist/security/ipService.d.ts.map +1 -1
- package/dist/security/ipService.js +238 -85
- package/dist/security/ipService.js.map +1 -1
- package/dist/security/limiter.d.ts +15 -11
- package/dist/security/limiter.d.ts.map +1 -1
- package/dist/security/limiter.js +100 -60
- package/dist/security/limiter.js.map +1 -1
- package/dist/security/requestContext.d.ts +15 -0
- package/dist/security/requestContext.d.ts.map +1 -0
- package/dist/security/requestContext.js +156 -0
- package/dist/security/requestContext.js.map +1 -0
- package/dist/storage/RedisTokenStore.d.ts +8 -7
- package/dist/storage/RedisTokenStore.d.ts.map +1 -1
- package/dist/storage/RedisTokenStore.js +39 -32
- package/dist/storage/RedisTokenStore.js.map +1 -1
- package/dist/types/config.d.ts +50 -6
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/public.d.ts +51 -28
- package/dist/types/public.d.ts.map +1 -1
- package/dist/types/tokens.d.ts +8 -1
- package/dist/types/tokens.d.ts.map +1 -1
- package/dist/utility/safeString.d.ts +2 -0
- package/dist/utility/safeString.d.ts.map +1 -0
- package/dist/utility/safeString.js +13 -0
- package/dist/utility/safeString.js.map +1 -0
- package/docs/agent-service-identity.md +69 -0
- package/docs/api-overview.md +56 -0
- package/docs/architecture.md +41 -0
- package/docs/authorization-tenants-audit.md +53 -0
- package/docs/final-thought.md +9 -0
- package/docs/getting-started.md +57 -0
- package/docs/how-it-works-internally.md +15 -0
- package/docs/key-rotation.md +13 -0
- package/docs/refresh-token-rotation.md +15 -0
- package/docs/replay-attack-detection.md +16 -0
- package/docs/replay-attack-prevention.md +15 -0
- package/docs/repository-setup.md +13 -0
- package/docs/requirements.md +31 -0
- package/docs/secure-refresh-flow.md +21 -0
- package/docs/security-audit.md +133 -0
- package/docs/security-layer.md +54 -0
- package/docs/session-risk-quarantine.md +36 -0
- package/docs/stateful-session-control.md +16 -0
- package/docs/testing.md +37 -0
- package/docs/threats-addressed.md +25 -0
- package/docs/use-cases.md +12 -0
- package/docs/what-authenik8-does.md +17 -0
- package/docs/why-authenik8.md +15 -0
- package/docs/why-stateful-matters.md +11 -0
- package/package.json +27 -9
- package/dist/oauth/brain/identityResolver.d.ts +0 -7
- package/dist/oauth/brain/identityResolver.d.ts.map +0 -1
- package/dist/oauth/brain/identityResolver.js +0 -32
- package/dist/oauth/brain/identityResolver.js.map +0 -1
- package/dist/oauth/brain/types.d.ts +0 -9
- package/dist/oauth/brain/types.d.ts.map +0 -1
- package/dist/oauth/identity/types.d.ts +0 -37
- package/dist/oauth/identity/types.d.ts.map +0 -1
- package/dist/oauth/types/identity.d.ts +0 -16
- package/dist/oauth/types/identity.d.ts.map +0 -1
- package/dist/oauth/types/identity.js +0 -3
- package/dist/oauth/types/identity.js.map +0 -1
- package/dist/oauth/userStore.d.ts +0 -20
- package/dist/oauth/userStore.d.ts.map +0 -1
- package/dist/oauth/userStore.js +0 -46
- package/dist/oauth/userStore.js.map +0 -1
- package/dist/storage/userStorage.d.ts +0 -7
- package/dist/storage/userStorage.d.ts.map +0 -1
- package/dist/storage/userStorage.js +0 -17
- package/dist/storage/userStorage.js.map +0 -1
- package/dist/tests/con.test.d.ts +0 -2
- package/dist/tests/con.test.d.ts.map +0 -1
- package/dist/tests/con.test.js +0 -71
- package/dist/tests/con.test.js.map +0 -1
- package/dist/tests/full.intergration.test.d.ts +0 -2
- package/dist/tests/full.intergration.test.d.ts.map +0 -1
- package/dist/tests/full.intergration.test.js +0 -79
- package/dist/tests/full.intergration.test.js.map +0 -1
- package/dist/tests/oauth.intergration.test.d.ts +0 -2
- package/dist/tests/oauth.intergration.test.d.ts.map +0 -1
- package/dist/tests/oauth.intergration.test.js +0 -38
- package/dist/tests/oauth.intergration.test.js.map +0 -1
- package/dist/tests/oauth1.test.d.ts +0 -9
- package/dist/tests/oauth1.test.d.ts.map +0 -1
- package/dist/tests/oauth1.test.js +0 -126
- package/dist/tests/oauth1.test.js.map +0 -1
- package/dist/tests/oauth2.test.d.ts +0 -2
- package/dist/tests/oauth2.test.d.ts.map +0 -1
- package/dist/tests/oauth2.test.js +0 -145
- package/dist/tests/oauth2.test.js.map +0 -1
- package/dist/tests/oauth3.test.d.ts +0 -2
- package/dist/tests/oauth3.test.d.ts.map +0 -1
- package/dist/tests/oauth3.test.js +0 -148
- package/dist/tests/oauth3.test.js.map +0 -1
- package/dist/tests/testApp.d.ts +0 -7
- package/dist/tests/testApp.d.ts.map +0 -1
- package/dist/tests/testApp.js +0 -53
- package/dist/tests/testApp.js.map +0 -1
- package/dist/types/admin.d.ts +0 -5
- package/dist/types/admin.d.ts.map +0 -1
- package/dist/types/admin.js.map +0 -1
- package/dist/types/storage.d.ts +0 -14
- package/dist/types/storage.d.ts.map +0 -1
- package/dist/types/storage.js.map +0 -1
- /package/dist/{oauth/brain → agent}/types.js +0 -0
- /package/dist/{oauth/identity → audit}/types.js +0 -0
package/dist/types/config.d.ts
CHANGED
|
@@ -1,14 +1,58 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
1
|
+
import type { Redis } from "ioredis";
|
|
2
|
+
import type { HelmetOptions } from "helmet";
|
|
3
|
+
import type { AgentIdentityConfig } from "../agent/types";
|
|
4
|
+
import type { AuditConfig } from "../audit/types";
|
|
5
|
+
import type { Authenik8JwkConfig } from "../auth/jwk";
|
|
6
|
+
import type { AuthorizationConfig } from "../authorization/types";
|
|
7
|
+
import type { IdentityPolicyConfig } from "../oauth/brain/identityPolicy";
|
|
8
|
+
import type { OAuthConfig, OAuthIdentityAdapter } from "../oauth/types";
|
|
9
|
+
import type { SessionRiskConfig } from "../risk/types";
|
|
10
|
+
export interface Authenik8SecurityConfig {
|
|
11
|
+
rateLimitPoints?: number;
|
|
12
|
+
rateLimitDuration?: number;
|
|
13
|
+
rateLimitBlock?: number;
|
|
14
|
+
rateLimiterEnabled?: boolean;
|
|
15
|
+
whiteListEnabled?: boolean;
|
|
16
|
+
helmetEnabled?: boolean;
|
|
17
|
+
/** Replaces the SDK's enforcing Helmet defaults when supplied. */
|
|
18
|
+
helmetOptions?: HelmetOptions;
|
|
19
|
+
}
|
|
5
20
|
export interface Authenik8Config {
|
|
6
|
-
|
|
7
|
-
|
|
21
|
+
/** @deprecated Configure `jwt` with ES256 JWKs for public-key verification. */
|
|
22
|
+
jwtSecret?: string;
|
|
23
|
+
jwt?: Authenik8JwkConfig;
|
|
24
|
+
jwtExpiry?: string | number;
|
|
8
25
|
refreshSecret: string;
|
|
9
26
|
oauth?: OAuthConfig;
|
|
10
27
|
redis?: Redis;
|
|
28
|
+
/**
|
|
29
|
+
* Isolates all SDK-owned Redis keys. When omitted, a stable prefix is derived
|
|
30
|
+
* from the configured JWT issuer and audience.
|
|
31
|
+
*/
|
|
32
|
+
redisKeyPrefix?: string;
|
|
11
33
|
identityAdapter?: OAuthIdentityAdapter;
|
|
34
|
+
/** OAuth email-link policy. Both automatic modes are disabled by default. */
|
|
35
|
+
oauthIdentityPolicy?: IdentityPolicyConfig;
|
|
36
|
+
/** Enables fail-closed agent/service identity issuance and middleware. */
|
|
37
|
+
agent?: AgentIdentityConfig;
|
|
38
|
+
/** Structured security events are delivered to application-owned sinks. */
|
|
39
|
+
audit?: AuditConfig;
|
|
40
|
+
/** Human role, permission, scope, and tenant authorization policy. */
|
|
41
|
+
authorization?: AuthorizationConfig;
|
|
42
|
+
/** Stateful anomaly detection and automatic session quarantine policy. */
|
|
43
|
+
risk?: SessionRiskConfig;
|
|
44
|
+
/** HTTP rate-limit, IP allowlist, and Helmet policy. */
|
|
45
|
+
security?: Authenik8SecurityConfig;
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated Use `trustedProxyCidrs`. A blanket proxy trust boolean is not
|
|
48
|
+
* sufficient to authenticate the sender of forwarding headers.
|
|
49
|
+
*/
|
|
12
50
|
trustProxyHeaders?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Networks containing reverse proxies that are authorized to set
|
|
53
|
+
* `X-Forwarded-For`. The socket peer and every trusted hop are verified.
|
|
54
|
+
*/
|
|
55
|
+
trustedProxyCidrs?: readonly string[];
|
|
56
|
+
allowCookieAuth?: boolean;
|
|
13
57
|
}
|
|
14
58
|
//# sourceMappingURL=config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,KAAK,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD,MAAM,WAAW,uBAAuB;IACtC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,kEAAkE;IAClE,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B;AAED,MAAM,WAAW,eAAe;IAC9B,+EAA+E;IAC/E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,kBAAkB,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,oBAAoB,CAAC;IACvC,6EAA6E;IAC7E,mBAAmB,CAAC,EAAE,oBAAoB,CAAC;IAC3C,0EAA0E;IAC1E,KAAK,CAAC,EAAE,mBAAmB,CAAC;IAC5B,2EAA2E;IAC3E,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,sEAAsE;IACtE,aAAa,CAAC,EAAE,mBAAmB,CAAC;IACpC,0EAA0E;IAC1E,IAAI,CAAC,EAAE,iBAAiB,CAAC;IACzB,wDAAwD;IACxD,QAAQ,CAAC,EAAE,uBAAuB,CAAC;IACnC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B"}
|
package/dist/types/public.d.ts
CHANGED
|
@@ -1,42 +1,65 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { Request, RequestHandler, Response } from "express";
|
|
2
|
+
import type { JSONWebKeySet } from "jose" with { "resolution-mode": "import" };
|
|
3
|
+
import type { Redis } from "ioredis";
|
|
4
|
+
import type { JwtPayload } from "../auth/jwtAuth";
|
|
5
|
+
import type { RefreshResult } from "../auth/refreshService";
|
|
6
|
+
import type { SessionMetadata } from "../auth/sessionStore";
|
|
7
|
+
import type { AgentIdentityApi } from "../agent/types";
|
|
8
|
+
import type { AuditEmitter } from "../audit/types";
|
|
9
|
+
import type { TenantResolver } from "../authorization/types";
|
|
10
|
+
import type { OAuthCallbackResult } from "../oauth/types";
|
|
11
|
+
import type { SessionObservation, SessionRiskReporter } from "../risk/types";
|
|
12
|
+
import type { TokenPayload, TokenPair } from "./tokens";
|
|
3
13
|
type GitHubProvider = {
|
|
4
|
-
redirect: (req:
|
|
5
|
-
handleCallback: (req:
|
|
6
|
-
profile: OAuthProfile;
|
|
7
|
-
mode: "login" | "link";
|
|
8
|
-
userId: string | null;
|
|
9
|
-
}>;
|
|
14
|
+
redirect: (req: Request, res: Response, mode?: "login" | "link") => Promise<void>;
|
|
15
|
+
handleCallback: (req: Request) => Promise<OAuthCallbackResult>;
|
|
10
16
|
};
|
|
11
17
|
type GoogleProvider = {
|
|
12
|
-
redirect: (req:
|
|
13
|
-
handleCallback: (req:
|
|
14
|
-
profile: OAuthProfile;
|
|
15
|
-
mode: "login" | "link";
|
|
16
|
-
userId: string | null;
|
|
17
|
-
}>;
|
|
18
|
+
redirect: (req: Request, res: Response, mode?: "login" | "link") => Promise<void>;
|
|
19
|
+
handleCallback: (req: Request) => Promise<OAuthCallbackResult>;
|
|
18
20
|
};
|
|
19
21
|
export interface Authenik8Instance {
|
|
20
|
-
signToken: (payload:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
signToken: (payload: Record<string, unknown> & {
|
|
23
|
+
userId?: string;
|
|
24
|
+
sessionId?: string;
|
|
25
|
+
}, observation?: SessionObservation) => Promise<string>;
|
|
26
|
+
verifyToken: (token: string) => Promise<JwtPayload | null>;
|
|
27
|
+
/** Verifies signature, expiry, current Redis session, and quarantine state. */
|
|
28
|
+
verifyActiveToken: (token: string) => Promise<JwtPayload | null>;
|
|
29
|
+
requireAuth: RequestHandler;
|
|
30
|
+
guestToken: () => Promise<string>;
|
|
31
|
+
getJwks: () => JSONWebKeySet;
|
|
32
|
+
listSessions: (userId: string) => Promise<SessionMetadata[]>;
|
|
33
|
+
revokeSession: (userId: string, sessionId: string) => Promise<void>;
|
|
34
|
+
revokeAllSessions: (userId: string) => Promise<void>;
|
|
35
|
+
agent?: AgentIdentityApi;
|
|
36
|
+
audit: AuditEmitter;
|
|
37
|
+
risk: SessionRiskReporter;
|
|
38
|
+
refreshToken: (token: string) => Promise<RefreshResult>;
|
|
39
|
+
generateRefreshToken: (payload: {
|
|
40
|
+
userId: string;
|
|
41
|
+
email: string;
|
|
42
|
+
sessionId?: string;
|
|
43
|
+
}) => Promise<string>;
|
|
44
|
+
rateLimit: RequestHandler;
|
|
45
|
+
ipWhitelist: RequestHandler;
|
|
46
|
+
helmet: RequestHandler;
|
|
47
|
+
addIP: (ip: string, ttlSeconds?: number) => Promise<void>;
|
|
29
48
|
removeIP: (ip: string) => Promise<void>;
|
|
30
49
|
listIPs: () => Promise<string[]>;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
50
|
+
/** @deprecated Prefer requireRole("admin"), which composes with tenant policy. */
|
|
51
|
+
requireAdmin: RequestHandler;
|
|
52
|
+
requireRole: (...roles: string[]) => RequestHandler;
|
|
53
|
+
requirePermission: (...permissions: string[]) => RequestHandler;
|
|
54
|
+
requireScope: (...scopes: string[]) => RequestHandler;
|
|
55
|
+
requireTenant: (resolveTenant?: TenantResolver) => RequestHandler;
|
|
56
|
+
incognito: RequestHandler;
|
|
57
|
+
redisclient?: Redis;
|
|
34
58
|
oauth?: {
|
|
35
59
|
google?: GoogleProvider;
|
|
36
60
|
github?: GitHubProvider;
|
|
37
61
|
};
|
|
38
|
-
issueTokens: (payload: TokenPayload) => Promise<TokenPair>;
|
|
39
|
-
issueTokensFromProfile: (profile: OAuthProfile) => Promise<TokenPair>;
|
|
62
|
+
issueTokens: (payload: TokenPayload, observation?: SessionObservation) => Promise<TokenPair>;
|
|
40
63
|
}
|
|
41
64
|
export {};
|
|
42
65
|
//# sourceMappingURL=public.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../src/types/public.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../src/types/public.ts"],"names":[],"mappings":"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"}
|
package/dist/types/tokens.d.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
export type TokenPayload = {
|
|
2
2
|
email: string;
|
|
3
3
|
role?: string;
|
|
4
|
+
roles?: string[];
|
|
5
|
+
permissions?: string[];
|
|
6
|
+
scopes?: string[];
|
|
7
|
+
scope?: string;
|
|
8
|
+
tenantId?: string;
|
|
9
|
+
tenantIds?: string[];
|
|
4
10
|
userId: string;
|
|
11
|
+
sessionId?: string;
|
|
5
12
|
};
|
|
6
13
|
export type TokenPair = {
|
|
7
|
-
accessToken:
|
|
14
|
+
accessToken: string;
|
|
8
15
|
refreshToken: string;
|
|
9
16
|
};
|
|
10
17
|
//# sourceMappingURL=tokens.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../src/types/tokens.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../src/types/tokens.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAA;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safeString.d.ts","sourceRoot":"","sources":["../../src/utility/safeString.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,GAAI,OAAO,MAAM,KAAG,OAMxD,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.containsControlCharacter = void 0;
|
|
4
|
+
const containsControlCharacter = (value) => {
|
|
5
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
6
|
+
const code = value.charCodeAt(index);
|
|
7
|
+
if (code <= 0x1f || code === 0x7f)
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
return false;
|
|
11
|
+
};
|
|
12
|
+
exports.containsControlCharacter = containsControlCharacter;
|
|
13
|
+
//# sourceMappingURL=safeString.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safeString.js","sourceRoot":"","sources":["../../src/utility/safeString.ts"],"names":[],"mappings":";;;AAAO,MAAM,wBAAwB,GAAG,CAAC,KAAa,EAAW,EAAE;IACjE,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACrD,MAAM,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QACrC,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC;IACjD,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AANW,QAAA,wBAAwB,4BAMnC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Agent and Service Identity
|
|
2
|
+
|
|
3
|
+
Agent identity is optional and fails closed. The application supplies the
|
|
4
|
+
source of truth for registered agents and their maximum scopes:
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
const auth = await createAuthenik8({
|
|
8
|
+
jwt,
|
|
9
|
+
refreshSecret,
|
|
10
|
+
redis,
|
|
11
|
+
agent: {
|
|
12
|
+
resolveAgent: async (agentId) => agentRepository.findActive(agentId),
|
|
13
|
+
authorizeDelegation: async ({ user, agent, requestedScopes }) =>
|
|
14
|
+
user.role === "admin" &&
|
|
15
|
+
agent.agentId === "build-worker" &&
|
|
16
|
+
requestedScopes.every((scope) => scope === "tasks:read"),
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Mint M2M tokens only after a trusted workload-authentication exchange such as
|
|
22
|
+
mTLS, cloud workload identity, or a signed client assertion:
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
const machine = await auth.agent!.issueToken({
|
|
26
|
+
agentId: "build-worker",
|
|
27
|
+
scopes: ["tasks:read"],
|
|
28
|
+
label: "production queue worker",
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
app.post(
|
|
32
|
+
"/internal/tasks",
|
|
33
|
+
auth.agent!.requireScopes("tasks:write"),
|
|
34
|
+
handler,
|
|
35
|
+
);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
`issueToken()` is a privileged SDK primitive and must not be exposed as an
|
|
39
|
+
unauthenticated HTTP endpoint. Agent tokens use a distinct `tokenUse`, carry an
|
|
40
|
+
exact scope set and `actorChain`, and are stored under
|
|
41
|
+
`agent-sessions:<agentId>`. Human middleware rejects agent tokens.
|
|
42
|
+
|
|
43
|
+
Delegated tokens require an active human access-token session and an explicit
|
|
44
|
+
`authorizeDelegation` decision:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
const delegated = await auth.agent!.issueDelegatedToken({
|
|
48
|
+
agentId: "build-worker",
|
|
49
|
+
userAccessToken,
|
|
50
|
+
scopes: ["tasks:read"],
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
They identify the human subject and agent actor through `sub`, `act`, and
|
|
55
|
+
`actorChain` claims. Revoking the originating human session invalidates the
|
|
56
|
+
delegation. Removing an agent or scope from `resolveAgent` invalidates existing
|
|
57
|
+
tokens during verification.
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
await auth.agent!.revokeSession(agentId, sessionId);
|
|
61
|
+
await auth.agent!.revokeAgent(agentId);
|
|
62
|
+
await auth.agent!.activateAgent(agentId);
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Public JWKS verification establishes signature validity but cannot observe
|
|
66
|
+
Redis session revocation. Security-sensitive agent routes should use the
|
|
67
|
+
session-aware SDK middleware or a trusted introspection boundary.
|
|
68
|
+
|
|
69
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# API Overview
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
const auth = await createAuthenik8(config);
|
|
5
|
+
|
|
6
|
+
// Access tokens and keys
|
|
7
|
+
await auth.signToken(payload);
|
|
8
|
+
await auth.verifyToken(token);
|
|
9
|
+
await auth.verifyActiveToken(token);
|
|
10
|
+
auth.getJwks();
|
|
11
|
+
|
|
12
|
+
// Refresh tokens
|
|
13
|
+
await auth.refreshToken(refreshToken);
|
|
14
|
+
await auth.generateRefreshToken(payload);
|
|
15
|
+
|
|
16
|
+
// Redis-backed sessions
|
|
17
|
+
await auth.listSessions(userId);
|
|
18
|
+
await auth.revokeSession(userId, sessionId);
|
|
19
|
+
await auth.revokeAllSessions(userId);
|
|
20
|
+
|
|
21
|
+
// Optional agent identity
|
|
22
|
+
await auth.agent?.issueToken({ agentId, scopes });
|
|
23
|
+
await auth.agent?.issueDelegatedToken({
|
|
24
|
+
agentId,
|
|
25
|
+
userAccessToken,
|
|
26
|
+
scopes,
|
|
27
|
+
});
|
|
28
|
+
auth.agent?.requireAgent;
|
|
29
|
+
auth.agent?.requireScopes("tasks:write");
|
|
30
|
+
await auth.agent?.revokeAgent(agentId);
|
|
31
|
+
|
|
32
|
+
// Security
|
|
33
|
+
auth.rateLimit;
|
|
34
|
+
auth.ipWhitelist;
|
|
35
|
+
auth.helmet;
|
|
36
|
+
await auth.addIP("203.0.113.10", 3600);
|
|
37
|
+
await auth.removeIP("203.0.113.10");
|
|
38
|
+
await auth.listIPs();
|
|
39
|
+
|
|
40
|
+
// Human middleware
|
|
41
|
+
auth.requireAuth;
|
|
42
|
+
auth.requireAdmin;
|
|
43
|
+
auth.requireRole("admin", "support");
|
|
44
|
+
auth.requirePermission("users:read");
|
|
45
|
+
auth.requireScope("profile:read");
|
|
46
|
+
auth.requireTenant();
|
|
47
|
+
|
|
48
|
+
// Risk state
|
|
49
|
+
await auth.risk.getState(principal);
|
|
50
|
+
await auth.risk.release(principal);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`verifyToken()` is signature-only. Use `verifyActiveToken()` for state-aware
|
|
54
|
+
verification.
|
|
55
|
+
|
|
56
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Architecture
|
|
2
|
+
|
|
3
|
+
```text
|
|
4
|
+
┌─────────────────┐
|
|
5
|
+
│ Client │
|
|
6
|
+
│ Web / Mobile │
|
|
7
|
+
└────────┬────────┘
|
|
8
|
+
│
|
|
9
|
+
▼
|
|
10
|
+
┌─────────────────┐
|
|
11
|
+
│ API / Backend │
|
|
12
|
+
└────────┬────────┘
|
|
13
|
+
│
|
|
14
|
+
▼
|
|
15
|
+
┌────────────────────────────┐
|
|
16
|
+
│ Authenik8-core │
|
|
17
|
+
├────────────────────────────┤
|
|
18
|
+
│ JWT signing/verification │
|
|
19
|
+
│ Refresh rotation/replay │
|
|
20
|
+
│ Authorization/tenancy │
|
|
21
|
+
│ Audit and risk signals │
|
|
22
|
+
│ Agent identity │
|
|
23
|
+
│ Security middleware │
|
|
24
|
+
└─────────────┬──────────────┘
|
|
25
|
+
│
|
|
26
|
+
▼
|
|
27
|
+
┌────────────────────────────┐
|
|
28
|
+
│ Redis │
|
|
29
|
+
├────────────────────────────┤
|
|
30
|
+
│ Session fingerprints │
|
|
31
|
+
│ Refresh-family state │
|
|
32
|
+
│ Revocation/quarantine │
|
|
33
|
+
│ Rate and signal windows │
|
|
34
|
+
└────────────────────────────┘
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Audit sinks and identity registries are application-owned dependencies. The SDK
|
|
38
|
+
uses narrow interfaces for those dependencies so their storage and delivery
|
|
39
|
+
choices remain outside the authentication core.
|
|
40
|
+
|
|
41
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Authorization, Tenants, and Audit Events
|
|
2
|
+
|
|
3
|
+
Authorization middleware authenticates first, uses exact claim matching, and
|
|
4
|
+
fails closed when a configured tenant cannot be resolved or is not granted:
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
const auth = await createAuthenik8({
|
|
8
|
+
jwt,
|
|
9
|
+
refreshSecret,
|
|
10
|
+
redis,
|
|
11
|
+
authorization: {
|
|
12
|
+
resolveTenant: (req) => req.params.tenantId,
|
|
13
|
+
},
|
|
14
|
+
audit: {
|
|
15
|
+
delivery: "best-effort",
|
|
16
|
+
sinks: [
|
|
17
|
+
{
|
|
18
|
+
write: async (event) => securityEventRepository.append(event),
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
app.get(
|
|
25
|
+
"/tenants/:tenantId/invoices",
|
|
26
|
+
auth.requireRole("billing-admin", "owner"),
|
|
27
|
+
auth.requirePermission("invoice:read"),
|
|
28
|
+
handler,
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const tokens = await auth.issueTokens(
|
|
32
|
+
{
|
|
33
|
+
userId: "user_1",
|
|
34
|
+
email: "user@example.com",
|
|
35
|
+
roles: ["billing-admin"],
|
|
36
|
+
permissions: ["invoice:read"],
|
|
37
|
+
scopes: ["profile:read"],
|
|
38
|
+
tenantIds: ["tenant_1"],
|
|
39
|
+
},
|
|
40
|
+
{ ip: request.ip, device: request.headers["user-agent"] },
|
|
41
|
+
);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Roles use any-of matching. Required permissions and scopes use all-of matching.
|
|
45
|
+
Checks build a set of granted claims and then inspect each required claim,
|
|
46
|
+
avoiding pairwise comparisons.
|
|
47
|
+
|
|
48
|
+
The SDK owns the versioned audit-event envelope. Applications own durable
|
|
49
|
+
console, file, queue, SIEM, or webhook sinks. Best-effort delivery protects
|
|
50
|
+
authentication availability; strict delivery rolls back issuance when a sink
|
|
51
|
+
cannot accept the event.
|
|
52
|
+
|
|
53
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Final Thought
|
|
2
|
+
|
|
3
|
+
JWT alone establishes signed claims; it is not a complete authentication
|
|
4
|
+
system.
|
|
5
|
+
|
|
6
|
+
Authenik8-core adds token lifecycle, revocation, authorization, audit, and risk
|
|
7
|
+
controls around those claims.
|
|
8
|
+
|
|
9
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Getting Started
|
|
2
|
+
|
|
3
|
+
Generate and persist an ES256 private JWK once. Do not generate a new key every
|
|
4
|
+
time the process starts.
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
import {
|
|
8
|
+
createAuthenik8,
|
|
9
|
+
generateSigningJwk,
|
|
10
|
+
verifyAccessTokenWithJwks,
|
|
11
|
+
} from "authenik8-core";
|
|
12
|
+
|
|
13
|
+
const privateJwk = await generateSigningJwk("2026-07-primary");
|
|
14
|
+
// Store privateJwk in your secret manager before constructing the engine.
|
|
15
|
+
|
|
16
|
+
const auth = await createAuthenik8({
|
|
17
|
+
jwt: {
|
|
18
|
+
keys: [privateJwk],
|
|
19
|
+
activeKid: "2026-07-primary",
|
|
20
|
+
issuer: "https://api.example.com",
|
|
21
|
+
audience: "example-api",
|
|
22
|
+
},
|
|
23
|
+
refreshSecret: process.env.REFRESH_SECRET!,
|
|
24
|
+
redisKeyPrefix: "example-api:production",
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
app.get("/.well-known/jwks.json", (_req, res) => res.json(auth.getJwks()));
|
|
28
|
+
app.get("/protected", auth.requireAuth, (_req, res) => res.sendStatus(204));
|
|
29
|
+
|
|
30
|
+
const tokens = await auth.issueTokens({
|
|
31
|
+
userId: "user_1",
|
|
32
|
+
email: "test@example.com",
|
|
33
|
+
});
|
|
34
|
+
const payload = await auth.verifyToken(tokens.accessToken);
|
|
35
|
+
|
|
36
|
+
// A separate service can verify with public keys only (or pass a JWKS URL).
|
|
37
|
+
const publicPayload = await verifyAccessTokenWithJwks(
|
|
38
|
+
tokens.accessToken,
|
|
39
|
+
auth.getJwks(),
|
|
40
|
+
{ issuer: "https://api.example.com", audience: "example-api" },
|
|
41
|
+
);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`verifyToken()` verifies signature and claims only. Use
|
|
45
|
+
`verifyActiveToken()` or `requireAuth` whenever Redis revocation and
|
|
46
|
+
quarantine must be enforced.
|
|
47
|
+
|
|
48
|
+
`jwtSecret` remains available as a deprecated JOSE/HS256 migration path. It
|
|
49
|
+
does not provide a public JWKS and should not be used for new applications.
|
|
50
|
+
If it is temporarily required, both it and `refreshSecret` need at least 32
|
|
51
|
+
bytes of independent random material.
|
|
52
|
+
|
|
53
|
+
The host application must load its environment before construction (for
|
|
54
|
+
example with a runtime `--env-file` option or an application-owned dotenv
|
|
55
|
+
bootstrap). Importing Authenik8-core never changes `process.env`.
|
|
56
|
+
|
|
57
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# How It Works Internally
|
|
2
|
+
|
|
3
|
+
Authenik8-core combines signed JWT claims with Redis-backed lifecycle state.
|
|
4
|
+
Signature verification establishes token authenticity; state-aware verification
|
|
5
|
+
additionally enforces revocation, rotation, and quarantine.
|
|
6
|
+
|
|
7
|
+
Internal flows are documented separately:
|
|
8
|
+
|
|
9
|
+
- [Refresh-token rotation](./refresh-token-rotation.md)
|
|
10
|
+
- [Replay-attack detection](./replay-attack-detection.md)
|
|
11
|
+
- [Stateful session control](./stateful-session-control.md)
|
|
12
|
+
- [Security layer](./security-layer.md)
|
|
13
|
+
- [Why stateful authentication matters](./why-stateful-matters.md)
|
|
14
|
+
|
|
15
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Key Rotation
|
|
2
|
+
|
|
3
|
+
1. Generate and securely persist a new key with a unique `kid`.
|
|
4
|
+
2. Put the new private JWK and previous verification keys in `jwt.keys`.
|
|
5
|
+
3. Set `activeKid` to the new key. New tokens now carry the new `kid`.
|
|
6
|
+
4. Keep old public keys until every token they signed has expired, then remove
|
|
7
|
+
them.
|
|
8
|
+
|
|
9
|
+
`auth.getJwks()` strips private key material and returns every configured public
|
|
10
|
+
verification key. Verification enforces ES256, `kid`, issuer, audience, expiry,
|
|
11
|
+
and token purpose.
|
|
12
|
+
|
|
13
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Refresh-Token Rotation
|
|
2
|
+
|
|
3
|
+
Each refresh token includes a unique identifier (`jti`). Redis stores a SHA-256
|
|
4
|
+
fingerprint of the current token for its refresh family.
|
|
5
|
+
|
|
6
|
+
During refresh:
|
|
7
|
+
|
|
8
|
+
1. The token signature, purpose, issuer, audience, and expiry are validated.
|
|
9
|
+
2. The supplied token fingerprint is compared with the current family record.
|
|
10
|
+
3. A Redis lock and compare-and-set transition allow only one rotation.
|
|
11
|
+
4. The old token is invalidated and a new token is issued with a new `jti`.
|
|
12
|
+
5. If a dependent security operation fails, the affected family is rolled back
|
|
13
|
+
or revoked rather than leaving partially issued credentials.
|
|
14
|
+
|
|
15
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Replay-Attack Detection
|
|
2
|
+
|
|
3
|
+
When a previously rotated refresh token is reused, its fingerprint no longer
|
|
4
|
+
matches the current family record.
|
|
5
|
+
|
|
6
|
+
The SDK then:
|
|
7
|
+
|
|
8
|
+
1. Rejects the request.
|
|
9
|
+
2. Revokes the affected refresh family.
|
|
10
|
+
3. Reports a replay-risk signal.
|
|
11
|
+
4. Quarantines the affected session.
|
|
12
|
+
5. Emits a structured audit event.
|
|
13
|
+
|
|
14
|
+
This blocks both token replay and concurrent attempts to rotate the same family.
|
|
15
|
+
|
|
16
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Example: Replay Attack Prevention
|
|
2
|
+
|
|
3
|
+
The first refresh succeeds and rotates the token. Reusing the previous token is
|
|
4
|
+
rejected:
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
await auth.refreshToken(token);
|
|
8
|
+
await auth.refreshToken(token); // Throws.
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Replay detection also revokes and quarantines the affected refresh family.
|
|
12
|
+
|
|
13
|
+
[Learn how replay detection works](./replay-attack-detection.md)
|
|
14
|
+
|
|
15
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Repository Setup
|
|
2
|
+
|
|
3
|
+
To connect an existing local repository to the upstream GitLab project:
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
git remote add origin https://gitlab.com/COD434/authenik8-core.git
|
|
7
|
+
git branch -M main
|
|
8
|
+
git push -uf origin main
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Verify the target remote and branch before pushing.
|
|
12
|
+
|
|
13
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Requirements
|
|
2
|
+
|
|
3
|
+
Authenik8-core uses stateful JWT authentication. A Redis-compatible store is
|
|
4
|
+
therefore required for session tracking, refresh rotation, revocation, and
|
|
5
|
+
quarantine.
|
|
6
|
+
|
|
7
|
+
Stateful verification provides stronger control than signature-only JWT
|
|
8
|
+
verification, but Redis becomes security-critical infrastructure. Deploy it
|
|
9
|
+
with authentication, encryption, restricted network access, persistence, and
|
|
10
|
+
monitoring appropriate to the application.
|
|
11
|
+
|
|
12
|
+
Cryptographic and configuration requirements:
|
|
13
|
+
|
|
14
|
+
- Prefer ES256 JWKs stored in a secret manager or HSM-backed key service.
|
|
15
|
+
- The refresh HMAC secret must contain 32-4096 bytes of cryptographically random
|
|
16
|
+
material and must be independent of the deprecated access HMAC secret.
|
|
17
|
+
- Access-token lifetime is 60 seconds to 24 hours; refresh lifetime is 60
|
|
18
|
+
seconds to 31 days; agent-token lifetime is 60 seconds to one hour.
|
|
19
|
+
- Keep issuer and audience stable. They also form the default Redis isolation
|
|
20
|
+
domain. Set `redisKeyPrefix` explicitly when multiple deployments share Redis
|
|
21
|
+
or when planning a key migration.
|
|
22
|
+
- Load environment variables in the host process before importing or
|
|
23
|
+
constructing the SDK. Authenik8-core does not invoke dotenv.
|
|
24
|
+
- Configure `trustedProxyCidrs` only for networks under your control.
|
|
25
|
+
|
|
26
|
+
CI uses `ioredis-mock` by design and does not start a Redis service. A
|
|
27
|
+
production readiness process must still test
|
|
28
|
+
the selected real Redis version and topology outside CI, including Lua support,
|
|
29
|
+
cluster hash-slot behavior, failover, persistence, latency, and recovery.
|
|
30
|
+
|
|
31
|
+
[Back to the documentation index](../README.md#documentation)
|