Skip to content

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

improvement: address auth template feedback

Scott Wilson978b4055fa73
diff --git a/backend/src/ee/services/identity-auth-template/identity-auth-template-schemas.ts b/backend/src/ee/services/identity-auth-template/identity-auth-template-schemas.ts
index 4f4e722537..0bf99c9aa4 100644
--- a/backend/src/ee/services/identity-auth-template/identity-auth-template-schemas.ts
+++ b/backend/src/ee/services/identity-auth-template/identity-auth-template-schemas.ts
@@ -66,9 +66,15 @@ export const kubernetesTemplateFieldsCreateSchema = kubernetesTemplateFieldsBase
// mirroring $redactTemplateSecrets. Derived from the request schemas so a new template
// field cannot reach the API undocumented, and so the response serializer drops anything
// the redaction step misses
-export const ldapTemplateFieldsResponseSchema = ldapTemplateFieldsSchema.omit({ bindPass: true }).extend({
- hasBindPass: z.boolean().describe("Whether a bind password is stored for this template")
-});
+// Older releases stored raw partial LDAP patches, so existing rows may legitimately omit
+// fields that are required when creating a template. Keep reads tolerant so one such row
+// cannot fail an entire list response.
+export const ldapTemplateFieldsResponseSchema = ldapTemplateFieldsSchema
+ .omit({ bindPass: true })
+ .partial()
+ .extend({
+ hasBindPass: z.boolean().describe("Whether a bind password is stored for this template")
+ });
export const kubernetesTemplateFieldsResponseSchema = kubernetesTemplateFieldsBaseSchema
.omit({ tokenReviewerJwt: true })
diff --git a/backend/src/ee/services/identity-auth-template/identity-auth-template-types.ts b/backend/src/ee/services/identity-auth-template/identity-auth-template-types.ts
index 1b93eda398..dc64997540 100644
--- a/backend/src/ee/services/identity-auth-template/identity-auth-template-types.ts
+++ b/backend/src/ee/services/identity-auth-template/identity-auth-template-types.ts
@@ -44,25 +44,6 @@ export type TKubernetesTemplateFields = {
allowedAudience?: string;
};
-// Union type for all template field types
-export type TTemplateFieldsByMethod = {
- [IdentityAuthTemplateMethod.LDAP]: TLdapTemplateFields;
- [IdentityAuthTemplateMethod.KUBERNETES]: TKubernetesTemplateFields;
-};
-
-// Generic base types that use conditional types for type safety
-export type TCreateIdentityAuthTemplateDTO = {
- name: string;
- authMethod: IdentityAuthTemplateMethod;
- templateFields: TTemplateFieldsByMethod[IdentityAuthTemplateMethod];
-} & Omit<TProjectPermission, "projectId">;
-
-export type TUpdateIdentityAuthTemplateDTO = {
- templateId: string;
- name?: string;
- templateFields?: Partial<TTemplateFieldsByMethod[IdentityAuthTemplateMethod]>;
-} & Omit<TProjectPermission, "projectId">;
-
export type TDeleteIdentityAuthTemplateDTO = {
templateId: string;
} & Omit<TProjectPermission, "projectId">;
@@ -89,7 +70,3 @@ export type TUnlinkTemplateUsageDTO = {
templateId: string;
identityIds: string[];
} & Omit<TProjectPermission, "projectId">;
-
-// Specific LDAP types for convenience
-export type TCreateLdapTemplateDTO = TCreateIdentityAuthTemplateDTO;
-export type TUpdateLdapTemplateDTO = TUpdateIdentityAuthTemplateDTO;
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.ts
index 4bb5ffcf22..5bfd52621e 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
@@ -851,6 +851,7 @@ export const identityKubernetesAuthServiceFactory = ({
);
}
+ const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
const { encryptor, decryptor } = await kmsService.createCipherPairWithDataKey({
type: KmsDataKey.Organization,
orgId: identityMembershipOrg.scopeOrgId
@@ -858,6 +859,13 @@ export const identityKubernetesAuthServiceFactory = ({
let template: TIdentityAuthTemplates | undefined;
if (templateId) {
+ if (!plan.machineIdentityAuthTemplates) {
+ throw new BadRequestError({
+ message:
+ "Failed to use identity auth template due to plan restriction. Upgrade plan to access machine identity auth templates."
+ });
+ }
+
const { permission: orgPermission } = await permissionService.getOrgPermission({
scope: OrganizationActionScope.Any,
actor,
@@ -894,7 +902,6 @@ export const identityKubernetesAuthServiceFactory = ({
});
}
- const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
const reformattedAccessTokenTrustedIps = accessTokenTrustedIps.map((accessTokenTrustedIp) => {
if (
!plan.ipAllowlisting &&
@@ -1174,6 +1181,7 @@ export const identityKubernetesAuthServiceFactory = ({
);
}
+ const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
const { encryptor, decryptor } = await kmsService.createCipherPairWithDataKey({
type: KmsDataKey.Organization,
orgId: identityMembershipOrg.scopeOrgId
@@ -1184,6 +1192,13 @@ export const identityKubernetesAuthServiceFactory = ({
// link CHANGE requires the attach-template permission; a re-assert must stay editable
// for actors that hold identity EditAuth alone
if (templateId && templateId !== identityKubernetesAuth.templateId) {
+ if (!plan.machineIdentityAuthTemplates) {
+ throw new BadRequestError({
+ message:
+ "Failed to use identity auth template due to plan restriction. Upgrade plan to access machine identity auth templates."
+ });
+ }
+
const { permission: orgPermission } = await permissionService.getOrgPermission({
scope: OrganizationActionScope.Any,
actor,
@@ -1232,7 +1247,6 @@ export const identityKubernetesAuthServiceFactory = ({
}
}
- const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
const reformattedAccessTokenTrustedIps = accessTokenTrustedIps?.map((accessTokenTrustedIp) => {
if (
!plan.ipAllowlisting &&
diff --git a/backend/src/services/identity-ldap-auth/identity-ldap-auth-service.ts b/backend/src/services/identity-ldap-auth/identity-ldap-auth-service.ts
index fe53035315..f6cc892c15 100644
--- a/backend/src/services/identity-ldap-auth/identity-ldap-auth-service.ts
+++ b/backend/src/services/identity-ldap-auth/identity-ldap-auth-service.ts
@@ -410,6 +410,13 @@ export const identityLdapAuthServiceFactory = ({
});
}
+ if (templateId && !plan.machineIdentityAuthTemplates) {
+ throw new BadRequestError({
+ message:
+ "Failed to use identity auth template due to plan restriction. Upgrade plan to access machine identity auth templates."
+ });
+ }
+
const reformattedAccessTokenTrustedIps = accessTokenTrustedIps.map((accessTokenTrustedIp) => {
if (
!plan.ipAllowlisting &&
@@ -621,6 +628,15 @@ export const identityLdapAuthServiceFactory = ({
});
}
+ // only a link change is new template use; a re-sent current templateId must not
+ // break routine edits for orgs that have since downgraded
+ if (templateId && templateId !== identityLdapAuth.templateId && !plan.machineIdentityAuthTemplates) {
+ throw new BadRequestError({
+ message:
+ "Failed to use identity auth template due to plan restriction. Upgrade plan to access machine identity auth templates."
+ });
+ }
+
const reformattedAccessTokenTrustedIps = accessTokenTrustedIps?.map((accessTokenTrustedIp) => {
if (
!plan.ipAllowlisting &&
diff --git a/frontend/src/hooks/api/identities/mutations.tsx b/frontend/src/hooks/api/identities/mutations.tsx
index 4b1e32fccd..f37eadbd37 100644
--- a/frontend/src/hooks/api/identities/mutations.tsx
+++ b/frontend/src/hooks/api/identities/mutations.tsx
@@ -1430,7 +1430,8 @@ export const useAddIdentityKubernetesAuth = () => {
accessTokenTrustedIps,
gatewayId,
gatewayPoolId,
- tokenReviewMode
+ tokenReviewMode,
+ verifyTlsCertificate
}) => {
const {
data: { identityKubernetesAuth }
@@ -1450,7 +1451,8 @@ export const useAddIdentityKubernetesAuth = () => {
accessTokenTrustedIps,
gatewayId,
gatewayPoolId,
- tokenReviewMode
+ tokenReviewMode,
+ verifyTlsCertificate
}
);
@@ -1576,7 +1578,8 @@ export const useUpdateIdentityKubernetesAuth = () => {
accessTokenTrustedIps,
gatewayId,
gatewayPoolId,
- tokenReviewMode
+ tokenReviewMode,
+ verifyTlsCertificate
}) => {
const {
data: { identityKubernetesAuth }
@@ -1597,7 +1600,8 @@ export const useUpdateIdentityKubernetesAuth = () => {
accessTokenTrustedIps,
gatewayId,
gatewayPoolId,
- tokenReviewMode
+ tokenReviewMode,
+ verifyTlsCertificate
}
);
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityKubernetesAuthForm.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityKubernetesAuthForm.tsx
index 7687a77432..c15ebc8c7e 100644
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityKubernetesAuthForm.tsx
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityKubernetesAuthForm.tsx
@@ -433,7 +433,9 @@ export const IdentityKubernetesAuthForm = ({
...customConfigPayload,
// unlink an existing template so the custom values are accepted
...(data.templateId ? { templateId: null } : {}),
- tokenReviewerJwt: tokenReviewerJwt || null,
+ // a blank field can only mean "clear" when the stored JWT was readable and
+ // prefilled; template-sourced JWTs read back as "" so blank must keep them
+ tokenReviewerJwt: tokenReviewerJwt || (data.tokenReviewerJwt ? null : undefined),
caCert
}
);