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(databricks): allow configuring connection oauth scopes
DimitrisStaratzisfd69cb3e3027
diff --git a/backend/src/services/app-connection/databricks/databricks-connection-enums.ts b/backend/src/services/app-connection/databricks/databricks-connection-enums.tsindex b65161e458..fe2598dc59 100644--- a/backend/src/services/app-connection/databricks/databricks-connection-enums.ts+++ b/backend/src/services/app-connection/databricks/databricks-connection-enums.ts@@ -1,3 +1,9 @@export enum DatabricksConnectionMethod {ServicePrincipal = "service-principal"}++export enum DatabricksConnectionScope {+ Secrets = "secrets",+ Authentication = "authentication",+ Scim = "scim"+}diff --git a/backend/src/services/app-connection/databricks/databricks-connection-fns.ts b/backend/src/services/app-connection/databricks/databricks-connection-fns.tsindex a9128ec517..92d0ef129f 100644--- a/backend/src/services/app-connection/databricks/databricks-connection-fns.ts+++ b/backend/src/services/app-connection/databricks/databricks-connection-fns.ts@@ -1,3 +1,5 @@+import { AxiosError } from "axios";+import { request } from "@app/lib/config/request";import { BadRequestError } from "@app/lib/errors";import { removeTrailingSlash } from "@app/lib/fn";@@ -25,13 +27,14 @@ export const getDatabricksConnectionListItem = () => {const authorizeDatabricksConnection = async ({clientId,clientSecret,- workspaceUrl-}: Pick<TDatabricksConnection["credentials"], "workspaceUrl" | "clientId" | "clientSecret">) => {+ workspaceUrl,+ scopes+}: Pick<TDatabricksConnection["credentials"], "workspaceUrl" | "clientId" | "clientSecret" | "scopes">) => {await blockLocalAndPrivateIpAddresses(workspaceUrl);const { data } = await request.post<TAuthorizeDatabricksConnection>(`${removeTrailingSlash(workspaceUrl)}/oidc/v1/token`,- "grant_type=client_credentials&scope=all-apis",+ new URLSearchParams({ grant_type: "client_credentials", scope: scopes?.join(" ") || "all-apis" }),{auth: {username: clientId,@@ -51,14 +54,14 @@ export const getDatabricksConnectionAccessToken = async (appConnectionDAL: Pick<TAppConnectionDALFactory, "updateById">,kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">) => {- const { clientSecret, clientId, workspaceUrl, accessToken, expiresAt } = credentials;+ const { accessToken, expiresAt } = credentials;// get new token if less than 10 minutes from expiryif (Date.now() < expiresAt - 10_000) {return accessToken;}- const authData = await authorizeDatabricksConnection({ clientId, clientSecret, workspaceUrl });+ const authData = await authorizeDatabricksConnection(credentials);const updatedCredentials: TDatabricksConnection["credentials"] = {...credentials,@@ -90,7 +93,10 @@ export const validateDatabricksConnectionCredentials = async (appConnection: TDa};} catch (e: unknown) {throw new BadRequestError({- message: "Unable to validate connection: verify credentials"+ message: `Unable to validate connection: ${+ (e instanceof AxiosError && (e.response?.data as { error_description?: string })?.error_description) ||+ "verify credentials"+ }`});}};diff --git a/backend/src/services/app-connection/databricks/databricks-connection-schemas.ts b/backend/src/services/app-connection/databricks/databricks-connection-schemas.tsindex ac0f1e830d..9c353070aa 100644--- a/backend/src/services/app-connection/databricks/databricks-connection-schemas.ts+++ b/backend/src/services/app-connection/databricks/databricks-connection-schemas.ts@@ -9,12 +9,17 @@ import {} from "@app/services/app-connection/app-connection-schemas";import { APP_CONNECTION_NAME_MAP } from "../app-connection-maps";-import { DatabricksConnectionMethod } from "./databricks-connection-enums";+import { DatabricksConnectionMethod, DatabricksConnectionScope } from "./databricks-connection-enums";export const DatabricksConnectionServicePrincipalInputCredentialsSchema = z.object({clientId: z.string().trim().min(1, "Client ID required"),clientSecret: z.string().trim().min(1, "Client Secret required"),- workspaceUrl: z.string().trim().url().min(1, "Workspace URL required")+ workspaceUrl: z.string().trim().url().min(1, "Workspace URL required"),+ scopes: z+ .nativeEnum(DatabricksConnectionScope)+ .array()+ .max(Object.values(DatabricksConnectionScope).length)+ .optional()});const DatabricksConnectionServicePrincipalOutputCredentialsSchema = z@@ -41,7 +46,8 @@ export const SanitizedDatabricksConnectionSchema = z.discriminatedUnion("method"method: z.literal(DatabricksConnectionMethod.ServicePrincipal),credentials: DatabricksConnectionServicePrincipalOutputCredentialsSchema.pick({clientId: true,- workspaceUrl: true+ workspaceUrl: true,+ scopes: true})}).describe(JSON.stringify({ title: `${APP_CONNECTION_NAME_MAP[AppConnection.Databricks]} (Service Principal)` }))]);diff --git a/docs/snippets/app-connections/databricks/form-fields.mdx b/docs/snippets/app-connections/databricks/form-fields.mdxindex 7740f7e1e0..42ef574ecb 100644--- a/docs/snippets/app-connections/databricks/form-fields.mdx+++ b/docs/snippets/app-connections/databricks/form-fields.mdx@@ -3,3 +3,4 @@- **Workspace URL**: The URL of your Databricks workspace.- **Client ID**: The Client ID of the Databricks service principal created for Infisical.- **Client Secret**: The [secret generated](#generate-a-secret) for that service principal.+- **Scopes** (optional): The OAuth scopes assigned to that secret: `secrets` for secret syncs, and `authentication` and `scim` for secret rotations (defaults to `all-apis`).diff --git a/frontend/src/hooks/api/appConnections/types/databricks-connection.ts b/frontend/src/hooks/api/appConnections/types/databricks-connection.tsindex 56774f9dda..8a3457d34f 100644--- a/frontend/src/hooks/api/appConnections/types/databricks-connection.ts+++ b/frontend/src/hooks/api/appConnections/types/databricks-connection.ts@@ -5,11 +5,18 @@ export enum DatabricksConnectionMethod {ServicePrincipal = "service-principal"}+export enum DatabricksConnectionScope {+ Secrets = "secrets",+ Authentication = "authentication",+ Scim = "scim"+}+export type TDatabricksConnection = TRootAppConnection & { app: AppConnection.Databricks } & {method: DatabricksConnectionMethod.ServicePrincipal;credentials: {workspaceUrl: string;clientId: string;clientSecret: string;+ scopes?: DatabricksConnectionScope[];};};diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/DatabricksConnectionForm.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/DatabricksConnectionForm.tsxindex f855b924f5..1c9907118f 100644--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/DatabricksConnectionForm.tsx+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/DatabricksConnectionForm.tsx@@ -4,6 +4,7 @@ import { Info } from "lucide-react";import { z } from "zod";import {+ Combobox,Field,FieldError,FieldLabel,@@ -22,6 +23,7 @@ import { APP_CONNECTION_MAP, getAppConnectionMethodDetails } from "@app/helpers/import { AppConnection } from "@app/hooks/api/appConnections/enums";import {DatabricksConnectionMethod,+ DatabricksConnectionScope,TDatabricksConnection} from "@app/hooks/api/appConnections/types/databricks-connection";@@ -46,7 +48,8 @@ const formSchema = z.discriminatedUnion("method", [credentials: z.object({workspaceUrl: z.string().url().trim().min(1, "Workspace URL required"),clientId: z.string().trim().min(1, "Client ID required"),- clientSecret: z.string().trim().min(1, "Client secret required")+ clientSecret: z.string().trim().min(1, "Client secret required"),+ scopes: z.nativeEnum(DatabricksConnectionScope).array().optional()})})]);@@ -158,6 +161,40 @@ export const DatabricksConnectionForm = ({ appConnection, onSubmit }: Props) =></Field>)}/>+ <Controller+ name="credentials.scopes"+ control={control}+ shouldUnregister+ render={({ field: { value, onChange }, fieldState: { error } }) => (+ <Field className="mb-4">+ <FieldLabel htmlFor="scopes">+ Scopes <span className="text-muted">(optional)</span>+ <Tooltip>+ <TooltipTrigger asChild>+ <Info />+ </TooltipTrigger>+ <TooltipContent className="max-w-sm">+ The OAuth scopes assigned to the client secret. Secret syncs require+ 'secrets', and secret rotations require 'authentication' and+ 'scim'. If none are selected, 'all-apis' will be used.+ </TooltipContent>+ </Tooltip>+ </FieldLabel>+ <Combobox+ id="scopes"+ multiple+ value={value ?? []}+ onValueChange={onChange}+ options={Object.values(DatabricksConnectionScope)}+ getOptionValue={(scope) => scope}+ getOptionLabel={(scope) => scope}+ placeholder="all-apis"+ isError={Boolean(error)}+ />+ <FieldError errors={[error]} />+ </Field>+ )}+ /><AppConnectionFormFootersubmitLabel={isUpdate ? "Update Credentials" : "Connect to Databricks"}/>