Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

init

DimitrisStaratzis5c60f463e8c7
diff --git a/backend/AGENTS.md b/backend/AGENTS.md
index 7065fcb5e7..b028fb7e9c 100644
--- a/backend/AGENTS.md
+++ b/backend/AGENTS.md
@@ -1146,6 +1146,23 @@ the same transaction. Keys are released on CA delete, on project hard delete, an
fails after its key was made. AWS KMS schedules deletion with a 30-day window; HSM keeps its key. A
failure is logged, never thrown, so the original outcome stands.
+### OIDC issuer (outbound workload identity federation)
+
+`services/oidc-issuer` signs short-lived JWTs that cloud providers exchange for access tokens, so a
+connection needs no stored client secret. Each org is its own issuer at
+`/api/v1/oidc-issuer/orgs/<orgId>`, with public discovery and JWKS routes under `.well-known`. The issuer
+URL and the `sub` shape are one-way doors: customers copy both into their provider.
+
+- **Keys are reserved `sign-verify` `kms_keys` rows named `oidc-issuer-*`, not a new `keyUsage`.** The
+ CMEK router validates `keyUsage` with `z.nativeEnum(KmsKeyUsage)`, so a new value would be creatable
+ through the public API. Customers cannot create reserved keys, which is what makes the name prefix safe.
+- **Keys are created on the first sign, never on a JWKS fetch.** Those routes are unauthenticated, and
+ existing orgs need no backfill. An empty JWKS is sent `no-store` so the first token is never checked
+ against a cached empty set.
+- **The second newest key signs.** The newest is published a full 24h period before it takes over, and
+ rotation keeps at most three keys. It runs under a Redis lock rather than an advisory lock, so no
+ database connection is held while RSA keys are generated, and it re-reads keys on the primary.
+
### Enterprise (EE) Features
Enterprise code lives in `src/ee/`:
diff --git a/backend/src/@types/fastify.d.ts b/backend/src/@types/fastify.d.ts
index 51a4c4e59b..0e5d7b490b 100644
--- a/backend/src/@types/fastify.d.ts
+++ b/backend/src/@types/fastify.d.ts
@@ -152,6 +152,7 @@ import { TMicrosoftTeamsServiceFactory } from "@app/services/microsoft-teams/mic
import { TNotificationServiceFactory } from "@app/services/notification/notification-service";
import { TOauthClientServiceFactory } from "@app/services/oauth-client/oauth-client-service";
import { TOfflineUsageReportServiceFactory } from "@app/services/offline-usage-report/offline-usage-report-service";
+import { TOidcIssuerServiceFactory } from "@app/services/oidc-issuer/oidc-issuer-service";
import { TOrgServiceFactory } from "@app/services/org/org-service";
import { TOrgAdminServiceFactory } from "@app/services/org-admin/org-admin-service";
import { TOrgProductStatsServiceFactory } from "@app/services/org-product-stats/org-product-stats-service";
@@ -311,6 +312,7 @@ declare module "fastify" {
signup: TAuthSignupFactory;
authToken: TAuthTokenServiceFactory;
oauthClient: TOauthClientServiceFactory;
+ oidcIssuer: TOidcIssuerServiceFactory;
permission: TPermissionServiceFactory;
org: TOrgServiceFactory;
oidc: TOidcConfigServiceFactory;
diff --git a/backend/src/keystore/keystore.ts b/backend/src/keystore/keystore.ts
index fbe25ecb29..a7d04f3c29 100644
--- a/backend/src/keystore/keystore.ts
+++ b/backend/src/keystore/keystore.ts
@@ -82,6 +82,7 @@ export const KeyStorePrefixes = {
SecretRotationLock: (rotationId: string) => `secret-rotation-v2-mutex-${rotationId}` as const,
StripeConnectionRefreshLock: (connectionId: string) => `stripe-connection-refresh-mutex-${connectionId}` as const,
PamAccountRotationLock: (accountId: string) => `pam-account-rotation-mutex-${accountId}` as const,
+ OidcIssuerKeyRotationLock: (orgId: string) => `oidc-issuer-key-rotation-mutex-${orgId}` as const,
SecretScanningFullScanLease: (resourceId: string) => `secret-scanning-v2-full-scan-lease-${resourceId}` as const,
SecretScanningDataSourceLock: (dataSourceId: string) =>
`secret-scanning-v2-data-source-mutex-${dataSourceId}` as const,
diff --git a/backend/src/server/config/rateLimiter.ts b/backend/src/server/config/rateLimiter.ts
index e3222f206e..3a42ec5550 100644
--- a/backend/src/server/config/rateLimiter.ts
+++ b/backend/src/server/config/rateLimiter.ts
@@ -77,6 +77,16 @@ export const ocspLimit: RateLimitOptions = {
keyGenerator: (req) => req.realIp
};
+// Cloud providers fetch the OIDC issuer's discovery document and JWKS from egress addresses shared by all of
+// their tenants, so readLimit would let one org's token exchanges throttle another's. Responses are small and
+// cacheable; this only has to stop one address flooding us.
+export const oidcIssuerLimit: RateLimitOptions = {
+ timeWindow: 60 * 1000,
+ hook: "preValidation",
+ max: 600,
+ keyGenerator: (req) => req.realIp
+};
+
// Gateways report load every 10s (6/min each), so 10 leaves room for tick drift and a restart
// landing in the same window without leaving headroom for a flood. Keyed by the reporting gateway
// rather than by IP, because the write limiter's IP key is shared: ~100 gateways behind one NAT
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts
index e14d0b8053..182c3e3341 100644
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@ -478,6 +478,7 @@ import { oauthClientServiceFactory } from "@app/services/oauth-client/oauth-clie
import { objectStorageServiceFactory } from "@app/services/object-storage/object-storage-service";
import { offlineUsageReportDALFactory } from "@app/services/offline-usage-report/offline-usage-report-dal";
import { offlineUsageReportServiceFactory } from "@app/services/offline-usage-report/offline-usage-report-service";
+import { oidcIssuerServiceFactory } from "@app/services/oidc-issuer/oidc-issuer-service";
import { incidentContactDALFactory } from "@app/services/org/incident-contacts-dal";
import { orgAccessReconcileConsumerFactory } from "@app/services/org/org-access-reconcile-consumer";
import { orgAccessSweepQueueFactory } from "@app/services/org/org-access-sweep-queue";
@@ -1076,6 +1077,8 @@ export const registerRoutes = async (
envConfig
});
+ const oidcIssuerService = oidcIssuerServiceFactory({ kmsDAL, kmsService, keyStore });
+
const encryptionKeyRotationService = encryptionKeyRotationServiceFactory({
kmsService,
kmsRootConfigDAL,
@@ -4732,6 +4735,7 @@ export const registerRoutes = async (
oidc: oidcService,
authToken: tokenService,
oauthClient: oauthClientService,
+ oidcIssuer: oidcIssuerService,
superAdmin: superAdminService,
encryptionKeyRotation: encryptionKeyRotationService,
offlineUsageReport: offlineUsageReportService,
diff --git a/backend/src/server/routes/v1/index.ts b/backend/src/server/routes/v1/index.ts
index 782df31ebd..0ffb767b10 100644
--- a/backend/src/server/routes/v1/index.ts
+++ b/backend/src/server/routes/v1/index.ts
@@ -71,6 +71,7 @@ import { registerInviteOrgRouter } from "./invite-org-router";
import { registerMicrosoftTeamsRouter } from "./microsoft-teams-router";
import { registerNotificationRouter } from "./notification-router";
import { registerOAuthRouter } from "./oauth-router";
+import { registerOidcIssuerRouter } from "./oidc-issuer-router";
import { registerOrgAdminRouter } from "./org-admin-router";
import { registerOrgIdentityRouter } from "./org-identity-router";
import { registerOrganizationMembershipsRouter } from "./organization-memberships-router";
@@ -128,6 +129,7 @@ export const registerV1Routes = async (server: FastifyZodProvider) => {
await server.register(registerPasswordRouter, { prefix: "/password" });
await server.register(registerAccountRecoveryRouter, { prefix: "/account-recovery" });
await server.register(registerOAuthRouter, { prefix: "/oauth" });
+ await server.register(registerOidcIssuerRouter, { prefix: "/oidc-issuer" });
await server.register(
async (orgRouter) => {
await orgRouter.register(registerOrgRouter);
diff --git a/backend/src/server/routes/v1/oidc-issuer-router.ts b/backend/src/server/routes/v1/oidc-issuer-router.ts
new file mode 100644
index 0000000000..66c6089cb7
--- /dev/null
+++ b/backend/src/server/routes/v1/oidc-issuer-router.ts
@@ -0,0 +1,73 @@
+import { z } from "zod";
+
+import { oidcIssuerLimit } from "@app/server/config/rateLimiter";
+
+// The next key is published a full signing period (24h) before it signs, so a cached JWKS younger than that
+// always holds the signing key
+const CACHE_MAX_AGE_SECONDS = 60 * 60;
+
+const OrgParamsSchema = z.object({
+ orgId: z.string().uuid()
+});
+
+// Unauthenticated, and shaped by OpenID Connect Discovery 1.0 and RFC 7517 rather than the house envelope,
+// because cloud providers fetch them to verify tokens Infisical signs
+export const registerOidcIssuerRouter = async (server: FastifyZodProvider) => {
+ server.route({
+ method: "GET",
+ url: "/orgs/:orgId/.well-known/openid-configuration",
+ config: {
+ rateLimit: oidcIssuerLimit
+ },
+ schema: {
+ hide: true,
+ params: OrgParamsSchema,
+ response: {
+ 200: z.object({
+ issuer: z.string(),
+ jwks_uri: z.string(),
+ response_types_supported: z.string().array(),
+ subject_types_supported: z.string().array(),
+ id_token_signing_alg_values_supported: z.string().array()
+ })
+ }
+ },
+ handler: async (req, res) => {
+ void res.header("Cache-Control", `public, max-age=${CACHE_MAX_AGE_SECONDS}`);
+ return server.services.oidcIssuer.getDiscoveryDocument(req.params.orgId);
+ }
+ });
+
+ server.route({
+ method: "GET",
+ url: "/orgs/:orgId/.well-known/jwks.json",
+ config: {
+ rateLimit: oidcIssuerLimit
+ },
+ schema: {
+ hide: true,
+ params: OrgParamsSchema,
+ response: {
+ 200: z.object({
+ keys: z
+ .object({
+ kty: z.string(),
+ n: z.string(),
+ e: z.string(),
+ kid: z.string(),
+ alg: z.string(),
+ use: z.string()
+ })
+ .array()
+ })
+ }
+ },
+ handler: async (req, res) => {
+ const jwks = await server.services.oidcIssuer.getJwks(req.params.orgId);
+
+ // An org gets keys on its first sign, so an empty set must not be cached or that first token fails to verify
+ void res.header("Cache-Control", jwks.keys.length ? `public, max-age=${CACHE_MAX_AGE_SECONDS}` : "no-store");
+ return jwks;
+ }
+ });
+};
diff --git a/backend/src/services/oidc-issuer/oidc-issuer-fns.test.ts b/backend/src/services/oidc-issuer/oidc-issuer-fns.test.ts
new file mode 100644
index 0000000000..b374a29cea
--- /dev/null
+++ b/backend/src/services/oidc-issuer/oidc-issuer-fns.test.ts
@@ -0,0 +1,66 @@
+import { createLocalJWKSet, jwtVerify } from "jose";
+
+import { signingService } from "@app/lib/crypto/sign/signing";
+import { AsymmetricKeyAlgorithm, SigningAlgorithm } from "@app/lib/crypto/sign/types";
+
+import { getKeyRotationPlan, getSigningKey, publicKeyToJwk, signJwt } from "./oidc-issuer-fns";
+
+const HOUR_MS = 60 * 60 * 1000;
+const now = new Date("2026-10-27T12:00:00Z");
+const keyCreatedHoursAgo = (id: string, hours: number) => ({
+ id,
+ createdAt: new Date(now.getTime() - hours * HOUR_MS)
+});
+
+describe("getKeyRotationPlan", () => {
+ test("creates the current and next keys on the first sign", () => {
+ expect(getKeyRotationPlan([], now)).toEqual({ keysToCreate: 2, keyIdsToDelete: [] });
+ expect(getKeyRotationPlan([keyCreatedHoursAgo("a", 1)], now)).toEqual({ keysToCreate: 1, keyIdsToDelete: [] });
+ });
+
+ test("does nothing while the newest key is inside its signing period", () => {
+ const keys = [keyCreatedHoursAgo("a", 47), keyCreatedHoursAgo("b", 23)];
+ expect(getKeyRotationPlan(keys, now)).toEqual({ keysToCreate: 0, keyIdsToDelete: [] });
+ });
+
+ test("rotates once the newest key is a signing period old, keeping three keys", () => {
+ expect(getKeyRotationPlan([keyCreatedHoursAgo("a", 48), keyCreatedHoursAgo("b", 24)], now)).toEqual({
+ keysToCreate: 1,
+ keyIdsToDelete: []
+ });
+
+ const keys = [keyCreatedHoursAgo("a", 72), keyCreatedHoursAgo("b", 48), keyCreatedHoursAgo("c", 24)];
+ expect(getKeyRotationPlan(keys, now)).toEqual({ keysToCreate: 1, keyIdsToDelete: ["a"] });
+ });
+
+ test("signs with the second newest key", () => {
+ const keys = [keyCreatedHoursAgo("a", 48), keyCreatedHoursAgo("b", 24), keyCreatedHoursAgo("c", 1)];
+ expect(getSigningKey(keys)?.id).toBe("b");
+ expect(getSigningKey(keys.slice(2))).toBeUndefined();
+ });
+});
+
+describe("signJwt", () => {
+ test("produces an RS256 token that verifies against the published JWK", async () => {
+ const { generateAsymmetricPrivateKey, getPublicKeyFromPrivateKey, sign } = signingService(
+ AsymmetricKeyAlgorithm.RSA_4096
+ );
+ const privateKey = await generateAsymmetricPrivateKey();
+ const jwk = await publicKeyToJwk(await getPublicKeyFromPrivateKey(privateKey));
+
+ const iat = Math.floor(Date.now() / 1000);
+ const token = await signJwt({
+ kid: jwk.kid,
+ claims: { iss: "https://issuer.test", sub: "app-connection:1", aud: "api://test", iat, exp: iat + 300 },
+ sign: (data) => sign(data, privateKey, SigningAlgorithm.RSASSA_PKCS1_V1_5_SHA_256, false)
+ });
+
+ const { payload, protectedHeader } = await jwtVerify(token, createLocalJWKSet({ keys: [jwk] }), {
+ issuer: "https://issuer.test",
+ audience: "api://test",
+ algorithms: ["RS256"]
+ });
+ expect(protectedHeader).toEqual({ alg: "RS256", typ: "JWT", kid: jwk.kid });
+ expect(payload.sub).toBe("app-connection:1");
+ });
+});
diff --git a/backend/src/services/oidc-issuer/oidc-issuer-fns.ts b/backend/src/services/oidc-issuer/oidc-issuer-fns.ts
new file mode 100644
index 0000000000..875bb337c2
--- /dev/null
+++ b/backend/src/services/oidc-issuer/oidc-issuer-fns.ts
@@ -0,0 +1,51 @@
+import { calculateJwkThumbprint, JWK } from "jose";
+
+import { crypto } from "@app/lib/crypto/cryptography";
+
+export const OIDC_ISSUER_KEY_NAME_PREFIX = "oidc-issuer-";
+export const OIDC_ISSUER_SIGNING_ALG = "RS256";
+
+const KEY_SIGNING_PERIOD_MS = 24 * 60 * 60 * 1000;
+const MAX_KEYS = 3;
+
+type TIssuerKey = { id: string; createdAt: Date };
+
+// Keys are ordered oldest first: previous, current, next. The newest key is published a full signing period
+// before it takes over, so a provider that cached the JWKS already has it, and the previous key stays published
+// for a period after it stops signing.
+export const getSigningKey = <T extends TIssuerKey>(keys: T[]): T | undefined => keys[keys.length - 2];
+
+export const getKeyRotationPlan = (keys: TIssuerKey[], now = new Date()) => {
+ if (keys.length < 2) return { keysToCreate: 2 - keys.length, keyIdsToDelete: [] as string[] };
+
+ if (now.getTime() - keys[keys.length - 1].createdAt.getTime() < KEY_SIGNING_PERIOD_MS) {
+ return { keysToCreate: 0, keyIdsToDelete: [] as string[] };
+ }
+
+ return { keysToCreate: 1, keyIdsToDelete: keys.slice(0, keys.length + 1 - MAX_KEYS).map(({ id }) => id) };
+};
+
+export const publicKeyToJwk = async (spki: Buffer) => {
+ const { kty, n, e } = crypto.nativeCrypto
+ .createPublicKey({ key: spki, format: "der", type: "spki" })
+ .export({ format: "jwk" }) as Required<Pick<JWK, "kty" | "n" | "e">>;
+
+ return { kty, n, e, kid: await calculateJwkThumbprint({ kty, n, e }), alg: OIDC_ISSUER_SIGNING_ALG, use: "sig" };
+};
+
+const encodeSegment = (value: object) => Buffer.from(JSON.stringify(value)).toString("base64url");
+
+export const signJwt = async ({
+ kid,
+ claims,
+ sign
+}: {
+ kid: string;
+ claims: Record<string, unknown>;
+ sign: (data: Buffer) => Promise<Buffer>;
+}) => {
+ const signingInput = `${encodeSegment({ alg: OIDC_ISSUER_SIGNING_ALG, typ: "JWT", kid })}.${encodeSegment(claims)}`;
+ const signature = await sign(Buffer.from(signingInput));
+
+ return `${signingInput}.${signature.toString("base64url")}`;
+};
diff --git a/backend/src/services/oidc-issuer/oidc-issuer-service.ts b/backend/src/services/oidc-issuer/oidc-issuer-service.ts
new file mode 100644
index 0000000000..16a3762dc8
--- /dev/null
+++ b/backend/src/services/oidc-issuer/oidc-issuer-service.ts
@@ -0,0 +1,193 @@
+import { Knex } from "knex";
+
+import { KeyStorePrefixes, TKeyStoreFactory, TKeyStoreLock } from "@app/keystore/keystore";
+import { getConfig } from "@app/lib/config/env";
+import { crypto } from "@app/lib/crypto/cryptography";
+import { AsymmetricKeyAlgorithm, SigningAlgorithm } from "@app/lib/crypto/sign/types";
+import { BadRequestError, InternalServerError, NotFoundError } from "@app/lib/errors";
+import { logger } from "@app/lib/logger";
+import { alphaNumericNanoId } from "@app/lib/nanoid";
+import { TKmsKeyDALFactory } from "@app/services/kms/kms-key-dal";
+import { TKmsServiceFactory } from "@app/services/kms/kms-service";
+import { KmsKeyUsage } from "@app/services/kms/kms-types";
+
+import {
+ getKeyRotationPlan,
+ getSigningKey,
+ OIDC_ISSUER_KEY_NAME_PREFIX,
+ OIDC_ISSUER_SIGNING_ALG,
+ publicKeyToJwk,
+ signJwt
+} from "./oidc-issuer-fns";
+import { TSignOidcIssuerTokenDTO } from "./oidc-issuer-types";
+
+const TOKEN_TTL_SECONDS = 5 * 60;
+const KEY_ROTATION_LOCK_TTL_MS = 30_000;
+
+type TOidcIssuerServiceFactoryDep = {
+ kmsDAL: Pick<TKmsKeyDALFactory, "find" | "delete" | "transaction">;
+ kmsService: Pick<TKmsServiceFactory, "generateKmsKey" | "getPublicKey" | "signWithKmsKey">;
+ keyStore: Pick<TKeyStoreFactory, "acquireLock">;
+};
+
+export type TOidcIssuerServiceFactory = ReturnType<typeof oidcIssuerServiceFactory>;
+
+export const oidcIssuerServiceFactory = ({ kmsDAL, kmsService, keyStore }: TOidcIssuerServiceFactoryDep) => {
+ const $getIssuerUrl = (orgId: string) => {
+ const { SITE_URL } = getConfig();
+ if (!SITE_URL) {
+ throw new BadRequestError({
+ message: "The OIDC issuer is unavailable because SITE_URL is not set. Set it to this instance's public URL."
+ });
+ }
+
+ return `${SITE_URL}/api/v1/oidc-issuer/orgs/${orgId}`;
+ };
+
+ // Issuer keys are reserved, so no customer can create one; the prefix only tells them apart from the
+ // org's other reserved keys.
+ const $listKeys = async (orgId: string, tx?: Knex) => {
+ const keys = await kmsDAL.find(
+ { orgId, projectId: null, isReserved: true, keyUsage: KmsKeyUsage.SIGN_VERIFY },
+ { sort: [["createdAt", "asc"]], tx }
+ );
+
+ return keys.filter(({ name }) => name.startsWith(OIDC_ISSUER_KEY_NAME_PREFIX));
+ };
+
+ // A Redis lock rather than an advisory lock, so no database connection is held while RSA keys are generated.
+ const $rotateKeys = async (orgId: string, waitForLock: boolean) => {
+ let lock: TKeyStoreLock;
+ try {
+ lock = await keyStore.acquireLock(
+ [KeyStorePrefixes.OidcIssuerKeyRotationLock(orgId)],
+ KEY_ROTATION_LOCK_TTL_MS,
+ waitForLock ? { retryCount: 20, retryDelay: 500 } : { retryCount: 0 }
+ );
+ } catch {
+ return null;
+ }
+
+ try {
+ // Read on the primary, which a transaction runs on: a lagging replica would hide a rotation that another
+ // request just finished, and this one would rotate again
+ const keys = await kmsDAL.transaction((tx) => $listKeys(orgId, tx));
+ const { keysToCreate, keyIdsToDelete } = getKeyRotationPlan(keys);
+
+ // Sequential, so createdAt orders the new keys
+ for (let i = 0; i < keysToCreate; i += 1) {
+ keys.push(
+ // eslint-disable-next-line no-await-in-loop
+ await kmsService.generateKmsKey({
+ orgId,
+ name: `${OIDC_ISSUER_KEY_NAME_PREFIX}${alphaNumericNanoId(8).toLowerCase()}`,
+ keyUsage: KmsKeyUsage.SIGN_VERIFY,
+ encryptionAlgorithm: AsymmetricKeyAlgorithm.RSA_4096,
+ isReserved: true,
+ isExportable: false
+ })
+ );
+ }
+
+ if (keyIdsToDelete.length) await kmsDAL.delete({ $in: { id: keyIdsToDelete } });
+
+ return keys.filter(({ id }) => !keyIdsToDelete.includes(id));
+ } finally {
+ try {
+ await lock.release();
+ } catch (err) {
+ logger.warn(err, `OIDC issuer key rotation lock release failed [orgId=${orgId}]`);
+ }
+ }
+ };
+
+ const $getSigningKey = async (orgId: string) => {
+ let keys = await $listKeys(orgId);
+
+ if (getKeyRotationPlan(keys).keysToCreate) {
+ // A busy lock means another request is already rotating and the current key is still valid, so only an
+ // org with no key to sign with waits for it
+ keys = (await $rotateKeys(orgId, !getSigningKey(keys))) ?? keys;
+ }
+
+ const signingKey = getSigningKey(keys);
+ if (!signingKey) {
+ throw new InternalServerError({
+ message: `Timed out creating the OIDC issuer signing keys for organization '${orgId}'. Try again.`
+ });
+ }
+
+ return signingKey;
+ };
+
+ const signToken = async ({ orgId, subject, audience }: TSignOidcIssuerTokenDTO) => {
+ const issuer = $getIssuerUrl(orgId);
+ const { id: kmsId } = await $getSigningKey(orgId);
+
+ const [{ kid }, sign] = await Promise.all([
+ kmsService.getPublicKey({ kmsId }).then(publicKeyToJwk),
+ kmsService.signWithKmsKey({ kmsId })
+ ]);
+
+ const iat = Math.floor(Date.now() / 1000);
+
+ return signJwt({
+ kid,
+ claims: {
+ iss: issuer,
+ sub: subject,
+ aud: audience,
+ iat,
+ nbf: iat,
+ exp: iat + TOKEN_TTL_SECONDS,
+ jti: crypto.nativeCrypto.randomUUID()
+ },
+ sign: async (data) => {
+ const { signature } = await sign({
+ data,
+ signingAlgorithm: SigningAlgorithm.RSASSA_PKCS1_V1_5_SHA_256,
+ isDigest: false
+ });
+ return signature;
+ }
+ });
+ };
+
+ const getDiscoveryDocument = (orgId: string) => {
+ const issuer = $getIssuerUrl(orgId);
+
+ return {
+ issuer,
+ jwks_uri: `${issuer}/.well-known/jwks.json`,
+ response_types_supported: ["id_token"],
+ subject_types_supported: ["public"],
+ id_token_signing_alg_values_supported: [OIDC_ISSUER_SIGNING_ALG]
+ };
+ };
+
+ const getJwks = async (orgId: string) => {
+ const keys = await $listKeys(orgId);
+
+ const jwks = await Promise.all(
+ keys.map(({ id }) =>
+ kmsService
+ .getPublicKey({ kmsId: id })
+ .then(publicKeyToJwk)
+ .catch((err) => {
+ // A rotation can delete the oldest key after it was listed. That key stopped signing a full
+ // period ago, so it is dropped rather than failing the whole set.
+ if (err instanceof NotFoundError) return null;
+ throw err;
+ })
+ )
+ );
+
+ return { keys: jwks.filter((jwk): jwk is NonNullable<typeof jwk> => jwk !== null) };
+ };
+
+ return {
+ signToken,
+ getDiscoveryDocument,
+ getJwks
+ };
+};
diff --git a/backend/src/services/oidc-issuer/oidc-issuer-types.ts b/backend/src/services/oidc-issuer/oidc-issuer-types.ts
new file mode 100644
index 0000000000..ab7b7fe783
--- /dev/null
+++ b/backend/src/services/oidc-issuer/oidc-issuer-types.ts
@@ -0,0 +1,5 @@
+export type TSignOidcIssuerTokenDTO = {
+ orgId: string;
+ subject: string;
+ audience: string;
+};