Skip to content

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

Address greptile comments

Carlos Monastyrskiaa9bb9d87c2b
diff --git a/backend/src/services/app-connection/palo-alto-networks/palo-alto-networks-connection-fns.ts b/backend/src/services/app-connection/palo-alto-networks/palo-alto-networks-connection-fns.ts
index 3965c3ccce..8c4ec77074 100644
--- a/backend/src/services/app-connection/palo-alto-networks/palo-alto-networks-connection-fns.ts
+++ b/backend/src/services/app-connection/palo-alto-networks/palo-alto-networks-connection-fns.ts
@@ -13,7 +13,7 @@ import { getMissingGatewayMessage } from "@app/lib/gateway-v2/gateway-errors";
import { withGatewayV2Proxy } from "@app/lib/gateway-v2/gateway-v2";
import { GatewayProxyProtocol } from "@app/lib/gateway-v2/types";
import { RETRYABLE_NETWORK_ERRORS } from "@app/lib/retry/network-errors";
-import { blockLocalAndPrivateIpAddresses, safeRequest } from "@app/lib/validator";
+import { safeRequest } from "@app/lib/validator";
import { getSharedHttpsAgent } from "@app/lib/validator/safe-request";
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
@@ -116,8 +116,6 @@ const executePaloAltoNetworksOperationWithGateway = async <T>(
throw new BadRequestError({ message: getMissingGatewayMessage(gatewayId) });
}
- await blockLocalAndPrivateIpAddresses(`https://${hostname}`, true);
-
const platformConnectionDetails = await gatewayV2Service.getPlatformConnectionDetailsByGatewayId({
gatewayId,
targetHost: hostname,
diff --git a/backend/src/services/certificate-sync/certificate-sync-dal.ts b/backend/src/services/certificate-sync/certificate-sync-dal.ts
index 4318bf6f3d..4220eeaabe 100644
--- a/backend/src/services/certificate-sync/certificate-sync-dal.ts
+++ b/backend/src/services/certificate-sync/certificate-sync-dal.ts
@@ -72,7 +72,11 @@ export const certificateSyncDALFactory = (db: TDbClient) => {
const findExternalIdentifiersInUse = async (
externalIdentifiers: string[],
- { excludePkiSyncId, destination }: { excludePkiSyncId: string; destination: string | string[] },
+ {
+ excludePkiSyncId,
+ destination,
+ connectionId
+ }: { excludePkiSyncId: string; destination: string | string[]; connectionId?: string },
tx?: Knex
): Promise<Set<string>> => {
try {
@@ -83,6 +87,9 @@ export const certificateSyncDALFactory = (db: TDbClient) => {
.whereIn(`${TableName.CertificateSync}.externalIdentifier`, externalIdentifiers)
.whereIn(`${TableName.PkiSync}.destination`, destinations)
.whereNot(`${TableName.CertificateSync}.pkiSyncId`, excludePkiSyncId)
+ .where((qb) => {
+ if (connectionId) void qb.where(`${TableName.PkiSync}.connectionId`, connectionId);
+ })
.select(`${TableName.CertificateSync}.externalIdentifier`)) as Array<{ externalIdentifier: string | null }>;
return new Set(docs.map((doc) => doc.externalIdentifier).filter((v): v is string => Boolean(v)));
} catch (error) {
diff --git a/backend/src/services/pki-sync/palo-alto-networks/palo-alto-networks-pki-sync-fns.ts b/backend/src/services/pki-sync/palo-alto-networks/palo-alto-networks-pki-sync-fns.ts
index 2aca36a32e..e62fc496c4 100644
--- a/backend/src/services/pki-sync/palo-alto-networks/palo-alto-networks-pki-sync-fns.ts
+++ b/backend/src/services/pki-sync/palo-alto-networks/palo-alto-networks-pki-sync-fns.ts
@@ -300,6 +300,7 @@ type TPlannedUpload = TCertificateMap[string] & {
mapKey: string;
name: string;
oldCertificateIdToRemove?: string;
+ replacedName?: string;
};
type TSyncFailure = { name: string; error: string };
@@ -350,6 +351,7 @@ const planUploads = ({
let name = mapKey;
let oldCertificateIdToRemove: string | undefined;
+ let replacedName: string | undefined;
if (certificateId) {
const renewedFromRecord = certificate?.renewedFromCertificateId
@@ -361,6 +363,7 @@ const planUploads = ({
name = renewedFromRecord.externalIdentifier;
oldCertificateIdToRemove = certificate?.renewedFromCertificateId ?? undefined;
} else if (certificate?.renewedFromCertificateId && !preserveItemOnRenewal) {
+ replacedName = renewedFromRecord?.externalIdentifier ?? directRecord?.externalIdentifier ?? undefined;
name = compileCertificateNameSchema(
certificateNameSchema ?? PALO_ALTO_NETWORKS_PKI_SYNC_LIST_OPTION.defaultCertificateNameSchema,
{
@@ -378,7 +381,7 @@ const planUploads = ({
}
activeNames.add(name);
- plannedUploads.push({ ...certData, mapKey, name, oldCertificateIdToRemove });
+ plannedUploads.push({ ...certData, mapKey, name, oldCertificateIdToRemove, replacedName });
}
return { plannedUploads, activeNames, skippedCertificates };
@@ -443,6 +446,13 @@ export const paloAltoNetworksPkiSyncFactory = ({
type TDeployPendingMarker = ReturnType<typeof createDeployPendingMarker>;
+ const findNamesOwnedByOtherSyncs = (pkiSync: TPkiSyncWithCredentials, names: string[]) =>
+ certificateSyncDAL.findExternalIdentifiersInUse(names, {
+ excludePkiSyncId: pkiSync.id,
+ destination: PALO_ALTO_NETWORKS_PKI_SYNC_DESTINATIONS,
+ connectionId: pkiSync.connectionId
+ });
+
const finishDeploy = async ({
client,
config,
@@ -491,13 +501,13 @@ export const paloAltoNetworksPkiSyncFactory = ({
const succeeded: TPlannedUpload[] = [];
const failedUploads: TSyncFailure[] = [];
let hasDeviceChanges = false;
- if (plannedUploads.length) await deployPending.mark();
for (const upload of plannedUploads) {
try {
if (upload.certificateId) {
await certificateSyncDAL.claimExternalIdentifier(pkiSyncId, upload.certificateId, upload.name);
}
+ await deployPending.mark();
const importedCa = await importCaChain(
client,
@@ -571,10 +581,7 @@ export const paloAltoNetworksPkiSyncFactory = ({
});
}
- const ownedByOtherSync = await certificateSyncDAL.findExternalIdentifiersInUse([...candidates], {
- excludePkiSyncId: pkiSync.id,
- destination: PALO_ALTO_NETWORKS_PKI_SYNC_DESTINATIONS
- });
+ const ownedByOtherSync = await findNamesOwnedByOtherSyncs(pkiSync, [...candidates]);
for (const name of candidates) {
// eslint-disable-next-line no-continue
@@ -655,6 +662,11 @@ export const paloAltoNetworksPkiSyncFactory = ({
});
let { hasDeviceChanges } = imports;
+ const importedKeys = new Set(imports.succeeded.map((upload) => upload.mapKey));
+ plannedUploads
+ .filter((upload) => upload.replacedName && !importedKeys.has(upload.mapKey))
+ .forEach((upload) => activeNames.add(upload.replacedName as string));
+
const profileTarget = config.sslTlsServiceProfileName
? getNewestLinkedUpload(imports.succeeded, syncRecordsByCertId)
: undefined;
@@ -736,6 +748,11 @@ export const paloAltoNetworksPkiSyncFactory = ({
.filter((record) => record.certificateId && !targetCertificateIds.has(record.certificateId))
.sort((a, b) => (b.createdAt?.getTime() ?? 0) - (a.createdAt?.getTime() ?? 0));
+ const ownedByOtherSync = await findNamesOwnedByOtherSyncs(
+ pkiSync,
+ targets.map((target) => target.externalIdentifier)
+ );
+
const deferredCertificateIds = await withClient(pkiSync, async (client, panorama, config) => {
const [existingCertificates, profileCertificate] = await Promise.all([
listCertificates(client, config),
@@ -768,8 +785,14 @@ export const paloAltoNetworksPkiSyncFactory = ({
}
for (const { externalIdentifier, certificateId } of targets) {
- // eslint-disable-next-line no-continue
- if (deferred.has(certificateId) || !existingCertificates.has(externalIdentifier)) continue;
+ if (
+ deferred.has(certificateId) ||
+ ownedByOtherSync.has(externalIdentifier) ||
+ !existingCertificates.has(externalIdentifier)
+ ) {
+ // eslint-disable-next-line no-continue
+ continue;
+ }
await deployPending.mark();
try {
await client.deleteConfig(getCertificateEntryXpath(config, externalIdentifier));
diff --git a/backend/src/services/pki-sync/palo-alto-networks/palo-alto-networks-pki-sync-schemas.ts b/backend/src/services/pki-sync/palo-alto-networks/palo-alto-networks-pki-sync-schemas.ts
index 9174aae57b..b5e6ffde02 100644
--- a/backend/src/services/pki-sync/palo-alto-networks/palo-alto-networks-pki-sync-schemas.ts
+++ b/backend/src/services/pki-sync/palo-alto-networks/palo-alto-networks-pki-sync-schemas.ts
@@ -49,7 +49,7 @@ const buildPaloAltoNetworksPkiSyncSchemas = <TDestination extends PkiSync, TConf
syncOptions: PaloAltoNetworksPkiSyncOptionsSchema,
subscriberId: z.string().uuid().nullish(),
connectionId: z.string().uuid(),
- projectId: z.string().trim().min(1).optional().describe(openApiHidden()),
+ projectId: z.string().trim().uuid().optional().describe(openApiHidden()),
applicationId: z.string().uuid().optional(),
certificateIds: z.array(z.string().uuid()).optional(),
filters: PkiSyncFiltersField
diff --git a/backend/src/services/pki-sync/pki-sync-fns.ts b/backend/src/services/pki-sync/pki-sync-fns.ts
index 75d9d4d319..7498d4111e 100644
--- a/backend/src/services/pki-sync/pki-sync-fns.ts
+++ b/backend/src/services/pki-sync/pki-sync-fns.ts
@@ -47,6 +47,7 @@ import { netScalerPkiSyncFactory } from "./netscaler/netscaler-pki-sync-fns";
import { NUTANIX_PRISM_CENTRAL_PKI_SYNC_LIST_OPTION } from "./nutanix-prism-central/nutanix-prism-central-pki-sync-constants";
import { nutanixPrismCentralPkiSyncFactory } from "./nutanix-prism-central/nutanix-prism-central-pki-sync-fns";
import {
+ PALO_ALTO_NETWORKS_PKI_SYNC_DESTINATIONS,
PALO_ALTO_NETWORKS_PKI_SYNC_LIST_OPTION,
PALO_ALTO_NETWORKS_SSL_TLS_PROFILE_PKI_SYNC_LIST_OPTION
} from "./palo-alto-networks/palo-alto-networks-pki-sync-constants";
@@ -133,6 +134,11 @@ export const listPkiSyncOptions = () => {
.sort((a, b) => a.name.localeCompare(b.name));
};
+const CONNECTION_SERIALISED_PKI_SYNC_DESTINATIONS = new Set<PkiSync>(PALO_ALTO_NETWORKS_PKI_SYNC_DESTINATIONS);
+
+export const isPkiSyncSerialisedPerConnection = (destination: PkiSync) =>
+ CONNECTION_SERIALISED_PKI_SYNC_DESTINATIONS.has(destination);
+
export const getPkiSyncProviderCapabilities = (destination: PkiSync) => {
const providerOption = PKI_SYNC_LIST_OPTIONS[destination];
if (!providerOption) {
diff --git a/backend/src/services/pki-sync/pki-sync-queue.ts b/backend/src/services/pki-sync/pki-sync-queue.ts
index c62df136dc..f559f63102 100644
--- a/backend/src/services/pki-sync/pki-sync-queue.ts
+++ b/backend/src/services/pki-sync/pki-sync-queue.ts
@@ -37,6 +37,7 @@ import { notifyPkiSyncFailure } from "./pki-sync-failure-notification-fns";
import { withPkiSyncFilterLock } from "./pki-sync-filter-reconcile-fns";
import {
getPkiSyncProviderCapabilities,
+ isPkiSyncSerialisedPerConnection,
parsePkiSyncErrorMessage,
PkiSyncFns,
truncateSyncMessage
@@ -846,7 +847,9 @@ export const pkiSyncQueueFactory = ({
const needsConnectionSlot = job.name === QueueJobs.PkiSyncSyncCertificates;
const needsHostSerialisation =
- needsConnectionSlot && getPkiSyncProviderCapabilities(pkiSync.destination).canRunHealthCheckCommand;
+ (needsConnectionSlot && getPkiSyncProviderCapabilities(pkiSync.destination).canRunHealthCheckCommand) ||
+ (isPkiSyncSerialisedPerConnection(pkiSync.destination) &&
+ (job.name === QueueJobs.PkiSyncSyncCertificates || job.name === QueueJobs.PkiSyncRemoveCertificates));
const targetHost = getPkiSyncTargetHost(pkiSync.destinationConfig);
diff --git a/frontend/src/components/pki-syncs/forms/schemas/palo-alto-networks-pki-sync-destination-schema.ts b/frontend/src/components/pki-syncs/forms/schemas/palo-alto-networks-pki-sync-destination-schema.ts
index b466176af3..96562beee2 100644
--- a/frontend/src/components/pki-syncs/forms/schemas/palo-alto-networks-pki-sync-destination-schema.ts
+++ b/frontend/src/components/pki-syncs/forms/schemas/palo-alto-networks-pki-sync-destination-schema.ts
@@ -53,15 +53,11 @@ const PaloAltoNetworksSyncOptionsSchema = z.object({
.replace(/\{\{applicationId\}\}/g, "0".repeat(32))
.replace(/\{\{applicationName\}\}/g, "application-name")
.replace(/\{\{commonName\}\}/g, "common-name").length;
- const lengthIsValid = compiledLength <= 31;
-
- const certificateIdIsPresent =
- val.includes("{{certificateId}}") || val.includes("{{shortCertificateId}}");
- return contentIsValid && certificateIdIsPresent && lengthIsValid;
+ return contentIsValid && compiledLength <= 31;
},
{
message:
- "Certificate name schema must include {{shortCertificateId}} and be at most 31 characters once placeholders are filled in ({{shortCertificateId}} counts as 22). It can also use {{applicationName}} and {{commonName}}. Outside placeholders, use only letters, numbers, hyphens (-), and underscores (_)."
+ "Certificate name schema must be at most 31 characters once placeholders are filled in ({{shortCertificateId}} counts as 22). Outside placeholders, use only letters, numbers, hyphens (-), and underscores (_). A name without {{shortCertificateId}} can hold only one certificate."
}
)
});
diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/PaloAltoNetworksConnectionForm.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/PaloAltoNetworksConnectionForm.tsx
index 97f12777a1..c48dc2941c 100644
--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/PaloAltoNetworksConnectionForm.tsx
+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/PaloAltoNetworksConnectionForm.tsx
@@ -331,7 +331,6 @@ export const PaloAltoNetworksConnectionForm = ({ appConnection, onSubmit }: Prop
</FieldLabel>
<TextArea
id="ssl-certificate"
- className="h-[3.6rem] resize-none!"
{...field}
placeholder="-----BEGIN CERTIFICATE----- ... -----END CERTIFICATE-----"
isError={Boolean(error?.message)}