Skip to content

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

feat(gateway): audit the auth method at resource creation

bernie-gcc2934f29996
diff --git a/backend/src/ee/routes/v1/kmip-server-router.ts b/backend/src/ee/routes/v1/kmip-server-router.ts
index c6b41f7200..6be4e25719 100644
--- a/backend/src/ee/routes/v1/kmip-server-router.ts
+++ b/backend/src/ee/routes/v1/kmip-server-router.ts
@@ -152,6 +152,21 @@ export const registerKmipServerRouter = async (server: FastifyZodProvider) => {
}
});
+ await server.services.auditLog.createAuditLog({
+ ...req.auditLogInfo,
+ orgId: req.permission.orgId,
+ event: {
+ type: EventType.RESOURCE_AUTH_METHOD_UPDATE,
+ metadata: {
+ resourceType: "kmip",
+ resourceId: kmipServer.id,
+ resourceName: kmipServer.name,
+ method: view.method as "aws" | "token",
+ methodConfigId: "config" in view && "id" in view.config ? view.config.id : kmipServer.id
+ }
+ }
+ });
+
const canRevoke = await server.services.resourceAuthMethod.canRevoke(kmipServer, "kmip");
return { ...kmipServer, canRevoke, authMethod: view };
@@ -285,6 +300,7 @@ export const registerKmipServerRouter = async (server: FastifyZodProvider) => {
metadata: {
resourceType: "kmip",
resourceId: req.params.kmipServerId,
+ resourceName: kmipServer.name,
method: view.method as "aws" | "token",
methodConfigId: "config" in view && "id" in view.config ? view.config.id : req.params.kmipServerId
}
diff --git a/backend/src/ee/routes/v2/relay-router.ts b/backend/src/ee/routes/v2/relay-router.ts
index 06293a293e..b9417001b1 100644
--- a/backend/src/ee/routes/v2/relay-router.ts
+++ b/backend/src/ee/routes/v2/relay-router.ts
@@ -105,6 +105,21 @@ export const registerRelayV2Router = async (server: FastifyZodProvider) => {
}
});
+ await server.services.auditLog.createAuditLog({
+ ...req.auditLogInfo,
+ orgId: req.permission.orgId,
+ event: {
+ type: EventType.RESOURCE_AUTH_METHOD_UPDATE,
+ metadata: {
+ resourceType: "relay",
+ resourceId: relay.id,
+ resourceName: relay.name,
+ method: view.method as "aws" | "token",
+ methodConfigId: "config" in view && "id" in view.config ? view.config.id : relay.id
+ }
+ }
+ });
+
const canRevoke = await server.services.resourceAuthMethod.canRevoke(relay, "relay");
return { ...relay, canRevoke, authMethod: view };
@@ -234,6 +249,7 @@ export const registerRelayV2Router = async (server: FastifyZodProvider) => {
metadata: {
resourceType: "relay",
resourceId: req.params.relayId,
+ resourceName: relay.name,
method: view.method as "aws" | "token",
methodConfigId: "config" in view && "id" in view.config ? view.config.id : req.params.relayId
}
diff --git a/backend/src/ee/routes/v3/gateway-router.ts b/backend/src/ee/routes/v3/gateway-router.ts
index 8759f224be..e3597a8594 100644
--- a/backend/src/ee/routes/v3/gateway-router.ts
+++ b/backend/src/ee/routes/v3/gateway-router.ts
@@ -234,6 +234,46 @@ const toSetAuthMethodArg = (input: TSettableAuthMethodInput) => {
return { method: ResourceAuthMethodType.Token } as const;
};
+const gatewayAuthMethodAuditMetadata = (
+ gatewayId: string,
+ gatewayName: string | undefined,
+ view: { method: string; config?: Record<string, unknown> }
+) => ({
+ resourceType: "gateway" as const,
+ resourceId: gatewayId,
+ resourceName: gatewayName,
+ method: view.method as "aws" | "gcp" | "kubernetes" | "token",
+ methodConfigId:
+ view.method === ResourceAuthMethodType.Aws ||
+ view.method === ResourceAuthMethodType.Gcp ||
+ view.method === ResourceAuthMethodType.Kubernetes
+ ? (view.config?.id as string)
+ : gatewayId,
+ ...(view.method === ResourceAuthMethodType.Aws
+ ? {
+ stsEndpoint: view.config?.stsEndpoint as string,
+ allowedPrincipalArns: view.config?.allowedPrincipalArns as string,
+ allowedAccountIds: view.config?.allowedAccountIds as string
+ }
+ : {}),
+ ...(view.method === ResourceAuthMethodType.Gcp
+ ? {
+ gcpAuthType: view.config?.type as string,
+ allowedServiceAccounts: view.config?.allowedServiceAccounts as string,
+ allowedProjects: view.config?.allowedProjects as string,
+ allowedZones: view.config?.allowedZones as string
+ }
+ : {}),
+ ...(view.method === ResourceAuthMethodType.Kubernetes
+ ? {
+ kubernetesHost: view.config?.kubernetesHost as string,
+ allowedNamespaces: view.config?.allowedNamespaces as string,
+ allowedNames: view.config?.allowedNames as string,
+ allowedAudience: view.config?.allowedAudience as string
+ }
+ : {})
+});
+
export const registerGatewayV3Router = async (server: FastifyZodProvider) => {
// ─── POST / ──────────────────────────────────────────────────────────────
// Create a gateway. Body requires `authMethod` so create-and-configure happen in one call.
@@ -278,6 +318,17 @@ export const registerGatewayV3Router = async (server: FastifyZodProvider) => {
}
});
+ // The allowlist decides who may authenticate as this gateway, so it belongs in the log at
+ // creation and not only when it is later edited.
+ await server.services.auditLog.createAuditLog({
+ ...req.auditLogInfo,
+ orgId: req.permission.orgId,
+ event: {
+ type: EventType.RESOURCE_AUTH_METHOD_UPDATE,
+ metadata: gatewayAuthMethodAuditMetadata(gateway.id, gateway.name, view)
+ }
+ });
+
const canRevoke = await server.services.resourceAuthMethod.canRevoke(gateway);
return { ...gateway, canRevoke, authMethod: view };
}
@@ -341,41 +392,7 @@ export const registerGatewayV3Router = async (server: FastifyZodProvider) => {
orgId: req.permission.orgId,
event: {
type: EventType.RESOURCE_AUTH_METHOD_UPDATE,
- metadata: {
- resourceType: "gateway",
- resourceId: req.params.gatewayId,
- resourceName: gateway.name,
- method: result.method as "aws" | "gcp" | "kubernetes" | "token",
- methodConfigId:
- result.method === ResourceAuthMethodType.Aws ||
- result.method === ResourceAuthMethodType.Gcp ||
- result.method === ResourceAuthMethodType.Kubernetes
- ? result.config.id
- : req.params.gatewayId,
- ...(result.method === ResourceAuthMethodType.Aws
- ? {
- stsEndpoint: result.config.stsEndpoint,
- allowedPrincipalArns: result.config.allowedPrincipalArns,
- allowedAccountIds: result.config.allowedAccountIds
- }
- : {}),
- ...(result.method === ResourceAuthMethodType.Gcp
- ? {
- gcpAuthType: result.config.type,
- allowedServiceAccounts: result.config.allowedServiceAccounts,
- allowedProjects: result.config.allowedProjects,
- allowedZones: result.config.allowedZones
- }
- : {}),
- ...(result.method === ResourceAuthMethodType.Kubernetes
- ? {
- kubernetesHost: result.config.kubernetesHost,
- allowedNamespaces: result.config.allowedNamespaces,
- allowedNames: result.config.allowedNames,
- allowedAudience: result.config.allowedAudience
- }
- : {})
- }
+ metadata: gatewayAuthMethodAuditMetadata(req.params.gatewayId, gateway.name, result)
}
});