nest icon indicating copy to clipboard operation
nest copied to clipboard

feat(microservice): add TLS over TCP support

Open Flusinerd opened this issue 3 years ago • 12 comments

PR Checklist

Please check if your PR fulfills the following requirements:

  • [x] The commit message follows our guidelines: https://github.com/nestjs/nest/blob/master/CONTRIBUTING.md
  • [x] Tests for the changes have been added (for bug fixes / features)
  • [x] Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce? Adds an additional property useTls?: boolean to the options for client and server. If useTls is set, it intersects the Nodes tls server / client options with the nest server/client options.

If useTls is set to true, it uses node's tls module instead of net to allow TCP over TLS support

[ ] Bugfix
[ X ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior?

Issue Number: #6745

What is the new behavior?

If useTls === true then it will use tls instead of net to create the server / client and intersect the appropriate options with the nest options

Does this PR introduce a breaking change?

[ ] Yes
[ X ] No

Other information

Flusinerd avatar Jul 11 '21 12:07 Flusinerd

For docs, should I update the docs in nestjs/docs.nestjs.com?

I think we could either add another section in: https://docs.nestjs.com/microservices/basics#client

Or make an own page for TCP Client or TCP TLS Client

Flusinerd avatar Jul 11 '21 12:07 Flusinerd

Pull Request Test Coverage Report for Build a18b5f60-086f-4c47-a111-2d294565e81c

  • 25 of 33 (75.76%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.03%) to 94.103%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/microservices/client/client-tcp.ts 15 23 65.22%
<!-- Total: 25 33
Totals Coverage Status
Change from base Build 38eae0db-18bc-4193-8057-69d114a8416f: -0.03%
Covered Lines: 5713
Relevant Lines: 6071

💛 - Coveralls

coveralls avatar Jul 11 '21 12:07 coveralls

For docs, should I update the docs in nestjs/docs.nestjs.com?

Correct

I think we could either add another section in:

Let's add a new section in the TCP chapter

kamilmysliwiec avatar Jul 12 '21 06:07 kamilmysliwiec

Docs have been updated as well, the PR is linked above

Flusinerd avatar Jul 12 '21 10:07 Flusinerd

I can add a sample later that I used for testing, should I include a self-signed certificate in the sample? I'm waiting for #7486 to merged, since this includes support for multi-application samples.

Flusinerd avatar Jul 12 '21 10:07 Flusinerd

I left a few comments. Can we also add an integration test?

kamilmysliwiec avatar Jul 27 '21 10:07 kamilmysliwiec

Hi, ty for the the feedback I'll try work on this this weekend.

Flusinerd avatar Jul 30 '21 08:07 Flusinerd

Currently I dont have that much time to work on this @AnisJS09 Do you want to continue?

Flusinerd avatar Aug 07 '21 10:08 Flusinerd

Okay, I managed to get some time to continue working on this. I worked on the review from @kamilmysliwiec and think I got it sorted.

Looking into integration testing right now. It seems like there are no e2e tests for TCP implemented atm. So what do you want to be covered for TCP clients? Just a simple addition using sync / async / rxjs of and rxjs from + exception and pub / sub. Similar to how its done in the nats example?

Flusinerd avatar Jan 16 '22 23:01 Flusinerd

TCP tests https://github.com/nestjs/nest/blob/master/integration/microservices/e2e/sum-rpc.spec.ts

kamilmysliwiec avatar Jan 17 '22 07:01 kamilmysliwiec

Ahh alright. I completely missed that. Will work on this later then and finish this feature request.

Flusinerd avatar Jan 17 '22 10:01 Flusinerd

Okay, I added the e2e tests. I included a self signed certificate.

Flusinerd avatar Jan 17 '22 12:01 Flusinerd

@Flusinerd @kamilmysliwiec is this actively being worked on? I would be happy to pick it up

nomaxg avatar Oct 28 '22 19:10 nomaxg

Hi. I don't think so. Feel free to continue

Flusinerd avatar Oct 28 '22 19:10 Flusinerd

Moving onto this PR https://github.com/nestjs/nest/pull/10628

kamilmysliwiec avatar Feb 01 '23 12:02 kamilmysliwiec