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
Add ST V3 copy to clipboard, default to is active
Tuan Dangf9c28ab045e0
diff --cc backend/src/utils/setup/index.tsindex 58ab0a7ecb,62c7272f3a..b9fe399927--- a/backend/src/utils/setup/index.ts+++ b/backend/src/utils/setup/index.ts@@@ -26,12 -26,8 +26,13 @@@ importreencryptSecretBlindIndexDataSalts} from "./reencryptData";import { getMongoURL, getNodeEnv, getRedisUrl, getSentryDSN } from "../../config";-import { initializePassport } from "../auth";+import {+ initializeGitHubStrategy,+ initializeGitLabStrategy,+ initializeGoogleStrategy,+ initializeSamlStrategy+} from "../authn/passport";+ import { logger } from "../logging";/*** Prepare Infisical upon startup. This includes tasks like:diff --cc frontend/src/views/Settings/ProjectSettingsPage/components/ServiceTokenV3Section/AddServiceTokenV3Modal.tsxindex 0745da36d5,cc3c81babe..c1779b19ed--- a/frontend/src/views/Settings/ProjectSettingsPage/components/ServiceTokenV3Section/AddServiceTokenV3Modal.tsx+++ b/frontend/src/views/Settings/ProjectSettingsPage/components/ServiceTokenV3Section/AddServiceTokenV3Modal.tsx@@@ -1,12 -1,12 +1,11 @@@--import { useEffect } from "react";++import { useEffect, useState } from "react";import { Controller, useFieldArray, useForm } from "react-hook-form";--import { faPlus,faXmark } from "@fortawesome/free-solid-svg-icons";++import { faPlus, faXmark, faCheck, faCopy } from "@fortawesome/free-solid-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";import { yupResolver } from "@hookform/resolvers/yup";import nacl from "tweetnacl";import { encodeBase64 } from "tweetnacl-util";import * as yup from "yup";--import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider";import {decryptAssymmetric,@@@ -28,6 -27,6 +27,7 @@@ importuseSubscription,useWorkspace} from "@app/context";++import { useToggle } from "@app/hooks";import {useCreateServiceTokenV3,useGetUserWsKey,@@@ -115,6 -102,6 +115,9 @@@ export const AddServiceTokenV3Modal = (handlePopUpOpen,handlePopUpToggle}: Props) => {++ const [newServiceTokenJSON, setNewServiceTokenJSON] = useState("");++ const [isServiceTokenJSONCopied, setIsServiceTokenJSONCopied] = useToggle(false);++const { subscription } = useSubscription();const { currentWorkspace } = useWorkspace();@@@ -142,6 -128,6 +145,21 @@@}]}});++++ useEffect(() => {++ let timer: NodeJS.Timeout;++++ if (isServiceTokenJSONCopied) {++ timer = setTimeout(() => setIsServiceTokenJSONCopied.off(), 2000);++ }++++ return () => clearTimeout(timer);++ }, [setIsServiceTokenJSONCopied]);++++ const copyTokenToClipboard = () => {++ navigator.clipboard.writeText(newServiceTokenJSON);++ setIsServiceTokenJSONCopied.on();++ };useEffect(() => {const serviceTokenData = popUp?.serviceTokenV3?.data as {@@@ -234,10 -213,8 +252,12 @@@name,scopes: reformattedScopes,trustedIps,- expiresIn: expiresIn === "" ? undefined : Number(expiresIn)+ expiresIn: expiresIn === "" ? undefined : Number(expiresIn),+ accessTokenTTL: Number(accessTokenTTL),+ isRefreshTokenRotationEnabled});++++ handlePopUpToggle("serviceTokenV3", false);} else {// createif (!currentWorkspace?._id) return;@@@ -276,12 -251,12 +296,15 @@@});const downloadData = {-- publicKey,-- privateKey,- refreshToken- serviceToken++ public_key: publicKey,++ private_key: privateKey,++ refresh_token: refreshToken};-- const blob = new Blob([JSON.stringify(downloadData, null, 2)], { type: "application/json" });++ const serviceTokenJSON = JSON.stringify(downloadData, null, 2);++ setNewServiceTokenJSON(serviceTokenJSON);++++ const blob = new Blob([serviceTokenJSON], { type: "application/json" });const href = URL.createObjectURL(blob);const link = document.createElement("a");link.href = href;@@@ -297,7 -272,7 +320,6 @@@});reset();-- handlePopUpToggle("serviceTokenV3", false);} catch (err) {console.error(err);createNotification({@@@ -306,6 -281,6 +328,8 @@@});}}++++ const hasServiceTokenJSON = Boolean(newServiceTokenJSON);return (<Modal@@@ -313,264 -288,232 +337,282 @@@onOpenChange={(isOpen) => {handlePopUpToggle("serviceTokenV3", isOpen);reset();++ setNewServiceTokenJSON("");}}><ModalContent title={`${popUp?.serviceTokenV3?.data ? "Update" : "Create"} Service Token V3`}>-- <form onSubmit={handleSubmit(onFormSubmit)}>-- <Controller-- control={control}-- defaultValue=""-- name="name"-- render={({ field, fieldState: { error } }) => (-- <FormControl-- label="Name"-- isError={Boolean(error)}-- errorText={error?.message}-- >-- <Input-- {...field}-- placeholder="My ST V3"-- />-- </FormControl>-- )}-- />-- {tokenScopes.map(({ id }, index) => (-- <div className="flex items-end space-x-2 mb-3" key={id}>-- <Controller-- control={control}-- name={`scopes.${index}.permission`}-- render={({ field: { onChange, ...field }, fieldState: { error } }) => (-- <FormControl-- className="mb-0"-- label={index === 0 ? "Permission" : undefined}-- errorText={error?.message}-- isError={Boolean(error)}-- >-- <Select-- defaultValue={field.value}-- {...field}-- onValueChange={(e) => onChange(e)}-- className="w-36"-- >-- <SelectItem value="read" key="st-v3-read">-- Read-- </SelectItem>-- <SelectItem value="readWrite" key="st-v3-write">-- Read & Write-- </SelectItem>-- </Select>-- </FormControl>-- )}-- />-- <Controller-- control={control}-- name={`scopes.${index}.environment`}-- render={({ field: { onChange, ...field }, fieldState: { error } }) => (-- <FormControl-- className="mb-0"-- label={index === 0 ? "Environment" : undefined}-- errorText={error?.message}-- isError={Boolean(error)}-- >-- <Select-- defaultValue={field.value}-- {...field}-- onValueChange={(e) => onChange(e)}-- className="w-36"-- >-- {currentWorkspace?.environments.map(({ name, slug }) => (-- <SelectItem value={slug} key={slug}>-- {name}-- </SelectItem>-- ))}-- </Select>-- </FormControl>-- )}-- />-- <Controller-- control={control}-- name={`scopes.${index}.secretPath`}-- defaultValue="/"-- render={({ field, fieldState: { error } }) => (-- <FormControl-- className="mb-0 flex-grow"-- label={index === 0 ? "Secrets Path" : undefined}-- isError={Boolean(error)}-- errorText={error?.message}-- >-- <Input {...field} placeholder="can be /, /nested/**, /**/deep" />-- </FormControl>-- )}-- />-- <IconButton-- onClick={() => remove(index)}-- size="lg"-- colorSchema="danger"-- variant="plain"-- ariaLabel="update"-- className="p-3"++ {!hasServiceTokenJSON ? (++ <form onSubmit={handleSubmit(onFormSubmit)}>++ <Controller++ control={control}++ defaultValue=""++ name="name"++ render={({ field, fieldState: { error } }) => (++ <FormControl++ label="Name"++ isError={Boolean(error)}++ errorText={error?.message}>-- <FontAwesomeIcon icon={faXmark} />-- </IconButton>-- </div>-- ))}-- <div className="my-4 ml-1">-- <Button-- variant="outline_bg"-- onClick={() =>-- append({-- permission: "read",-- environment: currentWorkspace?.environments?.[0]?.slug || "",-- secretPath: "/"-- })-- }-- leftIcon={<FontAwesomeIcon icon={faPlus} />}-- size="xs"-- >-- Add Scope-- </Button>-- </div>-- {tokenTrustedIps.map(({ id }, index) => (-- <div className="flex items-end space-x-2 mb-3" key={id}>-- <Controller-- control={control}-- name={`trustedIps.${index}.ipAddress`}-- defaultValue="0.0.0.0/0"-- render={({ field, fieldState: { error } }) => {-- return (++ <Input++ {...field}++ placeholder="My ST V3"++ />++ </FormControl>++ )}++ />++ {tokenScopes.map(({ id }, index) => (++ <div className="flex items-end space-x-2 mb-3" key={id}>++ <Controller++ control={control}++ name={`scopes.${index}.permission`}++ render={({ field: { onChange, ...field }, fieldState: { error } }) => (++ <FormControl++ className="mb-0"++ label={index === 0 ? "Permission" : undefined}++ errorText={error?.message}++ isError={Boolean(error)}++ >++ <Select++ defaultValue={field.value}++ {...field}++ onValueChange={(e) => onChange(e)}++ className="w-36"++ >++ <SelectItem value="read" key="st-v3-read">++ Read++ </SelectItem>++ <SelectItem value="readWrite" key="st-v3-write">++ Read & Write++ </SelectItem>++ </Select>++ </FormControl>++ )}++ />++ <Controller++ control={control}++ name={`scopes.${index}.environment`}++ render={({ field: { onChange, ...field }, fieldState: { error } }) => (++ <FormControl++ className="mb-0"++ label={index === 0 ? "Environment" : undefined}++ errorText={error?.message}++ isError={Boolean(error)}++ >++ <Select++ defaultValue={field.value}++ {...field}++ onValueChange={(e) => onChange(e)}++ className="w-36"++ >++ {currentWorkspace?.environments.map(({ name, slug }) => (++ <SelectItem value={slug} key={slug}>++ {name}++ </SelectItem>++ ))}++ </Select>++ </FormControl>++ )}++ />++ <Controller++ control={control}++ name={`scopes.${index}.secretPath`}++ defaultValue="/"++ render={({ field, fieldState: { error } }) => (<FormControlclassName="mb-0 flex-grow"-- label={index === 0 ? "Trusted IP" : undefined}++ label={index === 0 ? "Secrets Path" : undefined}isError={Boolean(error)}errorText={error?.message}>-- <Input-- value={field.value}-- onChange={(e) => {-- if (subscription?.ipAllowlisting) {-- field.onChange(e);-- return;-- }---- handlePopUpOpen("upgradePlan");-- }}-- placeholder="123.456.789.0"-- />++ <Input {...field} placeholder="can be /, /nested/**, /**/deep" /></FormControl>-- );-- }}-- />-- <IconButton++ )}++ />++ <IconButton++ onClick={() => remove(index)}++ size="lg"++ colorSchema="danger"++ variant="plain"++ ariaLabel="update"++ className="p-3"++ >++ <FontAwesomeIcon icon={faXmark} />++ </IconButton>++ </div>++ ))}++ <div className="my-4 ml-1">++ <Button++ variant="outline_bg"++ onClick={() =>++ append({++ permission: "read",++ environment: currentWorkspace?.environments?.[0]?.slug || "",++ secretPath: "/"++ })++ }++ leftIcon={<FontAwesomeIcon icon={faPlus} />}++ size="xs"++ >++ Add Scope++ </Button>++ </div>++ {tokenTrustedIps.map(({ id }, index) => (++ <div className="flex items-end space-x-2 mb-3" key={id}>++ <Controller++ control={control}++ name={`trustedIps.${index}.ipAddress`}++ defaultValue="0.0.0.0/0"++ render={({ field, fieldState: { error } }) => {++ return (++ <FormControl++ className="mb-0 flex-grow"++ label={index === 0 ? "Trusted IP" : undefined}++ isError={Boolean(error)}++ errorText={error?.message}++ >++ <Input++ value={field.value}++ onChange={(e) => {++ if (subscription?.ipAllowlisting) {++ field.onChange(e);++ return;++ }++++ handlePopUpOpen("upgradePlan");++ }}++ placeholder="123.456.789.0"++ />++ </FormControl>++ );++ }}++ />++ <IconButton++ onClick={() => {++ if (subscription?.ipAllowlisting) {++ removeTrustedIp(index);++ return;++ }++++ handlePopUpOpen("upgradePlan");++ }}++ size="lg"++ colorSchema="danger"++ variant="plain"++ ariaLabel="update"++ className="p-3"++ >++ <FontAwesomeIcon icon={faXmark} />++ </IconButton>++ </div>++ ))}++ <div className="my-4 ml-1">++ <Button++ variant="outline_bg"onClick={() => {if (subscription?.ipAllowlisting) {-- removeTrustedIp(index);++ appendTrustedIp({++ ipAddress: "0.0.0.0/0"++ })return;}--++handlePopUpOpen("upgradePlan");}}-- size="lg"-- colorSchema="danger"-- variant="plain"-- ariaLabel="update"-- className="p-3"++ leftIcon={<FontAwesomeIcon icon={faPlus} />}++ size="xs">-- <FontAwesomeIcon icon={faXmark} />-- </IconButton>++ Add IP Address++ </Button></div>-- ))}-- <div className="my-4 ml-1">-- <Button-- variant="outline_bg"-- onClick={() => {-- if (subscription?.ipAllowlisting) {-- appendTrustedIp({-- ipAddress: "0.0.0.0/0"-- })-- return;-- }---- handlePopUpOpen("upgradePlan");-- }}-- leftIcon={<FontAwesomeIcon icon={faPlus} />}-- size="xs"-- >-- Add IP Address-- </Button>-- </div>-- <Controller-- control={control}-- name="expiresIn"- defaultValue=""- defaultValue="15552000"-- render={({ field: { onChange, ...field }, fieldState: { error } }) => (-- <FormControl- label={`${popUp?.serviceTokenV3?.data ? "Update" : ""} Refresh Token Expires In`}- label={`${popUp?.serviceTokenV3?.data ? "Update" : ""} Expire In`}-- errorText={error?.message}-- isError={Boolean(error)}-- className="mt-4"-- >-- <Select-- defaultValue={field.value}-- {...field}-- onValueChange={(e) => onChange(e)}-- className="w-full"++ <Controller++ control={control}++ name="expiresIn"++ defaultValue=""++ render={({ field: { onChange, ...field }, fieldState: { error } }) => (++ <FormControl++ label={`${popUp?.serviceTokenV3?.data ? "Update" : ""} Refresh Token Expires In`}++ errorText={error?.message}++ isError={Boolean(error)}++ className="mt-4">-- {expirations.map(({ label, value }) => (-- <SelectItem value={String(value || "")} key={`api-key-expiration-${label}`}>-- {label}-- </SelectItem>-- ))}-- </Select>- </FormControl>- )}- />- <Controller- control={control}- defaultValue="7200"- name="accessTokenTTL"- render={({ field, fieldState: { error } }) => (- <FormControl- label="Access Token TTL (seconds)"- isError={Boolean(error)}- errorText={error?.message}- >- <Input- {...field}- placeholder="7200"- />-- </FormControl>-- )}-- />- <div className="mt-8 mb-[2.36rem]">- <div className="mt-8 flex items-center">- <Button- className="mr-4"- size="sm"- type="submit"- isLoading={isSubmitting}- isDisabled={isSubmitting}++ <Select++ defaultValue={field.value}++ {...field}++ onValueChange={(e) => onChange(e)}++ className="w-full"++ >++ {expirations.map(({ label, value }) => (++ <SelectItem value={String(value || "")} key={`api-key-expiration-${label}`}>++ {label}++ </SelectItem>++ ))}++ </Select>++ </FormControl>++ )}++ />+ <Controller+ control={control}- name="isRefreshTokenRotationEnabled"- render={({ field: { onChange, value } }) => (- <Switch- id="label-refresh-token-rotation"- onCheckedChange={(isChecked) => onChange(isChecked)}- isChecked={value}++ defaultValue="7200"++ name="accessTokenTTL"++ render={({ field, fieldState: { error } }) => (++ <FormControl++ label="Access Token TTL (seconds)"++ isError={Boolean(error)}++ errorText={error?.message}+ >- Refresh Token Rotation- </Switch>++ <Input++ {...field}++ placeholder="7200"++ />++ </FormControl>+ )}+ />- </div>- <div className="mt-8 flex items-center">- <Button- className="mr-4"- size="sm"- type="submit"- isLoading={isSubmitting}- isDisabled={isSubmitting}++ <div className="mt-8 mb-[2.36rem]">++ <Controller++ control={control}++ name="isRefreshTokenRotationEnabled"++ render={({ field: { onChange, value } }) => (++ <Switch++ id="label-refresh-token-rotation"++ onCheckedChange={(isChecked) => onChange(isChecked)}++ isChecked={value}++ >++ Refresh Token Rotation++ </Switch>++ )}++ />++ </div>++ <div className="mt-8 flex items-center">++ <Button++ className="mr-4"++ size="sm"++ type="submit"++ isLoading={isSubmitting}++ isDisabled={isSubmitting}++ >++ {popUp?.serviceTokenV3?.data ? "Update" : "Create"}++ </Button>++ <Button colorSchema="secondary" variant="plain">++ Cancel++ </Button>++ </div>++ </form>++ ) : (++ <div className="mt-2 mb-3 mr-2 flex items-center justify-end rounded-md bg-white/[0.07] p-2 text-base text-gray-400">++ <p className="mr-4 break-all">{newServiceTokenJSON}</p>++ <IconButton++ ariaLabel="copy icon"++ colorSchema="secondary"++ className="group relative"++ onClick={copyTokenToClipboard}>-- {popUp?.serviceTokenV3?.data ? "Update" : "Create"}-- </Button>-- <Button colorSchema="secondary" variant="plain">-- Cancel-- </Button>++ <FontAwesomeIcon icon={isServiceTokenJSONCopied ? faCheck : faCopy} />++ <span className="absolute -left-8 -top-20 hidden w-28 translate-y-full rounded-md bg-bunker-800 py-2 pl-3 text-center text-sm text-gray-400 group-hover:flex group-hover:animate-fadeIn">++ Click to copy++ </span>++ </IconButton></div>-- </form>++ )}<UpgradePlanModalisOpen={popUp?.upgradePlan?.isOpen}onOpenChange={(isOpen) => handlePopUpToggle("upgradePlan", isOpen)}