Skip to content

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

feat(pam): ad server resource & account

x0322050d13a99a1448
diff --git a/backend/src/ee/routes/v1/pam-account-routers/index.ts b/backend/src/ee/routes/v1/pam-account-routers/index.ts
index 55182b418d..20584dec08 100644
--- a/backend/src/ee/routes/v1/pam-account-routers/index.ts
+++ b/backend/src/ee/routes/v1/pam-account-routers/index.ts
@@ -1,3 +1,8 @@
+import {
+ CreateActiveDirectoryAccountSchema,
+ SanitizedActiveDirectoryAccountWithResourceSchema,
+ UpdateActiveDirectoryAccountSchema
+} from "@app/ee/services/pam-resource/active-directory/active-directory-resource-schemas";
import {
CreateAwsIamAccountSchema,
SanitizedAwsIamAccountWithResourceSchema,
@@ -100,5 +105,14 @@ export const PAM_ACCOUNT_REGISTER_ROUTER_MAP: Record<PamResource, (server: Fasti
createAccountSchema: CreateWindowsAccountSchema,
updateAccountSchema: UpdateWindowsAccountSchema
});
+ },
+ [PamResource.ActiveDirectory]: async (server: FastifyZodProvider) => {
+ registerPamAccountEndpoints({
+ server,
+ resourceType: PamResource.ActiveDirectory,
+ accountResponseSchema: SanitizedActiveDirectoryAccountWithResourceSchema,
+ createAccountSchema: CreateActiveDirectoryAccountSchema,
+ updateAccountSchema: UpdateActiveDirectoryAccountSchema
+ });
}
};
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.ts
index 1ade2cfc68..b50de48fc5 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
@@ -3,6 +3,7 @@ import { z } from "zod";
import { AuditLogInfo, EventType } from "@app/ee/services/audit-log/audit-log-types";
import { PamAccountOrderBy, PamAccountView } from "@app/ee/services/pam-account/pam-account-enums";
+import { SanitizedActiveDirectoryAccountWithResourceSchema } from "@app/ee/services/pam-resource/active-directory/active-directory-resource-schemas";
import { SanitizedAwsIamAccountWithResourceSchema } from "@app/ee/services/pam-resource/aws-iam/aws-iam-resource-schemas";
import { SanitizedKubernetesAccountWithResourceSchema } from "@app/ee/services/pam-resource/kubernetes/kubernetes-resource-schemas";
import { SanitizedMySQLAccountWithResourceSchema } from "@app/ee/services/pam-resource/mysql/mysql-resource-schemas";
@@ -28,7 +29,8 @@ const SanitizedAccountSchema = z.discriminatedUnion("resourceType", [
SanitizedMySQLAccountWithResourceSchema,
SanitizedRedisAccountWithResourceSchema,
SanitizedAwsIamAccountWithResourceSchema,
- SanitizedWindowsAccountWithResourceSchema
+ SanitizedWindowsAccountWithResourceSchema,
+ SanitizedActiveDirectoryAccountWithResourceSchema
]);
const ListPamAccountsResponseSchema = z.object({
diff --git a/backend/src/ee/routes/v1/pam-resource-routers/index.ts b/backend/src/ee/routes/v1/pam-resource-routers/index.ts
index 64c5e8f61d..54a0f6cde1 100644
--- a/backend/src/ee/routes/v1/pam-resource-routers/index.ts
+++ b/backend/src/ee/routes/v1/pam-resource-routers/index.ts
@@ -1,3 +1,8 @@
+import {
+ CreateActiveDirectoryResourceSchema,
+ SanitizedActiveDirectoryResourceSchema,
+ UpdateActiveDirectoryResourceSchema
+} from "@app/ee/services/pam-resource/active-directory/active-directory-resource-schemas";
import {
CreateAwsIamResourceSchema,
SanitizedAwsIamResourceSchema,
@@ -36,6 +41,7 @@ import {
} from "@app/ee/services/pam-resource/windows-server/windows-server-resource-schemas";
import {
+ registerActiveDirectoryRelatedResourcesEndpoint,
registerPamResourceEndpoints,
registerSshCaPublicKeyEndpoint,
registerSshCaSetupEndpoint
@@ -106,5 +112,15 @@ export const PAM_RESOURCE_REGISTER_ROUTER_MAP: Record<PamResource, (server: Fast
createResourceSchema: CreateWindowsResourceSchema,
updateResourceSchema: UpdateWindowsResourceSchema
});
+ },
+ [PamResource.ActiveDirectory]: async (server: FastifyZodProvider) => {
+ registerPamResourceEndpoints({
+ server,
+ resourceType: PamResource.ActiveDirectory,
+ resourceResponseSchema: SanitizedActiveDirectoryResourceSchema,
+ createResourceSchema: CreateActiveDirectoryResourceSchema,
+ updateResourceSchema: UpdateActiveDirectoryResourceSchema
+ });
+ registerActiveDirectoryRelatedResourcesEndpoint(server);
}
};
diff --git a/backend/src/ee/routes/v1/pam-resource-routers/pam-resource-endpoints.ts b/backend/src/ee/routes/v1/pam-resource-routers/pam-resource-endpoints.ts
index 89d78bf410..a559819bae 100644
--- a/backend/src/ee/routes/v1/pam-resource-routers/pam-resource-endpoints.ts
+++ b/backend/src/ee/routes/v1/pam-resource-routers/pam-resource-endpoints.ts
@@ -1,8 +1,16 @@
import { z } from "zod";
import { EventType } from "@app/ee/services/audit-log/audit-log-types";
+import { SanitizedActiveDirectoryResourceSchema } from "@app/ee/services/pam-resource/active-directory/active-directory-resource-schemas";
+import { SanitizedAwsIamResourceSchema } from "@app/ee/services/pam-resource/aws-iam/aws-iam-resource-schemas";
+import { SanitizedKubernetesResourceSchema } from "@app/ee/services/pam-resource/kubernetes/kubernetes-resource-schemas";
+import { SanitizedMySQLResourceSchema } from "@app/ee/services/pam-resource/mysql/mysql-resource-schemas";
import { PamResource } from "@app/ee/services/pam-resource/pam-resource-enums";
import { TPamResource } from "@app/ee/services/pam-resource/pam-resource-types";
+import { SanitizedPostgresResourceSchema } from "@app/ee/services/pam-resource/postgres/postgres-resource-schemas";
+import { SanitizedRedisResourceSchema } from "@app/ee/services/pam-resource/redis/redis-resource-schemas";
+import { SanitizedSSHResourceSchema } from "@app/ee/services/pam-resource/ssh/ssh-resource-schemas";
+import { SanitizedWindowsResourceSchema } from "@app/ee/services/pam-resource/windows-server/windows-server-resource-schemas";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { AuthMode } from "@app/services/auth/auth-type";
@@ -330,3 +338,42 @@ echo ""
}
});
};
+
+const RelatedResourceResponseSchema = z.union([
+ SanitizedPostgresResourceSchema,
+ SanitizedMySQLResourceSchema,
+ SanitizedSSHResourceSchema,
+ SanitizedKubernetesResourceSchema,
+ SanitizedAwsIamResourceSchema,
+ SanitizedRedisResourceSchema,
+ SanitizedWindowsResourceSchema,
+ SanitizedActiveDirectoryResourceSchema
+]);
+
+export const registerActiveDirectoryRelatedResourcesEndpoint = (server: FastifyZodProvider) => {
+ server.route({
+ method: "GET",
+ url: "/:resourceId/related-resources",
+ config: {
+ rateLimit: readLimit
+ },
+ schema: {
+ operationId: "getActiveDirectoryRelatedResources",
+ description: "List resources that belong to this Active Directory domain",
+ params: z.object({
+ resourceId: z.string().uuid()
+ }),
+ response: {
+ 200: z.object({
+ resources: RelatedResourceResponseSchema.array()
+ })
+ }
+ },
+ onRequest: verifyAuth([AuthMode.JWT]),
+ handler: async (req) => {
+ const resources = await server.services.pamResource.listRelatedResources(req.params.resourceId, req.permission);
+
+ return { resources };
+ }
+ });
+};
diff --git a/backend/src/ee/routes/v1/pam-resource-routers/pam-resource-router.ts b/backend/src/ee/routes/v1/pam-resource-routers/pam-resource-router.ts
index 2de5eda10d..a3fa14958e 100644
--- a/backend/src/ee/routes/v1/pam-resource-routers/pam-resource-router.ts
+++ b/backend/src/ee/routes/v1/pam-resource-routers/pam-resource-router.ts
@@ -1,6 +1,10 @@
import { z } from "zod";
import { EventType } from "@app/ee/services/audit-log/audit-log-types";
+import {
+ ActiveDirectoryResourceListItemSchema,
+ SanitizedActiveDirectoryResourceSchema
+} from "@app/ee/services/pam-resource/active-directory/active-directory-resource-schemas";
import {
AwsIamResourceListItemSchema,
SanitizedAwsIamResourceSchema
@@ -42,7 +46,8 @@ const SanitizedResourceSchema = z.union([
SanitizedKubernetesResourceSchema,
SanitizedAwsIamResourceSchema,
SanitizedRedisResourceSchema,
- SanitizedWindowsResourceSchema
+ SanitizedWindowsResourceSchema,
+ SanitizedActiveDirectoryResourceSchema
]);
const ResourceOptionsSchema = z.discriminatedUnion("resource", [
@@ -52,7 +57,8 @@ const ResourceOptionsSchema = z.discriminatedUnion("resource", [
KubernetesResourceListItemSchema,
AwsIamResourceListItemSchema,
RedisResourceListItemSchema,
- WindowsResourceListItemSchema
+ WindowsResourceListItemSchema,
+ ActiveDirectoryResourceListItemSchema
]);
export const registerPamResourceRouter = async (server: FastifyZodProvider) => {
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 b22514de6b..f7a49891c7 100644
--- a/backend/src/ee/services/pam-account/pam-account-service.ts
+++ b/backend/src/ee/services/pam-account/pam-account-service.ts
@@ -661,6 +661,10 @@ export const pamAccountServiceFactory = ({
kmsService
);
+ // Disable access to Active Directory
+ if (resourceType === PamResource.ActiveDirectory)
+ throw new BadRequestError({ message: `Active Directory resources cannot be accessed` });
+
// Temporarily disable access to Windows Server
if (resourceType === PamResource.Windows)
throw new BadRequestError({ message: `Windows resources cannot be accessed at this time` });
diff --git a/backend/src/ee/services/pam-resource/active-directory/active-directory-resource-enums.ts b/backend/src/ee/services/pam-resource/active-directory/active-directory-resource-enums.ts
new file mode 100644
index 0000000000..3e1783a57e
--- /dev/null
+++ b/backend/src/ee/services/pam-resource/active-directory/active-directory-resource-enums.ts
@@ -0,0 +1,4 @@
+export enum ActiveDirectoryAccountType {
+ User = "user",
+ Service = "service"
+}
diff --git a/backend/src/ee/services/pam-resource/active-directory/active-directory-resource-factory.ts b/backend/src/ee/services/pam-resource/active-directory/active-directory-resource-factory.ts
new file mode 100644
index 0000000000..0ba6bd016e
--- /dev/null
+++ b/backend/src/ee/services/pam-resource/active-directory/active-directory-resource-factory.ts
@@ -0,0 +1,188 @@
+import ldapjs from "ldapjs";
+
+import { BadRequestError } from "@app/lib/errors";
+import { GatewayProxyProtocol } from "@app/lib/gateway";
+import { withGatewayV2Proxy } from "@app/lib/gateway-v2/gateway-v2";
+import { logger } from "@app/lib/logger";
+
+import { verifyHostInputValidity } from "../../dynamic-secret/dynamic-secret-fns";
+import { TGatewayV2ServiceFactory } from "../../gateway-v2/gateway-v2-service";
+import { PamResource } from "../pam-resource-enums";
+import {
+ TPamResourceFactory,
+ TPamResourceFactoryRotateAccountCredentials,
+ TPamResourceFactoryValidateAccountCredentials
+} from "../pam-resource-types";
+import {
+ TActiveDirectoryAccountCredentials,
+ TActiveDirectoryResourceConnectionDetails
+} from "./active-directory-resource-types";
+
+const EXTERNAL_REQUEST_TIMEOUT = 10 * 1000;
+
+const executeWithGateway = async <T>(
+ config: {
+ connectionDetails: TActiveDirectoryResourceConnectionDetails;
+ resourceType: PamResource;
+ gatewayId: string;
+ targetPortOverride?: number;
+ },
+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">,
+ operation: (proxyPort: number) => Promise<T>
+): Promise<T> => {
+ const { connectionDetails, gatewayId, targetPortOverride } = config;
+ const [targetHost] = await verifyHostInputValidity({
+ host: connectionDetails.dcAddress,
+ isGateway: true,
+ isDynamicSecret: false
+ });
+ const platformConnectionDetails = await gatewayV2Service.getPlatformConnectionDetailsByGatewayId({
+ gatewayId,
+ targetHost,
+ targetPort: targetPortOverride ?? connectionDetails.port
+ });
+
+ if (!platformConnectionDetails) {
+ throw new BadRequestError({ message: "Unable to connect to gateway, no platform connection details found" });
+ }
+
+ return withGatewayV2Proxy(
+ async (proxyPort) => {
+ return operation(proxyPort);
+ },
+ {
+ protocol: GatewayProxyProtocol.Tcp,
+ relayHost: platformConnectionDetails.relayHost,
+ gateway: platformConnectionDetails.gateway,
+ relay: platformConnectionDetails.relay
+ }
+ );
+};
+
+export const activeDirectoryResourceFactory: TPamResourceFactory<
+ TActiveDirectoryResourceConnectionDetails,
+ TActiveDirectoryAccountCredentials
+> = (resourceType, connectionDetails, gatewayId, gatewayV2Service) => {
+ const validateConnection = async () => {
+ if (!gatewayId) {
+ throw new BadRequestError({ message: "Gateway ID is required" });
+ }
+
+ try {
+ await executeWithGateway({ connectionDetails, gatewayId, resourceType }, gatewayV2Service, async (proxyPort) => {
+ return new Promise<void>((resolve, reject) => {
+ const client = ldapjs.createClient({
+ url: `ldap://localhost:${proxyPort}`,
+ connectTimeout: EXTERNAL_REQUEST_TIMEOUT,
+ timeout: EXTERNAL_REQUEST_TIMEOUT
+ });
+
+ client.on("error", (err: Error) => {
+ client.unbind();
+ reject(err);
+ });
+
+ // Anonymous bind to verify this is a reachable LDAP server
+ client.bind("", "", (err) => {
+ if (err) {
+ // Even if anonymous bind is rejected, an LDAP error response means the server is an LDAP server
+ // Only reject if it's a connection-level error (not an LDAP protocol error)
+ if (err.name === "ConnectionError" || err.name === "TimeoutError") {
+ client.unbind();
+ reject(err);
+ } else {
+ logger.info("[Active Directory Resource Factory] LDAP connection validated (server responded)");
+ client.unbind();
+ resolve();
+ }
+ } else {
+ logger.info("[Active Directory Resource Factory] LDAP anonymous bind successful");
+ client.unbind();
+ resolve();
+ }
+ });
+ });
+ });
+ } catch (error) {
+ throw new BadRequestError({
+ message: `Unable to validate connection to ${resourceType}: ${(error as Error).message || String(error)}`
+ });
+ }
+
+ return connectionDetails;
+ };
+
+ const validateAccountCredentials: TPamResourceFactoryValidateAccountCredentials<
+ TActiveDirectoryAccountCredentials
+ > = async (credentials) => {
+ if (!gatewayId) {
+ throw new BadRequestError({ message: "Gateway ID is required" });
+ }
+
+ try {
+ await executeWithGateway({ connectionDetails, gatewayId, resourceType }, gatewayV2Service, async (proxyPort) => {
+ return new Promise<void>((resolve, reject) => {
+ // Bind DN uses UPN format: username@domain
+ const bindDn = `${credentials.username}@${connectionDetails.domain}`;
+
+ const client = ldapjs.createClient({
+ url: `ldap://localhost:${proxyPort}`,
+ connectTimeout: EXTERNAL_REQUEST_TIMEOUT,
+ timeout: EXTERNAL_REQUEST_TIMEOUT
+ });
+
+ client.on("error", (err: Error) => {
+ client.unbind();
+ reject(err);
+ });
+
+ client.bind(bindDn, credentials.password, (err) => {
+ if (err) {
+ client.unbind();
+ reject(new Error("LDAP bind failed: invalid credentials"));
+ } else {
+ logger.info("[Active Directory Resource Factory] LDAP credential validation successful");
+ client.unbind();
+ resolve();
+ }
+ });
+ });
+ });
+ } catch (error) {
+ throw new BadRequestError({
+ message: `Unable to validate credentials for ${resourceType}: ${(error as Error).message || String(error)}`
+ });
+ }
+
+ return credentials;
+ };
+
+ const rotateAccountCredentials: TPamResourceFactoryRotateAccountCredentials<
+ TActiveDirectoryAccountCredentials
+ > = async () => {
+ throw new BadRequestError({
+ message: "Credential rotation is not yet supported for Active Directory resources"
+ });
+ };
+
+ const handleOverwritePreventionForCensoredValues = async (
+ updatedAccountCredentials: TActiveDirectoryAccountCredentials,
+ currentCredentials: TActiveDirectoryAccountCredentials
+ ) => {
+ if (updatedAccountCredentials.password === "__INFISICAL_UNCHANGED__") {
+ return {
+ ...updatedAccountCredentials,
+ password: currentCredentials.password
+ };
+ }
+
+ return updatedAccountCredentials;
+ };
+
+ return {
+ validateConnection,
+ validateAccountCredentials,
+ rotateAccountCredentials,
+ handleOverwritePreventionForCensoredValues
+ };
+};
diff --git a/backend/src/ee/services/pam-resource/active-directory/active-directory-resource-fns.ts b/backend/src/ee/services/pam-resource/active-directory/active-directory-resource-fns.ts
new file mode 100644
index 0000000000..5b4ad8a299
--- /dev/null
+++ b/backend/src/ee/services/pam-resource/active-directory/active-directory-resource-fns.ts
@@ -0,0 +1,8 @@
+import { ActiveDirectoryResourceListItemSchema } from "./active-directory-resource-schemas";
+
+export const getActiveDirectoryResourceListItem = () => {
+ return {
+ name: ActiveDirectoryResourceListItemSchema.shape.name.value,
+ resource: ActiveDirectoryResourceListItemSchema.shape.resource.value
+ };
+};
diff --git a/backend/src/ee/services/pam-resource/active-directory/active-directory-resource-schemas.ts b/backend/src/ee/services/pam-resource/active-directory/active-directory-resource-schemas.ts
new file mode 100644
index 0000000000..7b29e9b5de
--- /dev/null
+++ b/backend/src/ee/services/pam-resource/active-directory/active-directory-resource-schemas.ts
@@ -0,0 +1,94 @@
+import { z } from "zod";
+
+import { PamResource } from "../pam-resource-enums";
+import {
+ BaseCreateGatewayPamResourceSchema,
+ BaseCreatePamAccountSchema,
+ BasePamAccountSchema,
+ BasePamAccountSchemaWithResource,
+ BasePamResourceSchema,
+ BaseUpdateGatewayPamResourceSchema,
+ BaseUpdatePamAccountSchema
+} from "../pam-resource-schemas";
+import { ActiveDirectoryAccountType } from "./active-directory-resource-enums";
+
+// Resources
+const BaseActiveDirectoryResourceSchema = BasePamResourceSchema.extend({
+ resourceType: z.literal(PamResource.ActiveDirectory)
+});
+
+export const ActiveDirectoryResourceListItemSchema = z.object({
+ name: z.literal("Active Directory"),
+ resource: z.literal(PamResource.ActiveDirectory)
+});
+
+export const ActiveDirectoryResourceConnectionDetailsSchema = z.object({
+ domain: z.string().trim().min(1).max(255),
+ dcAddress: z.string().trim().min(1).max(255),
+ port: z.coerce.number().int().min(1).max(65535)
+});
+
+// Credentials (username + password for AD)
+export const ActiveDirectoryAccountCredentialsSchema = z.object({
+ username: z.string().trim().min(1).max(255),
+ password: z.string().trim().min(1).max(255)
+});
+
+// Account metadata
+export const ActiveDirectoryAccountMetadataSchema = z.object({
+ accountType: z.nativeEnum(ActiveDirectoryAccountType)
+});
+
+export const ActiveDirectoryResourceSchema = BaseActiveDirectoryResourceSchema.extend({
+ connectionDetails: ActiveDirectoryResourceConnectionDetailsSchema,
+ rotationAccountCredentials: ActiveDirectoryAccountCredentialsSchema.nullable().optional()
+});
+
+export const SanitizedActiveDirectoryResourceSchema = BaseActiveDirectoryResourceSchema.extend({
+ connectionDetails: ActiveDirectoryResourceConnectionDetailsSchema,
+ rotationAccountCredentials: z
+ .object({
+ username: z.string()
+ })
+ .nullable()
+ .optional()
+});
+
+export const CreateActiveDirectoryResourceSchema = BaseCreateGatewayPamResourceSchema.extend({
+ connectionDetails: ActiveDirectoryResourceConnectionDetailsSchema,
+ rotationAccountCredentials: ActiveDirectoryAccountCredentialsSchema.nullable().optional()
+});
+
+export const UpdateActiveDirectoryResourceSchema = BaseUpdateGatewayPamResourceSchema.extend({
+ connectionDetails: ActiveDirectoryResourceConnectionDetailsSchema.optional(),
+ rotationAccountCredentials: ActiveDirectoryAccountCredentialsSchema.nullable().optional()
+});
+
+// Accounts
+export const ActiveDirectoryAccountSchema = BasePamAccountSchema.extend({
+ credentials: ActiveDirectoryAccountCredentialsSchema,
+ metadata: ActiveDirectoryAccountMetadataSchema
+});
+
+export const CreateActiveDirectoryAccountSchema = BaseCreatePamAccountSchema.extend({
+ credentials: ActiveDirectoryAccountCredentialsSchema,
+ metadata: ActiveDirectoryAccountMetadataSchema
+});
+
+export const UpdateActiveDirectoryAccountSchema = BaseUpdatePamAccountSchema.extend({
+ credentials: ActiveDirectoryAccountCredentialsSchema.optional(),
+ metadata: ActiveDirectoryAccountMetadataSchema.optional()
+});
+
+export const SanitizedActiveDirectoryAccountWithResourceSchema = BasePamAccountSchemaWithResource.extend({
+ resourceType: z.literal(PamResource.ActiveDirectory),
+ credentials: z.object({
+ username: z.string()
+ }),
+ metadata: ActiveDirectoryAccountMetadataSchema
+});
+
+// Sessions
+export const ActiveDirectorySessionCredentialsSchema = ActiveDirectoryResourceConnectionDetailsSchema.and(
+ ActiveDirectoryAccountCredentialsSchema
+);
diff --git a/backend/src/ee/services/pam-resource/active-directory/active-directory-resource-types.ts b/backend/src/ee/services/pam-resource/active-directory/active-directory-resource-types.ts
new file mode 100644
index 0000000000..ae2ad650f7
--- /dev/null
+++ b/backend/src/ee/services/pam-resource/active-directory/active-directory-resource-types.ts
@@ -0,0 +1,18 @@
+import { z } from "zod";
+
+import {
+ ActiveDirectoryAccountCredentialsSchema,
+ ActiveDirectoryAccountMetadataSchema,
+ ActiveDirectoryAccountSchema,
+ ActiveDirectoryResourceConnectionDetailsSchema,
+ ActiveDirectoryResourceSchema
+} from "./active-directory-resource-schemas";
+
+// Resources
+export type TActiveDirectoryResource = z.infer<typeof ActiveDirectoryResourceSchema>;
+export type TActiveDirectoryResourceConnectionDetails = z.infer<typeof ActiveDirectoryResourceConnectionDetailsSchema>;
+
+// Accounts
+export type TActiveDirectoryAccount = z.infer<typeof ActiveDirectoryAccountSchema>;
+export type TActiveDirectoryAccountCredentials = z.infer<typeof ActiveDirectoryAccountCredentialsSchema>;
+export type TActiveDirectoryAccountMetadata = z.infer<typeof ActiveDirectoryAccountMetadataSchema>;
diff --git a/backend/src/ee/services/pam-resource/pam-resource-dal.ts b/backend/src/ee/services/pam-resource/pam-resource-dal.ts
index e5b76a882c..77398baa69 100644
--- a/backend/src/ee/services/pam-resource/pam-resource-dal.ts
+++ b/backend/src/ee/services/pam-resource/pam-resource-dal.ts
@@ -84,5 +84,18 @@ export const pamResourceDALFactory = (db: TDbClient) => {
}
};
- return { ...orm, findById, findByProjectId };
+ const findByAdServerResourceId = async (adServerResourceId: string, tx?: Knex) => {
+ try {
+ const resources = await (tx || db.replicaNode())(TableName.PamResource)
+ .select(selectAllTableCols(TableName.PamResource))
+ .where(`${TableName.PamResource}.adServerResourceId`, adServerResourceId)
+ .orderByRaw(`${TableName.PamResource}."name" COLLATE "en-x-icu" ASC`);
+
+ return resources;
+ } catch (error) {
+ throw new DatabaseError({ error, name: "Find PAM resources by AD server resource ID" });
+ }
+ };
+
+ return { ...orm, findById, findByProjectId, findByAdServerResourceId };
};
diff --git a/backend/src/ee/services/pam-resource/pam-resource-enums.ts b/backend/src/ee/services/pam-resource/pam-resource-enums.ts
index 4ca6005ed6..f9c4c6d628 100644
--- a/backend/src/ee/services/pam-resource/pam-resource-enums.ts
+++ b/backend/src/ee/services/pam-resource/pam-resource-enums.ts
@@ -5,7 +5,8 @@ export enum PamResource {
Kubernetes = "kubernetes",
AwsIam = "aws-iam",
Redis = "redis",
- Windows = "windows"
+ Windows = "windows",
+ ActiveDirectory = "active-directory"
}
export enum PamResourceOrderBy {
diff --git a/backend/src/ee/services/pam-resource/pam-resource-factory.ts b/backend/src/ee/services/pam-resource/pam-resource-factory.ts
index 6401130825..0f189d455c 100644
--- a/backend/src/ee/services/pam-resource/pam-resource-factory.ts
+++ b/backend/src/ee/services/pam-resource/pam-resource-factory.ts
@@ -1,3 +1,4 @@
+import { activeDirectoryResourceFactory } from "./active-directory/active-directory-resource-factory";
import { awsIamResourceFactory } from "./aws-iam/aws-iam-resource-factory";
import { kubernetesResourceFactory } from "./kubernetes/kubernetes-resource-factory";
import { PamResource } from "./pam-resource-enums";
@@ -16,5 +17,6 @@ export const PAM_RESOURCE_FACTORY_MAP: Record<PamResource, TPamResourceFactoryIm
[PamResource.Kubernetes]: kubernetesResourceFactory as TPamResourceFactoryImplementation,
[PamResource.AwsIam]: awsIamResourceFactory as TPamResourceFactoryImplementation,
[PamResource.Redis]: redisResourceFactory as TPamResourceFactoryImplementation,
- [PamResource.Windows]: windowsResourceFactory as TPamResourceFactoryImplementation
+ [PamResource.Windows]: windowsResourceFactory as TPamResourceFactoryImplementation,
+ [PamResource.ActiveDirectory]: activeDirectoryResourceFactory as TPamResourceFactoryImplementation
};
diff --git a/backend/src/ee/services/pam-resource/pam-resource-fns.ts b/backend/src/ee/services/pam-resource/pam-resource-fns.ts
index 9b50e72277..e158caa275 100644
--- a/backend/src/ee/services/pam-resource/pam-resource-fns.ts
+++ b/backend/src/ee/services/pam-resource/pam-resource-fns.ts
@@ -3,6 +3,7 @@ import { TKmsServiceFactory } from "@app/services/kms/kms-service";
import { KmsDataKey } from "@app/services/kms/kms-types";
import { decryptAccountCredentials } from "../pam-account/pam-account-fns";
+import { getActiveDirectoryResourceListItem } from "./active-directory/active-directory-resource-fns";
import { getAwsIamResourceListItem } from "./aws-iam/aws-iam-resource-fns";
import { getKubernetesResourceListItem } from "./kubernetes/kubernetes-resource-fns";
import { getMySQLResourceListItem } from "./mysql/mysql-resource-fns";
@@ -18,7 +19,8 @@ export const listResourceOptions = () => {
getAwsIamResourceListItem(),
getKubernetesResourceListItem(),
getRedisResourceListItem(),
- getWindowsResourceListItem()
+ getWindowsResourceListItem(),
+ getActiveDirectoryResourceListItem()
].sort((a, b) => a.name.localeCompare(b.name));
};
diff --git a/backend/src/ee/services/pam-resource/pam-resource-service.ts b/backend/src/ee/services/pam-resource/pam-resource-service.ts
index 30eb48cd18..ca43596c77 100644
--- a/backend/src/ee/services/pam-resource/pam-resource-service.ts
+++ b/backend/src/ee/services/pam-resource/pam-resource-service.ts
@@ -104,7 +104,15 @@ export const pamResourceServiceFactory = ({
};
const create = async (
- { resourceType, connectionDetails, gatewayId, name, projectId, rotationAccountCredentials }: TCreateResourceDTO,
+ {
+ resourceType,
+ connectionDetails,
+ gatewayId,
+ name,
+ projectId,
+ rotationAccountCredentials,
+ adServerResourceId
+ }: TCreateResourceDTO,
actor: OrgServiceActor
) => {
const { permission } = await permissionService.getProjectPermission({
@@ -152,7 +160,8 @@ export const pamResourceServiceFactory = ({
gatewayId,
name,
projectId,
- encryptedRotationAccountCredentials
+ encryptedRotationAccountCredentials,
+ adServerResourceId: adServerResourceId ?? null
});
return await decryptResource(resource, projectId, kmsService);
@@ -167,7 +176,14 @@ export const pamResourceServiceFactory = ({
};
const updateById = async (
- { connectionDetails, resourceId, name, rotationAccountCredentials, gatewayId }: TUpdateResourceDTO,
+ {
+ connectionDetails,
+ resourceId,
+ name,
+ rotationAccountCredentials,
+ gatewayId,
+ adServerResourceId
+ }: TUpdateResourceDTO,
actor: OrgServiceActor
) => {
const resource = await pamResourceDAL.findById(resourceId);
@@ -196,6 +212,10 @@ export const pamResourceServiceFactory = ({
updateDoc.name = name;
}
+ if (adServerResourceId !== undefined) {
+ updateDoc.adServerResourceId = adServerResourceId;
+ }
+
if (connectionDetails !== undefined) {
const factory = PAM_RESOURCE_FACTORY_MAP[resource.resourceType as PamResource](
resource.resourceType as PamResource,
@@ -465,6 +485,30 @@ export const pamResourceServiceFactory = ({
return { caPublicKey };
};
+ const listRelatedResources = async (adServerResourceId: string, actor: OrgServiceActor) => {
+ const resource = await pamResourceDAL.findById(adServerResourceId);
+ if (!resource) throw new NotFoundError({ message: `Resource with ID '${adServerResourceId}' not found` });
+
+ if (resource.resourceType !== PamResource.ActiveDirectory) {
+ throw new BadRequestError({ message: "Related resources can only be listed for Active Directory resources" });
+ }
+
+ const { permission } = await permissionService.getProjectPermission({
+ actor: actor.type,
+ actorAuthMethod: actor.authMethod,
+ actorId: actor.id,
+ actorOrgId: actor.orgId,
+ projectId: resource.projectId,
+ actionProjectType: ActionProjectType.PAM
+ });
+
+ ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.PamResources);
+
+ const relatedResources = await pamResourceDAL.findByAdServerResourceId(adServerResourceId);
+
+ return Promise.all(relatedResources.map((r) => decryptResource(r, resource.projectId, kmsService)));
+ };
+
return {
getById,
create,
@@ -472,6 +516,7 @@ export const pamResourceServiceFactory = ({
deleteById,
list,
listResourceOptions,
- getOrCreateSshCa
+ getOrCreateSshCa,
+ listRelatedResources
};
};
diff --git a/backend/src/ee/services/pam-resource/pam-resource-types.ts b/backend/src/ee/services/pam-resource/pam-resource-types.ts
index 0968249bf4..5b555df1d6 100644
--- a/backend/src/ee/services/pam-resource/pam-resource-types.ts
+++ b/backend/src/ee/services/pam-resource/pam-resource-types.ts
@@ -1,6 +1,12 @@
import { OrderByDirection, TProjectPermission } from "@app/lib/types";
import { TGatewayV2ServiceFactory } from "../gateway-v2/gateway-v2-service";
+import {
+ TActiveDirectoryAccount,
+ TActiveDirectoryAccountCredentials,
+ TActiveDirectoryResource,
+ TActiveDirectoryResourceConnectionDetails
+} from "./active-directory/active-directory-resource-types";
import {
TAwsIamAccount,
TAwsIamAccountCredentials,
@@ -54,7 +60,8 @@ export type TPamResource =
| TAwsIamResource
| TKubernetesResource
| TRedisResource
- | TWindowsResource;
+ | TWindowsResource
+ | TActiveDirectoryResource;
export type TPamResourceConnectionDetails =
| TPostgresResourceConnectionDetails
| TMySQLResourceConnectionDetails
@@ -62,7 +69,8 @@ export type TPamResourceConnectionDetails =
| TKubernetesResourceConnectionDetails
| TAwsIamResourceConnectionDetails
| TRedisResourceConnectionDetails
- | TWindowsResourceConnectionDetails;
+ | TWindowsResourceConnectionDetails
+ | TActiveDirectoryResourceConnectionDetails;
export type TPamResourceMetadata = TSSHResourceMetadata;
// Account types
@@ -73,7 +81,8 @@ export type TPamAccount =
| TAwsIamAccount
| TKubernetesAccount
| TRedisAccount
- | TWindowsAccount;
+ | TWindowsAccount
+ | TActiveDirectoryAccount;
export type TPamAccountCredentials =
| TPostgresAccountCredentials
@@ -83,12 +92,14 @@ export type TPamAccountCredentials =
| TKubernetesAccountCredentials
| TAwsIamAccountCredentials
| TRedisAccountCredentials
- | TWindowsAccountCredentials;
+ | TWindowsAccountCredentials
+ | TActiveDirectoryAccountCredentials;
// Resource DTOs
export type TCreateResourceDTO = Pick<TPamResource, "name" | "connectionDetails" | "resourceType" | "projectId"> & {
gatewayId?: string | null;
rotationAccountCredentials?: TPamAccountCredentials | null;
+ adServerResourceId?: string | null;
};
export type TUpdateResourceDTO = Partial<Omit<TCreateResourceDTO, "resourceType" | "projectId">> & {
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 42c505d9ee..6bd3543048 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
@@ -56,12 +56,14 @@ export const SanitizedWindowsResourceSchema = BaseWindowsResourceSchema.extend({
export const CreateWindowsResourceSchema = BaseCreateGatewayPamResourceSchema.extend({
connectionDetails: WindowsResourceConnectionDetailsSchema,
- rotationAccountCredentials: WindowsAccountCredentialsSchema.nullable().optional()
+ rotationAccountCredentials: WindowsAccountCredentialsSchema.nullable().optional(),
+ adServerResourceId: z.string().uuid().nullable().optional()
});
export const UpdateWindowsResourceSchema = BaseUpdateGatewayPamResourceSchema.extend({
connectionDetails: WindowsResourceConnectionDetailsSchema.optional(),
- rotationAccountCredentials: WindowsAccountCredentialsSchema.nullable().optional()
+ rotationAccountCredentials: WindowsAccountCredentialsSchema.nullable().optional(),
+ adServerResourceId: z.string().uuid().nullable().optional()
});
// Accounts
diff --git a/frontend/public/images/integrations/ActiveDirectory.png b/frontend/public/images/integrations/ActiveDirectory.png
new file mode 100644
index 0000000000..1bdce5a877
Binary files /dev/null and b/frontend/public/images/integrations/ActiveDirectory.png differ
diff --git a/frontend/src/hooks/api/pam/enums.ts b/frontend/src/hooks/api/pam/enums.ts
index 4c05f5818a..5c1e24ef5e 100644
--- a/frontend/src/hooks/api/pam/enums.ts
+++ b/frontend/src/hooks/api/pam/enums.ts
@@ -18,7 +18,8 @@ export enum PamResourceType {
Snowflake = "snowflake",
DynamoDB = "dynamodb",
AwsIam = "aws-iam",
- Windows = "windows"
+ Windows = "windows",
+ ActiveDirectory = "active-directory"
}
export enum PamResourceOrderBy {
diff --git a/frontend/src/hooks/api/pam/maps.ts b/frontend/src/hooks/api/pam/maps.ts
index 178bbc2ad6..5cba0f893e 100644
--- a/frontend/src/hooks/api/pam/maps.ts
+++ b/frontend/src/hooks/api/pam/maps.ts
@@ -22,5 +22,6 @@ export const PAM_RESOURCE_TYPE_MAP: Record<
[PamResourceType.Snowflake]: { name: "Snowflake", image: "Snowflake.png" },
[PamResourceType.DynamoDB]: { name: "DynamoDB", image: "DynamoDB.png", size: 55 },
[PamResourceType.AwsIam]: { name: "AWS IAM", image: "Amazon Web Services.png" },
- [PamResourceType.Windows]: { name: "Windows Server", image: "Windows.png" }
+ [PamResourceType.Windows]: { name: "Windows Server", image: "Windows.png" },
+ [PamResourceType.ActiveDirectory]: { name: "Active Directory", image: "ActiveDirectory.png" }
};
diff --git a/frontend/src/hooks/api/pam/mutations.tsx b/frontend/src/hooks/api/pam/mutations.tsx
index ed9f69a93a..9d3fe937b0 100644
--- a/frontend/src/hooks/api/pam/mutations.tsx
+++ b/frontend/src/hooks/api/pam/mutations.tsx
@@ -47,8 +47,11 @@ export const useUpdatePamResource = () => {
return data.resource;
},
- onSuccess: ({ projectId }) => {
+ onSuccess: ({ projectId }, { resourceId, resourceType }) => {
queryClient.invalidateQueries({ queryKey: pamKeys.listResources({ projectId }) });
+ queryClient.invalidateQueries({
+ queryKey: pamKeys.getResource(resourceType, resourceId)
+ });
}
});
};
@@ -98,8 +101,9 @@ export const useUpdatePamAccount = () => {
return data.account;
},
- onSuccess: ({ projectId }) => {
+ onSuccess: ({ projectId }, { accountId }) => {
queryClient.invalidateQueries({ queryKey: pamKeys.listAccounts({ projectId }) });
+ queryClient.invalidateQueries({ queryKey: pamKeys.getAccount(accountId) });
}
});
};
diff --git a/frontend/src/hooks/api/pam/queries.tsx b/frontend/src/hooks/api/pam/queries.tsx
index 3e73329eae..b5f111c1a4 100644
--- a/frontend/src/hooks/api/pam/queries.tsx
+++ b/frontend/src/hooks/api/pam/queries.tsx
@@ -30,6 +30,7 @@ export const pamKeys = {
resourceType,
resourceId
],
+ listRelatedResources: (resourceId: string) => [...pamKeys.resource(), "related", resourceId],
listAccounts: ({ projectId, ...params }: TListPamAccountsDTO) => [
...pamKeys.account(),
"list",
@@ -119,6 +120,32 @@ export const useGetPamResourceById = (
});
};
+export const useListRelatedResources = (
+ resourceId?: string,
+ options?: Omit<
+ UseQueryOptions<
+ TPamResource[],
+ unknown,
+ TPamResource[],
+ ReturnType<typeof pamKeys.listRelatedResources>
+ >,
+ "queryKey" | "queryFn"
+ >
+) => {
+ return useQuery({
+ queryKey: pamKeys.listRelatedResources(resourceId || ""),
+ queryFn: async () => {
+ const { data } = await apiRequest.get<{ resources: TPamResource[] }>(
+ `/api/v1/pam/resources/active-directory/${resourceId}/related-resources`
+ );
+
+ return data.resources;
+ },
+ enabled: !!resourceId && (options?.enabled ?? true),
+ ...options
+ });
+};
+
// Accounts
type TListPamAccountsResponse = {
accounts: TPamAccount[];
diff --git a/frontend/src/hooks/api/pam/types/active-directory-resource.ts b/frontend/src/hooks/api/pam/types/active-directory-resource.ts
new file mode 100644
index 0000000000..fdb9110f5f
--- /dev/null
+++ b/frontend/src/hooks/api/pam/types/active-directory-resource.ts
@@ -0,0 +1,37 @@
+import { PamResourceType } from "../enums";
+import { TBasePamAccount } from "./base-account";
+import { TBasePamResource } from "./base-resource";
+
+export enum ActiveDirectoryAccountType {
+ User = "user",
+ Service = "service"
+}
+
+export type TActiveDirectoryConnectionDetails = {
+ domain: string;
+ dcAddress: string;
+ port: number;
+};
+
+export type TActiveDirectoryCredentials = {
+ username: string;
+ password: string;
+};
+
+export type TActiveDirectoryAccountMetadata = {
+ accountType: ActiveDirectoryAccountType;
+};
+
+// Resources
+export type TActiveDirectoryResource = TBasePamResource & {
+ resourceType: PamResourceType.ActiveDirectory;
+} & {
+ connectionDetails: TActiveDirectoryConnectionDetails;
+ rotationAccountCredentials?: TActiveDirectoryCredentials | null;
+};
+
+// Accounts
+export type TActiveDirectoryAccount = TBasePamAccount & {
+ credentials: TActiveDirectoryCredentials;
+ metadata: TActiveDirectoryAccountMetadata;
+};
diff --git a/frontend/src/hooks/api/pam/types/base-resource.ts b/frontend/src/hooks/api/pam/types/base-resource.ts
index 763e564ad3..075839df2f 100644
--- a/frontend/src/hooks/api/pam/types/base-resource.ts
+++ b/frontend/src/hooks/api/pam/types/base-resource.ts
@@ -3,6 +3,7 @@ export interface TBasePamResource {
projectId: string;
name: string;
gatewayId: string;
+ adServerResourceId?: string | null;
createdAt: string;
updatedAt: string;
}
diff --git a/frontend/src/hooks/api/pam/types/index.ts b/frontend/src/hooks/api/pam/types/index.ts
index d74bf4c4dc..e2d5494f9d 100644
--- a/frontend/src/hooks/api/pam/types/index.ts
+++ b/frontend/src/hooks/api/pam/types/index.ts
@@ -6,6 +6,7 @@ import {
PamResourceType,
PamSessionStatus
} from "../enums";
+import { TActiveDirectoryAccount, TActiveDirectoryResource } from "./active-directory-resource";
import { TAwsIamAccount, TAwsIamResource } from "./aws-iam-resource";
import { TKubernetesAccount, TKubernetesResource } from "./kubernetes-resource";
import { TMySQLAccount, TMySQLResource } from "./mysql-resource";
@@ -14,6 +15,7 @@ import { TRedisAccount, TRedisResource } from "./redis-resource";
import { TSSHAccount, TSSHResource } from "./ssh-resource";
import { TWindowsAccount, TWindowsResource } from "./windows-server-resource";
+export * from "./active-directory-resource";
export * from "./aws-iam-resource";
export * from "./kubernetes-resource";
export * from "./mysql-resource";
@@ -29,7 +31,8 @@ export type TPamResource =
| TSSHResource
| TAwsIamResource
| TKubernetesResource
- | TWindowsResource;
+ | TWindowsResource
+ | TActiveDirectoryResource;
export type TPamAccount =
| TPostgresAccount
@@ -38,7 +41,8 @@ export type TPamAccount =
| TSSHAccount
| TAwsIamAccount
| TKubernetesAccount
- | TWindowsAccount;
+ | TWindowsAccount
+ | TActiveDirectoryAccount;
export type TPamFolder = {
id: string;
@@ -122,13 +126,16 @@ export type TListPamResourcesDTO = {
export type TCreatePamResourceDTO = Pick<
TPamResource,
"name" | "connectionDetails" | "resourceType" | "gatewayId" | "projectId"
->;
+> & {
+ adServerResourceId?: string | null;
+};
export type TUpdatePamResourceDTO = Partial<
Pick<TPamResource, "name" | "connectionDetails" | "gatewayId">
> & {
resourceId: string;
resourceType: PamResourceType;
+ adServerResourceId?: string | null;
};
export type TDeletePamResourceDTO = {
diff --git a/frontend/src/pages/pam/PamAccountByIDPage/PamAccountByIDPage.tsx b/frontend/src/pages/pam/PamAccountByIDPage/PamAccountByIDPage.tsx
index 839ff35e18..4cf6550bd4 100644
--- a/frontend/src/pages/pam/PamAccountByIDPage/PamAccountByIDPage.tsx
+++ b/frontend/src/pages/pam/PamAccountByIDPage/PamAccountByIDPage.tsx
@@ -153,17 +153,19 @@ const PageContent = () => {
</div>
<div className="flex items-center gap-3">
{/* Windows Server accounts cannot be accessed temporarily */}
- {account.resource.resourceType !== PamResourceType.Windows && (
- <ProjectPermissionCan
- I={ProjectPermissionPamAccountActions.Access}
- a={ProjectPermissionSub.PamAccounts}
- >
- <Button variant="neutral" onClick={handleAccess} isPending={isAwsAccessPending}>
- <LogInIcon />
- Access
- </Button>
- </ProjectPermissionCan>
- )}
+ {/* Active Directory accounts cannot be accessed */}
+ {account.resource.resourceType !== PamResourceType.Windows &&
+ account.resource.resourceType !== PamResourceType.ActiveDirectory && (
+ <ProjectPermissionCan
+ I={ProjectPermissionPamAccountActions.Access}
+ a={ProjectPermissionSub.PamAccounts}
+ >
+ <Button variant="neutral" onClick={handleAccess} isPending={isAwsAccessPending}>
+ <LogInIcon />
+ Access
+ </Button>
+ </ProjectPermissionCan>
+ )}
<UnstableDropdownMenu>
<UnstableDropdownMenuTrigger asChild>
<Button variant="outline" size="sm">
diff --git a/frontend/src/pages/pam/PamAccountByIDPage/components/PamAccountCredentialsSection.tsx b/frontend/src/pages/pam/PamAccountByIDPage/components/PamAccountCredentialsSection.tsx
index cb539c1aca..de66646834 100644
--- a/frontend/src/pages/pam/PamAccountByIDPage/components/PamAccountCredentialsSection.tsx
+++ b/frontend/src/pages/pam/PamAccountByIDPage/components/PamAccountCredentialsSection.tsx
@@ -11,7 +11,12 @@ import {
} from "@app/components/v3";
import { ProjectPermissionSub } from "@app/context";
import { ProjectPermissionPamAccountActions } from "@app/context/ProjectPermissionContext/types";
-import { PamResourceType, TPamAccount, TWindowsCredentials } from "@app/hooks/api/pam";
+import {
+ PamResourceType,
+ TActiveDirectoryCredentials,
+ TPamAccount,
+ TWindowsCredentials
+} from "@app/hooks/api/pam";
import { TAwsIamCredentials } from "@app/hooks/api/pam/types/aws-iam-resource";
import { TBaseSqlCredentials } from "@app/hooks/api/pam/types/shared/sql-resource";
import { SSHAuthMethod, TSSHCredentials } from "@app/hooks/api/pam/types/ssh-resource";
@@ -76,6 +81,14 @@ const WindowsCredentialsContent = ({ credentials }: { credentials: TWindowsCrede
return <CopyableField label="Username" value={credentials.username} />;
};
+const ActiveDirectoryCredentialsContent = ({
+ credentials
+}: {
+ credentials: TActiveDirectoryCredentials;
+}) => {
+ return <CopyableField label="Username" value={credentials.username} />;
+};
+
const CredentialsContent = ({ account }: { account: TPamAccount }) => {
const { resourceType } = account.resource;
@@ -90,6 +103,12 @@ const CredentialsContent = ({ account }: { account: TPamAccount }) => {
return <AwsIamCredentialsContent credentials={account.credentials as TAwsIamCredentials} />;
case PamResourceType.Windows:
return <WindowsCredentialsContent credentials={account.credentials as TWindowsCredentials} />;
+ case PamResourceType.ActiveDirectory:
+ return (
+ <ActiveDirectoryCredentialsContent
+ credentials={account.credentials as TActiveDirectoryCredentials}
+ />
+ );
default:
return null;
}
diff --git a/frontend/src/pages/pam/PamAccountByIDPage/components/PamAccountResourcesSection.tsx b/frontend/src/pages/pam/PamAccountByIDPage/components/PamAccountResourcesSection.tsx
index 6d87d19362..ffd23e1938 100644
--- a/frontend/src/pages/pam/PamAccountByIDPage/components/PamAccountResourcesSection.tsx
+++ b/frontend/src/pages/pam/PamAccountByIDPage/components/PamAccountResourcesSection.tsx
@@ -1,7 +1,7 @@
import { MonitorIcon } from "lucide-react";
import { twMerge } from "tailwind-merge";
-import { PamResourceType, TPamAccount } from "@app/hooks/api/pam";
+import { PamResourceType, TPamAccount, useListRelatedResources } from "@app/hooks/api/pam";
type Props = {
account: TPamAccount;
@@ -34,9 +34,53 @@ const ResourceCard = ({ name, resourceId, onAccess }: ResourceCardProps) => {
);
};
+const ActiveDirectoryAccountResources = ({ account, onAccessResource }: Props) => {
+ const { resource } = account;
+
+ // For AD accounts, show all domain member resources (excluding the AD server itself)
+ const { data: relatedResources, isPending } = useListRelatedResources(resource.id);
+
+ return (
+ <div className="rounded-lg border border-border bg-container">
+ <div className="border-b border-border px-4 py-3">
+ <h3 className="text-lg font-medium">Resources</h3>
+ <p className="text-sm text-muted">Domain machines this account can access</p>
+ </div>
+ <div className="p-4">
+ {isPending && <p className="text-sm text-muted">Loading resources...</p>}
+ {!isPending && (!relatedResources || relatedResources.length === 0) && (
+ <p className="py-4 text-center text-sm text-muted">No domain resources found</p>
+ )}
+ {relatedResources && relatedResources.length > 0 && (
+ // Temporarily disable connecting to AD accounts
+ <div className="pointer-events-none grid grid-cols-1 gap-4 opacity-60 md:grid-cols-2">
+ {relatedResources.map((relatedResource) => {
+ return (
+ <ResourceCard
+ key={relatedResource.id}
+ name={relatedResource.name}
+ resourceId={relatedResource.id}
+ onAccess={() => onAccessResource(relatedResource.id)}
+ />
+ );
+ })}
+ </div>
+ )}
+ </div>
+ </div>
+ );
+};
+
export const PamAccountResourcesSection = ({ account, onAccessResource }: Props) => {
const { resource } = account;
+ // For Active Directory accounts, show related domain resources instead
+ if (resource.resourceType === PamResourceType.ActiveDirectory) {
+ return (
+ <ActiveDirectoryAccountResources account={account} onAccessResource={onAccessResource} />
+ );
+ }
+
return (
<div className="rounded-lg border border-border bg-container">
<div className="border-b border-border px-4 py-3">
diff --git a/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/ActiveDirectoryAccountForm.tsx b/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/ActiveDirectoryAccountForm.tsx
new file mode 100644
index 0000000000..bef6f3b390
--- /dev/null
+++ b/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/ActiveDirectoryAccountForm.tsx
@@ -0,0 +1,166 @@
+import { useState } from "react";
+import { Controller, FormProvider, useForm } from "react-hook-form";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { z } from "zod";
+
+import { Button, FormControl, Input, ModalClose, Select, SelectItem } from "@app/components/v2";
+import { PamResourceType, TActiveDirectoryAccount } from "@app/hooks/api/pam";
+import { UNCHANGED_PASSWORD_SENTINEL } from "@app/hooks/api/pam/constants";
+import { ActiveDirectoryAccountType } from "@app/hooks/api/pam/types/active-directory-resource";
+
+import { GenericAccountFields, genericAccountFieldsSchema } from "./GenericAccountFields";
+import { RequireMfaField } from "./RequireMfaField";
+
+type Props = {
+ account?: TActiveDirectoryAccount;
+ resourceId?: string;
+ resourceType?: PamResourceType;
+ onSubmit: (formData: FormData) => Promise<void>;
+};
+
+const formSchema = genericAccountFieldsSchema.extend({
+ credentials: z.object({
+ username: z.string().trim().min(1, "Username is required"),
+ password: z.string().trim().min(1, "Password is required")
+ }),
+ metadata: z.object({
+ accountType: z.nativeEnum(ActiveDirectoryAccountType)
+ }),
+ rotationEnabled: z.boolean().default(false),
+ requireMfa: z.boolean().nullable().optional()
+});
+
+type FormData = z.infer<typeof formSchema>;
+
+export const ActiveDirectoryAccountForm = ({ account, onSubmit }: Props) => {
+ const isUpdate = Boolean(account);
+ const [showPassword, setShowPassword] = useState(false);
+
+ const form = useForm<FormData>({
+ resolver: zodResolver(formSchema),
+ defaultValues: account
+ ? {
+ ...account,
+ credentials: {
+ ...account.credentials,
+ password: UNCHANGED_PASSWORD_SENTINEL
+ }
+ }
+ : {
+ name: "",
+ description: "",
+ requireMfa: false,
+ rotationEnabled: false,
+ credentials: {
+ username: "",
+ password: ""
+ },
+ metadata: {
+ accountType: ActiveDirectoryAccountType.User
+ }
+ }
+ });
+
+ const {
+ control,
+ handleSubmit,
+ formState: { isSubmitting, isDirty }
+ } = form;
+
+ return (
+ <FormProvider {...form}>
+ <form onSubmit={handleSubmit(onSubmit)}>
+ <GenericAccountFields />
+ <div className="mb-4 rounded-sm border border-mineshaft-600 bg-mineshaft-700/70 p-3">
+ <Controller
+ name="metadata.accountType"
+ control={control}
+ render={({ field: { value, onChange }, fieldState: { error } }) => (
+ <FormControl
+ className="mb-3"
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ label="Account Type"
+ >
+ <Select
+ value={value}
+ onValueChange={onChange}
+ className="w-full border border-mineshaft-500"
+ >
+ <SelectItem value={ActiveDirectoryAccountType.User}>User Account</SelectItem>
+ <SelectItem value={ActiveDirectoryAccountType.Service}>
+ Service Account
+ </SelectItem>
+ </Select>
+ </FormControl>
+ )}
+ />
+
+ <Controller
+ name="credentials.username"
+ control={control}
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ className="mb-3"
+ errorText={error?.message}
+ isError={Boolean(error?.message)}
+ label="Username"
+ >
+ <Input {...field} autoComplete="off" />
+ </FormControl>
+ )}
+ />
+
+ <Controller
+ name="credentials.password"
+ control={control}
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ className="mb-0"
+ errorText={error?.message}
+ isError={Boolean(error?.message)}
+ label="Password"
+ >
+ <Input
+ {...field}
+ type={showPassword ? "text" : "password"}
+ autoComplete="new-password"
+ onFocus={() => {
+ if (isUpdate && field.value === UNCHANGED_PASSWORD_SENTINEL) {
+ field.onChange("");
+ }
+ setShowPassword(true);
+ }}
+ onBlur={() => {
+ if (isUpdate && field.value === "") {
+ field.onChange(UNCHANGED_PASSWORD_SENTINEL);
+ }
+ setShowPassword(false);
+ }}
+ />
+ </FormControl>
+ )}
+ />
+ </div>
+ <RequireMfaField />
+ <div className="mt-6 flex items-center">
+ <Button
+ className="mr-4"
+ size="sm"
+ type="submit"
+ colorSchema="secondary"
+ isLoading={isSubmitting}
+ isDisabled={isSubmitting || !isDirty}
+ >
+ {isUpdate ? "Update Account" : "Create Account"}
+ </Button>
+ <ModalClose asChild>
+ <Button colorSchema="secondary" variant="plain">
+ Cancel
+ </Button>
+ </ModalClose>
+ </div>
+ </form>
+ </FormProvider>
+ );
+};
diff --git a/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/PamAccountForm.tsx b/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/PamAccountForm.tsx
index 74174415b2..b702cc5fd9 100644
--- a/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/PamAccountForm.tsx
+++ b/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/PamAccountForm.tsx
@@ -8,6 +8,7 @@ import {
import { DiscriminativePick } from "@app/types";
import { PamAccountHeader } from "../PamAccountHeader";
+import { ActiveDirectoryAccountForm } from "./ActiveDirectoryAccountForm";
import { AwsIamAccountForm } from "./AwsIamAccountForm";
import { KubernetesAccountForm } from "./KubernetesAccountForm";
import { MySQLAccountForm } from "./MySQLAccountForm";
@@ -113,6 +114,14 @@ const CreateForm = ({
resourceType={resourceType}
/>
);
+ case PamResourceType.ActiveDirectory:
+ return (
+ <ActiveDirectoryAccountForm
+ onSubmit={onSubmit}
+ resourceId={resourceId}
+ resourceType={resourceType}
+ />
+ );
default:
throw new Error(`Unhandled resource: ${resourceType}`);
}
@@ -163,6 +172,8 @@ const UpdateForm = ({ account, onComplete }: UpdateFormProps) => {
return <AwsIamAccountForm account={account as any} onSubmit={onSubmit} />;
case PamResourceType.Windows:
return <WindowsAccountForm account={account as any} onSubmit={onSubmit} />;
+ case PamResourceType.ActiveDirectory:
+ return <ActiveDirectoryAccountForm account={account as any} onSubmit={onSubmit} />;
default:
throw new Error(`Unhandled resource: ${account.resource.resourceType}`);
}
diff --git a/frontend/src/pages/pam/PamResourceByIDPage/PamResourceByIDPage.tsx b/frontend/src/pages/pam/PamResourceByIDPage/PamResourceByIDPage.tsx
index b14902ceb1..2c85e746ac 100644
--- a/frontend/src/pages/pam/PamResourceByIDPage/PamResourceByIDPage.tsx
+++ b/frontend/src/pages/pam/PamResourceByIDPage/PamResourceByIDPage.tsx
@@ -31,7 +31,8 @@ import { PamUpdateResourceModal } from "../PamResourcesPage/components/PamUpdate
import {
PamResourceAccountsSection,
PamResourceConnectionSection,
- PamResourceDetailsSection
+ PamResourceDetailsSection,
+ PamResourceRelatedResourcesSection
} from "./components";
const PageContent = () => {
@@ -186,10 +187,18 @@ const PageContent = () => {
<Tabs defaultValue="accounts">
<TabList>
<Tab value="accounts">Accounts</Tab>
+ {resource.resourceType === PamResourceType.ActiveDirectory && (
+ <Tab value="related-resources">Related Resources</Tab>
+ )}
</TabList>
<TabPanel value="accounts">
<PamResourceAccountsSection resource={resource} />
</TabPanel>
+ {resource.resourceType === PamResourceType.ActiveDirectory && (
+ <TabPanel value="related-resources">
+ <PamResourceRelatedResourcesSection resource={resource} />
+ </TabPanel>
+ )}
</Tabs>
</div>
</div>
diff --git a/frontend/src/pages/pam/PamResourceByIDPage/components/PamResourceAccountsSection.tsx b/frontend/src/pages/pam/PamResourceByIDPage/components/PamResourceAccountsSection.tsx
index 4fddc493dc..754d73d129 100644
--- a/frontend/src/pages/pam/PamResourceByIDPage/components/PamResourceAccountsSection.tsx
+++ b/frontend/src/pages/pam/PamResourceByIDPage/components/PamResourceAccountsSection.tsx
@@ -240,26 +240,28 @@ export const PamResourceAccountsSection = ({ resource }: Props) => {
<UnstableTableCell>
<div className="flex items-center gap-2">
{/* Temporarily disable accessing Windows Server accounts */}
- {resource.resourceType !== PamResourceType.Windows && (
- <ProjectPermissionCan
- I={ProjectPermissionPamAccountActions.Access}
- a={ProjectPermissionSub.PamAccounts}
- >
- <Button
- variant="ghost"
- size="xs"
- onClick={(e) => {
- e.stopPropagation();
- accessAccount(account);
- }}
- isPending={loadingAccountId === account.id}
- isDisabled={loadingAccountId === account.id}
+ {/* Disable accessing Active Directory accounts */}
+ {resource.resourceType !== PamResourceType.Windows &&
+ resource.resourceType !== PamResourceType.ActiveDirectory && (
+ <ProjectPermissionCan
+ I={ProjectPermissionPamAccountActions.Access}
+ a={ProjectPermissionSub.PamAccounts}
>
- <LogInIcon />
- Connect
- </Button>
- </ProjectPermissionCan>
- )}
+ <Button
+ variant="ghost"
+ size="xs"
+ onClick={(e) => {
+ e.stopPropagation();
+ accessAccount(account);
+ }}
+ isPending={loadingAccountId === account.id}
+ isDisabled={loadingAccountId === account.id}
+ >
+ <LogInIcon />
+ Connect
+ </Button>
+ </ProjectPermissionCan>
+ )}
<UnstableDropdownMenu>
<UnstableDropdownMenuTrigger asChild>
<UnstableIconButton variant="ghost" size="xs">
diff --git a/frontend/src/pages/pam/PamResourceByIDPage/components/PamResourceConnectionSection.tsx b/frontend/src/pages/pam/PamResourceByIDPage/components/PamResourceConnectionSection.tsx
index 89a2ab8fc0..1d8d631960 100644
--- a/frontend/src/pages/pam/PamResourceByIDPage/components/PamResourceConnectionSection.tsx
+++ b/frontend/src/pages/pam/PamResourceByIDPage/components/PamResourceConnectionSection.tsx
@@ -5,7 +5,7 @@ import { ProjectPermissionCan } from "@app/components/permissions";
import { Detail, DetailLabel, DetailValue, UnstableIconButton } from "@app/components/v3";
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/context";
import { gatewaysQueryKeys } from "@app/hooks/api";
-import { PamResourceType, TPamResource } from "@app/hooks/api/pam";
+import { PamResourceType, TPamResource, useGetPamResourceById } from "@app/hooks/api/pam";
type Props = {
resource: TPamResource;
@@ -127,18 +127,55 @@ const AwsIamConnectionDetails = ({
);
const WindowsConnectionDetails = ({
- connectionDetails
+ connectionDetails,
+ adServerResourceId
}: {
connectionDetails: { protocol: string; hostname: string; port: number };
+ adServerResourceId?: string | null;
+}) => {
+ const { data: adResource } = useGetPamResourceById(
+ PamResourceType.ActiveDirectory,
+ adServerResourceId || undefined,
+ { enabled: !!adServerResourceId }
+ );
+
+ return (
+ <>
+ <Detail>
+ <DetailLabel>Protocol</DetailLabel>
+ <DetailValue>{connectionDetails.protocol.toUpperCase()}</DetailValue>
+ </Detail>
+ <Detail>
+ <DetailLabel>Hostname</DetailLabel>
+ <DetailValue>{connectionDetails.hostname}</DetailValue>
+ </Detail>
+ <Detail>
+ <DetailLabel>Port</DetailLabel>
+ <DetailValue>{connectionDetails.port}</DetailValue>
+ </Detail>
+ <Detail>
+ <DetailLabel>AD Resource</DetailLabel>
+ <DetailValue>
+ {adResource ? adResource.name : <span className="text-muted">None</span>}
+ </DetailValue>
+ </Detail>
+ </>
+ );
+};
+
+const ActiveDirectoryConnectionDetails = ({
+ connectionDetails
+}: {
+ connectionDetails: { domain: string; dcAddress: string; port: number };
}) => (
<>
<Detail>
- <DetailLabel>Protocol</DetailLabel>
- <DetailValue>{connectionDetails.protocol.toUpperCase()}</DetailValue>
+ <DetailLabel>Domain</DetailLabel>
+ <DetailValue>{connectionDetails.domain}</DetailValue>
</Detail>
<Detail>
- <DetailLabel>Hostname</DetailLabel>
- <DetailValue>{connectionDetails.hostname}</DetailValue>
+ <DetailLabel>DC Address</DetailLabel>
+ <DetailValue>{connectionDetails.dcAddress}</DetailValue>
</Detail>
<Detail>
<DetailLabel>Port</DetailLabel>
@@ -161,7 +198,14 @@ const ConnectionDetailsContent = ({ resource }: Props) => {
case PamResourceType.AwsIam:
return <AwsIamConnectionDetails connectionDetails={resource.connectionDetails} />;
case PamResourceType.Windows:
- return <WindowsConnectionDetails connectionDetails={resource.connectionDetails} />;
+ return (
+ <WindowsConnectionDetails
+ connectionDetails={resource.connectionDetails}
+ adServerResourceId={resource.adServerResourceId}
+ />
+ );
+ case PamResourceType.ActiveDirectory:
+ return <ActiveDirectoryConnectionDetails connectionDetails={resource.connectionDetails} />;
default:
return null;
}
diff --git a/frontend/src/pages/pam/PamResourceByIDPage/components/PamResourceRelatedResourcesSection.tsx b/frontend/src/pages/pam/PamResourceByIDPage/components/PamResourceRelatedResourcesSection.tsx
new file mode 100644
index 0000000000..13d8ea2e21
--- /dev/null
+++ b/frontend/src/pages/pam/PamResourceByIDPage/components/PamResourceRelatedResourcesSection.tsx
@@ -0,0 +1,112 @@
+import { useNavigate, useParams } from "@tanstack/react-router";
+import { MonitorIcon } from "lucide-react";
+
+import {
+ UnstableEmpty,
+ UnstableEmptyHeader,
+ UnstableEmptyTitle,
+ UnstableTable,
+ UnstableTableBody,
+ UnstableTableCell,
+ UnstableTableHead,
+ UnstableTableHeader,
+ UnstableTableRow
+} from "@app/components/v3";
+import { useOrganization } from "@app/context";
+import { PAM_RESOURCE_TYPE_MAP, TPamResource, useListRelatedResources } from "@app/hooks/api/pam";
+
+type Props = {
+ resource: TPamResource;
+};
+
+export const PamResourceRelatedResourcesSection = ({ resource }: Props) => {
+ const navigate = useNavigate();
+ const { currentOrg } = useOrganization();
+ const params = useParams({ strict: false }) as { projectId?: string };
+ const { projectId } = params;
+
+ const { data: relatedResources, isPending } = useListRelatedResources(resource.id);
+
+ const handleResourceClick = (relatedResource: TPamResource) => {
+ navigate({
+ to: "/organizations/$orgId/projects/pam/$projectId/resources/$resourceType/$resourceId",
+ params: {
+ orgId: currentOrg.id,
+ projectId: projectId!,
+ resourceType: relatedResource.resourceType,
+ resourceId: relatedResource.id
+ }
+ });
+ };
+
+ return (
+ <div className="rounded-lg border border-border bg-container">
+ <div className="border-b border-border px-4 py-3">
+ <h3 className="text-lg font-medium">Related Resources</h3>
+ <p className="text-sm text-muted">Resources that belong to this Active Directory domain</p>
+ </div>
+ <div className="p-4">
+ <UnstableTable>
+ <UnstableTableHeader>
+ <UnstableTableRow>
+ <UnstableTableHead>Resource</UnstableTableHead>
+ <UnstableTableHead>Type</UnstableTableHead>
+ </UnstableTableRow>
+ </UnstableTableHeader>
+ <UnstableTableBody>
+ {isPending && (
+ <UnstableTableRow>
+ <UnstableTableCell colSpan={2} className="text-center text-muted">
+ Loading resources...
+ </UnstableTableCell>
+ </UnstableTableRow>
+ )}
+ {!isPending && (!relatedResources || relatedResources.length === 0) && (
+ <UnstableTableRow>
+ <UnstableTableCell colSpan={2}>
+ <UnstableEmpty className="border-0 bg-transparent py-8 shadow-none">
+ <UnstableEmptyHeader>
+ <UnstableEmptyTitle>No related resources found</UnstableEmptyTitle>
+ </UnstableEmptyHeader>
+ </UnstableEmpty>
+ </UnstableTableCell>
+ </UnstableTableRow>
+ )}
+ {relatedResources?.map((relatedResource) => {
+ const typeInfo = PAM_RESOURCE_TYPE_MAP[relatedResource.resourceType];
+ return (
+ <UnstableTableRow
+ key={relatedResource.id}
+ className="group cursor-pointer"
+ onClick={() => handleResourceClick(relatedResource)}
+ >
+ <UnstableTableCell>
+ <div className="flex items-center gap-3">
+ <div className="flex h-8 w-8 items-center justify-center rounded bg-foreground/5">
+ {typeInfo ? (
+ <img
+ alt={typeInfo.name}
+ src={`/images/integrations/${typeInfo.image}`}
+ className="size-4"
+ />
+ ) : (
+ <MonitorIcon className="size-4 text-muted" />
+ )}
+ </div>
+ <span className="font-medium">{relatedResource.name}</span>
+ </div>
+ </UnstableTableCell>
+ <UnstableTableCell>
+ <span className="text-sm text-muted">
+ {typeInfo?.name ?? relatedResource.resourceType}
+ </span>
+ </UnstableTableCell>
+ </UnstableTableRow>
+ );
+ })}
+ </UnstableTableBody>
+ </UnstableTable>
+ </div>
+ </div>
+ );
+};
diff --git a/frontend/src/pages/pam/PamResourceByIDPage/components/index.ts b/frontend/src/pages/pam/PamResourceByIDPage/components/index.ts
index 9df37d07ff..c7cd4bbbc4 100644
--- a/frontend/src/pages/pam/PamResourceByIDPage/components/index.ts
+++ b/frontend/src/pages/pam/PamResourceByIDPage/components/index.ts
@@ -1,3 +1,4 @@
export { PamResourceAccountsSection } from "./PamResourceAccountsSection";
export { PamResourceConnectionSection } from "./PamResourceConnectionSection";
export { PamResourceDetailsSection } from "./PamResourceDetailsSection";
+export { PamResourceRelatedResourcesSection } from "./PamResourceRelatedResourcesSection";
diff --git a/frontend/src/pages/pam/PamResourcesPage/components/PamResourceForm/ActiveDirectoryResourceForm.tsx b/frontend/src/pages/pam/PamResourcesPage/components/PamResourceForm/ActiveDirectoryResourceForm.tsx
new file mode 100644
index 0000000000..8532254e92
--- /dev/null
+++ b/frontend/src/pages/pam/PamResourcesPage/components/PamResourceForm/ActiveDirectoryResourceForm.tsx
@@ -0,0 +1,117 @@
+import { Controller, FormProvider, useForm } from "react-hook-form";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { z } from "zod";
+
+import { Button, FormControl, Input, ModalClose } from "@app/components/v2";
+import { PamResourceType, TActiveDirectoryResource } from "@app/hooks/api/pam";
+
+import { GenericResourceFields, genericResourceFieldsSchema } from "./GenericResourceFields";
+
+type Props = {
+ resource?: TActiveDirectoryResource;
+ onSubmit: (formData: FormData) => Promise<void>;
+};
+
+const formSchema = genericResourceFieldsSchema.extend({
+ resourceType: z.literal(PamResourceType.ActiveDirectory),
+ connectionDetails: z.object({
+ domain: z.string().trim().min(1, "Domain is required"),
+ dcAddress: z.string().trim().min(1, "DC address is required"),
+ port: z.coerce.number().int().min(1).max(65535)
+ })
+});
+
+type FormData = z.infer<typeof formSchema>;
+
+export const ActiveDirectoryResourceForm = ({ resource, onSubmit }: Props) => {
+ const isUpdate = Boolean(resource);
+
+ const form = useForm<FormData>({
+ resolver: zodResolver(formSchema),
+ defaultValues: resource ?? {
+ resourceType: PamResourceType.ActiveDirectory,
+ connectionDetails: {
+ domain: "",
+ dcAddress: "",
+ port: 389
+ }
+ }
+ });
+
+ const {
+ control,
+ handleSubmit,
+ formState: { isSubmitting, isDirty }
+ } = form;
+
+ return (
+ <FormProvider {...form}>
+ <form onSubmit={handleSubmit(onSubmit)}>
+ <GenericResourceFields />
+ <div className="mb-4 rounded-sm border border-mineshaft-600 bg-mineshaft-700/70 p-3 pb-0">
+ <Controller
+ name="connectionDetails.domain"
+ control={control}
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ className="mb-3"
+ errorText={error?.message}
+ isError={Boolean(error?.message)}
+ label="Domain"
+ >
+ <Input placeholder="corp.example.com" {...field} />
+ </FormControl>
+ )}
+ />
+ <div className="flex items-start gap-2">
+ <Controller
+ name="connectionDetails.dcAddress"
+ control={control}
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ className="flex-1"
+ errorText={error?.message}
+ isError={Boolean(error?.message)}
+ label="DC Address"
+ >
+ <Input placeholder="10.0.1.10 or dc.corp.example.com" {...field} />
+ </FormControl>
+ )}
+ />
+ <Controller
+ name="connectionDetails.port"
+ control={control}
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ className="w-28"
+ errorText={error?.message}
+ isError={Boolean(error?.message)}
+ label="Port"
+ >
+ <Input type="number" {...field} />
+ </FormControl>
+ )}
+ />
+ </div>
+ </div>
+ <div className="mt-6 flex items-center">
+ <Button
+ className="mr-4"
+ size="sm"
+ type="submit"
+ colorSchema="secondary"
+ isLoading={isSubmitting}
+ isDisabled={isSubmitting || !isDirty}
+ >
+ {isUpdate ? "Update Details" : "Create Resource"}
+ </Button>
+ <ModalClose asChild>
+ <Button colorSchema="secondary" variant="plain">
+ Cancel
+ </Button>
+ </ModalClose>
+ </div>
+ </form>
+ </FormProvider>
+ );
+};
diff --git a/frontend/src/pages/pam/PamResourcesPage/components/PamResourceForm/PamResourceForm.tsx b/frontend/src/pages/pam/PamResourcesPage/components/PamResourceForm/PamResourceForm.tsx
index d53c30754a..b634cf90eb 100644
--- a/frontend/src/pages/pam/PamResourcesPage/components/PamResourceForm/PamResourceForm.tsx
+++ b/frontend/src/pages/pam/PamResourcesPage/components/PamResourceForm/PamResourceForm.tsx
@@ -9,6 +9,7 @@ import {
import { DiscriminativePick } from "@app/types";
import { PamResourceHeader } from "../PamResourceHeader";
+import { ActiveDirectoryResourceForm } from "./ActiveDirectoryResourceForm";
import { AwsIamResourceForm } from "./AwsIamResourceForm";
import { KubernetesResourceForm } from "./KubernetesResourceForm";
import { MySQLResourceForm } from "./MySQLResourceForm";
@@ -37,7 +38,7 @@ const CreateForm = ({ resourceType, onComplete, projectId }: CreateFormProps) =>
const onSubmit = async (
formData: DiscriminativePick<
TPamResource,
- "name" | "resourceType" | "connectionDetails" | "gatewayId"
+ "name" | "resourceType" | "connectionDetails" | "gatewayId" | "adServerResourceId"
>
) => {
const resource = await createPamResource.mutateAsync({
@@ -66,6 +67,8 @@ const CreateForm = ({ resourceType, onComplete, projectId }: CreateFormProps) =>
return <AwsIamResourceForm onSubmit={onSubmit} />;
case PamResourceType.Windows:
return <WindowsResourceForm onSubmit={onSubmit} />;
+ case PamResourceType.ActiveDirectory:
+ return <ActiveDirectoryResourceForm onSubmit={onSubmit} />;
default:
throw new Error(`Unhandled resource: ${resourceType}`);
}
@@ -76,7 +79,10 @@ const UpdateForm = ({ resource, onComplete }: UpdateFormProps) => {
const { name: resourceName } = PAM_RESOURCE_TYPE_MAP[resource.resourceType];
const onSubmit = async (
- formData: DiscriminativePick<TPamResource, "name" | "resourceType" | "connectionDetails">
+ formData: DiscriminativePick<
+ TPamResource,
+ "name" | "resourceType" | "connectionDetails" | "adServerResourceId"
+ >
) => {
const updatedResource = await updatePamResource.mutateAsync({
resourceId: resource.id,
@@ -104,6 +110,8 @@ const UpdateForm = ({ resource, onComplete }: UpdateFormProps) => {
return <AwsIamResourceForm resource={resource} onSubmit={onSubmit} />;
case PamResourceType.Windows:
return <WindowsResourceForm resource={resource} onSubmit={onSubmit} />;
+ case PamResourceType.ActiveDirectory:
+ return <ActiveDirectoryResourceForm resource={resource} onSubmit={onSubmit} />;
default:
throw new Error(`Unhandled resource: ${(resource as any).resourceType}`);
}
diff --git a/frontend/src/pages/pam/PamResourcesPage/components/PamResourceForm/WindowsResourceForm.tsx b/frontend/src/pages/pam/PamResourcesPage/components/PamResourceForm/WindowsResourceForm.tsx
index cfe242f2e0..6c2596457e 100644
--- a/frontend/src/pages/pam/PamResourcesPage/components/PamResourceForm/WindowsResourceForm.tsx
+++ b/frontend/src/pages/pam/PamResourcesPage/components/PamResourceForm/WindowsResourceForm.tsx
@@ -2,8 +2,9 @@ import { Controller, FormProvider, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { z } from "zod";
-import { Button, FormControl, Input, ModalClose } from "@app/components/v2";
-import { PamResourceType, TWindowsResource } from "@app/hooks/api/pam";
+import { Button, FormControl, Input, ModalClose, Select, SelectItem } from "@app/components/v2";
+import { useProject } from "@app/context";
+import { PamResourceType, TWindowsResource, useListPamResources } from "@app/hooks/api/pam";
import { WindowsProtocol } from "@app/hooks/api/pam/types/windows-server-resource";
import { GenericResourceFields, genericResourceFieldsSchema } from "./GenericResourceFields";
@@ -19,24 +20,37 @@ const formSchema = genericResourceFieldsSchema.extend({
protocol: z.literal(WindowsProtocol.RDP),
hostname: z.string().trim().min(1, "Hostname is required"),
port: z.coerce.number().int().min(1).max(65535)
- })
+ }),
+ adServerResourceId: z.string().uuid().nullable().optional()
});
type FormData = z.infer<typeof formSchema>;
export const WindowsResourceForm = ({ resource, onSubmit }: Props) => {
const isUpdate = Boolean(resource);
+ const { projectId } = useProject();
+
+ const { data: adResources, isPending: isAdResourcesLoading } = useListPamResources({
+ projectId,
+ filterResourceTypes: PamResourceType.ActiveDirectory
+ });
const form = useForm<FormData>({
resolver: zodResolver(formSchema),
- defaultValues: resource ?? {
- resourceType: PamResourceType.Windows,
- connectionDetails: {
- protocol: WindowsProtocol.RDP,
- hostname: "",
- port: 3389
- }
- }
+ defaultValues: resource
+ ? {
+ ...resource,
+ adServerResourceId: resource.adServerResourceId ?? null
+ }
+ : {
+ resourceType: PamResourceType.Windows,
+ connectionDetails: {
+ protocol: WindowsProtocol.RDP,
+ hostname: "",
+ port: 3389
+ },
+ adServerResourceId: null
+ }
});
const {
@@ -49,6 +63,37 @@ export const WindowsResourceForm = ({ resource, onSubmit }: Props) => {
<FormProvider {...form}>
<form onSubmit={handleSubmit(onSubmit)}>
<GenericResourceFields />
+ <Controller
+ control={control}
+ name="adServerResourceId"
+ render={({ field: { value, onChange }, fieldState: { error } }) => (
+ <FormControl
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ label="Active Directory Resource"
+ helperText="Optionally associate this server with an AD domain"
+ >
+ <Select
+ value={value || "none"}
+ onValueChange={(val) => onChange(val === "none" ? null : val)}
+ className="w-full border border-mineshaft-500"
+ dropdownContainerClassName="max-w-none"
+ isLoading={isAdResourcesLoading}
+ placeholder="None"
+ position="popper"
+ >
+ <SelectItem value="none" key="none">
+ None
+ </SelectItem>
+ {(adResources?.resources || []).map((adResource) => (
+ <SelectItem value={adResource.id} key={adResource.id}>
+ {adResource.name}
+ </SelectItem>
+ ))}
+ </Select>
+ </FormControl>
+ )}
+ />
<div className="mb-4 rounded-sm border border-mineshaft-600 bg-mineshaft-700/70 p-3 pb-0">
<div className="mt-[0.675rem] flex items-start gap-2">
<Controller