Skip to content

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

refactor(pam-windows): expose username in access metadata, simplify schema

bernie-g215e4758cd25
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 26ae19f78b..de0ce5a511 100644
--- a/backend/src/ee/services/pam-account/pam-account-service.ts
+++ b/backend/src/ee/services/pam-account/pam-account-service.ts
@@ -72,6 +72,7 @@ import { TPamAccountCredentials } from "../pam-resource/pam-resource-types";
import { TRedisAccountCredentials } from "../pam-resource/redis/redis-resource-types";
import { TSqlAccountCredentials, TSqlResourceConnectionDetails } from "../pam-resource/shared/sql/sql-resource-types";
import { TSSHAccountCredentials, TSSHResourceInternalMetadata } from "../pam-resource/ssh/ssh-resource-types";
+import { TWindowsAccountCredentials } from "../pam-resource/windows-server/windows-server-resource-types";
import { TPamSessionDALFactory } from "../pam-session/pam-session-dal";
import { PamSessionStatus } from "../pam-session/pam-session-enums";
import { OrgPermissionGatewayActions, OrgPermissionSubjects } from "../permission/org-permission";
@@ -1065,6 +1066,19 @@ export const pamAccountServiceFactory = ({
};
}
break;
+ case PamResource.Windows:
+ {
+ const credentials = (await decryptAccountCredentials({
+ encryptedCredentials: account.encryptedCredentials,
+ kmsService,
+ projectId
+ })) as TWindowsAccountCredentials;
+
+ metadata = {
+ username: credentials.username
+ };
+ }
+ break;
case PamResource.Kubernetes:
metadata = {
resourceName: resource.name,
@@ -1300,9 +1314,6 @@ export const pamAccountServiceFactory = ({
}
}
- // Windows connection details store the target as `hostname`; every other
- // resource type (and the gateway's handler code) reads `host`. Remap
- // before returning so the gateway never has to special-case it.
if (decryptedResource.resourceType === PamResource.Windows) {
const { hostname, ...rest } = decryptedResource.connectionDetails as {
hostname: string;
@@ -1312,7 +1323,6 @@ export const pamAccountServiceFactory = ({
credentials: {
...rest,
host: hostname,
- accountName: account.name,
...decryptedAccount.credentials
},
policyRules,
diff --git a/backend/src/ee/services/pam-resource/windows-server/windows-server-resource-schemas.ts b/backend/src/ee/services/pam-resource/windows-server/windows-server-resource-schemas.ts
index 0b63032de7..643e16cb09 100644
--- a/backend/src/ee/services/pam-resource/windows-server/windows-server-resource-schemas.ts
+++ b/backend/src/ee/services/pam-resource/windows-server/windows-server-resource-schemas.ts
@@ -121,24 +121,8 @@ export const SanitizedWindowsAccountWithResourceSchema = BasePamAccountSchemaWit
});
// Sessions
-// Note the `host` field here: resource-facing schemas use `hostname` (matches
-// Windows / AD terminology), but the session-credentials endpoint remaps it to
-// `host` before responding so the gateway's handler dispatch can share one
-// code path across every resource type (all other resource types already
-// return `host`). See getSessionCredentials in pam-account-service.
-export const WindowsSessionCredentialsSchema = z
- .object({
- protocol: z.literal(WindowsProtocol.RDP),
- host: z.string().trim().min(1).max(255),
- port: z.coerce.number().int().min(1).max(65535),
- winrmPort: z.coerce.number().int().min(1).max(65535),
- useWinrmHttps: z.boolean(),
- winrmRejectUnauthorized: z.boolean(),
- winrmCaCert: z.string().optional(),
- winrmTlsServerName: z.string().optional(),
- // Account name from the CLI flag (e.g. --account test). The gateway's
- // RDP MITM bridge expects the user to type this into their RDP client,
- // distinct from the actual Windows username injected to the target.
- accountName: z.string().trim().min(1).max(255)
- })
+// Renames `hostname` to `host` so the gateway can dispatch all resource types
+// uniformly on a `host` field.
+export const WindowsSessionCredentialsSchema = WindowsResourceConnectionDetailsSchema.omit({ hostname: true })
+ .extend({ host: z.string().trim().min(1).max(255) })
.and(WindowsAccountCredentialsSchema);