Skip to content

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

fix: keep template reviewer JWT write-only after unlink

Scott Wilson518a8b3e5116
diff --git a/backend/src/db/migrations/20260825000000_identity-kubernetes-auth-jwt-provenance.ts b/backend/src/db/migrations/20260825000000_identity-kubernetes-auth-jwt-provenance.ts
new file mode 100644
index 0000000000..602903b8ac
--- /dev/null
+++ b/backend/src/db/migrations/20260825000000_identity-kubernetes-auth-jwt-provenance.ts
@@ -0,0 +1,24 @@
+import { Knex } from "knex";
+
+import { TableName } from "../schemas";
+
+export async function up(knex: Knex): Promise<void> {
+ if (!(await knex.schema.hasColumn(TableName.IdentityKubernetesAuth, "isTokenReviewerJwtTemplateSourced"))) {
+ await knex.schema.alterTable(TableName.IdentityKubernetesAuth, (t) => {
+ t.boolean("isTokenReviewerJwtTemplateSourced").notNullable().defaultTo(false);
+ });
+ // rows linked before this column existed copied their reviewer JWT from a template
+ await knex(TableName.IdentityKubernetesAuth)
+ .whereNotNull("templateId")
+ .whereNotNull("encryptedKubernetesTokenReviewerJwt")
+ .update({ isTokenReviewerJwtTemplateSourced: true });
+ }
+}
+
+export async function down(knex: Knex): Promise<void> {
+ if (await knex.schema.hasColumn(TableName.IdentityKubernetesAuth, "isTokenReviewerJwtTemplateSourced")) {
+ await knex.schema.alterTable(TableName.IdentityKubernetesAuth, (t) => {
+ t.dropColumn("isTokenReviewerJwtTemplateSourced");
+ });
+ }
+}
diff --git a/backend/src/db/schemas/identity-kubernetes-auths.ts b/backend/src/db/schemas/identity-kubernetes-auths.ts
index 8641e99205..af6acb330c 100644
--- a/backend/src/db/schemas/identity-kubernetes-auths.ts
+++ b/backend/src/db/schemas/identity-kubernetes-auths.ts
@@ -36,7 +36,8 @@ export const IdentityKubernetesAuthsSchema = z.object({
gatewayV2Id: z.string().uuid().nullable().optional(),
gatewayPoolId: z.string().uuid().nullable().optional(),
verifyTlsCertificate: z.boolean().default(false),
- templateId: z.string().uuid().nullable().optional()
+ templateId: z.string().uuid().nullable().optional(),
+ isTokenReviewerJwtTemplateSourced: z.boolean().default(false)
});
export type TIdentityKubernetesAuths = z.infer<typeof IdentityKubernetesAuthsSchema>;
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.ts
index eb16df2ef7..bde0667776 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
@@ -393,7 +393,8 @@ export const identityAuthTemplateServiceFactory = ({
: null,
encryptedKubernetesTokenReviewerJwt: merged.tokenReviewerJwt
? encryptor({ plainText: Buffer.from(merged.tokenReviewerJwt) }).cipherTextBlob
- : null
+ : null,
+ isTokenReviewerJwtTemplateSourced: Boolean(merged.tokenReviewerJwt)
};
// gateway references are re-resolved (and re-authorized) only when the patch touches
// them; linked rows keep their columns otherwise, so a gateway that was deleted after
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 9196461280..4bb5ffcf22 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
@@ -1074,6 +1074,7 @@ export const identityKubernetesAuthServiceFactory = ({
gatewayV2Id: resolvedGatewayV2Id,
gatewayPoolId: gatewayPoolId ?? null,
templateId: template?.id ?? null,
+ isTokenReviewerJwtTemplateSourced: Boolean(template && tokenReviewerJwt),
verifyTlsCertificate: resolvedVerifyTlsCertificate,
accessTokenTrustedIps: JSON.stringify(reformattedAccessTokenTrustedIps),
encryptedKubernetesTokenReviewerJwt: tokenReviewerJwt
@@ -1488,8 +1489,10 @@ export const identityKubernetesAuthServiceFactory = ({
updateQuery.encryptedKubernetesTokenReviewerJwt = encryptor({
plainText: Buffer.from(tokenReviewerJwt)
}).cipherTextBlob;
+ updateQuery.isTokenReviewerJwtTemplateSourced = Boolean(template);
} else if (tokenReviewerJwt === null) {
updateQuery.encryptedKubernetesTokenReviewerJwt = null;
+ updateQuery.isTokenReviewerJwtTemplateSourced = false;
}
const updatedKubernetesAuth = await identityKubernetesAuthDAL.updateById(identityKubernetesAuth.id, updateQuery);
@@ -1501,7 +1504,9 @@ export const identityKubernetesAuthServiceFactory = ({
: "";
const updatedTokenReviewerJwt =
- !updatedKubernetesAuth.templateId && updatedKubernetesAuth.encryptedKubernetesTokenReviewerJwt
+ !updatedKubernetesAuth.templateId &&
+ !updatedKubernetesAuth.isTokenReviewerJwtTemplateSourced &&
+ updatedKubernetesAuth.encryptedKubernetesTokenReviewerJwt
? decryptor({
cipherTextBlob: updatedKubernetesAuth.encryptedKubernetesTokenReviewerJwt
}).toString()
@@ -1582,10 +1587,15 @@ export const identityKubernetesAuthServiceFactory = ({
}
// a template's reviewer JWT is an org-scoped write-only credential copied onto the
- // identity row; identity-level readers must not be able to recover it. Manually
+ // identity row; identity-level readers must not be able to recover it, including
+ // after an unlink (the copied credential keeps its template provenance). Manually
// configured identities keep read-back (the caller supplied that value themselves).
let tokenReviewerJwt = "";
- if (!identityKubernetesAuth.templateId && identityKubernetesAuth.encryptedKubernetesTokenReviewerJwt) {
+ if (
+ !identityKubernetesAuth.templateId &&
+ !identityKubernetesAuth.isTokenReviewerJwtTemplateSourced &&
+ identityKubernetesAuth.encryptedKubernetesTokenReviewerJwt
+ ) {
tokenReviewerJwt = decryptor({
cipherTextBlob: identityKubernetesAuth.encryptedKubernetesTokenReviewerJwt
}).toString();