-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
cli: add --cert-principal-map to client commands #47449
cli: add --cert-principal-map to client commands #47449
Conversation
This needs unit tests, but it seems to work for me in manual testing. Before pushing on that, I want to make sure this is directionally correct. |
❌ The GitHub CI (Cockroach) build has failed on 7b9b37bb. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
I am not too fond of this approach, it really over-emphasizes the Why not deprecate the |
I agree. In my manual testing of this PR I confused myself several times.
My major complaint with |
I'm going to partially retract my complaint. Both |
The URL quoting is not mandatory over HTTP or anything network. It is available for convenience so that the result of fetching a URL can be stored in a file named after the entire last portion of URL (after quoting). |
Ah. Perhaps we should adjust the help text shown at start:
Should the help text for other client commands use the
|
Yes I agree these improvements would be worthwhile. (However meanwhile I am horrified that macOS puts single quotes in hostnames, and that Go's parser allows them. I'm 99.999% confident this is a giant no-no by all IETF standards) |
I'm +1 on this approach myself, just ran through the flow and this approach also fixes the issue with having additional directories to split node certs from client certs.
|
7b9b37b
to
04c0b12
Compare
I just revived this PR as a stop-gap for 20.1.
Agreed, yet I'm worried that properly fixing the "client" commands to not use |
Ok I can stand behind this for consistency's sake. |
Great. Let me add some additional testing to this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I re-reviewed this. LGTM modulo a test that the flag is processed. I would recommend not adding testing in more places than where --certs
is tested already.
Reviewed 3 of 3 files at r1.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @aaron-crl)
Sounds like the best option for the near term. Let's start tracking these hiccups so we can make sure we get a cleaner separation later. |
❌ The GitHub CI (Cockroach) build has failed on 04c0b124. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
Ack. #47210 is where I'm currently tracking these hiccups. Let me retitle that issue and expand the description. |
04c0b12
to
77baebe
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @aaron-crl)
pkg/cli/interactive_tests/test_cert_advisory_validation.tcl, line 87 at r2 (raw file):
expect $prompt send "$argv node ls --certs-dir=$certs_dir --cert-principal-map=foo.bar:node" eexpect "1 row"
I think I cargo-culted something wrong here as the test fails at this line. Perhaps I should be adding this test to test_secure.tcl
instead and using the existing start_secure_server
. I'd need to create an additional cert which doesn't validate without --cert-principal-map
, which is why I initially went with the addition here.
@knz I hope you can spot what I've done wrong and advise on the appropriate fix. Or give me guidance on how to debug this.
❌ The GitHub CI (Cockroach) build has failed on 77baebe2. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
77baebe
to
fd0979e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 2 files at r2.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @aaron-crl and @petermattis)
pkg/cli/interactive_tests/test_cert_advisory_validation.tcl, line 87 at r2 (raw file):
Previously, petermattis (Peter Mattis) wrote…
I think I cargo-culted something wrong here as the test fails at this line. Perhaps I should be adding this test to
test_secure.tcl
instead and using the existingstart_secure_server
. I'd need to create an additional cert which doesn't validate without--cert-principal-map
, which is why I initially went with the addition here.@knz I hope you can spot what I've done wrong and advise on the appropriate fix. Or give me guidance on how to debug this.
The magic incantation that I use is
killall -9 cockroach cockroachshort && rm -rf logs && expect -d -f pkg/cli/interactive_tests/xxxx.tcl ./cockroach
(expect -d
helps. However, it's possible that the default expect
in macOS gives you trouble. YMMV.)
pkg/cli/interactive_tests/test_cert_advisory_validation.tcl, line 83 at r3 (raw file):
start_test "Check that the client commands can use cert principal map." system "$argv start-single-node --certs-dir=$certs_dir --cert-principal-map=foo.bar:node --advertise-addr=localhost --background >>expect-cmd.log 2>&1" send "$argv sql --certs-dir=$certs_dir --cert-principal-map=foo.bar:node -e \"select 'hello'\""
You forgot \r
at the end of the line.
pkg/cli/interactive_tests/test_cert_advisory_validation.tcl, line 86 at r3 (raw file):
eexpect "hello" expect $prompt send "$argv node ls --certs-dir=$certs_dir --cert-principal-map=foo.bar:node"
ditto.
pkg/cli/interactive_tests/test_cert_advisory_validation.tcl, line 89 at r3 (raw file):
eexpect "1 row" expect $prompt send "$argv quit --certs-dir=$certs_dir --cert-principal-map=foo.bar:node"
\r
here too
fd0979e
to
fb97651
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @aaron-crl and @knz)
pkg/cli/interactive_tests/test_cert_advisory_validation.tcl, line 87 at r2 (raw file):
Previously, knz (kena) wrote…
The magic incantation that I use is
killall -9 cockroach cockroachshort && rm -rf logs && expect -d -f pkg/cli/interactive_tests/xxxx.tcl ./cockroach
(
expect -d
helps. However, it's possible that the defaultexpect
in macOS gives you trouble. YMMV.)
Thanks.
pkg/cli/interactive_tests/test_cert_advisory_validation.tcl, line 83 at r3 (raw file):
Previously, knz (kena) wrote…
You forgot
\r
at the end of the line.
Ah-ha! I've made exactly that mistake before. Thank you!
Done.
pkg/cli/interactive_tests/test_cert_advisory_validation.tcl, line 86 at r3 (raw file):
Previously, knz (kena) wrote…
ditto.
Done.
pkg/cli/interactive_tests/test_cert_advisory_validation.tcl, line 89 at r3 (raw file):
Previously, knz (kena) wrote…
\r
here too
Done.
lemme hand hold this for you |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should have marked my earlier comment approved.
@petermattis the proximate cause of the failure is that you can't use a |
Ok there's something uncanny going on with |
Yep, I just stumbled on this myself. I've added creation of a |
Just hit this myself. It will need a |
fb97651
to
d16ffd1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think I've got the test working, @knz. Thanks for your help!
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @knz)
Trying your code made me discover that the cert mapping only works for the node cert, not for SQL or RPC client certs. It's not possible to remap This comes as a surprise (to me). I have said something different to @Amruta-Ranade in the past. I had expected the cert mapping to be universal for all uses of certs, not just for node-node connections. |
Huh, this doesn't sound right to me. I'm pretty sure you can map the principal in a client cert, but you have to have the client cert named |
oh I had mixed up the filename maybe. I'll check again. |
That was the case for the OpenSSL generated certs. Does the crdb client do something different? |
(I don't see a test for it though.) |
I verified it works manually just now. Yeah, there isn't a test for it. Let me add one to this PR. |
ok I checked, it works (with a warning):
(I started the server with I'm a bit confused by the text of the warning (I'd have expected the opposite really, something along the lines of We'll need to document the file names though. it's a pitfall. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r4.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @petermattis)
pkg/cli/interactive_tests/test_cert_advisory_validation.tcl, line 82 at r3 (raw file):
start_test "Check that the client commands can use cert principal map." system "$argv start-single-node --certs-dir=$certs_dir --cert-principal-map=foo.bar:node --advertise-addr=localhost --background >>expect-cmd.log 2>&1"
Another thing: can you make the certs_dir a subdir of logs/
as well as add a -s=path=logs/db
to the command line here and other start-single-node
This is because the test hardness only collects artifacts from the logs
directory (specifically, that's a mounted volume and the artifact collection happens outside of docker)
Yes, it is a pitfall. Requiring the filenames to have a particular structure seems burdensome in hindsight. I don't think it is adding anything as we load all of the certs anyways a check what the principal inside says. I've changed the test to create a |
Add support for the `--cert-principal-map` flag to the certs and client commands. Anywhere we were accepting the `--certs-dir` flag, we now also accept the `--cert-principal-map` flag. Fixes cockroachdb#47300 Fixes cockroachdb#47754 Fixes cockroachdb#48116 Release note (cli change): Support the `--cert-principal-map` flag in the `cert *` and "client" commands such as `sql`, `init`, and `quit`.
d16ffd1
to
c360bd4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @knz and @petermattis)
pkg/cli/interactive_tests/test_cert_advisory_validation.tcl, line 82 at r3 (raw file):
Previously, knz (kena) wrote…
Another thing: can you make the certs_dir a subdir of
logs/
as well as add a-s=path=logs/db
to the command line here and otherstart-single-node
This is because the test hardness only collects artifacts from the
logs
directory (specifically, that's a mounted volume and the artifact collection happens outside of docker)
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r5.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @petermattis)
TFTR! bors r+ |
Build succeeded |
Add support for the
--cert-principal-map
flag to the certs and clientcommands. Anywhere we were accepting the
--certs-dir
flag, we now alsoaccept the
--cert-principal-map
flag.Fixes #47300
Release note (cli change): Support the
--cert-principal-map
flag inthe
cert *
and "client" commands such assql
.