Skip to content

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

fix(secret-sync): address second round of Daytona review feedback

InfisiCalvinad16606c2f4f
diff --git a/backend/src/services/app-connection/daytona/daytona-connection-fns.ts b/backend/src/services/app-connection/daytona/daytona-connection-fns.ts
index 64edb66902..cd597605e4 100644
--- a/backend/src/services/app-connection/daytona/daytona-connection-fns.ts
+++ b/backend/src/services/app-connection/daytona/daytona-connection-fns.ts
@@ -2,7 +2,6 @@ import { HttpStatusCode, isAxiosError } from "axios";
import { request } from "@app/lib/config/request";
import { BadRequestError } from "@app/lib/errors";
-import { logger } from "@app/lib/logger";
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
import { IntegrationUrls } from "@app/services/integration-auth/integration-list";
@@ -36,8 +35,9 @@ export const validateDaytonaConnectionCredentials = async (config: TDaytonaConne
headers: getDaytonaAuthHeaders(apiKey)
});
} catch (error: unknown) {
- logger.error({ error }, "Failed to validate Daytona connection");
-
+ // The raw Axios error is deliberately not logged: it carries the API key at
+ // config.headers.Authorization, which sits past the logger's depth-3 redaction and under a key
+ // name the redaction list does not cover.
if (isAxiosError(error)) {
if (error.response?.status === HttpStatusCode.Unauthorized) {
throw new BadRequestError({
diff --git a/backend/src/services/secret-sync/daytona/daytona-sync-fns.ts b/backend/src/services/secret-sync/daytona/daytona-sync-fns.ts
index 1c4b316d49..2a89575b56 100644
--- a/backend/src/services/secret-sync/daytona/daytona-sync-fns.ts
+++ b/backend/src/services/secret-sync/daytona/daytona-sync-fns.ts
@@ -2,7 +2,6 @@
import { HttpStatusCode, isAxiosError } from "axios";
import { request } from "@app/lib/config/request";
-import { logger } from "@app/lib/logger";
import { retryOnRateLimit } from "@app/lib/retry";
import { getDaytonaAuthHeaders } from "@app/services/app-connection/daytona";
import { IntegrationUrls } from "@app/services/integration-auth/integration-list";
@@ -10,12 +9,9 @@ import { SecretSyncError } from "@app/services/secret-sync/secret-sync-errors";
import { matchesSchema } from "@app/services/secret-sync/secret-sync-fns";
import { TSecretMap } from "@app/services/secret-sync/secret-sync-types";
+import { DAYTONA_SECRET_NAME_PATTERN, DAYTONA_SECRET_NAME_RULE } from "./daytona-sync-schemas";
import { TDaytonaListSecretsResponse, TDaytonaSecret, TDaytonaSyncWithCredentials } from "./daytona-sync-types";
-const DAYTONA_SECRET_NAME_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_-]*$/;
-const DAYTONA_SECRET_NAME_RULE =
- "Daytona secret names must start with a letter or underscore and contain only letters, digits, hyphens and underscores.";
-
const DAYTONA_PAGE_SIZE = 100;
const DAYTONA_MAX_PAGES = 10;
@@ -39,11 +35,11 @@ const listDaytonaSecrets = async (apiKey: string): Promise<TDaytonaSecret[]> =>
if (!cursor) return secrets;
}
- logger.warn(
- `Daytona secret listing stopped at the ${DAYTONA_MAX_PAGES} page cap; the destination may hold more secrets than were read`
+ // Returning here would hand reconciliation a partial snapshot: keys past the cap would look
+ // absent, so the sync would recreate them and skip deletions it owed.
+ throw new Error(
+ `Daytona returned more than ${DAYTONA_MAX_PAGES * DAYTONA_PAGE_SIZE} secrets, which exceeds the ${DAYTONA_MAX_PAGES} page listing cap. Refusing to sync from an incomplete view of the destination.`
);
-
- return secrets;
};
const createDaytonaSecret = (apiKey: string, name: string, value: string) =>
diff --git a/backend/src/services/secret-sync/daytona/daytona-sync-schemas.ts b/backend/src/services/secret-sync/daytona/daytona-sync-schemas.ts
index f0e3d40b70..32dfb9d0e3 100644
--- a/backend/src/services/secret-sync/daytona/daytona-sync-schemas.ts
+++ b/backend/src/services/secret-sync/daytona/daytona-sync-schemas.ts
@@ -11,6 +11,25 @@ import {
} from "@app/services/secret-sync/secret-sync-schemas";
import { TSyncOptionsConfig } from "@app/services/secret-sync/secret-sync-types";
+export const DAYTONA_SECRET_NAME_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_-]*$/;
+export const DAYTONA_SECRET_NAME_RULE =
+ "Daytona secret names must start with a letter or underscore and contain only letters, digits, hyphens and underscores.";
+
+// A key schema is applied to every synced key, so literal characters Daytona rejects (a slash, a
+// leading digit) would produce a sync that saves cleanly and then fails on every run. Placeholders
+// are substituted with a token that is itself valid so only the schema's literals are under test;
+// the resolved names are checked again at sync time.
+const isDaytonaCompatibleKeySchema = (keySchema?: string) =>
+ !keySchema || DAYTONA_SECRET_NAME_PATTERN.test(keySchema.replace(/\{\{secretKey\}\}|\{\{environment\}\}/g, "A"));
+
+const hasDaytonaCompatibleKeySchema = (val: { syncOptions?: { keySchema?: string } }) =>
+ isDaytonaCompatibleKeySchema(val.syncOptions?.keySchema);
+
+const DAYTONA_KEY_SCHEMA_ERROR = {
+ message: `Key schema produces names Daytona rejects. ${DAYTONA_SECRET_NAME_RULE}`,
+ path: ["syncOptions", "keySchema"]
+};
+
const DaytonaSyncDestinationConfigSchema = z.object({
organizationName: z
.string()
@@ -29,19 +48,17 @@ export const DaytonaSyncSchema = BaseSecretSyncSchema(SecretSync.Daytona, Dayton
})
.describe(JSON.stringify({ title: SECRET_SYNC_NAME_MAP[SecretSync.Daytona] }));
-export const CreateDaytonaSyncSchema = GenericCreateSecretSyncFieldsSchema(
- SecretSync.Daytona,
- DaytonaSyncOptionsConfig
-).extend({
- destinationConfig: DaytonaSyncDestinationConfigSchema
-});
+export const CreateDaytonaSyncSchema = GenericCreateSecretSyncFieldsSchema(SecretSync.Daytona, DaytonaSyncOptionsConfig)
+ .extend({
+ destinationConfig: DaytonaSyncDestinationConfigSchema
+ })
+ .refine(hasDaytonaCompatibleKeySchema, DAYTONA_KEY_SCHEMA_ERROR);
-export const UpdateDaytonaSyncSchema = GenericUpdateSecretSyncFieldsSchema(
- SecretSync.Daytona,
- DaytonaSyncOptionsConfig
-).extend({
- destinationConfig: DaytonaSyncDestinationConfigSchema.optional()
-});
+export const UpdateDaytonaSyncSchema = GenericUpdateSecretSyncFieldsSchema(SecretSync.Daytona, DaytonaSyncOptionsConfig)
+ .extend({
+ destinationConfig: DaytonaSyncDestinationConfigSchema.optional()
+ })
+ .refine(hasDaytonaCompatibleKeySchema, DAYTONA_KEY_SCHEMA_ERROR);
export const DaytonaSyncListItemSchema = z
.object({
diff --git a/docs/integrations/secret-syncs/daytona.mdx b/docs/integrations/secret-syncs/daytona.mdx
index a5478c86e3..3720a2563d 100644
--- a/docs/integrations/secret-syncs/daytona.mdx
+++ b/docs/integrations/secret-syncs/daytona.mdx
@@ -9,6 +9,8 @@ description: "Learn how to configure a Daytona sync for Infisical."
<Note>
Daytona secret names must start with a letter or an underscore, and can contain only letters, digits, hyphens, and underscores. A sync that includes a key Daytona rejects fails and names the offending key, so no secrets are written. Use a **key schema** to reshape names that do not fit.
+
+ The key schema itself is checked against the same rule when you create or update the sync, so a schema containing a slash is rejected up front rather than failing on every run.
</Note>
<Tabs>
@@ -84,10 +86,9 @@ description: "Learn how to configure a Daytona sync for Infisical."
"connectionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"environment": "dev",
"secretPath": "/my-secrets",
- "isEnabled": true,
+ "isAutoSyncEnabled": true,
"syncOptions": {
"initialSyncBehavior": "overwrite-destination",
- "autoSyncEnabled": true,
"disableSecretDeletion": false
},
"destinationConfig": {
@@ -104,7 +105,7 @@ description: "Learn how to configure a Daytona sync for Infisical."
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"name": "my-daytona-sync",
"description": "an example sync",
- "isEnabled": true,
+ "isAutoSyncEnabled": true,
"version": 1,
"folderId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"connectionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
@@ -124,7 +125,6 @@ description: "Learn how to configure a Daytona sync for Infisical."
"lastRemovedAt": null,
"syncOptions": {
"initialSyncBehavior": "overwrite-destination",
- "autoSyncEnabled": true,
"disableSecretDeletion": false
},
"projectId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",