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
improvement: add gateway support to chef app connection
Scott Wilsonc03481944391
diff --git a/backend/src/ee/services/app-connections/chef/chef-connection-fns.ts b/backend/src/ee/services/app-connections/chef/chef-connection-fns.tsindex 48b2508fc5..bad00f12c4 100644--- a/backend/src/ee/services/app-connections/chef/chef-connection-fns.ts+++ b/backend/src/ee/services/app-connections/chef/chef-connection-fns.ts@@ -1,9 +1,14 @@-import { AxiosError } from "axios";+import { AxiosError, AxiosRequestConfig, AxiosResponse } from "axios";import crypto from "crypto";+import https from "https";+import { TGatewayServiceFactory } from "@app/ee/services/gateway/gateway-service";+import { TGatewayV2ServiceFactory } from "@app/ee/services/gateway-v2/gateway-v2-service";import { request } from "@app/lib/config/request";import { BadRequestError } from "@app/lib/errors";import { removeTrailingSlash } from "@app/lib/fn";+import { GatewayProxyProtocol } from "@app/lib/gateway";+import { withGatewayV2Proxy } from "@app/lib/gateway-v2/gateway-v2";import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";import { AppConnection } from "@app/services/app-connection/app-connection-enums";import { IntegrationUrls } from "@app/services/integration-auth/integration-list";@@ -19,12 +24,8 @@ import {TUpdateChefDataBagItem} from "./chef-connection-types";-export const getChefServerUrl = async (serverUrl?: string) => {- const chefServerUrl = serverUrl ? removeTrailingSlash(serverUrl) : IntegrationUrls.CHEF_API_URL;-- await blockLocalAndPrivateIpAddresses(chefServerUrl);-- return chefServerUrl;+export const getChefServerUrl = (serverUrl?: string) => {+ return serverUrl ? removeTrailingSlash(serverUrl) : IntegrationUrls.CHEF_API_URL;};const buildSecureUrl = (baseUrl: string, path: string): string => {@@ -131,6 +132,66 @@ const getChefAuthHeaders = (};};+export const requestWithChefGateway = async <T>(+ gatewayId: string | null | undefined,+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId"> | undefined,+ requestConfig: AxiosRequestConfig+): Promise<AxiosResponse<T>> => {+ const url = new URL(requestConfig.url as string);++ if (gatewayId && gatewayV2Service) {+ await blockLocalAndPrivateIpAddresses(url.toString(), true);++ const targetHost = url.hostname;+ // port is an empty string when the URL uses the protocol's default port (443 for https, 80 for http)+ // eslint-disable-next-line no-nested-ternary+ const targetPort = url.port ? Number(url.port) : url.protocol === "https:" ? 443 : 80;++ const platformConnectionDetails = await gatewayV2Service.getPlatformConnectionDetailsByGatewayId({+ gatewayId,+ targetHost,+ targetPort+ });++ if (!platformConnectionDetails) {+ throw new BadRequestError({ message: "Unable to connect to gateway, no platform connection details found" });+ }++ return withGatewayV2Proxy(+ async (proxyPort) => {+ const isHttps = url.protocol === "https:";+ url.host = `localhost:${proxyPort}`;++ const finalRequestConfig: AxiosRequestConfig = {+ ...requestConfig,+ url: url.toString(),+ headers: {+ ...requestConfig.headers,+ Host: targetHost+ },+ ...(isHttps && {+ httpsAgent: new https.Agent({+ servername: targetHost+ })+ })+ };++ return request.request<T>(finalRequestConfig);+ },+ {+ protocol: GatewayProxyProtocol.Tcp,+ relayHost: platformConnectionDetails.relayHost,+ gateway: platformConnectionDetails.gateway,+ relay: platformConnectionDetails.relay+ }+ );+ }++ await blockLocalAndPrivateIpAddresses(url.toString(), false);++ return request.request<T>(requestConfig);+};+export const getChefConnectionListItem = () => {return {name: "Chef" as const,@@ -139,18 +200,24 @@ export const getChefConnectionListItem = () => {};};-export const validateChefConnectionCredentials = async (config: TChefConnectionConfig) => {- const { credentials: inputCredentials } = config;+export const validateChefConnectionCredentials = async (+ config: TChefConnectionConfig,+ _gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">,+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId"> | undefined+) => {+ const { credentials: inputCredentials, gatewayId } = config;try {const path = `/organizations/${inputCredentials.orgName}/users/${inputCredentials.userName}`;- const hostServerUrl = await getChefServerUrl(inputCredentials.serverUrl);+ const hostServerUrl = getChefServerUrl(inputCredentials.serverUrl);const headers = getChefAuthHeaders("GET", path, "", inputCredentials.userName, inputCredentials.privateKey);const secureUrl = buildSecureUrl(hostServerUrl, path);- await request.get(secureUrl, {+ await requestWithChefGateway(gatewayId, gatewayV2Service, {+ method: "GET",+ url: secureUrl,headers});} catch (error: unknown) {@@ -159,6 +226,9 @@ export const validateChefConnectionCredentials = async (config: TChefConnectionCmessage: `Failed to validate Chef credentials: ${error.message || "Unknown error"}`});}+ if (error instanceof BadRequestError) {+ throw error;+ }throw new BadRequestError({message: "Unable to validate Chef connection: verify credentials"});@@ -167,21 +237,27 @@ export const validateChefConnectionCredentials = async (config: TChefConnectionCreturn inputCredentials;};-export const listChefDataBags = async (appConnection: TChefConnection): Promise<TChefDataBag[]> => {+export const listChefDataBags = async (+ appConnection: Pick<TChefConnection, "credentials" | "gatewayId">,+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId"> | undefined+): Promise<TChefDataBag[]> => {const {- credentials: { serverUrl, userName, privateKey, orgName }+ credentials: { serverUrl, userName, privateKey, orgName },+ gatewayId} = appConnection;try {const path = `/organizations/${orgName}/data`;const body = "";- const hostServerUrl = await getChefServerUrl(serverUrl);+ const hostServerUrl = getChefServerUrl(serverUrl);const headers = getChefAuthHeaders("GET", path, body, userName, privateKey);const secureUrl = buildSecureUrl(hostServerUrl, path);- const res = await request.get<Record<string, string>>(secureUrl, {+ const res = await requestWithChefGateway<Record<string, string>>(gatewayId, gatewayV2Service, {+ method: "GET",+ url: secureUrl,headers});@@ -194,6 +270,9 @@ export const listChefDataBags = async (appConnection: TChefConnection): Promise<message: `Failed to list Chef data bags: ${error.message || "Unknown error"}`});}+ if (error instanceof BadRequestError) {+ throw error;+ }throw new BadRequestError({message: "Unable to list Chef data bags"});@@ -201,23 +280,27 @@ export const listChefDataBags = async (appConnection: TChefConnection): Promise<};export const listChefDataBagItems = async (- appConnection: TChefConnection,- dataBagName: string+ appConnection: Pick<TChefConnection, "credentials" | "gatewayId">,+ dataBagName: string,+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId"> | undefined): Promise<TChefDataBagItem[]> => {const {- credentials: { serverUrl, userName, privateKey, orgName }+ credentials: { serverUrl, userName, privateKey, orgName },+ gatewayId} = appConnection;try {const path = `/organizations/${orgName}/data/${dataBagName}`;const body = "";- const hostServerUrl = await getChefServerUrl(serverUrl);+ const hostServerUrl = getChefServerUrl(serverUrl);const headers = getChefAuthHeaders("GET", path, body, userName, privateKey);const secureUrl = buildSecureUrl(hostServerUrl, path);- const res = await request.get<Record<string, string>>(secureUrl, {+ const res = await requestWithChefGateway<Record<string, string>>(gatewayId, gatewayV2Service, {+ method: "GET",+ url: secureUrl,headers});@@ -230,30 +313,31 @@ export const listChefDataBagItems = async (message: `Failed to list Chef data bag items: ${error.message || "Unknown error"}`});}+ if (error instanceof BadRequestError) {+ throw error;+ }throw new BadRequestError({message: "Unable to list Chef data bag items"});}};-export const getChefDataBagItem = async ({- serverUrl,- userName,- privateKey,- orgName,- dataBagName,- dataBagItemName-}: TGetChefDataBagItem): Promise<TChefDataBagItemContent> => {+export const getChefDataBagItem = async (+ { serverUrl, userName, privateKey, orgName, dataBagName, dataBagItemName, gatewayId }: TGetChefDataBagItem,+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId"> | undefined+): Promise<TChefDataBagItemContent> => {try {const path = `/organizations/${orgName}/data/${dataBagName}/${dataBagItemName}`;const body = "";- const hostServerUrl = await getChefServerUrl(serverUrl);+ const hostServerUrl = getChefServerUrl(serverUrl);const headers = getChefAuthHeaders("GET", path, body, userName, privateKey);const secureUrl = buildSecureUrl(hostServerUrl, path);- const res = await request.get<TChefDataBagItemContent>(secureUrl, {+ const res = await requestWithChefGateway<TChefDataBagItemContent>(gatewayId, gatewayV2Service, {+ method: "GET",+ url: secureUrl,headers});@@ -264,30 +348,40 @@ export const getChefDataBagItem = async ({message: `Failed to get Chef data bag item: ${error.message || "Unknown error"}`});}+ if (error instanceof BadRequestError) {+ throw error;+ }throw new BadRequestError({message: "Unable to get Chef data bag item"});}};-export const createChefDataBagItem = async ({- serverUrl,- userName,- privateKey,- orgName,- dataBagName,- data-}: Omit<TUpdateChefDataBagItem, "dataBagItemName">): Promise<void> => {+export const createChefDataBagItem = async (+ {+ serverUrl,+ userName,+ privateKey,+ orgName,+ dataBagName,+ data,+ gatewayId+ }: Omit<TUpdateChefDataBagItem, "dataBagItemName">,+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId"> | undefined+): Promise<void> => {try {const path = `/organizations/${orgName}/data/${dataBagName}`;const body = JSON.stringify(data);- const hostServerUrl = await getChefServerUrl(serverUrl);+ const hostServerUrl = getChefServerUrl(serverUrl);const headers = getChefAuthHeaders("POST", path, body, userName, privateKey);const secureUrl = buildSecureUrl(hostServerUrl, path);- await request.post(secureUrl, data, {+ await requestWithChefGateway(gatewayId, gatewayV2Service, {+ method: "POST",+ url: secureUrl,+ data,headers});} catch (error) {@@ -296,31 +390,32 @@ export const createChefDataBagItem = async ({message: `Failed to create Chef data bag item: ${error.message || "Unknown error"}`});}+ if (error instanceof BadRequestError) {+ throw error;+ }throw new BadRequestError({message: "Unable to create Chef data bag item"});}};-export const updateChefDataBagItem = async ({- serverUrl,- userName,- privateKey,- orgName,- dataBagName,- dataBagItemName,- data-}: TUpdateChefDataBagItem): Promise<void> => {+export const updateChefDataBagItem = async (+ { serverUrl, userName, privateKey, orgName, dataBagName, dataBagItemName, data, gatewayId }: TUpdateChefDataBagItem,+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId"> | undefined+): Promise<void> => {try {const path = `/organizations/${orgName}/data/${dataBagName}/${dataBagItemName}`;const body = JSON.stringify(data);- const hostServerUrl = await getChefServerUrl(serverUrl);+ const hostServerUrl = getChefServerUrl(serverUrl);const headers = getChefAuthHeaders("PUT", path, body, userName, privateKey);const secureUrl = buildSecureUrl(hostServerUrl, path);- await request.put(secureUrl, data, {+ await requestWithChefGateway(gatewayId, gatewayV2Service, {+ method: "PUT",+ url: secureUrl,+ data,headers});} catch (error) {@@ -329,30 +424,39 @@ export const updateChefDataBagItem = async ({message: `Failed to update Chef data bag item: ${error.message || "Unknown error"}`});}+ if (error instanceof BadRequestError) {+ throw error;+ }throw new BadRequestError({message: "Unable to update Chef data bag item"});}};-export const removeChefDataBagItem = async ({- serverUrl,- userName,- privateKey,- orgName,- dataBagName,- dataBagItemName-}: Omit<TUpdateChefDataBagItem, "data">): Promise<void> => {+export const removeChefDataBagItem = async (+ {+ serverUrl,+ userName,+ privateKey,+ orgName,+ dataBagName,+ dataBagItemName,+ gatewayId+ }: Omit<TUpdateChefDataBagItem, "data">,+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId"> | undefined+): Promise<void> => {try {const path = `/organizations/${orgName}/data/${dataBagName}/${dataBagItemName}`;const body = "";- const hostServerUrl = await getChefServerUrl(serverUrl);+ const hostServerUrl = getChefServerUrl(serverUrl);const headers = getChefAuthHeaders("DELETE", path, body, userName, privateKey);const secureUrl = buildSecureUrl(hostServerUrl, path);- await request.delete(secureUrl, {+ await requestWithChefGateway(gatewayId, gatewayV2Service, {+ method: "DELETE",+ url: secureUrl,headers});} catch (error) {@@ -361,6 +465,9 @@ export const removeChefDataBagItem = async ({message: `Failed to remove Chef data bag item: ${error.message || "Unknown error"}`});}+ if (error instanceof BadRequestError) {+ throw error;+ }throw new BadRequestError({message: "Unable to remove Chef data bag item"});diff --git a/backend/src/ee/services/app-connections/chef/chef-connection-schemas.ts b/backend/src/ee/services/app-connections/chef/chef-connection-schemas.tsindex efe11c0f2d..8eb855a9a9 100644--- a/backend/src/ee/services/app-connections/chef/chef-connection-schemas.ts+++ b/backend/src/ee/services/app-connections/chef/chef-connection-schemas.ts@@ -60,7 +60,9 @@ export const ValidateChefConnectionCredentialsSchema = z.discriminatedUnion("met]);export const CreateChefConnectionSchema = ValidateChefConnectionCredentialsSchema.and(- GenericCreateAppConnectionFieldsSchema(AppConnection.Chef)+ GenericCreateAppConnectionFieldsSchema(AppConnection.Chef, {+ supportsGateways: true+ }));export const UpdateChefConnectionSchema = z@@ -69,7 +71,11 @@ export const UpdateChefConnectionSchema = zAppConnections.UPDATE(AppConnection.Chef).credentials)})- .and(GenericUpdateAppConnectionFieldsSchema(AppConnection.Chef));+ .and(+ GenericUpdateAppConnectionFieldsSchema(AppConnection.Chef, {+ supportsGateways: true+ })+ );export const ChefConnectionListItemSchema = z.object({diff --git a/backend/src/ee/services/app-connections/chef/chef-connection-service.ts b/backend/src/ee/services/app-connections/chef/chef-connection-service.tsindex 242b1fbf9a..2f7f8328e3 100644--- a/backend/src/ee/services/app-connections/chef/chef-connection-service.ts+++ b/backend/src/ee/services/app-connections/chef/chef-connection-service.ts@@ -2,6 +2,8 @@ import { BadRequestError, ForbiddenRequestError } from "@app/lib/errors";import { OrgServiceActor } from "@app/lib/types";import { AppConnection } from "../../../../services/app-connection/app-connection-enums";+import { TGatewayPoolServiceFactory } from "../../gateway-pool/gateway-pool-service";+import { TGatewayV2ServiceFactory } from "../../gateway-v2/gateway-v2-service";import { TLicenseServiceFactory } from "../../license/license-service";import { listChefDataBagItems, listChefDataBags } from "./chef-connection-fns";import { TChefConnection } from "./chef-connection-types";@@ -24,30 +26,39 @@ export const checkPlan = async (licenseService: Pick<TLicenseServiceFactory, "geexport const chefConnectionService = (getAppConnection: TGetAppConnectionFunc,- licenseService: Pick<TLicenseServiceFactory, "getPlan">+ licenseService: Pick<TLicenseServiceFactory, "getPlan">,+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">,+ gatewayPoolService: Pick<TGatewayPoolServiceFactory, "resolveEffectiveGatewayId">) => {- const listDataBags = async (appConnectionId: string, actor: OrgServiceActor) => {- await checkPlan(licenseService, actor.orgId);-+ const $getResolvedConnection = async (appConnectionId: string, actor: OrgServiceActor) => {const appConnection = await getAppConnection(AppConnection.Chef, appConnectionId, actor);if (!appConnection) {throw new ForbiddenRequestError({ message: "App connection not found" });}- return listChefDataBags(appConnection);+ const effectiveGatewayId = await gatewayPoolService.resolveEffectiveGatewayId({+ gatewayId: appConnection.gatewayId,+ gatewayPoolId: appConnection.gatewayPoolId+ });++ return { ...appConnection, gatewayId: effectiveGatewayId, gatewayPoolId: null };};- const listDataBagItems = async (appConnectionId: string, dataBagName: string, actor: OrgServiceActor) => {+ const listDataBags = async (appConnectionId: string, actor: OrgServiceActor) => {await checkPlan(licenseService, actor.orgId);- const appConnection = await getAppConnection(AppConnection.Chef, appConnectionId, actor);+ const appConnection = await $getResolvedConnection(appConnectionId, actor);- if (!appConnection) {- throw new ForbiddenRequestError({ message: "App connection not found" });- }+ return listChefDataBags(appConnection, gatewayV2Service);+ };++ const listDataBagItems = async (appConnectionId: string, dataBagName: string, actor: OrgServiceActor) => {+ await checkPlan(licenseService, actor.orgId);++ const appConnection = await $getResolvedConnection(appConnectionId, actor);- return listChefDataBagItems(appConnection, dataBagName);+ return listChefDataBagItems(appConnection, dataBagName, gatewayV2Service);};return {diff --git a/backend/src/ee/services/app-connections/chef/chef-connection-types.ts b/backend/src/ee/services/app-connections/chef/chef-connection-types.tsindex 5673614e9a..a4e6c22d7e 100644--- a/backend/src/ee/services/app-connections/chef/chef-connection-types.ts+++ b/backend/src/ee/services/app-connections/chef/chef-connection-types.ts@@ -18,8 +18,11 @@ export type TChefConnectionInput = z.infer<typeof CreateChefConnectionSchema> &export type TValidateChefConnectionCredentialsSchema = typeof ValidateChefConnectionCredentialsSchema;-export type TChefConnectionConfig = DiscriminativePick<TChefConnectionInput, "method" | "app" | "credentials"> & {- orgName: string;+export type TChefConnectionConfig = DiscriminativePick<+ TChefConnectionInput,+ "method" | "app" | "credentials" | "gatewayId" | "gatewayPoolId"+> & {+ orgId: string;};export type TChefDataBag = {@@ -37,6 +40,7 @@ export type TGetChefDataBagItem = {orgName: string;dataBagName: string;dataBagItemName: string;+ gatewayId?: string | null;};export type TUpdateChefDataBagItem = {@@ -47,4 +51,5 @@ export type TUpdateChefDataBagItem = {dataBagName: string;dataBagItemName: string;data: TChefDataBagItemContent;+ gatewayId?: string | null;};diff --git a/backend/src/ee/services/secret-sync/chef/chef-sync-fns.ts b/backend/src/ee/services/secret-sync/chef/chef-sync-fns.tsindex 65a4fca9b1..699037973b 100644--- a/backend/src/ee/services/secret-sync/chef/chef-sync-fns.ts+++ b/backend/src/ee/services/secret-sync/chef/chef-sync-fns.ts@@ -1,4 +1,6 @@import { getChefDataBagItem, updateChefDataBagItem } from "@app/ee/services/app-connections/chef";+import { TGatewayPoolServiceFactory } from "@app/ee/services/gateway-pool/gateway-pool-service";+import { TGatewayV2ServiceFactory } from "@app/ee/services/gateway-v2/gateway-v2-service";import { matchesSchema } from "@app/services/secret-sync/secret-sync-fns";import { TSecretMap } from "@app/services/secret-sync/secret-sync-types";@@ -11,22 +13,35 @@ import {TGetChefSecrets} from "./chef-sync-types";-const getChefSecretsRaw = async ({- serverUrl,- userName,- privateKey,- orgName,- dataBagName,- dataBagItemName-}: TGetChefSecrets): Promise<TChefDataBagItemContent> => {- const dataBagItem = await getChefDataBagItem({- serverUrl,- userName,- privateKey,- orgName,- dataBagName,- dataBagItemName+type TChefSyncGatewayV2Service = Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">;+type TChefSyncGatewayPoolService = Pick<TGatewayPoolServiceFactory, "resolveEffectiveGatewayId">;++const resolveGatewayId = async (+ secretSync: TChefSyncWithCredentials,+ gatewayPoolService: TChefSyncGatewayPoolService+) => {+ return gatewayPoolService.resolveEffectiveGatewayId({+ gatewayId: secretSync.connection.gatewayId,+ gatewayPoolId: secretSync.connection.gatewayPoolId});+};++const getChefSecretsRaw = async (+ { serverUrl, userName, privateKey, orgName, dataBagName, dataBagItemName, gatewayId }: TGetChefSecrets,+ gatewayV2Service: TChefSyncGatewayV2Service+): Promise<TChefDataBagItemContent> => {+ const dataBagItem = await getChefDataBagItem(+ {+ serverUrl,+ userName,+ privateKey,+ orgName,+ dataBagName,+ dataBagItemName,+ gatewayId+ },+ gatewayV2Service+ );// Ensure the data bag item has an id fieldif (!dataBagItem.id) {@@ -36,7 +51,11 @@ const getChefSecretsRaw = async ({return dataBagItem;};-const getChefSecrets = async (secretSync: TChefSyncWithCredentials): Promise<TChefSecrets> => {+const getChefSecrets = async (+ secretSync: TChefSyncWithCredentials,+ gatewayId: string | null,+ gatewayV2Service: TChefSyncGatewayV2Service+): Promise<TChefSecrets> => {const {connection,destinationConfig: { dataBagName, dataBagItemName }@@ -44,14 +63,18 @@ const getChefSecrets = async (secretSync: TChefSyncWithCredentials): Promise<TChconst { serverUrl, userName, privateKey, orgName } = connection.credentials;- const dataBagItem = await getChefSecretsRaw({- serverUrl,- orgName,- userName,- privateKey,- dataBagName,- dataBagItemName- });+ const dataBagItem = await getChefSecretsRaw(+ {+ serverUrl,+ orgName,+ userName,+ privateKey,+ dataBagName,+ dataBagItemName,+ gatewayId+ },+ gatewayV2Service+ );const { id, ...existingSecrets } = dataBagItem;@@ -69,7 +92,9 @@ const getChefSecrets = async (secretSync: TChefSyncWithCredentials): Promise<TChconst updateChefSecrets = async (secretSync: TChefSyncWithCredentials,id: string,- secrets: Record<string, TChefSecret>+ secrets: Record<string, TChefSecret>,+ gatewayId: string | null,+ gatewayV2Service: TChefSyncGatewayV2Service) => {const {connection,@@ -84,25 +109,36 @@ const updateChefSecrets = async (...secrets};- await updateChefDataBagItem({- serverUrl,- orgName,- userName,- privateKey,- dataBagName,- dataBagItemName,- data: dataBagItemContent- });+ await updateChefDataBagItem(+ {+ serverUrl,+ orgName,+ userName,+ privateKey,+ dataBagName,+ dataBagItemName,+ data: dataBagItemContent,+ gatewayId+ },+ gatewayV2Service+ );};export const ChefSyncFns = {- async syncSecrets(secretSync: TChefSyncWithCredentials, secretMap: TSecretMap) {+ async syncSecrets(+ secretSync: TChefSyncWithCredentials,+ secretMap: TSecretMap,+ gatewayV2Service: TChefSyncGatewayV2Service,+ gatewayPoolService: TChefSyncGatewayPoolService+ ) {const {environment,syncOptions: { disableSecretDeletion, keySchema }} = secretSync;- const { id, secrets } = await getChefSecrets(secretSync);+ const gatewayId = await resolveGatewayId(secretSync, gatewayPoolService);++ const { id, secrets } = await getChefSecrets(secretSync, gatewayId, gatewayV2Service);// Create a map of the existing secretsconst updatedSecretsMap = new Map(secrets.map((secret) => [secret.key, secret.value]));@@ -126,17 +162,30 @@ export const ChefSyncFns = {// Convert map to object for Chef APIconst updatedSecrets = Object.fromEntries(updatedSecretsMap.entries());- await updateChefSecrets(secretSync, id, updatedSecrets);+ await updateChefSecrets(secretSync, id, updatedSecrets, gatewayId, gatewayV2Service);},- async getSecrets(secretSync: TChefSyncWithCredentials): Promise<TSecretMap> {- const { secrets } = await getChefSecrets(secretSync);+ async getSecrets(+ secretSync: TChefSyncWithCredentials,+ gatewayV2Service: TChefSyncGatewayV2Service,+ gatewayPoolService: TChefSyncGatewayPoolService+ ): Promise<TSecretMap> {+ const gatewayId = await resolveGatewayId(secretSync, gatewayPoolService);++ const { secrets } = await getChefSecrets(secretSync, gatewayId, gatewayV2Service);return Object.fromEntries(secrets.map((secret) => [secret.key, { value: secret.value }]));},- async removeSecrets(secretSync: TChefSyncWithCredentials, secretMap: TSecretMap) {- const { id, secrets: existingSecrets } = await getChefSecrets(secretSync);+ async removeSecrets(+ secretSync: TChefSyncWithCredentials,+ secretMap: TSecretMap,+ gatewayV2Service: TChefSyncGatewayV2Service,+ gatewayPoolService: TChefSyncGatewayPoolService+ ) {+ const gatewayId = await resolveGatewayId(secretSync, gatewayPoolService);++ const { id, secrets: existingSecrets } = await getChefSecrets(secretSync, gatewayId, gatewayV2Service);const newSecrets = existingSecrets.filter((secret) => !Object.hasOwn(secretMap, secret.key));@@ -146,6 +195,6 @@ export const ChefSyncFns = {const updatedSecrets = Object.fromEntries(newSecrets.map((secret) => [secret.key, secret.value]));- await updateChefSecrets(secretSync, id, updatedSecrets);+ await updateChefSecrets(secretSync, id, updatedSecrets, gatewayId, gatewayV2Service);}};diff --git a/backend/src/ee/services/secret-sync/chef/chef-sync-types.ts b/backend/src/ee/services/secret-sync/chef/chef-sync-types.tsindex 0f70e7e1aa..c95bfacb56 100644--- a/backend/src/ee/services/secret-sync/chef/chef-sync-types.ts+++ b/backend/src/ee/services/secret-sync/chef/chef-sync-types.ts@@ -21,6 +21,7 @@ export type TGetChefSecrets = {orgName: string;dataBagName: string;dataBagItemName: string;+ gatewayId?: string | null;};export type TChefSecret = string | number | boolean | null;diff --git a/backend/src/services/app-connection/app-connection-service.ts b/backend/src/services/app-connection/app-connection-service.tsindex 0d9feccdfc..2999f519be 100644--- a/backend/src/services/app-connection/app-connection-service.ts+++ b/backend/src/services/app-connection/app-connection-service.ts@@ -1398,7 +1398,7 @@ export const appConnectionServiceFactory = ({datadog: datadogConnectionService(connectAppConnectionById),openai: openaiConnectionService(connectAppConnectionById),laravelForge: laravelForgeConnectionService(connectAppConnectionById),- chef: chefConnectionService(connectAppConnectionById, licenseService),+ chef: chefConnectionService(connectAppConnectionById, licenseService, gatewayV2Service, gatewayPoolService),octopusDeploy: octopusDeployConnectionService(connectAppConnectionById),dbt: dbtConnectionService(connectAppConnectionById),circleci: circleciConnectionService(connectAppConnectionById),diff --git a/backend/src/services/pki-sync/chef/chef-pki-sync-fns.ts b/backend/src/services/pki-sync/chef/chef-pki-sync-fns.tsindex 69c6cc2e0d..ac136c6958 100644--- a/backend/src/services/pki-sync/chef/chef-pki-sync-fns.ts+++ b/backend/src/services/pki-sync/chef/chef-pki-sync-fns.ts@@ -7,6 +7,8 @@ import {removeChefDataBagItem,updateChefDataBagItem} from "@app/ee/services/app-connections/chef";+import { TGatewayPoolServiceFactory } from "@app/ee/services/gateway-pool/gateway-pool-service";+import { TGatewayV2ServiceFactory } from "@app/ee/services/gateway-v2/gateway-v2-service";import { TChefDataBagItemContent } from "@app/ee/services/secret-sync/chef";import { logger } from "@app/lib/logger";import { TCertificateDALFactory } from "@app/services/certificate/certificate-dal";@@ -72,11 +74,28 @@ type TChefPkiSyncFactoryDeps = {| "findByPkiSyncId"| "updateSyncStatus">;+ gatewayV2Service?: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">;+ gatewayPoolService?: Pick<TGatewayPoolServiceFactory, "resolveEffectiveGatewayId">;};-export const chefPkiSyncFactory = ({ certificateDAL, certificateSyncDAL }: TChefPkiSyncFactoryDeps) => {+export const chefPkiSyncFactory = ({+ certificateDAL,+ certificateSyncDAL,+ gatewayV2Service,+ gatewayPoolService+}: TChefPkiSyncFactoryDeps) => {+ const $resolveGateway = async (pkiSync: TChefPkiSyncWithCredentials): Promise<string | null> => {+ return gatewayPoolService+ ? gatewayPoolService.resolveEffectiveGatewayId({+ gatewayId: pkiSync.connection.gatewayId,+ gatewayPoolId: pkiSync.connection.gatewayPoolId+ })+ : (pkiSync.connection.gatewayId ?? null);+ };+const $getChefDataBagItems = async (pkiSync: TChefPkiSyncWithCredentials,+ gatewayId: string | null,syncId = "unknown"): Promise<Record<string, boolean>> => {const {@@ -89,9 +108,11 @@ export const chefPkiSyncFactory = ({ certificateDAL, certificateSyncDAL }: TChef() =>listChefDataBagItems({- credentials: { serverUrl, userName, privateKey, orgName }- } as Parameters<typeof listChefDataBagItems>[0],- dataBagName+ credentials: { serverUrl, userName, privateKey, orgName },+ gatewayId+ },+ dataBagName,+ gatewayV2Service),{operation: "list-chef-data-bag-items",@@ -118,7 +139,9 @@ export const chefPkiSyncFactory = ({ certificateDAL, certificateSyncDAL }: TChef} = chefPkiSync;const { serverUrl, userName, privateKey, orgName } = connection.credentials;- const chefDataBagItems = await $getChefDataBagItems(chefPkiSync, pkiSync.id);+ const effectiveGatewayId = await $resolveGateway(chefPkiSync);++ const chefDataBagItems = await $getChefDataBagItems(chefPkiSync, effectiveGatewayId, pkiSync.id);const existingSyncRecords = await certificateSyncDAL.findByPkiSyncId(pkiSync.id);const syncRecordsByCertId = new Map<string, TCertificateSyncs>();@@ -278,15 +301,19 @@ export const chefPkiSyncFactory = ({ certificateDAL, certificateSyncDAL }: TChefif (itemExists) {await withRateLimitRetry(() =>- updateChefDataBagItem({- serverUrl,- userName,- privateKey,- orgName,- dataBagName,- dataBagItemName: targetItemName,- data: chefDataBagItem as unknown as TChefDataBagItemContent- }),+ updateChefDataBagItem(+ {+ serverUrl,+ userName,+ privateKey,+ orgName,+ dataBagName,+ dataBagItemName: targetItemName,+ data: chefDataBagItem as unknown as TChefDataBagItemContent,+ gatewayId: effectiveGatewayId+ },+ gatewayV2Service+ ),{operation: "update-chef-data-bag-item",syncId: pkiSync.id@@ -295,14 +322,18 @@ export const chefPkiSyncFactory = ({ certificateDAL, certificateSyncDAL }: TChef} else {await withRateLimitRetry(() =>- createChefDataBagItem({- serverUrl,- userName,- privateKey,- orgName,- dataBagName,- data: chefDataBagItem as unknown as TChefDataBagItemContent- }),+ createChefDataBagItem(+ {+ serverUrl,+ userName,+ privateKey,+ orgName,+ dataBagName,+ data: chefDataBagItem as unknown as TChefDataBagItemContent,+ gatewayId: effectiveGatewayId+ },+ gatewayV2Service+ ),{operation: "create-chef-data-bag-item",syncId: pkiSync.id@@ -364,14 +395,18 @@ export const chefPkiSyncFactory = ({ certificateDAL, certificateSyncDAL }: TCheftry {await withRateLimitRetry(() =>- removeChefDataBagItem({- serverUrl,- userName,- privateKey,- orgName,- dataBagName,- dataBagItemName: itemName- }),+ removeChefDataBagItem(+ {+ serverUrl,+ userName,+ privateKey,+ orgName,+ dataBagName,+ dataBagItemName: itemName,+ gatewayId: effectiveGatewayId+ },+ gatewayV2Service+ ),{operation: "remove-chef-data-bag-item",syncId: pkiSync.id@@ -535,6 +570,8 @@ export const chefPkiSyncFactory = ({ certificateDAL, certificateSyncDAL }: TChef} = chefPkiSync;const { serverUrl, userName, privateKey, orgName } = connection.credentials;+ const effectiveGatewayId = await $resolveGateway(chefPkiSync);+const existingSyncRecords = await certificateSyncDAL.findByPkiSyncId(sync.id);const certificateIdsToRemove: string[] = [];const itemsToRemove: string[] = [];@@ -563,14 +600,18 @@ export const chefPkiSyncFactory = ({ certificateDAL, certificateSyncDAL }: TCheftry {await withRateLimitRetry(() =>- removeChefDataBagItem({- serverUrl,- userName,- privateKey,- orgName,- dataBagName,- dataBagItemName: itemName- }),+ removeChefDataBagItem(+ {+ serverUrl,+ userName,+ privateKey,+ orgName,+ dataBagName,+ dataBagItemName: itemName,+ gatewayId: effectiveGatewayId+ },+ gatewayV2Service+ ),{operation: "remove-chef-data-bag-item",syncId: sync.iddiff --git a/backend/src/services/pki-sync/pki-sync-fns.ts b/backend/src/services/pki-sync/pki-sync-fns.tsindex 330b7bf058..a719495660 100644--- a/backend/src/services/pki-sync/pki-sync-fns.ts+++ b/backend/src/services/pki-sync/pki-sync-fns.ts@@ -253,7 +253,9 @@ export const PkiSyncFns = {checkPkiSyncDestination(pkiSync, PkiSync.Chef as PkiSync);const chefPkiSync = chefPkiSyncFactory({certificateDAL: dependencies.certificateDAL,- certificateSyncDAL: dependencies.certificateSyncDAL+ certificateSyncDAL: dependencies.certificateSyncDAL,+ gatewayV2Service: dependencies.gatewayV2Service,+ gatewayPoolService: dependencies.gatewayPoolService});return chefPkiSync.syncCertificates(pkiSync, certificateMap);}@@ -396,7 +398,9 @@ export const PkiSyncFns = {checkPkiSyncDestination(pkiSync, PkiSync.Chef as PkiSync);const chefPkiSync = chefPkiSyncFactory({certificateDAL: dependencies.certificateDAL,- certificateSyncDAL: dependencies.certificateSyncDAL+ certificateSyncDAL: dependencies.certificateSyncDAL,+ gatewayV2Service: dependencies.gatewayV2Service,+ gatewayPoolService: dependencies.gatewayPoolService});await chefPkiSync.removeCertificates(pkiSync, certificateNames, {certificateSyncDAL: dependencies.certificateSyncDAL,diff --git a/backend/src/services/secret-sync/secret-sync-fns.ts b/backend/src/services/secret-sync/secret-sync-fns.tsindex 12c33f1f62..9a9c45bbea 100644--- a/backend/src/services/secret-sync/secret-sync-fns.ts+++ b/backend/src/services/secret-sync/secret-sync-fns.ts@@ -424,7 +424,7 @@ export const SecretSyncFns = {case SecretSync.LaravelForge:return LaravelForgeSyncFns.syncSecrets(secretSync, schemaSecretMap);case SecretSync.Chef:- return ChefSyncFns.syncSecrets(secretSync, schemaSecretMap);+ return ChefSyncFns.syncSecrets(secretSync, schemaSecretMap, gatewayV2Service, gatewayPoolService);case SecretSync.OctopusDeploy:return OctopusDeploySyncFns.syncSecrets(secretSync, schemaSecretMap);case SecretSync.CircleCI:@@ -589,7 +589,7 @@ export const SecretSyncFns = {secretMap = await LaravelForgeSyncFns.getSecrets(secretSync);break;case SecretSync.Chef:- secretMap = await ChefSyncFns.getSecrets(secretSync);+ secretMap = await ChefSyncFns.getSecrets(secretSync, gatewayV2Service, gatewayPoolService);break;case SecretSync.OctopusDeploy:secretMap = await OctopusDeploySyncFns.getSecrets(secretSync);@@ -754,7 +754,7 @@ export const SecretSyncFns = {case SecretSync.LaravelForge:return LaravelForgeSyncFns.removeSecrets(secretSync, schemaSecretMap);case SecretSync.Chef:- return ChefSyncFns.removeSecrets(secretSync, schemaSecretMap);+ return ChefSyncFns.removeSecrets(secretSync, schemaSecretMap, gatewayV2Service, gatewayPoolService);case SecretSync.OctopusDeploy:return OctopusDeploySyncFns.removeSecrets(secretSync, schemaSecretMap);case SecretSync.CircleCI:diff --git a/docs/integrations/app-connections/chef.mdx b/docs/integrations/app-connections/chef.mdxindex 6759d79243..7e3c3c3d67 100644--- a/docs/integrations/app-connections/chef.mdx+++ b/docs/integrations/app-connections/chef.mdx@@ -90,6 +90,8 @@ Please access your **starter kit** to get all the required information to create- User name- Private key: Your Chef user's private key (.pem file)+ Optionally select a **Gateway** to route the connection through an Infisical Gateway for private network access.+</Step><Step title="Connection created">diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/ChefConnectionForm.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/ChefConnectionForm.tsxindex 8986054349..d858b5d04c 100644--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/ChefConnectionForm.tsx+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/ChefConnectionForm.tsx@@ -3,6 +3,7 @@ import { zodResolver } from "@hookform/resolvers/zod";import { Info } from "lucide-react";import { z } from "zod";+import { OrgPermissionCan } from "@app/components/permissions";import {Field,FieldError,@@ -18,6 +19,9 @@ import {TooltipContent,TooltipTrigger} from "@app/components/v3";+import { GatewayPicker } from "@app/components/v3/platform/GatewayPicker";+import { OrgPermissionSubjects } from "@app/context";+import { OrgGatewayPermissionActions } from "@app/context/OrgPermissionContext/types";import { APP_CONNECTION_MAP, getAppConnectionMethodDetails } from "@app/helpers/appConnections";import { ChefConnectionMethod, TChefConnection } from "@app/hooks/api/appConnections";import { AppConnection } from "@app/hooks/api/appConnections/enums";@@ -58,16 +62,63 @@ export const ChefConnectionForm = ({ appConnection, onSubmit }: Props) => {resolver: zodResolver(formSchema),defaultValues: appConnection ?? {app: AppConnection.Chef,- method: ChefConnectionMethod.UserKey+ method: ChefConnectionMethod.UserKey,+ gatewayId: null,+ gatewayPoolId: null}});- const { handleSubmit, control } = form;+ const { handleSubmit, control, setValue, watch } = form;++ const gatewayId = watch("gatewayId");+ const gatewayPoolId = watch("gatewayPoolId");return (<FormProvider {...form}><form onSubmit={handleSubmit(onSubmit)}>{!isUpdate && <GenericAppConnectionsFields />}+ <OrgPermissionCan+ I={OrgGatewayPermissionActions.AttachGateways}+ a={OrgPermissionSubjects.Gateway}+ >+ {(isAllowed) => (+ <Field className="mb-4">+ <FieldLabel>Gateway</FieldLabel>+ {isAllowed ? (+ <GatewayPicker+ isDisabled={!isAllowed}+ value={{ gatewayId: gatewayId ?? null, gatewayPoolId: gatewayPoolId ?? null }}+ onChange={({ gatewayId: newGwId, gatewayPoolId: newPoolId }) => {+ setValue("gatewayId", newGwId, { shouldDirty: true });+ setValue("gatewayPoolId", newPoolId, { shouldDirty: true });+ }}+ />+ ) : (+ <Tooltip>+ <TooltipTrigger asChild>+ <div>+ <GatewayPicker+ isDisabled={!isAllowed}+ value={{+ gatewayId: gatewayId ?? null,+ gatewayPoolId: gatewayPoolId ?? null+ }}+ onChange={({ gatewayId: newGwId, gatewayPoolId: newPoolId }) => {+ setValue("gatewayId", newGwId, { shouldDirty: true });+ setValue("gatewayPoolId", newPoolId, { shouldDirty: true });+ }}+ />+ </div>+ </TooltipTrigger>+ <TooltipContent>+ Restricted access. You don't have permission to attach gateways to+ resources.+ </TooltipContent>+ </Tooltip>+ )}+ </Field>+ )}+ </OrgPermissionCan><Controllername="credentials.serverUrl"control={control}