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: add support for access tokens in datadog app connection
adilson447d8c2b9d1c
diff --git a/backend/src/ee/services/secret-rotation-v2/datadog-application-key-secret/datadog-application-key-secret-rotation-fns.ts b/backend/src/ee/services/secret-rotation-v2/datadog-application-key-secret/datadog-application-key-secret-rotation-fns.tsindex 943565e117..11514f88fa 100644--- a/backend/src/ee/services/secret-rotation-v2/datadog-application-key-secret/datadog-application-key-secret-rotation-fns.ts+++ b/backend/src/ee/services/secret-rotation-v2/datadog-application-key-secret/datadog-application-key-secret-rotation-fns.ts@@ -42,7 +42,7 @@ export const datadogApplicationKeySecretRotationFactory: TRotationFactory<secretsMapping} = secretRotation;- const authHeaders = getDatadogAuthHeaders(connection.credentials);+ const authHeaders = getDatadogAuthHeaders(connection);const $createApplicationKey = async () => {const baseUrl = await getDatadogBaseUrl(connection);@@ -164,7 +164,7 @@ export const datadogApplicationKeySecretRotationFactory: TRotationFactory<try {await request.get(`${baseUrl}/api/v2/permissions`, {- headers: { "DD-API-KEY": connection.credentials.apiKey, "DD-APPLICATION-KEY": applicationKey }+ headers: { ...getDatadogAuthHeaders(connection), "DD-APPLICATION-KEY": applicationKey }});} catch (error: unknown) {if (error instanceof BadRequestError) throw error;diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.tsindex bdab71e86e..123c8c9ae1 100644--- a/backend/src/lib/api-docs/constants.ts+++ b/backend/src/lib/api-docs/constants.ts@@ -2961,7 +2961,8 @@ export const AppConnections = {DATADOG: {url: "The Datadog site URL to connect to (e.g., 'https://api.datadoghq.com').",apiKey: "The Datadog API key used to authenticate.",- applicationKey: "The Datadog Application key used to authenticate."+ applicationKey: "The Datadog Application key used to authenticate.",+ token: "The Datadog API token used to authenticate."},SSH: {host: "The hostname or IP address of the SSH server.",diff --git a/backend/src/services/app-connection/app-connection-fns.ts b/backend/src/services/app-connection/app-connection-fns.tsindex abeda2af23..4b91466dac 100644--- a/backend/src/services/app-connection/app-connection-fns.ts+++ b/backend/src/services/app-connection/app-connection-fns.ts@@ -694,6 +694,7 @@ export const getAppConnectionMethodName = (method: TAppConnection["method"]) =>case CircleCIConnectionMethod.ApiToken:case TravisCIConnectionMethod.ApiToken:case RundeckConnectionMethod.ApiToken:+ case DatadogConnectionMethod.Token:return "API Token";case DNSMadeEasyConnectionMethod.APIKeySecret:return "API Key & Secret";@@ -742,10 +743,11 @@ export const getAppConnectionMethodName = (method: TAppConnection["method"]) =>case FireworksConnectionMethod.ApiKey:case DevinConnectionMethod.ApiKey:case DigiCertConnectionMethod.ApiKey:- case DatadogConnectionMethod.ApiKey:case GoDaddyConnectionMethod.ApiKey:case TriggerDevConnectionMethod.ApiKey:return "API Key";+ case DatadogConnectionMethod.ApiKey:+ return "Application Keys";case ChefConnectionMethod.UserKey:return "User Key";case QoveryConnectionMethod.AccessToken:diff --git a/backend/src/services/app-connection/datadog/datadog-connection-enums.ts b/backend/src/services/app-connection/datadog/datadog-connection-enums.tsindex d05b5eb61a..d956d6ed15 100644--- a/backend/src/services/app-connection/datadog/datadog-connection-enums.ts+++ b/backend/src/services/app-connection/datadog/datadog-connection-enums.ts@@ -1,3 +1,4 @@export enum DatadogConnectionMethod {+ Token = "token",ApiKey = "api-key"}diff --git a/backend/src/services/app-connection/datadog/datadog-connection-fns.ts b/backend/src/services/app-connection/datadog/datadog-connection-fns.tsindex 241afcaaaa..81dc395d3e 100644--- a/backend/src/services/app-connection/datadog/datadog-connection-fns.ts+++ b/backend/src/services/app-connection/datadog/datadog-connection-fns.ts@@ -2,6 +2,7 @@ import { AxiosError } from "axios";import { BadRequestError } from "@app/lib/errors";import { removeTrailingSlash } from "@app/lib/fn";+import { DiscriminativePick } from "@app/lib/types";import { safeRequest } from "@app/lib/validator";import { AppConnection } from "../app-connection-enums";@@ -37,15 +38,24 @@ export const getDatadogConnectionListItem = () => {return {name: "Datadog" as const,app: AppConnection.Datadog as const,- methods: Object.values(DatadogConnectionMethod) as [DatadogConnectionMethod.ApiKey]+ methods: Object.values(DatadogConnectionMethod) as [DatadogConnectionMethod.Token, DatadogConnectionMethod.ApiKey]};};-export const getDatadogAppKeysAuthHeaders = (credentials: { apiKey: string; applicationKey: string }) => ({- "DD-API-KEY": credentials.apiKey,- "DD-APPLICATION-KEY": credentials.applicationKey,- Accept: "application/json"-});+export const getDatadogAuthHeaders = (connection: DiscriminativePick<TDatadogConnection, "method" | "credentials">) => {+ if (connection.method === DatadogConnectionMethod.Token) {+ return {+ Authorization: `Bearer ${connection.credentials.token}`,+ Accept: "application/json"+ };+ }++ return {+ "DD-API-KEY": connection.credentials.apiKey,+ "DD-APPLICATION-KEY": connection.credentials.applicationKey,+ Accept: "application/json"+ };+};type TDatadogJsonApiError = { detail?: string; title?: string; status?: string };@@ -68,7 +78,7 @@ export const validateDatadogConnectionCredentials = async (config: TDatadogConnetry {await safeRequest.get(`${baseUrl}/api/v2/validate_keys`, {- headers: getDatadogAppKeysAuthHeaders(config.credentials)+ headers: getDatadogAuthHeaders(config)});} catch (error: unknown) {throw new BadRequestError({@@ -115,7 +125,7 @@ export const listDatadogServiceAccounts = async (connection: TDatadogConnection)"page[size]": PAGE_SIZE,"page[number]": pageNumber},- headers: getDatadogAppKeysAuthHeaders(connection.credentials)+ headers: getDatadogAuthHeaders(connection)});const pageEntries = data.data ?? [];diff --git a/backend/src/services/app-connection/datadog/datadog-connection-schemas.ts b/backend/src/services/app-connection/datadog/datadog-connection-schemas.tsindex 2c098ebc4f..76ca8b1915 100644--- a/backend/src/services/app-connection/datadog/datadog-connection-schemas.ts+++ b/backend/src/services/app-connection/datadog/datadog-connection-schemas.ts@@ -27,11 +27,21 @@ export const DatadogConnectionApiKeyCredentialsSchema = z.object({.describe(AppConnections.CREDENTIALS.DATADOG.applicationKey)});+export const DatadogConnectionTokenCredentialsSchema = DatadogConnectionApiKeyCredentialsSchema.pick({+ url: true+}).extend({+ token: z.string().trim().min(1, "Token required").describe(AppConnections.CREDENTIALS.DATADOG.token)+});+const BaseDatadogConnectionSchema = BaseAppConnectionSchema.extend({app: z.literal(AppConnection.Datadog)});export const DatadogConnectionSchema = z.discriminatedUnion("method", [+ BaseDatadogConnectionSchema.extend({+ method: z.literal(DatadogConnectionMethod.Token),+ credentials: DatadogConnectionTokenCredentialsSchema+ }),BaseDatadogConnectionSchema.extend({method: z.literal(DatadogConnectionMethod.ApiKey),credentials: DatadogConnectionApiKeyCredentialsSchema@@ -39,13 +49,23 @@ export const DatadogConnectionSchema = z.discriminatedUnion("method", []);export const SanitizedDatadogConnectionSchema = z.discriminatedUnion("method", [+ BaseDatadogConnectionSchema.extend({+ method: z.literal(DatadogConnectionMethod.Token),+ credentials: DatadogConnectionTokenCredentialsSchema.pick({ url: true })+ }).describe(JSON.stringify({ title: `${APP_CONNECTION_NAME_MAP[AppConnection.Datadog]} (API Token)` })),BaseDatadogConnectionSchema.extend({method: z.literal(DatadogConnectionMethod.ApiKey),credentials: DatadogConnectionApiKeyCredentialsSchema.pick({ url: true })- }).describe(JSON.stringify({ title: `${APP_CONNECTION_NAME_MAP[AppConnection.Datadog]} (API Key)` }))+ }).describe(JSON.stringify({ title: `${APP_CONNECTION_NAME_MAP[AppConnection.Datadog]} (Application Keys)` }))]);export const ValidateDatadogConnectionCredentialsSchema = z.discriminatedUnion("method", [+ z.object({+ method: z.literal(DatadogConnectionMethod.Token).describe(AppConnections.CREATE(AppConnection.Datadog).method),+ credentials: DatadogConnectionTokenCredentialsSchema.describe(+ AppConnections.CREATE(AppConnection.Datadog).credentials+ )+ }),z.object({method: z.literal(DatadogConnectionMethod.ApiKey).describe(AppConnections.CREATE(AppConnection.Datadog).method),credentials: DatadogConnectionApiKeyCredentialsSchema.describe(@@ -60,9 +80,10 @@ export const CreateDatadogConnectionSchema = ValidateDatadogConnectionCredentialexport const UpdateDatadogConnectionSchema = z.object({- credentials: DatadogConnectionApiKeyCredentialsSchema.optional().describe(- AppConnections.UPDATE(AppConnection.Datadog).credentials- )+ credentials: z+ .union([DatadogConnectionApiKeyCredentialsSchema, DatadogConnectionTokenCredentialsSchema])+ .optional()+ .describe(AppConnections.UPDATE(AppConnection.Datadog).credentials)}).and(GenericUpdateAppConnectionFieldsSchema(AppConnection.Datadog));diff --git a/docs/integrations/app-connections/datadog.mdx b/docs/integrations/app-connections/datadog.mdxindex ae31568b21..7f37649dea 100644--- a/docs/integrations/app-connections/datadog.mdx+++ b/docs/integrations/app-connections/datadog.mdx@@ -3,13 +3,16 @@ title: "Datadog Connection"description: "Learn how to configure a Datadog Connection for Infisical."----Infisical supports the use of a Datadog [API Key](https://docs.datadoghq.com/account_management/api-app-keys/) paired with a Service Account [Application Key](https://docs.datadoghq.com/account_management/org_settings/service_accounts/) to authenticate with Datadog.+Infisical supports two methods for authenticating with Datadog:++- **API Token** (recommended): a Datadog API token that is sent as a bearer token (`Authorization: Bearer <token>`).+- **Application Keys**: a Datadog [API Key](https://docs.datadoghq.com/account_management/api-app-keys/) paired with a Service Account [Application Key](https://docs.datadoghq.com/account_management/org_settings/service_accounts/).<Note>- We recommend issuing the Application Key on a dedicated Service Account so the credentials Infisical uses can be rotated and revoked independently of any individual user.+ If you use the **Application Keys** method, we recommend issuing the Application Key on a dedicated Service Account so the credentials Infisical uses can be rotated and revoked independently of any individual user. The steps below walk through creating those credentials; the **API Token** method only requires a Datadog API token and the site URL.</Note>-## Create Datadog Credentials+## Create Datadog Application Keys Credentials<Steps><Step title="Open Organization Settings">@@ -110,9 +113,10 @@ Infisical supports the use of a Datadog [API Key](https://docs.datadoghq.com/accComplete the Datadog Connection form by entering:- A descriptive name for the connection- An optional description for future reference+ - The **Method** you want to use to authenticate (**API Token**, recommended, or **Application Keys**)- The Datadog **URL** for your region (e.g. `https://api.datadoghq.com`, `https://api.us5.datadoghq.com`, or `https://api.ddog-gov.com`)- - The **API Key** from earlier steps- - The Service Account **Application Key** from earlier steps+ - If using **API Token**: the Datadog **API Token**+ - If using **Application Keys**: the **API Key** and the Service Account **Application Key** from the earlier steps</Step>@@ -128,7 +132,23 @@ Infisical supports the use of a Datadog [API Key](https://docs.datadoghq.com/acc### Sample request- ```bash Request+ <CodeGroup>+ ```bash API Token (Recommended)+ curl --request POST \+ --url https://app.infisical.com/api/v1/app-connections/datadog \+ --header 'Content-Type: application/json' \+ --data '{+ "name": "my-datadog-connection",+ "method": "token",+ "projectId": "7ffbb072-2575-495a-b5b0-127f88caef78",+ "credentials": {+ "url": "https://api.datadoghq.com",+ "token": "<YOUR-API-TOKEN>"+ }+ }'+ ```++ ```bash Application Keyscurl --request POST \--url https://app.infisical.com/api/v1/app-connections/datadog \--header 'Content-Type: application/json' \@@ -143,6 +163,7 @@ Infisical supports the use of a Datadog [API Key](https://docs.datadoghq.com/acc}}'```+ </CodeGroup>### Sample responsediff --git a/frontend/src/helpers/appConnections.ts b/frontend/src/helpers/appConnections.tsindex 7e4ac18e69..a730a496c6 100644--- a/frontend/src/helpers/appConnections.ts+++ b/frontend/src/helpers/appConnections.ts@@ -643,6 +643,7 @@ export const getAppConnectionMethodDetails = (method: TAppConnection["method"])case TravisCIConnectionMethod.ApiToken:case DopplerConnectionMethod.ApiToken:case RundeckConnectionMethod.ApiToken:+ case DatadogConnectionMethod.Token:return { name: "API Token", icon: faKey };case VenafiConnectionMethod.ApiKey:return { name: "API Key", icon: faKey };@@ -712,8 +713,9 @@ export const getAppConnectionMethodDetails = (method: TAppConnection["method"])case AzureEntraIdConnectionMethod.ClientSecret:return { name: "Client Secret", icon: faKey };case OctopusDeployConnectionMethod.ApiKey:- case DatadogConnectionMethod.ApiKey:return { name: "API Key", icon: faKey };+ case DatadogConnectionMethod.ApiKey:+ return { name: "Application Keys", icon: faKey };case SshConnectionMethod.Password:return { name: "Password", icon: faLock };case SshConnectionMethod.SshKey:diff --git a/frontend/src/hooks/api/appConnections/types/datadog-connection.ts b/frontend/src/hooks/api/appConnections/types/datadog-connection.tsindex 186220ea38..d872430289 100644--- a/frontend/src/hooks/api/appConnections/types/datadog-connection.ts+++ b/frontend/src/hooks/api/appConnections/types/datadog-connection.ts@@ -2,14 +2,24 @@ import { AppConnection } from "@app/hooks/api/appConnections/enums";import { TRootAppConnection } from "@app/hooks/api/appConnections/types/root-connection";export enum DatadogConnectionMethod {+ Token = "token",ApiKey = "api-key"}-export type TDatadogConnection = TRootAppConnection & { app: AppConnection.Datadog } & {- method: DatadogConnectionMethod.ApiKey;- credentials: {- url: string;- apiKey: string;- applicationKey: string;- };-};+export type TDatadogConnection = TRootAppConnection & { app: AppConnection.Datadog } & (+ | {+ method: DatadogConnectionMethod.Token;+ credentials: {+ url: string;+ token: string;+ };+ }+ | {+ method: DatadogConnectionMethod.ApiKey;+ credentials: {+ url: string;+ apiKey: string;+ applicationKey: string;+ };+ }+ );diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/DatadogConnectionForm.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/DatadogConnectionForm.tsxindex 8fe554e74a..0e4727566d 100644--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/DatadogConnectionForm.tsx+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/DatadogConnectionForm.tsx@@ -9,10 +9,16 @@ import {FieldLabel,Input,SecretInput,+ Select,+ SelectContent,+ SelectItem,+ SelectTrigger,+ SelectValue,Tooltip,TooltipContent,TooltipTrigger} from "@app/components/v3";+import { APP_CONNECTION_MAP, getAppConnectionMethodDetails } from "@app/helpers/appConnections";import { AppConnection } from "@app/hooks/api/appConnections/enums";import {DatadogConnectionMethod,@@ -34,11 +40,20 @@ const rootSchema = genericAppConnectionFieldsSchema.extend({app: z.literal(AppConnection.Datadog)});+const urlSchema = z.string().trim().url("Invalid Datadog URL").min(1, "URL required").max(255);+const formSchema = z.discriminatedUnion("method", [+ rootSchema.extend({+ method: z.literal(DatadogConnectionMethod.Token),+ credentials: z.object({+ url: urlSchema,+ token: z.string().trim().min(1, "Token required")+ })+ }),rootSchema.extend({method: z.literal(DatadogConnectionMethod.ApiKey),credentials: z.object({- url: z.string().trim().url("Invalid Datadog URL").min(1, "URL required").max(255),+ url: urlSchema,apiKey: z.string().trim().min(1, "API Key required"),applicationKey: z.string().trim().min(1, "Application Key required")})@@ -54,17 +69,55 @@ export const DatadogConnectionForm = ({ appConnection, onSubmit }: Props) => {resolver: zodResolver(formSchema),defaultValues: appConnection ?? {app: AppConnection.Datadog,- method: DatadogConnectionMethod.ApiKey+ method: DatadogConnectionMethod.Token}});- const { handleSubmit, control } = form;+ const { handleSubmit, control, watch } = form;++ const selectedMethod = watch("method");return (<FormProvider {...form}><form onSubmit={handleSubmit(onSubmit)}>{!isUpdate && <GenericAppConnectionsFields />}+ <Controller+ name="method"+ control={control}+ render={({ field: { value, onChange }, fieldState: { error } }) => (+ <Field className="mb-4">+ <FieldLabel htmlFor="method">+ Method+ <Tooltip>+ <TooltipTrigger asChild>+ <Info />+ </TooltipTrigger>+ <TooltipContent className="max-w-sm">+ The method you would like to use to connect with{" "}+ {APP_CONNECTION_MAP[AppConnection.Datadog].name}. This field cannot be changed+ after creation.+ </TooltipContent>+ </Tooltip>+ </FieldLabel>+ <Select disabled={isUpdate} value={value} onValueChange={(val) => onChange(val)}>+ <SelectTrigger className="w-full" isError={Boolean(error)}>+ <SelectValue placeholder="Select a method..." />+ </SelectTrigger>+ <SelectContent position="popper">+ {Object.values(DatadogConnectionMethod).map((method) => (+ <SelectItem value={method} key={method}>+ {getAppConnectionMethodDetails(method).name}+ {method === DatadogConnectionMethod.Token ? " (Recommended)" : ""}+ </SelectItem>+ ))}+ </SelectContent>+ </Select>+ <FieldError errors={[error]} />+ </Field>+ )}+ />+<Controllername="credentials.url"control={control}@@ -92,30 +145,49 @@ export const DatadogConnectionForm = ({ appConnection, onSubmit }: Props) => {</Field>)}/>- <Controller- name="credentials.apiKey"- control={control}- shouldUnregister- render={({ field: { value, onChange }, fieldState: { error } }) => (- <Field className="mb-4">- <FieldLabel htmlFor="api-key">API Key</FieldLabel>- <SecretInput value={value} onChange={(e) => onChange(e.target.value)} />- <FieldError errors={[error]} />- </Field>- )}- />- <Controller- name="credentials.applicationKey"- control={control}- shouldUnregister- render={({ field: { value, onChange }, fieldState: { error } }) => (- <Field className="mb-4">- <FieldLabel htmlFor="application-key">Application Key</FieldLabel>- <SecretInput value={value} onChange={(e) => onChange(e.target.value)} />- <FieldError errors={[error]} />- </Field>- )}- />++ {selectedMethod === DatadogConnectionMethod.Token ? (+ <Controller+ name="credentials.token"+ control={control}+ shouldUnregister+ render={({ field: { value, onChange }, fieldState: { error } }) => (+ <Field className="mb-4">+ <FieldLabel htmlFor="token">API Token</FieldLabel>+ <SecretInput value={value} onChange={(e) => onChange(e.target.value)} />+ <FieldError errors={[error]} />+ </Field>+ )}+ />+ ) : (+ <>+ <Controller+ name="credentials.apiKey"+ control={control}+ shouldUnregister+ render={({ field: { value, onChange }, fieldState: { error } }) => (+ <Field className="mb-4">+ <FieldLabel htmlFor="api-key">API Key</FieldLabel>+ <SecretInput value={value} onChange={(e) => onChange(e.target.value)} />+ <FieldError errors={[error]} />+ </Field>+ )}+ />+ <Controller+ name="credentials.applicationKey"+ control={control}+ shouldUnregister+ render={({ field: { value, onChange }, fieldState: { error } }) => (+ <Field className="mb-4">+ <FieldLabel htmlFor="application-key">Application Key</FieldLabel>+ <SecretInput value={value} onChange={(e) => onChange(e.target.value)} />+ <FieldError errors={[error]} />+ </Field>+ )}+ />+ </>+ )}+<AppConnectionFormFootersubmitLabel={isUpdate ? "Update Credentials" : "Connect to Datadog"}/>