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(dynamic-secret): Github App Tokens
x032205e7ac783b103c
diff --git a/backend/src/ee/services/dynamic-secret/providers/github.ts b/backend/src/ee/services/dynamic-secret/providers/github.tsnew file mode 100644index 0000000000..9b5f02c783--- /dev/null+++ b/backend/src/ee/services/dynamic-secret/providers/github.ts@@ -0,0 +1,130 @@+import axios from "axios";+import * as jwt from "jsonwebtoken";++import { BadRequestError, InternalServerError } from "@app/lib/errors";+import { alphaNumericNanoId } from "@app/lib/nanoid";+import { IntegrationUrls } from "@app/services/integration-auth/integration-list";++import { DynamicSecretGithubSchema, TDynamicProviderFns } from "./models";++interface GitHubInstallationTokenResponse {+ token: string;+ expires_at: string; // ISO 8601 timestamp e.g., "2024-01-15T12:00:00Z"+ permissions?: Record<string, string>;+ repository_selection?: string;+}++interface TGithubProviderInputs {+ appId: number;+ installationId: number;+ privateKey: string;+}++export const GithubProvider = (): TDynamicProviderFns => {+ const validateProviderInputs = async (inputs: unknown) => {+ const providerInputs = await DynamicSecretGithubSchema.parseAsync(inputs);+ return providerInputs;+ };++ const $generateGitHubInstallationAccessToken = async (+ credentials: TGithubProviderInputs+ ): Promise<GitHubInstallationTokenResponse> => {+ const { appId, installationId, privateKey } = credentials;++ const nowInSeconds = Math.floor(Date.now() / 1000);+ const jwtPayload = {+ iat: nowInSeconds - 60,+ exp: nowInSeconds + 10 * 60 - 60,+ iss: String(appId)+ };++ let appJwt: string;+ try {+ appJwt = jwt.sign(jwtPayload, privateKey, { algorithm: "RS256" });+ } catch (error) {+ let message = "Failed to sign JWT.";+ if (error instanceof jwt.JsonWebTokenError) {+ message += ` JsonWebTokenError: ${error.message}`;+ }+ throw new InternalServerError({+ message+ });+ }++ const tokenUrl = `${IntegrationUrls.GITHUB_API_URL}/app/installations/${String(installationId)}/access_tokens`;++ try {+ const response = await axios.post<GitHubInstallationTokenResponse>(tokenUrl, undefined, {+ headers: {+ Authorization: `Bearer ${appJwt}`,+ Accept: "application/vnd.github.v3+json",+ "X-GitHub-Api-Version": "2022-11-28"+ }+ });++ if (response.status === 201 && response.data.token) {+ return response.data; // Includes token, expires_at, permissions, repository_selection+ }++ throw new InternalServerError({+ message: `GitHub API responded with unexpected status ${response.status}: ${JSON.stringify(response.data)}`+ });+ } catch (error) {+ let message = "Failed to fetch GitHub installation access token.";+ if (axios.isAxiosError(error) && error.response) {+ const githubErrorMsg =+ (error.response.data as { message?: string })?.message || JSON.stringify(error.response.data);+ message += ` GitHub API Error: ${error.response.status} - ${githubErrorMsg}`;++ // Classify as BadRequestError for auth-related issues (401, 403, 404) which might be due to user input+ if ([401, 403, 404].includes(error.response.status)) {+ throw new BadRequestError({ message });+ }+ }++ throw new InternalServerError({ message });+ }+ };++ const validateConnection = async (inputs: unknown) => {+ const providerInputs = await validateProviderInputs(inputs);+ await $generateGitHubInstallationAccessToken(providerInputs);+ return true;+ };++ const create = async (data: { inputs: unknown }) => {+ const { inputs } = data;+ const providerInputs = await validateProviderInputs(inputs);++ const ghTokenData = await $generateGitHubInstallationAccessToken(providerInputs);+ const entityId = alphaNumericNanoId(32);++ return {+ entityId,+ data: {+ TOKEN: ghTokenData.token,+ EXPIRES_AT: ghTokenData.expires_at,+ PERMISSIONS: ghTokenData.permissions,+ REPOSITORY_SELECTION: ghTokenData.repository_selection+ }+ };+ };++ const revoke = async (_inputs: unknown, entityId: string) => {+ // GitHub installation access tokens cannot be revoked.+ return { entityId };+ };++ const renew = async () => {+ // No renewal+ throw new BadRequestError({ message: "Github dynamic secret does not support renewal" });+ };++ return {+ validateProviderInputs,+ validateConnection,+ create,+ revoke,+ renew+ };+};diff --git a/backend/src/ee/services/dynamic-secret/providers/index.ts b/backend/src/ee/services/dynamic-secret/providers/index.tsindex 7e14cf1ab7..7fd65f98db 100644--- a/backend/src/ee/services/dynamic-secret/providers/index.ts+++ b/backend/src/ee/services/dynamic-secret/providers/index.ts@@ -7,6 +7,7 @@ import { AzureEntraIDProvider } from "./azure-entra-id";import { CassandraProvider } from "./cassandra";import { ElasticSearchProvider } from "./elastic-search";import { GcpIamProvider } from "./gcp-iam";+import { GithubProvider } from "./github";import { KubernetesProvider } from "./kubernetes";import { LdapProvider } from "./ldap";import { DynamicSecretProviders, TDynamicProviderFns } from "./models";@@ -44,5 +45,6 @@ export const buildDynamicSecretProviders = ({[DynamicSecretProviders.SapAse]: SapAseProvider(),[DynamicSecretProviders.Kubernetes]: KubernetesProvider({ gatewayService }),[DynamicSecretProviders.Vertica]: VerticaProvider({ gatewayService }),- [DynamicSecretProviders.GcpIam]: GcpIamProvider()+ [DynamicSecretProviders.GcpIam]: GcpIamProvider(),+ [DynamicSecretProviders.Github]: GithubProvider()});diff --git a/backend/src/ee/services/dynamic-secret/providers/models.ts b/backend/src/ee/services/dynamic-secret/providers/models.tsindex 8f361e1664..972c535430 100644--- a/backend/src/ee/services/dynamic-secret/providers/models.ts+++ b/backend/src/ee/services/dynamic-secret/providers/models.ts@@ -474,6 +474,23 @@ export const DynamicSecretGcpIamSchema = z.object({serviceAccountEmail: z.string().email().trim().min(1, "Service account email required").max(128)});+export const DynamicSecretGithubSchema = z.object({+ appId: z.number().min(1).describe("The ID of your GitHub App."),+ installationId: z.number().min(1).describe("The ID of the GitHub App installation."),+ privateKey: z+ .string()+ .trim()+ .min(1)+ .refine(+ (val) =>+ new RE2(+ /^-----BEGIN(?:(?: RSA| PGP| ENCRYPTED)? PRIVATE KEY)-----\s*[\s\S]*?-----END(?:(?: RSA| PGP| ENCRYPTED)? PRIVATE KEY)-----$/+ ).test(val),+ "Invalid PEM format for private key"+ )+ .describe("The private key generated for your GitHub App.")+});+export enum DynamicSecretProviders {SqlDatabase = "sql-database",Cassandra = "cassandra",@@ -492,7 +509,8 @@ export enum DynamicSecretProviders {SapAse = "sap-ase",Kubernetes = "kubernetes",Vertica = "vertica",- GcpIam = "gcp-iam"+ GcpIam = "gcp-iam",+ Github = "github"}export const DynamicSecretProviderSchema = z.discriminatedUnion("type", [@@ -513,7 +531,8 @@ export const DynamicSecretProviderSchema = z.discriminatedUnion("type", [z.object({ type: z.literal(DynamicSecretProviders.Totp), inputs: DynamicSecretTotpSchema }),z.object({ type: z.literal(DynamicSecretProviders.Kubernetes), inputs: DynamicSecretKubernetesSchema }),z.object({ type: z.literal(DynamicSecretProviders.Vertica), inputs: DynamicSecretVerticaSchema }),- z.object({ type: z.literal(DynamicSecretProviders.GcpIam), inputs: DynamicSecretGcpIamSchema })+ z.object({ type: z.literal(DynamicSecretProviders.GcpIam), inputs: DynamicSecretGcpIamSchema }),+ z.object({ type: z.literal(DynamicSecretProviders.Github), inputs: DynamicSecretGithubSchema })]);export type TDynamicProviderFns = {diff --git a/docs/documentation/platform/dynamic-secrets/github.mdx b/docs/documentation/platform/dynamic-secrets/github.mdxnew file mode 100644index 0000000000..9eced246d4--- /dev/null+++ b/docs/documentation/platform/dynamic-secrets/github.mdx@@ -0,0 +1,120 @@+---+title: "Github"+description: "Learn how to dynamically generate Github app tokens."+---++The Infisical Github dynamic secret allows you to generate short-lived tokens for a Github app on demand based on service account permissions.++<Warning>+ Github app tokens cannot be revoked. As such, revoking a token on Infisical does not invalidate the Github token; it remains active until it expires.+</Warning>++<Warning>+ Github app tokens are fixed to a TTL of 1 hour.+</Warning>++## Setup Github App++<Steps>+ <Step title="Create an application on GitHub">+ Navigate to [GitHub app settings](https://github.com/settings/apps) and click **New GitHub App**.++ ++ Give the application a name and a homepage URL. These values do not need to be anything specific.++ Disable webhook by unchecking the Active checkbox.+ ++ Configure the app's permissions to grant the necessary access for the dynamic secret's short-lived tokens.++ Create the Github application.+ ++ <Note>+ If you have a GitHub organization, you can create an application under it+ in your organization Settings > Developer settings > GitHub Apps > New GitHub App.+ </Note>+ </Step>+ <Step title="Save app credentials">+ Copy the **App ID** and generate a new **Private Key** for your Github application.+ ++ Save these for later steps.+ </Step>+ <Step title="Install app">+ Install your application to whichever repositories and organizations that you want the dynamic secret to access.+ ++ ++ Once you've installed the app, **copy the installation ID** from the URL and save it for later steps.+ + </Step>+</Steps>++## Set up Dynamic Secrets with Github++<Steps>+ <Step title="Open Secret Overview Dashboard">+ Open the Secret Overview dashboard and select the environment in which you would like to add a dynamic secret.+ </Step>+ <Step title="Click on the 'Add Dynamic Secret' button">+ + </Step>+ <Step title="Select 'Github'">+ + </Step>+ <Step title="Provide the inputs for dynamic secret parameters">+ <ParamField path="Secret Name" type="string" required>+ Name by which you want the secret to be referenced+ </ParamField>+ <ParamField path="App ID" type="string" required>+ The ID of the app created in earlier steps.+ </ParamField>+ <ParamField path="App Private Key PEM" type="string" required>+ The Private Key of the app created in earlier steps.+ </ParamField>+ <ParamField path="Installation ID" type="string" required>+ The ID of the installation from earlier steps.+ </ParamField>+ </Step>+ <Step title="Click `Submit`">+ After submitting the form, you will see a dynamic secret created in the dashboard.+ </Step>++ <Step title="Generate dynamic secrets">+ Once you've successfully configured the dynamic secret, you're ready to generate on-demand credentials.+ To do this, simply click on the 'Generate' button which appears when hovering over the dynamic secret item.+ Alternatively, you can initiate the creation of a new lease by selecting 'New Lease' from the dynamic secret lease list section.++ + ++ When generating these secrets, the TTL will be fixed to 1 hour.++ ++ Once you click the `Submit` button, a new secret lease will be generated and the credentials from it will be shown to you.++ + </Step>+</Steps>++## Audit or Revoke Leases++Once you have created one or more leases, you will be able to access them by clicking on the respective dynamic secret item on the dashboard.++This will allow you to see the expiration time of the lease or delete a lease before its set time to live.++++<Warning>+ Github app tokens cannot be revoked. As such, revoking a token on Infisical does not invalidate the Github token; it remains active until it expires.+</Warning>++## Renew Leases++<Warning>+ Github app tokens cannot be renewed because they are fixed to a lifetime of 1 hour.+</Warning>diff --git a/docs/images/platform/dynamic-secrets/github/install-app-modal.png b/docs/images/platform/dynamic-secrets/github/install-app-modal.pngnew file mode 100644index 0000000000..f3aa1c51dbBinary files /dev/null and b/docs/images/platform/dynamic-secrets/github/install-app-modal.png differdiff --git a/docs/images/platform/dynamic-secrets/github/install-app.png b/docs/images/platform/dynamic-secrets/github/install-app.pngnew file mode 100644index 0000000000..7be3d6c1b0Binary files /dev/null and b/docs/images/platform/dynamic-secrets/github/install-app.png differdiff --git a/docs/images/platform/dynamic-secrets/github/installation.png b/docs/images/platform/dynamic-secrets/github/installation.pngnew file mode 100644index 0000000000..61a06ec048Binary files /dev/null and b/docs/images/platform/dynamic-secrets/github/installation.png differdiff --git a/docs/images/platform/dynamic-secrets/github/lease.png b/docs/images/platform/dynamic-secrets/github/lease.pngnew file mode 100644index 0000000000..4ce6028986Binary files /dev/null and b/docs/images/platform/dynamic-secrets/github/lease.png differdiff --git a/docs/images/platform/dynamic-secrets/github/modal.png b/docs/images/platform/dynamic-secrets/github/modal.pngnew file mode 100644index 0000000000..9ac7743a81Binary files /dev/null and b/docs/images/platform/dynamic-secrets/github/modal.png differdiff --git a/docs/mint.json b/docs/mint.jsonindex c6d657d66f..3a5eda6354 100644--- a/docs/mint.json+++ b/docs/mint.json@@ -214,6 +214,7 @@"documentation/platform/dynamic-secrets/cassandra","documentation/platform/dynamic-secrets/elastic-search","documentation/platform/dynamic-secrets/gcp-iam",+ "documentation/platform/dynamic-secrets/github","documentation/platform/dynamic-secrets/ldap","documentation/platform/dynamic-secrets/mongo-atlas","documentation/platform/dynamic-secrets/mongo-db",diff --git a/frontend/src/components/features/TtlFormLabel.tsx b/frontend/src/components/features/TtlFormLabel.tsxindex 02f1622008..fdb9aea5ec 100644--- a/frontend/src/components/features/TtlFormLabel.tsx+++ b/frontend/src/components/features/TtlFormLabel.tsx@@ -26,7 +26,7 @@ export const TtlFormLabel = ({ label }: { label: string }) => (<FontAwesomeIconicon={faQuestionCircle}size="sm"- className="relative bottom-1 right-1"+ className="relative bottom-px right-1"/></Tooltip>}diff --git a/frontend/src/hooks/api/dynamicSecret/types.ts b/frontend/src/hooks/api/dynamicSecret/types.tsindex e8d80e6323..932f4f1a65 100644--- a/frontend/src/hooks/api/dynamicSecret/types.ts+++ b/frontend/src/hooks/api/dynamicSecret/types.ts@@ -12,7 +12,7 @@ export type TDynamicSecret = {defaultTTL: string;status?: DynamicSecretStatus;statusDetails?: string;- maxTTL: string;+ maxTTL?: string;usernameTemplate?: string | null;metadata?: { key: string; value: string }[];};@@ -35,7 +35,8 @@ export enum DynamicSecretProviders {SapAse = "sap-ase",Kubernetes = "kubernetes",Vertica = "vertica",- GcpIam = "gcp-iam"+ GcpIam = "gcp-iam",+ Github = "github"}export enum KubernetesDynamicSecretCredentialType {@@ -333,6 +334,14 @@ export type TDynamicSecretProvider =inputs: {serviceAccountEmail: string;};+ }+ | {+ type: DynamicSecretProviders.Github;+ inputs: {+ appId: number;+ installationId: number;+ privateKey: string;+ };};export type TCreateDynamicSecretDTO = {diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/CreateDynamicSecretForm.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/CreateDynamicSecretForm.tsxindex f673421900..1d3b77d00c 100644--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/CreateDynamicSecretForm.tsx+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/CreateDynamicSecretForm.tsx@@ -11,7 +11,7 @@ import {SiSnowflake} from "react-icons/si";import { VscAzure } from "react-icons/vsc";-import { faAws, faGoogle } from "@fortawesome/free-brands-svg-icons";+import { faAws, faGithub, faGoogle } from "@fortawesome/free-brands-svg-icons";import { faClock, faDatabase } from "@fortawesome/free-solid-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";import { AnimatePresence, motion } from "framer-motion";@@ -38,6 +38,7 @@ import { SnowflakeInputForm } from "./SnowflakeInputForm";import { SqlDatabaseInputForm } from "./SqlDatabaseInputForm";import { TotpInputForm } from "./TotpInputForm";import { VerticaInputForm } from "./VerticaInputForm";+import { GithubInputForm } from "./GithubInputForm";type Props = {isOpen?: boolean;@@ -143,6 +144,11 @@ const DYNAMIC_SECRET_LIST = [icon: <FontAwesomeIcon icon={faGoogle} size="lg" />,provider: DynamicSecretProviders.GcpIam,title: "GCP IAM"+ },+ {+ icon: <FontAwesomeIcon icon={faGithub} size="lg" />,+ provider: DynamicSecretProviders.Github,+ title: "Github"}];@@ -548,6 +554,25 @@ export const CreateDynamicSecretForm = ({/></motion.div>)}+ {wizardStep === WizardSteps.ProviderInputs &&+ selectedProvider === DynamicSecretProviders.Github && (+ <motion.div+ key="dynamic-github-step"+ transition={{ duration: 0.1 }}+ initial={{ opacity: 0, translateX: 30 }}+ animate={{ opacity: 1, translateX: 0 }}+ exit={{ opacity: 0, translateX: -30 }}+ >+ <GithubInputForm+ onCompleted={handleFormReset}+ onCancel={handleFormReset}+ projectSlug={projectSlug}+ secretPath={secretPath}+ environments={environments}+ isSingleEnvironmentMode={isSingleEnvironmentMode}+ />+ </motion.div>+ )}</AnimatePresence></ModalContent></Modal>diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/GithubInputForm.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/GithubInputForm.tsxnew file mode 100644index 0000000000..34620280f5--- /dev/null+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/GithubInputForm.tsx@@ -0,0 +1,234 @@+import { Controller, useForm } from "react-hook-form";+import { zodResolver } from "@hookform/resolvers/zod";+import { z } from "zod";++import { createNotification } from "@app/components/notifications";+import {+ Button,+ FilterableSelect,+ FormControl,+ FormLabel,+ Input,+ SecretInput,+ Tooltip+} from "@app/components/v2";+import { useCreateDynamicSecret } from "@app/hooks/api";+import { DynamicSecretProviders } from "@app/hooks/api/dynamicSecret/types";+import { WorkspaceEnv } from "@app/hooks/api/types";+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";+import { faQuestionCircle } from "@fortawesome/free-solid-svg-icons";++const formSchema = z.object({+ provider: z.object({+ appId: z.coerce.number().min(1, "Required"),+ installationId: z.coerce.number().min(1, "Required"),+ privateKey: z+ .string()+ .trim()+ .min(1, "Required")+ .refine(+ (val) =>+ /^-----BEGIN(?:(?: RSA| PGP| ENCRYPTED)? PRIVATE KEY)-----\s*[\s\S]*?-----END(?:(?: RSA| PGP| ENCRYPTED)? PRIVATE KEY)-----$/.test(+ val+ ),+ "Invalid PEM format for private key"+ )+ }),+ name: z.string().refine((val) => val.toLowerCase() === val, "Must be lowercase"),+ environment: z.object({ name: z.string(), slug: z.string() })+});+type TForm = z.infer<typeof formSchema>;++type Props = {+ onCompleted: () => void;+ onCancel: () => void;+ secretPath: string;+ projectSlug: string;+ environments: WorkspaceEnv[];+ isSingleEnvironmentMode?: boolean;+};++export const GithubInputForm = ({+ onCompleted,+ onCancel,+ environments,+ secretPath,+ projectSlug,+ isSingleEnvironmentMode+}: Props) => {+ const {+ control,+ formState: { isSubmitting },+ handleSubmit+ } = useForm<TForm>({+ resolver: zodResolver(formSchema),+ defaultValues: {+ environment: isSingleEnvironmentMode && environments.length > 0 ? environments[0] : undefined+ }+ });++ const createDynamicSecret = useCreateDynamicSecret();++ const handleCreateDynamicSecret = async ({ name, provider, environment }: TForm) => {+ if (createDynamicSecret.isPending) return;+ try {+ await createDynamicSecret.mutateAsync({+ provider: {+ type: DynamicSecretProviders.Github,+ inputs: {+ ...provider+ }+ },+ defaultTTL: "1h", // Github is limited to 1 hour tokens+ name,+ path: secretPath,+ projectSlug,+ environmentSlug: environment.slug+ });+ onCompleted();+ } catch {+ createNotification({+ type: "error",+ text: "Failed to create dynamic secret"+ });+ }+ };++ return (+ <div>+ <form onSubmit={handleSubmit(handleCreateDynamicSecret)} autoComplete="off">+ <div>+ <div className="flex items-center space-x-2">+ <div className="flex-grow">+ <Controller+ control={control}+ defaultValue=""+ name="name"+ render={({ field, fieldState: { error } }) => (+ <FormControl+ label="Secret Name"+ isError={Boolean(error)}+ errorText={error?.message}+ >+ <Input {...field} placeholder="dynamic-secret" />+ </FormControl>+ )}+ />+ </div>+ <div className="w-32">+ <FormControl+ label={+ <FormLabel+ label="Default TTL"+ icon={+ <Tooltip content="Github token TTL is fixed to 1 hour">+ <FontAwesomeIcon+ icon={faQuestionCircle}+ size="sm"+ className="relative bottom-px right-1"+ />+ </Tooltip>+ }+ />+ }+ >+ <Input disabled value="1h" className="pointer-events-none opacity-50" />+ </FormControl>+ </div>+ </div>+ <div>+ <div className="mb-4 mt-4 border-b border-mineshaft-500 pb-2 pl-1 font-medium text-mineshaft-200">+ Configuration+ </div>++ <div className="flex flex-col">+ <Controller+ control={control}+ name="provider.appId"+ render={({ field, fieldState: { error } }) => (+ <FormControl+ label="App ID"+ className="flex-grow"+ isError={Boolean(error?.message)}+ errorText={error?.message}+ isRequired+ >+ <Input placeholder="0000000" {...field} />+ </FormControl>+ )}+ />++ <Controller+ control={control}+ name="provider.installationId"+ render={({ field, fieldState: { error } }) => (+ <FormControl+ label="Installation ID"+ className="flex-grow"+ isError={Boolean(error?.message)}+ errorText={error?.message}+ isRequired+ >+ <Input placeholder="00000000" {...field} />+ </FormControl>+ )}+ />++ <Controller+ control={control}+ name="provider.privateKey"+ render={({ field, fieldState: { error } }) => (+ <FormControl+ label="App Private Key PEM"+ className="flex-grow"+ isError={Boolean(error?.message)}+ errorText={error?.message}+ isRequired+ >+ <SecretInput+ {...field}+ containerClassName="text-gray-400 group-focus-within:!border-primary-400/50 border border-mineshaft-500 bg-mineshaft-900 px-2.5 py-1.5"+ />+ </FormControl>+ )}+ />+ </div>++ {!isSingleEnvironmentMode && (+ <Controller+ control={control}+ name="environment"+ render={({ field: { value, onChange }, fieldState: { error } }) => (+ <FormControl+ label="Environment"+ isError={Boolean(error)}+ errorText={error?.message}+ >+ <FilterableSelect+ options={environments}+ value={value}+ onChange={onChange}+ placeholder="Select the environment to create secret in..."+ getOptionLabel={(option) => option.name}+ getOptionValue={(option) => option.slug}+ menuPlacement="top"+ />+ </FormControl>+ )}+ />+ )}+ </div>+ </div>++ <div className="mt-4 flex items-center space-x-4">+ <Button type="submit" isLoading={isSubmitting}>+ Submit+ </Button>+ <Button variant="outline_bg" onClick={onCancel}>+ Cancel+ </Button>+ </div>+ </form>+ </div>+ );+};diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/CreateDynamicSecretLease.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/CreateDynamicSecretLease.tsxindex 1bdf946652..4f41add4e6 100644--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/CreateDynamicSecretLease.tsx+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/CreateDynamicSecretLease.tsx@@ -368,6 +368,22 @@ const renderOutputForm = ();}+ if (provider === DynamicSecretProviders.Github) {+ const { TOKEN } = data as {+ TOKEN: string;+ };++ return (+ <div>+ <OutputDisplay+ label="Token"+ value={TOKEN}+ helperText="Important: Copy these credentials now. You will not be able to see them again after you close the modal."+ />+ </div>+ );+ }+return null;};@@ -608,6 +624,8 @@ export const CreateDynamicSecretLease = ({return <Spinner className="mx-auto h-40 text-mineshaft-700" />;}+ const fixedTtl = provider === DynamicSecretProviders.Github;+return (<div><AnimatePresence>@@ -629,8 +647,11 @@ export const CreateDynamicSecretLease = ({label={<TtlFormLabel label="Default TTL" />}isError={Boolean(error?.message)}errorText={error?.message}+ helperText={+ fixedTtl ? `This provider has a fixed TTL of ${field.value}` : undefined+ }>- <Input {...field} />+ <Input {...field} isDisabled={fixedTtl} /></FormControl>)}/>diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/DynamicSecretLease.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/DynamicSecretLease.tsxindex 49c38b2ebc..0e19ecbb5e 100644--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/DynamicSecretLease.tsx+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/DynamicSecretLease.tsx@@ -29,7 +29,7 @@ import {import { ProjectPermissionDynamicSecretActions, ProjectPermissionSub } from "@app/context";import { usePopUp } from "@app/hooks";import { useGetDynamicSecretLeases, useRevokeDynamicSecretLease } from "@app/hooks/api";-import { TDynamicSecret } from "@app/hooks/api/dynamicSecret/types";+import { DynamicSecretProviders, TDynamicSecret } from "@app/hooks/api/dynamicSecret/types";import { DynamicSecretLeaseStatus } from "@app/hooks/api/dynamicSecretLease/types";import { RenewDynamicSecretLease } from "./RenewDynamicSecretLease";@@ -44,6 +44,8 @@ type Props = {onClose: () => void;};+const DYNAMIC_SECRETS_WITHOUT_RENEWAL = [DynamicSecretProviders.Github];+export const DynamicSecretLease = ({projectSlug,dynamicSecretName,@@ -94,6 +96,8 @@ export const DynamicSecretLease = ({}};+ const canRenew = !DYNAMIC_SECRETS_WITHOUT_RENEWAL.includes(dynamicSecret.type);+return (<div><TableContainer>@@ -141,29 +145,31 @@ export const DynamicSecretLease = ({</Td><Td><div className="flex items-center space-x-4">- <ProjectPermissionCan- I={ProjectPermissionDynamicSecretActions.Lease}- a={subject(ProjectPermissionSub.DynamicSecrets, {- environment,- secretPath,- metadata: dynamicSecret.metadata- })}- renderTooltip- allowedLabel="Renew"- >- {(isAllowed) => (- <IconButton- ariaLabel="edit-folder"- variant="plain"- size="sm"- className="p-0"- isDisabled={!isAllowed}- onClick={() => handlePopUpOpen("renewSecret", { leaseId: id })}- >- <FontAwesomeIcon icon={faRepeat} size="lg" />- </IconButton>- )}- </ProjectPermissionCan>+ {canRenew && (+ <ProjectPermissionCan+ I={ProjectPermissionDynamicSecretActions.Lease}+ a={subject(ProjectPermissionSub.DynamicSecrets, {+ environment,+ secretPath,+ metadata: dynamicSecret.metadata+ })}+ renderTooltip+ allowedLabel="Renew"+ >+ {(isAllowed) => (+ <IconButton+ ariaLabel="edit-folder"+ variant="plain"+ size="sm"+ className="p-0"+ isDisabled={!isAllowed}+ onClick={() => handlePopUpOpen("renewSecret", { leaseId: id })}+ >+ <FontAwesomeIcon icon={faRepeat} size="lg" />+ </IconButton>+ )}+ </ProjectPermissionCan>+ )}<ProjectPermissionCanI={ProjectPermissionDynamicSecretActions.Lease}a={subject(ProjectPermissionSub.DynamicSecrets, {diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretForm.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretForm.tsxindex 11589d5310..b839cf7985 100644--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretForm.tsx+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretForm.tsx@@ -22,6 +22,7 @@ import { EditDynamicSecretSnowflakeForm } from "./EditDynamicSecretSnowflakeFormimport { EditDynamicSecretSqlProviderForm } from "./EditDynamicSecretSqlProviderForm";import { EditDynamicSecretTotpForm } from "./EditDynamicSecretTotpForm";import { EditDynamicSecretVerticaForm } from "./EditDynamicSecretVertica";+import { EditDynamicSecretGithubForm } from "./EditDynamicSecretGithubForm";type Props = {onClose: () => void;@@ -366,6 +367,23 @@ export const EditDynamicSecretForm = ({/></motion.div>)}+ {dynamicSecretDetails?.type === DynamicSecretProviders.Github && (+ <motion.div+ key="github-edit"+ transition={{ duration: 0.1 }}+ initial={{ opacity: 0, translateX: 30 }}+ animate={{ opacity: 1, translateX: 0 }}+ exit={{ opacity: 0, translateX: -30 }}+ >+ <EditDynamicSecretGithubForm+ onClose={onClose}+ projectSlug={projectSlug}+ secretPath={secretPath}+ dynamicSecret={dynamicSecretDetails}+ environment={environment}+ />+ </motion.div>+ )}</AnimatePresence>);};diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretGithubForm.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretGithubForm.tsxnew file mode 100644index 0000000000..f29566625a--- /dev/null+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretGithubForm.tsx@@ -0,0 +1,199 @@+import { Controller, useForm } from "react-hook-form";+import { zodResolver } from "@hookform/resolvers/zod";+import { z } from "zod";++import { createNotification } from "@app/components/notifications";+import { Button, FormControl, FormLabel, Input, SecretInput, Tooltip } from "@app/components/v2";+import { useUpdateDynamicSecret } from "@app/hooks/api";+import { TDynamicSecret } from "@app/hooks/api/dynamicSecret/types";+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";+import { faQuestionCircle } from "@fortawesome/free-solid-svg-icons";++const formSchema = z.object({+ inputs: z.object({+ appId: z.coerce.number().min(1, "Required"),+ installationId: z.coerce.number().min(1, "Required"),+ privateKey: z+ .string()+ .trim()+ .min(1, "Required")+ .refine(+ (val) =>+ /^-----BEGIN(?:(?: RSA| PGP| ENCRYPTED)? PRIVATE KEY)-----\s*[\s\S]*?-----END(?:(?: RSA| PGP| ENCRYPTED)? PRIVATE KEY)-----$/.test(+ val+ ),+ "Invalid PEM format for private key"+ )+ }),+ newName: z.string().refine((val) => val.toLowerCase() === val, "Must be lowercase")+});+type TForm = z.infer<typeof formSchema>;++type Props = {+ onClose: () => void;+ dynamicSecret: TDynamicSecret & { inputs: unknown };+ secretPath: string;+ environment: string;+ projectSlug: string;+};+export const EditDynamicSecretGithubForm = ({+ onClose,+ dynamicSecret,+ secretPath,+ environment,+ projectSlug+}: Props) => {+ const {+ control,+ formState: { isSubmitting },+ handleSubmit+ } = useForm<TForm>({+ resolver: zodResolver(formSchema),+ values: {+ newName: dynamicSecret.name,+ inputs: {+ ...(dynamicSecret.inputs as TForm["inputs"])+ }+ }+ });++ const updateDynamicSecret = useUpdateDynamicSecret();++ const handleUpdateDynamicSecret = async ({ inputs, newName }: TForm) => {+ if (updateDynamicSecret.isPending) return;+ try {+ await updateDynamicSecret.mutateAsync({+ name: dynamicSecret.name,+ path: secretPath,+ projectSlug,+ environmentSlug: environment,+ data: {+ inputs,+ newName: newName === dynamicSecret.name ? undefined : newName+ }+ });+ onClose();+ createNotification({+ type: "success",+ text: "Successfully updated dynamic secret"+ });+ } catch {+ createNotification({+ type: "error",+ text: "Failed to update dynamic secret"+ });+ }+ };++ return (+ <div>+ <form onSubmit={handleSubmit(handleUpdateDynamicSecret)} autoComplete="off">+ <div>+ <div className="flex items-center space-x-2">+ <div className="flex-grow">+ <Controller+ control={control}+ name="newName"+ render={({ field, fieldState: { error } }) => (+ <FormControl+ label="Secret Name"+ isError={Boolean(error)}+ errorText={error?.message}+ >+ <Input {...field} placeholder="dynamic-secret" />+ </FormControl>+ )}+ />+ </div>+ <div className="w-32">+ <FormControl+ label={+ <FormLabel+ label="Default TTL"+ icon={+ <Tooltip content="Github token TTL is fixed to 1 hour">+ <FontAwesomeIcon+ icon={faQuestionCircle}+ size="sm"+ className="relative bottom-px right-1"+ />+ </Tooltip>+ }+ />+ }+ >+ <Input disabled value="1h" className="pointer-events-none opacity-50" />+ </FormControl>+ </div>+ </div>+ <div>+ <div className="mb-4 mt-4 border-b border-mineshaft-500 pb-2 pl-1 font-medium text-mineshaft-200">+ Configuration+ </div>++ <div className="flex flex-col">+ <Controller+ control={control}+ name="inputs.appId"+ render={({ field, fieldState: { error } }) => (+ <FormControl+ label="App ID"+ className="flex-grow"+ isError={Boolean(error?.message)}+ errorText={error?.message}+ isRequired+ >+ <Input placeholder="0000000" {...field} />+ </FormControl>+ )}+ />++ <Controller+ control={control}+ name="inputs.installationId"+ render={({ field, fieldState: { error } }) => (+ <FormControl+ label="Installation ID"+ className="flex-grow"+ isError={Boolean(error?.message)}+ errorText={error?.message}+ isRequired+ >+ <Input placeholder="00000000" {...field} />+ </FormControl>+ )}+ />++ <Controller+ control={control}+ name="inputs.privateKey"+ render={({ field, fieldState: { error } }) => (+ <FormControl+ label="App Private Key PEM"+ className="flex-grow"+ isError={Boolean(error?.message)}+ errorText={error?.message}+ isRequired+ >+ <SecretInput+ {...field}+ containerClassName="text-gray-400 group-focus-within:!border-primary-400/50 border border-mineshaft-500 bg-mineshaft-900 px-2.5 py-1.5"+ />+ </FormControl>+ )}+ />+ </div>+ </div>+ </div>+ <div className="mt-4 flex items-center space-x-4">+ <Button type="submit" isLoading={isSubmitting}>+ Submit+ </Button>+ <Button variant="outline_bg" onClick={onClose}>+ Cancel+ </Button>+ </div>+ </form>+ </div>+ );+};diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/RenewDynamicSecretLease.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/RenewDynamicSecretLease.tsxindex 9cee0a671c..f9e91ffd0b 100644--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/RenewDynamicSecretLease.tsx+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/RenewDynamicSecretLease.tsx@@ -7,7 +7,7 @@ import { TtlFormLabel } from "@app/components/features";import { createNotification } from "@app/components/notifications";import { Button, FormControl, Input } from "@app/components/v2";import { useRenewDynamicSecretLease } from "@app/hooks/api";-import { TDynamicSecret } from "@app/hooks/api/dynamicSecret/types";+import { DynamicSecretProviders, TDynamicSecret } from "@app/hooks/api/dynamicSecret/types";type Props = {onClose: () => void;@@ -28,7 +28,7 @@ export const RenewDynamicSecretLease = ({environment,dynamicSecret}: Props) => {- const maxTtlMs = ms(dynamicSecret.maxTTL);+ const maxTtlMs = dynamicSecret.maxTTL ? ms(dynamicSecret.maxTTL) : undefined;const formSchema = z.object({ttl: z.string().superRefine((val, ctx) => {@@ -39,7 +39,7 @@ export const RenewDynamicSecretLease = ({code: z.ZodIssueCode.custom,message: "TTL must be greater than 1 second"});- if (valMs > maxTtlMs)+ if (maxTtlMs && valMs > maxTtlMs)ctx.addIssue({code: z.ZodIssueCode.custom,message: `TTL must be less than ${dynamicSecret.maxTTL}`