Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat: removed the check in rotation and also added useSudo capability
=31bf255a8d10
diff --git a/backend/src/ee/services/secret-rotation-v2/unix-linux-local-account-rotation/unix-linux-local-account-rotation-fns.ts b/backend/src/ee/services/secret-rotation-v2/unix-linux-local-account-rotation/unix-linux-local-account-rotation-fns.tsindex 0c27308ee8..c953938359 100644--- a/backend/src/ee/services/secret-rotation-v2/unix-linux-local-account-rotation/unix-linux-local-account-rotation-fns.ts+++ b/backend/src/ee/services/secret-rotation-v2/unix-linux-local-account-rotation/unix-linux-local-account-rotation-fns.ts@@ -56,10 +56,17 @@ const executeCommand = (client: Client, command: string): Promise<string> => {};// Change password for managed rotation (admin changing another user's password)-const changeManagedPassword = async (client: Client, username: string, newPassword: string): Promise<void> => {+const changeManagedPassword = async (+ client: Client,+ username: string,+ newPassword: string,+ useSudo: boolean = false+): Promise<void> => {// Using base64 encoding to avoid any shell escaping issuesconst encodedPassword = Buffer.from(`${username}:${newPassword}`).toString("base64");- const command = `echo '${encodedPassword}' | base64 -d | sudo chpasswd`;+ const command = useSudo+ ? `echo '${encodedPassword}' | base64 -d | sudo chpasswd`+ : `echo '${encodedPassword}' | base64 -d | chpasswd`;try {await executeCommand(client, command);@@ -161,8 +168,10 @@ export const unixLinuxLocalAccountRotationFactory: TRotationFactory<const {username,passwordRequirements,- rotationMethod = UnixLinuxLocalAccountRotationMethod.LoginAsRoot+ rotationMethod = UnixLinuxLocalAccountRotationMethod.LoginAsRoot,+ useSudo} = parameters;+ const shouldUseSudo = Boolean(useSudo ?? false);// Helper to verify SSH credentials workconst $verifyCredentials = async (targetUsername: string, targetPassword: string): Promise<void> => {@@ -198,10 +207,6 @@ export const unixLinuxLocalAccountRotationFactory: TRotationFactory<if (username === credentials.username)throw new BadRequestError({ message: "Provided username is used in Infisical app connections." });- const privilegedAccounts = ["root", "admin", "administrator", "sudo"];- if (privilegedAccounts.includes(username.toLowerCase()))- throw new BadRequestError({ message: "Cannot rotate passwords for privileged system accounts." });-// Determine which credentials to use for the SSH connectionlet connectConfig: TSshConnectionConfig;@@ -238,8 +243,8 @@ export const unixLinuxLocalAccountRotationFactory: TRotationFactory<// Self rotation: user changes their own password using passwd commandawait changeSelfPassword(client, currentPassword, newPassword);} else {- // Managed rotation: admin changes user's password using sudo chpasswd- await changeManagedPassword(client, username, newPassword);+ // Managed rotation: admin changes user's password using chpasswd (with sudo if specified)+ await changeManagedPassword(client, username, newPassword, shouldUseSudo);}} finally {client.destroy();diff --git a/backend/src/ee/services/secret-rotation-v2/unix-linux-local-account-rotation/unix-linux-local-account-rotation-schemas.ts b/backend/src/ee/services/secret-rotation-v2/unix-linux-local-account-rotation/unix-linux-local-account-rotation-schemas.tsindex fef7951fe5..747b0e8ffa 100644--- a/backend/src/ee/services/secret-rotation-v2/unix-linux-local-account-rotation/unix-linux-local-account-rotation-schemas.ts+++ b/backend/src/ee/services/secret-rotation-v2/unix-linux-local-account-rotation/unix-linux-local-account-rotation-schemas.ts@@ -40,7 +40,8 @@ const UnixLinuxLocalAccountRotationParametersSchema = z.object({rotationMethod: z.nativeEnum(UnixLinuxLocalAccountRotationMethod).optional()- .describe(SecretRotations.PARAMETERS.UNIX_LINUX_LOCAL_ACCOUNT.rotationMethod)+ .describe(SecretRotations.PARAMETERS.UNIX_LINUX_LOCAL_ACCOUNT.rotationMethod),+ useSudo: z.boolean().default(false).describe(SecretRotations.PARAMETERS.UNIX_LINUX_LOCAL_ACCOUNT.useSudo)});const UnixLinuxLocalAccountRotationSecretsMappingSchema = z.object({diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.tsindex 7e6aabe354..ab6ecff656 100644--- a/backend/src/lib/api-docs/constants.ts+++ b/backend/src/lib/api-docs/constants.ts@@ -3000,7 +3000,8 @@ export const SecretRotations = {rotationMethod:'Whether the rotation should be performed using "login-as-target" (the target user\'s own credentials) or "login-as-root" (the SSH connection\'s admin credentials). Defaults to "login-as-target".',password:- 'The current password of the target user. Required if "parameters.rotationMethod" is set to "login-as-target".'+ 'The current password of the target user. Required if "parameters.rotationMethod" is set to "login-as-target".',+ useSudo: "If true, uses sudo when executing the password rotation command. Defaults to false."},WINDOWS_LOCAL_ACCOUNT: {username: "The username of the Windows user account to rotate the password for.",diff --git a/docs/documentation/platform/secret-rotation/unix-linux-local-account.mdx b/docs/documentation/platform/secret-rotation/unix-linux-local-account.mdxindex 00f45e8d88..456623c9f3 100644--- a/docs/documentation/platform/secret-rotation/unix-linux-local-account.mdx+++ b/docs/documentation/platform/secret-rotation/unix-linux-local-account.mdx@@ -45,6 +45,7 @@ description: "Learn how to automatically rotate Unix/Linux local account passwor- **Login as Target** - Infisical will use the provided SSH username and password to log in and rotate its own password.- **Login as Root** - Infisical will use the SSH Connection's credentials to log in and rotate the provided user's password.- **Username** - The target SSH username whose password will be rotated.+ - **Use Sudo** - If true, uses sudo when executing the password rotation command. Defaults to false.- **Current Password** - The current password of the target user (required when **Rotation Method** is set to **Login as Target**).- **Password Requirements** - The constraints to apply when generating new passwords.diff --git a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/UnixLinuxLocalAccountRotationParametersFields.tsx b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/UnixLinuxLocalAccountRotationParametersFields.tsxindex 7e3737067c..245c219077 100644--- a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/UnixLinuxLocalAccountRotationParametersFields.tsx+++ b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/UnixLinuxLocalAccountRotationParametersFields.tsx@@ -2,7 +2,7 @@ import { Controller, useFormContext } from "react-hook-form";import { TSecretRotationV2Form } from "@app/components/secret-rotations-v2/forms/schemas";import { DEFAULT_PASSWORD_REQUIREMENTS } from "@app/components/secret-rotations-v2/forms/schemas/shared";-import { FormControl, Input, Select, SelectItem } from "@app/components/v2";+import { Checkbox, FormControl, Input, Select, SelectItem } from "@app/components/v2";import { SecretRotation } from "@app/hooks/api/secretRotationsV2";import { UnixLinuxLocalAccountRotationMethod } from "@app/hooks/api/secretRotationsV2/types/unix-linux-local-account-rotation";@@ -81,6 +81,29 @@ export const UnixLinuxLocalAccountRotationParametersFields = () => {</FormControl>)}/>+ {rotationMethod === UnixLinuxLocalAccountRotationMethod.LoginAsRoot && (+ <Controller+ name="parameters.useSudo"+ control={control}+ defaultValue={false}+ render={({ field: { value, onChange }, fieldState: { error } }) => (+ <FormControl+ isError={Boolean(error)}+ errorText={error?.message}+ tooltipText="When enabled, uses 'sudo chpasswd' to change the password. When disabled, uses 'chpasswd' directly. Enable this if the SSH connection user requires sudo privileges to change passwords."+ tooltipClassName="max-w-sm"+ >+ <Checkbox+ id="useSudo"+ isChecked={value}+ onCheckedChange={(checked) => onChange(checked)}+ >+ Use sudo to change password+ </Checkbox>+ </FormControl>+ )}+ />+ )}<div className="flex gap-3"><Controllername="parameters.username"diff --git a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ReviewFields/UnixLinuxLocalAccountRotationReviewFields.tsx b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ReviewFields/UnixLinuxLocalAccountRotationReviewFields.tsxindex ccc8158638..5c20eb93f5 100644--- a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ReviewFields/UnixLinuxLocalAccountRotationReviewFields.tsx+++ b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ReviewFields/UnixLinuxLocalAccountRotationReviewFields.tsx@@ -21,6 +21,7 @@ export const UnixLinuxLocalAccountRotationReviewFields = () => {<><SecretRotationReviewSection label="Parameters"><GenericFieldLabel label="Username">{parameters.username}</GenericFieldLabel>+ <GenericFieldLabel label="Use Sudo">{parameters.useSudo}</GenericFieldLabel></SecretRotationReviewSection>{passwordRequirements && (<SecretRotationReviewSection label="Password Requirements">diff --git a/frontend/src/components/secret-rotations-v2/forms/schemas/unix-linux-local-account-rotation-schema.ts b/frontend/src/components/secret-rotations-v2/forms/schemas/unix-linux-local-account-rotation-schema.tsindex 99baa796e5..f2d7984ef4 100644--- a/frontend/src/components/secret-rotations-v2/forms/schemas/unix-linux-local-account-rotation-schema.ts+++ b/frontend/src/components/secret-rotations-v2/forms/schemas/unix-linux-local-account-rotation-schema.ts@@ -11,7 +11,8 @@ export const UnixLinuxLocalAccountRotationSchema = zparameters: z.object({username: z.string().trim().min(1, "Username required"),passwordRequirements: PasswordRequirementsSchema.optional(),- rotationMethod: z.nativeEnum(UnixLinuxLocalAccountRotationMethod).optional()+ rotationMethod: z.nativeEnum(UnixLinuxLocalAccountRotationMethod).optional(),+ useSudo: z.boolean().default(false).optional()}),secretsMapping: z.object({username: z.string().trim().min(1, "Username required"),