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
refac: change rotation to use service accounts
adilson609dea873a03
diff --git a/backend/src/ee/routes/v2/secret-rotation-v2-routers/index.ts b/backend/src/ee/routes/v2/secret-rotation-v2-routers/index.tsindex 7799ef49c9..cade62b47d 100644--- a/backend/src/ee/routes/v2/secret-rotation-v2-routers/index.ts+++ b/backend/src/ee/routes/v2/secret-rotation-v2-routers/index.ts@@ -14,7 +14,7 @@ import { registerMsSqlCredentialsRotationRouter } from "./mssql-credentials-rotaimport { registerMySqlCredentialsRotationRouter } from "./mysql-credentials-rotation-router";import { registerOktaClientSecretRotationRouter } from "./okta-client-secret-rotation-router";import { registerOpenRouterApiKeyRotationRouter } from "./open-router-api-key-rotation-router";-import { registerOpenAIAdminApiKeyRotationRouter } from "./openai-admin-api-key-rotation-router";+import { registerOpenAIServiceAccountRotationRouter } from "./openai-service-account-rotation-router";import { registerOracleDBCredentialsRotationRouter } from "./oracledb-credentials-rotation-router";import { registerPostgresCredentialsRotationRouter } from "./postgres-credentials-rotation-router";import { registerRedisCredentialsRotationRouter } from "./redis-credentials-rotation-router";@@ -45,7 +45,7 @@ export const SECRET_ROTATION_REGISTER_ROUTER_MAP: Record<[SecretRotation.DbtServiceToken]: registerDbtServiceTokenRotationRouter,[SecretRotation.WindowsLocalAccount]: registerWindowsLocalAccountRotationRouter,[SecretRotation.OpenRouterApiKey]: registerOpenRouterApiKeyRotationRouter,- [SecretRotation.OpenAIAdminApiKey]: registerOpenAIAdminApiKeyRotationRouter,+ [SecretRotation.OpenAIServiceAccount]: registerOpenAIServiceAccountRotationRouter,[SecretRotation.HpIloLocalAccount]: registerHpIloRotationRouter,[SecretRotation.SupabaseApiKey]: registerSupabaseApiKeyRotationRouter,[SecretRotation.SalesforceOauthCredentials]: registerSalesforceOauthCredentialsRotationRouter,diff --git a/backend/src/ee/routes/v2/secret-rotation-v2-routers/openai-admin-api-key-rotation-router.ts b/backend/src/ee/routes/v2/secret-rotation-v2-routers/openai-admin-api-key-rotation-router.tsdeleted file mode 100644index 6e4bdf62ec..0000000000--- a/backend/src/ee/routes/v2/secret-rotation-v2-routers/openai-admin-api-key-rotation-router.ts+++ /dev/null@@ -1,19 +0,0 @@-import {- CreateOpenAIAdminApiKeyRotationSchema,- OpenAIAdminApiKeyRotationGeneratedCredentialsSchema,- OpenAIAdminApiKeyRotationSchema,- UpdateOpenAIAdminApiKeyRotationSchema-} from "@app/ee/services/secret-rotation-v2/openai-admin-api-key";-import { SecretRotation } from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-enums";--import { registerSecretRotationEndpoints } from "./secret-rotation-v2-endpoints";--export const registerOpenAIAdminApiKeyRotationRouter = async (server: FastifyZodProvider) =>- registerSecretRotationEndpoints({- type: SecretRotation.OpenAIAdminApiKey,- server,- responseSchema: OpenAIAdminApiKeyRotationSchema,- createSchema: CreateOpenAIAdminApiKeyRotationSchema,- updateSchema: UpdateOpenAIAdminApiKeyRotationSchema,- generatedCredentialsSchema: OpenAIAdminApiKeyRotationGeneratedCredentialsSchema- });diff --git a/backend/src/ee/routes/v2/secret-rotation-v2-routers/openai-service-account-rotation-router.ts b/backend/src/ee/routes/v2/secret-rotation-v2-routers/openai-service-account-rotation-router.tsnew file mode 100644index 0000000000..4addb82508--- /dev/null+++ b/backend/src/ee/routes/v2/secret-rotation-v2-routers/openai-service-account-rotation-router.ts@@ -0,0 +1,19 @@+import {+ CreateOpenAIServiceAccountRotationSchema,+ OpenAIServiceAccountRotationGeneratedCredentialsSchema,+ OpenAIServiceAccountRotationSchema,+ UpdateOpenAIServiceAccountRotationSchema+} from "@app/ee/services/secret-rotation-v2/openai-service-account";+import { SecretRotation } from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-enums";++import { registerSecretRotationEndpoints } from "./secret-rotation-v2-endpoints";++export const registerOpenAIServiceAccountRotationRouter = async (server: FastifyZodProvider) =>+ registerSecretRotationEndpoints({+ type: SecretRotation.OpenAIServiceAccount,+ server,+ responseSchema: OpenAIServiceAccountRotationSchema,+ createSchema: CreateOpenAIServiceAccountRotationSchema,+ updateSchema: UpdateOpenAIServiceAccountRotationSchema,+ generatedCredentialsSchema: OpenAIServiceAccountRotationGeneratedCredentialsSchema+ });diff --git a/backend/src/ee/routes/v2/secret-rotation-v2-routers/secret-rotation-v2-router.ts b/backend/src/ee/routes/v2/secret-rotation-v2-routers/secret-rotation-v2-router.tsindex 7808b27ded..96698a7730 100644--- a/backend/src/ee/routes/v2/secret-rotation-v2-routers/secret-rotation-v2-router.ts+++ b/backend/src/ee/routes/v2/secret-rotation-v2-routers/secret-rotation-v2-router.ts@@ -15,7 +15,7 @@ import { MsSqlCredentialsRotationListItemSchema } from "@app/ee/services/secret-import { MySqlCredentialsRotationListItemSchema } from "@app/ee/services/secret-rotation-v2/mysql-credentials";import { OktaClientSecretRotationListItemSchema } from "@app/ee/services/secret-rotation-v2/okta-client-secret";import { OpenRouterApiKeyRotationListItemSchema } from "@app/ee/services/secret-rotation-v2/open-router-api-key";-import { OpenAIAdminApiKeyRotationListItemSchema } from "@app/ee/services/secret-rotation-v2/openai-admin-api-key";+import { OpenAIServiceAccountRotationListItemSchema } from "@app/ee/services/secret-rotation-v2/openai-service-account";import { OracleDBCredentialsRotationListItemSchema } from "@app/ee/services/secret-rotation-v2/oracledb-credentials";import { PostgresCredentialsRotationListItemSchema } from "@app/ee/services/secret-rotation-v2/postgres-credentials";import { RedisCredentialsRotationListItemSchema } from "@app/ee/services/secret-rotation-v2/redis-credentials";@@ -46,7 +46,7 @@ const SecretRotationV2OptionsSchema = z.discriminatedUnion("type", [DbtServiceTokenRotationListItemSchema,WindowsLocalAccountRotationListItemSchema,OpenRouterApiKeyRotationListItemSchema,- OpenAIAdminApiKeyRotationListItemSchema,+ OpenAIServiceAccountRotationListItemSchema,HpIloRotationListItemSchema,SupabaseApiKeyRotationListItemSchema,SalesforceOauthCredentialsRotationListItemSchema,diff --git a/backend/src/ee/services/secret-rotation-v2/openai-admin-api-key/index.ts b/backend/src/ee/services/secret-rotation-v2/openai-admin-api-key/index.tsdeleted file mode 100644index 6696466853..0000000000--- a/backend/src/ee/services/secret-rotation-v2/openai-admin-api-key/index.ts+++ /dev/null@@ -1,3 +0,0 @@-export * from "./openai-admin-api-key-rotation-constants";-export * from "./openai-admin-api-key-rotation-schemas";-export * from "./openai-admin-api-key-rotation-types";diff --git a/backend/src/ee/services/secret-rotation-v2/openai-admin-api-key/openai-admin-api-key-rotation-fns.ts b/backend/src/ee/services/secret-rotation-v2/openai-admin-api-key/openai-admin-api-key-rotation-fns.tsdeleted file mode 100644index f2d752a2cd..0000000000--- a/backend/src/ee/services/secret-rotation-v2/openai-admin-api-key/openai-admin-api-key-rotation-fns.ts+++ /dev/null@@ -1,179 +0,0 @@-import { AxiosError } from "axios";--import {- TRotationFactory,- TRotationFactoryCheckActiveCredentials,- TRotationFactoryGetSecretsPayload,- TRotationFactoryIssueCredentials,- TRotationFactoryRevokeCredentials,- TRotationFactoryRotateCredentials-} from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-types";-import { request } from "@app/lib/config/request";-import { BadRequestError } from "@app/lib/errors";-import { OPENAI_API_BASE_URL, verifyOpenAIAdminApiKey } from "@app/services/app-connection/openai";--import {- TOpenAIAdminApiKeyCreateResponse,- TOpenAIAdminApiKeyRotationGeneratedCredentials,- TOpenAIAdminApiKeyRotationWithConnection-} from "./openai-admin-api-key-rotation-types";--type OpenAIErrorResponse = { error?: { message: string; type?: string; code?: string } };--const isOpenAIErrorResponse = (data: unknown): data is OpenAIErrorResponse => {- return typeof data === "object" && data !== null && "error" in data;-};--const createErrorMessage = (error: unknown) => {- if (error instanceof AxiosError) {- if (error.response?.data && isOpenAIErrorResponse(error.response.data)) {- const openAIError = error.response.data;- if (openAIError.error?.message) {- return openAIError.error.message;- }- }- if (error.message) {- return error.message;- }- }- return "Unknown error";-};--export const openAIAdminApiKeyRotationFactory: TRotationFactory<- TOpenAIAdminApiKeyRotationWithConnection,- TOpenAIAdminApiKeyRotationGeneratedCredentials-> = (secretRotation) => {- const {- connection,- parameters: { name },- secretsMapping- } = secretRotation;-- const provisioningApiKey = connection.credentials.apiKey;-- const provisioningHeaders = {- Authorization: `Bearer ${provisioningApiKey}`,- "Content-Type": "application/json"- };-- /**- * Creates a new admin API key via the OpenAI Admin API.- */- const $createApiKey = async () => {- try {- const keyName = `${name}-${Date.now()}`;-- const { data } = await request.post<TOpenAIAdminApiKeyCreateResponse>(- `${OPENAI_API_BASE_URL}/organization/admin_api_keys`,- { name: keyName },- { headers: provisioningHeaders }- );-- if (!data.value || !data.id) {- throw new Error("Invalid response from OpenAI: missing 'value' or 'id'.");- }-- return {- apiKey: data.value,- keyId: data.id- };- } catch (error: unknown) {- throw new BadRequestError({- message: `Failed to create OpenAI admin API key: ${createErrorMessage(error)}`- });- }- };-- /**- * Deletes an admin API key via the OpenAI Admin API.- */- const $deleteApiKey = async (keyId: string) => {- try {- await request.delete(`${OPENAI_API_BASE_URL}/organization/admin_api_keys/${keyId}`, {- headers: provisioningHeaders- });- } catch (error: unknown) {- // If key doesn't exist (404), consider it already deleted- if (error instanceof AxiosError && error.response?.status === 404) {- return;- }-- throw new BadRequestError({- message: `Failed to delete OpenAI admin API key: ${createErrorMessage(error)}`- });- }- };-- /**- * Issues a new set of credentials.- */- const issueCredentials: TRotationFactoryIssueCredentials<TOpenAIAdminApiKeyRotationGeneratedCredentials> = async (- callback- ) => {- const credentials = await $createApiKey();- return callback(credentials);- };-- /**- * Revokes a list of credentials.- */- const revokeCredentials: TRotationFactoryRevokeCredentials<TOpenAIAdminApiKeyRotationGeneratedCredentials> = async (- credentials,- callback- ) => {- if (!credentials?.length) return callback();-- await Promise.all(credentials.map(({ keyId }) => $deleteApiKey(keyId)));-- return callback();- };-- /**- * Rotates credentials by issuing new ones and revoking the old.- */- const rotateCredentials: TRotationFactoryRotateCredentials<TOpenAIAdminApiKeyRotationGeneratedCredentials> = async (- oldCredentials,- callback- ) => {- // First create the new credentials- const newCredentials = await $createApiKey();-- // Store the new credentials via callback- const result = await callback(newCredentials);-- // Then delete the old key if it exists- if (oldCredentials?.keyId) {- await $deleteApiKey(oldCredentials.keyId);- }-- return result;- };-- /**- * Maps the generated credentials into the secret payload format.- */- const getSecretsPayload: TRotationFactoryGetSecretsPayload<TOpenAIAdminApiKeyRotationGeneratedCredentials> = ({- apiKey- }) => [{ key: secretsMapping.apiKey, value: apiKey }];-- const checkActiveCredentials: TRotationFactoryCheckActiveCredentials<- TOpenAIAdminApiKeyRotationGeneratedCredentials- > = async ({ apiKey }) => {- try {- // A valid admin key can list admin keys; a 200 confirms the rotated key is still active.- await verifyOpenAIAdminApiKey(apiKey);- } catch (error: unknown) {- throw new BadRequestError({- message: `OpenAI admin API key verification failed: ${createErrorMessage(error)}`- });- }- };-- return {- issueCredentials,- revokeCredentials,- rotateCredentials,- getSecretsPayload,- checkActiveCredentials- };-};diff --git a/backend/src/ee/services/secret-rotation-v2/openai-admin-api-key/openai-admin-api-key-rotation-schemas.ts b/backend/src/ee/services/secret-rotation-v2/openai-admin-api-key/openai-admin-api-key-rotation-schemas.tsdeleted file mode 100644index 90a6fc957a..0000000000--- a/backend/src/ee/services/secret-rotation-v2/openai-admin-api-key/openai-admin-api-key-rotation-schemas.ts+++ /dev/null@@ -1,72 +0,0 @@-import { z } from "zod";--import { SecretRotation } from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-enums";-import {- BaseCreateSecretRotationSchema,- BaseSecretRotationSchema,- BaseUpdateSecretRotationSchema-} from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-schemas";-import { SecretRotations } from "@app/lib/api-docs";-import { SecretNameSchema } from "@app/server/lib/schemas";-import { AppConnection } from "@app/services/app-connection/app-connection-enums";--export const OpenAIAdminApiKeyRotationGeneratedCredentialsSchema = z- .object({- apiKey: z.string(),- keyId: z.string()- })- .array()- .min(1)- .max(2);--/** Max length for the user-provided base name; the created key name also gets a `-<timestamp>` suffix. */-export const OPENAI_ADMIN_API_KEY_NAME_MAX_LENGTH = 100;--const OpenAIAdminApiKeyRotationParametersSchema = z.object({- name: z- .string()- .trim()- .min(1, "Key name required")- .max(- OPENAI_ADMIN_API_KEY_NAME_MAX_LENGTH,- `Key name must be ${OPENAI_ADMIN_API_KEY_NAME_MAX_LENGTH} characters or fewer`- )- .describe(SecretRotations.PARAMETERS.OPENAI_ADMIN_API_KEY.name)-});--const OpenAIAdminApiKeyRotationSecretsMappingSchema = z.object({- apiKey: SecretNameSchema.describe(SecretRotations.SECRETS_MAPPING.OPENAI_ADMIN_API_KEY.apiKey)-});--export const OpenAIAdminApiKeyRotationTemplateSchema = z.object({- secretsMapping: z.object({- apiKey: z.string()- })-});--export const OpenAIAdminApiKeyRotationSchema = BaseSecretRotationSchema(SecretRotation.OpenAIAdminApiKey).extend({- type: z.literal(SecretRotation.OpenAIAdminApiKey),- parameters: OpenAIAdminApiKeyRotationParametersSchema,- secretsMapping: OpenAIAdminApiKeyRotationSecretsMappingSchema-});--export const CreateOpenAIAdminApiKeyRotationSchema = BaseCreateSecretRotationSchema(- SecretRotation.OpenAIAdminApiKey-).extend({- parameters: OpenAIAdminApiKeyRotationParametersSchema,- secretsMapping: OpenAIAdminApiKeyRotationSecretsMappingSchema-});--export const UpdateOpenAIAdminApiKeyRotationSchema = BaseUpdateSecretRotationSchema(- SecretRotation.OpenAIAdminApiKey-).extend({- parameters: OpenAIAdminApiKeyRotationParametersSchema.optional(),- secretsMapping: OpenAIAdminApiKeyRotationSecretsMappingSchema.optional()-});--export const OpenAIAdminApiKeyRotationListItemSchema = z.object({- name: z.literal("OpenAI Admin API Key"),- connection: z.literal(AppConnection.OpenAI),- type: z.literal(SecretRotation.OpenAIAdminApiKey),- template: OpenAIAdminApiKeyRotationTemplateSchema-});diff --git a/backend/src/ee/services/secret-rotation-v2/openai-admin-api-key/openai-admin-api-key-rotation-types.ts b/backend/src/ee/services/secret-rotation-v2/openai-admin-api-key/openai-admin-api-key-rotation-types.tsdeleted file mode 100644index b62191c5e0..0000000000--- a/backend/src/ee/services/secret-rotation-v2/openai-admin-api-key/openai-admin-api-key-rotation-types.ts+++ /dev/null@@ -1,41 +0,0 @@-import { z } from "zod";--import { TOpenAIConnection } from "@app/services/app-connection/openai";--import {- CreateOpenAIAdminApiKeyRotationSchema,- OpenAIAdminApiKeyRotationGeneratedCredentialsSchema,- OpenAIAdminApiKeyRotationListItemSchema,- OpenAIAdminApiKeyRotationSchema-} from "./openai-admin-api-key-rotation-schemas";--export type TOpenAIAdminApiKeyRotation = z.infer<typeof OpenAIAdminApiKeyRotationSchema>;--export type TOpenAIAdminApiKeyRotationInput = z.infer<typeof CreateOpenAIAdminApiKeyRotationSchema>;--export type TOpenAIAdminApiKeyRotationListItem = z.infer<typeof OpenAIAdminApiKeyRotationListItemSchema>;--export type TOpenAIAdminApiKeyRotationWithConnection = TOpenAIAdminApiKeyRotation & {- connection: TOpenAIConnection;-};--export type TOpenAIAdminApiKeyRotationGeneratedCredentials = z.infer<- typeof OpenAIAdminApiKeyRotationGeneratedCredentialsSchema->;--export interface TOpenAIAdminApiKeyRotationParameters {- name: string;-}--export interface TOpenAIAdminApiKeyRotationSecretsMapping {- apiKey: string;-}--export interface TOpenAIAdminApiKeyCreateResponse {- object: string;- id: string;- name: string;- redacted_value: string;- value: string;- created_at: number;-}diff --git a/backend/src/ee/services/secret-rotation-v2/openai-service-account/index.ts b/backend/src/ee/services/secret-rotation-v2/openai-service-account/index.tsnew file mode 100644index 0000000000..4daaff232f--- /dev/null+++ b/backend/src/ee/services/secret-rotation-v2/openai-service-account/index.ts@@ -0,0 +1,3 @@+export * from "./openai-service-account-rotation-constants";+export * from "./openai-service-account-rotation-schemas";+export * from "./openai-service-account-rotation-types";diff --git a/backend/src/ee/services/secret-rotation-v2/openai-admin-api-key/openai-admin-api-key-rotation-constants.ts b/backend/src/ee/services/secret-rotation-v2/openai-service-account/openai-service-account-rotation-constants.tssimilarity index 65%rename from backend/src/ee/services/secret-rotation-v2/openai-admin-api-key/openai-admin-api-key-rotation-constants.tsrename to backend/src/ee/services/secret-rotation-v2/openai-service-account/openai-service-account-rotation-constants.tsindex f7dbb4ddc4..6f9ff74d6e 100644--- a/backend/src/ee/services/secret-rotation-v2/openai-admin-api-key/openai-admin-api-key-rotation-constants.ts+++ b/backend/src/ee/services/secret-rotation-v2/openai-service-account/openai-service-account-rotation-constants.ts@@ -2,13 +2,13 @@ import { SecretRotation } from "@app/ee/services/secret-rotation-v2/secret-rotatimport { TSecretRotationV2ListItem } from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-types";import { AppConnection } from "@app/services/app-connection/app-connection-enums";-export const OPENAI_ADMIN_API_KEY_ROTATION_LIST_OPTION: TSecretRotationV2ListItem = {- name: "OpenAI Admin API Key",- type: SecretRotation.OpenAIAdminApiKey,+export const OPENAI_SERVICE_ACCOUNT_ROTATION_LIST_OPTION: TSecretRotationV2ListItem = {+ name: "OpenAI Service Account",+ type: SecretRotation.OpenAIServiceAccount,connection: AppConnection.OpenAI,template: {secretsMapping: {- apiKey: "OPENAI_ADMIN_API_KEY"+ apiKey: "OPENAI_API_KEY"}}};diff --git a/backend/src/ee/services/secret-rotation-v2/openai-service-account/openai-service-account-rotation-fns.ts b/backend/src/ee/services/secret-rotation-v2/openai-service-account/openai-service-account-rotation-fns.tsnew file mode 100644index 0000000000..f88e6f5d42--- /dev/null+++ b/backend/src/ee/services/secret-rotation-v2/openai-service-account/openai-service-account-rotation-fns.ts@@ -0,0 +1,185 @@+import { AxiosError } from "axios";++import {+ TRotationFactory,+ TRotationFactoryCheckActiveCredentials,+ TRotationFactoryGetSecretsPayload,+ TRotationFactoryIssueCredentials,+ TRotationFactoryRevokeCredentials,+ TRotationFactoryRotateCredentials+} from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-types";+import { request } from "@app/lib/config/request";+import { BadRequestError } from "@app/lib/errors";+import { OPENAI_API_BASE_URL } from "@app/services/app-connection/openai";++import {+ TOpenAIServiceAccountCreateResponse,+ TOpenAIServiceAccountRotationGeneratedCredentials,+ TOpenAIServiceAccountRotationWithConnection+} from "./openai-service-account-rotation-types";++type OpenAIErrorResponse = { error?: { message: string; type?: string; code?: string } };++const isOpenAIErrorResponse = (data: unknown): data is OpenAIErrorResponse => {+ return typeof data === "object" && data !== null && "error" in data;+};++const createErrorMessage = (error: unknown) => {+ if (error instanceof AxiosError) {+ if (error.response?.data && isOpenAIErrorResponse(error.response.data)) {+ const openAIError = error.response.data;+ if (openAIError.error?.message) {+ return openAIError.error.message;+ }+ }+ if (error.message) {+ return error.message;+ }+ }+ return "Unknown error";+};++export const openAIServiceAccountRotationFactory: TRotationFactory<+ TOpenAIServiceAccountRotationWithConnection,+ TOpenAIServiceAccountRotationGeneratedCredentials+> = (secretRotation) => {+ const {+ connection,+ parameters: { projectId, name },+ secretsMapping+ } = secretRotation;++ const provisioningApiKey = connection.credentials.apiKey;++ const provisioningHeaders = {+ Authorization: `Bearer ${provisioningApiKey}`,+ "Content-Type": "application/json"+ };++ /**+ * Creates a new project service account via the OpenAI Admin API. Its API key is+ * returned only once in the create response.+ */+ const $createServiceAccount = async () => {+ try {+ const serviceAccountName = `${name}-${Date.now()}`;++ const { data } = await request.post<TOpenAIServiceAccountCreateResponse>(+ `${OPENAI_API_BASE_URL}/organization/projects/${projectId}/service_accounts`,+ { name: serviceAccountName },+ { headers: provisioningHeaders }+ );++ if (!data.api_key?.value || !data.id) {+ throw new Error("Invalid response from OpenAI: missing service account 'id' or 'api_key.value'.");+ }++ return {+ apiKey: data.api_key.value,+ serviceAccountId: data.id+ };+ } catch (error: unknown) {+ throw new BadRequestError({+ message: `Failed to create OpenAI service account: ${createErrorMessage(error)}`+ });+ }+ };++ /**+ * Deletes a project service account via the OpenAI Admin API. Deleting the service+ * account also invalidates its API key.+ */+ const $deleteServiceAccount = async (serviceAccountId: string) => {+ try {+ await request.delete(+ `${OPENAI_API_BASE_URL}/organization/projects/${projectId}/service_accounts/${serviceAccountId}`,+ {+ headers: provisioningHeaders+ }+ );+ } catch (error: unknown) {+ // If the service account doesn't exist (404), consider it already deleted+ if (error instanceof AxiosError && error.response?.status === 404) {+ return;+ }++ throw new BadRequestError({+ message: `Failed to delete OpenAI service account: ${createErrorMessage(error)}`+ });+ }+ };++ /**+ * Issues a new set of credentials.+ */+ const issueCredentials: TRotationFactoryIssueCredentials<TOpenAIServiceAccountRotationGeneratedCredentials> = async (+ callback+ ) => {+ const credentials = await $createServiceAccount();+ return callback(credentials);+ };++ /**+ * Revokes a list of credentials.+ */+ const revokeCredentials: TRotationFactoryRevokeCredentials<+ TOpenAIServiceAccountRotationGeneratedCredentials+ > = async (credentials, callback) => {+ if (!credentials?.length) return callback();++ await Promise.all(credentials.map(({ serviceAccountId }) => $deleteServiceAccount(serviceAccountId)));++ return callback();+ };++ /**+ * Rotates credentials by issuing new ones and revoking the old.+ */+ const rotateCredentials: TRotationFactoryRotateCredentials<+ TOpenAIServiceAccountRotationGeneratedCredentials+ > = async (oldCredentials, callback) => {+ // First create the new credentials+ const newCredentials = await $createServiceAccount();++ // Store the new credentials via callback+ const result = await callback(newCredentials);++ // Then delete the old service account if it exists+ if (oldCredentials?.serviceAccountId) {+ await $deleteServiceAccount(oldCredentials.serviceAccountId);+ }++ return result;+ };++ /**+ * Maps the generated credentials into the secret payload format.+ */+ const getSecretsPayload: TRotationFactoryGetSecretsPayload<TOpenAIServiceAccountRotationGeneratedCredentials> = ({+ apiKey+ }) => [{ key: secretsMapping.apiKey, value: apiKey }];++ const checkActiveCredentials: TRotationFactoryCheckActiveCredentials<+ TOpenAIServiceAccountRotationGeneratedCredentials+ > = async ({ apiKey }) => {+ try {+ // A valid service account key can list models; a 200 confirms the rotated key is still active.+ await request.get(`${OPENAI_API_BASE_URL}/models`, {+ headers: { Authorization: `Bearer ${apiKey}` },+ validateStatus: (status) => status === 200+ });+ } catch (error: unknown) {+ throw new BadRequestError({+ message: `OpenAI service account key verification failed: ${createErrorMessage(error)}`+ });+ }+ };++ return {+ issueCredentials,+ revokeCredentials,+ rotateCredentials,+ getSecretsPayload,+ checkActiveCredentials+ };+};diff --git a/backend/src/ee/services/secret-rotation-v2/openai-service-account/openai-service-account-rotation-schemas.ts b/backend/src/ee/services/secret-rotation-v2/openai-service-account/openai-service-account-rotation-schemas.tsnew file mode 100644index 0000000000..942d87fa0f--- /dev/null+++ b/backend/src/ee/services/secret-rotation-v2/openai-service-account/openai-service-account-rotation-schemas.ts@@ -0,0 +1,77 @@+import { z } from "zod";++import { SecretRotation } from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-enums";+import {+ BaseCreateSecretRotationSchema,+ BaseSecretRotationSchema,+ BaseUpdateSecretRotationSchema+} from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-schemas";+import { SecretRotations } from "@app/lib/api-docs";+import { SecretNameSchema } from "@app/server/lib/schemas";+import { AppConnection } from "@app/services/app-connection/app-connection-enums";++export const OpenAIServiceAccountRotationGeneratedCredentialsSchema = z+ .object({+ apiKey: z.string(),+ serviceAccountId: z.string()+ })+ .array()+ .min(1)+ .max(2);++/** Max length for the user-provided base name; the created service account name also gets a `-<timestamp>` suffix. */+export const OPENAI_SERVICE_ACCOUNT_NAME_MAX_LENGTH = 100;++const OpenAIServiceAccountRotationParametersSchema = z.object({+ projectId: z+ .string()+ .trim()+ .min(1, "Project ID required")+ .describe(SecretRotations.PARAMETERS.OPENAI_SERVICE_ACCOUNT.projectId),+ name: z+ .string()+ .trim()+ .min(1, "Service account name required")+ .max(+ OPENAI_SERVICE_ACCOUNT_NAME_MAX_LENGTH,+ `Service account name must be ${OPENAI_SERVICE_ACCOUNT_NAME_MAX_LENGTH} characters or fewer`+ )+ .describe(SecretRotations.PARAMETERS.OPENAI_SERVICE_ACCOUNT.name)+});++const OpenAIServiceAccountRotationSecretsMappingSchema = z.object({+ apiKey: SecretNameSchema.describe(SecretRotations.SECRETS_MAPPING.OPENAI_SERVICE_ACCOUNT.apiKey)+});++export const OpenAIServiceAccountRotationTemplateSchema = z.object({+ secretsMapping: z.object({+ apiKey: z.string()+ })+});++export const OpenAIServiceAccountRotationSchema = BaseSecretRotationSchema(SecretRotation.OpenAIServiceAccount).extend({+ type: z.literal(SecretRotation.OpenAIServiceAccount),+ parameters: OpenAIServiceAccountRotationParametersSchema,+ secretsMapping: OpenAIServiceAccountRotationSecretsMappingSchema+});++export const CreateOpenAIServiceAccountRotationSchema = BaseCreateSecretRotationSchema(+ SecretRotation.OpenAIServiceAccount+).extend({+ parameters: OpenAIServiceAccountRotationParametersSchema,+ secretsMapping: OpenAIServiceAccountRotationSecretsMappingSchema+});++export const UpdateOpenAIServiceAccountRotationSchema = BaseUpdateSecretRotationSchema(+ SecretRotation.OpenAIServiceAccount+).extend({+ parameters: OpenAIServiceAccountRotationParametersSchema.optional(),+ secretsMapping: OpenAIServiceAccountRotationSecretsMappingSchema.optional()+});++export const OpenAIServiceAccountRotationListItemSchema = z.object({+ name: z.literal("OpenAI Service Account"),+ connection: z.literal(AppConnection.OpenAI),+ type: z.literal(SecretRotation.OpenAIServiceAccount),+ template: OpenAIServiceAccountRotationTemplateSchema+});diff --git a/backend/src/ee/services/secret-rotation-v2/openai-service-account/openai-service-account-rotation-types.ts b/backend/src/ee/services/secret-rotation-v2/openai-service-account/openai-service-account-rotation-types.tsnew file mode 100644index 0000000000..384296752a--- /dev/null+++ b/backend/src/ee/services/secret-rotation-v2/openai-service-account/openai-service-account-rotation-types.ts@@ -0,0 +1,48 @@+import { z } from "zod";++import { TOpenAIConnection } from "@app/services/app-connection/openai";++import {+ CreateOpenAIServiceAccountRotationSchema,+ OpenAIServiceAccountRotationGeneratedCredentialsSchema,+ OpenAIServiceAccountRotationListItemSchema,+ OpenAIServiceAccountRotationSchema+} from "./openai-service-account-rotation-schemas";++export type TOpenAIServiceAccountRotation = z.infer<typeof OpenAIServiceAccountRotationSchema>;++export type TOpenAIServiceAccountRotationInput = z.infer<typeof CreateOpenAIServiceAccountRotationSchema>;++export type TOpenAIServiceAccountRotationListItem = z.infer<typeof OpenAIServiceAccountRotationListItemSchema>;++export type TOpenAIServiceAccountRotationWithConnection = TOpenAIServiceAccountRotation & {+ connection: TOpenAIConnection;+};++export type TOpenAIServiceAccountRotationGeneratedCredentials = z.infer<+ typeof OpenAIServiceAccountRotationGeneratedCredentialsSchema+>;++export interface TOpenAIServiceAccountRotationParameters {+ projectId: string;+ name: string;+}++export interface TOpenAIServiceAccountRotationSecretsMapping {+ apiKey: string;+}++export interface TOpenAIServiceAccountCreateResponse {+ object: string;+ id: string;+ name: string;+ role: string;+ created_at: number;+ api_key: {+ object: string;+ id: string;+ name: string;+ value: string;+ created_at: number;+ };+}diff --git a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-enums.ts b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-enums.tsindex 1bfa235a50..d3f7b9b911 100644--- a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-enums.ts+++ b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-enums.ts@@ -15,7 +15,7 @@ export enum SecretRotation {DbtServiceToken = "dbt-service-token",WindowsLocalAccount = "windows-local-account",OpenRouterApiKey = "open-router-api-key",- OpenAIAdminApiKey = "openai-admin-api-key",+ OpenAIServiceAccount = "openai-service-account",HpIloLocalAccount = "hp-ilo-local-account",SupabaseApiKey = "supabase-api-key",SalesforceOauthCredentials = "salesforce-oauth-credentials",diff --git a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-fns.ts b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-fns.tsindex 1ef6ecca2d..f800d0481f 100644--- a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-fns.ts+++ b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-fns.ts@@ -23,7 +23,7 @@ import { MSSQL_CREDENTIALS_ROTATION_LIST_OPTION } from "./mssql-credentials";import { MYSQL_CREDENTIALS_ROTATION_LIST_OPTION } from "./mysql-credentials";import { OKTA_CLIENT_SECRET_ROTATION_LIST_OPTION } from "./okta-client-secret";import { OPEN_ROUTER_API_KEY_ROTATION_LIST_OPTION } from "./open-router-api-key";-import { OPENAI_ADMIN_API_KEY_ROTATION_LIST_OPTION } from "./openai-admin-api-key";+import { OPENAI_SERVICE_ACCOUNT_ROTATION_LIST_OPTION, TOpenAIServiceAccountRotation } from "./openai-service-account";import { ORACLEDB_CREDENTIALS_ROTATION_LIST_OPTION } from "./oracledb-credentials";import { POSTGRES_CREDENTIALS_ROTATION_LIST_OPTION } from "./postgres-credentials";import { REDIS_CREDENTIALS_ROTATION_LIST_OPTION } from "./redis-credentials";@@ -66,7 +66,7 @@ const SECRET_ROTATION_LIST_OPTIONS: Record<SecretRotation, TSecretRotationV2List[SecretRotation.DbtServiceToken]: DBT_SERVICE_TOKEN_ROTATION_LIST_OPTION,[SecretRotation.WindowsLocalAccount]: WINDOWS_LOCAL_ACCOUNT_ROTATION_LIST_OPTION,[SecretRotation.OpenRouterApiKey]: OPEN_ROUTER_API_KEY_ROTATION_LIST_OPTION,- [SecretRotation.OpenAIAdminApiKey]: OPENAI_ADMIN_API_KEY_ROTATION_LIST_OPTION,+ [SecretRotation.OpenAIServiceAccount]: OPENAI_SERVICE_ACCOUNT_ROTATION_LIST_OPTION,[SecretRotation.HpIloLocalAccount]: HP_ILO_ROTATION_LIST_OPTION,[SecretRotation.SupabaseApiKey]: SUPABASE_API_KEY_ROTATION_LIST_OPTION,[SecretRotation.SalesforceOauthCredentials]: SALESFORCE_OAUTH_CREDENTIALS_ROTATION_LIST_OPTION,@@ -394,6 +394,17 @@ export const throwOnImmutableParameterUpdate = (throw new BadRequestError({ message: "Cannot update service account ID" });}break;+ case SecretRotation.OpenAIServiceAccount:+ if (+ haveUnequalProperties(+ updatePayload.parameters as TOpenAIServiceAccountRotation["parameters"],+ secretRotation.parameters as TOpenAIServiceAccountRotation["parameters"],+ ["projectId"]+ )+ ) {+ throw new BadRequestError({ message: "Cannot update project ID" });+ }+ break;default:// do nothing}diff --git a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-maps.ts b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-maps.tsindex ca17ea39f7..f7e89d876d 100644--- a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-maps.ts+++ b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-maps.ts@@ -18,7 +18,7 @@ export const SECRET_ROTATION_NAME_MAP: Record<SecretRotation, string> = {[SecretRotation.DbtServiceToken]: "DBT Service Token",[SecretRotation.WindowsLocalAccount]: "Windows Local Account",[SecretRotation.OpenRouterApiKey]: "OpenRouter API Key",- [SecretRotation.OpenAIAdminApiKey]: "OpenAI Admin API Key",+ [SecretRotation.OpenAIServiceAccount]: "OpenAI Service Account",[SecretRotation.HpIloLocalAccount]: "HP iLO Local Account",[SecretRotation.SupabaseApiKey]: "Supabase API Key",[SecretRotation.SalesforceOauthCredentials]: "Salesforce OAuth Credentials",@@ -43,7 +43,7 @@ export const SECRET_ROTATION_CONNECTION_MAP: Record<SecretRotation, AppConnectio[SecretRotation.DbtServiceToken]: AppConnection.Dbt,[SecretRotation.WindowsLocalAccount]: AppConnection.SMB,[SecretRotation.OpenRouterApiKey]: AppConnection.OpenRouter,- [SecretRotation.OpenAIAdminApiKey]: AppConnection.OpenAI,+ [SecretRotation.OpenAIServiceAccount]: AppConnection.OpenAI,[SecretRotation.HpIloLocalAccount]: AppConnection.SSH,[SecretRotation.SupabaseApiKey]: AppConnection.Supabase,[SecretRotation.SalesforceOauthCredentials]: AppConnection.Salesforce,diff --git a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-service.ts b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-service.tsindex 1bb0c292ba..f6166a7957 100644--- a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-service.ts+++ b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-service.ts@@ -107,7 +107,7 @@ import { THpIloRotation, THpIloRotationGeneratedCredentials } from "./hp-ilo-rotimport { mongodbCredentialsRotationFactory } from "./mongodb-credentials/mongodb-credentials-rotation-fns";import { oktaClientSecretRotationFactory } from "./okta-client-secret/okta-client-secret-rotation-fns";import { openRouterApiKeyRotationFactory } from "./open-router-api-key/open-router-api-key-rotation-fns";-import { openAIAdminApiKeyRotationFactory } from "./openai-admin-api-key/openai-admin-api-key-rotation-fns";+import { openAIServiceAccountRotationFactory } from "./openai-service-account/openai-service-account-rotation-fns";import { redisCredentialsRotationFactory } from "./redis-credentials/redis-credentials-rotation-fns";import { TSecretRotationV2DALFactory } from "./secret-rotation-v2-dal";import { supabaseApiKeyRotationFactory } from "./supabase-api-key/supabase-api-key-rotation-fns";@@ -199,7 +199,7 @@ const SECRET_ROTATION_FACTORY_MAP: Record<SecretRotation, TRotationFactoryImplem[SecretRotation.DbtServiceToken]: dbtServiceTokenRotationFactory as TRotationFactoryImplementation,[SecretRotation.WindowsLocalAccount]: windowsLocalAccountRotationFactory as TRotationFactoryImplementation,[SecretRotation.OpenRouterApiKey]: openRouterApiKeyRotationFactory as TRotationFactoryImplementation,- [SecretRotation.OpenAIAdminApiKey]: openAIAdminApiKeyRotationFactory as TRotationFactoryImplementation,+ [SecretRotation.OpenAIServiceAccount]: openAIServiceAccountRotationFactory as TRotationFactoryImplementation,[SecretRotation.HpIloLocalAccount]: hpIloRotationFactory as TRotationFactoryImplementation,[SecretRotation.SupabaseApiKey]: supabaseApiKeyRotationFactory as TRotationFactoryImplementation,[SecretRotation.SalesforceOauthCredentials]:diff --git a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-types.ts b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-types.tsindex 0ed04a88b9..cd7d9d019b 100644--- a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-types.ts+++ b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-types.ts@@ -105,12 +105,12 @@ import {TOpenRouterApiKeyRotationWithConnection} from "./open-router-api-key";import {- TOpenAIAdminApiKeyRotation,- TOpenAIAdminApiKeyRotationGeneratedCredentials,- TOpenAIAdminApiKeyRotationInput,- TOpenAIAdminApiKeyRotationListItem,- TOpenAIAdminApiKeyRotationWithConnection-} from "./openai-admin-api-key";+ TOpenAIServiceAccountRotation,+ TOpenAIServiceAccountRotationGeneratedCredentials,+ TOpenAIServiceAccountRotationInput,+ TOpenAIServiceAccountRotationListItem,+ TOpenAIServiceAccountRotationWithConnection+} from "./openai-service-account";import {TOracleDBCredentialsRotation,TOracleDBCredentialsRotationInput,@@ -178,7 +178,7 @@ export type TSecretRotationV2 =| TDbtServiceTokenRotation| TWindowsLocalAccountRotation| TOpenRouterApiKeyRotation- | TOpenAIAdminApiKeyRotation+ | TOpenAIServiceAccountRotation| THpIloRotation| TSupabaseApiKeyRotation| TSalesforceOauthCredentialsRotation@@ -202,7 +202,7 @@ export type TSecretRotationV2WithConnection =| TDbtServiceTokenRotationWithConnection| TWindowsLocalAccountRotationWithConnection| TOpenRouterApiKeyRotationWithConnection- | TOpenAIAdminApiKeyRotationWithConnection+ | TOpenAIServiceAccountRotationWithConnection| THpIloRotationWithConnection| TSupabaseApiKeyRotationWithConnection| TSalesforceOauthCredentialsRotationWithConnection@@ -222,7 +222,7 @@ export type TSecretRotationV2GeneratedCredentials =| TDbtServiceTokenRotationGeneratedCredentials| TWindowsLocalAccountRotationGeneratedCredentials| TOpenRouterApiKeyRotationGeneratedCredentials- | TOpenAIAdminApiKeyRotationGeneratedCredentials+ | TOpenAIServiceAccountRotationGeneratedCredentials| THpIloRotationGeneratedCredentials| TSupabaseApiKeyRotationGeneratedCredentials| TSalesforceOauthCredentialsRotationGeneratedCredentials@@ -246,7 +246,7 @@ export type TSecretRotationV2Input =| TDbtServiceTokenRotationInput| TWindowsLocalAccountRotationInput| TOpenRouterApiKeyRotationInput- | TOpenAIAdminApiKeyRotationInput+ | TOpenAIServiceAccountRotationInput| THpIloRotationInput| TSupabaseApiKeyRotationInput| TSalesforceOauthCredentialsRotationInput@@ -270,7 +270,7 @@ export type TSecretRotationV2ListItem =| TDbtServiceTokenRotationListItem| TWindowsLocalAccountRotationListItem| TOpenRouterApiKeyRotationListItem- | TOpenAIAdminApiKeyRotationListItem+ | TOpenAIServiceAccountRotationListItem| THpIloRotationListItem| TSupabaseApiKeyRotationListItem| TSalesforceOauthCredentialsRotationListItemdiff --git a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-union-schema.ts b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-union-schema.tsindex 636fda37de..4fde3ce0dd 100644--- a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-union-schema.ts+++ b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-union-schema.ts@@ -11,7 +11,7 @@ import { MsSqlCredentialsRotationSchema } from "@app/ee/services/secret-rotationimport { MySqlCredentialsRotationSchema } from "@app/ee/services/secret-rotation-v2/mysql-credentials";import { OktaClientSecretRotationSchema } from "@app/ee/services/secret-rotation-v2/okta-client-secret";import { OpenRouterApiKeyRotationSchema } from "@app/ee/services/secret-rotation-v2/open-router-api-key";-import { OpenAIAdminApiKeyRotationSchema } from "@app/ee/services/secret-rotation-v2/openai-admin-api-key";+import { OpenAIServiceAccountRotationSchema } from "@app/ee/services/secret-rotation-v2/openai-service-account";import { OracleDBCredentialsRotationSchema } from "@app/ee/services/secret-rotation-v2/oracledb-credentials";import { PostgresCredentialsRotationSchema } from "@app/ee/services/secret-rotation-v2/postgres-credentials";import { RedisCredentialsRotationSchema } from "@app/ee/services/secret-rotation-v2/redis-credentials";@@ -41,7 +41,7 @@ export const SecretRotationV2Schema = z.discriminatedUnion("type", [DbtServiceTokenRotationSchema,WindowsLocalAccountRotationSchema,OpenRouterApiKeyRotationSchema,- OpenAIAdminApiKeyRotationSchema,+ OpenAIServiceAccountRotationSchema,HpIloRotationSchema,SupabaseApiKeyRotationSchema,SalesforceOauthCredentialsRotationSchema,diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.tsindex e61de909f2..0f3d2184f2 100644--- a/backend/src/lib/api-docs/constants.ts+++ b/backend/src/lib/api-docs/constants.ts@@ -2923,7 +2923,7 @@ export const AppConnections = {apiKey: "The OpenRouter Provisioning API key used to manage API keys."},OPENAI: {- apiKey: "The OpenAI Admin API key used to manage API keys."+ apiKey: "The OpenAI Admin API key used to manage project service accounts."},ANTHROPIC: {apiKey: "The Anthropic API key used to authenticate with the Anthropic API."@@ -3457,8 +3457,9 @@ export const SecretRotations = {includeByokInLimit:"Whether to include BYOK (Bring Your Own Key) usage in the spending limit. When enabled, usage from your own provider keys counts toward this key's limit. See OpenRouter BYOK docs for details."},- OPENAI_ADMIN_API_KEY: {- name: "The name for the generated OpenAI admin API key."+ OPENAI_SERVICE_ACCOUNT: {+ projectId: "The ID of the OpenAI project to create service accounts in.",+ name: "The name for the generated OpenAI service account."},SUPABASE_API_KEY: {projectRef: "The reference ID of the Supabase project to rotate the API key for.",@@ -3534,8 +3535,8 @@ export const SecretRotations = {OPEN_ROUTER_API_KEY: {apiKey: "The name of the secret that the rotated OpenRouter API key will be mapped to."},- OPENAI_ADMIN_API_KEY: {- apiKey: "The name of the secret that the rotated OpenAI admin API key will be mapped to."+ OPENAI_SERVICE_ACCOUNT: {+ apiKey: "The name of the secret that the rotated OpenAI service account API key will be mapped to."},SUPABASE_API_KEY: {apiKey: "The name of the secret that the rotated Supabase API key will be mapped to."diff --git a/backend/src/server/routes/v1/app-connection-routers/openai-connection-router.ts b/backend/src/server/routes/v1/app-connection-routers/openai-connection-router.tsindex 19b09b55b0..b1e4d94c49 100644--- a/backend/src/server/routes/v1/app-connection-routers/openai-connection-router.ts+++ b/backend/src/server/routes/v1/app-connection-routers/openai-connection-router.ts@@ -1,9 +1,14 @@+import { z } from "zod";++import { readLimit } from "@app/server/config/rateLimiter";+import { verifyAuth } from "@app/server/plugins/auth/verify-auth";import { AppConnection } from "@app/services/app-connection/app-connection-enums";import {CreateOpenAIConnectionSchema,SanitizedOpenAIConnectionSchema,UpdateOpenAIConnectionSchema} from "@app/services/app-connection/openai";+import { AuthMode } from "@app/services/auth/auth-type";import { registerAppConnectionEndpoints } from "./app-connection-endpoints";@@ -15,4 +20,33 @@ export const registerOpenAIConnectionRouter = async (server: FastifyZodProvider)createSchema: CreateOpenAIConnectionSchema,updateSchema: UpdateOpenAIConnectionSchema});++ // The below endpoints are not exposed and for Infisical App use++ server.route({+ method: "GET",+ url: `/:connectionId/projects`,+ config: {+ rateLimit: readLimit+ },+ schema: {+ operationId: "listOpenAIConnectionProjects",+ params: z.object({+ connectionId: z.string().uuid()+ }),+ response: {+ 200: z.object({+ projects: z.object({ id: z.string(), name: z.string() }).array()+ })+ }+ },+ onRequest: verifyAuth([AuthMode.JWT]),+ handler: async (req) => {+ const { connectionId } = req.params;++ const projects = await server.services.appConnection.openai.listProjects(connectionId, req.permission);++ return { projects };+ }+ });};diff --git a/backend/src/services/app-connection/app-connection-service.ts b/backend/src/services/app-connection/app-connection-service.tsindex 58ce98cbcf..119d99ebd8 100644--- a/backend/src/services/app-connection/app-connection-service.ts+++ b/backend/src/services/app-connection/app-connection-service.ts@@ -146,6 +146,7 @@ import { ValidateOnaConnectionCredentialsSchema } from "./ona";import { onaConnectionService } from "./ona/ona-connection-service";import { ValidateOpenRouterConnectionCredentialsSchema } from "./open-router";import { ValidateOpenAIConnectionCredentialsSchema } from "./openai";+import { openaiConnectionService } from "./openai/openai-connection-service";import { ValidateOvhConnectionCredentialsSchema } from "./ovh";import { ValidatePostgresConnectionCredentialsSchema } from "./postgres";import { ValidateQoveryConnectionCredentialsSchema } from "./qovery";@@ -1365,6 +1366,7 @@ export const appConnectionServiceFactory = ({externalInfisical: externalInfisicalConnectionService(connectAppConnectionById),okta: oktaConnectionService(connectAppConnectionById),datadog: datadogConnectionService(connectAppConnectionById),+ openai: openaiConnectionService(connectAppConnectionById),laravelForge: laravelForgeConnectionService(connectAppConnectionById),chef: chefConnectionService(connectAppConnectionById, licenseService),octopusDeploy: octopusDeployConnectionService(connectAppConnectionById),diff --git a/backend/src/services/app-connection/openai/openai-connection-fns.ts b/backend/src/services/app-connection/openai/openai-connection-fns.tsindex ec207d4cb4..93ee616e99 100644--- a/backend/src/services/app-connection/openai/openai-connection-fns.ts+++ b/backend/src/services/app-connection/openai/openai-connection-fns.ts@@ -1,9 +1,16 @@+import { AxiosError } from "axios";+import { request } from "@app/lib/config/request";-import { UnauthorizedError } from "@app/lib/errors";+import { BadRequestError, UnauthorizedError } from "@app/lib/errors";import { AppConnection } from "@app/services/app-connection/app-connection-enums";import { OpenAIConnectionMethod } from "./openai-connection-enums";-import { TOpenAIConnectionConfig } from "./openai-connection-types";+import {+ TOpenAIConnection,+ TOpenAIConnectionConfig,+ TOpenAIListProjectsResponse,+ TOpenAIProject+} from "./openai-connection-types";export const OPENAI_API_BASE_URL = "https://api.openai.com/v1";@@ -29,6 +36,42 @@ export const verifyOpenAIAdminApiKey = async (apiKey: string) =>validateStatus: (status) => status === 200});+export const listOpenAIProjects = async (+ appConnection: TOpenAIConnection+): Promise<Pick<TOpenAIProject, "id" | "name">[]> => {+ const { apiKey } = appConnection.credentials;+ const PAGE_SIZE = 100;+ const MAX_PAGES = 50;++ const projects: TOpenAIProject[] = [];++ try {+ let after: string | undefined;++ for (let page = 0; page < MAX_PAGES; page += 1) {+ // eslint-disable-next-line no-await-in-loop+ const { data } = await request.get<TOpenAIListProjectsResponse>(`${OPENAI_API_BASE_URL}/organization/projects`, {+ params: { limit: PAGE_SIZE, ...(after ? { after } : {}) },+ headers: {+ Authorization: `Bearer ${apiKey}`,+ "Content-Type": "application/json"+ }+ });++ projects.push(...(data.data ?? []).filter((project) => project.status === "active"));++ if (!data.has_more) break;+ after = data.last_id;+ }+ } catch (error: unknown) {+ throw new BadRequestError({+ message: `Failed to list OpenAI projects: ${error instanceof AxiosError ? error.message : "Unknown error"}`+ });+ }++ return projects.map(({ id, name }) => ({ id, name }));+};+export const validateOpenAIConnectionCredentials = async (config: TOpenAIConnectionConfig) => {const { apiKey } = config.credentials;diff --git a/backend/src/services/app-connection/openai/openai-connection-service.ts b/backend/src/services/app-connection/openai/openai-connection-service.tsnew file mode 100644index 0000000000..f8dad1cc1a--- /dev/null+++ b/backend/src/services/app-connection/openai/openai-connection-service.ts@@ -0,0 +1,22 @@+import { OrgServiceActor } from "@app/lib/types";++import { AppConnection } from "../app-connection-enums";+import { listOpenAIProjects } from "./openai-connection-fns";+import { TOpenAIConnection } from "./openai-connection-types";++type TGetAppConnectionFunc = (+ app: AppConnection,+ connectionId: string,+ actor: OrgServiceActor+) => Promise<TOpenAIConnection>;++export const openaiConnectionService = (getAppConnection: TGetAppConnectionFunc) => {+ const listProjects = async (connectionId: string, actor: OrgServiceActor) => {+ const appConnection = await getAppConnection(AppConnection.OpenAI, connectionId, actor);+ return listOpenAIProjects(appConnection);+ };++ return {+ listProjects+ };+};diff --git a/backend/src/services/app-connection/openai/openai-connection-types.ts b/backend/src/services/app-connection/openai/openai-connection-types.tsindex 74edaf0dd8..c8270465e8 100644--- a/backend/src/services/app-connection/openai/openai-connection-types.ts+++ b/backend/src/services/app-connection/openai/openai-connection-types.ts@@ -20,3 +20,19 @@ export type TValidateOpenAIConnectionCredentialsSchema = typeof ValidateOpenAICoexport type TOpenAIConnectionConfig = DiscriminativePick<TOpenAIConnectionInput, "method" | "app" | "credentials"> & {orgId: string;};++export type TOpenAIProject = {+ id: string;+ name: string;+ status: string;+ created_at: number;+ archived_at: number | null;+};++export type TOpenAIListProjectsResponse = {+ object: string;+ data: TOpenAIProject[];+ first_id: string;+ last_id: string;+ has_more: boolean;+};diff --git a/docs/api-reference/endpoints/app-connections/openai/create.mdx b/docs/api-reference/endpoints/app-connections/openai/create.mdxindex 6e1b46b48f..b65ae82696 100644--- a/docs/api-reference/endpoints/app-connections/openai/create.mdx+++ b/docs/api-reference/endpoints/app-connections/openai/create.mdx@@ -7,7 +7,7 @@ openapi: "POST /api/v1/app-connections/openai"Check out the configuration docs for [OpenAI Connections](/integrations/app-connections/openai) to learn how to obtain the required credentials.</Note>-Creates an OpenAI app connection using an Admin API key. The connection can then be used for [OpenAI Admin API Key secret rotations](/documentation/platform/secret-rotation/openai-admin-api-key).+Creates an OpenAI app connection using an Admin API key. The connection can then be used for [OpenAI Service Account secret rotations](/documentation/platform/secret-rotation/openai-service-account).## Request bodydiff --git a/docs/api-reference/endpoints/secret-rotations/openai-admin-api-key/delete.mdx b/docs/api-reference/endpoints/secret-rotations/openai-admin-api-key/delete.mdxdeleted file mode 100644index 6b63654a59..0000000000--- a/docs/api-reference/endpoints/secret-rotations/openai-admin-api-key/delete.mdx+++ /dev/null@@ -1,4 +0,0 @@-----title: "Delete"-openapi: "DELETE /api/v2/secret-rotations/openai-admin-api-key/{rotationId}"----diff --git a/docs/api-reference/endpoints/secret-rotations/openai-admin-api-key/get-by-id.mdx b/docs/api-reference/endpoints/secret-rotations/openai-admin-api-key/get-by-id.mdxdeleted file mode 100644index 1d101b67bb..0000000000--- a/docs/api-reference/endpoints/secret-rotations/openai-admin-api-key/get-by-id.mdx+++ /dev/null@@ -1,4 +0,0 @@-----title: "Get by ID"-openapi: "GET /api/v2/secret-rotations/openai-admin-api-key/{rotationId}"----diff --git a/docs/api-reference/endpoints/secret-rotations/openai-admin-api-key/get-by-name.mdx b/docs/api-reference/endpoints/secret-rotations/openai-admin-api-key/get-by-name.mdxdeleted file mode 100644index 6aaf513ba6..0000000000--- a/docs/api-reference/endpoints/secret-rotations/openai-admin-api-key/get-by-name.mdx+++ /dev/null@@ -1,4 +0,0 @@-----title: "Get by Name"-openapi: "GET /api/v2/secret-rotations/openai-admin-api-key/rotation-name/{rotationName}"----diff --git a/docs/api-reference/endpoints/secret-rotations/openai-admin-api-key/get-generated-credentials-by-id.mdx b/docs/api-reference/endpoints/secret-rotations/openai-admin-api-key/get-generated-credentials-by-id.mdxdeleted file mode 100644index 087d396c75..0000000000--- a/docs/api-reference/endpoints/secret-rotations/openai-admin-api-key/get-generated-credentials-by-id.mdx+++ /dev/null@@ -1,4 +0,0 @@-----title: "Get Credentials by ID"-openapi: "GET /api/v2/secret-rotations/openai-admin-api-key/{rotationId}/generated-credentials"----diff --git a/docs/api-reference/endpoints/secret-rotations/openai-admin-api-key/list.mdx b/docs/api-reference/endpoints/secret-rotations/openai-admin-api-key/list.mdxdeleted file mode 100644index 1710db5822..0000000000--- a/docs/api-reference/endpoints/secret-rotations/openai-admin-api-key/list.mdx+++ /dev/null@@ -1,4 +0,0 @@-----title: "List"-openapi: "GET /api/v2/secret-rotations/openai-admin-api-key"----diff --git a/docs/api-reference/endpoints/secret-rotations/openai-admin-api-key/rotate-secrets.mdx b/docs/api-reference/endpoints/secret-rotations/openai-admin-api-key/rotate-secrets.mdxdeleted file mode 100644index 9f6d9221d1..0000000000--- a/docs/api-reference/endpoints/secret-rotations/openai-admin-api-key/rotate-secrets.mdx+++ /dev/null@@ -1,4 +0,0 @@-----title: "Rotate Secrets"-openapi: "POST /api/v2/secret-rotations/openai-admin-api-key/{rotationId}/rotate-secrets"----diff --git a/docs/api-reference/endpoints/secret-rotations/openai-admin-api-key/update.mdx b/docs/api-reference/endpoints/secret-rotations/openai-admin-api-key/update.mdxdeleted file mode 100644index 57831a588e..0000000000--- a/docs/api-reference/endpoints/secret-rotations/openai-admin-api-key/update.mdx+++ /dev/null@@ -1,8 +0,0 @@-----title: "Update"-openapi: "PATCH /api/v2/secret-rotations/openai-admin-api-key/{rotationId}"------<Note>- Check out the configuration docs for [OpenAI Admin API Key Rotations](/documentation/platform/secret-rotation/openai-admin-api-key) to learn how to obtain the required parameters.-</Note>diff --git a/docs/api-reference/endpoints/secret-rotations/openai-admin-api-key/create.mdx b/docs/api-reference/endpoints/secret-rotations/openai-service-account/create.mdxsimilarity index 60%rename from docs/api-reference/endpoints/secret-rotations/openai-admin-api-key/create.mdxrename to docs/api-reference/endpoints/secret-rotations/openai-service-account/create.mdxindex bfe6d6f01b..ae93e90c52 100644--- a/docs/api-reference/endpoints/secret-rotations/openai-admin-api-key/create.mdx+++ b/docs/api-reference/endpoints/secret-rotations/openai-service-account/create.mdx@@ -1,13 +1,13 @@---title: "Create"-openapi: "POST /api/v2/secret-rotations/openai-admin-api-key"+openapi: "POST /api/v2/secret-rotations/openai-service-account"---<Note>- Check out the configuration docs for [OpenAI Admin API Key Rotations](/documentation/platform/secret-rotation/openai-admin-api-key) to learn how to obtain the required parameters.+ Check out the configuration docs for [OpenAI Service Account Rotations](/documentation/platform/secret-rotation/openai-service-account) to learn how to obtain the required parameters.</Note>-Creates an OpenAI Admin API Key secret rotation. Infisical will create and rotate admin API keys via your [OpenAI connection](/integrations/app-connections/openai) and write them to the specified secret path.+Creates an OpenAI Service Account secret rotation. Infisical will create and rotate project service accounts via your [OpenAI connection](/integrations/app-connections/openai) and write their API keys to the specified secret path.## Request body@@ -21,21 +21,22 @@ Creates an OpenAI Admin API Key secret rotation. Infisical will create and rotat| `isAutoRotationEnabled` | boolean | Yes | Whether to rotate automatically on the schedule. || `rotationInterval` | number | Yes | Days between rotations (e.g. `30`). || `rotateAtUtc` | object | Yes | Time of day (UTC) to run rotation: `{ "hours", "minutes" }`. |-| `parameters.name` | string | Yes | Name for the generated admin API key in OpenAI (max 100 characters). |-| `secretsMapping.apiKey` | string | Yes | Secret key name to store the generated API key (e.g. `OPENAI_ADMIN_API_KEY`). |+| `parameters.projectId` | string | Yes | ID of the OpenAI project to create service accounts in (e.g. `proj_abc123`). Cannot be changed after creation. |+| `parameters.name` | string | Yes | Name for the generated service account in OpenAI (max 100 characters). |+| `secretsMapping.apiKey` | string | Yes | Secret key name to store the generated API key (e.g. `OPENAI_API_KEY`). || `description` | string | No | Optional description. |## Sample request```bashcurl --request POST \- --url https://us.infisical.com/api/v2/secret-rotations/openai-admin-api-key \+ --url https://us.infisical.com/api/v2/secret-rotations/openai-service-account \--header 'Content-Type: application/json' \--header 'Authorization: Bearer <ACCESS_TOKEN>' \--data '{"name": "my-openai-rotation","projectId": "<project-id>",- "description": "OpenAI admin API key rotation",+ "description": "OpenAI service account rotation","connectionId": "<openai-connection-id>","environment": "dev","secretPath": "/",@@ -43,10 +44,11 @@ curl --request POST \"rotationInterval": 30,"rotateAtUtc": { "hours": 0, "minutes": 0 },"parameters": {- "name": "my-app-key"+ "projectId": "proj_abc123",+ "name": "my-app-service-account"},"secretsMapping": {- "apiKey": "OPENAI_ADMIN_API_KEY"+ "apiKey": "OPENAI_API_KEY"}}'```@@ -58,16 +60,17 @@ curl --request POST \"secretRotation": {"id": "<rotation-id>","name": "my-openai-rotation",- "description": "OpenAI admin API key rotation",- "secretsMapping": { "apiKey": "OPENAI_ADMIN_API_KEY" },+ "description": "OpenAI service account rotation",+ "secretsMapping": { "apiKey": "OPENAI_API_KEY" },"isAutoRotationEnabled": true,"activeIndex": 0,"connectionId": "<openai-connection-id>","rotationInterval": 30,"rotateAtUtc": { "hours": 0, "minutes": 0 },- "type": "openai-admin-api-key",+ "type": "openai-service-account","parameters": {- "name": "my-app-key"+ "projectId": "proj_abc123",+ "name": "my-app-service-account"}}}diff --git a/docs/api-reference/endpoints/secret-rotations/openai-service-account/delete.mdx b/docs/api-reference/endpoints/secret-rotations/openai-service-account/delete.mdxnew file mode 100644index 0000000000..ad98d17954--- /dev/null+++ b/docs/api-reference/endpoints/secret-rotations/openai-service-account/delete.mdx@@ -0,0 +1,4 @@+---+title: "Delete"+openapi: "DELETE /api/v2/secret-rotations/openai-service-account/{rotationId}"+---diff --git a/docs/api-reference/endpoints/secret-rotations/openai-service-account/get-by-id.mdx b/docs/api-reference/endpoints/secret-rotations/openai-service-account/get-by-id.mdxnew file mode 100644index 0000000000..e92cd9752e--- /dev/null+++ b/docs/api-reference/endpoints/secret-rotations/openai-service-account/get-by-id.mdx@@ -0,0 +1,4 @@+---+title: "Get by ID"+openapi: "GET /api/v2/secret-rotations/openai-service-account/{rotationId}"+---diff --git a/docs/api-reference/endpoints/secret-rotations/openai-service-account/get-by-name.mdx b/docs/api-reference/endpoints/secret-rotations/openai-service-account/get-by-name.mdxnew file mode 100644index 0000000000..ea2d3a21e9--- /dev/null+++ b/docs/api-reference/endpoints/secret-rotations/openai-service-account/get-by-name.mdx@@ -0,0 +1,4 @@+---+title: "Get by Name"+openapi: "GET /api/v2/secret-rotations/openai-service-account/rotation-name/{rotationName}"+---diff --git a/docs/api-reference/endpoints/secret-rotations/openai-service-account/get-generated-credentials-by-id.mdx b/docs/api-reference/endpoints/secret-rotations/openai-service-account/get-generated-credentials-by-id.mdxnew file mode 100644index 0000000000..bc8737da1c--- /dev/null+++ b/docs/api-reference/endpoints/secret-rotations/openai-service-account/get-generated-credentials-by-id.mdx@@ -0,0 +1,4 @@+---+title: "Get Credentials by ID"+openapi: "GET /api/v2/secret-rotations/openai-service-account/{rotationId}/generated-credentials"+---diff --git a/docs/api-reference/endpoints/secret-rotations/openai-service-account/list.mdx b/docs/api-reference/endpoints/secret-rotations/openai-service-account/list.mdxnew file mode 100644index 0000000000..dfe457a9b8--- /dev/null+++ b/docs/api-reference/endpoints/secret-rotations/openai-service-account/list.mdx@@ -0,0 +1,4 @@+---+title: "List"+openapi: "GET /api/v2/secret-rotations/openai-service-account"+---diff --git a/docs/api-reference/endpoints/secret-rotations/openai-service-account/rotate-secrets.mdx b/docs/api-reference/endpoints/secret-rotations/openai-service-account/rotate-secrets.mdxnew file mode 100644index 0000000000..b5073e82e8--- /dev/null+++ b/docs/api-reference/endpoints/secret-rotations/openai-service-account/rotate-secrets.mdx@@ -0,0 +1,4 @@+---+title: "Rotate Secrets"+openapi: "POST /api/v2/secret-rotations/openai-service-account/{rotationId}/rotate-secrets"+---diff --git a/docs/api-reference/endpoints/secret-rotations/openai-service-account/update.mdx b/docs/api-reference/endpoints/secret-rotations/openai-service-account/update.mdxnew file mode 100644index 0000000000..c4953f20c7--- /dev/null+++ b/docs/api-reference/endpoints/secret-rotations/openai-service-account/update.mdx@@ -0,0 +1,8 @@+---+title: "Update"+openapi: "PATCH /api/v2/secret-rotations/openai-service-account/{rotationId}"+---++<Note>+ Check out the configuration docs for [OpenAI Service Account Rotations](/documentation/platform/secret-rotation/openai-service-account) to learn how to obtain the required parameters.+</Note>diff --git a/docs/docs.json b/docs/docs.jsonindex 2a5b805e3e..20168344bd 100644--- a/docs/docs.json+++ b/docs/docs.json@@ -499,7 +499,7 @@"documentation/platform/secret-rotation/mysql-credentials","documentation/platform/secret-rotation/hp-ilo-local-account","documentation/platform/secret-rotation/okta-client-secret",- "documentation/platform/secret-rotation/openai-admin-api-key",+ "documentation/platform/secret-rotation/openai-service-account","documentation/platform/secret-rotation/openrouter-api-key","documentation/platform/secret-rotation/oracledb-credentials","documentation/platform/secret-rotation/postgres-credentials",@@ -2523,16 +2523,16 @@]},{- "group": "OpenAI Admin API Key",+ "group": "OpenAI Service Account","pages": [- "api-reference/endpoints/secret-rotations/openai-admin-api-key/create",- "api-reference/endpoints/secret-rotations/openai-admin-api-key/delete",- "api-reference/endpoints/secret-rotations/openai-admin-api-key/get-by-id",- "api-reference/endpoints/secret-rotations/openai-admin-api-key/get-by-name",- "api-reference/endpoints/secret-rotations/openai-admin-api-key/get-generated-credentials-by-id",- "api-reference/endpoints/secret-rotations/openai-admin-api-key/list",- "api-reference/endpoints/secret-rotations/openai-admin-api-key/rotate-secrets",- "api-reference/endpoints/secret-rotations/openai-admin-api-key/update"+ "api-reference/endpoints/secret-rotations/openai-service-account/create",+ "api-reference/endpoints/secret-rotations/openai-service-account/delete",+ "api-reference/endpoints/secret-rotations/openai-service-account/get-by-id",+ "api-reference/endpoints/secret-rotations/openai-service-account/get-by-name",+ "api-reference/endpoints/secret-rotations/openai-service-account/get-generated-credentials-by-id",+ "api-reference/endpoints/secret-rotations/openai-service-account/list",+ "api-reference/endpoints/secret-rotations/openai-service-account/rotate-secrets",+ "api-reference/endpoints/secret-rotations/openai-service-account/update"]},{diff --git a/docs/documentation/platform/secret-rotation/openai-admin-api-key.mdx b/docs/documentation/platform/secret-rotation/openai-service-account.mdxsimilarity index 54%rename from docs/documentation/platform/secret-rotation/openai-admin-api-key.mdxrename to docs/documentation/platform/secret-rotation/openai-service-account.mdxindex 2c73589f12..a88092eba5 100644--- a/docs/documentation/platform/secret-rotation/openai-admin-api-key.mdx+++ b/docs/documentation/platform/secret-rotation/openai-service-account.mdx@@ -1,6 +1,6 @@----title: "OpenAI Admin API Key"-description: "Learn how to automatically rotate OpenAI admin API keys."+title: "OpenAI Service Account"+description: "Learn how to automatically rotate OpenAI project service accounts."---<Note>@@ -11,9 +11,9 @@ description: "Learn how to automatically rotate OpenAI admin API keys."## Prerequisites-- Create an [OpenAI Connection](/integrations/app-connections/openai) using an **Admin API key**. That connection is used to create and delete admin API keys on your behalf during rotation.+- Create an [OpenAI Connection](/integrations/app-connections/openai) using an **Admin API key**. That connection is used to create and delete project service accounts on your behalf during rotation.-## Create an OpenAI Admin API Key Rotation in Infisical+## Create an OpenAI Service Account Rotation in Infisical<Tabs><Tab title="Infisical UI">@@ -21,59 +21,60 @@ description: "Learn how to automatically rotate OpenAI admin API keys."- 2. Select the **OpenAI Admin API Key** option.+ 2. Select the **OpenAI Service Account** option.- + 3. Configure the rotation behavior, then click **Next**.- + - - **OpenAI Connection** – The connection that will create and delete admin API keys during rotation.+ - **OpenAI Connection** – The connection that will create and delete service accounts during rotation.- **Rotation Interval** – The interval, in days, after which a rotation is triggered.- **Rotate At** – The local time of day when rotation runs once the interval has elapsed.- **Auto-Rotation Enabled** – Whether to rotate automatically on the interval. Turn off to rotate only manually or pause rotation.- 4. Set the OpenAI Admin API Key parameter, then click **Next**.+ 4. Set the OpenAI Service Account parameters, then click **Next**.- + - - **Key name** – The name for the generated OpenAI admin API key (required, up to 100 characters). Infisical appends a timestamp suffix to this name in the OpenAI dashboard (e.g. `my-app-key-1720268400000`) so that the active and previous keys stay distinguishable during the overlap window. Keys are deleted by their key ID, so the name is used only for identification.+ - **Project** – The OpenAI project to create service accounts in. Projects are listed via your OpenAI connection. This cannot be changed after the rotation is created.+ - **Service Account Name** – The name for the generated OpenAI service account (required, up to 100 characters). Infisical appends a timestamp suffix to this name in the OpenAI dashboard (e.g. `my-app-service-account-1720268400000`) so that the active and previous service accounts stay distinguishable during the overlap window. Service accounts are deleted by their ID, so the name is used only for identification.5. Specify the secret name that the rotated API key will be mapped to. Then click **Next**.- + - - **API Key** – The name of the secret in Infisical where the rotated admin API key value will be stored.+ - **API Key** – The name of the secret in Infisical where the rotated service account API key value will be stored.6. Give your rotation a name and description (optional). Then click **Next**.- + - **Name** – A slug-friendly name for this rotation configuration.- **Description** (optional) – Notes about this rotation.7. Review your configuration, then click **Create Secret Rotation**.- + - 8. Your **OpenAI Admin API Key** rotation is created. The current admin API key is available as a secret at the mapped path. Rotations will create a new key, switch the active secret to it, then revoke the previous key for zero-downtime rotation.+ 8. Your **OpenAI Service Account** rotation is created. The current service account's API key is available as a secret at the mapped path. Rotations will create a new service account, switch the active secret to its API key, then delete the previous service account for zero-downtime rotation.- + </Tab><Tab title="API">- To create an OpenAI Admin API Key rotation, call the [Create OpenAI Admin API Key Rotation](/api-reference/endpoints/secret-rotations/openai-admin-api-key/create) API endpoint.+ To create an OpenAI Service Account rotation, call the [Create OpenAI Service Account Rotation](/api-reference/endpoints/secret-rotations/openai-service-account/create) API endpoint.### Sample request```bash Requestcurl --request POST \- --url https://us.infisical.com/api/v2/secret-rotations/openai-admin-api-key \+ --url https://us.infisical.com/api/v2/secret-rotations/openai-service-account \--header 'Content-Type: application/json' \--data '{"name": "my-openai-rotation","projectId": "<project-id>",- "description": "OpenAI admin API key rotation",+ "description": "OpenAI service account rotation","connectionId": "<openai-connection-id>","environment": "dev","secretPath": "/",@@ -84,10 +85,11 @@ description: "Learn how to automatically rotate OpenAI admin API keys.""minutes": 0},"parameters": {- "name": "my-app-key"+ "projectId": "proj_abc123",+ "name": "my-app-service-account"},"secretsMapping": {- "apiKey": "OPENAI_ADMIN_API_KEY"+ "apiKey": "OPENAI_API_KEY"}}'```@@ -99,18 +101,19 @@ description: "Learn how to automatically rotate OpenAI admin API keys.""secretRotation": {"id": "<rotation-id>","name": "my-openai-rotation",- "description": "OpenAI admin API key rotation",+ "description": "OpenAI service account rotation","secretsMapping": {- "apiKey": "OPENAI_ADMIN_API_KEY"+ "apiKey": "OPENAI_API_KEY"},"isAutoRotationEnabled": true,"activeIndex": 0,"connectionId": "<openai-connection-id>","rotationInterval": 30,"rotateAtUtc": { "hours": 0, "minutes": 0 },- "type": "openai-admin-api-key",+ "type": "openai-service-account","parameters": {- "name": "my-app-key"+ "projectId": "proj_abc123",+ "name": "my-app-service-account"}}}diff --git a/docs/images/secret-rotations-v2/openai-admin-api-key/step-1.png b/docs/images/secret-rotations-v2/openai-service-account/step-1.pngsimilarity index 100%rename from docs/images/secret-rotations-v2/openai-admin-api-key/step-1.pngrename to docs/images/secret-rotations-v2/openai-service-account/step-1.pngdiff --git a/docs/images/secret-rotations-v2/openai-admin-api-key/step-2.png b/docs/images/secret-rotations-v2/openai-service-account/step-2.pngsimilarity index 100%rename from docs/images/secret-rotations-v2/openai-admin-api-key/step-2.pngrename to docs/images/secret-rotations-v2/openai-service-account/step-2.pngdiff --git a/docs/images/secret-rotations-v2/openai-admin-api-key/step-3.png b/docs/images/secret-rotations-v2/openai-service-account/step-3.pngsimilarity index 100%rename from docs/images/secret-rotations-v2/openai-admin-api-key/step-3.pngrename to docs/images/secret-rotations-v2/openai-service-account/step-3.pngdiff --git a/docs/images/secret-rotations-v2/openai-admin-api-key/step-4.png b/docs/images/secret-rotations-v2/openai-service-account/step-4.pngsimilarity index 100%rename from docs/images/secret-rotations-v2/openai-admin-api-key/step-4.pngrename to docs/images/secret-rotations-v2/openai-service-account/step-4.pngdiff --git a/docs/images/secret-rotations-v2/openai-admin-api-key/step-5.png b/docs/images/secret-rotations-v2/openai-service-account/step-5.pngsimilarity index 100%rename from docs/images/secret-rotations-v2/openai-admin-api-key/step-5.pngrename to docs/images/secret-rotations-v2/openai-service-account/step-5.pngdiff --git a/docs/images/secret-rotations-v2/openai-admin-api-key/step-6.png b/docs/images/secret-rotations-v2/openai-service-account/step-6.pngsimilarity index 100%rename from docs/images/secret-rotations-v2/openai-admin-api-key/step-6.pngrename to docs/images/secret-rotations-v2/openai-service-account/step-6.pngdiff --git a/docs/images/secret-rotations-v2/openai-admin-api-key/step-7.png b/docs/images/secret-rotations-v2/openai-service-account/step-7.pngsimilarity index 100%rename from docs/images/secret-rotations-v2/openai-admin-api-key/step-7.pngrename to docs/images/secret-rotations-v2/openai-service-account/step-7.pngdiff --git a/docs/integrations/app-connections/openai.mdx b/docs/integrations/app-connections/openai.mdxindex 570206bb62..1c1fd8a3ce 100644--- a/docs/integrations/app-connections/openai.mdx+++ b/docs/integrations/app-connections/openai.mdx@@ -3,7 +3,7 @@ title: "OpenAI Connection"description: "Learn how to configure an OpenAI connection for Infisical."----Infisical supports connecting to OpenAI using an **Admin API Key**. This connection is used to manage and rotate OpenAI admin API keys via [Secret Rotation](/documentation/platform/secret-rotation/openai-admin-api-key).+Infisical supports connecting to OpenAI using an **Admin API Key**. This connection is used to create and rotate OpenAI project service accounts via [Secret Rotation](/documentation/platform/secret-rotation/openai-service-account).## Prerequisites@@ -72,7 +72,7 @@ You need an OpenAI **Admin API key** created by an **Organization Owner**. Admin</Step><Step title="Connection Created">- After clicking **Connect to OpenAI**, Infisical validates the key against the OpenAI API. Your **OpenAI Connection** is then ready to use for [OpenAI Admin API Key Secret Rotation](/documentation/platform/secret-rotation/openai-admin-api-key).+ After clicking **Connect to OpenAI**, Infisical validates the key against the OpenAI API. Your **OpenAI Connection** is then ready to use for [OpenAI Service Account Secret Rotation](/documentation/platform/secret-rotation/openai-service-account).</Step>diff --git a/frontend/src/components/secret-rotations-v2/ViewSecretRotationV2GeneratedCredentials/ViewOpenAIAdminApiKeyRotationGeneratedCredentials.tsx b/frontend/src/components/secret-rotations-v2/ViewSecretRotationV2GeneratedCredentials/ViewOpenAIServiceAccountRotationGeneratedCredentials.tsxsimilarity index 74%rename from frontend/src/components/secret-rotations-v2/ViewSecretRotationV2GeneratedCredentials/ViewOpenAIAdminApiKeyRotationGeneratedCredentials.tsxrename to frontend/src/components/secret-rotations-v2/ViewSecretRotationV2GeneratedCredentials/ViewOpenAIServiceAccountRotationGeneratedCredentials.tsxindex 8606664df0..48e8adb730 100644--- a/frontend/src/components/secret-rotations-v2/ViewSecretRotationV2GeneratedCredentials/ViewOpenAIAdminApiKeyRotationGeneratedCredentials.tsx+++ b/frontend/src/components/secret-rotations-v2/ViewSecretRotationV2GeneratedCredentials/ViewOpenAIServiceAccountRotationGeneratedCredentials.tsx@@ -1,13 +1,13 @@import { CredentialDisplay } from "@app/components/secret-rotations-v2/ViewSecretRotationV2GeneratedCredentials/shared/CredentialDisplay";-import { TOpenAIAdminApiKeyRotationGeneratedCredentialsResponse } from "@app/hooks/api/secretRotationsV2/types/openai-admin-api-key-rotation";+import { TOpenAIServiceAccountRotationGeneratedCredentialsResponse } from "@app/hooks/api/secretRotationsV2/types/openai-service-account-rotation";import { ViewRotationGeneratedCredentialsDisplay } from "./shared";type Props = {- generatedCredentialsResponse: TOpenAIAdminApiKeyRotationGeneratedCredentialsResponse;+ generatedCredentialsResponse: TOpenAIServiceAccountRotationGeneratedCredentialsResponse;};-export const ViewOpenAIAdminApiKeyRotationGeneratedCredentials = ({+export const ViewOpenAIServiceAccountRotationGeneratedCredentials = ({generatedCredentialsResponse: { generatedCredentials, activeIndex }}: Props) => {const inactiveIndex = activeIndex === 0 ? 1 : 0;diff --git a/frontend/src/components/secret-rotations-v2/ViewSecretRotationV2GeneratedCredentials/ViewSecretRotationV2GeneratedCredentials.tsx b/frontend/src/components/secret-rotations-v2/ViewSecretRotationV2GeneratedCredentials/ViewSecretRotationV2GeneratedCredentials.tsxindex 0d37a62964..bb2e4efbeb 100644--- a/frontend/src/components/secret-rotations-v2/ViewSecretRotationV2GeneratedCredentials/ViewSecretRotationV2GeneratedCredentials.tsx+++ b/frontend/src/components/secret-rotations-v2/ViewSecretRotationV2GeneratedCredentials/ViewSecretRotationV2GeneratedCredentials.tsx@@ -28,7 +28,7 @@ import { ViewDatadogApplicationKeySecretRotationGeneratedCredentials } from "./Vimport { ViewDbtServiceTokenRotationGeneratedCredentials } from "./ViewDbtSeviceTokenRotationGeneratedCredentials";import { ViewHpIloRotationGeneratedCredentials } from "./ViewHpIloRotationGeneratedCredentials";import { ViewOktaClientSecretRotationGeneratedCredentials } from "./ViewOktaClientSecretRotationGeneratedCredentials";-import { ViewOpenAIAdminApiKeyRotationGeneratedCredentials } from "./ViewOpenAIAdminApiKeyRotationGeneratedCredentials";+import { ViewOpenAIServiceAccountRotationGeneratedCredentials } from "./ViewOpenAIServiceAccountRotationGeneratedCredentials";import { ViewOpenRouterApiKeyRotationGeneratedCredentials } from "./ViewOpenRouterApiKeyRotationGeneratedCredentials";import { ViewRedisCredentialsRotationGeneratedCredentials } from "./ViewRedisCredentialsRotationGeneratedCredentials";import { ViewSalesforceOauthCredentialsRotationGeneratedCredentials } from "./ViewSalesforceOauthCredentialsRotationGeneratedCredentials";@@ -162,9 +162,9 @@ const Content = ({ secretRotation }: ContentProps) => {/>);break;- case SecretRotation.OpenAIAdminApiKey:+ case SecretRotation.OpenAIServiceAccount:Component = (- <ViewOpenAIAdminApiKeyRotationGeneratedCredentials+ <ViewOpenAIServiceAccountRotationGeneratedCredentialsgeneratedCredentialsResponse={generatedCredentialsResponse}/>);diff --git a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/OpenAIAdminApiKeyRotationParametersFields.tsx b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/OpenAIAdminApiKeyRotationParametersFields.tsxdeleted file mode 100644index 0a7c93d4dd..0000000000--- a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/OpenAIAdminApiKeyRotationParametersFields.tsx+++ /dev/null@@ -1,36 +0,0 @@-import { Controller, useFormContext } from "react-hook-form";--import { TSecretRotationV2Form } from "@app/components/secret-rotations-v2/forms/schemas";-import { OPENAI_ADMIN_API_KEY_NAME_MAX_LENGTH } from "@app/components/secret-rotations-v2/forms/schemas/openai-admin-api-key-rotation-schema";-import { FormControl, Input } from "@app/components/v2";-import { SecretRotation } from "@app/hooks/api/secretRotationsV2";--export const OpenAIAdminApiKeyRotationParametersFields = () => {- const { control } = useFormContext<- TSecretRotationV2Form & {- type: SecretRotation.OpenAIAdminApiKey;- }- >();-- return (- <Controller- name="parameters.name"- control={control}- render={({ field: { value, onChange }, fieldState: { error } }) => (- <FormControl- isError={Boolean(error)}- errorText={error?.message}- label="Key Name"- tooltipText="A descriptive name for the generated admin API key. This will be saved in the OpenAI dashboard for reference with a suffix of the timestamp of the key creation."- >- <Input- value={value}- onChange={onChange}- placeholder="OpenAI Admin API Key Name"- maxLength={OPENAI_ADMIN_API_KEY_NAME_MAX_LENGTH}- />- </FormControl>- )}- />- );-};diff --git a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/OpenAIServiceAccountRotationParametersFields.tsx b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/OpenAIServiceAccountRotationParametersFields.tsxnew file mode 100644index 0000000000..966c0333fa--- /dev/null+++ b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/OpenAIServiceAccountRotationParametersFields.tsx@@ -0,0 +1,76 @@+import { Controller, useFormContext } from "react-hook-form";+import { SingleValue } from "react-select";++import { TSecretRotationV2Form } from "@app/components/secret-rotations-v2/forms/schemas";+import { OPENAI_SERVICE_ACCOUNT_NAME_MAX_LENGTH } from "@app/components/secret-rotations-v2/forms/schemas/openai-service-account-rotation-schema";+import { FilterableSelect, FormControl, Input } from "@app/components/v2";+import { useListOpenAIConnectionProjects } from "@app/hooks/api/appConnections/openai";+import { TOpenAIProject } from "@app/hooks/api/appConnections/openai/types";+import { SecretRotation } from "@app/hooks/api/secretRotationsV2";++export const OpenAIServiceAccountRotationParametersFields = () => {+ const { control, watch } = useFormContext<+ TSecretRotationV2Form & {+ type: SecretRotation.OpenAIServiceAccount;+ }+ >();++ const connectionId = watch("connection.id");++ const { data: projects, isPending: isProjectsPending } = useListOpenAIConnectionProjects(+ connectionId,+ {+ enabled: Boolean(connectionId)+ }+ );++ return (+ <>+ <Controller+ name="parameters.projectId"+ control={control}+ render={({ field: { value, onChange }, fieldState: { error } }) => (+ <FormControl+ isError={Boolean(error)}+ errorText={error?.message}+ label="Project"+ tooltipText="The OpenAI project to create service accounts in. This cannot be changed after the rotation is created."+ >+ <FilterableSelect+ menuPlacement="top"+ isLoading={isProjectsPending && Boolean(connectionId)}+ isDisabled={!connectionId}+ value={projects?.find((project) => project.id === value) ?? null}+ onChange={(option) => {+ onChange((option as SingleValue<TOpenAIProject>)?.id ?? "");+ }}+ options={projects}+ placeholder="Select a project..."+ getOptionLabel={(option) => option.name}+ getOptionValue={(option) => option.id}+ />+ </FormControl>+ )}+ />+ <Controller+ name="parameters.name"+ control={control}+ render={({ field: { value, onChange }, fieldState: { error } }) => (+ <FormControl+ isError={Boolean(error)}+ errorText={error?.message}+ label="Service Account Name"+ tooltipText="A descriptive name for the generated service account. This will be saved in the OpenAI dashboard for reference with a suffix of the timestamp of the service account creation."+ >+ <Input+ value={value}+ onChange={onChange}+ placeholder="OpenAI Service Account Name"+ maxLength={OPENAI_SERVICE_ACCOUNT_NAME_MAX_LENGTH}+ />+ </FormControl>+ )}+ />+ </>+ );+};diff --git a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/SecretRotationV2ParametersFields.tsx b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/SecretRotationV2ParametersFields.tsxindex ed75555afd..cd93d7ca5e 100644--- a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/SecretRotationV2ParametersFields.tsx+++ b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/SecretRotationV2ParametersFields.tsx@@ -14,7 +14,7 @@ import { HpIloRotationParametersFields } from "./HpIloRotationParametersFields";import { LdapPasswordRotationParametersFields } from "./LdapPasswordRotationParametersFields";import { MongoRotationParametersFields } from "./MongoRotationParametersFields";import { OktaClientSecretRotationParametersFields } from "./OktaClientSecretRotationParametersFields";-import { OpenAIAdminApiKeyRotationParametersFields } from "./OpenAIAdminApiKeyRotationParametersFields";+import { OpenAIServiceAccountRotationParametersFields } from "./OpenAIServiceAccountRotationParametersFields";import { OpenRouterApiKeyRotationParametersFields } from "./OpenRouterApiKeyRotationParametersFields";import { RedisCredentialsRotationParametersFields } from "./RedisCredentialsRotationParametersFields";import { SalesforceOauthCredentialsRotationParametersFields } from "./SalesforceOauthCredentialsRotationParametersFields";@@ -41,7 +41,7 @@ const COMPONENT_MAP: Record<SecretRotation, React.FC> = {[SecretRotation.DbtServiceToken]: DbtServiceTokenRotationParametersFields,[SecretRotation.WindowsLocalAccount]: WindowsLocalAccountRotationParametersFields,[SecretRotation.OpenRouterApiKey]: OpenRouterApiKeyRotationParametersFields,- [SecretRotation.OpenAIAdminApiKey]: OpenAIAdminApiKeyRotationParametersFields,+ [SecretRotation.OpenAIServiceAccount]: OpenAIServiceAccountRotationParametersFields,[SecretRotation.HpIloLocalAccount]: HpIloRotationParametersFields,[SecretRotation.SupabaseApiKey]: SupabaseApiKeyRotationParametersFields,[SecretRotation.SalesforceOauthCredentials]: SalesforceOauthCredentialsRotationParametersFields,diff --git a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ReviewFields/OpenAIAdminApiKeyRotationReviewFields.tsx b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ReviewFields/OpenAIServiceAccountRotationReviewFields.tsxsimilarity index 72%rename from frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ReviewFields/OpenAIAdminApiKeyRotationReviewFields.tsxrename to frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ReviewFields/OpenAIServiceAccountRotationReviewFields.tsxindex 787cf2c6d6..1eacbd6465 100644--- a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ReviewFields/OpenAIAdminApiKeyRotationReviewFields.tsx+++ b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ReviewFields/OpenAIServiceAccountRotationReviewFields.tsx@@ -6,10 +6,10 @@ import { SecretRotation } from "@app/hooks/api/secretRotationsV2";import { SecretRotationReviewSection } from "./shared";-export const OpenAIAdminApiKeyRotationReviewFields = () => {+export const OpenAIServiceAccountRotationReviewFields = () => {const { watch } = useFormContext<TSecretRotationV2Form & {- type: SecretRotation.OpenAIAdminApiKey;+ type: SecretRotation.OpenAIServiceAccount;}>();@@ -18,7 +18,8 @@ export const OpenAIAdminApiKeyRotationReviewFields = () => {return (<><SecretRotationReviewSection label="Parameters">- <GenericFieldLabel label="Key Name">{parameters.name}</GenericFieldLabel>+ <GenericFieldLabel label="Project ID">{parameters.projectId}</GenericFieldLabel>+ <GenericFieldLabel label="Service Account Name">{parameters.name}</GenericFieldLabel></SecretRotationReviewSection><SecretRotationReviewSection label="Secrets Mapping"><GenericFieldLabel label="API Key">{apiKey}</GenericFieldLabel>diff --git a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ReviewFields/SecretRotationReviewFields.tsx b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ReviewFields/SecretRotationReviewFields.tsxindex a5b18b5364..b86ac2b3ce 100644--- a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ReviewFields/SecretRotationReviewFields.tsx+++ b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ReviewFields/SecretRotationReviewFields.tsx@@ -16,7 +16,7 @@ import { DbtServiceTokenRotationReviewFields } from "./DbtServiceTokenRotationReimport { HpIloRotationReviewFields } from "./HpIloRotationReviewFields";import { LdapPasswordRotationReviewFields } from "./LdapPasswordRotationReviewFields";import { OktaClientSecretRotationReviewFields } from "./OktaClientSecretRotationReviewFields";-import { OpenAIAdminApiKeyRotationReviewFields } from "./OpenAIAdminApiKeyRotationReviewFields";+import { OpenAIServiceAccountRotationReviewFields } from "./OpenAIServiceAccountRotationReviewFields";import { OpenRouterApiKeyRotationReviewFields } from "./OpenRouterApiKeyRotationReviewFields";import { RedisCredentialsRotationReviewFields } from "./RedisCredentialsRotationReviewFields";import { SalesforceOauthCredentialsRotationReviewFields } from "./SalesforceOauthCredentialsRotationReviewFields";@@ -43,7 +43,7 @@ const COMPONENT_MAP: Record<SecretRotation, React.FC> = {[SecretRotation.DbtServiceToken]: DbtServiceTokenRotationReviewFields,[SecretRotation.WindowsLocalAccount]: WindowsLocalAccountRotationReviewFields,[SecretRotation.OpenRouterApiKey]: OpenRouterApiKeyRotationReviewFields,- [SecretRotation.OpenAIAdminApiKey]: OpenAIAdminApiKeyRotationReviewFields,+ [SecretRotation.OpenAIServiceAccount]: OpenAIServiceAccountRotationReviewFields,[SecretRotation.HpIloLocalAccount]: HpIloRotationReviewFields,[SecretRotation.SupabaseApiKey]: SupabaseApiKeyRotationReviewFields,[SecretRotation.SalesforceOauthCredentials]: SalesforceOauthCredentialsRotationReviewFields,diff --git a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2SecretsMappingFields/OpenAIAdminApiKeyRotationSecretsMappingFields.tsx b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2SecretsMappingFields/OpenAIServiceAccountRotationSecretsMappingFields.tsxsimilarity index 88%rename from frontend/src/components/secret-rotations-v2/forms/SecretRotationV2SecretsMappingFields/OpenAIAdminApiKeyRotationSecretsMappingFields.tsxrename to frontend/src/components/secret-rotations-v2/forms/SecretRotationV2SecretsMappingFields/OpenAIServiceAccountRotationSecretsMappingFields.tsxindex 8b51e7bad0..e81917df2e 100644--- a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2SecretsMappingFields/OpenAIAdminApiKeyRotationSecretsMappingFields.tsx+++ b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2SecretsMappingFields/OpenAIServiceAccountRotationSecretsMappingFields.tsx@@ -6,14 +6,14 @@ import { SecretRotation, useSecretRotationV2Option } from "@app/hooks/api/secretimport { SecretsMappingTable } from "./shared";-export const OpenAIAdminApiKeyRotationSecretsMappingFields = () => {+export const OpenAIServiceAccountRotationSecretsMappingFields = () => {const { control } = useFormContext<TSecretRotationV2Form & {- type: SecretRotation.OpenAIAdminApiKey;+ type: SecretRotation.OpenAIServiceAccount;}>();- const { rotationOption } = useSecretRotationV2Option(SecretRotation.OpenAIAdminApiKey);+ const { rotationOption } = useSecretRotationV2Option(SecretRotation.OpenAIServiceAccount);const items = [{diff --git a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2SecretsMappingFields/SecretRotationV2SecretsMappingFields.tsx b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2SecretsMappingFields/SecretRotationV2SecretsMappingFields.tsxindex e905957f13..ae49913118 100644--- a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2SecretsMappingFields/SecretRotationV2SecretsMappingFields.tsx+++ b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2SecretsMappingFields/SecretRotationV2SecretsMappingFields.tsx@@ -13,7 +13,7 @@ import { DbtServiceTokenRotationSecretsMappingFields } from "./DbtServiceTokenRoimport { HpIloRotationSecretsMappingFields } from "./HpIloRotationSecretsMappingFields";import { LdapPasswordRotationSecretsMappingFields } from "./LdapPasswordRotationSecretsMappingFields";import { OktaClientSecretRotationSecretsMappingFields } from "./OktaClientSecretRotationSecretsMappingFields";-import { OpenAIAdminApiKeyRotationSecretsMappingFields } from "./OpenAIAdminApiKeyRotationSecretsMappingFields";+import { OpenAIServiceAccountRotationSecretsMappingFields } from "./OpenAIServiceAccountRotationSecretsMappingFields";import { OpenRouterApiKeyRotationSecretsMappingFields } from "./OpenRouterApiKeyRotationSecretsMappingFields";import { RedisCredentialsRotationSecretsMappingFields } from "./RedisCredentialsRotationSecretsMappingFields";import { SalesforceOauthCredentialsRotationSecretsMappingFields } from "./SalesforceOauthCredentialsRotationSecretsMappingFields";@@ -40,7 +40,7 @@ const COMPONENT_MAP: Record<SecretRotation, React.FC> = {[SecretRotation.DbtServiceToken]: DbtServiceTokenRotationSecretsMappingFields,[SecretRotation.WindowsLocalAccount]: WindowsLocalAccountRotationSecretsMappingFields,[SecretRotation.OpenRouterApiKey]: OpenRouterApiKeyRotationSecretsMappingFields,- [SecretRotation.OpenAIAdminApiKey]: OpenAIAdminApiKeyRotationSecretsMappingFields,+ [SecretRotation.OpenAIServiceAccount]: OpenAIServiceAccountRotationSecretsMappingFields,[SecretRotation.HpIloLocalAccount]: HpIloRotationSecretsMappingFields,[SecretRotation.SupabaseApiKey]: SupabaseApiKeyRotationSecretsMappingFields,[SecretRotation.SalesforceOauthCredentials]:diff --git a/frontend/src/components/secret-rotations-v2/forms/schemas/index.ts b/frontend/src/components/secret-rotations-v2/forms/schemas/index.tsindex 1fe8fffb13..2e5b0accb5 100644--- a/frontend/src/components/secret-rotations-v2/forms/schemas/index.ts+++ b/frontend/src/components/secret-rotations-v2/forms/schemas/index.ts@@ -21,7 +21,7 @@ import { DbtServiceTokenRotationSchema } from "./dbt-service-token-rotation-scheimport { HpIloRotationSchema } from "./hp-ilo-rotation-schema";import { OktaClientSecretRotationSchema } from "./okta-client-secret-rotation-schema";import { OpenRouterApiKeyRotationSchema } from "./open-router-api-key-rotation-schema";-import { OpenAIAdminApiKeyRotationSchema } from "./openai-admin-api-key-rotation-schema";+import { OpenAIServiceAccountRotationSchema } from "./openai-service-account-rotation-schema";import { OracleDBCredentialsRotationSchema } from "./oracledb-credentials-rotation-schema";import { RedisCredentialsRotationSchema } from "./redis-credentials-rotation-schema";import { SalesforceOauthCredentialsRotationSchema } from "./salesforce-oauth-credentials-rotation-schema";@@ -49,7 +49,7 @@ export const SecretRotationV2FormSchema = (isUpdate: boolean) =>DbtServiceTokenRotationSchema,WindowsLocalAccountRotationSchema,OpenRouterApiKeyRotationSchema,- OpenAIAdminApiKeyRotationSchema,+ OpenAIServiceAccountRotationSchema,HpIloRotationSchema,SupabaseApiKeyRotationSchema,SalesforceOauthCredentialsRotationSchema,diff --git a/frontend/src/components/secret-rotations-v2/forms/schemas/openai-admin-api-key-rotation-schema.ts b/frontend/src/components/secret-rotations-v2/forms/schemas/openai-service-account-rotation-schema.tssimilarity index 56%rename from frontend/src/components/secret-rotations-v2/forms/schemas/openai-admin-api-key-rotation-schema.tsrename to frontend/src/components/secret-rotations-v2/forms/schemas/openai-service-account-rotation-schema.tsindex a90c70919d..00c1ad608f 100644--- a/frontend/src/components/secret-rotations-v2/forms/schemas/openai-admin-api-key-rotation-schema.ts+++ b/frontend/src/components/secret-rotations-v2/forms/schemas/openai-service-account-rotation-schema.ts@@ -4,19 +4,20 @@ import { BaseSecretRotationSchema } from "@app/components/secret-rotations-v2/foimport { SecretRotation } from "@app/hooks/api/secretRotationsV2";/** Max length for the user-provided base name (matches backend schema). */-export const OPENAI_ADMIN_API_KEY_NAME_MAX_LENGTH = 100;+export const OPENAI_SERVICE_ACCOUNT_NAME_MAX_LENGTH = 100;-export const OpenAIAdminApiKeyRotationSchema = z+export const OpenAIServiceAccountRotationSchema = z.object({- type: z.literal(SecretRotation.OpenAIAdminApiKey),+ type: z.literal(SecretRotation.OpenAIServiceAccount),parameters: z.object({+ projectId: z.string().trim().min(1, "Project required"),name: z.string().trim()- .min(1, "Key name required")+ .min(1, "Service account name required").max(- OPENAI_ADMIN_API_KEY_NAME_MAX_LENGTH,- `Key name must be ${OPENAI_ADMIN_API_KEY_NAME_MAX_LENGTH} characters or fewer`+ OPENAI_SERVICE_ACCOUNT_NAME_MAX_LENGTH,+ `Service account name must be ${OPENAI_SERVICE_ACCOUNT_NAME_MAX_LENGTH} characters or fewer`)}),secretsMapping: z.object({diff --git a/frontend/src/helpers/secretRotationsV2.ts b/frontend/src/helpers/secretRotationsV2.tsindex 4e8f168b3b..3cdac95bdf 100644--- a/frontend/src/helpers/secretRotationsV2.ts+++ b/frontend/src/helpers/secretRotationsV2.ts@@ -85,8 +85,8 @@ export const SECRET_ROTATION_MAP: Record<image: "OpenRouter.png",size: 50},- [SecretRotation.OpenAIAdminApiKey]: {- name: "OpenAI Admin API Key",+ [SecretRotation.OpenAIServiceAccount]: {+ name: "OpenAI Service Account",image: "OpenAI.png",size: 50},@@ -134,7 +134,7 @@ export const SECRET_ROTATION_CONNECTION_MAP: Record<SecretRotation, AppConnectio[SecretRotation.DbtServiceToken]: AppConnection.Dbt,[SecretRotation.WindowsLocalAccount]: AppConnection.SMB,[SecretRotation.OpenRouterApiKey]: AppConnection.OpenRouter,- [SecretRotation.OpenAIAdminApiKey]: AppConnection.OpenAI,+ [SecretRotation.OpenAIServiceAccount]: AppConnection.OpenAI,[SecretRotation.HpIloLocalAccount]: AppConnection.SSH,[SecretRotation.SupabaseApiKey]: AppConnection.Supabase,[SecretRotation.SalesforceOauthCredentials]: AppConnection.Salesforce,@@ -160,7 +160,7 @@ export const IS_ROTATION_DUAL_CREDENTIALS: Record<SecretRotation, boolean> = {[SecretRotation.DbtServiceToken]: true,[SecretRotation.WindowsLocalAccount]: false,[SecretRotation.OpenRouterApiKey]: true,- [SecretRotation.OpenAIAdminApiKey]: true,+ [SecretRotation.OpenAIServiceAccount]: true,[SecretRotation.HpIloLocalAccount]: false,[SecretRotation.SupabaseApiKey]: true,[SecretRotation.SalesforceOauthCredentials]: true,diff --git a/frontend/src/hooks/api/appConnections/openai/index.ts b/frontend/src/hooks/api/appConnections/openai/index.tsnew file mode 100644index 0000000000..2c1906d369--- /dev/null+++ b/frontend/src/hooks/api/appConnections/openai/index.ts@@ -0,0 +1,2 @@+export * from "./queries";+export * from "./types";diff --git a/frontend/src/hooks/api/appConnections/openai/queries.tsx b/frontend/src/hooks/api/appConnections/openai/queries.tsxnew file mode 100644index 0000000000..379896256a--- /dev/null+++ b/frontend/src/hooks/api/appConnections/openai/queries.tsx@@ -0,0 +1,37 @@+import { useQuery, UseQueryOptions } from "@tanstack/react-query";++import { apiRequest } from "@app/config/request";++import { appConnectionKeys } from "../queries";+import { TOpenAIProject } from "./types";++const openaiConnectionKeys = {+ all: [...appConnectionKeys.all, "openai"] as const,+ listProjects: (connectionId: string) =>+ [...openaiConnectionKeys.all, "projects", connectionId] as const+};++export const useListOpenAIConnectionProjects = (+ connectionId: string,+ options?: Omit<+ UseQueryOptions<+ TOpenAIProject[],+ unknown,+ TOpenAIProject[],+ ReturnType<typeof openaiConnectionKeys.listProjects>+ >,+ "queryKey" | "queryFn"+ >+) => {+ return useQuery({+ queryKey: openaiConnectionKeys.listProjects(connectionId),+ queryFn: async () => {+ const { data } = await apiRequest.get<{ projects: TOpenAIProject[] }>(+ `/api/v1/app-connections/openai/${connectionId}/projects`+ );++ return data.projects;+ },+ ...options+ });+};diff --git a/frontend/src/hooks/api/appConnections/openai/types.ts b/frontend/src/hooks/api/appConnections/openai/types.tsnew file mode 100644index 0000000000..bd7e711fbe--- /dev/null+++ b/frontend/src/hooks/api/appConnections/openai/types.ts@@ -0,0 +1,4 @@+export type TOpenAIProject = {+ id: string;+ name: string;+};diff --git a/frontend/src/hooks/api/secretRotationsV2/enums.ts b/frontend/src/hooks/api/secretRotationsV2/enums.tsindex b7cb3aa898..015ed127ad 100644--- a/frontend/src/hooks/api/secretRotationsV2/enums.ts+++ b/frontend/src/hooks/api/secretRotationsV2/enums.ts@@ -15,7 +15,7 @@ export enum SecretRotation {DbtServiceToken = "dbt-service-token",WindowsLocalAccount = "windows-local-account",OpenRouterApiKey = "open-router-api-key",- OpenAIAdminApiKey = "openai-admin-api-key",+ OpenAIServiceAccount = "openai-service-account",HpIloLocalAccount = "hp-ilo-local-account",SupabaseApiKey = "supabase-api-key",SalesforceOauthCredentials = "salesforce-oauth-credentials",diff --git a/frontend/src/hooks/api/secretRotationsV2/types/index.ts b/frontend/src/hooks/api/secretRotationsV2/types/index.tsindex d14510c593..8188fc6618 100644--- a/frontend/src/hooks/api/secretRotationsV2/types/index.ts+++ b/frontend/src/hooks/api/secretRotationsV2/types/index.ts@@ -76,10 +76,10 @@ import {TOpenRouterApiKeyRotationOption} from "./open-router-api-key-rotation";import {- TOpenAIAdminApiKeyRotation,- TOpenAIAdminApiKeyRotationGeneratedCredentialsResponse,- TOpenAIAdminApiKeyRotationOption-} from "./openai-admin-api-key-rotation";+ TOpenAIServiceAccountRotation,+ TOpenAIServiceAccountRotationGeneratedCredentialsResponse,+ TOpenAIServiceAccountRotationOption+} from "./openai-service-account-rotation";import {TOracleDBCredentialsRotation,TOracleDBCredentialsRotationGeneratedCredentialsResponse@@ -127,7 +127,7 @@ export type TSecretRotationV2 = (| TDbtServiceTokenRotation| TWindowsLocalAccountRotation| TOpenRouterApiKeyRotation- | TOpenAIAdminApiKeyRotation+ | TOpenAIServiceAccountRotation| THpIloRotation| TSupabaseApiKeyRotation| TSalesforceOauthCredentialsRotation@@ -151,7 +151,7 @@ export type TSecretRotationV2Option =| TDbtServiceTokenRotationOption| TWindowsLocalAccountRotationOption| TOpenRouterApiKeyRotationOption- | TOpenAIAdminApiKeyRotationOption+ | TOpenAIServiceAccountRotationOption| THpIloRotationOption| TSupabaseApiKeyRotationOption| TSalesforceOauthCredentialsRotationOption@@ -179,7 +179,7 @@ export type TViewSecretRotationGeneratedCredentialsResponse =| TDbtServiceTokenRotationGeneratedCredentialsResponse| TWindowsLocalAccountRotationGeneratedCredentialsResponse| TOpenRouterApiKeyRotationGeneratedCredentialsResponse- | TOpenAIAdminApiKeyRotationGeneratedCredentialsResponse+ | TOpenAIServiceAccountRotationGeneratedCredentialsResponse| THpIloRotationGeneratedCredentialsResponse| TSupabaseApiKeyRotationGeneratedCredentialsResponse| TSalesforceOauthCredentialsRotationGeneratedCredentialsResponse@@ -255,7 +255,7 @@ export type TSecretRotationOptionMap = {[SecretRotation.DbtServiceToken]: TDbtServiceTokenRotationOption;[SecretRotation.WindowsLocalAccount]: TWindowsLocalAccountRotationOption;[SecretRotation.OpenRouterApiKey]: TOpenRouterApiKeyRotationOption;- [SecretRotation.OpenAIAdminApiKey]: TOpenAIAdminApiKeyRotationOption;+ [SecretRotation.OpenAIServiceAccount]: TOpenAIServiceAccountRotationOption;[SecretRotation.HpIloLocalAccount]: THpIloRotationOption;[SecretRotation.SupabaseApiKey]: TSupabaseApiKeyRotationOption;[SecretRotation.SalesforceOauthCredentials]: TSalesforceOauthCredentialsRotationOption;@@ -280,7 +280,7 @@ export type TSecretRotationGeneratedCredentialsResponseMap = {[SecretRotation.DbtServiceToken]: TDbtServiceTokenRotationGeneratedCredentialsResponse;[SecretRotation.WindowsLocalAccount]: TWindowsLocalAccountRotationGeneratedCredentialsResponse;[SecretRotation.OpenRouterApiKey]: TOpenRouterApiKeyRotationGeneratedCredentialsResponse;- [SecretRotation.OpenAIAdminApiKey]: TOpenAIAdminApiKeyRotationGeneratedCredentialsResponse;+ [SecretRotation.OpenAIServiceAccount]: TOpenAIServiceAccountRotationGeneratedCredentialsResponse;[SecretRotation.HpIloLocalAccount]: THpIloRotationGeneratedCredentialsResponse;[SecretRotation.SupabaseApiKey]: TSupabaseApiKeyRotationGeneratedCredentialsResponse;[SecretRotation.SalesforceOauthCredentials]: TSalesforceOauthCredentialsRotationGeneratedCredentialsResponse;diff --git a/frontend/src/hooks/api/secretRotationsV2/types/openai-admin-api-key-rotation.ts b/frontend/src/hooks/api/secretRotationsV2/types/openai-admin-api-key-rotation.tsdeleted file mode 100644index c8782e6d7f..0000000000--- a/frontend/src/hooks/api/secretRotationsV2/types/openai-admin-api-key-rotation.ts+++ /dev/null@@ -1,36 +0,0 @@-import { AppConnection } from "@app/hooks/api/appConnections/enums";-import { SecretRotation } from "@app/hooks/api/secretRotationsV2";-import {- TSecretRotationV2Base,- TSecretRotationV2GeneratedCredentialsResponseBase-} from "@app/hooks/api/secretRotationsV2/types/shared";--export type TOpenAIAdminApiKeyRotation = TSecretRotationV2Base & {- type: SecretRotation.OpenAIAdminApiKey;- parameters: {- name: string;- };- secretsMapping: {- apiKey: string;- };-};--export type TOpenAIAdminApiKeyRotationGeneratedCredentials = {- apiKey: string;- keyId: string;-};--export type TOpenAIAdminApiKeyRotationGeneratedCredentialsResponse =- TSecretRotationV2GeneratedCredentialsResponseBase<- SecretRotation.OpenAIAdminApiKey,- TOpenAIAdminApiKeyRotationGeneratedCredentials- >;--export type TOpenAIAdminApiKeyRotationOption = {- name: string;- type: SecretRotation.OpenAIAdminApiKey;- connection: AppConnection.OpenAI;- template: {- secretsMapping: TOpenAIAdminApiKeyRotation["secretsMapping"];- };-};diff --git a/frontend/src/hooks/api/secretRotationsV2/types/openai-service-account-rotation.ts b/frontend/src/hooks/api/secretRotationsV2/types/openai-service-account-rotation.tsnew file mode 100644index 0000000000..51eb7c76c3--- /dev/null+++ b/frontend/src/hooks/api/secretRotationsV2/types/openai-service-account-rotation.ts@@ -0,0 +1,37 @@+import { AppConnection } from "@app/hooks/api/appConnections/enums";+import { SecretRotation } from "@app/hooks/api/secretRotationsV2";+import {+ TSecretRotationV2Base,+ TSecretRotationV2GeneratedCredentialsResponseBase+} from "@app/hooks/api/secretRotationsV2/types/shared";++export type TOpenAIServiceAccountRotation = TSecretRotationV2Base & {+ type: SecretRotation.OpenAIServiceAccount;+ parameters: {+ projectId: string;+ name: string;+ };+ secretsMapping: {+ apiKey: string;+ };+};++export type TOpenAIServiceAccountRotationGeneratedCredentials = {+ apiKey: string;+ serviceAccountId: string;+};++export type TOpenAIServiceAccountRotationGeneratedCredentialsResponse =+ TSecretRotationV2GeneratedCredentialsResponseBase<+ SecretRotation.OpenAIServiceAccount,+ TOpenAIServiceAccountRotationGeneratedCredentials+ >;++export type TOpenAIServiceAccountRotationOption = {+ name: string;+ type: SecretRotation.OpenAIServiceAccount;+ connection: AppConnection.OpenAI;+ template: {+ secretsMapping: TOpenAIServiceAccountRotation["secretsMapping"];+ };+};