Skip to content

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

Only discover accounts you can log into by default

x481436d129f7
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 2271b3d223..c460841405 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
@@ -24,46 +24,13 @@ const MAX_SWEEP_TARGETS = 65536;
const MAX_ACCOUNTS_PER_HOST = 2000;
const MAX_ACCOUNTS_PER_SCAN = 50000;
const MAX_USERNAME_LENGTH = 64;
-const PASSWD_MARKER = "__INFISICAL_PASSWD__";
-const DEFAULT_UID_MIN = 1000;
-const DEFAULT_UID_MAX = 60000;
-// one round-trip that returns the login.defs uid bounds followed by the passwd database
-const ENUMERATION_COMMAND = `grep -E '^UID_(MIN|MAX)' /etc/login.defs 2>/dev/null; echo '${PASSWD_MARKER}'; getent passwd 2>/dev/null || cat /etc/passwd 2>/dev/null`;
+// enumerate the passwd database; login-capability is decided from each entry's shell
+const ENUMERATION_COMMAND = `getent passwd 2>/dev/null || cat /etc/passwd 2>/dev/null`;
const NOLOGIN_SHELL_REGEX = new RE2(/(nologin|\/false|\/true|\/sync|\/shutdown|\/halt)$/);
-const UID_MIN_REGEX = new RE2(/^UID_MIN\s+(\d+)/m);
-const UID_MAX_REGEX = new RE2(/^UID_MAX\s+(\d+)/m);
const TRAILING_HYPHENS_REGEX = new RE2(/-+$/);
-const SYSTEM_ACCOUNT_NAMES = new Set([
- "daemon",
- "bin",
- "sys",
- "adm",
- "lp",
- "sync",
- "shutdown",
- "halt",
- "mail",
- "news",
- "uucp",
- "operator",
- "games",
- "gopher",
- "ftp",
- "nobody",
- "dbus",
- "sshd",
- "www-data",
- "backup",
- "list",
- "irc",
- "gnats",
- "proxy",
- "man"
-]);
-
type TUnixAccount = { host: string; port: number; credentials: SshExecCredentials };
const toUnixAccount = (account: TDiscoveryCredentialAccount): TUnixAccount => {
@@ -84,28 +51,16 @@ const isUsableAccount = (account: TUnixAccount) => {
return false;
};
-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;
- if (name.startsWith("_") || SYSTEM_ACCOUNT_NAMES.has(name)) return false;
- if (shell && NOLOGIN_SHELL_REGEX.test(shell)) return false;
- return true;
-};
-
-const parseUnixUsernames = (output: string, includeSystemAccounts: boolean): string[] => {
- const [defsPart = "", passwdPart = ""] = output.split(PASSWD_MARKER);
-
- const uidMin = Number(defsPart.match(UID_MIN_REGEX)?.[1]) || DEFAULT_UID_MIN;
- const uidMax = Number(defsPart.match(UID_MAX_REGEX)?.[1]) || DEFAULT_UID_MAX;
+// an account is discoverable if it can be logged into
+const hasLoginShell = (shell: string) => !(shell && NOLOGIN_SHELL_REGEX.test(shell));
+const parseUnixUsernames = (output: string): string[] => {
const usernames = new Set<string>();
- for (const line of passwdPart.split("\n")) {
+ for (const line of output.split("\n")) {
if (usernames.size >= MAX_ACCOUNTS_PER_HOST) break;
- const [name, , uidStr, , , , shell = ""] = line.trim().split(":");
- if (name && name.length <= MAX_USERNAME_LENGTH) {
- if (name === "root" || includeSystemAccounts || isLoginAccount(name, uidStr, shell, uidMin, uidMax)) {
- usernames.add(name);
- }
+ const [name, , , , , , shell = ""] = line.trim().split(":");
+ if (name && name.length <= MAX_USERNAME_LENGTH && hasLoginShell(shell)) {
+ usernames.add(name);
}
}
return [...usernames];
@@ -118,7 +73,7 @@ export const unixDiscoveryFactory: TPamDiscoveryFactory = ({
gatewayV2Service
}) => {
const accounts = credentialAccounts.map(toUnixAccount);
- const config = configuration as { cidrRanges: string[]; includeSystemAccounts?: boolean };
+ const config = configuration as { cidrRanges: string[] };
// accounts whose stored host matches the target are tried first, then every other account
const orderAccountsForHost = (host: string) => [
@@ -155,7 +110,7 @@ export const unixDiscoveryFactory: TPamDiscoveryFactory = ({
// eslint-disable-next-line no-await-in-loop
const output = await enumerateHost(host, account, signal);
return {
- accounts: parseUnixUsernames(output, config.includeSystemAccounts ?? false).map((username) => ({
+ accounts: parseUnixUsernames(output).map((username) => ({
accountType: PamAccountType.SSH,
name: slugify(`${host} ${username}`, { lowercase: true }).slice(0, 64).replace(TRAILING_HYPHENS_REGEX, ""),
fingerprint: `${host}:${username}`,
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 59fe6c3f8a..105011bf75 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
@@ -29,8 +29,7 @@ export const UnixDiscoveryConfigSchema = z
.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)
+ credentialAccountIds: z.array(z.string().uuid()).min(1).max(50)
})
.superRefine((config, ctx) => {
try {
diff --git a/frontend/src/pages/pam/PamDiscoveryPage/components/DiscoveryConfigFields.tsx b/frontend/src/pages/pam/PamDiscoveryPage/components/DiscoveryConfigFields.tsx
index 21d4731b80..11db07446f 100644
--- a/frontend/src/pages/pam/PamDiscoveryPage/components/DiscoveryConfigFields.tsx
+++ b/frontend/src/pages/pam/PamDiscoveryPage/components/DiscoveryConfigFields.tsx
@@ -149,16 +149,14 @@ export const DiscoveryConfigFields = ({
export const unixDiscoveryConfigFormShape = {
cidrRanges: z.string().min(1, "At least one target is required"),
- credentialAccountIds: z.array(z.string()).min(1, "Select at least one account"),
- includeSystemAccounts: z.boolean()
+ credentialAccountIds: z.array(z.string()).min(1, "Select at least one account")
};
export type TUnixDiscoveryConfigFields = z.infer<z.ZodObject<typeof unixDiscoveryConfigFormShape>>;
export const UNIX_DISCOVERY_CONFIG_DEFAULTS: TUnixDiscoveryConfigFields = {
cidrRanges: "",
- credentialAccountIds: [],
- includeSystemAccounts: false
+ credentialAccountIds: []
};
const parseCidrRanges = (value: string): string[] =>
@@ -173,16 +171,14 @@ export const unixDiscoveryConfigFromSource = (
cidrRanges: Array.isArray(config.cidrRanges) ? (config.cidrRanges as string[]).join("\n") : "",
credentialAccountIds: Array.isArray(config.credentialAccountIds)
? (config.credentialAccountIds as string[])
- : [],
- includeSystemAccounts: Boolean(config.includeSystemAccounts)
+ : []
});
export const buildUnixDiscoveryConfiguration = (
data: TUnixDiscoveryConfigFields
): Record<string, unknown> => ({
cidrRanges: parseCidrRanges(data.cidrRanges),
- credentialAccountIds: data.credentialAccountIds,
- includeSystemAccounts: data.includeSystemAccounts
+ credentialAccountIds: data.credentialAccountIds
});
export const SshCredentialAccountsField = ({
@@ -237,44 +233,22 @@ export const UnixDiscoveryConfigFields = ({
}: {
control: Control<TUnixDiscoveryConfigFields>;
}) => (
- <>
- <Controller
- control={control}
- name="cidrRanges"
- render={({ field, fieldState }) => (
- <Field>
- <FieldLabel>Targets</FieldLabel>
- <FieldContent>
- <TextArea {...field} rows={3} placeholder="10.0.0.0/24, 192.168.1.10, host.internal" />
- <FieldDescription>
- IP addresses, IPv4 CIDR ranges, or hostnames, one per line or comma-separated.
- </FieldDescription>
- <FieldError>{fieldState.error?.message}</FieldError>
- </FieldContent>
- </Field>
- )}
- />
-
- <Controller
- control={control}
- name="includeSystemAccounts"
- render={({ field }) => (
- <Field>
- <div className="flex items-center justify-between gap-4">
- <FieldLabel htmlFor="includeSystemAccounts" className="mb-0">
- Include system/service accounts
- </FieldLabel>
- <Switch
- id="includeSystemAccounts"
- variant="pam"
- checked={field.value}
- onCheckedChange={field.onChange}
- />
- </div>
- </Field>
- )}
- />
- </>
+ <Controller
+ control={control}
+ name="cidrRanges"
+ render={({ field, fieldState }) => (
+ <Field>
+ <FieldLabel>Targets</FieldLabel>
+ <FieldContent>
+ <TextArea {...field} rows={3} placeholder="10.0.0.0/24, 192.168.1.10, host.internal" />
+ <FieldDescription>
+ IP addresses, IPv4 CIDR ranges, or hostnames, one per line or comma-separated.
+ </FieldDescription>
+ <FieldError>{fieldState.error?.message}</FieldError>
+ </FieldContent>
+ </Field>
+ )}
+ />
);
// Shared credential-account + schedule fields, used by both the create modal and the edit tab.