Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

add verification of secrets for auth0 rotations

adilsondb72db904c79
diff --git a/backend/src/ee/services/secret-rotation-v2/auth0-client-secret/auth0-client-secret-rotation-fns.ts b/backend/src/ee/services/secret-rotation-v2/auth0-client-secret/auth0-client-secret-rotation-fns.ts
index 3a4c26211a..4fc02f39de 100644
--- a/backend/src/ee/services/secret-rotation-v2/auth0-client-secret/auth0-client-secret-rotation-fns.ts
+++ b/backend/src/ee/services/secret-rotation-v2/auth0-client-secret/auth0-client-secret-rotation-fns.ts
@@ -1,15 +1,20 @@
+import { AxiosError } from "axios";
+
import {
TAuth0ClientSecretRotationGeneratedCredentials,
TAuth0ClientSecretRotationWithConnection
} from "@app/ee/services/secret-rotation-v2/auth0-client-secret/auth0-client-secret-rotation-types";
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 { removeTrailingSlash } from "@app/lib/fn";
import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
import { getAuth0ConnectionAccessToken } from "@app/services/app-connection/auth0/auth0-connection-fns";
@@ -95,10 +100,42 @@ export const auth0ClientSecretRotationFactory: TRotationFactory<
return secrets;
};
+ const checkActiveCredentials: TRotationFactoryCheckActiveCredentials<
+ TAuth0ClientSecretRotationGeneratedCredentials
+ > = async ({ clientId: activeClientId, clientSecret }) => {
+ const { domain, audience } = connection.credentials;
+ const instanceUrl = domain.startsWith("http") ? domain : `https://${domain}`;
+ await blockLocalAndPrivateIpAddresses(instanceUrl);
+
+ try {
+ await request.request({
+ method: "POST",
+ url: `${removeTrailingSlash(instanceUrl)}/oauth/token`,
+ headers: { "content-type": "application/x-www-form-urlencoded" },
+ data: new URLSearchParams({
+ grant_type: "client_credentials",
+ client_id: activeClientId,
+ client_secret: clientSecret,
+ audience
+ })
+ });
+ } catch (error: unknown) {
+ if (error instanceof AxiosError) {
+ const errorData = error.response?.data as { error?: string; error_description?: string } | undefined;
+ if (errorData?.error === "access_denied") return;
+ throw new BadRequestError({
+ message: `Auth0 client credentials check failed: ${errorData?.error_description ?? errorData?.error ?? error.message}`
+ });
+ }
+ throw error;
+ }
+ };
+
return {
issueCredentials,
revokeCredentials,
rotateCredentials,
- getSecretsPayload
+ getSecretsPayload,
+ checkActiveCredentials
};
};
diff --git a/backend/src/ee/services/secret-rotation-v2/databricks-service-principal-secret/databricks-service-principal-secret-rotation-fns.ts b/backend/src/ee/services/secret-rotation-v2/databricks-service-principal-secret/databricks-service-principal-secret-rotation-fns.ts
index 6581c057cd..a9048bb7c5 100644
--- a/backend/src/ee/services/secret-rotation-v2/databricks-service-principal-secret/databricks-service-principal-secret-rotation-fns.ts
+++ b/backend/src/ee/services/secret-rotation-v2/databricks-service-principal-secret/databricks-service-principal-secret-rotation-fns.ts
@@ -7,6 +7,7 @@ import {
} from "@app/ee/services/secret-rotation-v2/databricks-service-principal-secret/databricks-service-principal-secret-rotation-types";
import {
TRotationFactory,
+ TRotationFactoryCheckActiveCredentials,
TRotationFactoryGetSecretsPayload,
TRotationFactoryIssueCredentials,
TRotationFactoryRevokeCredentials,
@@ -253,10 +254,62 @@ export const databricksServicePrincipalSecretRotationFactory: TRotationFactory<
{ key: secretsMapping.clientSecret, value: clientSecret }
];
+ const checkActiveCredentials: TRotationFactoryCheckActiveCredentials<
+ TDatabricksServicePrincipalSecretRotationGeneratedCredentials
+ > = async ({ clientId: activeClientId, clientSecret }) => {
+ const workspaceUrl = removeTrailingSlash(connection.credentials.workspaceUrl);
+ await blockLocalAndPrivateIpAddresses(workspaceUrl);
+ const tokenEndpoint = `${workspaceUrl}/oidc/v1/token`;
+ const basicAuth = Buffer.from(`${activeClientId}:${clientSecret}`).toString("base64");
+
+ try {
+ await request.post(
+ tokenEndpoint,
+ new URLSearchParams({
+ grant_type: "client_credentials",
+ scope: "all-apis"
+ }).toString(),
+ {
+ headers: {
+ "Content-Type": "application/x-www-form-urlencoded",
+ Authorization: `Basic ${basicAuth}`
+ }
+ }
+ );
+ } catch (error: unknown) {
+ let errorMessage = "Unknown error";
+
+ if (error instanceof AxiosError && error.response?.data) {
+ const responseData: unknown = error.response.data;
+
+ if (typeof responseData === "string") {
+ errorMessage = responseData;
+ } else if (typeof responseData === "object" && responseData !== null) {
+ const data = responseData as Record<string, unknown>;
+ errorMessage =
+ (data.error_description as string | undefined) ||
+ (data.error as string | undefined) ||
+ (data.message as string | undefined) ||
+ error.message ||
+ "Unknown error";
+ }
+ } else if (error instanceof AxiosError && error.message) {
+ errorMessage = error.message;
+ } else if (error instanceof Error) {
+ errorMessage = error.message;
+ }
+
+ throw new BadRequestError({
+ message: `Databricks client credentials check failed: ${errorMessage}`
+ });
+ }
+ };
+
return {
issueCredentials,
revokeCredentials,
rotateCredentials,
- getSecretsPayload
+ getSecretsPayload,
+ checkActiveCredentials
};
};
diff --git a/backend/src/ee/services/secret-rotation-v2/okta-client-secret/okta-client-secret-rotation-fns.ts b/backend/src/ee/services/secret-rotation-v2/okta-client-secret/okta-client-secret-rotation-fns.ts
index 0fe4438d1f..a943f788fd 100644
--- a/backend/src/ee/services/secret-rotation-v2/okta-client-secret/okta-client-secret-rotation-fns.ts
+++ b/backend/src/ee/services/secret-rotation-v2/okta-client-secret/okta-client-secret-rotation-fns.ts
@@ -3,6 +3,7 @@ import { AxiosError } from "axios";
import {
TRotationFactory,
+ TRotationFactoryCheckActiveCredentials,
TRotationFactoryGetSecretsPayload,
TRotationFactoryIssueCredentials,
TRotationFactoryRevokeCredentials,
@@ -264,10 +265,46 @@ export const oktaClientSecretRotationFactory: TRotationFactory<
{ key: secretsMapping.clientSecret, value: clientSecret }
];
+ const checkActiveCredentials: TRotationFactoryCheckActiveCredentials<
+ TOktaClientSecretRotationGeneratedCredentials
+ > = async ({ clientId: activeClientId, clientSecret }) => {
+ const instanceUrl = await getOktaInstanceUrl(connection);
+ const tokenUrl = `${instanceUrl}/oauth2/default/v1/token`;
+ const basicAuth = Buffer.from(`${activeClientId}:${clientSecret}`).toString("base64");
+
+ try {
+ await request.post(
+ tokenUrl,
+ new URLSearchParams({
+ grant_type: "client_credentials",
+ scope: "infisical-credential-check"
+ }).toString(),
+ {
+ headers: {
+ Accept: "application/json",
+ "Content-Type": "application/x-www-form-urlencoded",
+ Authorization: `Basic ${basicAuth}`
+ }
+ }
+ );
+ } catch (error: unknown) {
+ if (error instanceof AxiosError) {
+ const errorData = error.response?.data as { error?: string; error_description?: string } | undefined;
+ throw new BadRequestError({
+ message: `Okta client credentials check failed: ${errorData?.error_description ?? errorData?.error ?? error.message}`
+ });
+ }
+ throw new BadRequestError({
+ message: `Okta client credentials check failed: ${createErrorMessage(error)}`
+ });
+ }
+ };
+
return {
issueCredentials,
revokeCredentials,
rotateCredentials,
- getSecretsPayload
+ getSecretsPayload,
+ checkActiveCredentials
};
};