Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat(access-policies): Allow policy limits on access request times
x0322055c9243d6911b
diff --git a/backend/src/db/migrations/20250808021941_access-policy-max-time-period.ts b/backend/src/db/migrations/20250808021941_access-policy-max-time-period.tsnew file mode 100644index 0000000000..218260b3e8--- /dev/null+++ b/backend/src/db/migrations/20250808021941_access-policy-max-time-period.ts@@ -0,0 +1,19 @@+import { Knex } from "knex";++import { TableName } from "../schemas/models";++export async function up(knex: Knex): Promise<void> {+ if (!(await knex.schema.hasColumn(TableName.AccessApprovalPolicy, "maxTimePeriod"))) {+ await knex.schema.alterTable(TableName.AccessApprovalPolicy, (t) => {+ t.string("maxTimePeriod").nullable(); // Ex: 1h - Null is permanent+ });+ }+}++export async function down(knex: Knex): Promise<void> {+ if (await knex.schema.hasColumn(TableName.AccessApprovalPolicy, "maxTimePeriod")) {+ await knex.schema.alterTable(TableName.AccessApprovalPolicy, (t) => {+ t.dropColumn("maxTimePeriod");+ });+ }+}diff --git a/backend/src/db/schemas/access-approval-policies.ts b/backend/src/db/schemas/access-approval-policies.tsindex ea57c54d22..66ed79ab74 100644--- a/backend/src/db/schemas/access-approval-policies.ts+++ b/backend/src/db/schemas/access-approval-policies.ts@@ -17,7 +17,8 @@ export const AccessApprovalPoliciesSchema = z.object({updatedAt: z.date(),enforcementLevel: z.string().default("hard"),deletedAt: z.date().nullable().optional(),- allowedSelfApprovals: z.boolean().default(true)+ allowedSelfApprovals: z.boolean().default(true),+ maxTimePeriod: z.string().nullable().optional()});export type TAccessApprovalPolicies = z.infer<typeof AccessApprovalPoliciesSchema>;diff --git a/backend/src/ee/routes/v1/access-approval-policy-router.ts b/backend/src/ee/routes/v1/access-approval-policy-router.tsindex ef44344dea..f5278476f3 100644--- a/backend/src/ee/routes/v1/access-approval-policy-router.ts+++ b/backend/src/ee/routes/v1/access-approval-policy-router.ts@@ -3,6 +3,7 @@ import { z } from "zod";import { ApproverType, BypasserType } from "@app/ee/services/access-approval-policy/access-approval-policy-types";import { removeTrailingSlash } from "@app/lib/fn";+import { ms } from "@app/lib/ms";import { EnforcementLevel } from "@app/lib/types";import { readLimit, writeLimit } from "@app/server/config/rateLimiter";import { verifyAuth } from "@app/server/plugins/auth/verify-auth";@@ -71,7 +72,24 @@ export const registerAccessApprovalPolicyRouter = async (server: FastifyZodProvi.optional(),approvals: z.number().min(1).default(1),enforcementLevel: z.nativeEnum(EnforcementLevel).default(EnforcementLevel.Hard),- allowedSelfApprovals: z.boolean().default(true)+ allowedSelfApprovals: z.boolean().default(true),+ maxTimePeriod: z+ .string()+ .trim()+ .optional()+ .transform((val, ctx) => {+ if (val === undefined) return undefined;+ const parsedMs = ms(val);++ if (typeof parsedMs !== "number" || parsedMs <= 0) {+ ctx.addIssue({+ code: z.ZodIssueCode.custom,+ message: "Invalid time period format or value. Must be a positive duration (e.g., '1h', '30m', '2d')."+ });+ return z.NEVER;+ }+ return val;+ })}).refine((val) => Boolean(val.environment) || Boolean(val.environments),@@ -124,7 +142,8 @@ export const registerAccessApprovalPolicyRouter = async (server: FastifyZodProvi.array().nullable().optional(),- bypassers: z.object({ type: z.nativeEnum(BypasserType), id: z.string().nullable().optional() }).array()+ bypassers: z.object({ type: z.nativeEnum(BypasserType), id: z.string().nullable().optional() }).array(),+ maxTimePeriod: z.string().nullable().optional()}).array().nullable()@@ -233,7 +252,24 @@ export const registerAccessApprovalPolicyRouter = async (server: FastifyZodProvistepNumber: z.number().int()}).array()+ .optional(),+ maxTimePeriod: z+ .string()+ .trim().optional()+ .transform((val, ctx) => {+ if (val === undefined) return undefined;+ const parsedMs = ms(val);++ if (typeof parsedMs !== "number" || parsedMs <= 0) {+ ctx.addIssue({+ code: z.ZodIssueCode.custom,+ message: "Invalid time period format or value. Must be a positive duration (e.g., '1h', '30m', '2d')."+ });+ return z.NEVER;+ }+ return val;+ })}),response: {200: z.object({@@ -314,7 +350,8 @@ export const registerAccessApprovalPolicyRouter = async (server: FastifyZodProvi}).array().nullable()- .optional()+ .optional(),+ maxTimePeriod: z.string().nullable().optional()})})}diff --git a/backend/src/ee/routes/v1/access-approval-request-router.ts b/backend/src/ee/routes/v1/access-approval-request-router.tsindex 7a70d63746..c9e7b0d5c9 100644--- a/backend/src/ee/routes/v1/access-approval-request-router.ts+++ b/backend/src/ee/routes/v1/access-approval-request-router.ts@@ -128,7 +128,8 @@ export const registerAccessApprovalRequestRouter = async (server: FastifyZodProvenvId: z.string(),enforcementLevel: z.string(),deletedAt: z.date().nullish(),- allowedSelfApprovals: z.boolean()+ allowedSelfApprovals: z.boolean(),+ maxTimePeriod: z.string().nullable().optional()}),reviewers: z.object({diff --git a/backend/src/ee/services/access-approval-policy/access-approval-policy-dal.ts b/backend/src/ee/services/access-approval-policy/access-approval-policy-dal.tsindex 9baf762d63..78221d988b 100644--- a/backend/src/ee/services/access-approval-policy/access-approval-policy-dal.ts+++ b/backend/src/ee/services/access-approval-policy/access-approval-policy-dal.ts@@ -56,6 +56,7 @@ export interface TAccessApprovalPolicyDALFactoryallowedSelfApprovals: boolean;secretPath: string;deletedAt?: Date | null | undefined;+ maxTimePeriod?: string | null;projectId: string;bypassers: (| {@@ -96,6 +97,7 @@ export interface TAccessApprovalPolicyDALFactoryallowedSelfApprovals: boolean;secretPath: string;deletedAt?: Date | null | undefined;+ maxTimePeriod?: string | null;environments: {id: string;name: string;@@ -141,6 +143,7 @@ export interface TAccessApprovalPolicyDALFactoryallowedSelfApprovals: boolean;secretPath: string;deletedAt?: Date | null | undefined;+ maxTimePeriod?: string | null;}| undefined>;diff --git a/backend/src/ee/services/access-approval-policy/access-approval-policy-service.ts b/backend/src/ee/services/access-approval-policy/access-approval-policy-service.tsindex 0b3c4e1285..95d1a98779 100644--- a/backend/src/ee/services/access-approval-policy/access-approval-policy-service.ts+++ b/backend/src/ee/services/access-approval-policy/access-approval-policy-service.ts@@ -100,7 +100,8 @@ export const accessApprovalPolicyServiceFactory = ({environments,enforcementLevel,allowedSelfApprovals,- approvalsRequired+ approvalsRequired,+ maxTimePeriod}) => {const project = await projectDAL.findProjectBySlug(projectSlug, actorOrgId);if (!project) throw new NotFoundError({ message: `Project with slug '${projectSlug}' not found` });@@ -219,7 +220,8 @@ export const accessApprovalPolicyServiceFactory = ({secretPath,name,enforcementLevel,- allowedSelfApprovals+ allowedSelfApprovals,+ maxTimePeriod},tx);@@ -318,7 +320,8 @@ export const accessApprovalPolicyServiceFactory = ({enforcementLevel,allowedSelfApprovals,approvalsRequired,- environments+ environments,+ maxTimePeriod}: TUpdateAccessApprovalPolicy) => {const groupApprovers = approvers.filter((approver) => approver.type === ApproverType.Group);@@ -461,7 +464,8 @@ export const accessApprovalPolicyServiceFactory = ({secretPath,name,enforcementLevel,- allowedSelfApprovals+ allowedSelfApprovals,+ maxTimePeriod},tx);diff --git a/backend/src/ee/services/access-approval-policy/access-approval-policy-types.ts b/backend/src/ee/services/access-approval-policy/access-approval-policy-types.tsindex 27ec228f78..0ed8b05825 100644--- a/backend/src/ee/services/access-approval-policy/access-approval-policy-types.ts+++ b/backend/src/ee/services/access-approval-policy/access-approval-policy-types.ts@@ -41,6 +41,7 @@ export type TCreateAccessApprovalPolicy = {enforcementLevel: EnforcementLevel;allowedSelfApprovals: boolean;approvalsRequired?: { numberOfApprovals: number; stepNumber: number }[];+ maxTimePeriod?: string;} & Omit<TProjectPermission, "projectId">;export type TUpdateAccessApprovalPolicy = {@@ -60,6 +61,7 @@ export type TUpdateAccessApprovalPolicy = {allowedSelfApprovals: boolean;approvalsRequired?: { numberOfApprovals: number; stepNumber: number }[];environments?: string[];+ maxTimePeriod?: string;} & Omit<TProjectPermission, "projectId">;export type TDeleteAccessApprovalPolicy = {@@ -104,7 +106,8 @@ export interface TAccessApprovalPolicyServiceFactory {environment,enforcementLevel,allowedSelfApprovals,- approvalsRequired+ approvalsRequired,+ maxTimePeriod}: TCreateAccessApprovalPolicy) => Promise<{environment: {name: string;@@ -135,6 +138,7 @@ export interface TAccessApprovalPolicyServiceFactory {allowedSelfApprovals: boolean;secretPath: string;deletedAt?: Date | null | undefined;+ maxTimePeriod?: string | null;}>;deleteAccessApprovalPolicy: ({policyId,@@ -159,6 +163,7 @@ export interface TAccessApprovalPolicyServiceFactory {allowedSelfApprovals: boolean;secretPath: string;deletedAt?: Date | null | undefined;+ maxTimePeriod?: string | null;environment: {id: string;name: string;@@ -185,7 +190,8 @@ export interface TAccessApprovalPolicyServiceFactory {enforcementLevel,allowedSelfApprovals,approvalsRequired,- environments+ environments,+ maxTimePeriod}: TUpdateAccessApprovalPolicy) => Promise<{environment: {id: string;@@ -208,6 +214,7 @@ export interface TAccessApprovalPolicyServiceFactory {allowedSelfApprovals: boolean;secretPath?: string | null | undefined;deletedAt?: Date | null | undefined;+ maxTimePeriod?: string | null;}>;getAccessApprovalPolicyByProjectSlug: ({actorId,@@ -242,6 +249,7 @@ export interface TAccessApprovalPolicyServiceFactory {allowedSelfApprovals: boolean;secretPath: string;deletedAt?: Date | null | undefined;+ maxTimePeriod?: string | null;environment: {id: string;name: string;@@ -298,6 +306,7 @@ export interface TAccessApprovalPolicyServiceFactory {allowedSelfApprovals: boolean;secretPath: string;deletedAt?: Date | null | undefined;+ maxTimePeriod?: string | null;environment: {id: string;name: string;diff --git a/backend/src/ee/services/access-approval-request/access-approval-request-dal.ts b/backend/src/ee/services/access-approval-request/access-approval-request-dal.tsindex 9872df0676..68f9240a6a 100644--- a/backend/src/ee/services/access-approval-request/access-approval-request-dal.ts+++ b/backend/src/ee/services/access-approval-request/access-approval-request-dal.ts@@ -63,6 +63,7 @@ export interface TAccessApprovalRequestDALFactory extends Omit<TOrmify<TableNameenforcementLevel: string;allowedSelfApprovals: boolean;deletedAt: Date | null | undefined;+ maxTimePeriod?: string | null;};projectId: string;environments: string[];@@ -161,6 +162,7 @@ export interface TAccessApprovalRequestDALFactory extends Omit<TOrmify<TableNameallowedSelfApprovals: boolean;envId: string;deletedAt: Date | null | undefined;+ maxTimePeriod?: string | null;};projectId: string;environment: string;@@ -297,7 +299,8 @@ export const accessApprovalRequestDALFactory = (db: TDbClient): TAccessApprovalRdb.ref("enforcementLevel").withSchema(TableName.AccessApprovalPolicy).as("policyEnforcementLevel"),db.ref("allowedSelfApprovals").withSchema(TableName.AccessApprovalPolicy).as("policyAllowedSelfApprovals"),db.ref("envId").withSchema(TableName.AccessApprovalPolicy).as("policyEnvId"),- db.ref("deletedAt").withSchema(TableName.AccessApprovalPolicy).as("policyDeletedAt")+ db.ref("deletedAt").withSchema(TableName.AccessApprovalPolicy).as("policyDeletedAt"),+ db.ref("maxTimePeriod").withSchema(TableName.AccessApprovalPolicy).as("policyMaxTimePeriod")).select(db.ref("approverUserId").withSchema(TableName.AccessApprovalPolicyApprover)).select(db.ref("sequence").withSchema(TableName.AccessApprovalPolicyApprover).as("approverSequence"))@@ -364,7 +367,8 @@ export const accessApprovalRequestDALFactory = (db: TDbClient): TAccessApprovalRenforcementLevel: doc.policyEnforcementLevel,allowedSelfApprovals: doc.policyAllowedSelfApprovals,envId: doc.policyEnvId,- deletedAt: doc.policyDeletedAt+ deletedAt: doc.policyDeletedAt,+ maxTimePeriod: doc.policyMaxTimePeriod},requestedByUser: {userId: doc.requestedByUserId,@@ -574,7 +578,8 @@ export const accessApprovalRequestDALFactory = (db: TDbClient): TAccessApprovalRtx.ref("enforcementLevel").withSchema(TableName.AccessApprovalPolicy).as("policyEnforcementLevel"),tx.ref("allowedSelfApprovals").withSchema(TableName.AccessApprovalPolicy).as("policyAllowedSelfApprovals"),tx.ref("approvals").withSchema(TableName.AccessApprovalPolicy).as("policyApprovals"),- tx.ref("deletedAt").withSchema(TableName.AccessApprovalPolicy).as("policyDeletedAt")+ tx.ref("deletedAt").withSchema(TableName.AccessApprovalPolicy).as("policyDeletedAt"),+ tx.ref("maxTimePeriod").withSchema(TableName.AccessApprovalPolicy).as("policyMaxTimePeriod"));const findById: TAccessApprovalRequestDALFactory["findById"] = async (id, tx) => {@@ -595,7 +600,8 @@ export const accessApprovalRequestDALFactory = (db: TDbClient): TAccessApprovalRsecretPath: el.policySecretPath,enforcementLevel: el.policyEnforcementLevel,allowedSelfApprovals: el.policyAllowedSelfApprovals,- deletedAt: el.policyDeletedAt+ deletedAt: el.policyDeletedAt,+ maxTimePeriod: el.policyMaxTimePeriod},requestedByUser: {userId: el.requestedByUserId,diff --git a/backend/src/ee/services/access-approval-request/access-approval-request-service.ts b/backend/src/ee/services/access-approval-request/access-approval-request-service.tsindex dcbe717da0..58f5c57db5 100644--- a/backend/src/ee/services/access-approval-request/access-approval-request-service.ts+++ b/backend/src/ee/services/access-approval-request/access-approval-request-service.ts@@ -156,6 +156,15 @@ export const accessApprovalRequestServiceFactory = ({throw new BadRequestError({ message: "The policy linked to this request has been deleted" });}+ // Check if the requested time falls under policy.maxTimePeriod+ if (policy.maxTimePeriod) {+ if (!temporaryRange || ms(temporaryRange) > ms(policy.maxTimePeriod)) {+ throw new BadRequestError({+ message: `Requested access time range is limited to ${policy.maxTimePeriod} by policy`+ });+ }+ }+const approverIds: string[] = [];const approverGroupIds: string[] = [];diff --git a/backend/src/ee/services/access-approval-request/access-approval-request-types.ts b/backend/src/ee/services/access-approval-request/access-approval-request-types.tsindex 9066aec8fe..88a46192bd 100644--- a/backend/src/ee/services/access-approval-request/access-approval-request-types.ts+++ b/backend/src/ee/services/access-approval-request/access-approval-request-types.ts@@ -82,6 +82,7 @@ export interface TAccessApprovalRequestServiceFactory {allowedSelfApprovals: boolean;envId: string;deletedAt: Date | null | undefined;+ maxTimePeriod?: string | null;};projectId: string;environment: string;diff --git a/frontend/src/hooks/api/accessApproval/mutation.tsx b/frontend/src/hooks/api/accessApproval/mutation.tsxindex ad7917a8f6..69637243f4 100644--- a/frontend/src/hooks/api/accessApproval/mutation.tsx+++ b/frontend/src/hooks/api/accessApproval/mutation.tsx@@ -26,7 +26,8 @@ export const useCreateAccessApprovalPolicy = () => {secretPath,enforcementLevel,allowedSelfApprovals,- approvalsRequired+ approvalsRequired,+ maxTimePeriod}) => {const { data } = await apiRequest.post("/api/v1/access-approvals/policies", {environments,@@ -38,7 +39,8 @@ export const useCreateAccessApprovalPolicy = () => {name,enforcementLevel,allowedSelfApprovals,- approvalsRequired+ approvalsRequired,+ maxTimePeriod});return data;},@@ -64,7 +66,8 @@ export const useUpdateAccessApprovalPolicy = () => {enforcementLevel,allowedSelfApprovals,approvalsRequired,- environments+ environments,+ maxTimePeriod}) => {const { data } = await apiRequest.patch(`/api/v1/access-approvals/policies/${id}`, {approvals,@@ -75,7 +78,8 @@ export const useUpdateAccessApprovalPolicy = () => {enforcementLevel,allowedSelfApprovals,approvalsRequired,- environments+ environments,+ maxTimePeriod});return data;},diff --git a/frontend/src/hooks/api/accessApproval/types.ts b/frontend/src/hooks/api/accessApproval/types.tsindex bc569165b7..5d23449773 100644--- a/frontend/src/hooks/api/accessApproval/types.ts+++ b/frontend/src/hooks/api/accessApproval/types.ts@@ -18,6 +18,7 @@ export type TAccessApprovalPolicy = {approvers?: Approver[];bypassers?: Bypasser[];allowedSelfApprovals: boolean;+ maxTimePeriod?: string;};export enum ApproverType {@@ -93,6 +94,7 @@ export type TAccessApprovalRequest = {enforcementLevel: EnforcementLevel;deletedAt: Date | null;allowedSelfApprovals: boolean;+ maxTimePeriod: string | null;};reviewers: {@@ -173,6 +175,7 @@ export type TCreateAccessPolicyDTO = {enforcementLevel?: EnforcementLevel;allowedSelfApprovals: boolean;approvalsRequired?: { numberOfApprovals: number; stepNumber: number }[];+ maxTimePeriod?: string;};export type TUpdateAccessPolicyDTO = {@@ -188,6 +191,7 @@ export type TUpdateAccessPolicyDTO = {// for invalidating listprojectSlug: string;approvalsRequired?: { numberOfApprovals: number; stepNumber: number }[];+ maxTimePeriod?: string;};export type TDeleteSecretPolicyDTO = {diff --git a/frontend/src/pages/project/AccessControlPage/components/MembersTab/components/MemberRoleForm/SpecificPrivilegeSection.tsx b/frontend/src/pages/project/AccessControlPage/components/MembersTab/components/MemberRoleForm/SpecificPrivilegeSection.tsxindex 0256d32193..5dd4397444 100644--- a/frontend/src/pages/project/AccessControlPage/components/MembersTab/components/MemberRoleForm/SpecificPrivilegeSection.tsx+++ b/frontend/src/pages/project/AccessControlPage/components/MembersTab/components/MemberRoleForm/SpecificPrivilegeSection.tsx@@ -220,6 +220,24 @@ export const SpecificPrivilegeSecretForm = ({return;}+ const policy = policies.find(+ (p) =>+ p.environments.find((e) => e.slug === selectedEnvironment) && p.secretPath === secretPath+ );++ if (+ policy?.maxTimePeriod &&+ (!data.temporaryAccess.isTemporary ||+ ms(data.temporaryAccess.temporaryRange) > ms(policy.maxTimePeriod))+ ) {+ createNotification({+ type: "error",+ text: `Requested access time range is limited to ${policy.maxTimePeriod} by policy`,+ title: "Error"+ });+ return;+ }+const actions = [{ action: ProjectPermissionActions.Read, allowed: data.read },{ action: ProjectPermissionActions.Create, allowed: data.create },diff --git a/frontend/src/pages/secret-manager/SecretApprovalsPage/components/ApprovalPolicyList/components/AccessPolicyModal.tsx b/frontend/src/pages/secret-manager/SecretApprovalsPage/components/ApprovalPolicyList/components/AccessPolicyModal.tsxindex b254b8ac72..d555564704 100644--- a/frontend/src/pages/secret-manager/SecretApprovalsPage/components/ApprovalPolicyList/components/AccessPolicyModal.tsx+++ b/frontend/src/pages/secret-manager/SecretApprovalsPage/components/ApprovalPolicyList/components/AccessPolicyModal.tsx@@ -91,7 +91,8 @@ const formSchema = z}).array().default([])- .optional()+ .optional(),+ maxTimePeriod: z.string().trim().optional()}).superRefine((data, ctx) => {if (data.policyType === PolicyType.ChangePolicy) {@@ -440,6 +441,25 @@ const Form = ({</FormControl>)}/>++ {isAccessPolicyType && (+ <Controller+ control={control}+ name="maxTimePeriod"+ render={({ field, fieldState: { error } }) => (+ <FormControl+ label="Max. Time Period"+ tooltipText="The maximum amount of time someone can request access for. Ex: 1h, 3w, 30d"+ isError={Boolean(error)}+ errorText={error?.message}+ className="flex-shrink"+ >+ <Input {...field} value={field.value} placeholder="permanent" />+ </FormControl>+ )}+ />+ )}+{!isAccessPolicyType && (<Controllercontrol={control}diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/SecretListView/SecretDetailSidebar.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/SecretListView/SecretDetailSidebar.tsxindex d3845fcbca..953176ff5b 100644--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/SecretListView/SecretDetailSidebar.tsx+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/SecretListView/SecretDetailSidebar.tsx@@ -27,7 +27,10 @@ import { twMerge } from "tailwind-merge";import { UpgradePlanModal } from "@app/components/license/UpgradePlanModal";import { createNotification } from "@app/components/notifications";import { ProjectPermissionCan } from "@app/components/permissions";-import { hasSecretReference, SecretReferenceTree } from "@app/components/secrets/SecretReferenceDetails";+import {+ hasSecretReference,+ SecretReferenceTree+} from "@app/components/secrets/SecretReferenceDetails";import {Button,Drawer,@@ -49,8 +52,12 @@ import {Tooltip} from "@app/components/v2";import { InfisicalSecretInput } from "@app/components/v2/InfisicalSecretInput";-import { ProjectPermissionActions, ProjectPermissionSub, useProjectPermission, useWorkspace } from "@app/context";-+import {+ ProjectPermissionActions,+ ProjectPermissionSub,+ useProjectPermission,+ useWorkspace+} from "@app/context";import { ProjectPermissionSecretActions } from "@app/context/ProjectPermissionContext/types";import { getProjectBaseURL } from "@app/helpers/project";import { usePopUp } from "@app/hooks";