Skip to content

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

Address PR comments

Carlos Monastyrskic9b253d4dedf
diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.ts
index 1d388ace23..798c2c3a35 100644
--- a/backend/src/ee/services/audit-log/audit-log-types.ts
+++ b/backend/src/ee/services/audit-log/audit-log-types.ts
@@ -459,6 +459,8 @@ export enum EventType {
PKI_SYNC_SYNC_CERTIFICATES = "pki-sync-sync-certificates",
PKI_SYNC_IMPORT_CERTIFICATES = "pki-sync-import-certificates",
PKI_SYNC_REMOVE_CERTIFICATES = "pki-sync-remove-certificates",
+ PKI_SYNC_SET_DEFAULT_CERTIFICATE = "pki-sync-set-default-certificate",
+ PKI_SYNC_CLEAR_DEFAULT_CERTIFICATE = "pki-sync-clear-default-certificate",
OIDC_GROUP_MEMBERSHIP_MAPPING_ASSIGN_USER = "oidc-group-membership-mapping-assign-user",
OIDC_GROUP_MEMBERSHIP_MAPPING_REMOVE_USER = "oidc-group-membership-mapping-remove-user",
CREATE_KMIP_CLIENT = "create-kmip-client",
@@ -3471,6 +3473,23 @@ interface PkiSyncRemoveCertificatesEvent {
};
}
+interface PkiSyncSetDefaultCertificateEvent {
+ type: EventType.PKI_SYNC_SET_DEFAULT_CERTIFICATE;
+ metadata: {
+ pkiSyncId: string;
+ name: string;
+ certificateId: string;
+ };
+}
+
+interface PkiSyncClearDefaultCertificateEvent {
+ type: EventType.PKI_SYNC_CLEAR_DEFAULT_CERTIFICATE;
+ metadata: {
+ pkiSyncId: string;
+ name: string;
+ };
+}
+
interface OidcGroupMembershipMappingAssignUserEvent {
type: EventType.OIDC_GROUP_MEMBERSHIP_MAPPING_ASSIGN_USER;
metadata: {
@@ -5195,6 +5214,8 @@ export type Event =
| PkiSyncSyncCertificatesEvent
| PkiSyncImportCertificatesEvent
| PkiSyncRemoveCertificatesEvent
+ | PkiSyncSetDefaultCertificateEvent
+ | PkiSyncClearDefaultCertificateEvent
| OidcGroupMembershipMappingAssignUserEvent
| OidcGroupMembershipMappingRemoveUserEvent
| CreateKmipClientEvent
diff --git a/backend/src/server/routes/v1/pki-sync-routers/aws-elastic-load-balancer-pki-sync-router.ts b/backend/src/server/routes/v1/pki-sync-routers/aws-elastic-load-balancer-pki-sync-router.ts
index 462670ddb2..2c99370f88 100644
--- a/backend/src/server/routes/v1/pki-sync-routers/aws-elastic-load-balancer-pki-sync-router.ts
+++ b/backend/src/server/routes/v1/pki-sync-routers/aws-elastic-load-balancer-pki-sync-router.ts
@@ -4,6 +4,7 @@ import { EventType } from "@app/ee/services/audit-log/audit-log-types";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { AWSRegion } from "@app/services/app-connection/app-connection-enums";
+import { AwsLoadBalancerType } from "@app/services/app-connection/aws/aws-connection-enums";
import { AuthMode } from "@app/services/auth/auth-type";
import {
AWS_ELASTIC_LOAD_BALANCER_PKI_SYNC_LIST_OPTION,
@@ -52,7 +53,7 @@ export const registerAwsElasticLoadBalancerPkiSyncRouter = async (
z.object({
loadBalancerArn: z.string(),
loadBalancerName: z.string(),
- type: z.enum(["application", "network", "gateway"]),
+ type: z.nativeEnum(AwsLoadBalancerType),
scheme: z.string(),
state: z.string(),
vpcId: z.string().optional(),
@@ -127,7 +128,7 @@ export const registerAwsElasticLoadBalancerPkiSyncRouter = async (
server.route({
method: "POST",
- url: "/:pkiSyncId/certificates/:certificateId/set-default",
+ url: "/:pkiSyncId/certificates/:certificateId/default",
config: {
rateLimit: writeLimit
},
@@ -159,10 +160,11 @@ export const registerAwsElasticLoadBalancerPkiSyncRouter = async (
...req.auditLogInfo,
projectId: pkiSyncInfo.projectId,
event: {
- type: EventType.UPDATE_PKI_SYNC,
+ type: EventType.PKI_SYNC_SET_DEFAULT_CERTIFICATE,
metadata: {
pkiSyncId,
- name: pkiSyncInfo.name
+ name: pkiSyncInfo.name,
+ certificateId
}
}
});
@@ -173,7 +175,7 @@ export const registerAwsElasticLoadBalancerPkiSyncRouter = async (
server.route({
method: "DELETE",
- url: "/:pkiSyncId/default-certificate",
+ url: "/:pkiSyncId/certificates/default",
config: {
rateLimit: writeLimit
},
@@ -204,7 +206,7 @@ export const registerAwsElasticLoadBalancerPkiSyncRouter = async (
...req.auditLogInfo,
projectId: pkiSyncInfo.projectId,
event: {
- type: EventType.UPDATE_PKI_SYNC,
+ type: EventType.PKI_SYNC_CLEAR_DEFAULT_CERTIFICATE,
metadata: {
pkiSyncId,
name: pkiSyncInfo.name
diff --git a/backend/src/services/app-connection/aws/aws-connection-enums.ts b/backend/src/services/app-connection/aws/aws-connection-enums.ts
index 0b571de0c8..1e125aa07a 100644
--- a/backend/src/services/app-connection/aws/aws-connection-enums.ts
+++ b/backend/src/services/app-connection/aws/aws-connection-enums.ts
@@ -2,3 +2,9 @@ export enum AwsConnectionMethod {
AssumeRole = "assume-role",
AccessKey = "access-key"
}
+
+export enum AwsLoadBalancerType {
+ Application = "application",
+ Network = "network",
+ Gateway = "gateway"
+}
diff --git a/backend/src/services/app-connection/aws/aws-connection-service.ts b/backend/src/services/app-connection/aws/aws-connection-service.ts
index ca68cda0c4..0ef44cb80a 100644
--- a/backend/src/services/app-connection/aws/aws-connection-service.ts
+++ b/backend/src/services/app-connection/aws/aws-connection-service.ts
@@ -8,6 +8,7 @@ import {
TListAwsConnectionListeners,
TListAwsConnectionLoadBalancers
} from "@app/services/app-connection/app-connection-types";
+import { AwsLoadBalancerType } from "@app/services/app-connection/aws/aws-connection-enums";
import { getAwsConnectionConfig } from "@app/services/app-connection/aws/aws-connection-fns";
import { TAwsConnection } from "@app/services/app-connection/aws/aws-connection-types";
import { SecretSync } from "@app/services/secret-sync/secret-sync-enums";
@@ -95,7 +96,7 @@ const listAwsIamUsers = async (appConnection: TAwsConnection) => {
export type TAwsLoadBalancerInfo = {
loadBalancerArn: string;
loadBalancerName: string;
- type: "application" | "network" | "gateway";
+ type: AwsLoadBalancerType;
scheme: string;
state: string;
vpcId?: string;
@@ -139,11 +140,11 @@ const listAwsLoadBalancers = async (
if (response.LoadBalancers) {
for (const lb of response.LoadBalancers) {
if (lb.LoadBalancerArn && lb.LoadBalancerName && lb.Type) {
- if (lb.Type === "application" || lb.Type === "network") {
+ if (lb.Type === AwsLoadBalancerType.Application || lb.Type === AwsLoadBalancerType.Network) {
loadBalancers.push({
loadBalancerArn: lb.LoadBalancerArn,
loadBalancerName: lb.LoadBalancerName,
- type: lb.Type as "application" | "network",
+ type: lb.Type as AwsLoadBalancerType,
scheme: lb.Scheme || "unknown",
state: lb.State?.Code || "unknown",
vpcId: lb.VpcId,
diff --git a/backend/src/services/certificate-sync/certificate-sync-dal.ts b/backend/src/services/certificate-sync/certificate-sync-dal.ts
index 1e8532f519..50769c253a 100644
--- a/backend/src/services/certificate-sync/certificate-sync-dal.ts
+++ b/backend/src/services/certificate-sync/certificate-sync-dal.ts
@@ -16,7 +16,7 @@ export const certificateSyncDALFactory = (db: TDbClient) => {
const findByPkiSyncId = async (pkiSyncId: string, tx?: Knex) => {
try {
- const docs = await (tx || db)(TableName.CertificateSync)
+ const docs = await (tx || db.replicaNode())(TableName.CertificateSync)
.where({ pkiSyncId })
.select(selectAllTableCols(TableName.CertificateSync));
return docs;
@@ -38,7 +38,7 @@ export const certificateSyncDALFactory = (db: TDbClient) => {
const findByPkiSyncAndCertificate = async (pkiSyncId: string, certificateId: string, tx?: Knex) => {
try {
- const doc = await (tx || db)(TableName.CertificateSync)
+ const doc = await (tx || db.replicaNode())(TableName.CertificateSync)
.where({ pkiSyncId, certificateId })
.select(selectAllTableCols(TableName.CertificateSync))
.first();
@@ -187,6 +187,18 @@ export const certificateSyncDALFactory = (db: TDbClient) => {
}
};
+ /**
+ * Removes a specific flag/key from the syncMetadata JSONB column for all certificate_sync records
+ * belonging to a given pkiSyncId.
+ *
+ * This is used, for example, to clear the "isDefault" flag from all certificates when the default
+ * certificate is changed or cleared.
+ *
+ * The SQL logic:
+ * 1. Filters records where syncMetadata is not null and contains the specified flag
+ * 2. Removes the flag from the JSONB object using the `-` operator
+ * 3. If removing the flag results in an empty object `{}`, sets the column to NULL instead
+ */
const clearSyncMetadataFlag = async (pkiSyncId: string, flag: string, tx?: Knex): Promise<void> => {
try {
await (tx || db)(TableName.CertificateSync)
diff --git a/backend/src/services/certificate-sync/certificate-sync-schemas.ts b/backend/src/services/certificate-sync/certificate-sync-schemas.ts
index 13a3632a72..aa823c18c9 100644
--- a/backend/src/services/certificate-sync/certificate-sync-schemas.ts
+++ b/backend/src/services/certificate-sync/certificate-sync-schemas.ts
@@ -14,13 +14,7 @@ export type TAwsElbSyncMetadata = z.infer<typeof AwsElbSyncMetadataSchema>;
export const BaseSyncMetadataSchema = z.object({}).catchall(z.unknown());
-export const SyncMetadataSchema = z
- .object({
- isDefault: z.boolean().optional()
- })
- .catchall(z.unknown())
- .nullable()
- .optional();
+export const SyncMetadataSchema = AwsElbSyncMetadataSchema.extend({}).catchall(z.unknown()).nullable().optional();
export type TSyncMetadata = z.infer<typeof SyncMetadataSchema>;
diff --git a/docs/documentation/platform/pki/certificate-syncs/aws-elastic-load-balancer.mdx b/docs/documentation/platform/pki/certificate-syncs/aws-elastic-load-balancer.mdx
index c13fc2f2b2..8b98b4a5d3 100644
--- a/docs/documentation/platform/pki/certificate-syncs/aws-elastic-load-balancer.mdx
+++ b/docs/documentation/platform/pki/certificate-syncs/aws-elastic-load-balancer.mdx
@@ -3,6 +3,8 @@ title: "AWS Elastic Load Balancer"
description: "Learn how to configure an AWS Elastic Load Balancer Certificate Sync for Infisical PKI."
---
+The AWS Elastic Load Balancer Certificate Sync allows you to automatically deploy and manage TLS/SSL certificates on your AWS Application Load Balancers (ALBs) and Network Load Balancers (NLBs). Certificates are first imported into AWS Certificate Manager (ACM) and then attached to your configured listeners, enabling secure HTTPS/TLS traffic to your load balancers with automatic certificate lifecycle management.
+
**Prerequisites:**
- Create an [AWS Connection](/integrations/app-connections/aws)
@@ -164,7 +166,7 @@ You can set a certificate as the default for all configured listeners. The defau
```bash Request
curl --request POST \
- --url https://app.infisical.com/api/v1/cert-manager/syncs/aws-elastic-load-balancer/{pkiSyncId}/certificates/{certificateId}/set-default \
+ --url https://app.infisical.com/api/v1/cert-manager/syncs/aws-elastic-load-balancer/{pkiSyncId}/certificates/{certificateId}/default \
--header 'Authorization: Bearer <access-token>'
```
@@ -172,7 +174,7 @@ You can set a certificate as the default for all configured listeners. The defau
```bash Request
curl --request DELETE \
- --url https://app.infisical.com/api/v1/cert-manager/syncs/aws-elastic-load-balancer/{pkiSyncId}/default-certificate \
+ --url https://app.infisical.com/api/v1/cert-manager/syncs/aws-elastic-load-balancer/{pkiSyncId}/certificates/default \
--header 'Authorization: Bearer <access-token>'
```
</Tab>
diff --git a/docs/integrations/app-connections/aws.mdx b/docs/integrations/app-connections/aws.mdx
index fc9f6722ef..3d0dc8f1c1 100644
--- a/docs/integrations/app-connections/aws.mdx
+++ b/docs/integrations/app-connections/aws.mdx
@@ -214,6 +214,58 @@ Infisical supports two methods for connecting to AWS.
- Tag-related permissions: Manages certificate tags for identification and organization
</Note>
</Accordion>
+ <Accordion title="AWS Elastic Load Balancer">
+ Use the following custom policy to grant the minimum permissions required by Infisical to sync certificates to AWS Elastic Load Balancers:
+
+ ```json
+ {
+ "Version": "2012-10-17",
+ "Statement": [
+ {
+ "Sid": "AllowCertificateManagerAccess",
+ "Effect": "Allow",
+ "Action": [
+ "acm:ListCertificates",
+ "acm:DescribeCertificate",
+ "acm:ImportCertificate",
+ "acm:DeleteCertificate",
+ "acm:ListTagsForCertificate"
+ ],
+ "Resource": "*"
+ },
+ {
+ "Sid": "AllowElasticLoadBalancerAccess",
+ "Effect": "Allow",
+ "Action": [
+ "elasticloadbalancing:DescribeLoadBalancers",
+ "elasticloadbalancing:DescribeListeners",
+ "elasticloadbalancing:DescribeListenerCertificates",
+ "elasticloadbalancing:AddListenerCertificates",
+ "elasticloadbalancing:RemoveListenerCertificates",
+ "elasticloadbalancing:ModifyListener"
+ ],
+ "Resource": "*"
+ }
+ ]
+ }
+ ```
+ <Note>
+ **ACM Permissions:**
+ - **ListCertificates**: Lists all certificates in the account
+ - **ImportCertificate**: Imports certificates from Infisical into AWS Certificate Manager
+ - **DeleteCertificate**: Removes certificates that are no longer managed by Infisical
+ - **DescribeCertificate**: Retrieves certificate details for comparison during sync
+ - **ListTagsForCertificate**: Retrieves certificate tags for identification
+
+ **ELB Permissions:**
+ - **DescribeLoadBalancers**: Lists available load balancers for selection
+ - **DescribeListeners**: Lists HTTPS/TLS listeners on load balancers
+ - **DescribeListenerCertificates**: Lists certificates attached to listeners
+ - **AddListenerCertificates**: Attaches certificates to listeners
+ - **RemoveListenerCertificates**: Removes certificates from listeners
+ - **ModifyListener**: Sets the default certificate on listeners
+ </Note>
+ </Accordion>
</AccordionGroup>
</Tab>
</Tabs>
@@ -430,6 +482,58 @@ Infisical supports two methods for connecting to AWS.
- Tag-related permissions: Manages certificate tags for identification and organization
</Note>
</Accordion>
+ <Accordion title="AWS Elastic Load Balancer">
+ Use the following custom policy to grant the minimum permissions required by Infisical to sync certificates to AWS Elastic Load Balancers:
+
+ ```json
+ {
+ "Version": "2012-10-17",
+ "Statement": [
+ {
+ "Sid": "AllowCertificateManagerAccess",
+ "Effect": "Allow",
+ "Action": [
+ "acm:ListCertificates",
+ "acm:DescribeCertificate",
+ "acm:ImportCertificate",
+ "acm:DeleteCertificate",
+ "acm:ListTagsForCertificate"
+ ],
+ "Resource": "*"
+ },
+ {
+ "Sid": "AllowElasticLoadBalancerAccess",
+ "Effect": "Allow",
+ "Action": [
+ "elasticloadbalancing:DescribeLoadBalancers",
+ "elasticloadbalancing:DescribeListeners",
+ "elasticloadbalancing:DescribeListenerCertificates",
+ "elasticloadbalancing:AddListenerCertificates",
+ "elasticloadbalancing:RemoveListenerCertificates",
+ "elasticloadbalancing:ModifyListener"
+ ],
+ "Resource": "*"
+ }
+ ]
+ }
+ ```
+ <Note>
+ **ACM Permissions:**
+ - **ListCertificates**: Lists all certificates in the account
+ - **ImportCertificate**: Imports certificates from Infisical into AWS Certificate Manager
+ - **DeleteCertificate**: Removes certificates that are no longer managed by Infisical
+ - **DescribeCertificate**: Retrieves certificate details for comparison during sync
+ - **ListTagsForCertificate**: Retrieves certificate tags for identification
+
+ **ELB Permissions:**
+ - **DescribeLoadBalancers**: Lists available load balancers for selection
+ - **DescribeListeners**: Lists HTTPS/TLS listeners on load balancers
+ - **DescribeListenerCertificates**: Lists certificates attached to listeners
+ - **AddListenerCertificates**: Attaches certificates to listeners
+ - **RemoveListenerCertificates**: Removes certificates from listeners
+ - **ModifyListener**: Sets the default certificate on listeners
+ </Note>
+ </Accordion>
</AccordionGroup>
</Tab>
</Tabs>
diff --git a/frontend/src/components/pki-syncs/forms/AwsElasticLoadBalancerPkiSyncFields.tsx b/frontend/src/components/pki-syncs/forms/AwsElasticLoadBalancerPkiSyncFields.tsx
index 796628f5c5..b2cecb60be 100644
--- a/frontend/src/components/pki-syncs/forms/AwsElasticLoadBalancerPkiSyncFields.tsx
+++ b/frontend/src/components/pki-syncs/forms/AwsElasticLoadBalancerPkiSyncFields.tsx
@@ -6,8 +6,8 @@ import { AWS_REGIONS } from "@app/helpers/appConnections";
import {
PkiSync,
TAwsListener,
- useAwsListeners,
- useAwsLoadBalancers
+ useListAwsListeners,
+ useListAwsLoadBalancers
} from "@app/hooks/api/pkiSyncs";
import { TPkiSyncForm } from "./schemas/pki-sync-schema";
@@ -74,12 +74,12 @@ export const AwsElasticLoadBalancerPkiSyncFields = () => {
name: "destinationConfig.listeners"
});
- const { data: loadBalancers, isLoading: isLoadingLoadBalancers } = useAwsLoadBalancers(
+ const { data: loadBalancers, isLoading: isLoadingLoadBalancers } = useListAwsLoadBalancers(
{ connectionId, region },
{ enabled: !!connectionId && !!region }
);
- const { data: listeners, isLoading: isLoadingListeners } = useAwsListeners(
+ const { data: listeners, isLoading: isLoadingListeners } = useListAwsListeners(
{ connectionId, region, loadBalancerArn },
{ enabled: !!connectionId && !!region && !!loadBalancerArn }
);
diff --git a/frontend/src/components/pki-syncs/forms/PkiSyncOptionsFields/PkiSyncOptionsFields.tsx b/frontend/src/components/pki-syncs/forms/PkiSyncOptionsFields/PkiSyncOptionsFields.tsx
index 9568e91c0b..2f7ef852e3 100644
--- a/frontend/src/components/pki-syncs/forms/PkiSyncOptionsFields/PkiSyncOptionsFields.tsx
+++ b/frontend/src/components/pki-syncs/forms/PkiSyncOptionsFields/PkiSyncOptionsFields.tsx
@@ -83,7 +83,10 @@ export const PkiSyncOptionsFields = ({ destination }: Props) => {
{currentDestination === PkiSync.AwsElasticLoadBalancer && (
<p className="mt-4">
For AWS Elastic Load Balancer, this will remove the certificate from both
- the load balancer listeners and AWS Certificate Manager.
+ the load balancer listeners and AWS Certificate Manager. This only affects
+ certificates managed by this specific sync and will not interfere with
+ certificates managed by other syncs (such as ACM syncs or other ELB
+ syncs).
</p>
)}
<p className="mt-4">
diff --git a/frontend/src/hooks/api/pkiSyncs/mutations.tsx b/frontend/src/hooks/api/pkiSyncs/mutations.tsx
index 4364391bbe..32cb9d2dc5 100644
--- a/frontend/src/hooks/api/pkiSyncs/mutations.tsx
+++ b/frontend/src/hooks/api/pkiSyncs/mutations.tsx
@@ -272,7 +272,7 @@ export const useSetCertificateAsDefault = () => {
destination: string;
}) => {
const { data } = await apiRequest.post<{ message: string }>(
- `/api/v1/cert-manager/syncs/${destination}/${pkiSyncId}/certificates/${certificateId}/set-default`
+ `/api/v1/cert-manager/syncs/${destination}/${pkiSyncId}/certificates/${certificateId}/default`
);
return data;
@@ -288,7 +288,7 @@ export const useClearDefaultCertificate = () => {
return useMutation({
mutationFn: async ({ pkiSyncId, destination }: { pkiSyncId: string; destination: string }) => {
const { data } = await apiRequest.delete<{ message: string }>(
- `/api/v1/cert-manager/syncs/${destination}/${pkiSyncId}/default-certificate`
+ `/api/v1/cert-manager/syncs/${destination}/${pkiSyncId}/certificates/default`
);
return data;
diff --git a/frontend/src/hooks/api/pkiSyncs/queries.tsx b/frontend/src/hooks/api/pkiSyncs/queries.tsx
index e9c90f42ab..1d1f5ad5e6 100644
--- a/frontend/src/hooks/api/pkiSyncs/queries.tsx
+++ b/frontend/src/hooks/api/pkiSyncs/queries.tsx
@@ -158,7 +158,7 @@ export const useListPkiSyncCertificates = (
});
};
-export const useAwsLoadBalancers = (
+export const useListAwsLoadBalancers = (
{ connectionId, region }: { connectionId: string; region: string },
options?: Omit<
UseQueryOptions<
@@ -186,7 +186,7 @@ export const useAwsLoadBalancers = (
});
};
-export const useAwsListeners = (
+export const useListAwsListeners = (
{
connectionId,
region,