[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>
This commit is contained in:
@@ -27,13 +27,13 @@ type Channel interface {
|
||||
|
||||
// NewMailChannel instantiates a new mail communication channel.
|
||||
func NewMailChannel(cfg config.Config, logger log.Logger) (Channel, error) {
|
||||
tm, err := pool.StringToTLSMode(cfg.Notifications.RevaGatewayTLSMode)
|
||||
tm, err := pool.StringToTLSMode(cfg.Notifications.GRPCClientTLS.Mode)
|
||||
if err != nil {
|
||||
logger.Error().Err(err).Msg("could not get gateway client tls mode")
|
||||
return nil, err
|
||||
}
|
||||
gc, err := pool.GetGatewayServiceClient(cfg.Notifications.RevaGateway,
|
||||
pool.WithTLSCACert(cfg.Notifications.RevaGatewayTLSCACert),
|
||||
pool.WithTLSCACert(cfg.Notifications.GRPCClientTLS.CACert),
|
||||
pool.WithTLSMode(tm),
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
@@ -77,13 +77,13 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tm, err := pool.StringToTLSMode(cfg.Notifications.RevaGatewayTLSMode)
|
||||
tm, err := pool.StringToTLSMode(cfg.Notifications.GRPCClientTLS.Mode)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
gwclient, err := pool.GetGatewayServiceClient(
|
||||
cfg.Notifications.RevaGateway,
|
||||
pool.WithTLSCACert(cfg.Notifications.RevaGatewayTLSCACert),
|
||||
pool.WithTLSCACert(cfg.Notifications.GRPCClientTLS.CACert),
|
||||
pool.WithTLSMode(tm),
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
@@ -22,13 +22,12 @@ type Config struct {
|
||||
|
||||
// Notifications defines the config options for the notifications service.
|
||||
type Notifications struct {
|
||||
SMTP SMTP `yaml:"SMTP"`
|
||||
Events Events `yaml:"events"`
|
||||
MachineAuthAPIKey string `yaml:"machine_auth_api_key" env:"OCIS_MACHINE_AUTH_API_KEY;NOTIFICATIONS_MACHINE_AUTH_API_KEY" desc:"Machine auth API key used to validate internal requests necessary to access resources from other services."`
|
||||
EmailTemplatePath string `yaml:"email_template_path" env:"OCIS_EMAIL_TEMPLATE_PATH;NOTIFICATIONS_EMAIL_TEMPLATE_PATH" desc:"Path to Email notification templates overriding embedded ones."`
|
||||
RevaGateway string `yaml:"reva_gateway" env:"REVA_GATEWAY" desc:"CS3 gateway used to look up user metadata"`
|
||||
RevaGatewayTLSMode string `yaml:"reva_gateway_tls_mode" env:"REVA_GATEWAY_TLS_MODE"`
|
||||
RevaGatewayTLSCACert string `yaml:"reva_gateway_tls_cacert" env:"REVA_GATEWAY_TLS_CACERT"`
|
||||
SMTP SMTP `yaml:"SMTP"`
|
||||
Events Events `yaml:"events"`
|
||||
MachineAuthAPIKey string `yaml:"machine_auth_api_key" env:"OCIS_MACHINE_AUTH_API_KEY;NOTIFICATIONS_MACHINE_AUTH_API_KEY" desc:"Machine auth API key used to validate internal requests necessary to access resources from other services."`
|
||||
EmailTemplatePath string `yaml:"email_template_path" env:"OCIS_EMAIL_TEMPLATE_PATH;NOTIFICATIONS_EMAIL_TEMPLATE_PATH" desc:"Path to Email notification templates overriding embedded ones."`
|
||||
RevaGateway string `yaml:"reva_gateway" env:"REVA_GATEWAY" desc:"CS3 gateway used to look up user metadata"`
|
||||
GRPCClientTLS *shared.GRPCClientTLS `yaml:"grpc_client_tls"`
|
||||
}
|
||||
|
||||
// SMTP combines the smtp configuration options.
|
||||
|
||||
@@ -37,9 +37,7 @@ func DefaultConfig() *config.Config {
|
||||
ConsumerGroup: "notifications",
|
||||
EnableTLS: false,
|
||||
},
|
||||
RevaGateway: shared.DefaultRevaConfig().Address,
|
||||
RevaGatewayTLSMode: shared.DefaultRevaConfig().TLSMode,
|
||||
RevaGatewayTLSCACert: shared.DefaultRevaConfig().TLSCACert,
|
||||
RevaGateway: shared.DefaultRevaConfig().Address,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -60,6 +58,12 @@ func EnsureDefaults(cfg *config.Config) {
|
||||
if cfg.Notifications.MachineAuthAPIKey == "" && cfg.Commons != nil && cfg.Commons.MachineAuthAPIKey != "" {
|
||||
cfg.Notifications.MachineAuthAPIKey = cfg.Commons.MachineAuthAPIKey
|
||||
}
|
||||
if cfg.Notifications.GRPCClientTLS == nil {
|
||||
cfg.Notifications.GRPCClientTLS = &shared.GRPCClientTLS{}
|
||||
if cfg.Commons != nil && cfg.Commons.GRPCClientTLS != nil {
|
||||
cfg.Notifications.GRPCClientTLS = cfg.Commons.GRPCClientTLS
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Sanitize(cfg *config.Config) {
|
||||
|
||||
Reference in New Issue
Block a user