Skip to content

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

fix http request to zilliz cloud

adilsonb702313d24a8
diff --git a/backend/src/ee/services/dynamic-secret/providers/milvus.test.ts b/backend/src/ee/services/dynamic-secret/providers/milvus.test.ts
new file mode 100644
index 0000000000..d115bf4f7f
--- /dev/null
+++ b/backend/src/ee/services/dynamic-secret/providers/milvus.test.ts
@@ -0,0 +1,59 @@
+import { describe, expect, test } from "vitest";
+
+import { parseMilvusHost, resolveMilvusUseTls } from "./milvus";
+
+describe("parseMilvusHost", () => {
+ test("parses bare localhost", () => {
+ const { hostname, origin } = parseMilvusHost("localhost", 19530, false);
+ expect(hostname).toBe("localhost");
+ expect(origin).toBe("http://localhost:19530");
+ });
+
+ test("parses localhost with http scheme", () => {
+ const { hostname, origin } = parseMilvusHost("http://localhost", 19530, false);
+ expect(hostname).toBe("localhost");
+ expect(origin).toBe("http://localhost:19530");
+ });
+
+ test("uses https when TLS is enabled", () => {
+ const { hostname, origin } = parseMilvusHost("milvus.example.com", 19530, true);
+ expect(hostname).toBe("milvus.example.com");
+ expect(origin).toBe("https://milvus.example.com:19530");
+ });
+
+ test("overrides embedded port with the port input", () => {
+ const { hostname, origin } = parseMilvusHost("localhost:9999", 19530, false);
+ expect(hostname).toBe("localhost");
+ expect(origin).toBe("http://localhost:19530");
+ });
+
+ test("parses bare IPv4 address", () => {
+ const { hostname, origin } = parseMilvusHost("127.0.0.1", 19530, false);
+ expect(hostname).toBe("127.0.0.1");
+ expect(origin).toBe("http://127.0.0.1:19530");
+ });
+
+ test("uses https when host scheme is https without CA", () => {
+ const { hostname, origin } = parseMilvusHost("https://localhost", 19530, resolveMilvusUseTls("https://localhost"));
+ expect(hostname).toBe("localhost");
+ expect(origin).toBe("https://localhost:19530");
+ });
+});
+
+describe("resolveMilvusUseTls", () => {
+ test("enables TLS for https host without CA", () => {
+ expect(resolveMilvusUseTls("https://milvus.example.com")).toBe(true);
+ });
+
+ test("disables TLS for http host even when CA is provided", () => {
+ expect(resolveMilvusUseTls("http://milvus.example.com", "ca-cert")).toBe(false);
+ });
+
+ test("enables TLS for bare host when CA is provided", () => {
+ expect(resolveMilvusUseTls("milvus.example.com", "ca-cert")).toBe(true);
+ });
+
+ test("disables TLS for bare host without CA", () => {
+ expect(resolveMilvusUseTls("localhost")).toBe(false);
+ });
+});
diff --git a/backend/src/ee/services/dynamic-secret/providers/milvus.ts b/backend/src/ee/services/dynamic-secret/providers/milvus.ts
index fbabb8682c..4e0eed2174 100644
--- a/backend/src/ee/services/dynamic-secret/providers/milvus.ts
+++ b/backend/src/ee/services/dynamic-secret/providers/milvus.ts
@@ -46,10 +46,34 @@ const generatePassword = () => {
return customAlphabet(charset, 32)();
};
+// it is possible to connect to Milvus without defining a CA, because they have their on demand cluster on zilliz cloud
+export const resolveMilvusUseTls = (host: string, ca?: string) => {
+ if (/^https:\/\//i.test(host)) return true;
+ if (/^http:\/\//i.test(host)) return false;
+ return Boolean(ca);
+};
+
+export const parseMilvusHost = (host: string, port: number, useTls: boolean) => {
+ const hostWithoutScheme = host.replace(/^https?:\/\//i, "");
+ const scheme = useTls ? "https" : "http";
+ const urlString = hostWithoutScheme.includes("://") ? hostWithoutScheme : `${scheme}://${hostWithoutScheme}`;
+
+ let url: URL;
+ try {
+ url = new URL(urlString);
+ } catch (err) {
+ logger.error(err, `Invalid Milvus host URL: ${host}`);
+ throw new BadRequestError({ message: "Invalid Milvus host URL" });
+ }
+
+ url.port = String(port);
+ return { hostname: url.hostname, origin: url.origin };
+};
+
const buildBaseUrl = (providerInputs: TMilvusProviderInputs, host: string, port: number) => {
- const sanitizedHost = host.replace(/^https?:\/\//i, "");
- const scheme = providerInputs.ca ? "https" : "http";
- return `${scheme}://${sanitizedHost}:${port}`;
+ const useTls = resolveMilvusUseTls(host, providerInputs.ca);
+ const { origin } = parseMilvusHost(host, port, useTls);
+ return origin;
};
export const MILVUS_MAX_USERNAME_LENGTH = 32;
@@ -67,13 +91,13 @@ export const MilvusProvider = ({
}: TMilvusProviderDTO): TDynamicProviderFns => {
const validateProviderInputs = async (inputs: object) => {
const providerInputs = await DynamicSecretMilvusSchema.parseAsync(inputs);
- const sanitizedHost = providerInputs.host.replace(/^https?:\/\//i, "");
+ const useTls = resolveMilvusUseTls(providerInputs.host, providerInputs.ca);
+ const { hostname, origin } = parseMilvusHost(providerInputs.host, providerInputs.port, useTls);
const isGateway = Boolean(providerInputs.gatewayId || providerInputs.gatewayPoolId);
- if (!isGateway) {
- await blockLocalAndPrivateIpAddresses(sanitizedHost);
- }
- await verifyHostInputValidity({ host: sanitizedHost, isDynamicSecret: true, isGateway });
+ await blockLocalAndPrivateIpAddresses(origin, isGateway);
+
+ await verifyHostInputValidity({ host: hostname, isDynamicSecret: true, isGateway });
return providerInputs;
};
diff --git a/backend/src/ee/services/dynamic-secret/providers/models.ts b/backend/src/ee/services/dynamic-secret/providers/models.ts
index fe54098918..01e2272556 100644
--- a/backend/src/ee/services/dynamic-secret/providers/models.ts
+++ b/backend/src/ee/services/dynamic-secret/providers/models.ts
@@ -725,7 +725,7 @@ export const DynamicSecretMilvusSchema = z.object({
.trim()
.min(1)
.describe(
- "Milvus endpoint host. URL scheme is optional; defaults to https when a CA is provided, otherwise http (e.g. localhost or http://localhost)."
+ "Milvus endpoint host. URL scheme is optional; uses https when the host includes https:// or a CA is provided, http when the host includes http://, otherwise http (e.g. localhost)."
),
port: z.number().int().min(1).max(65535),
username: z.string().trim().min(1).describe("Admin username used to manage Milvus users and roles"),