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

[full-ci] Introduce TLS Settings for go-micro based grpc services and clients #4901

Merged
merged 2 commits into from
Nov 3, 2022

Conversation

rhafer
Copy link
Contributor

@rhafer rhafer commented Oct 25, 2022

TLS for the services can be configure by setting the OCIS_GRPC_TLS_ENABLED" "OCIS_GRPC_TLS_CERTIFICATE" and "OCIS_GRPC_TLS_KEY" enviroment variables.

TLS for the clients can configured by setting the "OCIS_GRPC_CLIENT_TLS_MODE" and "OCIS_GRPC_CLIENT_TLS_CACERT" variables.

By default TLS is disabled.

@rhafer rhafer self-assigned this Oct 25, 2022
@rhafer rhafer force-pushed the go-micro-tls branch 6 times, most recently from 8594125 to 1f36279 Compare October 26, 2022 10:17
@mmattel
Copy link
Contributor

mmattel commented Oct 26, 2022

I see a problem there, not with the implementation or the env description texts.

The problem is, that none of the envs starting with OCIS_ will be part of the documentation because they are not assigned to a particular services (global scope) and currently not automatically catched by the process.

This impacts that we have important envs to configure but nobody knows...

Referncing #3917 (Harmonize env variable naming for those which are not bound to a particular service) @dragonchaser fyi

@rhafer
Copy link
Contributor Author

rhafer commented Oct 26, 2022

The problem is, that none of the envs starting with OCIS_ will be part of the documentation because they are not assigned to a particular services (global scope) and currently not automatically catched by the process.

This is not what is happening here. Actually the env vars are assigned to specific services. Even if the struct are defined on a "global" level (mainly to avoid to much duplication and copy and pasting the same thing all over the code base, also because currently there is no need to override these settings on a per service base). Each service that needs those settings instantiates that struct in it's own config struct. And the documentation will get properly generated. Exactly the same thing was done in: #4798 (e.g. for the REVA_GATEWAY_TLS_MODE and REVA_GATEWAY_TLS_CACERT settings) and the documentation is properly generated for those. See https://owncloud.dev/services/users/configuration/

@rhafer rhafer marked this pull request as ready for review October 26, 2022 12:16
@rhafer rhafer requested review from wkloucek and C0rby and removed request for lookacat and kulmann October 26, 2022 12:16
@rhafer rhafer marked this pull request as draft October 26, 2022 12:57
@rhafer rhafer marked this pull request as ready for review October 27, 2022 07:14
@rhafer rhafer force-pushed the go-micro-tls branch 2 times, most recently from 99272bd to 2ce07b4 Compare November 2, 2022 08:41
@micbar micbar requested a review from butonic November 2, 2022 09:45
ocis-pkg/config/config.go Outdated Show resolved Hide resolved
Copy link
Member

@butonic butonic left a comment

Choose a reason for hiding this comment

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

I'm not sure about the verious places where you configure the GRPC default client:

err = ogrpc.Configure(ogrpc.GetClientOptions(cfg.GRPCClientTLS)...)

That only works because GRPCClientTLS is a *shared.GRPCClientTLS that is filled by EnsureDefaults(), only has a single OCIS_GRPC_CLIENT_TLS_* set of env vars and no service specific config.

While it looks fragile to me and I think we may need to add service specific certificates in the future, this is a great step in the right direction.

@butonic

This comment was marked as resolved.

@butonic
Copy link
Member

butonic commented Nov 2, 2022

I set

					// grpc server config
					"OCIS_GRPC_TLS_ENABLED": "on",
					"OCIS_GRPC_TLS_CERTIFICATE": "/home/vscode/.ocis/idm/ldap.crt",
					"OCIS_GRPC_TLS_KEY":  "/home/vscode/.ocis/idm/ldap.key",

					// grpc client config
					"OCIS_GRPC_CLIENT_TLS_MODE": "insecure",

now getting:

2022-11-02T12:28:03Z ERR error starting the grpc server error="unable to register services: rgrpc: grpc service publicshareprovider could not be started,: rpc error: code = Unavailable desc = connection error: desc = \"transport: authentication handshake failed: tls: first record does not look like a TLS handshake\"" service=sharing

🤔

@butonic
Copy link
Member

butonic commented Nov 2, 2022

my bad it has to be "OCIS_GRPC_TLS_ENABLED": "true", and it works nicely!

Copy link
Member

@butonic butonic left a comment

Choose a reason for hiding this comment

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

looks like the PR needs a rebase on / merge of master as some of the expected test lines look shifted.

@rhafer
Copy link
Contributor Author

rhafer commented Nov 2, 2022

That only works because GRPCClientTLS is a *shared.GRPCClientTLS that is filled by EnsureDefaults(), only has a single OCIS_GRPC_CLIENT_TLS_* set of env vars and no service specific config.

Yes. And I did that on purpose. Mainly to avoid spreading even more code duplication across all the services' pkg/config.

While it looks fragile to me and I think we may need to add service specific certificates in the future, this is a great step in the right direction.

Two questions:

  1. Why do you think it's fragile?
  2. In which case to you think we need per service certificates? I am having a hard time coming up with a setup where it would really be needed to have per service env vars for configuring the certificates. When starting separate ocis instance per service you can always set "OCIS_GRPC_TLS_CERTIFICATE to a different value per ocis instance if really needed. If you run a single ocis instance, why would you need separate certificates? And if you really want that, you can even configure it in the config file (each service's configuration section can have it's own tls configuration).

@rhafer
Copy link
Contributor Author

rhafer commented Nov 2, 2022

I set

					// grpc server config
					"OCIS_GRPC_TLS_ENABLED": "on",
					"`": "/home/vscode/.ocis/idm/ldap.crt",
					"OCIS_GRPC_TLS_KEY":  "/home/vscode/.ocis/idm/ldap.key",

					// grpc client config
					"OCIS_GRPC_CLIENT_TLS_MODE": "insecure",

BTW, you can even leave OCIS_GRPC_TLS_CERTIFICATE and OCIS_GRPC_TLS_KEY empty. It will just generate (insecure) certificates in-memory (at every start of ocis).

@mmattel
Copy link
Contributor

mmattel commented Nov 2, 2022

you can even leave OCIS_GRPC_TLS_CERTIFICATE and OCIS_GRPC_TLS_KEY empty. It will just generate (insecure) certificates in-memory (at every start of ocis).

A sentence could be added to the description reflecting this behaviour.

@rhafer
Copy link
Contributor Author

rhafer commented Nov 2, 2022

you can even leave OCIS_GRPC_TLS_CERTIFICATE and OCIS_GRPC_TLS_KEY empty. It will just generate (insecure) certificates in-memory (at every start of ocis).

A sentence could be added to the description reflecting this behaviour.

It's there: https://github.com/owncloud/ocis/pull/4901/files#diff-bc4f34bf14cfb981d81d2f12ed8f70c7c34023813282c8a82d4bc54c3938de4bR44 😄

@mmattel
Copy link
Contributor

mmattel commented Nov 2, 2022

Added some commitable suggestions, from a docs pov, looks fine to me though I would be happy to have an answer to #4901 (comment) for a general improvment of that env descriptions - which can be fixed post merging this PR but should be considered.

rhafer and others added 2 commits November 3, 2022 08:58
TLS for the services can be configure by setting the OCIS_MICRO_GRPC_TLS_ENABLED"
"OCIS_MICRO_GRPC_TLS_CERTIFICATE" and "OCIS_MICRO_GRPC_TLS_KEY"
enviroment variables.

TLS for the clients can configured by setting the "OCIS_MICRO_GRPC_CLIENT_TLS_MODE"
and "OCIS_MICRO_GRPC_CLIENT_TLS_CACERT" variables.

By default TLS is disabled.

Co-authored-by: Martin <github@diemattels.at>
All grpc service (whether they're based on reva) or go-micro use the
same set of config vars now.

TLS for the services can be configure by setting the OCIS_GRPC_TLS_ENABLED,
OCIS_GRPC_TLS_CERTIFICATE and OCIS_GRPC_TLS_KEY enviroment variables.

TLS for the clients can configured by setting the OCIS_GRPC_CLIENT_TLS_MODE
and OCIS_MICRO_GRPC_CLIENT_TLS_CACERT variables.

There are no individual per service config vars currently. If really
needed, per service tls configurations can be specified via config file.

Co-authored-by: Martin <github@diemattels.at>
@sonarcloud
Copy link

sonarcloud bot commented Nov 3, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 16 Code Smells

0.0% 0.0% Coverage
44.6% 44.6% Duplication

@butonic
Copy link
Member

butonic commented Nov 3, 2022

  • Why do you think it's fragile?

Reusing a shared config requires initializing it with EnsureDefaults ... I'm just beginning to hold a grudge against all the boilerplate, which I consider fragile when trying to create a new service. At the moment I think it is still nearld impossible to add a service and get the config and env var parsing right ... not really a critique af this PR, I admit.

  • In which case to you think we need per service certificates? I am having a hard time coming up with a setup where it would really be needed to have per service env vars for configuring the certificates. When starting separate ocis instance per service you can always set "OCIS_GRPC_TLS_CERTIFICATE to a different value per ocis instance if really needed. If you run a single ocis instance, why would you need separate certificates? And if you really want that, you can even configure it in the config file (each service's configuration section can have it's own tls configuration).

Yeah, I had the same thought but did not really follow up on it. Thank you for driving the nail into the coffin by confirming it.

@butonic butonic merged commit ee974af into owncloud:master Nov 3, 2022
ownclouders pushed a commit that referenced this pull request Nov 3, 2022
Author: Ralf Haferkamp <rhaferkamp@owncloud.com>
Date:   Thu Nov 3 10:17:08 2022 +0100

    [full-ci] Introduce TLS Settings for go-micro based grpc services and clients (#4901)

    * Introduce TLS Settings for go-micro based grpc services and clients

    TLS for the services can be configure by setting the OCIS_MICRO_GRPC_TLS_ENABLED"
    "OCIS_MICRO_GRPC_TLS_CERTIFICATE" and "OCIS_MICRO_GRPC_TLS_KEY"
    enviroment variables.

    TLS for the clients can configured by setting the "OCIS_MICRO_GRPC_CLIENT_TLS_MODE"
    and "OCIS_MICRO_GRPC_CLIENT_TLS_CACERT" variables.

    By default TLS is disabled.

    Co-authored-by: Martin <github@diemattels.at>

    * Unify TLS configuration for all grpc services

    All grpc service (whether they're based on reva) or go-micro use the
    same set of config vars now.

    TLS for the services can be configure by setting the OCIS_GRPC_TLS_ENABLED,
    OCIS_GRPC_TLS_CERTIFICATE and OCIS_GRPC_TLS_KEY enviroment variables.

    TLS for the clients can configured by setting the OCIS_GRPC_CLIENT_TLS_MODE
    and OCIS_MICRO_GRPC_CLIENT_TLS_CACERT variables.

    There are no individual per service config vars currently. If really
    needed, per service tls configurations can be specified via config file.

    Co-authored-by: Martin <github@diemattels.at>

    Co-authored-by: Martin <github@diemattels.at>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants