Skip to content

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

feat: zero-downtime gateway re-enrollment

bernie-g925516c33efe
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 a9d78b9f55..3b1cd668a2 100644
--- a/backend/src/ee/services/gateway-v2/gateway-v2-service.ts
+++ b/backend/src/ee/services/gateway-v2/gateway-v2-service.ts
@@ -1327,13 +1327,17 @@ export const gatewayV2ServiceFactory = ({
try {
let gateway;
if (tokenRecord.gatewayId) {
- // Re-enrollment: reuse existing gateway record, update relay if changed
+ // Re-enrollment: reuse existing gateway record.
+ // Bump tokenVersion to invalidate the old machine's JWT and clear health status.
const existing = await gatewayV2DAL.findById(tokenRecord.gatewayId);
if (!existing) throw new NotFoundError({ message: `Gateway ${tokenRecord.gatewayId} not found` });
- if (relay.id !== existing.relayId) {
- await gatewayV2DAL.updateById(existing.id, { relayId: relay.id });
- }
- gateway = { ...existing, relayId: relay.id };
+ const updated = await gatewayV2DAL.updateById(existing.id, {
+ $incr: { tokenVersion: 1 },
+ relayId: relay.id,
+ heartbeat: null,
+ lastHealthCheckStatus: null
+ });
+ gateway = updated;
} else {
// Fresh enrollment: create new gateway record
gateway = await gatewayV2DAL.create({
@@ -1465,8 +1469,8 @@ export const gatewayV2ServiceFactory = ({
if (gatewayId) {
// Re-enroll an existing (enrolled) gateway.
- // Wrapped in a transaction so tokenVersion bump, old token cleanup, and new token
- // creation are atomic. If any step fails, the gateway's JWT is not revoked.
+ // The old gateway keeps running until the new machine enrolls with this token.
+ // tokenVersion is bumped in enrollGateway when the token is consumed, not here.
const gateway = await gatewayV2DAL.findById(gatewayId);
if (!gateway || gateway.orgId !== orgPermission.orgId) {
throw new NotFoundError({ message: `Gateway ${gatewayId} not found` });
@@ -1475,12 +1479,6 @@ export const gatewayV2ServiceFactory = ({
const gatewayToken = $generateEnrollmentToken();
const record = await gatewayEnrollmentTokenDAL.transaction(async (tx) => {
- await gatewayV2DAL.updateById(
- gatewayId,
- { $incr: { tokenVersion: 1 }, heartbeat: null, lastHealthCheckStatus: null },
- tx
- );
-
const existingTokens = await gatewayEnrollmentTokenDAL.find({ gatewayId }, { tx });
const unusedTokenIds = existingTokens.filter((t) => !t.usedAt).map((t) => t.id);
if (unusedTokenIds.length > 0) {
diff --git a/frontend/src/hooks/api/gateways/queries.tsx b/frontend/src/hooks/api/gateways/queries.tsx
index 79db1a2808..eed9541344 100644
--- a/frontend/src/hooks/api/gateways/queries.tsx
+++ b/frontend/src/hooks/api/gateways/queries.tsx
@@ -67,9 +67,10 @@ export const gatewaysQueryKeys = {
...dataV2.map((g) => ({
...g,
isV1: false as const,
- isPending: reEnrollGatewayIds.has(g.id) as boolean,
+ isPending: false as const,
isExpired: false as const,
- isTokenOnly: false as const
+ isTokenOnly: false as const,
+ hasReEnrollToken: reEnrollGatewayIds.has(g.id) as boolean
})),
...standaloneTokens.map((t) => ({
id: t.id,
diff --git a/frontend/src/pages/organization/NetworkingPage/components/GatewayTab/GatewayTab.tsx b/frontend/src/pages/organization/NetworkingPage/components/GatewayTab/GatewayTab.tsx
index 81fc9bf01a..bb7f4cf185 100644
--- a/frontend/src/pages/organization/NetworkingPage/components/GatewayTab/GatewayTab.tsx
+++ b/frontend/src/pages/organization/NetworkingPage/components/GatewayTab/GatewayTab.tsx
@@ -298,6 +298,11 @@ export const GatewayTab = withPermission(
</span>
);
})()}
+ {"hasReEnrollToken" in el && el.hasReEnrollToken && (
+ <span className="rounded-sm bg-yellow-900/30 px-1.5 py-0.5 text-xs text-yellow-500">
+ Re-enrolling
+ </span>
+ )}
</div>
</Td>
<Td>
diff --git a/frontend/src/pages/organization/NetworkingPage/components/GatewayTab/components/ReEnrollGatewayModal.tsx b/frontend/src/pages/organization/NetworkingPage/components/GatewayTab/components/ReEnrollGatewayModal.tsx
index 47dee57301..103d75847d 100644
--- a/frontend/src/pages/organization/NetworkingPage/components/GatewayTab/components/ReEnrollGatewayModal.tsx
+++ b/frontend/src/pages/organization/NetworkingPage/components/GatewayTab/components/ReEnrollGatewayModal.tsx
@@ -68,7 +68,7 @@ export const ReEnrollGatewayModal = ({ isOpen, onOpenChange, gatewayData }: Prop
if (step !== "confirm") return undefined;
if (gatewayData.isTokenOnly)
return "This will create a new enrollment token, replacing the expired one.";
- return "This will create a new enrollment token and invalidate the current gateway credentials. The gateway will stop working until re-enrolled.";
+ return "This will create a new enrollment token. The existing gateway will keep running until the new machine enrolls.";
})()}
>
{step === "confirm" && (