Skip to content

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

Merge branch 'main' into PLATFRM-114

x03220510e9eebc25ac
diff --cc backend/src/ee/services/pam-account/pam-account-service.ts
index b473b6b99b,945db36240..d3c7422d85
--- a/backend/src/ee/services/pam-account/pam-account-service.ts
+++ b/backend/src/ee/services/pam-account/pam-account-service.ts
@@@ -65,8 -58,7 +72,9 @@@ type TPamAccountServiceFactoryDep =
>;
userDAL: TUserDALFactory;
auditLogService: Pick<TAuditLogServiceFactory, "createAuditLog">;
+ approvalPolicyDAL: TApprovalPolicyDALFactory;
+ approvalRequestGrantsDAL: TApprovalRequestGrantsDALFactory;
+ pamSessionExpirationService: Pick<TPamSessionExpirationServiceFactory, "scheduleSessionExpiration">;
};
export type TPamAccountServiceFactory = ReturnType<typeof pamAccountServiceFactory>;
@@@ -84,8 -76,7 +92,9 @@@ export const pamAccountServiceFactory
kmsService,
gatewayV2Service,
auditLogService,
+ approvalPolicyDAL,
- approvalRequestGrantsDAL
++ approvalRequestGrantsDAL,
+ pamSessionExpirationService
}: TPamAccountServiceFactoryDep) => {
const create = async (
{
@@@ -549,51 -552,82 +570,109 @@@
const resource = await pamResourceDAL.findById(account.resourceId);
if (!resource) throw new NotFoundError({ message: `Resource with ID '${account.resourceId}' not found` });
- const { permission } = await permissionService.getProjectPermission({
- actor: actor.type,
- actorAuthMethod: actor.authMethod,
- actorId: actor.id,
- actorOrgId: actor.orgId,
- projectId,
- actionProjectType: ActionProjectType.PAM
- });
+ const fac = APPROVAL_POLICY_FACTORY_MAP[ApprovalPolicyType.PamAccess](ApprovalPolicyType.PamAccess);
- ForbiddenError.from(permission).throwUnlessCan(
- ProjectPermissionPamAccountActions.Access,
- subject(ProjectPermissionSub.PamAccounts, {
- resourceName: resource.name,
- accountName: account.name,
- accountPath: folderPath
- })
- );
+ const inputs = {
+ resourceId: resource.id,
+ accountPath: path.join(folderPath, account.name)
+ };
+
+ const canAccess = await fac.canAccess(approvalRequestGrantsDAL, resource.projectId, actor.id, inputs);
+
+ if (canAccess) {
+ // Grant exists, allow access without checking permission
+ } else {
+ const policy = await fac.matchPolicy(approvalPolicyDAL, resource.projectId, inputs);
+
+ if (policy) {
+ throw new PolicyViolationError({
+ message: "A policy is in place for this resource",
+ details: {
+ policyId: policy.id,
+ policyName: policy.name,
+ policyType: policy.type
+ }
+ });
+ }
+
+ // If there isn't a policy in place, continue with checking permission
+ const { permission } = await permissionService.getProjectPermission({
+ actor: actor.type,
+ actorAuthMethod: actor.authMethod,
+ actorId: actor.id,
+ actorOrgId: actor.orgId,
+ projectId: account.projectId,
+ actionProjectType: ActionProjectType.PAM
+ });
+
+ ForbiddenError.from(permission).throwUnlessCan(
+ ProjectPermissionPamAccountActions.Access,
+ subject(ProjectPermissionSub.PamAccounts, {
+ resourceName: resource.name,
+ accountName: account.name,
+ accountPath: folderPath
+ })
+ );
+ }
+ const { connectionDetails, gatewayId, resourceType } = await decryptResource(
+ resource,
+ account.projectId,
+ kmsService
+ );
+
+ const user = await userDAL.findById(actor.id);
+ if (!user) throw new NotFoundError({ message: `User with ID '${actor.id}' not found` });
+
+ if (resourceType === PamResource.AwsIam) {
+ const awsCredentials = (await decryptAccountCredentials({
+ encryptedCredentials: account.encryptedCredentials,
+ kmsService,
+ projectId: account.projectId
+ })) as TAwsIamAccountCredentials;
+
+ const { consoleUrl, expiresAt } = await generateConsoleFederationUrl({
+ connectionDetails,
+ targetRoleArn: awsCredentials.targetRoleArn,
+ roleSessionName: actorEmail,
+ projectId: account.projectId, // Use project ID as External ID for security
+ sessionDuration: awsCredentials.defaultSessionDuration
+ });
+
+ const session = await pamSessionDAL.create({
+ accountName: account.name,
+ actorEmail,
+ actorIp,
+ actorName,
+ actorUserAgent,
+ projectId: account.projectId,
+ resourceName: resource.name,
+ resourceType: resource.resourceType,
+ status: PamSessionStatus.Active, // AWS IAM sessions are immediately active
+ accountId: account.id,
+ userId: actor.id,
+ expiresAt,
+ startedAt: new Date()
+ });
+
+ // Schedule session expiration job to run at expiresAt
+ await pamSessionExpirationService.scheduleSessionExpiration(session.id, expiresAt);
+
+ return {
+ sessionId: session.id,
+ resourceType,
+ account,
+ consoleUrl,
+ metadata: {
+ awsAccountId: extractAwsAccountIdFromArn(connectionDetails.roleArn),
+ targetRoleArn: awsCredentials.targetRoleArn,
+ federatedUsername: actorEmail,
+ expiresAt: expiresAt.toISOString()
+ }
+ };
+ }
+
+ // For gateway-based resources (Postgres, MySQL, SSH), create session first
const session = await pamSessionDAL.create({
accountName: account.name,
actorEmail,
diff --cc backend/src/server/routes/index.ts
index 382ff30d7e,cee4f58ae4..e191aa0432
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@@ -2428,7 -2413,10 +2429,11 @@@ export const registerRoutes = async
gatewayV2Service
});
+ const approvalPolicyDAL = approvalPolicyDALFactory(db);
+ const pamSessionExpirationService = pamSessionExpirationServiceFactory({
+ queueService,
+ pamSessionDAL
+ });
const pamAccountService = pamAccountServiceFactory({
pamAccountDAL,
@@@ -2442,8 -2430,7 +2447,9 @@@
projectDAL,
userDAL,
auditLogService,
+ approvalRequestGrantsDAL,
- approvalPolicyDAL
++ approvalPolicyDAL,
+ pamSessionExpirationService
});
const pamAccountRotation = pamAccountRotationServiceFactory({