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
fix(secret-sync): move portainer environment check to stack fetch so imports are covered
Yeongjin Lee17feb5df4c31
diff --git a/backend/src/services/secret-sync/portainer/portainer-sync-fns.ts b/backend/src/services/secret-sync/portainer/portainer-sync-fns.tsindex 5d677e7d2f..e97be94c88 100644--- a/backend/src/services/secret-sync/portainer/portainer-sync-fns.ts+++ b/backend/src/services/secret-sync/portainer/portainer-sync-fns.ts@@ -24,17 +24,27 @@ const getPortainerClientDetails = (secretSync: TPortainerSyncWithCredentials) =>};const getPortainerStack = async (secretSync: TPortainerSyncWithCredentials): Promise<TPortainerStackResponse> => {- const { instanceUrl, headers, stackId } = getPortainerClientDetails(secretSync);+ const { instanceUrl, headers, environmentId, stackId } = getPortainerClientDetails(secretSync);+ let stack: TPortainerStackResponse;try {const { data } = await safeRequest.get<TPortainerStackResponse>(`${instanceUrl}/api/stacks/${stackId}`, {headers});- return data;+ stack = data;} catch (error) {throw new SecretSyncError({ error });}++ if (stack.EndpointId !== environmentId) {+ throw new SecretSyncError({+ message: `Stack with ID '${stackId}' belongs to Portainer environment '${stack.EndpointId}', not the configured environment '${environmentId}'`,+ shouldRetry: false+ });+ }++ return stack;};/**@@ -49,13 +59,6 @@ const writeStackEnv = async () => {const { instanceUrl, headers, environmentId, stackId } = getPortainerClientDetails(secretSync);- if (stack.EndpointId !== environmentId) {- throw new SecretSyncError({- message: `Stack with ID '${stackId}' belongs to Portainer environment '${stack.EndpointId}', not the configured environment '${environmentId}'`,- shouldRetry: false- });- }-try {if (stack.GitConfig?.URL) {// The Git settings are replaced wholesale, so the existing reference and auto-update config are echoed back