Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
refactor(billing): sign service JWT with RS256 private key
Tre Dubrava91d34c4d6fa3
diff --git a/backend/src/services/license-client/license-client-backends.ts b/backend/src/services/license-client/license-client-backends.tsindex de73eb62c2..a8d4530a27 100644--- a/backend/src/services/license-client/license-client-backends.ts+++ b/backend/src/services/license-client/license-client-backends.ts@@ -20,30 +20,30 @@ const SUBSCRIPTION_PATH = "/v1/subscription";const CHECKOUT_SESSION_PATH = "/v1/billing/checkout-session";const PORTAL_SESSION_PATH = "/v1/billing/portal-session";-// Issuer/audience/subject are a fixed contract with the license server (it validates them against-// its own configured values), not per-deployment config, so they live here rather than in env.-const SERVICE_TOKEN_ISSUER = "infisical";-const SERVICE_TOKEN_AUDIENCE = "license-server";+// Issuer/audience/subject match the license server's in-code constants (it validates iss/aud against+// them). They are public claims, not per-deployment config, so they live here rather than in env.+const SERVICE_TOKEN_ISSUER = "infisical-cloud";+const SERVICE_TOKEN_AUDIENCE = "infisical-license-server";const SERVICE_TOKEN_SUBJECT = "infisical-cloud";-// The license server validates a short-lived HS256 service JWT (iss/aud/exp/sub) signed with the-// shared service key. Mint a fresh token per request; signing is cheap and results are cached upstream.-const mintServiceToken = (hmacSecret: string): string =>- jwt.sign({}, hmacSecret, {- algorithm: "HS256",+// The license server validates a short-lived RS256 service JWT (iss/aud/exp/sub) that we sign with+// our private key and it verifies with the matching public key. Mint a fresh token per request.+const mintServiceToken = (signingKey: string): string =>+ jwt.sign({}, signingKey, {+ algorithm: "RS256",issuer: SERVICE_TOKEN_ISSUER,audience: SERVICE_TOKEN_AUDIENCE,subject: SERVICE_TOKEN_SUBJECT,expiresIn: "2m"});-export const licenseServerBackend = (serverUrl: string, hmacSecret: string): TLicenseClientBackend => ({+export const licenseServerBackend = (serverUrl: string, signingKey: string): TLicenseClientBackend => ({fetchEntitlements: async (orgId: string): Promise<TEntitlementsResponse> => {const url = new URL(ENTITLEMENTS_PATH, serverUrl);url.searchParams.set("org_id", orgId);const res = await fetch(url, {method: "GET",- headers: { Authorization: `Bearer ${mintServiceToken(hmacSecret)}` },+ headers: { Authorization: `Bearer ${mintServiceToken(signingKey)}` },redirect: "manual"});if (!res.ok) {@@ -57,7 +57,7 @@ export const licenseServerBackend = (serverUrl: string, hmacSecret: string): TLiconst url = new URL(PRODUCTS_PATH, serverUrl);const res = await fetch(url, {method: "GET",- headers: { Authorization: `Bearer ${mintServiceToken(hmacSecret)}` },+ headers: { Authorization: `Bearer ${mintServiceToken(signingKey)}` },redirect: "manual"});if (!res.ok) {@@ -75,7 +75,7 @@ export const licenseServerBackend = (serverUrl: string, hmacSecret: string): TLiurl.searchParams.set("org_id", orgId);const res = await fetch(url, {method: "GET",- headers: { Authorization: `Bearer ${mintServiceToken(hmacSecret)}` },+ headers: { Authorization: `Bearer ${mintServiceToken(signingKey)}` },redirect: "manual"});if (res.status === 404) {@@ -101,7 +101,7 @@ export const licenseServerBackend = (serverUrl: string, hmacSecret: string): TLiurl.searchParams.set("org_id", orgId);const res = await fetch(url, {method: "POST",- headers: { Authorization: `Bearer ${mintServiceToken(hmacSecret)}`, "Content-Type": "application/json" },+ headers: { Authorization: `Bearer ${mintServiceToken(signingKey)}`, "Content-Type": "application/json" },body: JSON.stringify(payload),redirect: "manual"});@@ -117,7 +117,7 @@ export const licenseServerBackend = (serverUrl: string, hmacSecret: string): TLiurl.searchParams.set("org_id", orgId);const res = await fetch(url, {method: "POST",- headers: { Authorization: `Bearer ${mintServiceToken(hmacSecret)}`, "Content-Type": "application/json" },+ headers: { Authorization: `Bearer ${mintServiceToken(signingKey)}`, "Content-Type": "application/json" },body: JSON.stringify(payload),redirect: "manual"});diff --git a/backend/src/services/license-client/license-client.ts b/backend/src/services/license-client/license-client.tsindex 7bfe28badc..02028ec823 100644--- a/backend/src/services/license-client/license-client.ts+++ b/backend/src/services/license-client/license-client.ts@@ -22,8 +22,8 @@ const buildBackend = (envConfig: TLicenseClientFactoryDep["envConfig"]): TLicens}const serverUrl = envConfig.LICENSE_SERVER_V2_URL;- const hmacSecret = envConfig.LICENSE_SERVER_V2_SERVICE_KEY;- if (!serverUrl || !hmacSecret) {+ const signingKey = envConfig.LICENSE_SERVER_V2_SERVICE_KEY;+ if (!serverUrl || !signingKey) {logger.warn("license-client: enabled but LICENSE_SERVER_V2_URL / _SERVICE_KEY is missing; serving feature fallbacks");@@ -43,7 +43,8 @@ const buildBackend = (envConfig: TLicenseClientFactoryDep["envConfig"]): TLicensreturn null;}- return licenseServerBackend(serverUrl, hmacSecret);+ // The signing key is a PEM private key; env vars often carry it with escaped newlines.+ return licenseServerBackend(serverUrl, signingKey.replace(/\\n/g, "\n"));};export const licenseClientFactory = ({ envConfig, keyStore }: TLicenseClientFactoryDep) => {