Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support passing certificate buffer #336

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions milvus/grpc/BaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,15 @@

// If the root certificate path is provided, also set to one-way authentication
this.tlsMode =
this.config.tls && this.config.tls.rootCertPath
this.config.tls &&
(this.config.tls.rootCert || this.config.tls.rootCertPath)
? TLS_MODE.ONE_WAY
: this.tlsMode;

// If the private key path is provided, set to two-way authentication
this.tlsMode =
this.config.tls && this.config.tls.privateKeyPath
this.config.tls &&
(this.config.tls.privateKey || this.config.tls.privateKeyPath)
? TLS_MODE.TWO_WAY
: this.tlsMode;

Expand All @@ -187,20 +189,34 @@
// For one-way authentication, create SSL credentials with the root certificate if provided
const sslOption = this.config.tls?.rootCertPath
? readFileSync(this.config.tls?.rootCertPath)
: undefined;
: this.config.tls?.rootCert || undefined;
this.creds = credentials.createSsl(sslOption);
break;
case TLS_MODE.TWO_WAY:
// For two-way authentication, create SSL credentials with the root certificate, private key, certificate chain, and verify options
const { rootCertPath, privateKeyPath, certChainPath, verifyOptions } =
this.config.tls!;
const rootCertBuff: Buffer | null = rootCertPath
const {
rootCertPath,
rootCert,
privateKeyPath,
privateKey,
certChainPath,
certChain,
verifyOptions,
} = this.config.tls!;

const rootCertBuff: Buffer | null = rootCert
? rootCert

Check warning on line 208 in milvus/grpc/BaseClient.ts

View check run for this annotation

Codecov / codecov/patch

milvus/grpc/BaseClient.ts#L208

Added line #L208 was not covered by tests
: rootCertPath
? readFileSync(rootCertPath)
: null;
const privateKeyBuff: Buffer | null = privateKeyPath
const privateKeyBuff: Buffer | null = privateKey
? privateKey

Check warning on line 213 in milvus/grpc/BaseClient.ts

View check run for this annotation

Codecov / codecov/patch

milvus/grpc/BaseClient.ts#L213

Added line #L213 was not covered by tests
: privateKeyPath
? readFileSync(privateKeyPath)
: null;
const certChainBuff: Buffer | null = certChainPath
const certChainBuff: Buffer | null = certChain
? certChain

Check warning on line 218 in milvus/grpc/BaseClient.ts

View check run for this annotation

Codecov / codecov/patch

milvus/grpc/BaseClient.ts#L218

Added line #L218 was not covered by tests
: certChainPath
? readFileSync(certChainPath)
: null;
this.creds = credentials.createSsl(
Expand Down
6 changes: 6 additions & 0 deletions milvus/types/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,16 @@ export interface ClientConfig {
tls?: {
// root certificate file path, it can be a CA PEM (Certificate Authority PEM) or Server PEM (Server Certificate PEM):
rootCertPath?: string;
// root certificate buffer
rootCert?: Buffer;
// private key path
privateKeyPath?: string;
// private key buffer
privateKey?: Buffer;
// certificate path
certChainPath?: string;
// certificate buffer
certChain?: Buffer;
// verify options
verifyOptions?: Record<string, any>;
// server name
Expand Down
15 changes: 15 additions & 0 deletions test/grpc/MilvusClient.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from 'path';
import { readFileSync } from 'fs';
import {
MilvusClient,
ERROR_REASONS,
Expand Down Expand Up @@ -215,5 +216,19 @@ describe(`Milvus client`, () => {

// const healthy = await mc.checkHealth();
// expect(healthy.isHealthy).toEqual(true);

// const mc2 = new MilvusClient({
// address: 'localhost:19530',
// tls: {
// rootCert: readFileSync(`test/cert/ca.pem`),
// privateKey: readFileSync(`test/cert/client.key`),
// certChain: readFileSync(`test/cert/client.pem`),
// serverName: 'localhost',
// },
// logLevel: 'debug',
// });

// const healthy2 = await mc2.checkHealth();
// expect(healthy2.isHealthy).toEqual(true);
// });
});
Loading