Skip to content

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

feat(gateway): distinguish resource auth method create from update in audit log

bernie-g04a8cb0f17d3
diff --git a/backend/src/ee/routes/v1/kmip-server-router.ts b/backend/src/ee/routes/v1/kmip-server-router.ts
index efc613683d..2b4bea87c5 100644
--- a/backend/src/ee/routes/v1/kmip-server-router.ts
+++ b/backend/src/ee/routes/v1/kmip-server-router.ts
@@ -4,10 +4,8 @@ import { KmipServersSchema } from "@app/db/schemas";
import { EventType, UserAgentType } from "@app/ee/services/audit-log/audit-log-types";
import { MIN_SERVER_CERT_TTL } from "@app/ee/services/kmip/kmip-service";
import { validateAccountIds, validatePrincipalArns } from "@app/ee/services/resource-auth-method/aws-auth-validators";
-import {
- ResourceAuthMethodType,
- TSettableAuthMethod
-} from "@app/ee/services/resource-auth-method/resource-auth-method-fns";
+import { resourceAuthMethodAuditMetadata } from "@app/ee/services/resource-auth-method/resource-auth-method-audit-fns";
+import { ResourceAuthMethodType } from "@app/ee/services/resource-auth-method/resource-auth-method-fns";
import { AuthMethodViewSchema } from "@app/ee/services/resource-auth-method/resource-auth-method-schemas";
import { ApiDocsTags } from "@app/lib/api-docs";
import { BadRequestError, UnauthorizedError } from "@app/lib/errors";
@@ -159,14 +157,13 @@ export const registerKmipServerRouter = async (server: FastifyZodProvider) => {
...req.auditLogInfo,
orgId: req.permission.orgId,
event: {
- type: EventType.RESOURCE_AUTH_METHOD_UPDATE,
- metadata: {
+ type: EventType.RESOURCE_AUTH_METHOD_CREATE,
+ metadata: resourceAuthMethodAuditMetadata({
resourceType: "kmip",
resourceId: kmipServer.id,
resourceName: kmipServer.name,
- method: view.method as TSettableAuthMethod,
- methodConfigId: "config" in view && "id" in view.config ? view.config.id : kmipServer.id
- }
+ view
+ })
}
});
@@ -300,13 +297,12 @@ export const registerKmipServerRouter = async (server: FastifyZodProvider) => {
orgId: req.permission.orgId,
event: {
type: EventType.RESOURCE_AUTH_METHOD_UPDATE,
- metadata: {
+ metadata: resourceAuthMethodAuditMetadata({
resourceType: "kmip",
resourceId: req.params.kmipServerId,
resourceName: kmipServer.name,
- method: view.method as TSettableAuthMethod,
- methodConfigId: "config" in view && "id" in view.config ? view.config.id : req.params.kmipServerId
- }
+ view
+ })
}
});
diff --git a/backend/src/ee/routes/v2/relay-router.ts b/backend/src/ee/routes/v2/relay-router.ts
index ae1592a10e..134de5e3e4 100644
--- a/backend/src/ee/routes/v2/relay-router.ts
+++ b/backend/src/ee/routes/v2/relay-router.ts
@@ -3,10 +3,8 @@ import z from "zod";
import { RelaysSchema } from "@app/db/schemas";
import { EventType, UserAgentType } from "@app/ee/services/audit-log/audit-log-types";
import { validateAccountIds, validatePrincipalArns } from "@app/ee/services/resource-auth-method/aws-auth-validators";
-import {
- ResourceAuthMethodType,
- TSettableAuthMethod
-} from "@app/ee/services/resource-auth-method/resource-auth-method-fns";
+import { resourceAuthMethodAuditMetadata } from "@app/ee/services/resource-auth-method/resource-auth-method-audit-fns";
+import { ResourceAuthMethodType } from "@app/ee/services/resource-auth-method/resource-auth-method-fns";
import { AuthMethodViewSchema } from "@app/ee/services/resource-auth-method/resource-auth-method-schemas";
import { UnauthorizedError } from "@app/lib/errors";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
@@ -112,14 +110,13 @@ export const registerRelayV2Router = async (server: FastifyZodProvider) => {
...req.auditLogInfo,
orgId: req.permission.orgId,
event: {
- type: EventType.RESOURCE_AUTH_METHOD_UPDATE,
- metadata: {
+ type: EventType.RESOURCE_AUTH_METHOD_CREATE,
+ metadata: resourceAuthMethodAuditMetadata({
resourceType: "relay",
resourceId: relay.id,
resourceName: relay.name,
- method: view.method as TSettableAuthMethod,
- methodConfigId: "config" in view && "id" in view.config ? view.config.id : relay.id
- }
+ view
+ })
}
});
@@ -249,13 +246,12 @@ export const registerRelayV2Router = async (server: FastifyZodProvider) => {
orgId: req.permission.orgId,
event: {
type: EventType.RESOURCE_AUTH_METHOD_UPDATE,
- metadata: {
+ metadata: resourceAuthMethodAuditMetadata({
resourceType: "relay",
resourceId: req.params.relayId,
resourceName: relay.name,
- method: view.method as TSettableAuthMethod,
- methodConfigId: "config" in view && "id" in view.config ? view.config.id : req.params.relayId
- }
+ view
+ })
}
});
diff --git a/backend/src/ee/routes/v3/gateway-router.ts b/backend/src/ee/routes/v3/gateway-router.ts
index e6d95530d9..de27e5db51 100644
--- a/backend/src/ee/routes/v3/gateway-router.ts
+++ b/backend/src/ee/routes/v3/gateway-router.ts
@@ -14,6 +14,7 @@ import {
validateAllowedNamespaces,
validateKubernetesHost
} from "@app/ee/services/resource-auth-method/kubernetes-auth-validators";
+import { resourceAuthMethodAuditMetadata } from "@app/ee/services/resource-auth-method/resource-auth-method-audit-fns";
import {
GcpAuthType,
KubernetesTokenReviewMode,
@@ -21,9 +22,8 @@ import {
type TSettableAuthMethod
} from "@app/ee/services/resource-auth-method/resource-auth-method-fns";
import { AuthMethodViewSchema } from "@app/ee/services/resource-auth-method/resource-auth-method-schemas";
-import { TAuthMethodView } from "@app/ee/services/resource-auth-method/resource-auth-method-types";
import { ApiDocsTags, GATEWAYS } from "@app/lib/api-docs";
-import { InternalServerError, UnauthorizedError } from "@app/lib/errors";
+import { UnauthorizedError } from "@app/lib/errors";
import { logger } from "@app/lib/logger";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
import { slugSchema } from "@app/server/lib/schemas";
@@ -236,56 +236,6 @@ const toSetAuthMethodArg = (input: TSettableAuthMethodInput) => {
return { method: ResourceAuthMethodType.Token } as const;
};
-const gatewayAuthMethodAuditMetadata = (gatewayId: string, gatewayName: string, view: TAuthMethodView) => {
- const base = {
- resourceType: "gateway" as const,
- resourceId: gatewayId,
- resourceName: gatewayName
- };
-
- if (view.method === ResourceAuthMethodType.Aws) {
- return {
- ...base,
- method: view.method,
- methodConfigId: view.config.id,
- stsEndpoint: view.config.stsEndpoint,
- allowedPrincipalArns: view.config.allowedPrincipalArns,
- allowedAccountIds: view.config.allowedAccountIds
- };
- }
-
- if (view.method === ResourceAuthMethodType.Gcp) {
- return {
- ...base,
- method: view.method,
- methodConfigId: view.config.id,
- gcpAuthType: view.config.type,
- allowedServiceAccounts: view.config.allowedServiceAccounts,
- allowedProjects: view.config.allowedProjects,
- allowedZones: view.config.allowedZones
- };
- }
-
- if (view.method === ResourceAuthMethodType.Kubernetes) {
- return {
- ...base,
- method: view.method,
- methodConfigId: view.config.id,
- kubernetesHost: view.config.kubernetesHost,
- allowedNamespaces: view.config.allowedNamespaces,
- allowedNames: view.config.allowedNames,
- allowedAudience: view.config.allowedAudience
- };
- }
-
- if (view.method === ResourceAuthMethodType.Token) {
- return { ...base, method: view.method, methodConfigId: gatewayId };
- }
-
- // Legacy identity gateways cannot be created or have their method set, so reaching this is a bug.
- throw new InternalServerError({ message: `Cannot audit auth method "${view.method}" for a gateway` });
-};
-
export const registerGatewayV3Router = async (server: FastifyZodProvider) => {
// ─── POST / ──────────────────────────────────────────────────────────────
// Create a gateway. Body requires `authMethod` so create-and-configure happen in one call.
@@ -335,8 +285,13 @@ export const registerGatewayV3Router = async (server: FastifyZodProvider) => {
...req.auditLogInfo,
orgId: req.permission.orgId,
event: {
- type: EventType.RESOURCE_AUTH_METHOD_UPDATE,
- metadata: gatewayAuthMethodAuditMetadata(gateway.id, gateway.name, view)
+ type: EventType.RESOURCE_AUTH_METHOD_CREATE,
+ metadata: resourceAuthMethodAuditMetadata({
+ resourceType: "gateway",
+ resourceId: gateway.id,
+ resourceName: gateway.name,
+ view
+ })
}
});
@@ -403,7 +358,12 @@ export const registerGatewayV3Router = async (server: FastifyZodProvider) => {
orgId: req.permission.orgId,
event: {
type: EventType.RESOURCE_AUTH_METHOD_UPDATE,
- metadata: gatewayAuthMethodAuditMetadata(req.params.gatewayId, updated.name, result)
+ metadata: resourceAuthMethodAuditMetadata({
+ resourceType: "gateway",
+ resourceId: req.params.gatewayId,
+ resourceName: updated.name,
+ view: result
+ })
}
});
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 a36cd07bed..d68d05ce40 100644
--- a/backend/src/ee/services/audit-log/audit-log-types.ts
+++ b/backend/src/ee/services/audit-log/audit-log-types.ts
@@ -897,6 +897,7 @@ export enum EventType {
// Resource Auth Methods
RESOURCE_AUTH_METHOD_LOGIN = "resource-auth-method-login",
RESOURCE_AUTH_METHOD_LOGIN_FAILED = "resource-auth-method-login-failed",
+ RESOURCE_AUTH_METHOD_CREATE = "resource-auth-method-create",
RESOURCE_AUTH_METHOD_UPDATE = "resource-auth-method-update",
RESOURCE_AUTH_METHOD_REVOKE = "resource-auth-method-revoke",
RELAY_CREATE = "relay-create",
@@ -7319,26 +7320,33 @@ interface ResourceAuthMethodLoginFailedEvent {
};
}
+interface ResourceAuthMethodConfigMetadata {
+ resourceType: ResourceAuthMethodResourceType;
+ resourceId: string;
+ resourceName?: string;
+ method: ResourceAuthMethodKind;
+ methodConfigId: string;
+ stsEndpoint?: string;
+ allowedPrincipalArns?: string;
+ allowedAccountIds?: string;
+ kubernetesHost?: string;
+ allowedNamespaces?: string;
+ allowedNames?: string;
+ allowedAudience?: string;
+ gcpAuthType?: string;
+ allowedServiceAccounts?: string;
+ allowedProjects?: string;
+ allowedZones?: string;
+}
+
+interface ResourceAuthMethodCreateEvent {
+ type: EventType.RESOURCE_AUTH_METHOD_CREATE;
+ metadata: ResourceAuthMethodConfigMetadata;
+}
+
interface ResourceAuthMethodUpdateEvent {
type: EventType.RESOURCE_AUTH_METHOD_UPDATE;
- metadata: {
- resourceType: ResourceAuthMethodResourceType;
- resourceId: string;
- resourceName?: string;
- method: ResourceAuthMethodKind;
- methodConfigId: string;
- stsEndpoint?: string;
- allowedPrincipalArns?: string;
- allowedAccountIds?: string;
- kubernetesHost?: string;
- allowedNamespaces?: string;
- allowedNames?: string;
- allowedAudience?: string;
- gcpAuthType?: string;
- allowedServiceAccounts?: string;
- allowedProjects?: string;
- allowedZones?: string;
- };
+ metadata: ResourceAuthMethodConfigMetadata;
}
interface ResourceAuthMethodRevokeEvent {
@@ -8233,6 +8241,7 @@ export type Event =
| GatewayConnectEvent
| ResourceAuthMethodLoginEvent
| ResourceAuthMethodLoginFailedEvent
+ | ResourceAuthMethodCreateEvent
| ResourceAuthMethodUpdateEvent
| ResourceAuthMethodRevokeEvent
| RelayCreateEvent
diff --git a/backend/src/ee/services/resource-auth-method/resource-auth-method-audit-fns.ts b/backend/src/ee/services/resource-auth-method/resource-auth-method-audit-fns.ts
new file mode 100644
index 0000000000..c0b42723e7
--- /dev/null
+++ b/backend/src/ee/services/resource-auth-method/resource-auth-method-audit-fns.ts
@@ -0,0 +1,62 @@
+import { InternalServerError } from "@app/lib/errors";
+
+import { ResourceAuthMethodType } from "./resource-auth-method-fns";
+import { TAuthMethodView } from "./resource-auth-method-types";
+
+type TResourceAuthMethodAuditArg = {
+ resourceType: "gateway" | "relay" | "kmip";
+ resourceId: string;
+ resourceName: string;
+ view: TAuthMethodView;
+};
+
+export const resourceAuthMethodAuditMetadata = ({
+ resourceType,
+ resourceId,
+ resourceName,
+ view
+}: TResourceAuthMethodAuditArg) => {
+ const base = { resourceType, resourceId, resourceName };
+
+ if (view.method === ResourceAuthMethodType.Aws) {
+ return {
+ ...base,
+ method: view.method,
+ methodConfigId: view.config.id,
+ stsEndpoint: view.config.stsEndpoint,
+ allowedPrincipalArns: view.config.allowedPrincipalArns,
+ allowedAccountIds: view.config.allowedAccountIds
+ };
+ }
+
+ if (view.method === ResourceAuthMethodType.Gcp) {
+ return {
+ ...base,
+ method: view.method,
+ methodConfigId: view.config.id,
+ gcpAuthType: view.config.type,
+ allowedServiceAccounts: view.config.allowedServiceAccounts,
+ allowedProjects: view.config.allowedProjects,
+ allowedZones: view.config.allowedZones
+ };
+ }
+
+ if (view.method === ResourceAuthMethodType.Kubernetes) {
+ return {
+ ...base,
+ method: view.method,
+ methodConfigId: view.config.id,
+ kubernetesHost: view.config.kubernetesHost,
+ allowedNamespaces: view.config.allowedNamespaces,
+ allowedNames: view.config.allowedNames,
+ allowedAudience: view.config.allowedAudience
+ };
+ }
+
+ if (view.method === ResourceAuthMethodType.Token) {
+ return { ...base, method: view.method, methodConfigId: resourceId };
+ }
+
+ // Legacy identity gateways cannot be created or have their method set, so reaching this is a bug.
+ throw new InternalServerError({ message: `Cannot audit auth method "${view.method}" for a ${resourceType}` });
+};
diff --git a/frontend/src/hooks/api/auditLogs/constants.tsx b/frontend/src/hooks/api/auditLogs/constants.tsx
index 12eac7147a..fe67e26ca1 100644
--- a/frontend/src/hooks/api/auditLogs/constants.tsx
+++ b/frontend/src/hooks/api/auditLogs/constants.tsx
@@ -439,6 +439,7 @@ export const eventToNameMap: { [K in EventType]: string } = {
[EventType.GATEWAY_ENROLLMENT_TOKEN_CREATE]: "Generate gateway enrollment token",
[EventType.RESOURCE_AUTH_METHOD_LOGIN]: "Resource login",
[EventType.RESOURCE_AUTH_METHOD_LOGIN_FAILED]: "Resource login failed",
+ [EventType.RESOURCE_AUTH_METHOD_CREATE]: "Create resource auth method",
[EventType.RESOURCE_AUTH_METHOD_UPDATE]: "Update resource auth method",
[EventType.RESOURCE_AUTH_METHOD_REVOKE]: "Revoke resource access",
[EventType.RELAY_CREATE]: "Create relay",
diff --git a/frontend/src/hooks/api/auditLogs/enums.tsx b/frontend/src/hooks/api/auditLogs/enums.tsx
index e61a136b08..00c64801ac 100644
--- a/frontend/src/hooks/api/auditLogs/enums.tsx
+++ b/frontend/src/hooks/api/auditLogs/enums.tsx
@@ -435,6 +435,7 @@ export enum EventType {
GATEWAY_ENROLLMENT_TOKEN_CREATE = "gateway-enrollment-token-create",
RESOURCE_AUTH_METHOD_LOGIN = "resource-auth-method-login",
RESOURCE_AUTH_METHOD_LOGIN_FAILED = "resource-auth-method-login-failed",
+ RESOURCE_AUTH_METHOD_CREATE = "resource-auth-method-create",
RESOURCE_AUTH_METHOD_UPDATE = "resource-auth-method-update",
RESOURCE_AUTH_METHOD_REVOKE = "resource-auth-method-revoke",
RELAY_CREATE = "relay-create",