mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Merge pull request #4409 from Infisical/misc/address-secret-approval-request-permission-issue-for-tags
misc: address permission issue for secrets with tags
This commit is contained in:
@@ -1448,6 +1448,7 @@ export const secretApprovalRequestServiceFactory = ({
|
|||||||
|
|
||||||
const commits: Omit<TSecretApprovalRequestsSecretsV2Insert, "requestId">[] = [];
|
const commits: Omit<TSecretApprovalRequestsSecretsV2Insert, "requestId">[] = [];
|
||||||
const commitTagIds: Record<string, string[]> = {};
|
const commitTagIds: Record<string, string[]> = {};
|
||||||
|
const existingTagIds: Record<string, string[]> = {};
|
||||||
|
|
||||||
const { encryptor: secretManagerEncryptor } = await kmsService.createCipherPairWithDataKey({
|
const { encryptor: secretManagerEncryptor } = await kmsService.createCipherPairWithDataKey({
|
||||||
type: KmsDataKey.SecretManager,
|
type: KmsDataKey.SecretManager,
|
||||||
@@ -1513,6 +1514,11 @@ export const secretApprovalRequestServiceFactory = ({
|
|||||||
type: SecretType.Shared
|
type: SecretType.Shared
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
secretsToUpdateStoredInDB.forEach((el) => {
|
||||||
|
if (el.tags?.length) existingTagIds[el.key] = el.tags.map((i) => i.id);
|
||||||
|
});
|
||||||
|
|
||||||
if (secretsToUpdateStoredInDB.length !== secretsToUpdate.length)
|
if (secretsToUpdateStoredInDB.length !== secretsToUpdate.length)
|
||||||
throw new NotFoundError({
|
throw new NotFoundError({
|
||||||
message: `Secret does not exist: ${secretsToUpdateStoredInDB.map((el) => el.key).join(",")}`
|
message: `Secret does not exist: ${secretsToUpdateStoredInDB.map((el) => el.key).join(",")}`
|
||||||
@@ -1556,7 +1562,10 @@ export const secretApprovalRequestServiceFactory = ({
|
|||||||
secretMetadata
|
secretMetadata
|
||||||
}) => {
|
}) => {
|
||||||
const secretId = updatingSecretsGroupByKey[secretKey][0].id;
|
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 {
|
return {
|
||||||
...latestSecretVersions[secretId],
|
...latestSecretVersions[secretId],
|
||||||
secretMetadata,
|
secretMetadata,
|
||||||
|
|||||||
@@ -684,9 +684,9 @@ export const secretV2BridgeDALFactory = ({ db, keyStore }: TSecretV2DalArg) => {
|
|||||||
throw new BadRequestError({ message: "Missing personal user id" });
|
throw new BadRequestError({ message: "Missing personal user id" });
|
||||||
}
|
}
|
||||||
void bd.orWhere({
|
void bd.orWhere({
|
||||||
key: el.key,
|
[`${TableName.SecretV2}.key` as "key"]: el.key,
|
||||||
type: el.type,
|
[`${TableName.SecretV2}.type` as "type"]: el.type,
|
||||||
userId: el.type === SecretType.Personal ? el.userId : null
|
[`${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.SecretV2}.id`,
|
||||||
`${TableName.SecretRotationV2SecretMapping}.secretId`
|
`${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(selectAllTableCols(TableName.SecretV2))
|
||||||
.select(db.ref("rotationId").withSchema(TableName.SecretRotationV2SecretMapping));
|
.select(db.ref("rotationId").withSchema(TableName.SecretRotationV2SecretMapping));
|
||||||
return secrets.map((secret) => ({
|
|
||||||
...secret,
|
const docs = sqlNestRelationships({
|
||||||
isRotatedSecret: Boolean(secret.rotationId)
|
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) {
|
} catch (error) {
|
||||||
throw new DatabaseError({ error, name: "find by secret keys" });
|
throw new DatabaseError({ error, name: "find by secret keys" });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user