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
misc: adress permission issue for secrets with tags
Sheen Capadngan6c7062fa16e8
diff --git a/backend/src/ee/services/secret-approval-request/secret-approval-request-service.ts b/backend/src/ee/services/secret-approval-request/secret-approval-request-service.tsindex 90a7b0e1f6..bf89694f9c 100644--- a/backend/src/ee/services/secret-approval-request/secret-approval-request-service.ts+++ b/backend/src/ee/services/secret-approval-request/secret-approval-request-service.ts@@ -1447,6 +1447,7 @@ export const secretApprovalRequestServiceFactory = ({const commits: Omit<TSecretApprovalRequestsSecretsV2Insert, "requestId">[] = [];const commitTagIds: Record<string, string[]> = {};+ const existingTagIds: Record<string, string[]> = {};const { encryptor: secretManagerEncryptor } = await kmsService.createCipherPairWithDataKey({type: KmsDataKey.SecretManager,@@ -1512,6 +1513,11 @@ export const secretApprovalRequestServiceFactory = ({type: SecretType.Shared})));++ secretsToUpdateStoredInDB.forEach((el) => {+ if (el.tags?.length) existingTagIds[el.key] = el.tags.map((i) => i.id);+ });+if (secretsToUpdateStoredInDB.length !== secretsToUpdate.length)throw new NotFoundError({message: `Secret does not exist: ${secretsToUpdateStoredInDB.map((el) => el.key).join(",")}`@@ -1555,7 +1561,10 @@ export const secretApprovalRequestServiceFactory = ({secretMetadata}) => {const secretId = updatingSecretsGroupByKey[secretKey][0].id;- if (tagIds?.length) commitTagIds[newSecretName ?? secretKey] = tagIds;+ if (tagIds?.length || existingTagIds[secretKey]?.length) {+ commitTagIds[newSecretName ?? secretKey] = tagIds || existingTagIds[secretKey];+ }+return {...latestSecretVersions[secretId],secretMetadata,diff --git a/backend/src/services/secret-v2-bridge/secret-v2-bridge-dal.ts b/backend/src/services/secret-v2-bridge/secret-v2-bridge-dal.tsindex c2a72f2e60..8d9c6958ad 100644--- a/backend/src/services/secret-v2-bridge/secret-v2-bridge-dal.ts+++ b/backend/src/services/secret-v2-bridge/secret-v2-bridge-dal.ts@@ -684,9 +684,9 @@ export const secretV2BridgeDALFactory = ({ db, keyStore }: TSecretV2DalArg) => {throw new BadRequestError({ message: "Missing personal user id" });}void bd.orWhere({- key: el.key,- type: el.type,- userId: el.type === SecretType.Personal ? el.userId : null+ [`${TableName.SecretV2}.key` as "key"]: el.key,+ [`${TableName.SecretV2}.type` as "type"]: el.type,+ [`${TableName.SecretV2}.userId` as "userId"]: el.type === SecretType.Personal ? el.userId : null});});})@@ -695,12 +695,60 @@ export const secretV2BridgeDALFactory = ({ db, keyStore }: TSecretV2DalArg) => {`${TableName.SecretV2}.id`,`${TableName.SecretRotationV2SecretMapping}.secretId`)++ .leftJoin(+ TableName.SecretV2JnTag,+ `${TableName.SecretV2}.id`,+ `${TableName.SecretV2JnTag}.${TableName.SecretV2}Id`+ )+ .leftJoin(+ TableName.SecretTag,+ `${TableName.SecretV2JnTag}.${TableName.SecretTag}Id`,+ `${TableName.SecretTag}.id`+ )+ .leftJoin(TableName.ResourceMetadata, `${TableName.SecretV2}.id`, `${TableName.ResourceMetadata}.secretId`)+ .select(db.ref("id").withSchema(TableName.SecretTag).as("tagId"))+ .select(db.ref("color").withSchema(TableName.SecretTag).as("tagColor"))+ .select(db.ref("slug").withSchema(TableName.SecretTag).as("tagSlug"))+ .select(+ db.ref("id").withSchema(TableName.ResourceMetadata).as("metadataId"),+ db.ref("key").withSchema(TableName.ResourceMetadata).as("metadataKey"),+ db.ref("value").withSchema(TableName.ResourceMetadata).as("metadataValue")+ ).select(selectAllTableCols(TableName.SecretV2)).select(db.ref("rotationId").withSchema(TableName.SecretRotationV2SecretMapping));- return secrets.map((secret) => ({- ...secret,- isRotatedSecret: Boolean(secret.rotationId)- }));++ const docs = sqlNestRelationships({+ data: secrets,+ key: "id",+ parentMapper: (secret) => ({+ ...secret,+ isRotatedSecret: Boolean(secret.rotationId)+ }),+ childrenMapper: [+ {+ key: "tagId",+ label: "tags" as const,+ mapper: ({ tagId: id, tagColor: color, tagSlug: slug }) => ({+ id,+ color,+ slug,+ name: slug+ })+ },+ {+ key: "metadataId",+ label: "secretMetadata" as const,+ mapper: ({ metadataKey, metadataValue, metadataId }) => ({+ id: metadataId,+ key: metadataKey,+ value: metadataValue+ })+ }+ ]+ });++ return docs;} catch (error) {throw new DatabaseError({ error, name: "find by secret keys" });}