Conversation
The index command read OC_GRPC_CLIENT_TLS_MODE with a meaning of its own: "insecure" dialed without TLS, and every other value, including the default and "off", dialed with verified TLS and ignored OC_GRPC_CLIENT_TLS_CACERT. Against the default setup, where the gRPC services run without TLS, it failed unless --insecure was passed, and against services with TLS enabled it only connected when their certificate was trusted by the system roots, never with the generated certificate or a private CA. Map the mode with pool.StringToTLSMode and dial with pool.NewConn, the mapping and dialer the other services' reva clients use: "off" dials without TLS, "insecure" uses TLS without verifying the certificate and "on" verifies it against the configured CA. --insecure still forces a connection without TLS, and then the mode is not read at all.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 9 |
🟢 Coverage 94.12% diff coverage · +0.09% coverage variation
Metric Results Coverage variation ✅ +0.09% coverage variation (-1.00%) Diff coverage ✅ 94.12% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (c8dd8ce) 89061 21597 24.25% Head commit (9cfb21a) 89066 (+5) 21678 (+81) 24.34% (+0.09%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#3620) 17 16 94.12% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
dschmidt
left a comment
There was a problem hiding this comment.
Thanks, this is basically what I proposed in #3505 (comment):
the command should evaluate OC_GRPC_CLIENT_TLS_MODE with the same semantics as every other client.
Going through pool.StringToTLSMode/pool.NewConn instead of mirroring the switch by hand is the better variant, and it also covers OC_GRPC_CLIENT_TLS_CACERT, which I had left as a follow-up.
Rejecting unknown modes is also more consistent than silently falling back to verified TLS like my diff did.
Three requests from my side (although others might disagree):
- Please do drop --insecure from the places #3505 added it (README, services/search/MIGRATION.md, and the two re-index hints in pkg/mapping/reconcile.go). With this fix the flag is unnecessary in the default setup and actively wrong with TLS-enabled gRPC, so keeping it documented as the go-to just re-establishes the workaround for the bug you fixed.
- Optional, but since you are in there: default --endpoint to cfg.GRPC.Addr when the flag is not set (it is a hardcoded 127.0.0.1:9220 today), so a reconfigured OC_SEARCH_GRPC_ADDR works without passing --endpoint. That was the second hunk in my proposal.
- We write new test files with Ginkgo/Gomega instead of plain testing.T tables, could you convert index_test.go? The coverage itself looks good.
cc @butonic, this is the config-semantics fix from the #3505 discussion.
|
Looked at it again and was thinking: isn't the test covering a lot of reva client territory? The three TLS-server cases (mode insecure against TLS, mode on with the CA cert, mode off against TLS) verify what pool.NewConn does with those options, and they are the only reason for the whole selfSignedCert apparatus (~40 lines of x509/PEM boilerplate plus the TLS listener). That behavior belongs to reva's pool and would be better pinned by a test over there. I'd drop the TLS server, selfSignedCert and those three cases. What remains covers the actual change completely, without any crypto imports:
|
--endpoint defaulted to a hardcoded 127.0.0.1:9220, so a search service moved with SEARCH_GRPC_ADDR could only be reached by passing the flag. Use the configured address when the flag is not set.
With the client TLS mode honored, the default setup no longer needs --insecure, and with TLS enabled for gRPC the flag makes the command fail, since it turns TLS off. Drop it from the README examples and from the two re-index hints the service logs. MIGRATION.md keeps it: its section covers upgrading to 8.0.x, which still needs the flag.
Run the command against a search service without TLS only: what the command decides is whether to turn TLS off, how the mode maps and which endpoint it dials. What pool.NewConn does with each mode belongs to reva. Also cover the endpoint default.
|
Thanks, and sorry I missed your proposal in #3505: I looked at its diff but not its discussion, so the description should have credited you. I've pushed three commits for your points:
|
Oh no worries. I think it's great we came to the same conclusion independently ... and that you even found a more standard approach :)
That's a tough one indeed. I'm not sure, maybe we should make it
👍🏻
So does the reindex command still work with |
The section was titled v7.x.x to v8.0.0 and told everyone to pass --insecure, which only 8.0.0 and 8.0.1 need. Title it v7.x.x to v8.x.x, drop the flag from the commands and say in an IMPORTANT block which releases still need it.
Yes, in the default setup: Your |
|
Thanks, this looks good to me now. Two small things left, both in
Nits:
|
The insecure-mode spec only asserted an error, so against main it passed on a refused connection to the hardcoded endpoint. Match the TLS handshake error instead. Pass insecure credentials to the test server explicitly, which is what it already did, so the static analysis no longer reports a server without credentials.
After the fallback the variable holds the configured address rather than the flag, and the reva import belongs with the third-party ones, as in server.go. The flag help also says that with mode on the server certificate must be valid for that address.
With OC_GRPC_CLIENT_TLS_MODE=on the certificate is checked against the dialed address, which is now SEARCH_GRPC_ADDR by default. A bind address such as 0.0.0.0:9220 then fails verification unless --endpoint names a host the certificate is valid for.
|
Thanks! Done in three more commits:
I've also fixed the description: it's one endpoint spec, and the specs that omit |
|
I'm sorry, I was a little quick with the endpointFlag - flag suffix is used with other non bools as well... can I ask you to revert that? 🤦♂️ I'm not sure about the versions referenced in the Migrations docs. 8.1.0 is about to be released and we probably dont get this in until then. |
The Flag suffix is the convention for the command's flag variables, not only for booleans.
8.1.0 ships before this fix, so it still needs the flag too.
|
Ha, no worries: a rename that goes there and back is the cheapest review round there is 😄 |
Description
opencloud search indexreadsOC_GRPC_CLIENT_TLS_MODEwith a meaning of its own:insecuredials without TLS, and every other value, including the default andoff, dials with verified TLS and ignoresOC_GRPC_CLIENT_TLS_CACERT. The setting itself (pkg/shared) and the clients the other services build through reva's pool mean something else:offis no TLS,insecureis TLS without verifying the certificate, andonverifies it against the configured CA.This maps the mode with
pool.StringToTLSModeand dials withpool.NewConn, the mapping and dialer the other services' reva clients use.NewConndials the endpoint directly, so there is still no registry lookup.--insecurestill forces a connection without TLS, and then the mode is not read at all, so scripts and the acceptance tests that pass it keep working.--endpointnow defaults to the configured gRPC address (SEARCH_GRPC_ADDR) instead of a hardcoded127.0.0.1:9220.Related Issue
No issue. It started in opencloud-eu/web-extensions#575 (comment), where I offered to add
--insecureto the search README and @JammingBen welcomed it. The README already got it in #3505, and looking at why the flag is needed at all led here. @dschmidt had proposed the same fix in #3505 (comment), which I missed when opening this.Motivation and Context
opencloud search index --all-spacesfails withtls: first record does not look like a TLS handshakeunless--insecureis passed. SettingOC_GRPC_CLIENT_TLS_MODE=offexplicitly doesn't help. The upgrade guide already describes the intended behavior ("OC_GRPC_CLIENT_TLS_MODEdefaults tooff", "Drop it only if you run gRPC with TLS"), which only holds with this change.OC_GRPC_TLS_ENABLED=trueandOC_GRPC_CLIENT_TLS_MODE=insecure, the documented combination), the command can't connect with any mode or flag, and with a private CA it ignoresOC_GRPC_CLIENT_TLS_CACERT.Two behavior changes, both where the setting contradicts its documented meaning: with
OC_GRPC_CLIENT_TLS_MODE=insecureagainst services without TLS, the command now fails like every other client does with that combination (before, it happened to work), and an unknown mode is now rejected withunknown TLS modeunless--insecureis passed, instead of dialing TLS.#3505 added
--insecureto the README, toservices/search/MIGRATION.mdand to the two re-index hints the service logs (pkg/mapping/reconcile.go). With this change the flag is no longer needed for the default setup, and with TLS enabled for gRPC it makes the command fail, since it turns TLS off, so it is dropped from the README and the log hints. InMIGRATION.mdthe section now covers every 8.x release, without the flag, and anIMPORTANTblock says that 8.0.x and 8.1.x still need it.How Has This Been Tested?
opencloudeu/opencloud-rolling:8.0.1in a single container afteropencloud init, once with the default gRPC setup and once withOC_GRPC_TLS_ENABLED=trueandOC_GRPC_CLIENT_TLS_MODE=insecure.search index --all-spacesran inside the container with the stock binary and with one built from this branch (Alpine, CGO).offand only works with--insecureor modeinsecure. The patched binary works with the mode unset oroff, and with--insecure; modeinsecureoronnow fails there, as the other clients do.insecuremode.services/search/pkg/commandruns the command against an in-process gRPC server without TLS: unset,off,--insecureand an unknown mode with--insecureconnect,insecurefails, an unknown mode is rejected withunknown TLS mode, and one covers--endpointtaking precedence, while the specs that omit it cover the default. All seven fail against main'sindex.go. Whatpool.NewConndoes with each mode belongs to reva, so the TLS-server cases from the first version were dropped at review.go vetandgolangci-lint run --new-from-revwith the repo config report nothing for the changed files (the config excludes test files), and thepkg/mappingtests pass.Types of changes
Checklist: