Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat: allow host credentials for blob storage S3 integration (#7072)

Steffen Schmitz8d808923a1fe
diff --git a/packages/shared/prisma/generated/types.ts b/packages/shared/prisma/generated/types.ts
index 8c237ad62e..273089c178 100644
--- a/packages/shared/prisma/generated/types.ts
+++ b/packages/shared/prisma/generated/types.ts
@@ -228,8 +228,8 @@ export type BlobStorageIntegration = {
type: BlobStorageIntegrationType;
bucket_name: string;
prefix: string;
- access_key_id: string;
- secret_access_key: string;
+ access_key_id: string | null;
+ secret_access_key: string | null;
region: string;
endpoint: string | null;
force_path_style: boolean;
diff --git a/packages/shared/prisma/migrations/20250529071241_make_blobstorage_integration_credentials_optional/migration.sql b/packages/shared/prisma/migrations/20250529071241_make_blobstorage_integration_credentials_optional/migration.sql
new file mode 100644
index 0000000000..7088f8a22e
--- /dev/null
+++ b/packages/shared/prisma/migrations/20250529071241_make_blobstorage_integration_credentials_optional/migration.sql
@@ -0,0 +1,3 @@
+-- AlterTable
+ALTER TABLE "blob_storage_integrations" ALTER COLUMN "access_key_id" DROP NOT NULL,
+ALTER COLUMN "secret_access_key" DROP NOT NULL;
diff --git a/packages/shared/prisma/schema.prisma b/packages/shared/prisma/schema.prisma
index 6c62ad7d56..1425b95294 100644
--- a/packages/shared/prisma/schema.prisma
+++ b/packages/shared/prisma/schema.prisma
@@ -951,8 +951,8 @@ model BlobStorageIntegration {
type BlobStorageIntegrationType @map("type")
bucketName String @map("bucket_name")
prefix String @map("prefix")
- accessKeyId String @map("access_key_id")
- secretAccessKey String @map("secret_access_key")
+ accessKeyId String? @map("access_key_id")
+ secretAccessKey String? @map("secret_access_key")
region String @map("region")
endpoint String? @map("endpoint")
forcePathStyle Boolean @map("force_path_style")
diff --git a/web/src/features/blobstorage-integration/blobstorage-integration-router.ts b/web/src/features/blobstorage-integration/blobstorage-integration-router.ts
index 67510cf56a..be6b6e8b2b 100644
--- a/web/src/features/blobstorage-integration/blobstorage-integration-router.ts
+++ b/web/src/features/blobstorage-integration/blobstorage-integration-router.ts
@@ -16,12 +16,13 @@ import {
QueueJobs,
StorageServiceFactory,
} from "@langfuse/shared/src/server";
+import { randomUUID } from "crypto";
+import { decrypt } from "@langfuse/shared/encryption";
import {
type BlobStorageIntegration,
BlobStorageIntegrationType,
} from "@langfuse/shared";
-import { randomUUID } from "crypto";
-import { decrypt } from "@langfuse/shared/encryption";
+import { env } from "@/src/env.mjs";
export const blobStorageIntegrationRouter = createTRPCRouter({
get: protectedProjectProcedure
@@ -97,6 +98,19 @@ export const blobStorageIntegrationRouter = createTRPCRouter({
fileType,
} = input;
+ const isSelfHosted = !env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION;
+ const canUseHostCredentials =
+ isSelfHosted && type === BlobStorageIntegrationType.S3;
+ const isUsingHostCredentials =
+ canUseHostCredentials && (!accessKeyId || !secretAccessKey);
+
+ if (!canUseHostCredentials && !accessKeyId) {
+ throw new TRPCError({
+ code: "BAD_REQUEST",
+ message: "Access Key ID and Secret Access Key are required",
+ });
+ }
+
const data: Partial<BlobStorageIntegration> = {
type,
bucketName,
@@ -122,7 +136,6 @@ export const blobStorageIntegrationRouter = createTRPCRouter({
);
if (existingConfig) {
- // Record exists, perform update
if (secretAccessKey) {
data.secretAccessKey = encrypt(secretAccessKey);
}
@@ -135,11 +148,11 @@ export const blobStorageIntegrationRouter = createTRPCRouter({
});
} else {
// Record doesn't exist, perform create
- // For create, secretAccessKey is mandatory
- if (!secretAccessKey) {
+ if (!isUsingHostCredentials && !secretAccessKey) {
throw new TRPCError({
code: "BAD_REQUEST",
- message: "Secret access key is required for new configuration",
+ message:
+ "Secret access key is required for new configuration when not using host credentials",
});
}
@@ -148,12 +161,17 @@ export const blobStorageIntegrationRouter = createTRPCRouter({
...(data as BlobStorageIntegration),
projectId: input.projectId,
accessKeyId,
- secretAccessKey: encrypt(secretAccessKey),
+ secretAccessKey: secretAccessKey
+ ? encrypt(secretAccessKey)
+ : undefined,
},
});
}
});
} catch (e) {
+ if (e instanceof TRPCError) {
+ throw e;
+ }
logger.error(`Failed to update blob storage integration`, e);
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
@@ -292,13 +310,6 @@ export const blobStorageIntegrationRouter = createTRPCRouter({
projectId: input.projectId,
scope: "integrations:CRUD",
});
- await auditLog({
- session: ctx.session,
- action: "create",
- resourceType: "blobStorageIntegration",
- resourceId: input.projectId,
- after: { action: "validation_test" },
- });
// Get persisted configuration
const integration = await ctx.prisma.blobStorageIntegration.findUnique({
@@ -327,11 +338,13 @@ export const blobStorageIntegrationRouter = createTRPCRouter({
forcePathStyle,
} = integration;
- const secretAccessKey = decrypt(encryptedSecretAccessKey);
+ const secretAccessKey = encryptedSecretAccessKey
+ ? decrypt(encryptedSecretAccessKey)
+ : undefined;
// Create storage service with provided configuration
const storageService = StorageServiceFactory.getInstance({
- accessKeyId,
+ accessKeyId: accessKeyId || undefined,
secretAccessKey,
bucketName,
endpoint: endpoint || undefined,
diff --git a/web/src/features/blobstorage-integration/types.ts b/web/src/features/blobstorage-integration/types.ts
index c1c71ab0e8..71d4118539 100644
--- a/web/src/features/blobstorage-integration/types.ts
+++ b/web/src/features/blobstorage-integration/types.ts
@@ -9,11 +9,8 @@ export const blobStorageIntegrationFormSchema = z.object({
bucketName: z.string().min(1, { message: "Bucket name is required" }),
endpoint: z.string().url().optional().nullable(),
region: z.string().default("auto"),
- accessKeyId: z.string().min(1, { message: "Access key ID is required" }),
- secretAccessKey: z
- .string()
- .min(1, { message: "Secret access key is required" })
- .nullable(), // Only required on create
+ accessKeyId: z.string().optional(),
+ secretAccessKey: z.string().nullable().optional(),
prefix: z
.string()
.refine((value) => !value || value === "" || value.endsWith("/"), {
diff --git a/web/src/pages/project/[projectId]/settings/integrations/blobstorage.tsx b/web/src/pages/project/[projectId]/settings/integrations/blobstorage.tsx
index a84ecf36ff..ed7d0e8e8d 100644
--- a/web/src/pages/project/[projectId]/settings/integrations/blobstorage.tsx
+++ b/web/src/pages/project/[projectId]/settings/integrations/blobstorage.tsx
@@ -22,6 +22,7 @@ import {
SelectValue,
} from "@/src/components/ui/select";
import { useHasEntitlement } from "@/src/features/entitlements/hooks";
+import { env } from "@/src/env.mjs";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
import {
blobStorageIntegrationFormSchema,
@@ -144,6 +145,14 @@ const BlobStorageIntegrationSettingsForm = ({
const [integrationType, setIntegrationType] =
useState<BlobStorageIntegrationType>(BlobStorageIntegrationType.S3);
+ // Check if this is a self-hosted instance (no cloud region set)
+ const isSelfHosted = !env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION;
+
+ // Check if user has blob storage entitlement
+ const hasBlobStorageEntitlement = useHasEntitlement(
+ "integration-blobstorage",
+ );
+
const blobStorageForm = useForm<BlobStorageIntegrationFormSchema>({
resolver: zodResolver(blobStorageIntegrationFormSchema),
defaultValues: {
@@ -369,6 +378,12 @@ const BlobStorageIntegrationSettingsForm = ({
: integrationType === "S3"
? "AWS Access Key ID"
: "Access Key ID"}
+ {/* Show optional indicator for S3 types on self-hosted instances with entitlement */}
+ {isSelfHosted &&
+ hasBlobStorageEntitlement &&
+ integrationType === "S3" && (
+ <span className="text-muted-foreground"> (optional)</span>
+ )}
</FormLabel>
<FormControl>
<Input {...field} />
@@ -377,7 +392,9 @@ const BlobStorageIntegrationSettingsForm = ({
{integrationType === "AZURE_BLOB_STORAGE"
? "Your Azure storage account name"
: integrationType === "S3"
- ? "Your AWS IAM user access key ID"
+ ? isSelfHosted && hasBlobStorageEntitlement
+ ? "Your AWS IAM user access key ID. Leave empty to use host credentials (IAM roles, instance profiles, etc.)"
+ : "Your AWS IAM user access key ID"
: "Access key for your S3-compatible storage"}
</FormDescription>
<FormMessage />
@@ -396,6 +413,12 @@ const BlobStorageIntegrationSettingsForm = ({
: integrationType === "S3"
? "AWS Secret Access Key"
: "Secret Access Key"}
+ {/* Show optional indicator for S3 types on self-hosted instances with entitlement */}
+ {isSelfHosted &&
+ hasBlobStorageEntitlement &&
+ integrationType === "S3" && (
+ <span className="text-muted-foreground"> (optional)</span>
+ )}
</FormLabel>
<FormControl>
<PasswordInput
@@ -408,7 +431,9 @@ const BlobStorageIntegrationSettingsForm = ({
{integrationType === "AZURE_BLOB_STORAGE"
? "Your Azure storage account access key"
: integrationType === "S3"
- ? "Your AWS IAM user secret access key"
+ ? isSelfHosted && hasBlobStorageEntitlement
+ ? "Your AWS IAM user secret access key. Leave empty to use host credentials (IAM roles, instance profiles, etc.)"
+ : "Your AWS IAM user secret access key"
: "Secret key for your S3-compatible storage"}
</FormDescription>
<FormMessage />
diff --git a/worker/src/ee/integrations/blobstorage/handleBlobStorageIntegrationProjectJob.ts b/worker/src/ee/integrations/blobstorage/handleBlobStorageIntegrationProjectJob.ts
index b370e41f46..9b88561ab1 100644
--- a/worker/src/ee/integrations/blobstorage/handleBlobStorageIntegrationProjectJob.ts
+++ b/worker/src/ee/integrations/blobstorage/handleBlobStorageIntegrationProjectJob.ts
@@ -49,8 +49,8 @@ const processBlobStorageExport = async (config: {
bucketName: string;
endpoint: string | null;
region?: string;
- accessKeyId: string;
- secretAccessKey: string;
+ accessKeyId: string | undefined;
+ secretAccessKey: string | undefined;
prefix?: string;
forcePathStyle?: boolean;
type: BlobStorageIntegrationType;
@@ -186,8 +186,10 @@ export const handleBlobStorageIntegrationProjectJob = async (
bucketName: blobStorageIntegration.bucketName,
endpoint: blobStorageIntegration.endpoint,
region: blobStorageIntegration.region || undefined,
- accessKeyId: blobStorageIntegration.accessKeyId,
- secretAccessKey: decrypt(blobStorageIntegration.secretAccessKey),
+ accessKeyId: blobStorageIntegration.accessKeyId || undefined,
+ secretAccessKey: blobStorageIntegration.secretAccessKey
+ ? decrypt(blobStorageIntegration.secretAccessKey)
+ : undefined,
prefix: blobStorageIntegration.prefix || undefined,
forcePathStyle: blobStorageIntegration.forcePathStyle || undefined,
type: blobStorageIntegration.type,