Skip to content

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

Address PR comments

Carlos Monastyrski9075bdd10c9c
diff --git a/backend/src/services/app-connection/f5-big-ip/f5-big-ip-connection-fns.ts b/backend/src/services/app-connection/f5-big-ip/f5-big-ip-connection-fns.ts
index 06c29123a8..0354120322 100644
--- a/backend/src/services/app-connection/f5-big-ip/f5-big-ip-connection-fns.ts
+++ b/backend/src/services/app-connection/f5-big-ip/f5-big-ip-connection-fns.ts
@@ -62,7 +62,8 @@ const requestWithF5BigIpGateway = async <T>(
...requestConfig.headers,
Host: hostname
},
- httpsAgent
+ httpsAgent,
+ maxRedirects: 0
};
const resp = await request.request<T>(finalRequestConfig);
@@ -84,7 +85,8 @@ const requestWithF5BigIpGateway = async <T>(
});
const resp = await request.request<T>({
...requestConfig,
- httpsAgent
+ httpsAgent,
+ maxRedirects: 0
});
return resp.data;
};
@@ -206,7 +208,8 @@ export const executeF5BigIpOperationWithGateway = async <T>(
...requestCfg.headers,
Host: hostname
},
- httpsAgent
+ httpsAgent,
+ maxRedirects: 0
});
return resp.data;
};
@@ -231,7 +234,8 @@ export const executeF5BigIpOperationWithGateway = async <T>(
const makeRequest = async <R>(requestCfg: AxiosRequestConfig): Promise<R> => {
const resp = await request.request<R>({
...requestCfg,
- httpsAgent
+ httpsAgent,
+ maxRedirects: 0
});
return resp.data;
};
diff --git a/backend/src/services/certificate-sync/certificate-sync-dal.ts b/backend/src/services/certificate-sync/certificate-sync-dal.ts
index 50769c253a..88cd236309 100644
--- a/backend/src/services/certificate-sync/certificate-sync-dal.ts
+++ b/backend/src/services/certificate-sync/certificate-sync-dal.ts
@@ -70,6 +70,23 @@ export const certificateSyncDALFactory = (db: TDbClient) => {
}
};
+ const findExternalIdentifiersInUse = async (
+ externalIdentifiers: string[],
+ excludePkiSyncId: string,
+ tx?: Knex
+ ): Promise<Set<string>> => {
+ try {
+ if (externalIdentifiers.length === 0) return new Set();
+ const docs = (await (tx || db.replicaNode())(TableName.CertificateSync)
+ .whereIn("externalIdentifier", externalIdentifiers)
+ .andWhereNot({ pkiSyncId: excludePkiSyncId })
+ .select("externalIdentifier")) as Array<{ externalIdentifier: string | null }>;
+ return new Set(docs.map((doc) => doc.externalIdentifier).filter((v): v is string => Boolean(v)));
+ } catch (error) {
+ throw new DatabaseError({ error, name: "FindExternalIdentifiersInUse" });
+ }
+ };
+
const addCertificates = async (
pkiSyncId: string,
certificateData: Array<{ certificateId: string; externalIdentifier?: string }>,
@@ -312,6 +329,7 @@ export const certificateSyncDALFactory = (db: TDbClient) => {
findByPkiSyncAndCertificate,
findCertificateIdsByPkiSyncId,
findPkiSyncIdsByCertificateId,
+ findExternalIdentifiersInUse,
addCertificates,
removeCertificates,
removeAllCertificatesFromSync,
diff --git a/backend/src/services/pki-sync/f5-big-ip/f5-big-ip-pki-sync-fns.ts b/backend/src/services/pki-sync/f5-big-ip/f5-big-ip-pki-sync-fns.ts
index 982e6fcd44..46b86c4b87 100644
--- a/backend/src/services/pki-sync/f5-big-ip/f5-big-ip-pki-sync-fns.ts
+++ b/backend/src/services/pki-sync/f5-big-ip/f5-big-ip-pki-sync-fns.ts
@@ -43,6 +43,7 @@ type TF5BigIpPkiSyncFactoryDeps = {
| "updateById"
| "findByPkiSyncId"
| "updateSyncStatus"
+ | "findExternalIdentifiersInUse"
>;
certificateDAL: Pick<TCertificateDALFactory, "findById">;
gatewayV2Service?: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">;
@@ -204,6 +205,28 @@ const saveF5BigIpConfig = async (session: TF5BigIpSession): Promise<void> => {
const F5_BIG_IP_UPLOAD_CHUNK_SIZE_BYTES = 512 * 1024;
+const F5_BIG_IP_UPLOAD_DIR = "/var/config/rest/downloads";
+
+const cleanupUploadedSourceFile = async (session: TF5BigIpSession, filename: string): Promise<void> => {
+ try {
+ await session.makeRequest({
+ method: "POST",
+ url: `${session.baseUrl}/mgmt/tm/util/unix-rm`,
+ data: {
+ command: "run",
+ // `-f` so a missing file is not an error.
+ utilCmdArgs: `-f ${F5_BIG_IP_UPLOAD_DIR}/${filename}`
+ },
+ headers: session.headers
+ });
+ } catch (error: unknown) {
+ logger.warn(
+ { error },
+ `F5 BIG-IP: best-effort source-file cleanup failed for "${filename}" — likely insufficient role (Certificate Manager doesn't grant unix-rm); safe to ignore`
+ );
+ }
+};
+
const uploadFileToF5BigIp = async (session: TF5BigIpSession, filename: string, fileContent: string): Promise<void> => {
const buffer = Buffer.from(fileContent, "utf-8");
const size = buffer.length;
@@ -872,6 +895,12 @@ export const f5BigIpPkiSyncFactory = ({
await installSslCertObject(session, partition, chainName, certFileName(chainName));
}
+ await cleanupUploadedSourceFile(session, certFileName(targetName));
+ await cleanupUploadedSourceFile(session, keyFileName(targetName));
+ if (certificateChain && chainName) {
+ await cleanupUploadedSourceFile(session, certFileName(chainName));
+ }
+
if (profileType !== F5BigIpProfileType.None && profileName) {
await bindCertToProfile(
session,
@@ -966,26 +995,26 @@ export const f5BigIpPkiSyncFactory = ({
}
const managedCertNamePattern = buildManagedCertNamePattern(certificateNameSchema);
-
+ const partitionCandidates: string[] = [];
for (const certName of existingCertNames) {
if (
managedCertNamePattern.test(certName) &&
!activeExternalIdentifiers.has(certName) &&
+ !certNamesToRemove.has(certName) &&
!certName.endsWith(F5_BIG_IP_CHAIN_SUFFIX)
) {
- certNamesToRemove.add(certName);
+ partitionCandidates.push(certName);
}
}
- const chainNamesToRemove = new Set<string>();
- for (const certName of existingCertNames) {
- if (certName.endsWith(F5_BIG_IP_CHAIN_SUFFIX)) {
- const leafName = certName.slice(0, -F5_BIG_IP_CHAIN_SUFFIX.length);
- const isOrphan = !existingCertNames.has(leafName) && !activeExternalIdentifiers.has(certName);
- const matchesManagedPattern =
- managedCertNamePattern.test(certName) || managedCertNamePattern.test(leafName);
- if (isOrphan && matchesManagedPattern) {
- chainNamesToRemove.add(certName);
+ if (partitionCandidates.length > 0) {
+ const ownedByOtherSync = await certificateSyncDAL.findExternalIdentifiersInUse(
+ partitionCandidates,
+ pkiSync.id
+ );
+ for (const certName of partitionCandidates) {
+ if (!ownedByOtherSync.has(certName)) {
+ certNamesToRemove.add(certName);
}
}
}
@@ -1015,32 +1044,6 @@ export const f5BigIpPkiSyncFactory = ({
);
}
}
-
- for (const chainName of chainNamesToRemove) {
- try {
- await unbindCertPathsFromAllProfiles(session, partition, [buildPartitionedPath(partition, chainName)]);
- await deleteSslCertObject(session, partition, chainName);
-
- removed += 1;
-
- logger.info(
- `F5 BIG-IP PKI sync [syncId=${pkiSync.id}]: removed orphaned chain "${chainName}" from ${credentials.hostname}`
- );
- } catch (error: unknown) {
- let errorMessage = "Unknown error";
- if (error instanceof AxiosError) {
- errorMessage = String((error.response?.data as { message?: string })?.message || error.message);
- } else if (error instanceof Error) {
- errorMessage = error.message;
- }
- failedRemovals.push({ name: chainName, error: errorMessage });
-
- logger.error(
- { error },
- `F5 BIG-IP PKI sync [syncId=${pkiSync.id}]: failed to remove orphaned chain "${chainName}" — ${errorMessage}`
- );
- }
- }
}
await saveF5BigIpConfig(session);
diff --git a/backend/src/services/pki-sync/pki-sync-queue.ts b/backend/src/services/pki-sync/pki-sync-queue.ts
index 51ba996619..6314cdc25d 100644
--- a/backend/src/services/pki-sync/pki-sync-queue.ts
+++ b/backend/src/services/pki-sync/pki-sync-queue.ts
@@ -533,6 +533,23 @@ export const pkiSyncQueueFactory = ({
}
}
+ if (syncResult.details?.skippedCertificates) {
+ for (const skip of syncResult.details.skippedCertificates) {
+ const metadata = certificateMetadata.get(skip.name);
+ if (metadata) {
+ const updateIndex = postSyncUpdates.findIndex((u) => u.certificateId === metadata.id);
+ if (updateIndex >= 0) {
+ postSyncUpdates[updateIndex] = {
+ pkiSyncId: pkiSync.id,
+ certificateId: metadata.id,
+ status: CertificateSyncStatus.Failed,
+ message: `Certificate skipped: ${skip.reason}`
+ };
+ }
+ }
+ }
+ }
+
if (postSyncUpdates.length > 0) {
await certificateSyncDAL.bulkUpdateSyncStatus(postSyncUpdates);
}