Skip to content

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

fix(pam): use policy max duration for inline approval requests (#6316)

Saif Ur Rahman60dfd489a2b1
diff --git a/backend/src/ee/services/pam-account/pam-account-service.ts b/backend/src/ee/services/pam-account/pam-account-service.ts
index a4899ca05b..0a7044df26 100644
--- a/backend/src/ee/services/pam-account/pam-account-service.ts
+++ b/backend/src/ee/services/pam-account/pam-account-service.ts
@@ -42,6 +42,7 @@ import { TApprovalPolicyDALFactory } from "@app/services/approval-policy/approva
import { ApprovalPolicyType } from "@app/services/approval-policy/approval-policy-enums";
import { APPROVAL_POLICY_FACTORY_MAP } from "@app/services/approval-policy/approval-policy-factory";
import { TApprovalRequestGrantsDALFactory } from "@app/services/approval-policy/approval-request-dal";
+import { TPamAccessPolicy } from "@app/services/approval-policy/pam-access/pam-access-policy-types";
import { ActorType, MfaMethod } from "@app/services/auth/auth-type";
import { TAuthTokenServiceFactory } from "@app/services/auth-token/auth-token-service";
import { TKmsServiceFactory } from "@app/services/kms/kms-service";
@@ -833,7 +834,12 @@ export const pamAccountServiceFactory = ({
details: {
policyId: policy.id,
policyName: policy.name,
- policyType: policy.type
+ policyType: policy.type,
+ constraints: {
+ accessDuration: {
+ max: (policy as TPamAccessPolicy).constraints.constraints.accessDuration.max
+ }
+ }
}
});
}
diff --git a/backend/src/ee/services/pam-web-access/pam-web-access-service.ts b/backend/src/ee/services/pam-web-access/pam-web-access-service.ts
index 97c4cc294c..b035867b04 100644
--- a/backend/src/ee/services/pam-web-access/pam-web-access-service.ts
+++ b/backend/src/ee/services/pam-web-access/pam-web-access-service.ts
@@ -23,6 +23,7 @@ import { TApprovalPolicyDALFactory } from "@app/services/approval-policy/approva
import { ApprovalPolicyType } from "@app/services/approval-policy/approval-policy-enums";
import { APPROVAL_POLICY_FACTORY_MAP } from "@app/services/approval-policy/approval-policy-factory";
import { TApprovalRequestGrantsDALFactory } from "@app/services/approval-policy/approval-request-dal";
+import { TPamAccessPolicy } from "@app/services/approval-policy/pam-access/pam-access-policy-types";
import { ActorType, MfaMethod } from "@app/services/auth/auth-type";
import { TAuthTokenServiceFactory } from "@app/services/auth-token/auth-token-service";
import { TokenType } from "@app/services/auth-token/auth-token-types";
@@ -227,7 +228,12 @@ export const pamWebAccessServiceFactory = ({
details: {
policyId: matchedPolicy.id,
policyName: matchedPolicy.name,
- policyType: matchedPolicy.type
+ policyType: matchedPolicy.type,
+ constraints: {
+ accessDuration: {
+ max: (matchedPolicy as TPamAccessPolicy).constraints.constraints.accessDuration.max
+ }
+ }
}
});
}
diff --git a/frontend/src/pages/pam/PamAccountAccessPage/useWebAccessSession.ts b/frontend/src/pages/pam/PamAccountAccessPage/useWebAccessSession.ts
index df9234d722..9a7286c8b5 100644
--- a/frontend/src/pages/pam/PamAccountAccessPage/useWebAccessSession.ts
+++ b/frontend/src/pages/pam/PamAccountAccessPage/useWebAccessSession.ts
@@ -2,11 +2,13 @@ import { useCallback, useEffect, useRef, useState } from "react";
import { FitAddon } from "@xterm/addon-fit";
import { WebLinksAddon } from "@xterm/addon-web-links";
import { Terminal } from "@xterm/xterm";
+import ms from "ms";
import { Readline } from "xterm-readline";
import { apiRequest } from "@app/config/request";
import { MfaSessionStatus, TMfaSessionStatusResponse } from "@app/hooks/api/mfaSession/types";
+import { DEFAULT_ACCESS_DURATION } from "../constants";
import { WebSocketServerMessageSchema, WsMessageType } from "./web-access-types";
import "@xterm/xterm/css/xterm.css";
@@ -277,6 +279,7 @@ export const useWebAccessSession = ({
policyId?: string;
policyName?: string;
policyType?: string;
+ constraints?: { accessDuration: { max: string } };
};
};
};
@@ -361,6 +364,9 @@ export const useWebAccessSession = ({
// Check for PolicyViolationError
if (axiosErr?.response?.data?.error === "PolicyViolationError") {
const policyName = axiosErr.response!.data!.details?.policyName ?? "Unknown Policy";
+ const accessDurationMax =
+ axiosErr.response!.data!.details?.constraints?.accessDuration.max ??
+ DEFAULT_ACCESS_DURATION;
terminal.write(`\r\nThis account is protected by approval policy: "${policyName}"\r\n`);
@@ -388,7 +394,10 @@ export const useWebAccessSession = ({
{
projectId,
requestData: {
- accessDuration: "1h",
+ accessDuration:
+ ms(accessDurationMax) < ms(DEFAULT_ACCESS_DURATION)
+ ? accessDurationMax
+ : DEFAULT_ACCESS_DURATION,
resourceName,
accountName
},
diff --git a/frontend/src/pages/pam/PamDataExplorerPage/use-data-explorer-session.ts b/frontend/src/pages/pam/PamDataExplorerPage/use-data-explorer-session.ts
index 8be7838fa2..e236eb8857 100644
--- a/frontend/src/pages/pam/PamDataExplorerPage/use-data-explorer-session.ts
+++ b/frontend/src/pages/pam/PamDataExplorerPage/use-data-explorer-session.ts
@@ -1,8 +1,10 @@
import { useCallback, useEffect, useRef, useState } from "react";
+import ms from "ms";
import { apiRequest } from "@app/config/request";
import { MfaSessionStatus, TMfaSessionStatusResponse } from "@app/hooks/api/mfaSession/types";
+import { DEFAULT_ACCESS_DURATION } from "../constants";
import type {
DataExplorerClientMessage,
DataExplorerServerMessage,
@@ -31,6 +33,7 @@ type ApprovalState = {
required: boolean;
policyName?: string;
policyId?: string;
+ accessDurationMax?: string;
creating: boolean;
submitted: boolean;
approvalRequestId?: string;
@@ -239,6 +242,7 @@ export const useDataExplorerSession = ({
mfaMethod?: string;
policyId?: string;
policyName?: string;
+ constraints?: { accessDuration: { max: string } };
};
};
};
@@ -262,6 +266,7 @@ export const useDataExplorerSession = ({
required: true,
policyName: details?.policyName,
policyId: details?.policyId,
+ accessDurationMax: details?.constraints?.accessDuration.max,
creating: false,
submitted: false
});
@@ -347,7 +352,11 @@ export const useDataExplorerSession = ({
{
projectId,
requestData: {
- accessDuration: "1h",
+ accessDuration:
+ approvalState.accessDurationMax &&
+ ms(approvalState.accessDurationMax) < ms(DEFAULT_ACCESS_DURATION)
+ ? approvalState.accessDurationMax
+ : DEFAULT_ACCESS_DURATION,
resourceName,
accountName
},
diff --git a/frontend/src/pages/pam/constants.ts b/frontend/src/pages/pam/constants.ts
new file mode 100644
index 0000000000..cce5b6ffdc
--- /dev/null
+++ b/frontend/src/pages/pam/constants.ts
@@ -0,0 +1 @@
+export const DEFAULT_ACCESS_DURATION = "1h";