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
Merge remote-tracking branch 'origin/pam-revamp' into bernie/pam-286-technical-plan-access-request-implementation
bernie-g20b8923cf28c
diff --cc backend/src/ee/services/pam-session/pam-session-service.tsindex 371cb58335,e8b01bf039..e0c87562ee--- a/backend/src/ee/services/pam-session/pam-session-service.ts+++ b/backend/src/ee/services/pam-session/pam-session-service.ts@@@ -52,7 -52,12 +53,13 @@@ import { TPamFolderDALFactory } from ".import { PamRecordingStorageBackend } from "../pam-session-recording/pam-recording-enums";import { generateSessionRecordingSecrets } from "../pam-session-recording/pam-recording-secrets";import { ResourcePermissionPamResourceActions } from "../permission/resource-permission";+import { TPamAccessRequestServiceFactory } from "../pam-access-request/pam-access-request-service";+ import {+ AWS_STS_MIN_DURATION_SECONDS,+ exchangeCredentialsForConsoleUrl,+ extractAwsAccountIdFromArn,+ generateAwsIamSessionCredentials+ } from "./aws-iam/aws-iam-federation";import { DEFAULT_SESSION_DURATION_MS } from "./pam-session-constants";import { TPamSessionDALFactory } from "./pam-session-dal";import { TPamSessionExpirationServiceFactory } from "./pam-session-expiration-queue";@@@ -391,32 -424,92 +400,106 @@@ export const pamSessionServiceFactorysessionDurationMs = Math.min(parsed, maxDurationMs);}- await checkAccount(account.id, account.folderId, projectId, launchAuthorizationAction, actor);-- enforceRecordingConfig(account);-+ if (requiresApproval) {+ const grant = await pamAccessRequestService.checkGrant({+ userId: actor.actorId,+ accountId: account.id,+ projectId+ });+ if (!grant) {+ throw new ForbiddenRequestError({+ name: "PAM_APPROVAL_REQUIRED",+ message: "Access request required"+ });+ }+ const grantRemainingMs = new Date(grant.expiresAt!).getTime() - Date.now();+ if (grantRemainingMs <= 0) {+ throw new ForbiddenRequestError({+ name: "PAM_APPROVAL_REQUIRED",+ message: "Access grant has expired"+ });+ }+ sessionDurationMs = Math.min(sessionDurationMs, grantRemainingMs);+ }++ // AWS IAM: no gateway, no proxy -- generate STS credentials directly+ if (account.accountType === PamAccountType.AwsIam) {+ const stsDurationSeconds = Math.floor(sessionDurationMs / 1000);++ if (stsDurationSeconds < AWS_STS_MIN_DURATION_SECONDS) {+ throw new BadRequestError({+ message: `AWS IAM sessions require a minimum duration of ${AWS_STS_MIN_DURATION_SECONDS} seconds (15 minutes)`+ });+ }++ const rawConnectionDetails = await decrypt(projectId, account.encryptedConnectionDetails);+ const rawCredentials = await decrypt(projectId, account.encryptedCredentials);++ const stsCredentials = await generateAwsIamSessionCredentials({+ connectionDetails: { roleArn: rawConnectionDetails.roleArn as string },+ targetRoleArn: rawCredentials.targetRoleArn as string,+ roleSessionName: actorEmail.replace(new RE2(/[^\w+=,.@-]/g), "_").substring(0, 64),+ projectId,+ sessionDuration: stsDurationSeconds+ });++ const { expiresAt } = stsCredentials;++ const metadata: Record<string, string> = {};++ if (accessMethod === PamAccessMethod.Web) {+ const consoleUrl = await exchangeCredentialsForConsoleUrl({+ accessKeyId: stsCredentials.accessKeyId,+ secretAccessKey: stsCredentials.secretAccessKey,+ sessionToken: stsCredentials.sessionToken+ });+ metadata.consoleUrl = consoleUrl;+ } else {+ metadata.accessKeyId = stsCredentials.accessKeyId;+ metadata.secretAccessKey = stsCredentials.secretAccessKey;+ metadata.sessionToken = stsCredentials.sessionToken;+ metadata.expiresAt = expiresAt.toISOString();+ metadata.targetRoleArn = rawCredentials.targetRoleArn as string;+ metadata.federatedUsername = actorEmail;++ const awsAccountId = extractAwsAccountIdFromArn(rawConnectionDetails.roleArn as string);+ if (awsAccountId) {+ metadata.awsAccountId = awsAccountId;+ }+ }++ const session = await pamSessionDAL.create({+ status: PamSessionStatus.Active,+ accessMethod,+ expiresAt,+ startedAt: new Date(),+ accountName: account.name,+ accountType: account.accountType,+ actorEmail,+ actorIp,+ actorName,+ actorUserAgent,+ projectId,+ accountId: account.id,+ userId: actor.actorId,+ reason: trimmedReason,+ folderName: account.folderName+ });++ await pamSessionExpirationService.scheduleSessionExpiration(session.id, expiresAt);++ return {+ sessionId: session.id,+ accountId: account.id,+ accountType: account.accountType as PamAccountType,+ accountName: account.name,+ metadata,+ sessionDurationMs+ };+ }+- await checkAccount(- account.id,- account.folderId,- projectId,- ResourcePermissionPamResourceActions.LaunchSessions,- actor- );-+ enforceRecordingConfig(account);+const effectiveGatewayId = await gatewayPoolService.resolveEffectiveGatewayId({gatewayId: account.gatewayId ?? account.templateGatewayId,gatewayPoolId: account.gatewayPoolId ?? account.templateGatewayPoolIddiff --cc frontend/src/pages/pam/PamTemplatesPage/components/TemplateDetailSheet.tsxindex a3589a25e5,27e3358947..73773f7a18--- a/frontend/src/pages/pam/PamTemplatesPage/components/TemplateDetailSheet.tsx+++ b/frontend/src/pages/pam/PamTemplatesPage/components/TemplateDetailSheet.tsx@@@ -385,237 -380,229 +386,243 @@@ const SettingsTab = (return (<form onSubmit={handleSubmit(onSubmit)} className="flex flex-1 flex-col gap-4 p-4">- {applicablePolicies.length > 0 && (- <Card>- <CardHeader className="border-b">- <CardTitle className="text-base">Policies</CardTitle>- <CardDescription>- Policies available for {typeName} accounts using this template.- </CardDescription>- </CardHeader>- <CardContent className="flex flex-col gap-6">- {applicablePolicies.map((p) => {- const Editor = POLICY_EDITORS[p.key]!;- return (- <Editor- key={p.key}- label={p.label}- description={p.description}- value={policies[p.key]}- onChange={(value) => {- const next = { ...policies };- if (value === null || value === undefined) delete next[p.key];- else next[p.key] = value;- setValue("policies", next, { shouldDirty: true });- }}- />- );- })}- </CardContent>- </Card>- )}+ <Card>+ <CardHeader className="border-b">+ <CardTitle className="text-base">Policies</CardTitle>+ <CardDescription>+ Policies available for {typeName} accounts using this template.+ </CardDescription>+ </CardHeader>+ <CardContent className="flex flex-col gap-6">+ <Controller+ control={control}+ name="requiresApproval"+ render={({ field }) => (+ <Field orientation="horizontal" className="items-center!">+ <FieldContent>+ <FieldTitle>Require Approval</FieldTitle>+ <FieldDescription>+ Users must request and receive approval before launching sessions on accounts+ using this template.+ </FieldDescription>+ </FieldContent>+ <Switch checked={field.value} variant="pam" onCheckedChange={field.onChange} />+ </Field>+ )}+ />+ {applicablePolicies.map((p) => {+ const Editor = POLICY_EDITORS[p.key]!;+ return (+ <Editor+ key={p.key}+ label={p.label}+ description={p.description}+ value={policies[p.key]}+ onChange={(value) => {+ const next = { ...policies };+ if (value === null || value === undefined) delete next[p.key];+ else next[p.key] = value;+ setValue("policies", next, { shouldDirty: true });+ }}+ />+ );+ })}+ </CardContent>+ </Card>- <Card>- <CardHeader className="border-b">- <CardTitle className="text-base">System Settings</CardTitle>- <CardDescription>System-level defaults for accounts using this template.</CardDescription>- </CardHeader>- <CardContent className="flex flex-col gap-6">- <Field>- <FieldLabel>Gateway</FieldLabel>- <FieldContent>- <GatewayPicker- value={{ gatewayId, gatewayPoolId }}- onChange={(value) => {- setValue("gatewayId", value.gatewayId, { shouldDirty: true });- setValue("gatewayPoolId", value.gatewayPoolId, { shouldDirty: true });- }}- noGatewayLabel="No Gateway"- noGatewayIcon={Ban}- />- <FieldDescription>- Used to reach accounts unless overridden on the account.- </FieldDescription>- </FieldContent>- </Field>- </CardContent>- </Card>-- <Card>- <CardHeader className="border-b">- <CardTitle className="text-base">Session Recording</CardTitle>- <CardDescription>- Where session recordings for accounts using this template are stored.- </CardDescription>- </CardHeader>- <CardContent className="flex flex-col gap-6">- <Controller- name="recordingStorageBackend"- control={control}- render={({ field }) => (- <Field>- <FieldLabel>Storage backend</FieldLabel>- <FieldContent>- <Select value={field.value} onValueChange={(v) => field.onChange(v)}>- <SelectTrigger className="w-full">- <SelectValue />- </SelectTrigger>- <SelectContent position="popper">- <SelectItem value="postgres">Internal Database</SelectItem>- <SelectItem value="aws-s3">AWS S3</SelectItem>- </SelectContent>- </Select>- </FieldContent>- </Field>- )}- />-- {requiresRecording && storageBackend === "postgres" && (- <Alert variant="warning">- <AlertTriangleIcon />- <AlertTitle>Accounts cannot be launched</AlertTitle>- <AlertDescription>- {typeName} accounts require an external recording storage backend. Accounts using- this template can still be created, but sessions can't be launched until- external storage is configured.- </AlertDescription>- </Alert>- )}-- {storageBackend === "aws-s3" && (- <>+ {showGatewaySettings && (+ <Card>+ <CardHeader className="border-b">+ <CardTitle className="text-base">System Settings</CardTitle>+ <CardDescription>+ System-level defaults for accounts using this template.+ </CardDescription>+ </CardHeader>+ <CardContent className="flex flex-col gap-6">+ <Field>+ <FieldLabel>Gateway</FieldLabel>+ <FieldContent>+ <GatewayPicker+ value={{ gatewayId, gatewayPoolId }}+ onChange={(value) => {+ setValue("gatewayId", value.gatewayId, { shouldDirty: true });+ setValue("gatewayPoolId", value.gatewayPoolId, { shouldDirty: true });+ }}+ noGatewayLabel="No Gateway"+ noGatewayIcon={Ban}+ />+ <FieldDescription>+ Used to reach accounts unless overridden on the account.+ </FieldDescription>+ </FieldContent>+ </Field>+ </CardContent>+ </Card>+ )}++ {showGatewaySettings && (+ <Card>+ <CardHeader className="border-b">+ <CardTitle className="text-base">Session Recording</CardTitle>+ <CardDescription>+ Where session recordings for accounts using this template are stored.+ </CardDescription>+ </CardHeader>+ <CardContent className="flex flex-col gap-6">+ <Controller+ name="recordingStorageBackend"+ control={control}+ render={({ field }) => (+ <Field>+ <FieldLabel>Storage backend</FieldLabel>+ <FieldContent>+ <Select value={field.value} onValueChange={(v) => field.onChange(v)}>+ <SelectTrigger className="w-full">+ <SelectValue />+ </SelectTrigger>+ <SelectContent position="popper">+ <SelectItem value="postgres">Internal Database</SelectItem>+ <SelectItem value="aws-s3">AWS S3</SelectItem>+ </SelectContent>+ </Select>+ </FieldContent>+ </Field>+ )}+ />++ {requiresRecording && storageBackend === "postgres" && (<Alert variant="warning"><AlertTriangleIcon />- <AlertTitle>Changing bucket affects existing recordings</AlertTitle>+ <AlertTitle>Accounts cannot be launched</AlertTitle><AlertDescription>- Changing the bucket on a template with existing recordings makes those recordings- inaccessible unless you manually migrate each object. Keep the same bucket and key- prefix when rotating credentials.+ {typeName} accounts require an external recording storage backend. Accounts using+ this template can still be created, but sessions can't be launched until+ external storage is configured.</AlertDescription></Alert>+ )}- <Controller- name="recordingConnectionId"- control={control}- render={({ field, fieldState }) => (- <Field>- <FieldLabel>AWS Connection</FieldLabel>- <FieldContent>- <Select- value={field.value ?? ""}- onValueChange={(v) => field.onChange(v || null)}- >- <SelectTrigger className="w-full" isError={!!fieldState.error}>- <SelectValue placeholder="Select an AWS connection" />- </SelectTrigger>- <SelectContent position="popper">- {awsConnections.map((conn) => (- <SelectItem key={conn.id} value={conn.id}>- {conn.name}- </SelectItem>- ))}- </SelectContent>- </Select>- {fieldState.error ? (- <FieldError>{fieldState.error.message}</FieldError>- ) : (- <FieldDescription>- The AWS connection used to authenticate with S3.- </FieldDescription>- )}- </FieldContent>- </Field>- )}- />-- <Controller- name="s3Bucket"- control={control}- render={({ field, fieldState }) => (- <Field>- <FieldLabel>S3 Bucket</FieldLabel>- <FieldContent>- <Input- {...field}- placeholder="my-recordings-bucket"- isError={!!fieldState.error}- />- <FieldError>{fieldState.error?.message}</FieldError>- </FieldContent>- </Field>- )}- />-- <Controller- name="s3Region"- control={control}- render={({ field }) => (- <Field>- <FieldLabel>Region</FieldLabel>- <FieldContent>- <Input {...field} placeholder="us-east-1" />- </FieldContent>- </Field>- )}- />-- <Controller- name="s3KeyPrefix"- control={control}- render={({ field }) => (- <Field>- <FieldLabel>Key prefix (optional)</FieldLabel>- <FieldContent>- <Input {...field} placeholder="pam-recordings/" />- <FieldDescription>Optional prefix for S3 object keys.</FieldDescription>- </FieldContent>- </Field>- )}- />- </>- )}-- <Controller- control={control}- name="settings.sessionLogMaskingPatterns"- render={({ field, fieldState }) => (- <Field>- <FieldLabel>Session Log Masking</FieldLabel>- <FieldContent>- <TextArea- rows={5}- placeholder={"rm\\s+-rf.*\npassword\\s*=\\s*\\S+\n\\b\\d{3}-\\d{2}-\\d{4}\\b"}- value={field.value ?? ""}- isError={!!fieldState.error}- onChange={(e) => {- const val = e.target.value;- field.onChange(val.trim() ? val : "");- }}- />- <FieldDescription>- Matching content in session recordings will be masked (one regex per line).- </FieldDescription>- <FieldError>{fieldState.error?.message}</FieldError>- </FieldContent>- </Field>+ {storageBackend === "aws-s3" && (+ <>+ <Alert variant="warning">+ <AlertTriangleIcon />+ <AlertTitle>Changing bucket affects existing recordings</AlertTitle>+ <AlertDescription>+ Changing the bucket on a template with existing recordings makes those+ recordings inaccessible unless you manually migrate each object. Keep the same+ bucket and key prefix when rotating credentials.+ </AlertDescription>+ </Alert>++ <Controller+ name="recordingConnectionId"+ control={control}+ render={({ field, fieldState }) => (+ <Field>+ <FieldLabel>AWS Connection</FieldLabel>+ <FieldContent>+ <Select+ value={field.value ?? ""}+ onValueChange={(v) => field.onChange(v || null)}+ >+ <SelectTrigger className="w-full" isError={!!fieldState.error}>+ <SelectValue placeholder="Select an AWS connection" />+ </SelectTrigger>+ <SelectContent position="popper">+ {awsConnections.map((conn) => (+ <SelectItem key={conn.id} value={conn.id}>+ {conn.name}+ </SelectItem>+ ))}+ </SelectContent>+ </Select>+ {fieldState.error ? (+ <FieldError>{fieldState.error.message}</FieldError>+ ) : (+ <FieldDescription>+ The AWS connection used to authenticate with S3.+ </FieldDescription>+ )}+ </FieldContent>+ </Field>+ )}+ />++ <Controller+ name="s3Bucket"+ control={control}+ render={({ field, fieldState }) => (+ <Field>+ <FieldLabel>S3 Bucket</FieldLabel>+ <FieldContent>+ <Input+ {...field}+ placeholder="my-recordings-bucket"+ isError={!!fieldState.error}+ />+ <FieldError>{fieldState.error?.message}</FieldError>+ </FieldContent>+ </Field>+ )}+ />++ <Controller+ name="s3Region"+ control={control}+ render={({ field }) => (+ <Field>+ <FieldLabel>Region</FieldLabel>+ <FieldContent>+ <Input {...field} placeholder="us-east-1" />+ </FieldContent>+ </Field>+ )}+ />++ <Controller+ name="s3KeyPrefix"+ control={control}+ render={({ field }) => (+ <Field>+ <FieldLabel>Key prefix (optional)</FieldLabel>+ <FieldContent>+ <Input {...field} placeholder="pam-recordings/" />+ <FieldDescription>Optional prefix for S3 object keys.</FieldDescription>+ </FieldContent>+ </Field>+ )}+ />+ </>)}- />- </CardContent>- </Card>++ <Controller+ control={control}+ name="settings.sessionLogMaskingPatterns"+ render={({ field, fieldState }) => (+ <Field>+ <FieldLabel>Session Log Masking</FieldLabel>+ <FieldContent>+ <TextArea+ rows={5}+ placeholder={"rm\\s+-rf.*\npassword\\s*=\\s*\\S+\n\\b\\d{3}-\\d{2}-\\d{4}\\b"}+ value={field.value ?? ""}+ isError={!!fieldState.error}+ onChange={(e) => {+ const val = e.target.value;+ field.onChange(val.trim() ? val : "");+ }}+ />+ <FieldDescription>+ Matching content in session recordings will be masked (one regex per line).+ </FieldDescription>+ <FieldError>{fieldState.error?.message}</FieldError>+ </FieldContent>+ </Field>+ )}+ />+ </CardContent>+ </Card>+ )}<div aria-hidden className="h-8 shrink-0" />{isDirty && <SheetSaveBar isPending={updateTemplate.isPending} onDiscard={() => reset()} />}