mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-04 19:26:19 +00:00
Merge pull request #4575 from Infisical/daniel/allow-empty-secret-keys
fix: allow spaces in secret keys
This commit is contained in:
@@ -43,8 +43,6 @@ export const GenericResourceNameSchema = z
|
|||||||
export const BaseSecretNameSchema = z.string().trim().min(1);
|
export const BaseSecretNameSchema = z.string().trim().min(1);
|
||||||
|
|
||||||
export const SecretNameSchema = BaseSecretNameSchema.refine(
|
export const SecretNameSchema = BaseSecretNameSchema.refine(
|
||||||
(el) => !el.includes(" "),
|
(el) => !el.includes(":"),
|
||||||
"Secret name cannot contain spaces."
|
"Secret name cannot contain colon."
|
||||||
)
|
).refine((el) => !el.includes("/"), "Secret name cannot contain forward slash.");
|
||||||
.refine((el) => !el.includes(":"), "Secret name cannot contain colon.")
|
|
||||||
.refine((el) => !el.includes("/"), "Secret name cannot contain forward slash.");
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ type Props = {
|
|||||||
isReadOnly?: boolean;
|
isReadOnly?: boolean;
|
||||||
autoCapitalization?: boolean;
|
autoCapitalization?: boolean;
|
||||||
containerClassName?: string;
|
containerClassName?: string;
|
||||||
|
warning?: ReactNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
const inputVariants = cva(
|
const inputVariants = cva(
|
||||||
@@ -84,6 +85,7 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(
|
|||||||
size = "md",
|
size = "md",
|
||||||
isReadOnly,
|
isReadOnly,
|
||||||
autoCapitalization,
|
autoCapitalization,
|
||||||
|
warning,
|
||||||
...props
|
...props
|
||||||
},
|
},
|
||||||
ref
|
ref
|
||||||
@@ -116,10 +118,11 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(
|
|||||||
onInput={handleInput}
|
onInput={handleInput}
|
||||||
className={twMerge(
|
className={twMerge(
|
||||||
leftIcon ? "pl-10" : "pl-2.5",
|
leftIcon ? "pl-10" : "pl-2.5",
|
||||||
rightIcon ? "pr-10" : "pr-2.5",
|
rightIcon || warning ? "pr-10" : "pr-2.5",
|
||||||
inputVariants({ className, isError, size, isRounded, variant })
|
inputVariants({ className, isError, size, isRounded, variant })
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
{Boolean(warning) && !rightIcon && warning}
|
||||||
{rightIcon && <span className="absolute right-0 mr-3">{rightIcon}</span>}
|
{rightIcon && <span className="absolute right-0 mr-3">{rightIcon}</span>}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
+26
-2
@@ -1,7 +1,7 @@
|
|||||||
import { ClipboardEvent, useRef } from "react";
|
import { ClipboardEvent, useRef } from "react";
|
||||||
import { Controller, useForm } from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
import { subject } from "@casl/ability";
|
import { subject } from "@casl/ability";
|
||||||
import { faTriangleExclamation } from "@fortawesome/free-solid-svg-icons";
|
import { faTriangleExclamation, faWarning } from "@fortawesome/free-solid-svg-icons";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
@@ -12,7 +12,8 @@ import {
|
|||||||
FilterableSelect,
|
FilterableSelect,
|
||||||
FormControl,
|
FormControl,
|
||||||
Input,
|
Input,
|
||||||
PasswordGenerator
|
PasswordGenerator,
|
||||||
|
Tooltip
|
||||||
} from "@app/components/v2";
|
} from "@app/components/v2";
|
||||||
import { CreatableSelect } from "@app/components/v2/CreatableSelect";
|
import { CreatableSelect } from "@app/components/v2/CreatableSelect";
|
||||||
import { InfisicalSecretInput } from "@app/components/v2/InfisicalSecretInput";
|
import { InfisicalSecretInput } from "@app/components/v2/InfisicalSecretInput";
|
||||||
@@ -217,6 +218,29 @@ export const CreateSecretForm = ({ secretPath = "/", onClose }: Props) => {
|
|||||||
// @ts-expect-error this is for multiple ref single component
|
// @ts-expect-error this is for multiple ref single component
|
||||||
secretKeyInputRef.current = e;
|
secretKeyInputRef.current = e;
|
||||||
}}
|
}}
|
||||||
|
warning={
|
||||||
|
secretKey?.includes(" ") ? (
|
||||||
|
<Tooltip
|
||||||
|
className={"w-full max-w-72"}
|
||||||
|
content={
|
||||||
|
<div>
|
||||||
|
Secret key contains whitespaces.
|
||||||
|
<br />
|
||||||
|
<br /> If this is the desired format, you need to provide it as{" "}
|
||||||
|
<code className="rounded-md bg-mineshaft-500 px-1 py-0.5">
|
||||||
|
{encodeURIComponent(secretKey.trim())}
|
||||||
|
</code>{" "}
|
||||||
|
when making API requests.
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon
|
||||||
|
icon={faWarning}
|
||||||
|
className="absolute right-0 mr-3 text-yellow-600"
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
) : undefined
|
||||||
|
}
|
||||||
placeholder="Type your secret name"
|
placeholder="Type your secret name"
|
||||||
onPaste={handlePaste}
|
onPaste={handlePaste}
|
||||||
autoCapitalization={currentProject?.autoCapitalization}
|
autoCapitalization={currentProject?.autoCapitalization}
|
||||||
|
|||||||
+24
-2
@@ -1,7 +1,7 @@
|
|||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { Controller, useForm } from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
import { subject } from "@casl/ability";
|
import { subject } from "@casl/ability";
|
||||||
import { faCheck, faClose, faCopy } from "@fortawesome/free-solid-svg-icons";
|
import { faCheck, faClose, faCopy, faWarning } from "@fortawesome/free-solid-svg-icons";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { AnimatePresence, motion } from "framer-motion";
|
import { AnimatePresence, motion } from "framer-motion";
|
||||||
@@ -78,6 +78,7 @@ function SecretRenameRow({ environments, getSecretByKey, secretKey, secretPath }
|
|||||||
control,
|
control,
|
||||||
reset,
|
reset,
|
||||||
trigger,
|
trigger,
|
||||||
|
watch,
|
||||||
getValues,
|
getValues,
|
||||||
formState: { isDirty, isSubmitting, errors }
|
formState: { isDirty, isSubmitting, errors }
|
||||||
} = useForm<TFormSchema>({
|
} = useForm<TFormSchema>({
|
||||||
@@ -144,14 +145,35 @@ function SecretRenameRow({ environments, getSecretByKey, secretKey, secretPath }
|
|||||||
setIsSecNameCopied.on();
|
setIsSecNameCopied.on();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const currentSecretValue = watch("key");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form
|
<form
|
||||||
onSubmit={handleSubmit(handleFormSubmit)}
|
onSubmit={handleSubmit(handleFormSubmit)}
|
||||||
className="secret-table relative mb-2 flex w-full flex-row items-center justify-between overflow-hidden rounded-lg border border-solid border-mineshaft-700 bg-mineshaft-800 font-inter"
|
className="secret-table relative mb-2 flex w-full flex-row items-center justify-between overflow-hidden rounded-lg border border-solid border-mineshaft-700 bg-mineshaft-800 font-inter"
|
||||||
>
|
>
|
||||||
<div className="flex h-11 flex-1 flex-shrink-0 items-center">
|
<div className="flex h-11 flex-1 flex-shrink-0 items-center">
|
||||||
<span className="flex h-full min-w-[11rem] items-center justify-start border-r-2 border-mineshaft-600 px-4">
|
<span className="flex h-full min-w-[11rem] items-center justify-between gap-2 border-r-2 border-mineshaft-600 px-4">
|
||||||
Key
|
Key
|
||||||
|
{currentSecretValue?.trim()?.includes(" ") &&
|
||||||
|
currentSecretValue?.trim() !== secretKey && (
|
||||||
|
<Tooltip
|
||||||
|
className={"w-full max-w-72"}
|
||||||
|
content={
|
||||||
|
<div>
|
||||||
|
Secret key contains whitespaces.
|
||||||
|
<br />
|
||||||
|
<br /> If this is the desired format, you need to provide it as{" "}
|
||||||
|
<code className="rounded-md bg-mineshaft-500 px-1 py-0.5">
|
||||||
|
{encodeURIComponent(secretKey.trim())}
|
||||||
|
</code>{" "}
|
||||||
|
when making API requests.
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon icon={faWarning} className="text-yellow-600" />
|
||||||
|
</Tooltip>
|
||||||
|
)}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<Controller
|
<Controller
|
||||||
|
|||||||
+25
-2
@@ -1,12 +1,12 @@
|
|||||||
import { ClipboardEvent, useRef } from "react";
|
import { ClipboardEvent, useRef } from "react";
|
||||||
import { Controller, useForm } from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
import { faTriangleExclamation } from "@fortawesome/free-solid-svg-icons";
|
import { faTriangleExclamation, faWarning } from "@fortawesome/free-solid-svg-icons";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { createNotification } from "@app/components/notifications";
|
import { createNotification } from "@app/components/notifications";
|
||||||
import { Button, FormControl, Input, PasswordGenerator } from "@app/components/v2";
|
import { Button, FormControl, Input, PasswordGenerator, Tooltip } from "@app/components/v2";
|
||||||
import { CreatableSelect } from "@app/components/v2/CreatableSelect";
|
import { CreatableSelect } from "@app/components/v2/CreatableSelect";
|
||||||
import { InfisicalSecretInput } from "@app/components/v2/InfisicalSecretInput";
|
import { InfisicalSecretInput } from "@app/components/v2/InfisicalSecretInput";
|
||||||
import { ProjectPermissionActions, ProjectPermissionSub, useProjectPermission } from "@app/context";
|
import { ProjectPermissionActions, ProjectPermissionSub, useProjectPermission } from "@app/context";
|
||||||
@@ -178,6 +178,29 @@ export const CreateSecretForm = ({
|
|||||||
// @ts-expect-error this is for multiple ref single component
|
// @ts-expect-error this is for multiple ref single component
|
||||||
secretKeyInputRef.current = e;
|
secretKeyInputRef.current = e;
|
||||||
}}
|
}}
|
||||||
|
warning={
|
||||||
|
secretKey?.includes(" ") ? (
|
||||||
|
<Tooltip
|
||||||
|
className={"w-full max-w-72"}
|
||||||
|
content={
|
||||||
|
<div>
|
||||||
|
Secret key contains whitespaces.
|
||||||
|
<br />
|
||||||
|
<br /> If this is the desired format, you need to provide it as{" "}
|
||||||
|
<code className="rounded-md bg-mineshaft-500 px-1 py-0.5">
|
||||||
|
{encodeURIComponent(secretKey.trim())}
|
||||||
|
</code>{" "}
|
||||||
|
when making API requests.
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon
|
||||||
|
icon={faWarning}
|
||||||
|
className="absolute right-0 mr-3 text-yellow-600"
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
) : undefined
|
||||||
|
}
|
||||||
placeholder="Type your secret name"
|
placeholder="Type your secret name"
|
||||||
onPaste={handlePaste}
|
onPaste={handlePaste}
|
||||||
autoCapitalization={autoCapitalize}
|
autoCapitalization={autoCapitalize}
|
||||||
|
|||||||
+25
-1
@@ -43,7 +43,7 @@ import { twMerge } from "tailwind-merge";
|
|||||||
import { ProjectPermissionSecretActions } from "@app/context/ProjectPermissionContext/types";
|
import { ProjectPermissionSecretActions } from "@app/context/ProjectPermissionContext/types";
|
||||||
import { hasSecretReadValueOrDescribePermission } from "@app/lib/fn/permission";
|
import { hasSecretReadValueOrDescribePermission } from "@app/lib/fn/permission";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { faEyeSlash, faKey, faRotate } from "@fortawesome/free-solid-svg-icons";
|
import { faEyeSlash, faKey, faRotate, faWarning } from "@fortawesome/free-solid-svg-icons";
|
||||||
import { PendingAction } from "@app/hooks/api/secretFolders/types";
|
import { PendingAction } from "@app/hooks/api/secretFolders/types";
|
||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
import { CreateReminderForm } from "@app/pages/secret-manager/SecretDashboardPage/components/SecretListView/CreateReminderForm";
|
import { CreateReminderForm } from "@app/pages/secret-manager/SecretDashboardPage/components/SecretListView/CreateReminderForm";
|
||||||
@@ -487,6 +487,30 @@ export const SecretItem = memo(
|
|||||||
placeholder={error?.message}
|
placeholder={error?.message}
|
||||||
isError={Boolean(error)}
|
isError={Boolean(error)}
|
||||||
onKeyUp={() => trigger("key")}
|
onKeyUp={() => trigger("key")}
|
||||||
|
warning={
|
||||||
|
field?.value !== (originalSecret.originalKey || originalSecret.key) &&
|
||||||
|
field.value?.includes(" ") ? (
|
||||||
|
<Tooltip
|
||||||
|
className={"w-full max-w-72"}
|
||||||
|
content={
|
||||||
|
<div>
|
||||||
|
Secret key contains whitespaces.
|
||||||
|
<br />
|
||||||
|
<br /> If this is the desired format, you need to provide it as{" "}
|
||||||
|
<code className="rounded-md bg-mineshaft-500 px-1 py-0.5">
|
||||||
|
{encodeURIComponent(field.value.trim())}
|
||||||
|
</code>{" "}
|
||||||
|
when making API requests.
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon
|
||||||
|
icon={faWarning}
|
||||||
|
className="text-yellow-600 opacity-60"
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
) : undefined
|
||||||
|
}
|
||||||
{...field}
|
{...field}
|
||||||
className="w-full px-0 placeholder:text-red-500 focus:text-bunker-100 focus:ring-transparent"
|
className="w-full px-0 placeholder:text-red-500 focus:text-bunker-100 focus:ring-transparent"
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user