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
fix: address pam aws console-url review feedback
x032205da5762b2f952
diff --git a/backend/src/ee/routes/v1/pam-account-routers/pam-account-router.ts b/backend/src/ee/routes/v1/pam-account-routers/pam-account-router.tsindex 46e1067984..2c0bab0168 100644--- a/backend/src/ee/routes/v1/pam-account-routers/pam-account-router.ts+++ b/backend/src/ee/routes/v1/pam-account-routers/pam-account-router.ts@@ -664,6 +664,22 @@ export const registerPamAccountRouter = async (server: FastifyZodProvider) => {req.permission);+ // Each console-URL mint produces a fresh authenticated browser session,+ // so audit it independently from the originating /access call.+ await server.services.auditLog.createAuditLog({+ ...req.auditLogInfo,+ orgId: req.permission.orgId,+ projectId: req.body.projectId,+ event: {+ type: EventType.PAM_ACCOUNT_ACCESS,+ metadata: {+ accountId: result.accountId ?? "",+ resourceName: result.resourceName,+ accountName: result.accountName+ }+ }+ });+return { consoleUrl: result.consoleUrl };}});diff --git a/backend/src/ee/services/pam-account/pam-account-service.ts b/backend/src/ee/services/pam-account/pam-account-service.tsindex 70f468f823..13a78b2574 100644--- a/backend/src/ee/services/pam-account/pam-account-service.ts+++ b/backend/src/ee/services/pam-account/pam-account-service.ts@@ -25,6 +25,7 @@ import {import { createSshCert, createSshKeyPair } from "@app/ee/services/ssh/ssh-certificate-authority-fns";import { SshCertType } from "@app/ee/services/ssh/ssh-certificate-authority-types";import { SshCertKeyAlgorithm } from "@app/ee/services/ssh-certificate/ssh-certificate-types";+import { KeyStorePrefixes, TKeyStoreFactory } from "@app/keystore/keystore";import { DatabaseErrorCode } from "@app/lib/error-codes";import {BadRequestError,@@ -118,6 +119,7 @@ type TPamAccountServiceFactoryDep = {TPamAccountDependenciesDALFactory,"findByAccountId" | "updateById" | "countByAccountIds">;+ keyStore: Pick<TKeyStoreFactory, "setItemWithExpiry" | "getItem">;};export type TPamAccountServiceFactory = ReturnType<typeof pamAccountServiceFactory>;@@ -143,7 +145,8 @@ export const pamAccountServiceFactory = ({approvalRequestGrantsDAL,pamSessionExpirationService,resourceMetadataDAL,- pamAccountDependenciesDAL+ pamAccountDependenciesDAL,+ keyStore}: TPamAccountServiceFactoryDep) => {// Helper to resolve account parent (resource or domain)const resolveAccountParent = async ({@@ -889,6 +892,18 @@ export const pamAccountServiceFactory = ({startedAt: new Date()});+ // Cache the AccessKeyId so /aws-console-url can verify the caller is+ // submitting credentials that actually belong to this session, not creds+ // from some other AWS role they happen to control. AccessKeyId is a+ // non-secret identifier (analogous to a username); the secret/token are+ // never stored server-side.+ const ttlSeconds = Math.max(1, Math.floor((credentials.expiresAt.getTime() - Date.now()) / 1000));+ await keyStore.setItemWithExpiry(+ KeyStorePrefixes.PamAwsIamAccessKeyId(session.id),+ ttlSeconds,+ credentials.accessKeyId+ );+// Schedule session expiration job to run at expiresAtawait pamSessionExpirationService.scheduleSessionExpiration(session.id, credentials.expiresAt);@@ -1084,13 +1099,34 @@ export const pamAccountServiceFactory = ({throw new BadRequestError({ message: "Session has ended or expired" });}+ // Confirm the submitted creds actually belong to this session by comparing+ // against the AccessKeyId we stashed at /access time. If the cache entry is+ // gone, the session has effectively expired even if the row hasn't been+ // marked yet.+ const expectedAccessKeyId = await keyStore.getItem(KeyStorePrefixes.PamAwsIamAccessKeyId(sessionId));+ if (!expectedAccessKeyId) {+ throw new BadRequestError({+ message: "Session credentials are no longer available. Please re-access the account."+ });+ }+ if (expectedAccessKeyId !== accessKeyId) {+ throw new ForbiddenRequestError({+ message: "Submitted credentials do not match the session"+ });+ }+const consoleUrl = await exchangeCredentialsForConsoleUrl({accessKeyId,secretAccessKey,sessionToken});- return { consoleUrl };+ return {+ consoleUrl,+ accountId: session.accountId,+ accountName: session.accountName,+ resourceName: session.resourceName+ };};const getSessionCredentials = async (sessionId: string, actor: OrgServiceActor) => {diff --git a/backend/src/keystore/keystore.ts b/backend/src/keystore/keystore.tsindex 788ab234d5..7cbc866330 100644--- a/backend/src/keystore/keystore.ts+++ b/backend/src/keystore/keystore.ts@@ -99,6 +99,8 @@ export const KeyStorePrefixes = {TelemetryGroupIdentify: (orgId: string) => `telemetry-group-identify:${orgId}` as const,SecretEtag: (projectId: string) => `secret-etag:${projectId}` as const,+ PamAwsIamAccessKeyId: (sessionId: string) => `pam-aws-iam-access-key-id:${sessionId}` as const,+CertDashboardStats: (projectId: string) => `cert-dashboard-stats:${projectId}` as const,CertActivityTrend: (projectId: string, range: string) => `cert-activity-trend:${projectId}:${range}` as const,CertPqcTrend: (projectId: string, range: string) => `cert-pqc-trend:${projectId}:${range}` as const,diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.tsindex dcd76b4e63..451eb875e8 100644--- a/backend/src/server/routes/index.ts+++ b/backend/src/server/routes/index.ts@@ -2913,7 +2913,8 @@ export const registerRoutes = async (approvalPolicyDAL,pamSessionExpirationService,resourceMetadataDAL,- pamAccountDependenciesDAL+ pamAccountDependenciesDAL,+ keyStore});const pamAccountRotation = pamAccountRotationServiceFactory({