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

Implement TLS support #44

Merged
merged 3 commits into from
Mar 11, 2024
Merged

Implement TLS support #44

merged 3 commits into from
Mar 11, 2024

Conversation

supl
Copy link
Collaborator

@supl supl commented Mar 4, 2024

Description

This PR implements the TLS support so that user can pass CA root certificate and override authority to build TLS gRPC connection to targets.

The command-line tool has three more options

  • --tls
  • --ca-root-cert-path and --ca-root-cert-pem
  • --override-authority

Related issues and/or PRs

N/A

Changes made

  • added a new class TlsRequestCoordinator
  • made AdminClient able to setup SSL context when using netty

Checklist

  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation to reflect the changes.
  • Any remaining open issues linked to this PR are documented and up-to-date (Jira, GitHub, etc.).
  • Tests (unit, integration, etc.) have been added for the changes.
  • My changes generate no new warnings.
  • Any dependent changes in other PRs have been merged and published.

Additional notes

  • Support TLS connection between scalar-admin clients and servers

@supl supl added the enhancement New feature or request label Mar 4, 2024
@supl supl self-assigned this Mar 4, 2024
@supl supl marked this pull request as draft March 4, 2024 09:18
Comment on lines -78 to +111
coordinator = new RequestCoordinator(srvServiceUrl);
} else if (addresses != null) {
coordinator = createCoordinator(srvServiceUrl);
} else { // addresses != null
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sonalint recommends removing this unnecessary conditional statement

String caRootCert = null;

if (caRootCertPem != null) {
caRootCert = caRootCertPem.replace("\\n", System.lineSeparator());
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

in case the user pass PEM formatted file in one line

Copy link
Collaborator Author

@supl supl Mar 5, 2024

Choose a reason for hiding this comment

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

@kota2and3kan
FYI. The error we met yesterday was because picocli takes \n as a plaintext but not a newline character. So we need to convert it ourselves.

Copy link
Contributor

Choose a reason for hiding this comment

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

@supl
Ah, I see. I understood.
Thank you for your investigation!

Copy link
Contributor

@feeblefakie feeblefakie Mar 7, 2024

Choose a reason for hiding this comment

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

@supl
Can you make sure if it is really picocli thing?
I'm not sure, but it might be shell thing.

I haven't run this command, but did a quick check with zsh and bash as follows. (Do you use bash?)

# zsh
$ echo "aaa\nbbb"
aaa
bbb

# bash
bash-3.2$ echo "aaa\nbbb"
aaa\nbbb

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@feeblefakie

Thanks for your concern.

Yes, I used bash to run the command.

I did a survey for this.

It seems neither bash nor zsh expand newline's escape sequence (\n) to newline.

The different results you got on zsh and bash should be because of echo.
It seems echo (as a built-in command) in zsh uses -e option by default while bash's echo doesn't.

If we use this command

printf "aaa\nbbb"

we should get the same result

aaa
bbb

It's not even because of using single quote or double quote.
On zsh,

 % echo 'aaa\nbbb'
aaa
bbb

Echo in zsh by default expands newline escape sequence.
It equals we run

> echo -e "aaa\nbbb"
aaa
bbb

on bash.

To confirm this again, I run picocli on zsh

% ./scalar-admin --ca-root-cert-pem "aaa\nccc" -c pause
aaa\nccc

(I revised this PR's call to just print out the argument)

So, I think this is not shell's issue.
Picocli just doesn't expand newline escape sequence either.

Copy link

@choplin choplin Mar 7, 2024

Choose a reason for hiding this comment

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

@feeblefakie Just to be precise, the example you provided is caused not by the difference of the shells but by the difference in the echo commands. Both in bash and zsh, echo is a built-in command (you can see type echo). And, only the echo of zsh interpreters backslashed escape characters, like "\n". We need the -e flag for bash's echo. See man of bash and zsh.

So, I suppose when passing string parameters to this command, the difference between bash and zsh does not affect.

Copy link

Choose a reason for hiding this comment

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

You can see that the strings passed to the programs are the same:

# zsh
❯ ruby -e "puts ARGV" "foo\nbar"
foo\nbar

# bash
❯ bash
bash-5.2$ ruby -e "puts ARGV" "foo\nbar"
foo\nbar

Copy link

Choose a reason for hiding this comment

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

@supl Sorry that I found that you already replied after reloading

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@choplin
No problem at all.
Thank you very much for clarifying this question 🙇

Copy link
Contributor

Choose a reason for hiding this comment

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

@supl @choplin Thank you for the clarification!

@supl supl marked this pull request as ready for review March 5, 2024 04:36
@@ -22,6 +27,30 @@ public AdminClient(String host, int port) {
this.blockingStub = AdminGrpc.newBlockingStub(channel);
}

public AdminClient(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

@brfrn169 brfrn169 left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!

Co-authored-by: Toshihiro Suzuki <brfrn169@gmail.com>
Copy link
Contributor

@kota2and3kan kota2and3kan left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!


FYI: I was able to run the scalar-admin command with TLS in my local environment as follows.

$ build/install/scalar-admin/bin/scalar-admin --tls -c pause --ca-root-cert-path ~/cert/ca.pem  --override-authority envoy.scalar.example.com -a 172.20.255.200:60053
Pause completed at 2024-03-07T06:36:42.004Z UTC (1709793402004)

Copy link

@choplin choplin left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@feeblefakie feeblefakie left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!

String caRootCert = null;

if (caRootCertPem != null) {
caRootCert = caRootCertPem.replace("\\n", System.lineSeparator());
Copy link
Contributor

Choose a reason for hiding this comment

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

@supl @choplin Thank you for the clarification!

@feeblefakie feeblefakie merged commit 9733d34 into main Mar 11, 2024
@feeblefakie feeblefakie deleted the support-tls branch March 11, 2024 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants