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: handle scheme-less urls for kubernetes auth validation in templates
Scott Wilsoncfa4d05b16b6
diff --git a/backend/src/ee/services/identity-auth-template/identity-auth-template-service.test.ts b/backend/src/ee/services/identity-auth-template/identity-auth-template-service.test.tsindex 45b3d5dda9..f13f565982 100644--- a/backend/src/ee/services/identity-auth-template/identity-auth-template-service.test.ts+++ b/backend/src/ee/services/identity-auth-template/identity-auth-template-service.test.ts@@ -124,6 +124,17 @@ describe("identityAuthTemplateServiceFactory kubernetes host validation", () =>expect(identityKubernetesAuthDAL.updateByTemplateId).not.toHaveBeenCalled();});+ it("blocks a scheme-less private host (block sees the same URL the dial sites use)", async () => {+ // the stored host may legally omit a scheme; without normalization new URL() inside+ // the block throws a TypeError instead of validating the host+ const { service, identityKubernetesAuthDAL } = createService({ gatewayColumns: NO_GATEWAY });++ await expect(patchTemplate(service, { kubernetesHost: "10.0.0.1:6443" })).rejects.toThrow(+ "Local IPs not allowed as URL"+ );+ expect(identityKubernetesAuthDAL.updateByTemplateId).not.toHaveBeenCalled();+ });+it("allows a private host while the template's gateway column is set", async () => {const { service, identityKubernetesAuthDAL } = createService();diff --git a/backend/src/ee/services/identity-auth-template/identity-auth-template-service.ts b/backend/src/ee/services/identity-auth-template/identity-auth-template-service.tsindex a07920e5d3..02ea1e83bb 100644--- a/backend/src/ee/services/identity-auth-template/identity-auth-template-service.ts+++ b/backend/src/ee/services/identity-auth-template/identity-auth-template-service.ts@@ -20,6 +20,7 @@ import { TOrgPermission } from "@app/lib/types";import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";import { ActorType } from "@app/services/auth/auth-type";import { TIdentityKubernetesAuthDALFactory } from "@app/services/identity-kubernetes-auth/identity-kubernetes-auth-dal";+import { withKubernetesHostScheme } from "@app/services/identity-kubernetes-auth/identity-kubernetes-auth-fns";import { IdentityKubernetesAuthTokenReviewMode } from "@app/services/identity-kubernetes-auth/identity-kubernetes-auth-types";import { validateKubernetesConnectionFields } from "@app/services/identity-kubernetes-auth/identity-kubernetes-auth-validators";import { TIdentityLdapAuthDALFactory } from "@app/services/identity-ldap-auth/identity-ldap-auth-dal";@@ -307,7 +308,9 @@ export const identityAuthTemplateServiceFactory = ({!normalizedFields.gatewayId &&!normalizedFields.gatewayPoolId) {- await blockLocalAndPrivateIpAddresses(normalizedFields.kubernetesHost);+ // the stored host may omit a scheme; normalize the same way the dial sites do, or+ // new URL() inside the block throws on legal hosts instead of validating them+ await blockLocalAndPrivateIpAddresses(withKubernetesHostScheme(normalizedFields.kubernetesHost));}if (normalizedFields.gatewayId || normalizedFields.gatewayPoolId) {$authorizeKubernetesTemplateGateway({@@ -462,7 +465,7 @@ export const identityAuthTemplateServiceFactory = ({!merged.gatewayId &&!merged.gatewayPoolId) {- await blockLocalAndPrivateIpAddresses(merged.kubernetesHost);+ await blockLocalAndPrivateIpAddresses(withKubernetesHostScheme(merged.kubernetesHost));}kubernetesPropagationData = {kubernetesHost: merged.kubernetesHost ?? null,diff --git a/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.test.ts b/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.test.tsindex 6fd9bd7cd5..70e2c99fe7 100644--- a/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.test.ts+++ b/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.test.ts@@ -203,6 +203,23 @@ describe("identityKubernetesAuthServiceFactory template attach validation", () =expect(identityKubernetesAuthDAL.create).not.toHaveBeenCalled();});+ it("rejects a scheme-less private host (block sees the same URL the dial sites use)", async () => {+ // the stored host may legally omit a scheme; without normalization new URL() inside+ // the block throws a TypeError instead of validating the host+ const { service, identityKubernetesAuthDAL } = createService({+ templateBlobFields: {+ kubernetesHost: "10.0.0.1:6443",+ tokenReviewMode: IdentityKubernetesAuthTokenReviewMode.Api,+ tokenReviewerJwt: "reviewer-jwt",+ allowedAudience: ""+ },+ templateGatewayColumns: NO_GATEWAY+ });++ await expect(attachWithTemplate(service)).rejects.toThrow("Local IPs not allowed as URL");+ expect(identityKubernetesAuthDAL.create).not.toHaveBeenCalled();+ });+it("attaches a healthy direct-dial template", async () => {const { service, identityKubernetesAuthDAL } = createService();diff --git a/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts b/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.tsindex b3428247a6..d4f47fcfb0 100644--- a/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts+++ b/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts@@ -322,7 +322,7 @@ export const identityKubernetesAuthServiceFactory = ({!fields.gatewayId &&!fields.gatewayPoolId) {- await blockLocalAndPrivateIpAddresses(fields.kubernetesHost);+ await blockLocalAndPrivateIpAddresses(withKubernetesHostScheme(fields.kubernetesHost));}};