Skip to content

JSCO-68: Analytics SDK - Support for mTLS#19

Merged
anirudhlakhotia merged 1 commit into
couchbase:mainfrom
anirudhlakhotia:MTLS
May 14, 2026
Merged

JSCO-68: Analytics SDK - Support for mTLS#19
anirudhlakhotia merged 1 commit into
couchbase:mainfrom
anirudhlakhotia:MTLS

Conversation

@anirudhlakhotia

Copy link
Copy Markdown
Contributor

JSCO-68: mTLS client-certificate auth

new CertificateCredential({ pfx: Buffer, passphrase?: string })
new CertificateCredential({ cert: string|Buffer, key: string|Buffer, passphrase?: string })
type ClusterCredential = Credential | JwtCredential | CertificateCredential
cluster.setCredential(newCertCred) // same-type only

Adds a third credential variant. The constructor takes either PKCS#12 (pfx) or PEM (cert + key); both, or neither, throws. mTLS requires an https:// endpoint; http:// is rejected.

Cert credentials don't send an Authorization header — auth happens during the TLS handshake. setCredential supports cert-cert rotation; cross-type rotation throws.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds mTLS client-certificate authentication support alongside existing password and JWT credentials.

Changes:

  • Adds CertificateCredential with PKCS#12 and PEM credential options.
  • Updates HTTP client behavior to use TLS client certs and omit Authorization for certificate auth.
  • Adds validation/tests for mTLS usage, credential rotation, and public exports.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
lib/credential.ts Adds certificate credential type and extends ClusterCredential.
lib/httpclient.ts Applies certificate material to HTTPS agents and blocks mTLS over HTTP.
lib/cluster.ts Accepts CertificateCredential in credential validation.
lib/analytics.ts Exports CertificateCredential from the public API barrel.
test/credential.test.ts Adds tests for certificate construction, HTTP rejection, rotation, and headers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/credential.ts Outdated
Comment thread lib/credential.ts
Comment thread lib/cluster.ts
}

/**
* Replace the credential used for subsequent HTTP requests, for example to

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets update this doc to mention the client cert rotation as well.

Comment thread lib/httpclient.ts Outdated
})
}
const tlsOptions = this._buildTlsOptions(securityOptions)
const tlsOptions = this._buildTlsOptions(this._securityOptions)

@thejcfactor thejcfactor May 14, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the http client owns _securityOptions. I wonder if we can just have _buildTlsOptions() do: const securityOptions = this._securityOptions instead of needing to passing it as an argument?

Comment thread test/credential.test.ts
assert.throws(() => new CertificateCredential({}), InvalidArgumentError)
})

it('rejects cert without key', function () {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice to also have a unit test that confirms we reject the key if we don't have a cert.

@thejcfactor thejcfactor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of small comments/thoughts. Looking good though!

JSCO-68: mTLS client-certificate auth

  new CertificateCredential({ pfx: Buffer, passphrase?: string })
  new CertificateCredential({ cert: string|Buffer, key: string|Buffer, passphrase?: string })
  type ClusterCredential = Credential | JwtCredential | CertificateCredential
  cluster.setCredential(newCertCred)         // same-type only

Adds a third credential variant. The constructor takes either PKCS#12
(pfx) or PEM (cert + key); both, or neither, throws. mTLS requires an
https:// endpoint; http:// is rejected.

Cert credentials don't send an Authorization header — auth happens
during the TLS handshake. setCredential supports cert-cert rotation;
cross-type rotation throws.
@anirudhlakhotia anirudhlakhotia merged commit 16f2458 into couchbase:main May 14, 2026
55 of 56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants