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

feat(runtime/tls): Add support for client certificates to connectTls #9426

Closed
wants to merge 12 commits into from

Conversation

erik
Copy link
Contributor

@erik erik commented Feb 7, 2021

Allows specifying a client certificate for mutual TLS in calls to Deno.connectTls().

await Deno.connectTls({
  hostname: "example.com",
  port: 443,
  certChain: "-----BEGIN CERTIFICATE-----\n...",
  privateKey: "-----BEGIN PRIVATE KEY-----\n...",
});

Some implementation notes:

  • The existing ConnectTlsOptions parameter certFile is confusing when combined with client certificate param certChain. Should we pull them into a separate object? Prefix the names with client? Open to suggestions.
  • The certificate chain and private key are passed in as a string rather than a file path for flexibility (as discussed in Allow Setting SSL Certs via string instead of just File Path #5810). This is inconsistent with the behavior of the existing certFile param.
  • I couldn't think of a great way to unit test that the certificates are actually set properly on the underlying connection, since Deno.Conn has no way of exposing the peer's client certificate from the other end of the connection.

Partially implements #6170

@CLAassistant
Copy link

CLAassistant commented Feb 7, 2021

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. The changes LGTM in themselves but another maintainer should make the call on the API.

I personally think the file-based API is kind of clunky but it's precedent. It also has going for it that key data doesn't go through JS land.

cli/tests/unit/tls_test.ts Outdated Show resolved Hide resolved
@lucacasonato
Copy link
Member

We have already started moving away from the file based APIs for new unstable APIs like Deno.createHttpClient(), so I think there is at least some precedent here.

@bartlomieju
Copy link
Member

We have already started moving away from the file based APIs for new unstable APIs like Deno.createHttpClient(), so I think there is at least some precedent here.

Agree with Luca. Additionally Deno.connectTls is a stable API, so we need to be extra careful when changing the interface (that means reading cert from file should still be supported). We should follow the same convention as in Deno.createHttpClient() for the field names.

@lucacasonato
Copy link
Member

that means reading cert from file should still be supported

Why? We don't support it for Deno.createHttpClient(). I think we should deprecate reading certificates from files for 2.0.

@bartlomieju
Copy link
Member

that means reading cert from file should still be supported

Why? We don't support it for Deno.createHttpClient(). I think we should deprecate reading certificates from files for 2.0.

Yes, for 2.0, but for now it should still be supported.

@bartlomieju
Copy link
Member

bartlomieju commented Feb 7, 2021

We have already started moving away from the file based APIs for new unstable APIs like Deno.createHttpClient(), so I think there is at least some precedent here.

Agree with Luca. Additionally Deno.connectTls is a stable API, so we need to be extra careful when changing the interface (that means reading cert from file should still be supported). We should follow the same convention as in Deno.createHttpClient() for the field names.

Disregard this comment, I misunderstood what this PR does.

Implementation looks good to me, but let's put it in the unstable namespace for now.

@erik
Copy link
Contributor Author

erik commented Feb 8, 2021

Thanks for the quick review all!

@bartlomieju updated, let me know if the refactor looks right

cli/dts/lib.deno.ns.d.ts Outdated Show resolved Hide resolved
cli/tests/unit/tls_test.ts Outdated Show resolved Hide resolved
@erik erik force-pushed the erik/add-client-certificate-support branch from 1e04560 to b36083c Compare February 9, 2021 02:20
@erik erik force-pushed the erik/add-client-certificate-support branch from 23ca51b to ee3c790 Compare February 9, 2021 06:59
Base automatically changed from master to main February 19, 2021 14:59
@erik
Copy link
Contributor Author

erik commented Mar 1, 2021

I decided not to use Deno for the project this was relevant to, so I'll be closing out the PR

If someone else decides to pick this up later, the implementation works fine as is, but integration tests aren't working on GitHub CI for reasons I couldn't figure out. They pass reliably locally. Probably something simple

@erik erik closed this Mar 1, 2021
@lucacasonato
Copy link
Member

@erik No worries.This PR is 99% there, just need to get the tests working in CI. I will pick this up for the 1.9 release. Thanks for the effort!

@justinmchase
Copy link
Contributor

I will pick this up for the 1.9 release.

I'm currently using 1.11.5 and it seems as if this isn't yet available, is there an update on this? I'm trying to use the kubernetes api which in some cases require a client certificate for authentication.

@justinmchase
Copy link
Contributor

Related To #10516

@cryptographix
Copy link
Contributor

@lucacasonato any update on this change? Just spent a couple of hours writing a node mTLS proxy server to sit behind deno, but would prefer to do everything with deno. Can I help with getting this PR into the next release?

@ry
Copy link
Member

ry commented Aug 6, 2021

@seanwykes I've rebased this patch and opened a new PR in #11598 - we'll try to get it in for 1.13.0 (which comes out next week)

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.

8 participants