Skip to content

fix(grpc)!: require OC_INSECURE=true for the insecure client TLS mode - #4117

Open
asaah262 wants to merge 5 commits into
opencloud-eu:mainfrom
asaah262:fix/866-grpc-insecure-tls-guard
Open

asaah262 wants to merge 5 commits into
opencloud-eu:mainfrom
asaah262:fix/866-grpc-insecure-tls-guard

Conversation

@asaah262

@asaah262 asaah262 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Description

OC_GRPC_CLIENT_TLS_MODE=insecure makes the go-micro gRPC clients use TLS without verifying the server certificate. Until now, any installation could set it.

The insecure mode now has to be allowed explicitly, with the new setting grpc_client_tls.insecure. It works like the other insecure switches of the configuration:

  • in the YAML config, globally (grpc_client_tls: insecure: true) or per service;
  • with OC_INSECURE=true, which is parsed like everywhere else in the configuration: true, TRUE and 1 count as true;
  • opencloud init --insecure yes writes it into the generated config. It only writes the permission, not the mode.

Without it, creating the gRPC client in the insecure mode fails with an error that names both OC_INSECURE and grpc_client_tls.insecure, and the services that use such a client don't start.

The descriptions of OC_GRPC_CLIENT_TLS_MODE and OC_GRPC_TLS_ENABLED now mention this requirement, with both the env var and the config option. The second one also gets a typo fix ("certifcate").

Nothing else changes: the modes off (the default) and on work as before, with or without the new setting.

Related Issue

  • None

Motivation and Context

Skipping the certificate check means that the gRPC traffic between the services is encrypted, but a man-in-the-middle can still read and change it. That is fine for development setups with the auto-generated self-signed certificates, but it should not be possible to switch it on in production by accident. OC_INSECURE and opencloud init --insecure already mark a setup as insecure for development, so the gRPC clients now require the same.

Breaking change: installations that run with OC_GRPC_CLIENT_TLS_MODE=insecure (for example together with OC_GRPC_TLS_ENABLED=true and the auto-generated certificate) no longer start unless they also set OC_INSECURE=true or grpc_client_tls.insecure: true. Production setups should use OC_GRPC_CLIENT_TLS_MODE=on with a certificate that the clients can verify (OC_GRPC_CLIENT_TLS_CACERT). The default mode off is not affected.

How Has This Been Tested?

  • Test environment: macOS, Go tests.
  • New Go tests:
    • pkg/service/grpc/client_test.go:
      • TestNewClientInsecureTLSMode, mode insecure: allowed through the client option, a client is created; not allowed or not given, an error naming OC_INSECURE and grpc_client_tls.insecure, and no client. Also not allowed when only OC_INSECURE=true is set in the environment, since the client only looks at the configuration.
      • TestNewClientOtherTLSModesIgnoreInsecure: the modes "", off and on still create a client without the setting.
      • TestGetClientOptionsInsecure: the setting is passed on from shared.GRPCClientTLS.
    • pkg/shared/shared_types_test.go, TestGRPCClientTLSInsecureFromEnv: OC_INSECURE true, 1 and false set the field.
    • pkg/config/helpers_test.go, TestBindSourcesToStructs_GRPCClientTLSInsecure: the setting is read from the YAML config.
    • opencloud/pkg/init/init_test.go, TestCreateConfigGRPCClientTLS: init with --insecure writes grpc_client_tls.insecure: true and no mode, without it no grpc_client_tls section.
  • go test and go test -race pass for the changed packages and for ./opencloud/..., pkg/config/..., the auth-guest service and the revaconfigs of storage-users and storage-system. go build ./pkg/... ./opencloud/... ./services/... passes. go vet reports nothing for the changed packages. git diff --check is clean. The env var annotations are valid.
  • Not run locally: golangci-lint, the unit tests of all services, and the acceptance tests. The CI doesn't set OC_GRPC_CLIENT_TLS_MODE, so the acceptance tests don't reach the changed code.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation added

AI assistance: Claude Code (claude-opus-5-5) wrote the first draft of the code, the tests and this description; I reviewed and adjusted them.

@codacy-production

codacy-production Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 38 complexity

Metric Results
Complexity 38

View in Codacy

🟢 Coverage 100.00% diff coverage · +0.27% coverage variation

Metric Results
Coverage variation ✅ +0.27% coverage variation (-1.00%)
Diff coverage ✅ 100.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (a2f9b5b) 95037 29290 30.82%
Head commit (cde7ec7) 95048 (+11) 29554 (+264) 31.09% (+0.27%)

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 (#4117) 11 11 100.00%

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.

@pbleser-oc pbleser-oc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, looks good to me. The check matches what it should do, and the tests fail without the fix.

One thing for a follow-up, not for this PR: OC_GRPC_CLIENT_TLS_MODE=insecure is also passed to the reva gRPC clients (pool.WithTLSMode in several services, and tls_mode/permissionssvc_tls_mode in the reva configs), and those still skip the certificate check without OC_INSECURE. So services that only use reva clients keep running in that mode. Maybe worth an issue to guard those too, or to check it once at startup for all services?

Comment thread pkg/service/grpc/client.go Outdated
case "insecure":
// Skipping the server certificate check is only meant for development
// setups, so it has to be allowed explicitly.
if insecure, _ := strconv.ParseBool(os.Getenv("OC_INSECURE")); !insecure {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A suggestion: everywhere else, OC_INSECURE is an env alias on a config setting (tls_insecure, insecure, ...), so those can also be set in the YAML config, and opencloud init --insecure writes them there without setting any env var. The mode itself can be set in YAML too (grpc_client_tls: mode: insecure), but this check only looks at the env var.

What do you think about a field on shared.GRPCClientTLS, e.g. Insecure bool with yaml:"insecure" env:"OC_INSECURE", passed on through GetClientOptions as a client option and checked here? Then it works the same way as the other insecure switches, from YAML or the env.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, thanks. I'll move it into the config: an Insecure field on shared.GRPCClientTLS (yaml:"insecure", env:"OC_INSECURE"), passed through GetClientOptions and checked in NewClient instead of reading the env var directly. That way the YAML config and opencloud init --insecure work the same as for the other insecure settings.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done: af4aa22 adds insecure to shared.GRPCClientTLS (yaml:"insecure" env:"OC_INSECURE"), passes it on through GetClientOptions, and NewClient only checks that option now. 3a7e697 makes opencloud init --insecure write grpc_client_tls: insecure: true (only the permission, not the mode).

@pbleser-oc

Copy link
Copy Markdown
Member

On the Type:Breaking-Change label: I'm not sure this should count as breaking, since it would make the next release a major one. @micbar, could you weigh in? You know better how we've handled cases like this so far.

For labelling it breaking:

  • A configuration that works today stops working: with OC_GRPC_CLIENT_TLS_MODE=insecure and without OC_INSECURE=true, the services that create a go-micro gRPC client no longer start after the update, without any earlier warning.
  • The descriptions of the env vars never say that insecure is for development only. OC_GRPC_TLS_ENABLED=true with the generated certificate plus insecure is the simplest way to get TLS between the services, so some installations may use it in production, e.g. on an internal network.

Against labelling it breaking:

  • The mode is documented for use with the auto-generated self-signed certificates, i.e. for development and test setups.
  • It encrypts the traffic but lets anyone in between read and change it, so no production setup should use it. If one does, failing to start is arguably what we want, as part of the hardening.
  • Nothing in our own CI, devtools/ or deployments/ uses it.
  • Installations that do use it only need OC_INSECURE=true (or a verifiable certificate with OC_GRPC_CLIENT_TLS_MODE=on), which a note in the release notes can point out.

@asaah262

Copy link
Copy Markdown
Contributor Author

@pbleser-oc Thanks! There's an issue for the reva clients now: opencloud-eu/reva#1072. I'll add the paths you mention (permissionssvc_tls_mode in the storage-users config, the reva grpc_client_options) and the idea of a single check at startup to it.

@pbleser-oc pbleser-oc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks Sara, the config option works nicely, and opencloud init --insecure writing it is a good addition. Only two small wording points inline.

The three new commits only have a subject line. af4aa22 in particular could say in its body why the check moved from the environment into the configuration (so that it also works through the YAML config and opencloud init --insecure).

Comment thread pkg/service/grpc/client.go Outdated
// Skipping the server certificate check is only meant for development
// setups, so it has to be allowed explicitly.
if !options.tlsInsecure {
return nil, errors.New("grpc client TLS mode 'insecure' disables server certificate verification and requires OC_INSECURE=true; use OC_GRPC_CLIENT_TLS_MODE=on with a trusted certificate otherwise")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Now that the check reads the config option, the message only names OC_INSECURE=true: someone who configures this through the YAML file won't find grpc_client_tls.insecure from it. Maybe something like "... requires OC_INSECURE=true (or grpc_client_tls.insecure: true in the config file)"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, done in cde7ec7. The message now reads "… requires OC_INSECURE=true or grpc_client_tls.insecure: true in the config file; use OC_GRPC_CLIENT_TLS_MODE=on with a trusted certificate otherwise", and the tests check that both are named.

Comment thread pkg/shared/shared_types.go Outdated
type GRPCClientTLS struct {
Mode string `yaml:"mode" env:"OC_GRPC_CLIENT_TLS_MODE" desc:"TLS mode for grpc connection to the go-micro based grpc services. Possible values are 'off', 'insecure' and 'on'. 'off': disables transport security for the clients. 'insecure' allows using transport security, but disables certificate verification (to be used with the autogenerated self-signed certificates). 'on' enables transport security, including server certificate verification." introductionVersion:"1.0.0"`
CACert string `yaml:"cacert" env:"OC_GRPC_CLIENT_TLS_CACERT" desc:"Path/File name for the root CA certificate (in PEM format) used to validate TLS server certificates of the go-micro based grpc services." introductionVersion:"1.0.0"`
Mode string `yaml:"mode" env:"OC_GRPC_CLIENT_TLS_MODE" desc:"TLS mode for grpc connection to the go-micro based grpc services. Possible values are 'off', 'insecure' and 'on'. 'off': disables transport security for the clients. 'insecure' allows using transport security, but disables certificate verification (to be used with the autogenerated self-signed certificates). 'insecure' is only accepted when OC_INSECURE is set to 'true', otherwise the services fail to start. 'on' enables transport security, including server certificate verification." introductionVersion:"1.0.0"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The description of the mode still says "'insecure' is only accepted when OC_INSECURE is set to 'true'". It could name the new insecure option as well, since the docs of the env vars and of the config file are generated from it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in cde7ec7: the description of OC_GRPC_CLIENT_TLS_MODE now names grpc_client_tls.insecure as well. I changed the description of OC_GRPC_TLS_ENABLED the same way, since it had the same sentence about OC_INSECURE.

@asaah262

Copy link
Copy Markdown
Contributor Author

@pbleser-oc As discussed, I've kept the commit messages to one line each; the details on why the check moved into the configuration, and what opencloud init --insecure writes, are in the PR description.

@asaah262
asaah262 requested a review from micbar November 25, 2026 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants