Skip to content

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

address more reviews

x77cb5fc1e9c7
diff --git a/backend/src/ee/services/pam-discovery/pam-discovery-source-service.ts b/backend/src/ee/services/pam-discovery/pam-discovery-source-service.ts
index fc146924cb..e2e1375018 100644
--- a/backend/src/ee/services/pam-discovery/pam-discovery-source-service.ts
+++ b/backend/src/ee/services/pam-discovery/pam-discovery-source-service.ts
@@ -104,7 +104,8 @@ export const pamDiscoverySourceServiceFactory = (deps: TPamDiscoverySourceServic
const decryptToObject = (blob: Buffer, decryptor: (i: { cipherTextBlob: Buffer }) => Buffer) =>
JSON.parse(decryptor({ cipherTextBlob: blob }).toString("utf-8")) as Record<string, unknown>;
- const SSH_CERT_TTL = "10m";
+ // one cert is minted per scan and reused for every host, so it must outlive the whole run
+ const SSH_CERT_TTL = "1h";
// certificate accounts can't be presented by an ssh client, so sign an ephemeral user cert the gateway will present;
// password/private-key accounts pass through unchanged
diff --git a/backend/src/ee/services/pam-discovery/unix/unix-discovery-factory.ts b/backend/src/ee/services/pam-discovery/unix/unix-discovery-factory.ts
index 89ea2b04a8..89fc227c10 100644
--- a/backend/src/ee/services/pam-discovery/unix/unix-discovery-factory.ts
+++ b/backend/src/ee/services/pam-discovery/unix/unix-discovery-factory.ts
@@ -1,7 +1,4 @@
-import net from "node:net";
-
import slugify from "@sindresorhus/slugify";
-import { Netmask } from "netmask";
import pLimit from "p-limit";
import RE2 from "re2";
@@ -18,11 +15,11 @@ import {
TDiscoveryScanResult,
TPamDiscoveryFactory
} from "../pam-discovery-types";
+import { expandTargets } from "./unix-discovery-fns";
const SSH_EXEC_TIMEOUT_MS = 20 * 1000;
const SCAN_CONCURRENCY = 64;
const SWEEP_DIAL_TIMEOUT_MS = 3 * 1000;
-const MAX_TARGET_HOSTS = 65536;
const MAX_SWEEP_TARGETS = 65536;
const PASSWD_MARKER = "__INFISICAL_PASSWD__";
const DEFAULT_UID_MIN = 1000;
@@ -84,31 +81,6 @@ const isUsableAccount = (account: TUnixAccount) => {
return false;
};
-const expandTargets = (cidrRanges: string[]): string[] => {
- const hosts = new Set<string>();
- for (const range of cidrRanges) {
- const trimmed = range.trim();
- if (trimmed) {
- if (trimmed.includes("/")) {
- if (!net.isIPv4(trimmed.split("/")[0])) {
- throw new BadRequestError({ message: `Only IPv4 CIDR ranges are supported: ${trimmed}` });
- }
- const block = new Netmask(trimmed);
- if (hosts.size + block.size > MAX_TARGET_HOSTS) {
- throw new BadRequestError({ message: `Targets expand to more than ${MAX_TARGET_HOSTS} hosts` });
- }
- block.forEach((ip) => hosts.add(ip));
- } else {
- hosts.add(trimmed);
- if (hosts.size > MAX_TARGET_HOSTS) {
- throw new BadRequestError({ message: `Targets expand to more than ${MAX_TARGET_HOSTS} hosts` });
- }
- }
- }
- }
- return [...hosts];
-};
-
const isLoginAccount = (name: string, uidStr: string, shell: string, uidMin: number, uidMax: number) => {
const uid = Number(uidStr);
if (Number.isNaN(uid) || uid < uidMin || uid > uidMax) return false;
diff --git a/backend/src/ee/services/pam-discovery/unix/unix-discovery-fns.ts b/backend/src/ee/services/pam-discovery/unix/unix-discovery-fns.ts
new file mode 100644
index 0000000000..95f938b17a
--- /dev/null
+++ b/backend/src/ee/services/pam-discovery/unix/unix-discovery-fns.ts
@@ -0,0 +1,33 @@
+import net from "node:net";
+
+import { Netmask } from "netmask";
+
+import { BadRequestError } from "@app/lib/errors";
+
+export const MAX_TARGET_HOSTS = 65536;
+
+// expands cidr ranges / bare ips / hostnames into the deduped set of target hosts. Enforces IPv4-only CIDRs and the host cap
+export const expandTargets = (cidrRanges: string[]): string[] => {
+ const hosts = new Set<string>();
+ for (const range of cidrRanges) {
+ const trimmed = range.trim();
+ if (trimmed) {
+ if (trimmed.includes("/")) {
+ if (!net.isIPv4(trimmed.split("/")[0])) {
+ throw new BadRequestError({ message: `Only IPv4 CIDR ranges are supported: ${trimmed}` });
+ }
+ const block = new Netmask(trimmed);
+ if (hosts.size + block.size > MAX_TARGET_HOSTS) {
+ throw new BadRequestError({ message: `Targets expand to more than ${MAX_TARGET_HOSTS} hosts` });
+ }
+ block.forEach((ip) => hosts.add(ip));
+ } else {
+ hosts.add(trimmed);
+ if (hosts.size > MAX_TARGET_HOSTS) {
+ throw new BadRequestError({ message: `Targets expand to more than ${MAX_TARGET_HOSTS} hosts` });
+ }
+ }
+ }
+ }
+ return [...hosts];
+};
diff --git a/backend/src/ee/services/pam-discovery/unix/unix-discovery-schemas.ts b/backend/src/ee/services/pam-discovery/unix/unix-discovery-schemas.ts
index 116d33d043..59fe6c3f8a 100644
--- a/backend/src/ee/services/pam-discovery/unix/unix-discovery-schemas.ts
+++ b/backend/src/ee/services/pam-discovery/unix/unix-discovery-schemas.ts
@@ -5,6 +5,8 @@ import { z } from "zod";
import { isValidIpOrCidr } from "@app/lib/ip";
+import { expandTargets } from "./unix-discovery-fns";
+
const HOSTNAME_REGEX = new RE2(
/^[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
);
@@ -18,14 +20,26 @@ const isValidIpv4Target = (value: string) => {
const isValidTarget = (value: string) =>
isValidIpv4Target(value) || (value.length <= 253 && HOSTNAME_REGEX.test(value));
-export const UnixDiscoveryConfigSchema = z.object({
- cidrRanges: z
- .array(z.string().trim().min(1))
- .min(1)
- .max(50)
- .refine((ranges) => ranges.every(isValidTarget), {
- message: "Each target must be a valid IPv4 address, IPv4 CIDR range, or hostname"
- }),
- credentialAccountIds: z.array(z.string().uuid()).min(1).max(50),
- includeSystemAccounts: z.boolean().default(false)
-});
+export const UnixDiscoveryConfigSchema = z
+ .object({
+ cidrRanges: z
+ .array(z.string().trim().min(1))
+ .min(1)
+ .max(50)
+ .refine((ranges) => ranges.every(isValidTarget), {
+ message: "Each target must be a valid IPv4 address, IPv4 CIDR range, or hostname"
+ }),
+ credentialAccountIds: z.array(z.string().uuid()).min(1).max(50),
+ includeSystemAccounts: z.boolean().default(false)
+ })
+ .superRefine((config, ctx) => {
+ try {
+ expandTargets(config.cidrRanges);
+ } catch (err) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ path: ["cidrRanges"],
+ message: err instanceof Error ? err.message : "Invalid targets"
+ });
+ }
+ });
diff --git a/frontend/src/pages/pam/PamDiscoveryPage/components/DiscoveryConfigFields.tsx b/frontend/src/pages/pam/PamDiscoveryPage/components/DiscoveryConfigFields.tsx
index 07dfdf2d94..18a6e87797 100644
--- a/frontend/src/pages/pam/PamDiscoveryPage/components/DiscoveryConfigFields.tsx
+++ b/frontend/src/pages/pam/PamDiscoveryPage/components/DiscoveryConfigFields.tsx
@@ -1,7 +1,10 @@
import { Control, Controller, useWatch } from "react-hook-form";
+import { AlertTriangle } from "lucide-react";
import { z } from "zod";
import {
+ Alert,
+ AlertDescription,
Field,
FieldContent,
FieldDescription,
@@ -214,6 +217,13 @@ export const SshCredentialAccountsField = ({
connects.
</FieldDescription>
<FieldError>{fieldState.error?.message}</FieldError>
+ <Alert variant="warning" className="mt-1">
+ <AlertTriangle />
+ <AlertDescription>
+ Password accounts send their password to every host scanned in the range, including
+ hosts you don&apos;t control. We recommend a key or certificate account for scanning.
+ </AlertDescription>
+ </Alert>
</FieldContent>
</Field>
)}