Skip to content

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

feat(gateway): terraform support

bernie-g95bcdc43d2f4
diff --git a/backend/src/ee/routes/v3/gateway-router.ts b/backend/src/ee/routes/v3/gateway-router.ts
index de27e5db51..859970c36a 100644
--- a/backend/src/ee/routes/v3/gateway-router.ts
+++ b/backend/src/ee/routes/v3/gateway-router.ts
@@ -34,7 +34,7 @@ import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";
const loginRateLimit = { windowMs: 60 * 1000, max: 10 };
-const SanitizedGatewayV2Schema = GatewaysV2Schema.pick({
+const GatewayV2ResourceSchema = GatewaysV2Schema.pick({
id: true,
identityId: true,
relayId: true,
@@ -45,7 +45,9 @@ const SanitizedGatewayV2Schema = GatewaysV2Schema.pick({
heartbeatTTL: true,
directAddress: true,
directHeartbeat: true
-}).extend({
+});
+
+const SanitizedGatewayV2Schema = GatewayV2ResourceSchema.extend({
canRevoke: z.boolean()
});
@@ -336,23 +338,35 @@ export const registerGatewayV3Router = async (server: FastifyZodProvider) => {
tags: [ApiDocsTags.GatewaysV3],
params: z.object({ gatewayId: z.string().trim().uuid() }),
body: z.object({
+ name: slugSchema({ field: "name" }).optional().describe(GATEWAYS.UPDATE.name),
authMethod: SettableAuthMethodInputSchema.optional().describe(GATEWAYS.UPDATE.authMethod)
}),
response: { 200: GatewayWithAuthMethodSchema }
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
- if (req.body.authMethod) {
- const setInput = toSetAuthMethodArg(req.body.authMethod);
+ // The auth method goes first: it does the network work that actually fails, so a rejected
+ // change cannot leave behind a rename. Neither half is transactional.
+ const authResult = req.body.authMethod
+ ? await server.services.resourceAuthMethod.setMethod({
+ resource: { type: "gateway", id: req.params.gatewayId },
+ authMethod: toSetAuthMethodArg(req.body.authMethod),
+ actor: req.permission
+ })
+ : null;
- const result = await server.services.resourceAuthMethod.setMethod({
- resource: { type: "gateway", id: req.params.gatewayId },
- authMethod: setInput,
- actor: req.permission
- });
+ const rename = req.body.name
+ ? await server.services.gatewayV2.renameGateway({
+ orgPermission: req.permission,
+ gatewayId: req.params.gatewayId,
+ name: req.body.name
+ })
+ : null;
- const updated = await server.services.gatewayV2.getGatewayById({ gatewayId: req.params.gatewayId });
+ const gateway = await server.services.gatewayV2.getGatewayById({ gatewayId: req.params.gatewayId });
+ // Both events are written after the rename so they agree on what the gateway is called.
+ if (authResult) {
await server.services.auditLog.createAuditLog({
...req.auditLogInfo,
orgId: req.permission.orgId,
@@ -361,8 +375,8 @@ export const registerGatewayV3Router = async (server: FastifyZodProvider) => {
metadata: resourceAuthMethodAuditMetadata({
resourceType: "gateway",
resourceId: req.params.gatewayId,
- resourceName: updated.name,
- view: result
+ resourceName: gateway.name,
+ view: authResult
})
}
});
@@ -376,7 +390,7 @@ export const registerGatewayV3Router = async (server: FastifyZodProvider) => {
resourceType: "gateway",
resourceId: req.params.gatewayId,
orgId: req.permission.orgId,
- method: result.method as TSettableAuthMethod
+ method: authResult.method as TSettableAuthMethod
}
})
.catch((err) => {
@@ -384,7 +398,17 @@ export const registerGatewayV3Router = async (server: FastifyZodProvider) => {
});
}
- const gateway = await server.services.gatewayV2.getGatewayById({ gatewayId: req.params.gatewayId });
+ if (rename && rename.previousName !== gateway.name) {
+ await server.services.auditLog.createAuditLog({
+ ...req.auditLogInfo,
+ orgId: req.permission.orgId,
+ event: {
+ type: EventType.GATEWAY_UPDATE,
+ metadata: { gatewayId: gateway.id, name: gateway.name, previousName: rename.previousName }
+ }
+ });
+ }
+
const view = await server.services.resourceAuthMethod.getByGatewayId({
resource: { type: "gateway", id: req.params.gatewayId },
actor: req.permission
@@ -394,6 +418,40 @@ export const registerGatewayV3Router = async (server: FastifyZodProvider) => {
}
});
+ // ─── DELETE /:gatewayId ──────────────────────────────────────────────────
+ // Removing the record disconnects the running gateway for good. The service refuses while the
+ // gateway is still attached to resources or reviewing Kubernetes tokens for other gateways.
+ server.route({
+ method: "DELETE",
+ url: "/:gatewayId",
+ config: { rateLimit: writeLimit },
+ schema: {
+ hide: false,
+ operationId: "deleteGateway",
+ tags: [ApiDocsTags.GatewaysV3],
+ params: z.object({ gatewayId: z.string().trim().uuid().describe(GATEWAYS.DELETE.gatewayId) }),
+ response: { 200: GatewayV2ResourceSchema }
+ },
+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
+ handler: async (req) => {
+ const gateway = await server.services.gatewayV2.deleteGatewayById({
+ orgPermission: req.permission,
+ id: req.params.gatewayId
+ });
+
+ await server.services.auditLog.createAuditLog({
+ ...req.auditLogInfo,
+ orgId: req.permission.orgId,
+ event: {
+ type: EventType.GATEWAY_DELETE,
+ metadata: { gatewayId: gateway.id, name: gateway.name }
+ }
+ });
+
+ return gateway;
+ }
+ });
+
// ─── POST /:gatewayId/token-auth/generate-enrollment-token ────────────────
server.route({
method: "POST",
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 196a7bf1c5..ae51ec7d52 100644
--- a/backend/src/ee/services/audit-log/audit-log-types.ts
+++ b/backend/src/ee/services/audit-log/audit-log-types.ts
@@ -903,6 +903,8 @@ export enum EventType {
// Gateway Enrollment Tokens
GATEWAY_CREATE = "gateway-create",
+ GATEWAY_UPDATE = "gateway-update",
+ GATEWAY_DELETE = "gateway-delete",
GATEWAY_ENROLLMENT_TOKEN_CREATE = "gateway-enrollment-token-create",
GATEWAY_ENROLL = "gateway-enroll",
GATEWAY_CONNECT = "gateway-connect",
@@ -7410,6 +7412,23 @@ interface GatewayCreateEvent {
};
}
+interface GatewayUpdateEvent {
+ type: EventType.GATEWAY_UPDATE;
+ metadata: {
+ gatewayId: string;
+ name: string;
+ previousName: string;
+ };
+}
+
+interface GatewayDeleteEvent {
+ type: EventType.GATEWAY_DELETE;
+ metadata: {
+ gatewayId: string;
+ name: string;
+ };
+}
+
interface GatewayEnrollmentTokenCreateEvent {
type: EventType.GATEWAY_ENROLLMENT_TOKEN_CREATE;
metadata: {
@@ -8397,6 +8416,8 @@ export type Event =
| VerifyEmailDomainEvent
| DeleteEmailDomainEvent
| GatewayCreateEvent
+ | GatewayUpdateEvent
+ | GatewayDeleteEvent
| GatewayEnrollmentTokenCreateEvent
| GatewayEnrollEvent
| GatewayConnectEvent
diff --git a/backend/src/ee/services/gateway-v2/gateway-v2-service.ts b/backend/src/ee/services/gateway-v2/gateway-v2-service.ts
index 6e8d209bd5..03020c0f52 100644
--- a/backend/src/ee/services/gateway-v2/gateway-v2-service.ts
+++ b/backend/src/ee/services/gateway-v2/gateway-v2-service.ts
@@ -1317,6 +1317,48 @@ export const gatewayV2ServiceFactory = ({
// --- V3 service methods ---
+ const renameGateway = async ({
+ orgPermission,
+ gatewayId,
+ name
+ }: {
+ orgPermission: OrgServiceActor;
+ gatewayId: string;
+ name: string;
+ }) => {
+ const gateway = await gatewayV2DAL.findOne({ id: gatewayId, orgId: orgPermission.orgId });
+ if (!gateway) {
+ throw new NotFoundError({ message: `Gateway ${gatewayId} not found` });
+ }
+
+ const { permission } = await permissionService.getOrgPermission({
+ actor: orgPermission.type,
+ actorId: orgPermission.id,
+ orgId: gateway.orgId,
+ actorAuthMethod: orgPermission.authMethod,
+ actorOrgId: orgPermission.orgId,
+ scope: OrganizationActionScope.Any
+ });
+
+ ForbiddenError.from(permission).throwUnlessCan(
+ OrgPermissionGatewayActions.EditGateways,
+ OrgPermissionSubjects.Gateway
+ );
+
+ if (gateway.name === name) return { gateway, previousName: name };
+
+ try {
+ const renamed = await gatewayV2DAL.updateById(gateway.id, { name });
+ return { gateway: renamed, previousName: gateway.name };
+ } catch (err) {
+ if (err instanceof DatabaseError && (err.error as { code: string })?.code === DatabaseErrorCode.UniqueViolation) {
+ throw new BadRequestError({ message: `A gateway named "${name}" already exists` });
+ }
+
+ throw err;
+ }
+ };
+
const createGateway = async ({
orgId,
actorId,
@@ -1480,6 +1522,7 @@ export const gatewayV2ServiceFactory = ({
enrollGateway,
// V3
createGateway,
+ renameGateway,
connectGateway
};
};
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts
index 0c18afc89c..236dd8dc75 100644
--- a/backend/src/lib/api-docs/constants.ts
+++ b/backend/src/lib/api-docs/constants.ts
@@ -4023,7 +4023,11 @@ export const GATEWAYS = {
authMethod:
"Auth method to configure on the gateway. `aws` carries the AWS allowlists; `gcp` carries the GCP token type and service account/project/zone allowlists; `kubernetes` carries the cluster host and namespace/service account allowlists; `token` is configurationless and requires a separate POST /v3/gateways/:id/token call to mint the bootstrap token."
},
+ DELETE: {
+ gatewayId: "The ID of the gateway to delete."
+ },
UPDATE: {
+ name: "New name for the gateway. Renaming does not affect the gateway's ID, so resources referencing it keep working.",
authMethod:
"Replacement auth method. Same shape as in create: `aws` with allowlists, `gcp` with GCP allowlists, `kubernetes` with cluster config, or `token` with no config. Existing gateways keep working until they restart and re-authenticate via the new method."
},
diff --git a/frontend/src/hooks/api/gateways-v2/mutations.tsx b/frontend/src/hooks/api/gateways-v2/mutations.tsx
index 1b6ae51bed..d8ae8c2839 100644
--- a/frontend/src/hooks/api/gateways-v2/mutations.tsx
+++ b/frontend/src/hooks/api/gateways-v2/mutations.tsx
@@ -71,14 +71,16 @@ export const useUpdateGateway = () => {
return useMutation({
mutationFn: async ({
gatewayId,
+ name,
authMethod
}: {
gatewayId: string;
+ name?: string;
authMethod?: SettableAuthMethodInput;
}) => {
const { data } = await apiRequest.patch<TGatewayV2WithAuthMethod>(
`/api/v3/gateways/${gatewayId}`,
- { authMethod }
+ { name, authMethod }
);
return data;
},
diff --git a/frontend/src/pages/organization/NetworkingPage/GatewayDetailsByIDPage/components/GatewayPageHeader/GatewayPageHeader.tsx b/frontend/src/pages/organization/NetworkingPage/GatewayDetailsByIDPage/components/GatewayPageHeader/GatewayPageHeader.tsx
index 40ef4868a1..8e0ee35262 100644
--- a/frontend/src/pages/organization/NetworkingPage/GatewayDetailsByIDPage/components/GatewayPageHeader/GatewayPageHeader.tsx
+++ b/frontend/src/pages/organization/NetworkingPage/GatewayDetailsByIDPage/components/GatewayPageHeader/GatewayPageHeader.tsx
@@ -1,5 +1,12 @@
import { useNavigate } from "@tanstack/react-router";
-import { BanIcon, CopyIcon, EllipsisIcon, HeartPulseIcon, TrashIcon } from "lucide-react";
+import {
+ BanIcon,
+ CopyIcon,
+ EllipsisIcon,
+ HeartPulseIcon,
+ PencilIcon,
+ TrashIcon
+} from "lucide-react";
import { createNotification } from "@app/components/notifications";
import { OrgPermissionCan } from "@app/components/permissions";
@@ -34,6 +41,8 @@ import {
} from "@app/hooks/api/gateways-v2";
import { TGatewayV2 } from "@app/hooks/api/gateways-v2/types";
+import { RenameGatewayModal } from "./RenameGatewayModal";
+
export const GatewayPageHeader = ({ gateway, orgId }: { gateway: TGatewayV2; orgId: string }) => {
const navigate = useNavigate();
const { mutateAsync: deleteGateway, isPending: isDeleting } = useDeleteGatewayV2ById();
@@ -42,7 +51,8 @@ export const GatewayPageHeader = ({ gateway, orgId }: { gateway: TGatewayV2; org
useTriggerGatewayV2Heartbeat();
const { popUp, handlePopUpOpen, handlePopUpToggle } = usePopUp([
"deleteGateway",
- "revokeGateway"
+ "revokeGateway",
+ "renameGateway"
] as const);
const onDelete = async () => {
@@ -103,6 +113,20 @@ export const GatewayPageHeader = ({ gateway, orgId }: { gateway: TGatewayV2; org
<CopyIcon />
Copy Gateway ID
</DropdownMenuItem>
+ <OrgPermissionCan
+ I={OrgGatewayPermissionActions.EditGateways}
+ a={OrgPermissionSubjects.Gateway}
+ >
+ {(isAllowed) => (
+ <DropdownMenuItem
+ isDisabled={!isAllowed}
+ onClick={() => handlePopUpOpen("renameGateway")}
+ >
+ <PencilIcon />
+ Rename Gateway
+ </DropdownMenuItem>
+ )}
+ </OrgPermissionCan>
{isRegistered && (
<DropdownMenuItem isDisabled={isHeartbeating} onClick={onHeartbeat}>
<HeartPulseIcon />
@@ -145,6 +169,12 @@ export const GatewayPageHeader = ({ gateway, orgId }: { gateway: TGatewayV2; org
</DropdownMenu>
</PageHeader>
+ <RenameGatewayModal
+ isOpen={popUp.renameGateway.isOpen}
+ onToggle={(isOpen) => handlePopUpToggle("renameGateway", isOpen)}
+ gateway={gateway}
+ />
+
<AlertDialog
open={popUp.deleteGateway.isOpen}
confirmationValue={gateway.name}
diff --git a/frontend/src/pages/organization/NetworkingPage/GatewayDetailsByIDPage/components/GatewayPageHeader/RenameGatewayModal.tsx b/frontend/src/pages/organization/NetworkingPage/GatewayDetailsByIDPage/components/GatewayPageHeader/RenameGatewayModal.tsx
new file mode 100644
index 0000000000..dee04fe89e
--- /dev/null
+++ b/frontend/src/pages/organization/NetworkingPage/GatewayDetailsByIDPage/components/GatewayPageHeader/RenameGatewayModal.tsx
@@ -0,0 +1,105 @@
+import { useEffect, useMemo, useState } from "react";
+import { z } from "zod";
+
+import { createNotification } from "@app/components/notifications";
+import {
+ Button,
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+ Field,
+ FieldError,
+ FieldLabel,
+ Input
+} from "@app/components/v3";
+import { useUpdateGateway } from "@app/hooks/api/gateways-v2";
+import { TGatewayV2 } from "@app/hooks/api/gateways-v2/types";
+import { slugSchema } from "@app/lib/schemas";
+
+const formSchema = z.object({
+ name: slugSchema({ field: "name" })
+});
+
+type Props = {
+ isOpen: boolean;
+ onToggle: (isOpen: boolean) => void;
+ gateway: TGatewayV2;
+};
+
+export const RenameGatewayModal = ({ isOpen, onToggle, gateway }: Props) => {
+ const updateGateway = useUpdateGateway();
+ const [name, setName] = useState(gateway.name);
+ const [formErrors, setFormErrors] = useState<z.ZodIssue[]>([]);
+
+ const errors = useMemo(() => {
+ const errorMap: Record<string, string | undefined> = {};
+ formErrors.forEach((issue) => {
+ if (issue.path.length > 0) errorMap[String(issue.path[0])] = issue.message;
+ });
+ return errorMap;
+ }, [formErrors]);
+
+ useEffect(() => {
+ if (isOpen) {
+ setName(gateway.name);
+ setFormErrors([]);
+ }
+ }, [isOpen, gateway.name]);
+
+ const handleSubmit = async () => {
+ setFormErrors([]);
+ const validation = formSchema.safeParse({ name });
+ if (!validation.success) {
+ setFormErrors(validation.error.issues);
+ return;
+ }
+
+ if (name.trim() === gateway.name) {
+ onToggle(false);
+ return;
+ }
+
+ try {
+ await updateGateway.mutateAsync({ gatewayId: gateway.id, name: name.trim() });
+ createNotification({ type: "success", text: "Gateway renamed" });
+ onToggle(false);
+ } catch (err: unknown) {
+ const message = err instanceof Error ? err.message : "Failed to rename gateway";
+ createNotification({ type: "error", text: message });
+ }
+ };
+
+ return (
+ <Dialog open={isOpen} onOpenChange={onToggle}>
+ <DialogContent>
+ <DialogHeader>
+ <DialogTitle>Rename Gateway</DialogTitle>
+ <DialogDescription>
+ The gateway keeps its ID, so anything already pointing at it carries on working.
+ </DialogDescription>
+ </DialogHeader>
+ <Field data-invalid={Boolean(errors.name)}>
+ <FieldLabel htmlFor="rename-gateway-name">Name</FieldLabel>
+ <Input
+ id="rename-gateway-name"
+ value={name}
+ onChange={(e) => setName(e.target.value)}
+ isError={Boolean(errors.name)}
+ />
+ <FieldError>{errors.name}</FieldError>
+ </Field>
+ <DialogFooter>
+ <Button variant="ghost" onClick={() => onToggle(false)} type="button">
+ Cancel
+ </Button>
+ <Button variant="org" onClick={handleSubmit} isPending={updateGateway.isPending}>
+ Save Changes
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ );
+};