mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Fix env check blocking secrets with no matching reference
This commit is contained in:
@@ -597,19 +597,27 @@ export const expandSecretReferencesFactory = ({
|
|||||||
return secretCache[cacheKey][secretKey] || { value: "", tags: [] };
|
return secretCache[cacheKey][secretKey] || { value: "", tags: [] };
|
||||||
}
|
}
|
||||||
|
|
||||||
const folder = await folderDAL.findBySecretPath(projectId, environment, secretPath);
|
try {
|
||||||
if (!folder) return { value: "", tags: [] };
|
const folder = await folderDAL.findBySecretPath(projectId, environment, secretPath);
|
||||||
const secrets = await secretDAL.findByFolderId({ folderId: folder.id });
|
if (!folder) return { value: "", tags: [] };
|
||||||
|
const secrets = await secretDAL.findByFolderId({ folderId: folder.id });
|
||||||
|
|
||||||
const decryptedSecret = secrets.reduce<Record<string, { value: string; tags: string[] }>>((prev, secret) => {
|
const decryptedSecret = secrets.reduce<Record<string, { value: string; tags: string[] }>>((prev, secret) => {
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
prev[secret.key] = { value: decryptSecret(secret.encryptedValue) || "", tags: secret.tags?.map((el) => el.slug) };
|
prev[secret.key] = {
|
||||||
return prev;
|
value: decryptSecret(secret.encryptedValue) || "",
|
||||||
}, {});
|
tags: secret.tags?.map((el) => el.slug)
|
||||||
|
};
|
||||||
|
return prev;
|
||||||
|
}, {});
|
||||||
|
|
||||||
secretCache[cacheKey] = decryptedSecret;
|
secretCache[cacheKey] = decryptedSecret;
|
||||||
|
|
||||||
return secretCache[cacheKey][secretKey] || { value: "", tags: [] };
|
return secretCache[cacheKey][secretKey] || { value: "", tags: [] };
|
||||||
|
} catch (error) {
|
||||||
|
secretCache[cacheKey] = {};
|
||||||
|
return { value: "", tags: [] };
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const recursivelyExpandSecret = async (dto: {
|
const recursivelyExpandSecret = async (dto: {
|
||||||
@@ -664,6 +672,7 @@ export const expandSecretReferencesFactory = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const cacheKey = getCacheUniqueKey(environment, secretPath);
|
const cacheKey = getCacheUniqueKey(environment, secretPath);
|
||||||
|
if (!secretCache[cacheKey]) secretCache[cacheKey] = {};
|
||||||
secretCache[cacheKey][secretKey] = referredValue;
|
secretCache[cacheKey][secretKey] = referredValue;
|
||||||
|
|
||||||
referencedSecretValue = referredValue.value;
|
referencedSecretValue = referredValue.value;
|
||||||
@@ -683,6 +692,7 @@ export const expandSecretReferencesFactory = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const cacheKey = getCacheUniqueKey(secretReferenceEnvironment, secretReferencePath);
|
const cacheKey = getCacheUniqueKey(secretReferenceEnvironment, secretReferencePath);
|
||||||
|
if (!secretCache[cacheKey]) secretCache[cacheKey] = {};
|
||||||
secretCache[cacheKey][secretReferenceKey] = referedValue;
|
secretCache[cacheKey][secretReferenceKey] = referedValue;
|
||||||
|
|
||||||
referencedSecretValue = referedValue.value;
|
referencedSecretValue = referedValue.value;
|
||||||
|
|||||||
@@ -159,17 +159,14 @@ export const secretV2BridgeServiceFactory = ({
|
|||||||
const uniqueReferenceEnvironmentSlugs = Array.from(new Set(references.map((el) => el.environment)));
|
const uniqueReferenceEnvironmentSlugs = Array.from(new Set(references.map((el) => el.environment)));
|
||||||
const referencesEnvironments = await projectEnvDAL.findBySlugs(projectId, uniqueReferenceEnvironmentSlugs, tx);
|
const referencesEnvironments = await projectEnvDAL.findBySlugs(projectId, uniqueReferenceEnvironmentSlugs, tx);
|
||||||
|
|
||||||
if (referencesEnvironments.length !== uniqueReferenceEnvironmentSlugs.length)
|
// Filter out references to non-existent environments
|
||||||
throw new BadRequestError({
|
|
||||||
message: `Referenced environment not found. Missing ${diff(
|
|
||||||
uniqueReferenceEnvironmentSlugs,
|
|
||||||
referencesEnvironments.map((el) => el.slug)
|
|
||||||
).join(",")}`
|
|
||||||
});
|
|
||||||
|
|
||||||
const referencesEnvironmentGroupBySlug = groupBy(referencesEnvironments, (i) => i.slug);
|
const referencesEnvironmentGroupBySlug = groupBy(referencesEnvironments, (i) => i.slug);
|
||||||
|
const validEnvironmentReferences = references.filter((el) => referencesEnvironmentGroupBySlug[el.environment]);
|
||||||
|
|
||||||
|
if (validEnvironmentReferences.length === 0) return;
|
||||||
|
|
||||||
const referredFolders = await folderDAL.findByManySecretPath(
|
const referredFolders = await folderDAL.findByManySecretPath(
|
||||||
references.map((el) => ({
|
validEnvironmentReferences.map((el) => ({
|
||||||
secretPath: el.secretPath,
|
secretPath: el.secretPath,
|
||||||
envId: referencesEnvironmentGroupBySlug[el.environment][0].id
|
envId: referencesEnvironmentGroupBySlug[el.environment][0].id
|
||||||
})),
|
})),
|
||||||
@@ -179,7 +176,7 @@ export const secretV2BridgeServiceFactory = ({
|
|||||||
const referencesFolderGroupByPath = groupBy(referredFolders.filter(Boolean), (i) => `${i?.envId}-${i?.path}`);
|
const referencesFolderGroupByPath = groupBy(referredFolders.filter(Boolean), (i) => `${i?.envId}-${i?.path}`);
|
||||||
|
|
||||||
// Find only references that have valid folders (don't throw for missing paths)
|
// Find only references that have valid folders (don't throw for missing paths)
|
||||||
const validReferences = references.filter((el) => {
|
const validReferences = validEnvironmentReferences.filter((el) => {
|
||||||
const folderId =
|
const folderId =
|
||||||
referencesFolderGroupByPath[`${referencesEnvironmentGroupBySlug[el.environment][0].id}-${el.secretPath}`]?.[0]
|
referencesFolderGroupByPath[`${referencesEnvironmentGroupBySlug[el.environment][0].id}-${el.secretPath}`]?.[0]
|
||||||
?.id;
|
?.id;
|
||||||
|
|||||||
Reference in New Issue
Block a user