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
fix(gateway): pin TokenReview requests and honour TLS verification
bernie-g0d0f93d4d083
diff --git a/backend/src/ee/services/resource-auth-method/kubernetes-auth-fns.ts b/backend/src/ee/services/resource-auth-method/kubernetes-auth-fns.tsindex ea59562c17..25d6f35900 100644--- a/backend/src/ee/services/resource-auth-method/kubernetes-auth-fns.ts+++ b/backend/src/ee/services/resource-auth-method/kubernetes-auth-fns.ts@@ -1,14 +1,13 @@import { isIP } from "node:net";import { AxiosError } from "axios";-import https from "https";import picomatch from "picomatch";import RE2 from "re2";-import { request } from "@app/lib/config/request";import { BadRequestError, UnauthorizedError } from "@app/lib/errors";import { logger } from "@app/lib/logger";import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";+import { safeRequest } from "@app/lib/validator/safe-request";import {handleAxiosError,KubernetesAuthErrorContext@@ -39,12 +38,6 @@ export const assertKubernetesHostAllowed = async (kubernetesHost: string) => {}};-// Verification is impossible without a CA, since cluster CAs are in no public trust store.-export const resolveEffectiveVerifyTlsCertificate = (caCertificate: string, storedVerify: boolean) => {- if (!caCertificate.length) return false;- return storedVerify;-};-// Surfaces a bad host or reviewer when the config is saved rather than when a gateway later// fails to start. Makes network calls, so call it outside a transaction.export const validateKubernetesConfigReachable = async ({@@ -59,12 +52,10 @@ export const validateKubernetesConfigReachable = async ({verifyTlsCertificate: boolean;}) => {const host = kubernetesHost.startsWith("https://") ? kubernetesHost : `https://${kubernetesHost}`;- const effectiveVerify = resolveEffectiveVerifyTlsCertificate(caCertificate ?? "", verifyTlsCertificate);-await validateKubernetesHostConnectivity({kubernetesHost: host,caCert: caCertificate,- verifyTlsCertificate: effectiveVerify+ verifyTlsCertificate});if (tokenReviewerJwt) {@@ -72,7 +63,7 @@ export const validateKubernetesConfigReachable = async ({kubernetesHost: host,tokenReviewerJwt,caCert: caCertificate,- verifyTlsCertificate: effectiveVerify+ verifyTlsCertificate});}};@@ -113,7 +104,7 @@ export const reviewServiceAccountToken = async ({let review: TCreateTokenReviewResponse;try {- const res = await request.post<TCreateTokenReviewResponse>(+ const res = await safeRequest.post<TCreateTokenReviewResponse>(`${baseUrl}/apis/authentication.k8s.io/v1/tokenreviews`,{apiVersion: "authentication.k8s.io/v1",@@ -132,11 +123,11 @@ export const reviewServiceAccountToken = async ({},signal: AbortSignal.timeout(TOKEN_REVIEW_TIMEOUT_MS),timeout: TOKEN_REVIEW_TIMEOUT_MS,- httpsAgent: new https.Agent({- ca: caCertificate || undefined,- rejectUnauthorized: resolveEffectiveVerifyTlsCertificate(caCertificate, verifyTlsCertificate),- servername: toServerName(kubernetesHost)- })+ // safeRequest pins the connection to the addresses it validated, so a hostname that+ // re-resolves to a private address between config time and login cannot be reached.+ ca: caCertificate || undefined,+ rejectUnauthorized: verifyTlsCertificate,+ servername: toServerName(kubernetesHost)});review = res.data;diff --git a/backend/src/ee/services/resource-auth-method/resource-auth-method-service.ts b/backend/src/ee/services/resource-auth-method/resource-auth-method-service.tsindex c049a2c4f0..b2f5b2e4f7 100644--- a/backend/src/ee/services/resource-auth-method/resource-auth-method-service.ts+++ b/backend/src/ee/services/resource-auth-method/resource-auth-method-service.ts@@ -443,16 +443,40 @@ export const resourceAuthMethodServiceFactory = ({let encryptedKubernetesSecrets: TEncryptedKubernetesSecrets = {};if (authMethod.method === ResourceAuthMethodType.Kubernetes) {await assertKubernetesHostAllowed(authMethod.kubernetesHost);- // A stored reviewer is left alone; it was already checked when it was set.++ // Switching in from another method has no stored secret to preserve, so omitted means null.+ const isMethodChange = previousMethod !== ResourceAuthMethodType.Kubernetes;++ // Validate against the credentials that will actually be stored. An omitted secret keeps the+ // stored one, so validating with only what this request carried would check a different+ // config than the one a gateway later logs in with.+ let effectiveCa = authMethod.caCertificate;+ let effectiveReviewer = authMethod.tokenReviewerJwt;+ if (!isMethodChange && current && (effectiveCa === undefined || effectiveReviewer === undefined)) {+ const stored = await resourceKubernetesAuthDAL.findOne({ authMethodId: current.id });+ const needsCa = effectiveCa === undefined && stored?.encryptedKubernetesCaCertificate;+ const needsReviewer = effectiveReviewer === undefined && stored?.encryptedKubernetesTokenReviewerJwt;+ if (stored && (needsCa || needsReviewer)) {+ const { decryptor } = await kmsService.createCipherPairWithDataKey({+ type: KmsDataKey.Organization,+ orgId: actor.orgId+ });+ if (needsCa && stored.encryptedKubernetesCaCertificate) {+ effectiveCa = decryptor({ cipherTextBlob: stored.encryptedKubernetesCaCertificate }).toString();+ }+ if (needsReviewer && stored.encryptedKubernetesTokenReviewerJwt) {+ effectiveReviewer = decryptor({ cipherTextBlob: stored.encryptedKubernetesTokenReviewerJwt }).toString();+ }+ }+ }+await validateKubernetesConfigReachable({kubernetesHost: authMethod.kubernetesHost,- caCertificate: authMethod.caCertificate,- tokenReviewerJwt: authMethod.tokenReviewerJwt,+ caCertificate: effectiveCa,+ tokenReviewerJwt: effectiveReviewer,verifyTlsCertificate: authMethod.verifyTlsCertificate});- // Switching in from another method has no stored secret to preserve, so omitted means null.- const isMethodChange = previousMethod !== ResourceAuthMethodType.Kubernetes;encryptedKubernetesSecrets = await encryptKubernetesSecrets(actor.orgId, {caCertificate: authMethod.caCertificate ?? (isMethodChange ? "" : undefined),tokenReviewerJwt: authMethod.tokenReviewerJwt ?? (isMethodChange ? "" : undefined)diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.tsindex b91b2dcdbd..b9762677e3 100644--- a/backend/src/lib/api-docs/constants.ts+++ b/backend/src/lib/api-docs/constants.ts@@ -3807,7 +3807,7 @@ export const GATEWAYS = {kubernetesHost:"The URL of the Kubernetes API server that Infisical reviews the gateway's service account token against (e.g. https://my-cluster.example.com:6443).",caCertificate:- "The PEM-encoded CA certificate of the Kubernetes API server. Required to verify the API server's TLS certificate. Write-only: never returned by the API.",+ "The PEM-encoded CA certificate that issued the Kubernetes API server's TLS certificate. Required when the API server uses a certificate the system trust store does not recognise, which is the usual case for a cluster CA.",tokenReviewerJwt:"A long-lived service account token with the system:auth-delegator ClusterRole used to submit TokenReview requests. Omit to have the gateway's own token act as the reviewer. Write-only: never returned by the API.",allowedNamespaces:@@ -3817,7 +3817,7 @@ export const GATEWAYS = {allowedAudience:"The audience the gateway's service account token must carry. Leave empty to skip the audience check.",verifyTlsCertificate:- "Whether to verify the Kubernetes API server's TLS certificate. Only takes effect when a CA certificate is configured."+ "Whether to verify the Kubernetes API server's TLS certificate. Verified against the CA certificate when one is configured, otherwise against the system trust store."},LOGIN: {gatewayId: "The ID of the gateway logging in (AWS and Kubernetes methods only).",diff --git a/docs/documentation/platform/gateways/gateway-deployment.mdx b/docs/documentation/platform/gateways/gateway-deployment.mdxindex a73474551f..72b3732379 100644--- a/docs/documentation/platform/gateways/gateway-deployment.mdx+++ b/docs/documentation/platform/gateways/gateway-deployment.mdx@@ -166,7 +166,7 @@ This guide covers everything you need to deploy and configure Infisical Gateways| **Allowed Namespaces** | Namespaces whose service accounts may authenticate as this gateway. Supports `*` wildcards. || **Allowed Service Account Names** | Service account names that may authenticate as this gateway. Supports `*` wildcards. || **Allowed Audience** | Optional. The audience the token must carry. |- | **CA Certificate** | Optional, but required to verify the API server's TLS certificate. |+ | **CA Certificate** | The CA that issued the API server's certificate. Needed unless that certificate is already trusted by the public trust store, which for a cluster CA it will not be. || **Token Reviewer JWT** | Optional. A token with the `system:auth-delegator` ClusterRole. Leave empty to let the gateway's own service account review its token, which the Helm chart configures by default. |At least one of **Allowed Namespaces** or **Allowed Service Account Names** must be set, so that not every pod in the cluster can enroll as the gateway.diff --git a/frontend/src/pages/organization/NetworkingPage/components/NetworkingAuthMethodForm.tsx b/frontend/src/pages/organization/NetworkingPage/components/NetworkingAuthMethodForm.tsxindex 0b776db4ef..ded6ec7b7e 100644--- a/frontend/src/pages/organization/NetworkingPage/components/NetworkingAuthMethodForm.tsx+++ b/frontend/src/pages/organization/NetworkingPage/components/NetworkingAuthMethodForm.tsx@@ -493,7 +493,8 @@ export const NetworkingAuthMethodForm = ({</TooltipTrigger><TooltipContent className="max-w-md">The PEM-encoded CA certificate that issued the Kubernetes API server's- TLS certificate. Required for TLS certificate verification to take effect.+ TLS certificate. Needed whenever the server uses a certificate the system+ trust store does not recognise, which is the usual case for a cluster CA.</TooltipContent></Tooltip></FieldLabel>diff --git a/helm-charts/infisical-gateway/CHANGELOG.md b/helm-charts/infisical-gateway/CHANGELOG.mdindex 78a22331c3..6181363ab8 100644--- a/helm-charts/infisical-gateway/CHANGELOG.md+++ b/helm-charts/infisical-gateway/CHANGELOG.md@@ -1,6 +1,7 @@## 1.3.0 (August 4, 2026)* Added Kubernetes auth enrollment (`gateway.enrollment.method: kubernetes`). The gateway authenticates with the projected service account token of its own pod, so no enrollment token or cloud credential needs to be distributed to the cluster.* Added `gateway.enrollment.kubernetes.gatewayId` and `gateway.enrollment.kubernetes.serviceAccountTokenPath`.+* Kubernetes enrollment requires a CLI image that supports `--enroll-method=kubernetes`. Set `image.tag` to such a release until the chart default is bumped.## 1.2.0 (July 17, 2026)* Added `extraEnv` for injecting additional environment variables into the gateway container.diff --git a/helm-charts/infisical-gateway/values.yaml b/helm-charts/infisical-gateway/values.yamlindex 4d27f335aa..b355d56472 100644--- a/helm-charts/infisical-gateway/values.yaml+++ b/helm-charts/infisical-gateway/values.yaml@@ -1,5 +1,7 @@image:repository: infisical/cli+ # gateway.enrollment.method=kubernetes needs a CLI that understands --enroll-method=kubernetes.+ # Override this with a release that contains it until the default below is bumped.tag: "0.43.84"pullPolicy: IfNotPresent