Skip to content

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

discrim union

Andreyc4175b117394
diff --git a/backend/src/ee/routes/v1/pam-routers/pam-account-router.ts b/backend/src/ee/routes/v1/pam-routers/pam-account-router.ts
index 4697f2044d..8a3be67bea 100644
--- a/backend/src/ee/routes/v1/pam-routers/pam-account-router.ts
+++ b/backend/src/ee/routes/v1/pam-routers/pam-account-router.ts
@@ -7,7 +7,8 @@ import {
ACCOUNT_TYPE_CONFIGS,
buildPamAccountTypeMetadata,
PamAccountAccessibilityIssue,
- PamAccountTypeMetadataSchema
+ PamAccountTypeMetadataSchema,
+ revealedCredentialsSchema
} from "@app/ee/services/pam-account/pam-account-schemas";
import { ROTATION_STATUS } from "@app/ee/services/pam-account-rotation/pam-account-rotation-service";
import {
@@ -89,6 +90,23 @@ const SanitizedAccountDetailSchema = z.discriminatedUnion(
accountDetailVariants as [(typeof accountDetailVariants)[number], ...(typeof accountDetailVariants)[number][]]
);
+const accountCredentialVariants = Object.keys(ACCOUNT_TYPE_CONFIGS).map((accountType) =>
+ z.object({
+ accountType: z.literal(accountType as TSupportedAccountType),
+ credentials: revealedCredentialsSchema(accountType as TSupportedAccountType).describe(
+ "The account's stored credentials, secrets included"
+ )
+ })
+);
+
+const PamAccountCredentialsSchema = z.discriminatedUnion(
+ "accountType",
+ accountCredentialVariants as [
+ (typeof accountCredentialVariants)[number],
+ ...(typeof accountCredentialVariants)[number][]
+ ]
+);
+
const toPascalCase = (s: string) =>
s
.split("-")
@@ -773,10 +791,7 @@ export const registerPamAccountRouter = async (server: FastifyZodProvider) => {
.describe("A verified MFA session ID. Required when the template requires MFA.")
}),
response: {
- 200: z.object({
- accountType: z.string().describe("The account's platform type"),
- credentials: z.record(z.unknown()).describe("The account's stored credentials, secrets included")
- })
+ 200: PamAccountCredentialsSchema
}
},
config: { rateLimit: writeLimit },
@@ -812,7 +827,9 @@ export const registerPamAccountRouter = async (server: FastifyZodProvider) => {
}
});
- return { accountType: result.accountType, credentials: result.credentials };
+ return { accountType: result.accountType, credentials: result.credentials } as unknown as z.infer<
+ typeof PamAccountCredentialsSchema
+ >;
}
});
diff --git a/backend/src/ee/services/pam-account/pam-account-schemas.ts b/backend/src/ee/services/pam-account/pam-account-schemas.ts
index 2d4d344a87..e2e84ca2b9 100644
--- a/backend/src/ee/services/pam-account/pam-account-schemas.ts
+++ b/backend/src/ee/services/pam-account/pam-account-schemas.ts
@@ -1331,6 +1331,17 @@ export const isCredentialConfigured = (
});
};
+export const revealedCredentialsSchema = (accountType: TSupportedAccountType) => {
+ const config = ACCOUNT_TYPE_CONFIGS[accountType];
+ return config.sanitizedCredentials.extend(
+ Object.fromEntries(
+ fieldsFromSchema(config.credentials, config.ui)
+ .filter((field) => field.secret)
+ .map((field) => [field.key, z.string().optional()])
+ )
+ );
+};
+
export const noRevealableCredentialMessage = (accountName: string) =>
`Account '${accountName}' has no stored credential to reveal. Its authentication method brokers access per session instead.`;