From df9f6d7eca8402da7bab79697dc20ec5a7e55ca7 Mon Sep 17 00:00:00 2001 From: Michal Klos Date: Fri, 14 Aug 2026 12:13:29 +0200 Subject: [PATCH] feat: [stable-8.1][OCISDEV-1115] harden nats communication (#12791) feat: [OCISDEV-1115] harden nats communication (#12777) * feat: [OCISDEV-1115] harden nats communication * feat: bump reva for tls-enabled stores --- changelog/unreleased/enhancement-nats-tls.md | 8 + go.mod | 2 +- go.sum | 4 +- ocis-pkg/natsjsregistry/registry.go | 34 ++- ocis-pkg/shared/shared_types.go | 7 +- services/activitylog/pkg/command/server.go | 1 + services/activitylog/pkg/config/config.go | 7 +- services/collaboration/pkg/command/server.go | 1 + services/collaboration/pkg/config/store.go | 7 +- services/eventhistory/pkg/command/server.go | 1 + services/eventhistory/pkg/config/config.go | 7 +- services/gateway/pkg/config/config.go | 7 +- services/gateway/pkg/revaconfig/config.go | 7 +- services/graph/pkg/config/cache.go | 7 +- services/graph/pkg/service/v0/service.go | 1 + services/notifications/pkg/command/server.go | 1 + services/notifications/pkg/config/config.go | 7 +- services/ocs/pkg/config/config.go | 7 +- services/ocs/pkg/server/http/server.go | 1 + services/postprocessing/pkg/command/server.go | 1 + services/postprocessing/pkg/config/config.go | 7 +- services/proxy/pkg/command/server.go | 2 + services/proxy/pkg/config/config.go | 14 +- services/settings/pkg/config/config.go | 7 +- services/settings/pkg/store/metadata/cache.go | 2 + .../storage-publiclink/pkg/config/config.go | 7 +- .../pkg/revaconfig/config.go | 7 +- services/storage-system/pkg/config/config.go | 7 +- .../storage-system/pkg/revaconfig/config.go | 7 +- services/storage-users/pkg/config/config.go | 14 +- .../storage-users/pkg/revaconfig/drivers.go | 70 +++++-- services/userlog/pkg/command/server.go | 1 + services/userlog/pkg/config/config.go | 7 +- .../storageprovider/storageprovider.go | 2 + .../auth/manager/publicshares/publicshares.go | 4 + .../rhttp/datatx/utils/download/download.go | 3 + .../receivedsharecache/receivedsharecache.go | 198 ++++++++++-------- .../reva/v2/pkg/storage/cache/cache.go | 17 +- .../storage/fs/posix/lookup/store_idcache.go | 1 + .../reva/v2/pkg/storage/fs/posix/posix.go | 1 + .../utils/decomposedfs/decomposedfs.go | 1 + .../storage/utils/decomposedfs/tree/tree.go | 3 + .../pkg/storage/utils/decomposedfs/upload.go | 2 + .../utils/decomposedfs/upload/upload.go | 5 +- .../reva/v2/pkg/storage/utils/metadata/cs3.go | 11 + .../owncloud/reva/v2/pkg/store/options.go | 20 ++ .../owncloud/reva/v2/pkg/store/store.go | 78 +++++-- vendor/modules.txt | 2 +- 48 files changed, 444 insertions(+), 174 deletions(-) create mode 100644 changelog/unreleased/enhancement-nats-tls.md diff --git a/changelog/unreleased/enhancement-nats-tls.md b/changelog/unreleased/enhancement-nats-tls.md new file mode 100644 index 00000000000..b1eba8a82f2 --- /dev/null +++ b/changelog/unreleased/enhancement-nats-tls.md @@ -0,0 +1,8 @@ +Enhancement: Add TLS support for NATS store and registry connections + +All `nats-js-kv` store, cache, and service registry connections now support +TLS. Configure via `OCIS_CACHE_ENABLE_TLS`, `OCIS_PERSISTENT_STORE_ENABLE_TLS`, +and `MICRO_REGISTRY_ENABLE_TLS`, with corresponding `*_TLS_INSECURE` and +`*_TLS_ROOT_CA_CERTIFICATE` variants per connection type. + +https://github.com/owncloud/ocis/pull/12765 diff --git a/go.mod b/go.mod index 9c13aeeb288..793d9063d64 100644 --- a/go.mod +++ b/go.mod @@ -65,7 +65,7 @@ require ( github.com/open-policy-agent/opa v1.19.0 github.com/orcaman/concurrent-map v1.0.0 github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245 - github.com/owncloud/reva/v2 v2.0.0-20260803145357-624c8ac70757 + github.com/owncloud/reva/v2 v2.0.0-20260813081421-ca7fa1632ddf github.com/pkg/errors v0.9.1 github.com/pkg/xattr v0.4.12 github.com/prometheus/client_golang v1.24.1 diff --git a/go.sum b/go.sum index 0a1487d9930..2e86893c04f 100644 --- a/go.sum +++ b/go.sum @@ -735,8 +735,8 @@ github.com/orcaman/concurrent-map v1.0.0 h1:I/2A2XPCb4IuQWcQhBhSwGfiuybl/J0ev9HD github.com/orcaman/concurrent-map v1.0.0/go.mod h1:Lu3tH6HLW3feq74c2GC+jIMS/K2CFcDWnWD9XkenwhI= github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245 h1:JRidLTAKhnvyLMRtVtSF4lhBa0NSAOs6fof+d6JnKII= github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245/go.mod h1:z61VMGAJRtR1nbgXWiNoCkxUXP1B3Je9rMuJbnGd+Og= -github.com/owncloud/reva/v2 v2.0.0-20260803145357-624c8ac70757 h1:5Ucr5ccvOA3d+wPMQSeq/CWWSxYveKc0A7J0+uhe1mM= -github.com/owncloud/reva/v2 v2.0.0-20260803145357-624c8ac70757/go.mod h1:/ome8cEE7tI4ZSX8Jp+5u3XF+u94VZbrR5YwfbphF4E= +github.com/owncloud/reva/v2 v2.0.0-20260813081421-ca7fa1632ddf h1:T54EsWCPDr97ByB51yGKgQS+VDuG2JEtemgRBDjcMfI= +github.com/owncloud/reva/v2 v2.0.0-20260813081421-ca7fa1632ddf/go.mod h1:/ome8cEE7tI4ZSX8Jp+5u3XF+u94VZbrR5YwfbphF4E= github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw= github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0= github.com/pablodz/inotifywaitgo v0.0.12 h1:DVJJTFMDlSAdO46yisPF2vzozs/r+4k6ih8MVghq78M= diff --git a/ocis-pkg/natsjsregistry/registry.go b/ocis-pkg/natsjsregistry/registry.go index 49555a7d612..cc30af5ae8b 100644 --- a/ocis-pkg/natsjsregistry/registry.go +++ b/ocis-pkg/natsjsregistry/registry.go @@ -3,6 +3,7 @@ package natsjsregistry import ( "context" + "crypto/tls" "encoding/json" "errors" "fmt" @@ -14,6 +15,7 @@ import ( natsjskv "github.com/go-micro/plugins/v4/store/nats-js-kv" "github.com/nats-io/nats.go" "github.com/owncloud/ocis/v2/ocis-pkg/generators" + revastore "github.com/owncloud/reva/v2/pkg/store" "go-micro.dev/v4/registry" "go-micro.dev/v4/server" "go-micro.dev/v4/store" @@ -21,10 +23,13 @@ import ( ) var ( - _registryName = "nats-js-kv" - _registryAddressEnv = "MICRO_REGISTRY_ADDRESS" - _registryUsernameEnv = "MICRO_REGISTRY_AUTH_USERNAME" - _registryPasswordEnv = "MICRO_REGISTRY_AUTH_PASSWORD" + _registryName = "nats-js-kv" + _registryAddressEnv = "MICRO_REGISTRY_ADDRESS" + _registryUsernameEnv = "MICRO_REGISTRY_AUTH_USERNAME" + _registryPasswordEnv = "MICRO_REGISTRY_AUTH_PASSWORD" + _registryEnableTLSEnv = "MICRO_REGISTRY_ENABLE_TLS" + _registryTLSInsecureEnv = "MICRO_REGISTRY_TLS_INSECURE" + _registryTLSRootCAEnv = "MICRO_REGISTRY_TLS_ROOT_CA_CERTIFICATE" _serviceDelimiter = "@" ) @@ -211,6 +216,10 @@ func (n *storeregistry) storeOptions(opts registry.Options) []store.Option { natsOptions := nats.GetDefaultOptions() natsOptions.Name = generators.GenerateConnectionName(serviceName, generators.NTypeRegistry) natsOptions.User, natsOptions.Password = getAuth() + if tlsConf := getTLS(); tlsConf != nil { + natsOptions.TLSConfig = tlsConf + natsOptions.Secure = true + } natsOptions.ReconnectedCB = func(_ *nats.Conn) { if err := n.Init(); err != nil { fmt.Println("cannot reconnect to nats") @@ -233,3 +242,20 @@ func (n *storeregistry) storeOptions(opts registry.Options) []store.Option { func getAuth() (string, string) { return os.Getenv(_registryUsernameEnv), os.Getenv(_registryPasswordEnv) } + +var ( + _tlsOnce sync.Once + _tlsConfig *tls.Config +) + +func getTLS() *tls.Config { + _tlsOnce.Do(func() { + if os.Getenv(_registryEnableTLSEnv) != "true" { + return + } + insecure := os.Getenv(_registryTLSInsecureEnv) == "true" + rootCA := os.Getenv(_registryTLSRootCAEnv) + _tlsConfig = revastore.BuildNatsTLSConfig(insecure, rootCA) + }) + return _tlsConfig +} diff --git a/ocis-pkg/shared/shared_types.go b/ocis-pkg/shared/shared_types.go index db78b9c0c46..4fd757c1cc5 100644 --- a/ocis-pkg/shared/shared_types.go +++ b/ocis-pkg/shared/shared_types.go @@ -62,8 +62,11 @@ type Cache struct { Table string `yaml:"table" env:"OCIS_CACHE_STORE_TABLE" desc:"The database table the store should use." introductionVersion:"pre5.0"` TTL time.Duration `yaml:"ttl" env:"OCIS_CACHE_TTL" desc:"Time to live for events in the store. The duration can be set as number followed by a unit identifier like s, m or h." introductionVersion:"pre5.0"` DisablePersistence bool `yaml:"disable_persistence" env:"OCIS_CACHE_DISABLE_PERSISTENCE" desc:"Disables persistence of the cache. Only applies when store type 'nats-js-kv' is configured. Defaults to false." introductionVersion:"5.0"` - AuthUsername string `yaml:"auth_username" env:"OCIS_CACHE_AUTH_USERNAME" desc:"The username to use for authentication. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"pre5.0"` - AuthPassword string `yaml:"auth_password" env:"OCIS_CACHE_AUTH_PASSWORD" desc:"The password to use for authentication. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"pre5.0"` + AuthUsername string `yaml:"auth_username" env:"OCIS_CACHE_AUTH_USERNAME" desc:"The username to use for authentication. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"pre5.0"` + AuthPassword string `yaml:"auth_password" env:"OCIS_CACHE_AUTH_PASSWORD" desc:"The password to use for authentication. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"pre5.0"` + EnableTLS bool `yaml:"enable_tls" env:"OCIS_CACHE_ENABLE_TLS" desc:"Activate TLS for the connection to the NATS store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSInsecure bool `yaml:"tls_insecure" env:"OCIS_CACHE_TLS_INSECURE" desc:"Disable TLS certificate verification for the NATS store connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSRootCACertificate string `yaml:"tls_root_ca_certificate" env:"OCIS_CACHE_TLS_ROOT_CA_CERTIFICATE" desc:"Path to the PEM-encoded root CA certificate used to validate the NATS store TLS certificate. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` } // Commons holds configuration that are common to all extensions. Each extension can then decide whether diff --git a/services/activitylog/pkg/command/server.go b/services/activitylog/pkg/command/server.go index 28bdf997f24..44a5c88eb18 100644 --- a/services/activitylog/pkg/command/server.go +++ b/services/activitylog/pkg/command/server.go @@ -90,6 +90,7 @@ func Server(cfg *config.Config) *cli.Command { microstore.Database(cfg.Store.Database), microstore.Table(cfg.Store.Table), store.Authentication(cfg.Store.AuthUsername, cfg.Store.AuthPassword), + store.TLS(cfg.Store.EnableTLS, cfg.Store.TLSInsecure, cfg.Store.TLSRootCACertificate), ) tm, err := pool.StringToTLSMode(cfg.GRPCClientTLS.Mode) diff --git a/services/activitylog/pkg/config/config.go b/services/activitylog/pkg/config/config.go index 8b646f65782..d8abf8d2b2e 100644 --- a/services/activitylog/pkg/config/config.go +++ b/services/activitylog/pkg/config/config.go @@ -52,8 +52,11 @@ type Store struct { Database string `yaml:"database" env:"ACTIVITYLOG_STORE_DATABASE" desc:"The database name the configured store should use." introductionVersion:"pre5.0"` Table string `yaml:"table" env:"ACTIVITYLOG_STORE_TABLE" desc:"The database table the store should use." introductionVersion:"pre5.0"` TTL time.Duration `yaml:"ttl" env:"OCIS_PERSISTENT_STORE_TTL;ACTIVITYLOG_STORE_TTL" desc:"Time to live for events in the store. See the Environment Variable Types description for more details." introductionVersion:"pre5.0"` - AuthUsername string `yaml:"username" env:"OCIS_PERSISTENT_STORE_AUTH_USERNAME;ACTIVITYLOG_STORE_AUTH_USERNAME" desc:"The username to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` - AuthPassword string `yaml:"password" env:"OCIS_PERSISTENT_STORE_AUTH_PASSWORD;ACTIVITYLOG_STORE_AUTH_PASSWORD" desc:"The password to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + AuthUsername string `yaml:"username" env:"OCIS_PERSISTENT_STORE_AUTH_USERNAME;ACTIVITYLOG_STORE_AUTH_USERNAME" desc:"The username to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + AuthPassword string `yaml:"password" env:"OCIS_PERSISTENT_STORE_AUTH_PASSWORD;ACTIVITYLOG_STORE_AUTH_PASSWORD" desc:"The password to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + EnableTLS bool `yaml:"enable_tls" env:"OCIS_PERSISTENT_STORE_ENABLE_TLS;ACTIVITYLOG_STORE_ENABLE_TLS" desc:"Activate TLS for the connection to the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSInsecure bool `yaml:"tls_insecure" env:"OCIS_PERSISTENT_STORE_TLS_INSECURE;ACTIVITYLOG_STORE_TLS_INSECURE" desc:"Disable TLS certificate verification for the store connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSRootCACertificate string `yaml:"tls_root_ca_certificate" env:"OCIS_PERSISTENT_STORE_TLS_ROOT_CA_CERTIFICATE;ACTIVITYLOG_STORE_TLS_ROOT_CA_CERTIFICATE" desc:"Path to the PEM-encoded root CA certificate for the store TLS connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` } // ServiceAccount is the configuration for the used service account diff --git a/services/collaboration/pkg/command/server.go b/services/collaboration/pkg/command/server.go index d27e46cd586..cb6a93f8b38 100644 --- a/services/collaboration/pkg/command/server.go +++ b/services/collaboration/pkg/command/server.go @@ -83,6 +83,7 @@ func Server(cfg *config.Config) *cli.Command { microstore.Database(cfg.Store.Database), microstore.Table(cfg.Store.Table), store.Authentication(cfg.Store.AuthUsername, cfg.Store.AuthPassword), + store.TLS(cfg.Store.EnableTLS, cfg.Store.TLSInsecure, cfg.Store.TLSRootCACertificate), ) gr := runner.NewGroup() diff --git a/services/collaboration/pkg/config/store.go b/services/collaboration/pkg/config/store.go index 6f2051e4b10..93a5da5507c 100644 --- a/services/collaboration/pkg/config/store.go +++ b/services/collaboration/pkg/config/store.go @@ -9,6 +9,9 @@ type Store struct { Database string `yaml:"database" env:"COLLABORATION_STORE_DATABASE" desc:"The database name the configured store should use." introductionVersion:"7.0.0"` Table string `yaml:"table" env:"COLLABORATION_STORE_TABLE" desc:"The database table the store should use." introductionVersion:"7.0.0"` TTL time.Duration `yaml:"ttl" env:"OCIS_PERSISTENT_STORE_TTL;COLLABORATION_STORE_TTL" desc:"Time to live for events in the store. Defaults to '30m' (30 minutes). See the Environment Variable Types description for more details." introductionVersion:"7.0.0"` - AuthUsername string `yaml:"username" env:"OCIS_PERSISTENT_STORE_AUTH_USERNAME;COLLABORATION_STORE_AUTH_USERNAME" desc:"The username to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"7.0.0"` - AuthPassword string `yaml:"password" env:"OCIS_PERSISTENT_STORE_AUTH_PASSWORD;COLLABORATION_STORE_AUTH_PASSWORD" desc:"The password to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"7.0.0"` + AuthUsername string `yaml:"username" env:"OCIS_PERSISTENT_STORE_AUTH_USERNAME;COLLABORATION_STORE_AUTH_USERNAME" desc:"The username to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"7.0.0"` + AuthPassword string `yaml:"password" env:"OCIS_PERSISTENT_STORE_AUTH_PASSWORD;COLLABORATION_STORE_AUTH_PASSWORD" desc:"The password to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"7.0.0"` + EnableTLS bool `yaml:"enable_tls" env:"OCIS_PERSISTENT_STORE_ENABLE_TLS;COLLABORATION_STORE_ENABLE_TLS" desc:"Activate TLS for the connection to the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSInsecure bool `yaml:"tls_insecure" env:"OCIS_PERSISTENT_STORE_TLS_INSECURE;COLLABORATION_STORE_TLS_INSECURE" desc:"Disable TLS certificate verification for the store connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSRootCACertificate string `yaml:"tls_root_ca_certificate" env:"OCIS_PERSISTENT_STORE_TLS_ROOT_CA_CERTIFICATE;COLLABORATION_STORE_TLS_ROOT_CA_CERTIFICATE" desc:"Path to the PEM-encoded root CA certificate for the store TLS connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` } diff --git a/services/eventhistory/pkg/command/server.go b/services/eventhistory/pkg/command/server.go index 06df1fd00bb..920fb8999df 100644 --- a/services/eventhistory/pkg/command/server.go +++ b/services/eventhistory/pkg/command/server.go @@ -72,6 +72,7 @@ func Server(cfg *config.Config) *cli.Command { microstore.Database(cfg.Store.Database), microstore.Table(cfg.Store.Table), store.Authentication(cfg.Store.AuthUsername, cfg.Store.AuthPassword), + store.TLS(cfg.Store.EnableTLS, cfg.Store.TLSInsecure, cfg.Store.TLSRootCACertificate), ) service := grpc.NewService( diff --git a/services/eventhistory/pkg/config/config.go b/services/eventhistory/pkg/config/config.go index 0841fd9243f..78b07bd0744 100644 --- a/services/eventhistory/pkg/config/config.go +++ b/services/eventhistory/pkg/config/config.go @@ -42,8 +42,11 @@ type Store struct { Database string `yaml:"database" env:"EVENTHISTORY_STORE_DATABASE" desc:"The database name the configured store should use." introductionVersion:"pre5.0"` Table string `yaml:"table" env:"EVENTHISTORY_STORE_TABLE" desc:"The database table the store should use." introductionVersion:"pre5.0"` TTL time.Duration `yaml:"ttl" env:"OCIS_PERSISTENT_STORE_TTL;EVENTHISTORY_STORE_TTL" desc:"Time to live for events in the store. Defaults to '336h' (2 weeks). See the Environment Variable Types description for more details." introductionVersion:"pre5.0"` - AuthUsername string `yaml:"username" env:"OCIS_PERSISTENT_STORE_AUTH_USERNAME;EVENTHISTORY_STORE_AUTH_USERNAME" desc:"The username to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` - AuthPassword string `yaml:"password" env:"OCIS_PERSISTENT_STORE_AUTH_PASSWORD;EVENTHISTORY_STORE_AUTH_PASSWORD" desc:"The password to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + AuthUsername string `yaml:"username" env:"OCIS_PERSISTENT_STORE_AUTH_USERNAME;EVENTHISTORY_STORE_AUTH_USERNAME" desc:"The username to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + AuthPassword string `yaml:"password" env:"OCIS_PERSISTENT_STORE_AUTH_PASSWORD;EVENTHISTORY_STORE_AUTH_PASSWORD" desc:"The password to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + EnableTLS bool `yaml:"enable_tls" env:"OCIS_PERSISTENT_STORE_ENABLE_TLS;EVENTHISTORY_STORE_ENABLE_TLS" desc:"Activate TLS for the connection to the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSInsecure bool `yaml:"tls_insecure" env:"OCIS_PERSISTENT_STORE_TLS_INSECURE;EVENTHISTORY_STORE_TLS_INSECURE" desc:"Disable TLS certificate verification for the store connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSRootCACertificate string `yaml:"tls_root_ca_certificate" env:"OCIS_PERSISTENT_STORE_TLS_ROOT_CA_CERTIFICATE;EVENTHISTORY_STORE_TLS_ROOT_CA_CERTIFICATE" desc:"Path to the PEM-encoded root CA certificate for the store TLS connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` } // Events combines the configuration options for the event bus. diff --git a/services/gateway/pkg/config/config.go b/services/gateway/pkg/config/config.go index 786d1d0f7aa..0c9d0d4eb8c 100644 --- a/services/gateway/pkg/config/config.go +++ b/services/gateway/pkg/config/config.go @@ -93,6 +93,9 @@ type Cache struct { ProviderCacheDatabase string `yaml:"provider_cache_database" env:"OCIS_CACHE_DATABASE" desc:"The database name the configured store should use." introductionVersion:"pre5.0"` ProviderCacheTTL time.Duration `yaml:"provider_cache_ttl" env:"OCIS_CACHE_TTL;GATEWAY_PROVIDER_CACHE_TTL" desc:"Default time to live for user info in the cache. Only applied when access tokens has no expiration. See the Environment Variable Types description for more details." introductionVersion:"pre5.0"` ProviderCacheDisablePersistence bool `yaml:"provider_cache_disable_persistence" env:"OCIS_CACHE_DISABLE_PERSISTENCE;GATEWAY_PROVIDER_CACHE_DISABLE_PERSISTENCE" desc:"Disables persistence of the provider cache. Only applies when store type 'nats-js-kv' is configured. Defaults to false." introductionVersion:"5.0"` - ProviderCacheAuthUsername string `yaml:"provider_cache_auth_username" env:"OCIS_CACHE_AUTH_USERNAME;GATEWAY_PROVIDER_CACHE_AUTH_USERNAME" desc:"The username to use for authentication. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` - ProviderCacheAuthPassword string `yaml:"provider_cache_auth_password" env:"OCIS_CACHE_AUTH_PASSWORD;GATEWAY_PROVIDER_CACHE_AUTH_PASSWORD" desc:"The password to use for authentication. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + ProviderCacheAuthUsername string `yaml:"provider_cache_auth_username" env:"OCIS_CACHE_AUTH_USERNAME;GATEWAY_PROVIDER_CACHE_AUTH_USERNAME" desc:"The username to use for authentication. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + ProviderCacheAuthPassword string `yaml:"provider_cache_auth_password" env:"OCIS_CACHE_AUTH_PASSWORD;GATEWAY_PROVIDER_CACHE_AUTH_PASSWORD" desc:"The password to use for authentication. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + ProviderCacheEnableTLS bool `yaml:"provider_cache_enable_tls" env:"OCIS_CACHE_ENABLE_TLS;GATEWAY_PROVIDER_CACHE_ENABLE_TLS" desc:"Activate TLS for the connection to the cache store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + ProviderCacheTLSInsecure bool `yaml:"provider_cache_tls_insecure" env:"OCIS_CACHE_TLS_INSECURE;GATEWAY_PROVIDER_CACHE_TLS_INSECURE" desc:"Disable TLS certificate verification for the cache store connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + ProviderCacheTLSRootCACertificate string `yaml:"provider_cache_tls_root_ca_certificate" env:"OCIS_CACHE_TLS_ROOT_CA_CERTIFICATE;GATEWAY_PROVIDER_CACHE_TLS_ROOT_CA_CERTIFICATE" desc:"Path to the PEM-encoded root CA certificate for the cache store TLS connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` } diff --git a/services/gateway/pkg/revaconfig/config.go b/services/gateway/pkg/revaconfig/config.go index 0a7d90a8fdd..7f5d675826b 100644 --- a/services/gateway/pkg/revaconfig/config.go +++ b/services/gateway/pkg/revaconfig/config.go @@ -72,8 +72,11 @@ func GatewayConfigFromStruct(cfg *config.Config, logger log.Logger) map[string]i "cache_table": "provider", "cache_ttl": cfg.Cache.ProviderCacheTTL, "disable_persistence": cfg.Cache.ProviderCacheDisablePersistence, - "cache_auth_username": cfg.Cache.ProviderCacheAuthUsername, - "cache_auth_password": cfg.Cache.ProviderCacheAuthPassword, + "cache_auth_username": cfg.Cache.ProviderCacheAuthUsername, + "cache_auth_password": cfg.Cache.ProviderCacheAuthPassword, + "cache_enable_tls": cfg.Cache.ProviderCacheEnableTLS, + "cache_tls_insecure": cfg.Cache.ProviderCacheTLSInsecure, + "cache_tls_root_ca_certificate": cfg.Cache.ProviderCacheTLSRootCACertificate, }, }, "authregistry": map[string]interface{}{ diff --git a/services/graph/pkg/config/cache.go b/services/graph/pkg/config/cache.go index ca7a103a8dc..a39d451cbd7 100644 --- a/services/graph/pkg/config/cache.go +++ b/services/graph/pkg/config/cache.go @@ -10,6 +10,9 @@ type Cache struct { Table string `yaml:"table" env:"GRAPH_CACHE_STORE_TABLE" desc:"The database table the store should use." introductionVersion:"pre5.0"` TTL time.Duration `yaml:"ttl" env:"OCIS_CACHE_TTL;GRAPH_CACHE_TTL" desc:"Time to live for cache records in the graph. Defaults to '336h' (2 weeks). See the Environment Variable Types description for more details." introductionVersion:"pre5.0"` DisablePersistence bool `yaml:"disable_persistence" env:"OCIS_CACHE_DISABLE_PERSISTENCE;GRAPH_CACHE_DISABLE_PERSISTENCE" desc:"Disables persistence of the cache. Only applies when store type 'nats-js-kv' is configured. Defaults to false." introductionVersion:"5.0"` - AuthUsername string `yaml:"username" env:"OCIS_CACHE_AUTH_USERNAME;GRAPH_CACHE_AUTH_USERNAME" desc:"The username to authenticate with the cache. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` - AuthPassword string `yaml:"password" env:"OCIS_CACHE_AUTH_PASSWORD;GRAPH_CACHE_AUTH_PASSWORD" desc:"The password to authenticate with the cache. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + AuthUsername string `yaml:"username" env:"OCIS_CACHE_AUTH_USERNAME;GRAPH_CACHE_AUTH_USERNAME" desc:"The username to authenticate with the cache. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + AuthPassword string `yaml:"password" env:"OCIS_CACHE_AUTH_PASSWORD;GRAPH_CACHE_AUTH_PASSWORD" desc:"The password to authenticate with the cache. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + EnableTLS bool `yaml:"enable_tls" env:"OCIS_CACHE_ENABLE_TLS;GRAPH_CACHE_ENABLE_TLS" desc:"Activate TLS for the connection to the cache store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSInsecure bool `yaml:"tls_insecure" env:"OCIS_CACHE_TLS_INSECURE;GRAPH_CACHE_TLS_INSECURE" desc:"Disable TLS certificate verification for the cache store connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSRootCACertificate string `yaml:"tls_root_ca_certificate" env:"OCIS_CACHE_TLS_ROOT_CA_CERTIFICATE;GRAPH_CACHE_TLS_ROOT_CA_CERTIFICATE" desc:"Path to the PEM-encoded root CA certificate for the cache store TLS connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` } diff --git a/services/graph/pkg/service/v0/service.go b/services/graph/pkg/service/v0/service.go index 1d41eaea41a..4674a98c690 100644 --- a/services/graph/pkg/service/v0/service.go +++ b/services/graph/pkg/service/v0/service.go @@ -183,6 +183,7 @@ func NewService(opts ...Option) (Graph, error) { //nolint:maintidx microstore.Table(options.Config.Cache.Table), store.DisablePersistence(options.Config.Cache.DisablePersistence), store.Authentication(options.Config.Cache.AuthUsername, options.Config.Cache.AuthPassword), + store.TLS(options.Config.Cache.EnableTLS, options.Config.Cache.TLSInsecure, options.Config.Cache.TLSRootCACertificate), } m := roles.NewManager( roles.StoreOptions(storeOptions), diff --git a/services/notifications/pkg/command/server.go b/services/notifications/pkg/command/server.go index 4afe1fc7a11..383e7eb71d6 100644 --- a/services/notifications/pkg/command/server.go +++ b/services/notifications/pkg/command/server.go @@ -134,6 +134,7 @@ func Server(cfg *config.Config) *cli.Command { microstore.Database(cfg.Store.Database), microstore.Table(cfg.Store.Table), store.Authentication(cfg.Store.AuthUsername, cfg.Store.AuthPassword), + store.TLS(cfg.Store.EnableTLS, cfg.Store.TLSInsecure, cfg.Store.TLSRootCACertificate), ) svc := service.NewEventsNotifier(evts, channel, logger, gatewaySelector, valueService, diff --git a/services/notifications/pkg/config/config.go b/services/notifications/pkg/config/config.go index cb049dc268a..e5c16c32a73 100644 --- a/services/notifications/pkg/config/config.go +++ b/services/notifications/pkg/config/config.go @@ -76,6 +76,9 @@ type Store struct { Database string `yaml:"database" env:"NOTIFICATIONS_STORE_DATABASE" desc:"The database name the configured store should use." introductionVersion:"7.1.0"` Table string `yaml:"table" env:"NOTIFICATIONS_STORE_TABLE" desc:"The database table the store should use." introductionVersion:"7.1.0"` TTL time.Duration `yaml:"ttl" env:"OCIS_PERSISTENT_STORE_TTL;NOTIFICATIONS_STORE_TTL" desc:"Time to live for notifications in the store. Defaults to '336h' (2 weeks). See the Environment Variable Types description for more details." introductionVersion:"7.1.0"` - AuthUsername string `yaml:"username" env:"OCIS_PERSISTENT_STORE_AUTH_USERNAME;NOTIFICATIONS_STORE_AUTH_USERNAME" desc:"The username to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"7.1.0"` - AuthPassword string `yaml:"password" env:"OCIS_PERSISTENT_STORE_AUTH_PASSWORD;NOTIFICATIONS_STORE_AUTH_PASSWORD" desc:"The password to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"7.1.0"` + AuthUsername string `yaml:"username" env:"OCIS_PERSISTENT_STORE_AUTH_USERNAME;NOTIFICATIONS_STORE_AUTH_USERNAME" desc:"The username to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"7.1.0"` + AuthPassword string `yaml:"password" env:"OCIS_PERSISTENT_STORE_AUTH_PASSWORD;NOTIFICATIONS_STORE_AUTH_PASSWORD" desc:"The password to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"7.1.0"` + EnableTLS bool `yaml:"enable_tls" env:"OCIS_PERSISTENT_STORE_ENABLE_TLS;NOTIFICATIONS_STORE_ENABLE_TLS" desc:"Activate TLS for the connection to the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSInsecure bool `yaml:"tls_insecure" env:"OCIS_PERSISTENT_STORE_TLS_INSECURE;NOTIFICATIONS_STORE_TLS_INSECURE" desc:"Disable TLS certificate verification for the store connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSRootCACertificate string `yaml:"tls_root_ca_certificate" env:"OCIS_PERSISTENT_STORE_TLS_ROOT_CA_CERTIFICATE;NOTIFICATIONS_STORE_TLS_ROOT_CA_CERTIFICATE" desc:"Path to the PEM-encoded root CA certificate for the store TLS connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` } diff --git a/services/ocs/pkg/config/config.go b/services/ocs/pkg/config/config.go index 4097ff4ef68..657577cb5dd 100644 --- a/services/ocs/pkg/config/config.go +++ b/services/ocs/pkg/config/config.go @@ -35,6 +35,9 @@ type SigningKeys struct { Store string `yaml:"store" env:"OCIS_CACHE_STORE;OCS_PRESIGNEDURL_SIGNING_KEYS_STORE" desc:"The type of the signing key store. Supported values are: 'redis-sentinel' and 'nats-js-kv'. See the text description for details." introductionVersion:"5.0"` Nodes []string `yaml:"addresses" env:"OCIS_CACHE_STORE_NODES;OCS_PRESIGNEDURL_SIGNING_KEYS_STORE_NODES" desc:"A list of nodes to access the configured store. Note that the behaviour how nodes are used is dependent on the library of the configured store. See the Environment Variable Types description for more details." introductionVersion:"5.0"` TTL time.Duration `yaml:"ttl" env:"OCIS_CACHE_TTL;OCS_PRESIGNEDURL_SIGNING_KEYS_STORE_TTL" desc:"Default time to live for signing keys. See the Environment Variable Types description for more details." introductionVersion:"5.0"` - AuthUsername string `yaml:"username" env:"OCIS_CACHE_AUTH_USERNAME;OCS_PRESIGNEDURL_SIGNING_KEYS_STORE_AUTH_USERNAME" desc:"The username to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` - AuthPassword string `yaml:"password" env:"OCIS_CACHE_AUTH_PASSWORD;OCS_PRESIGNEDURL_SIGNING_KEYS_STORE_AUTH_PASSWORD" desc:"The password to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + AuthUsername string `yaml:"username" env:"OCIS_CACHE_AUTH_USERNAME;OCS_PRESIGNEDURL_SIGNING_KEYS_STORE_AUTH_USERNAME" desc:"The username to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + AuthPassword string `yaml:"password" env:"OCIS_CACHE_AUTH_PASSWORD;OCS_PRESIGNEDURL_SIGNING_KEYS_STORE_AUTH_PASSWORD" desc:"The password to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + EnableTLS bool `yaml:"enable_tls" env:"OCIS_CACHE_ENABLE_TLS;OCS_PRESIGNEDURL_SIGNING_KEYS_STORE_ENABLE_TLS" desc:"Activate TLS for the connection to the signing key store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSInsecure bool `yaml:"tls_insecure" env:"OCIS_CACHE_TLS_INSECURE;OCS_PRESIGNEDURL_SIGNING_KEYS_STORE_TLS_INSECURE" desc:"Disable TLS certificate verification for the signing key store connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSRootCACertificate string `yaml:"tls_root_ca_certificate" env:"OCIS_CACHE_TLS_ROOT_CA_CERTIFICATE;OCS_PRESIGNEDURL_SIGNING_KEYS_STORE_TLS_ROOT_CA_CERTIFICATE" desc:"Path to the PEM-encoded root CA certificate for the signing key store TLS connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` } diff --git a/services/ocs/pkg/server/http/server.go b/services/ocs/pkg/server/http/server.go index 6277eb5e4d1..491fdf1fdc7 100644 --- a/services/ocs/pkg/server/http/server.go +++ b/services/ocs/pkg/server/http/server.go @@ -43,6 +43,7 @@ func Server(opts ...Option) (http.Service, error) { microstore.Database("proxy"), microstore.Table("signing-keys"), store.Authentication(options.Config.SigningKeys.AuthUsername, options.Config.SigningKeys.AuthPassword), + store.TLS(options.Config.SigningKeys.EnableTLS, options.Config.SigningKeys.TLSInsecure, options.Config.SigningKeys.TLSRootCACertificate), ) handle := svc.NewService( diff --git a/services/postprocessing/pkg/command/server.go b/services/postprocessing/pkg/command/server.go index eeb99c73f12..521c27b1897 100644 --- a/services/postprocessing/pkg/command/server.go +++ b/services/postprocessing/pkg/command/server.go @@ -65,6 +65,7 @@ func Server(cfg *config.Config) *cli.Command { microstore.Database(cfg.Store.Database), microstore.Table(cfg.Store.Table), store.Authentication(cfg.Store.AuthUsername, cfg.Store.AuthPassword), + store.TLS(cfg.Store.EnableTLS, cfg.Store.TLSInsecure, cfg.Store.TLSRootCACertificate), ) svc, err := service.NewPostprocessingService(ctx, bus, logger, st, traceProvider, cfg.Postprocessing) diff --git a/services/postprocessing/pkg/config/config.go b/services/postprocessing/pkg/config/config.go index 8919df2f7a1..f7c750b18a4 100644 --- a/services/postprocessing/pkg/config/config.go +++ b/services/postprocessing/pkg/config/config.go @@ -62,6 +62,9 @@ type Store struct { Database string `yaml:"database" env:"POSTPROCESSING_STORE_DATABASE" desc:"The database name the configured store should use." introductionVersion:"pre5.0"` Table string `yaml:"table" env:"POSTPROCESSING_STORE_TABLE" desc:"The database table the store should use." introductionVersion:"pre5.0"` TTL time.Duration `yaml:"ttl" env:"OCIS_PERSISTENT_STORE_TTL;POSTPROCESSING_STORE_TTL" desc:"Time to live for events in the store. See the Environment Variable Types description for more details." introductionVersion:"pre5.0"` - AuthUsername string `yaml:"username" env:"OCIS_PERSISTENT_STORE_AUTH_USERNAME;POSTPROCESSING_STORE_AUTH_USERNAME" desc:"The username to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` - AuthPassword string `yaml:"password" env:"OCIS_PERSISTENT_STORE_AUTH_PASSWORD;POSTPROCESSING_STORE_AUTH_PASSWORD" desc:"The password to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + AuthUsername string `yaml:"username" env:"OCIS_PERSISTENT_STORE_AUTH_USERNAME;POSTPROCESSING_STORE_AUTH_USERNAME" desc:"The username to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + AuthPassword string `yaml:"password" env:"OCIS_PERSISTENT_STORE_AUTH_PASSWORD;POSTPROCESSING_STORE_AUTH_PASSWORD" desc:"The password to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + EnableTLS bool `yaml:"enable_tls" env:"OCIS_PERSISTENT_STORE_ENABLE_TLS;POSTPROCESSING_STORE_ENABLE_TLS" desc:"Activate TLS for the connection to the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSInsecure bool `yaml:"tls_insecure" env:"OCIS_PERSISTENT_STORE_TLS_INSECURE;POSTPROCESSING_STORE_TLS_INSECURE" desc:"Disable TLS certificate verification for the store connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSRootCACertificate string `yaml:"tls_root_ca_certificate" env:"OCIS_PERSISTENT_STORE_TLS_ROOT_CA_CERTIFICATE;POSTPROCESSING_STORE_TLS_ROOT_CA_CERTIFICATE" desc:"Path to the PEM-encoded root CA certificate for the store TLS connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` } diff --git a/services/proxy/pkg/command/server.go b/services/proxy/pkg/command/server.go index 317da53da35..2342d009670 100644 --- a/services/proxy/pkg/command/server.go +++ b/services/proxy/pkg/command/server.go @@ -77,6 +77,7 @@ func Server(cfg *config.Config) *cli.Command { microstore.Table(cfg.OIDC.UserinfoCache.Table), store.DisablePersistence(cfg.OIDC.UserinfoCache.DisablePersistence), store.Authentication(cfg.OIDC.UserinfoCache.AuthUsername, cfg.OIDC.UserinfoCache.AuthPassword), + store.TLS(cfg.OIDC.UserinfoCache.EnableTLS, cfg.OIDC.UserinfoCache.TLSInsecure, cfg.OIDC.UserinfoCache.TLSRootCACertificate), ) signingKeyStore := store.Create( @@ -86,6 +87,7 @@ func Server(cfg *config.Config) *cli.Command { microstore.Database("proxy"), microstore.Table("signing-keys"), store.Authentication(cfg.PreSignedURL.SigningKeys.AuthUsername, cfg.PreSignedURL.SigningKeys.AuthPassword), + store.TLS(cfg.PreSignedURL.SigningKeys.EnableTLS, cfg.PreSignedURL.SigningKeys.TLSInsecure, cfg.PreSignedURL.SigningKeys.TLSRootCACertificate), ) cfg.GrpcClient, err = grpc.NewClient( diff --git a/services/proxy/pkg/config/config.go b/services/proxy/pkg/config/config.go index c18228741ce..a1466a69a58 100644 --- a/services/proxy/pkg/config/config.go +++ b/services/proxy/pkg/config/config.go @@ -143,8 +143,11 @@ type Cache struct { Table string `yaml:"table" env:"PROXY_OIDC_USERINFO_CACHE_TABLE" desc:"The database table the store should use." introductionVersion:"pre5.0"` TTL time.Duration `yaml:"ttl" env:"OCIS_CACHE_TTL;PROXY_OIDC_USERINFO_CACHE_TTL" desc:"Default time to live for user info in the user info cache. Only applied when access tokens has no expiration. See the Environment Variable Types description for more details." introductionVersion:"pre5.0"` DisablePersistence bool `yaml:"disable_persistence" env:"OCIS_CACHE_DISABLE_PERSISTENCE;PROXY_OIDC_USERINFO_CACHE_DISABLE_PERSISTENCE" desc:"Disables persistence of the cache. Only applies when store type 'nats-js-kv' is configured. Defaults to false." introductionVersion:"pre5.0"` - AuthUsername string `yaml:"username" env:"OCIS_CACHE_AUTH_USERNAME;PROXY_OIDC_USERINFO_CACHE_AUTH_USERNAME" desc:"The username to authenticate with the cache. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` - AuthPassword string `yaml:"password" env:"OCIS_CACHE_AUTH_PASSWORD;PROXY_OIDC_USERINFO_CACHE_AUTH_PASSWORD" desc:"The password to authenticate with the cache. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + AuthUsername string `yaml:"username" env:"OCIS_CACHE_AUTH_USERNAME;PROXY_OIDC_USERINFO_CACHE_AUTH_USERNAME" desc:"The username to authenticate with the cache. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + AuthPassword string `yaml:"password" env:"OCIS_CACHE_AUTH_PASSWORD;PROXY_OIDC_USERINFO_CACHE_AUTH_PASSWORD" desc:"The password to authenticate with the cache. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + EnableTLS bool `yaml:"enable_tls" env:"OCIS_CACHE_ENABLE_TLS;PROXY_OIDC_USERINFO_CACHE_ENABLE_TLS" desc:"Activate TLS for the connection to the cache store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSInsecure bool `yaml:"tls_insecure" env:"OCIS_CACHE_TLS_INSECURE;PROXY_OIDC_USERINFO_CACHE_TLS_INSECURE" desc:"Disable TLS certificate verification for the cache store connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSRootCACertificate string `yaml:"tls_root_ca_certificate" env:"OCIS_CACHE_TLS_ROOT_CA_CERTIFICATE;PROXY_OIDC_USERINFO_CACHE_TLS_ROOT_CA_CERTIFICATE" desc:"Path to the PEM-encoded root CA certificate for the cache store TLS connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` } // RoleAssignment contains the configuration for how to assign roles to users during login @@ -198,8 +201,11 @@ type SigningKeys struct { Nodes []string `yaml:"addresses" env:"OCIS_CACHE_STORE_NODES;PROXY_PRESIGNEDURL_SIGNING_KEYS_STORE_NODES" desc:"A list of nodes to access the configured store. Note that the behaviour how nodes are used is dependent on the library of the configured store. See the Environment Variable Types description for more details." introductionVersion:"5.0"` TTL time.Duration `yaml:"ttl" env:"OCIS_CACHE_TTL;PROXY_PRESIGNEDURL_SIGNING_KEYS_STORE_TTL" desc:"Default time to live for signing keys. See the Environment Variable Types description for more details." introductionVersion:"5.0"` DisablePersistence bool `yaml:"disable_persistence" env:"OCIS_CACHE_DISABLE_PERSISTENCE;PROXY_PRESIGNEDURL_SIGNING_KEYS_STORE_DISABLE_PERSISTENCE" desc:"Disables persistence of the store. Only applies when store type 'nats-js-kv' is configured. Defaults to true." introductionVersion:"5.0"` - AuthUsername string `yaml:"username" env:"OCIS_CACHE_AUTH_USERNAME;PROXY_PRESIGNEDURL_SIGNING_KEYS_STORE_AUTH_USERNAME" desc:"The username to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` - AuthPassword string `yaml:"password" env:"OCIS_CACHE_AUTH_PASSWORD;PROXY_PRESIGNEDURL_SIGNING_KEYS_STORE_AUTH_PASSWORD" desc:"The password to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + AuthUsername string `yaml:"username" env:"OCIS_CACHE_AUTH_USERNAME;PROXY_PRESIGNEDURL_SIGNING_KEYS_STORE_AUTH_USERNAME" desc:"The username to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + AuthPassword string `yaml:"password" env:"OCIS_CACHE_AUTH_PASSWORD;PROXY_PRESIGNEDURL_SIGNING_KEYS_STORE_AUTH_PASSWORD" desc:"The password to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + EnableTLS bool `yaml:"enable_tls" env:"OCIS_CACHE_ENABLE_TLS;PROXY_PRESIGNEDURL_SIGNING_KEYS_STORE_ENABLE_TLS" desc:"Activate TLS for the connection to the signing key store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSInsecure bool `yaml:"tls_insecure" env:"OCIS_CACHE_TLS_INSECURE;PROXY_PRESIGNEDURL_SIGNING_KEYS_STORE_TLS_INSECURE" desc:"Disable TLS certificate verification for the signing key store connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSRootCACertificate string `yaml:"tls_root_ca_certificate" env:"OCIS_CACHE_TLS_ROOT_CA_CERTIFICATE;PROXY_PRESIGNEDURL_SIGNING_KEYS_STORE_TLS_ROOT_CA_CERTIFICATE" desc:"Path to the PEM-encoded root CA certificate for the signing key store TLS connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` } // ClaimsSelectorConf is the config for the claims-selector diff --git a/services/settings/pkg/config/config.go b/services/settings/pkg/config/config.go index 7dca0fb2406..59cc7cd1fdb 100644 --- a/services/settings/pkg/config/config.go +++ b/services/settings/pkg/config/config.go @@ -63,6 +63,9 @@ type Cache struct { DirectoryTable string `yaml:"directories_table" env:"SETTINGS_DIRECTORY_CACHE_TABLE" desc:"The database table the store should use for the directory cache." introductionVersion:"pre5.0"` TTL time.Duration `yaml:"ttl" env:"OCIS_CACHE_TTL;SETTINGS_CACHE_TTL" desc:"Default time to live for entries in the cache. Only applied when access tokens has no expiration. See the Environment Variable Types description for more details." introductionVersion:"pre5.0"` DisablePersistence bool `yaml:"disable_persistence" env:"OCIS_CACHE_DISABLE_PERSISTENCE;SETTINGS_CACHE_DISABLE_PERSISTENCE" desc:"Disables persistence of the cache. Only applies when store type 'nats-js-kv' is configured. Defaults to false." introductionVersion:"5.0"` - AuthUsername string `yaml:"username" env:"OCIS_CACHE_AUTH_USERNAME;SETTINGS_CACHE_AUTH_USERNAME" desc:"The username to authenticate with the cache. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` - AuthPassword string `yaml:"password" env:"OCIS_CACHE_AUTH_PASSWORD;SETTINGS_CACHE_AUTH_PASSWORD" desc:"The password to authenticate with the cache. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + AuthUsername string `yaml:"username" env:"OCIS_CACHE_AUTH_USERNAME;SETTINGS_CACHE_AUTH_USERNAME" desc:"The username to authenticate with the cache. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + AuthPassword string `yaml:"password" env:"OCIS_CACHE_AUTH_PASSWORD;SETTINGS_CACHE_AUTH_PASSWORD" desc:"The password to authenticate with the cache. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + EnableTLS bool `yaml:"enable_tls" env:"OCIS_CACHE_ENABLE_TLS;SETTINGS_CACHE_ENABLE_TLS" desc:"Activate TLS for the connection to the cache store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSInsecure bool `yaml:"tls_insecure" env:"OCIS_CACHE_TLS_INSECURE;SETTINGS_CACHE_TLS_INSECURE" desc:"Disable TLS certificate verification for the cache store connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSRootCACertificate string `yaml:"tls_root_ca_certificate" env:"OCIS_CACHE_TLS_ROOT_CA_CERTIFICATE;SETTINGS_CACHE_TLS_ROOT_CA_CERTIFICATE" desc:"Path to the PEM-encoded root CA certificate for the cache store TLS connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` } diff --git a/services/settings/pkg/store/metadata/cache.go b/services/settings/pkg/store/metadata/cache.go index 3f365e8e466..c5fc6a4d15e 100644 --- a/services/settings/pkg/store/metadata/cache.go +++ b/services/settings/pkg/store/metadata/cache.go @@ -140,6 +140,7 @@ func (c *CachedMDC) Init(ctx context.Context, id string) error { microstore.Table(c.cfg.Metadata.Cache.DirectoryTable), store.DisablePersistence(c.cfg.Metadata.Cache.DisablePersistence), store.Authentication(c.cfg.Metadata.Cache.AuthUsername, c.cfg.Metadata.Cache.AuthPassword), + store.TLS(c.cfg.Metadata.Cache.EnableTLS, c.cfg.Metadata.Cache.TLSInsecure, c.cfg.Metadata.Cache.TLSRootCACertificate), ) c.filesCache = store.Create( store.Store(c.cfg.Metadata.Cache.Store), @@ -149,6 +150,7 @@ func (c *CachedMDC) Init(ctx context.Context, id string) error { microstore.Table(c.cfg.Metadata.Cache.FileTable), store.DisablePersistence(c.cfg.Metadata.Cache.DisablePersistence), store.Authentication(c.cfg.Metadata.Cache.AuthUsername, c.cfg.Metadata.Cache.AuthPassword), + store.TLS(c.cfg.Metadata.Cache.EnableTLS, c.cfg.Metadata.Cache.TLSInsecure, c.cfg.Metadata.Cache.TLSRootCACertificate), ) return c.next.Init(ctx, id) } diff --git a/services/storage-publiclink/pkg/config/config.go b/services/storage-publiclink/pkg/config/config.go index 12d26a1c476..d9b7bffec0e 100644 --- a/services/storage-publiclink/pkg/config/config.go +++ b/services/storage-publiclink/pkg/config/config.go @@ -68,6 +68,9 @@ type Store struct { Nodes []string `yaml:"nodes" env:"OCIS_PERSISTENT_STORE_NODES;STORAGE_PUBLICLINK_STORE_NODES" desc:"A list of nodes to access the configured store. This has no effect when 'memory' store is configured. Note that the behaviour how nodes are used is dependent on the library of the configured store. See the Environment Variable Types description for more details." introductionVersion:"8.0.0"` Database string `yaml:"database" env:"STORAGE_PUBLICLINK_STORE_DATABASE" desc:"The database name the configured store should use." introductionVersion:"8.0.0"` Table string `yaml:"table" env:"STORAGE_PUBLICLINK_STORE_TABLE" desc:"The database table the store should use." introductionVersion:"8.0.0"` - AuthUsername string `yaml:"username" env:"OCIS_PERSISTENT_STORE_AUTH_USERNAME;STORAGE_PUBLICLINK_STORE_AUTH_USERNAME" desc:"The username to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.0.0"` - AuthPassword string `yaml:"password" env:"OCIS_PERSISTENT_STORE_AUTH_PASSWORD;STORAGE_PUBLICLINK_STORE_AUTH_PASSWORD" desc:"The password to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.0.0"` + AuthUsername string `yaml:"username" env:"OCIS_PERSISTENT_STORE_AUTH_USERNAME;STORAGE_PUBLICLINK_STORE_AUTH_USERNAME" desc:"The username to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.0.0"` + AuthPassword string `yaml:"password" env:"OCIS_PERSISTENT_STORE_AUTH_PASSWORD;STORAGE_PUBLICLINK_STORE_AUTH_PASSWORD" desc:"The password to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.0.0"` + EnableTLS bool `yaml:"enable_tls" env:"OCIS_PERSISTENT_STORE_ENABLE_TLS;STORAGE_PUBLICLINK_STORE_ENABLE_TLS" desc:"Activate TLS for the connection to the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSInsecure bool `yaml:"tls_insecure" env:"OCIS_PERSISTENT_STORE_TLS_INSECURE;STORAGE_PUBLICLINK_STORE_TLS_INSECURE" desc:"Disable TLS certificate verification for the store connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSRootCACertificate string `yaml:"tls_root_ca_certificate" env:"OCIS_PERSISTENT_STORE_TLS_ROOT_CA_CERTIFICATE;STORAGE_PUBLICLINK_STORE_TLS_ROOT_CA_CERTIFICATE" desc:"Path to the PEM-encoded root CA certificate for the store TLS connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` } diff --git a/services/storage-publiclink/pkg/revaconfig/config.go b/services/storage-publiclink/pkg/revaconfig/config.go index 1464bacc320..2551bd932f6 100644 --- a/services/storage-publiclink/pkg/revaconfig/config.go +++ b/services/storage-publiclink/pkg/revaconfig/config.go @@ -44,8 +44,11 @@ func StoragePublicLinkConfigFromStruct(cfg *config.Config) map[string]interface{ "store_nodes": cfg.Store.Nodes, "store_database": cfg.Store.Database, "store_table": cfg.Store.Table, - "store_username": cfg.Store.AuthUsername, - "store_password": cfg.Store.AuthPassword, + "store_username": cfg.Store.AuthUsername, + "store_password": cfg.Store.AuthPassword, + "store_enable_tls": cfg.Store.EnableTLS, + "store_tls_insecure": cfg.Store.TLSInsecure, + "store_tls_root_ca_certificate": cfg.Store.TLSRootCACertificate, }, }, }, diff --git a/services/storage-system/pkg/config/config.go b/services/storage-system/pkg/config/config.go index e215ba6e610..d270ef641b9 100644 --- a/services/storage-system/pkg/config/config.go +++ b/services/storage-system/pkg/config/config.go @@ -91,6 +91,9 @@ type Cache struct { Database string `yaml:"database" env:"OCIS_CACHE_DATABASE" desc:"The database name the configured store should use." introductionVersion:"pre5.0"` TTL time.Duration `yaml:"ttl" env:"OCIS_CACHE_TTL;STORAGE_SYSTEM_CACHE_TTL" desc:"Default time to live for user info in the user info cache. Only applied when access tokens has no expiration. See the Environment Variable Types description for more details." introductionVersion:"pre5.0"` DisablePersistence bool `yaml:"disable_persistence" env:"OCIS_CACHE_DISABLE_PERSISTENCE;STORAGE_SYSTEM_CACHE_DISABLE_PERSISTENCE" desc:"Disables persistence of the cache. Only applies when store type 'nats-js-kv' is configured. Defaults to false." introductionVersion:"5.0"` - AuthUsername string `yaml:"auth_username" env:"OCIS_CACHE_AUTH_USERNAME;STORAGE_SYSTEM_CACHE_AUTH_USERNAME" desc:"Username for the configured store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` - AuthPassword string `yaml:"auth_password" env:"OCIS_CACHE_AUTH_PASSWORD;STORAGE_SYSTEM_CACHE_AUTH_PASSWORD" desc:"Password for the configured store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + AuthUsername string `yaml:"auth_username" env:"OCIS_CACHE_AUTH_USERNAME;STORAGE_SYSTEM_CACHE_AUTH_USERNAME" desc:"Username for the configured store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + AuthPassword string `yaml:"auth_password" env:"OCIS_CACHE_AUTH_PASSWORD;STORAGE_SYSTEM_CACHE_AUTH_PASSWORD" desc:"Password for the configured store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + EnableTLS bool `yaml:"enable_tls" env:"OCIS_CACHE_ENABLE_TLS;STORAGE_SYSTEM_CACHE_ENABLE_TLS" desc:"Activate TLS for the connection to the cache store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSInsecure bool `yaml:"tls_insecure" env:"OCIS_CACHE_TLS_INSECURE;STORAGE_SYSTEM_CACHE_TLS_INSECURE" desc:"Disable TLS certificate verification for the cache store connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSRootCACertificate string `yaml:"tls_root_ca_certificate" env:"OCIS_CACHE_TLS_ROOT_CA_CERTIFICATE;STORAGE_SYSTEM_CACHE_TLS_ROOT_CA_CERTIFICATE" desc:"Path to the PEM-encoded root CA certificate for the cache store TLS connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` } diff --git a/services/storage-system/pkg/revaconfig/config.go b/services/storage-system/pkg/revaconfig/config.go index b7684a21505..418377b9bee 100644 --- a/services/storage-system/pkg/revaconfig/config.go +++ b/services/storage-system/pkg/revaconfig/config.go @@ -169,8 +169,11 @@ func metadataDrivers(localEndpoint string, cfg *config.Config) map[string]interf "cache_database": cfg.FileMetadataCache.Database, "cache_ttl": cfg.FileMetadataCache.TTL, "cache_disable_persistence": cfg.FileMetadataCache.DisablePersistence, - "cache_auth_username": cfg.FileMetadataCache.AuthUsername, - "cache_auth_password": cfg.FileMetadataCache.AuthPassword, + "cache_auth_username": cfg.FileMetadataCache.AuthUsername, + "cache_auth_password": cfg.FileMetadataCache.AuthPassword, + "cache_enable_tls": cfg.FileMetadataCache.EnableTLS, + "cache_tls_insecure": cfg.FileMetadataCache.TLSInsecure, + "cache_tls_root_ca_certificate": cfg.FileMetadataCache.TLSRootCACertificate, }, }, } diff --git a/services/storage-users/pkg/config/config.go b/services/storage-users/pkg/config/config.go index a1fc33b1a5c..44688ca2cc7 100644 --- a/services/storage-users/pkg/config/config.go +++ b/services/storage-users/pkg/config/config.go @@ -229,8 +229,11 @@ type FilemetadataCache struct { Database string `yaml:"database" env:"OCIS_CACHE_DATABASE" desc:"The database name the configured store should use." introductionVersion:"pre5.0"` TTL time.Duration `yaml:"ttl" env:"OCIS_CACHE_TTL;STORAGE_USERS_FILEMETADATA_CACHE_TTL" desc:"Default time to live for user info in the user info cache. Only applied when access tokens has no expiration. See the Environment Variable Types description for more details." introductionVersion:"pre5.0"` DisablePersistence bool `yaml:"disable_persistence" env:"OCIS_CACHE_DISABLE_PERSISTENCE;STORAGE_USERS_FILEMETADATA_CACHE_DISABLE_PERSISTENCE" desc:"Disables persistence of the cache. Only applies when store type 'nats-js-kv' is configured. Defaults to false." introductionVersion:"5.0"` - AuthUsername string `yaml:"username" env:"OCIS_CACHE_AUTH_USERNAME;STORAGE_USERS_FILEMETADATA_CACHE_AUTH_USERNAME" desc:"The username to authenticate with the cache store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` - AuthPassword string `yaml:"password" env:"OCIS_CACHE_AUTH_PASSWORD;STORAGE_USERS_FILEMETADATA_CACHE_AUTH_PASSWORD" desc:"The password to authenticate with the cache store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + AuthUsername string `yaml:"username" env:"OCIS_CACHE_AUTH_USERNAME;STORAGE_USERS_FILEMETADATA_CACHE_AUTH_USERNAME" desc:"The username to authenticate with the cache store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + AuthPassword string `yaml:"password" env:"OCIS_CACHE_AUTH_PASSWORD;STORAGE_USERS_FILEMETADATA_CACHE_AUTH_PASSWORD" desc:"The password to authenticate with the cache store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + EnableTLS bool `yaml:"enable_tls" env:"OCIS_CACHE_ENABLE_TLS;STORAGE_USERS_FILEMETADATA_CACHE_ENABLE_TLS" desc:"Activate TLS for the connection to the cache store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSInsecure bool `yaml:"tls_insecure" env:"OCIS_CACHE_TLS_INSECURE;STORAGE_USERS_FILEMETADATA_CACHE_TLS_INSECURE" desc:"Disable TLS certificate verification for the cache store connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSRootCACertificate string `yaml:"tls_root_ca_certificate" env:"OCIS_CACHE_TLS_ROOT_CA_CERTIFICATE;STORAGE_USERS_FILEMETADATA_CACHE_TLS_ROOT_CA_CERTIFICATE" desc:"Path to the PEM-encoded root CA certificate for the cache store TLS connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` } // IDCache holds cache config @@ -240,8 +243,11 @@ type IDCache struct { Database string `yaml:"database" env:"OCIS_CACHE_DATABASE" desc:"The database name the configured store should use." introductionVersion:"pre5.0"` TTL time.Duration `yaml:"ttl" env:"OCIS_CACHE_TTL;STORAGE_USERS_ID_CACHE_TTL" desc:"Default time to live for user info in the user info cache. Only applied when access tokens have no expiration. Defaults to 300s which is derived from the underlaying package though not explicitly set as default. See the Environment Variable Types description for more details." introductionVersion:"pre5.0"` DisablePersistence bool `yaml:"disable_persistence" env:"OCIS_CACHE_DISABLE_PERSISTENCE;STORAGE_USERS_ID_CACHE_DISABLE_PERSISTENCE" desc:"Disables persistence of the cache. Only applies when store type 'nats-js-kv' is configured. Defaults to false." introductionVersion:"5.0"` - AuthUsername string `yaml:"username" env:"OCIS_CACHE_AUTH_USERNAME;STORAGE_USERS_ID_CACHE_AUTH_USERNAME" desc:"The username to authenticate with the cache store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` - AuthPassword string `yaml:"password" env:"OCIS_CACHE_AUTH_PASSWORD;STORAGE_USERS_ID_CACHE_AUTH_PASSWORD" desc:"The password to authenticate with the cache store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + AuthUsername string `yaml:"username" env:"OCIS_CACHE_AUTH_USERNAME;STORAGE_USERS_ID_CACHE_AUTH_USERNAME" desc:"The username to authenticate with the cache store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + AuthPassword string `yaml:"password" env:"OCIS_CACHE_AUTH_PASSWORD;STORAGE_USERS_ID_CACHE_AUTH_PASSWORD" desc:"The password to authenticate with the cache store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + EnableTLS bool `yaml:"enable_tls" env:"OCIS_CACHE_ENABLE_TLS;STORAGE_USERS_ID_CACHE_ENABLE_TLS" desc:"Activate TLS for the connection to the cache store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSInsecure bool `yaml:"tls_insecure" env:"OCIS_CACHE_TLS_INSECURE;STORAGE_USERS_ID_CACHE_TLS_INSECURE" desc:"Disable TLS certificate verification for the cache store connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSRootCACertificate string `yaml:"tls_root_ca_certificate" env:"OCIS_CACHE_TLS_ROOT_CA_CERTIFICATE;STORAGE_USERS_ID_CACHE_TLS_ROOT_CA_CERTIFICATE" desc:"Path to the PEM-encoded root CA certificate for the cache store TLS connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` } // S3Driver is the storage driver configuration when using 's3' storage driver diff --git a/services/storage-users/pkg/revaconfig/drivers.go b/services/storage-users/pkg/revaconfig/drivers.go index 20e08015521..0c59be695b6 100644 --- a/services/storage-users/pkg/revaconfig/drivers.go +++ b/services/storage-users/pkg/revaconfig/drivers.go @@ -102,8 +102,11 @@ func Posix(cfg *config.Config, enableFSWatch bool) map[string]interface{} { "cache_database": cfg.IDCache.Database, "cache_ttl": cfg.IDCache.TTL, "cache_disable_persistence": cfg.IDCache.DisablePersistence, - "cache_auth_username": cfg.IDCache.AuthUsername, - "cache_auth_password": cfg.IDCache.AuthPassword, + "cache_auth_username": cfg.IDCache.AuthUsername, + "cache_auth_password": cfg.IDCache.AuthPassword, + "cache_enable_tls": cfg.IDCache.EnableTLS, + "cache_tls_insecure": cfg.IDCache.TLSInsecure, + "cache_tls_root_ca_certificate": cfg.IDCache.TLSRootCACertificate, }, "filemetadatacache": map[string]interface{}{ "cache_store": cfg.FilemetadataCache.Store, @@ -111,8 +114,11 @@ func Posix(cfg *config.Config, enableFSWatch bool) map[string]interface{} { "cache_database": cfg.FilemetadataCache.Database, "cache_ttl": cfg.FilemetadataCache.TTL, "cache_disable_persistence": cfg.FilemetadataCache.DisablePersistence, - "cache_auth_username": cfg.FilemetadataCache.AuthUsername, - "cache_auth_password": cfg.FilemetadataCache.AuthPassword, + "cache_auth_username": cfg.FilemetadataCache.AuthUsername, + "cache_auth_password": cfg.FilemetadataCache.AuthPassword, + "cache_enable_tls": cfg.FilemetadataCache.EnableTLS, + "cache_tls_insecure": cfg.FilemetadataCache.TLSInsecure, + "cache_tls_root_ca_certificate": cfg.FilemetadataCache.TLSRootCACertificate, }, "use_space_groups": cfg.Drivers.Posix.UseSpaceGroups, "watch_fs": enableFSWatch, @@ -186,8 +192,11 @@ func Ocis(cfg *config.Config) map[string]interface{} { "cache_database": cfg.FilemetadataCache.Database, "cache_ttl": cfg.FilemetadataCache.TTL, "cache_disable_persistence": cfg.FilemetadataCache.DisablePersistence, - "cache_auth_username": cfg.FilemetadataCache.AuthUsername, - "cache_auth_password": cfg.FilemetadataCache.AuthPassword, + "cache_auth_username": cfg.FilemetadataCache.AuthUsername, + "cache_auth_password": cfg.FilemetadataCache.AuthPassword, + "cache_enable_tls": cfg.FilemetadataCache.EnableTLS, + "cache_tls_insecure": cfg.FilemetadataCache.TLSInsecure, + "cache_tls_root_ca_certificate": cfg.FilemetadataCache.TLSRootCACertificate, }, "idcache": map[string]interface{}{ "cache_store": cfg.IDCache.Store, @@ -195,8 +204,11 @@ func Ocis(cfg *config.Config) map[string]interface{} { "cache_database": cfg.IDCache.Database, "cache_ttl": cfg.IDCache.TTL, "cache_disable_persistence": cfg.IDCache.DisablePersistence, - "cache_auth_username": cfg.IDCache.AuthUsername, - "cache_auth_password": cfg.IDCache.AuthPassword, + "cache_auth_username": cfg.IDCache.AuthUsername, + "cache_auth_password": cfg.IDCache.AuthPassword, + "cache_enable_tls": cfg.IDCache.EnableTLS, + "cache_tls_insecure": cfg.IDCache.TLSInsecure, + "cache_tls_root_ca_certificate": cfg.IDCache.TLSRootCACertificate, }, "events": map[string]interface{}{ "numconsumers": cfg.Events.NumConsumers, @@ -242,8 +254,11 @@ func OcisNoEvents(cfg *config.Config) map[string]interface{} { "cache_database": cfg.FilemetadataCache.Database, "cache_ttl": cfg.FilemetadataCache.TTL, "cache_disable_persistence": cfg.FilemetadataCache.DisablePersistence, - "cache_auth_username": cfg.FilemetadataCache.AuthUsername, - "cache_auth_password": cfg.FilemetadataCache.AuthPassword, + "cache_auth_username": cfg.FilemetadataCache.AuthUsername, + "cache_auth_password": cfg.FilemetadataCache.AuthPassword, + "cache_enable_tls": cfg.FilemetadataCache.EnableTLS, + "cache_tls_insecure": cfg.FilemetadataCache.TLSInsecure, + "cache_tls_root_ca_certificate": cfg.FilemetadataCache.TLSRootCACertificate, }, "idcache": map[string]interface{}{ "cache_store": cfg.IDCache.Store, @@ -251,8 +266,11 @@ func OcisNoEvents(cfg *config.Config) map[string]interface{} { "cache_database": cfg.IDCache.Database, "cache_ttl": cfg.IDCache.TTL, "cache_disable_persistence": cfg.IDCache.DisablePersistence, - "cache_auth_username": cfg.IDCache.AuthUsername, - "cache_auth_password": cfg.IDCache.AuthPassword, + "cache_auth_username": cfg.IDCache.AuthUsername, + "cache_auth_password": cfg.IDCache.AuthPassword, + "cache_enable_tls": cfg.IDCache.EnableTLS, + "cache_tls_insecure": cfg.IDCache.TLSInsecure, + "cache_tls_root_ca_certificate": cfg.IDCache.TLSRootCACertificate, }, } } @@ -312,8 +330,11 @@ func S3NG(cfg *config.Config) map[string]interface{} { "cache_database": cfg.FilemetadataCache.Database, "cache_ttl": cfg.FilemetadataCache.TTL, "cache_disable_persistence": cfg.FilemetadataCache.DisablePersistence, - "cache_auth_username": cfg.FilemetadataCache.AuthUsername, - "cache_auth_password": cfg.FilemetadataCache.AuthPassword, + "cache_auth_username": cfg.FilemetadataCache.AuthUsername, + "cache_auth_password": cfg.FilemetadataCache.AuthPassword, + "cache_enable_tls": cfg.FilemetadataCache.EnableTLS, + "cache_tls_insecure": cfg.FilemetadataCache.TLSInsecure, + "cache_tls_root_ca_certificate": cfg.FilemetadataCache.TLSRootCACertificate, }, "idcache": map[string]interface{}{ "cache_store": cfg.IDCache.Store, @@ -321,8 +342,11 @@ func S3NG(cfg *config.Config) map[string]interface{} { "cache_database": cfg.IDCache.Database, "cache_ttl": cfg.IDCache.TTL, "cache_disable_persistence": cfg.IDCache.DisablePersistence, - "cache_auth_username": cfg.IDCache.AuthUsername, - "cache_auth_password": cfg.IDCache.AuthPassword, + "cache_auth_username": cfg.IDCache.AuthUsername, + "cache_auth_password": cfg.IDCache.AuthPassword, + "cache_enable_tls": cfg.IDCache.EnableTLS, + "cache_tls_insecure": cfg.IDCache.TLSInsecure, + "cache_tls_root_ca_certificate": cfg.IDCache.TLSRootCACertificate, }, "events": map[string]interface{}{ "numconsumers": cfg.Events.NumConsumers, @@ -372,8 +396,11 @@ func S3NGNoEvents(cfg *config.Config) map[string]interface{} { "cache_database": cfg.FilemetadataCache.Database, "cache_ttl": cfg.FilemetadataCache.TTL, "cache_disable_persistence": cfg.FilemetadataCache.DisablePersistence, - "cache_auth_username": cfg.FilemetadataCache.AuthUsername, - "cache_auth_password": cfg.FilemetadataCache.AuthPassword, + "cache_auth_username": cfg.FilemetadataCache.AuthUsername, + "cache_auth_password": cfg.FilemetadataCache.AuthPassword, + "cache_enable_tls": cfg.FilemetadataCache.EnableTLS, + "cache_tls_insecure": cfg.FilemetadataCache.TLSInsecure, + "cache_tls_root_ca_certificate": cfg.FilemetadataCache.TLSRootCACertificate, }, "idcache": map[string]interface{}{ "cache_store": cfg.IDCache.Store, @@ -381,8 +408,11 @@ func S3NGNoEvents(cfg *config.Config) map[string]interface{} { "cache_database": cfg.IDCache.Database, "cache_ttl": cfg.IDCache.TTL, "cache_disable_persistence": cfg.IDCache.DisablePersistence, - "cache_auth_username": cfg.IDCache.AuthUsername, - "cache_auth_password": cfg.IDCache.AuthPassword, + "cache_auth_username": cfg.IDCache.AuthUsername, + "cache_auth_password": cfg.IDCache.AuthPassword, + "cache_enable_tls": cfg.IDCache.EnableTLS, + "cache_tls_insecure": cfg.IDCache.TLSInsecure, + "cache_tls_root_ca_certificate": cfg.IDCache.TLSRootCACertificate, }, } } diff --git a/services/userlog/pkg/command/server.go b/services/userlog/pkg/command/server.go index 615ae1e2ecc..e89054db02f 100644 --- a/services/userlog/pkg/command/server.go +++ b/services/userlog/pkg/command/server.go @@ -95,6 +95,7 @@ func Server(cfg *config.Config) *cli.Command { microstore.Database(cfg.Persistence.Database), microstore.Table(cfg.Persistence.Table), store.Authentication(cfg.Persistence.AuthUsername, cfg.Persistence.AuthPassword), + store.TLS(cfg.Persistence.EnableTLS, cfg.Persistence.TLSInsecure, cfg.Persistence.TLSRootCACertificate), ) tm, err := pool.StringToTLSMode(cfg.GRPCClientTLS.Mode) diff --git a/services/userlog/pkg/config/config.go b/services/userlog/pkg/config/config.go index 46b75f5ce27..a9857c55b5e 100644 --- a/services/userlog/pkg/config/config.go +++ b/services/userlog/pkg/config/config.go @@ -45,8 +45,11 @@ type Persistence struct { Database string `yaml:"database" env:"USERLOG_STORE_DATABASE" desc:"The database name the configured store should use." introductionVersion:"pre5.0"` Table string `yaml:"table" env:"USERLOG_STORE_TABLE" desc:"The database table the store should use." introductionVersion:"pre5.0"` TTL time.Duration `yaml:"ttl" env:"OCIS_PERSISTENT_STORE_TTL;USERLOG_STORE_TTL" desc:"Time to live for events in the store. Defaults to '336h' (2 weeks). See the Environment Variable Types description for more details." introductionVersion:"pre5.0"` - AuthUsername string `yaml:"username" env:"OCIS_PERSISTENT_STORE_AUTH_USERNAME;USERLOG_STORE_AUTH_USERNAME" desc:"The username to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` - AuthPassword string `yaml:"password" env:"OCIS_PERSISTENT_STORE_AUTH_PASSWORD;USERLOG_STORE_AUTH_PASSWORD" desc:"The password to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + AuthUsername string `yaml:"username" env:"OCIS_PERSISTENT_STORE_AUTH_USERNAME;USERLOG_STORE_AUTH_USERNAME" desc:"The username to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + AuthPassword string `yaml:"password" env:"OCIS_PERSISTENT_STORE_AUTH_PASSWORD;USERLOG_STORE_AUTH_PASSWORD" desc:"The password to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"` + EnableTLS bool `yaml:"enable_tls" env:"OCIS_PERSISTENT_STORE_ENABLE_TLS;USERLOG_STORE_ENABLE_TLS" desc:"Activate TLS for the connection to the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSInsecure bool `yaml:"tls_insecure" env:"OCIS_PERSISTENT_STORE_TLS_INSECURE;USERLOG_STORE_TLS_INSECURE" desc:"Disable TLS certificate verification for the store connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` + TLSRootCACertificate string `yaml:"tls_root_ca_certificate" env:"OCIS_PERSISTENT_STORE_TLS_ROOT_CA_CERTIFICATE;USERLOG_STORE_TLS_ROOT_CA_CERTIFICATE" desc:"Path to the PEM-encoded root CA certificate for the store TLS connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"` } // Events combines the configuration options for the event bus. diff --git a/vendor/github.com/owncloud/reva/v2/internal/grpc/services/storageprovider/storageprovider.go b/vendor/github.com/owncloud/reva/v2/internal/grpc/services/storageprovider/storageprovider.go index 2bf7025e9b8..e74357a6657 100644 --- a/vendor/github.com/owncloud/reva/v2/internal/grpc/services/storageprovider/storageprovider.go +++ b/vendor/github.com/owncloud/reva/v2/internal/grpc/services/storageprovider/storageprovider.go @@ -440,6 +440,8 @@ func (s *Service) InitiateFileUpload(ctx context.Context, req *provider.Initiate st = status.NewFailedPrecondition(ctx, err, "failed precondition") case errtypes.Locked: st = status.NewLocked(ctx, "locked") + case errtypes.IsTooEarly: + st = status.NewAborted(ctx, err, "upload in progress, retry later") default: st = status.NewInternal(ctx, "error getting upload id: "+err.Error()) } diff --git a/vendor/github.com/owncloud/reva/v2/pkg/auth/manager/publicshares/publicshares.go b/vendor/github.com/owncloud/reva/v2/pkg/auth/manager/publicshares/publicshares.go index 5c56275d78f..038c1ed5101 100644 --- a/vendor/github.com/owncloud/reva/v2/pkg/auth/manager/publicshares/publicshares.go +++ b/vendor/github.com/owncloud/reva/v2/pkg/auth/manager/publicshares/publicshares.go @@ -61,6 +61,9 @@ type config struct { StoreTable string `mapstructure:"store_table"` StoreUsername string `mapstructure:"store_username"` StorePassword string `mapstructure:"store_password"` + StoreEnableTLS bool `mapstructure:"store_enable_tls"` + StoreTLSInsecure bool `mapstructure:"store_tls_insecure"` + StoreTLSRootCACert string `mapstructure:"store_tls_root_ca_certificate"` } func parseConfig(m map[string]interface{}) (*config, error) { @@ -86,6 +89,7 @@ func New(m map[string]interface{}) (auth.Manager, error) { microstore.Database(mgr.c.StoreDatabase), microstore.Table(mgr.c.StoreTable), store.Authentication(mgr.c.StoreUsername, mgr.c.StorePassword), + store.TLS(mgr.c.StoreEnableTLS, mgr.c.StoreTLSInsecure, mgr.c.StoreTLSRootCACert), ) mgr.bfp = NewBruteForceProtection(revaStore, mgr.c.BruteForceTimeGap, mgr.c.BruteForceMaxAttempts) return mgr, nil diff --git a/vendor/github.com/owncloud/reva/v2/pkg/rhttp/datatx/utils/download/download.go b/vendor/github.com/owncloud/reva/v2/pkg/rhttp/datatx/utils/download/download.go index d4b5fbd31e9..7a0a5655fb2 100644 --- a/vendor/github.com/owncloud/reva/v2/pkg/rhttp/datatx/utils/download/download.go +++ b/vendor/github.com/owncloud/reva/v2/pkg/rhttp/datatx/utils/download/download.go @@ -275,6 +275,9 @@ func handleError(w http.ResponseWriter, log *zerolog.Logger, err error, action s case errtypes.Aborted: log.Debug().Err(err).Str("action", action).Msg("etags do not match") w.WriteHeader(http.StatusPreconditionFailed) + case errtypes.IsTooEarly: + log.Debug().Err(err).Str("action", action).Msg("resource is processing") + w.WriteHeader(http.StatusTooEarly) default: log.Error().Err(err).Str("action", action).Msg("unexpected error") w.WriteHeader(http.StatusInternalServerError) diff --git a/vendor/github.com/owncloud/reva/v2/pkg/share/manager/jsoncs3/receivedsharecache/receivedsharecache.go b/vendor/github.com/owncloud/reva/v2/pkg/share/manager/jsoncs3/receivedsharecache/receivedsharecache.go index a35869fd78b..6b7ab6681d6 100644 --- a/vendor/github.com/owncloud/reva/v2/pkg/share/manager/jsoncs3/receivedsharecache/receivedsharecache.go +++ b/vendor/github.com/owncloud/reva/v2/pkg/share/manager/jsoncs3/receivedsharecache/receivedsharecache.go @@ -22,6 +22,7 @@ import ( "context" "encoding/json" "fmt" + "math/rand/v2" "os" "path" "path/filepath" @@ -99,7 +100,7 @@ func (c *Cache) Add(ctx context.Context, userID, spaceID string, rs *collaborati defer unlock() if _, ok := c.ReceivedSpaces.Load(userID); !ok { - err := c.syncWithLock(ctx, userID) + err := c.syncIfStale(ctx, userID) if err != nil { return err } @@ -109,7 +110,7 @@ func (c *Cache) Add(ctx context.Context, userID, spaceID string, rs *collaborati defer span.End() span.SetAttributes(attribute.String("cs3.userid", userID), attribute.String("cs3.spaceid", spaceID)) - persistFunc := func() error { + err := c.retryPersist(ctx, userID, spaceID, func() error { c.initializeIfNeeded(userID, spaceID) rss, _ := c.ReceivedSpaces.Load(userID) @@ -124,44 +125,12 @@ func (c *Cache) Add(ctx context.Context, userID, spaceID string, rs *collaborati } return c.persist(ctx, userID) - } - - log := appctx.GetLogger(ctx).With(). - Str("hostname", os.Getenv("HOSTNAME")). - Str("userID", userID). - Str("spaceID", spaceID).Logger() - - var err error - for retries := 100; retries > 0; retries-- { - err = persistFunc() - switch err.(type) { - case nil: - span.SetStatus(codes.Ok, "") - return nil - case errtypes.Aborted: - log.Debug().Msg("aborted when persisting added received share: etag changed. retrying...") - // this is the expected status code from the server when the if-match etag check fails - // continue with sync below - case errtypes.PreconditionFailed: - log.Debug().Msg("precondition failed when persisting added received share: etag changed. retrying...") - // actually, this is the wrong status code and we treat it like errtypes.Aborted because of inconsistencies on the server side - // continue with sync below - case errtypes.AlreadyExists: - log.Debug().Msg("already exists when persisting added received share. retrying...") - // CS3 uses an already exists error instead of precondition failed when using an If-None-Match=* header / IfExists flag in the InitiateFileUpload call. - // Thas happens when the cache thinks there is no file. - // continue with sync below - default: - span.SetStatus(codes.Error, fmt.Sprintf("persisting added received share failed. giving up: %s", err.Error())) - log.Error().Err(err).Msg("persisting added received share failed") - return err - } - if err := c.syncWithLock(ctx, userID); err != nil { - span.RecordError(err) - span.SetStatus(codes.Error, err.Error()) - log.Error().Err(err).Msg("persisting added received share failed. giving up.") - return err - } + }) + if err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, err.Error()) + } else { + span.SetStatus(codes.Ok, "") } return err } @@ -174,7 +143,7 @@ func (c *Cache) Get(ctx context.Context, userID, spaceID, shareID string) (*Stat span.SetAttributes(attribute.String("cs3.userid", userID)) defer unlock() - err := c.syncWithLock(ctx, userID) + err := c.syncIfStale(ctx, userID) if err != nil { return nil, err } @@ -193,11 +162,11 @@ func (c *Cache) Remove(ctx context.Context, userID, spaceID, shareID string) err span.SetAttributes(attribute.String("cs3.userid", userID)) defer unlock() - ctx, span = appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "Add") + ctx, span = appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "Remove") defer span.End() span.SetAttributes(attribute.String("cs3.userid", userID), attribute.String("cs3.spaceid", spaceID)) - persistFunc := func() error { + err := c.retryPersist(ctx, userID, spaceID, func() error { c.initializeIfNeeded(userID, spaceID) rss, _ := c.ReceivedSpaces.Load(userID) @@ -211,44 +180,12 @@ func (c *Cache) Remove(ctx context.Context, userID, spaceID, shareID string) err } return c.persist(ctx, userID) - } - - log := appctx.GetLogger(ctx).With(). - Str("hostname", os.Getenv("HOSTNAME")). - Str("userID", userID). - Str("spaceID", spaceID).Logger() - - var err error - for retries := 100; retries > 0; retries-- { - err = persistFunc() - switch err.(type) { - case nil: - span.SetStatus(codes.Ok, "") - return nil - case errtypes.Aborted: - log.Debug().Msg("aborted when persisting added received share: etag changed. retrying...") - // this is the expected status code from the server when the if-match etag check fails - // continue with sync below - case errtypes.PreconditionFailed: - log.Debug().Msg("precondition failed when persisting added received share: etag changed. retrying...") - // actually, this is the wrong status code and we treat it like errtypes.Aborted because of inconsistencies on the server side - // continue with sync below - case errtypes.AlreadyExists: - log.Debug().Msg("already exists when persisting added received share. retrying...") - // CS3 uses an already exists error instead of precondition failed when using an If-None-Match=* header / IfExists flag in the InitiateFileUpload call. - // Thas happens when the cache thinks there is no file. - // continue with sync below - default: - span.SetStatus(codes.Error, fmt.Sprintf("persisting added received share failed. giving up: %s", err.Error())) - log.Error().Err(err).Msg("persisting added received share failed") - return err - } - if err := c.syncWithLock(ctx, userID); err != nil { - span.RecordError(err) - span.SetStatus(codes.Error, err.Error()) - log.Error().Err(err).Msg("persisting added received share failed. giving up.") - return err - } + }) + if err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, err.Error()) + } else { + span.SetStatus(codes.Ok, "") } return err } @@ -256,13 +193,14 @@ func (c *Cache) Remove(ctx context.Context, userID, spaceID, shareID string) err // List returns a list of received shares for a given user // The return list is guaranteed to be thread-safe func (c *Cache) List(ctx context.Context, userID string) (map[string]*Space, error) { - ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "Grab lock") - unlock := c.lockUser(userID) - span.End() + ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "List") + defer span.End() span.SetAttributes(attribute.String("cs3.userid", userID)) + + unlock := c.lockUser(userID) defer unlock() - err := c.syncWithLock(ctx, userID) + err := c.syncIfStale(ctx, userID) if err != nil { return nil, err } @@ -285,8 +223,71 @@ func (c *Cache) List(ctx context.Context, userID string) (map[string]*Space, err return spaces, nil } -func (c *Cache) syncWithLock(ctx context.Context, userID string) error { - ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "Sync") +func isSyncTransient(err error) bool { + _, isTooEarly := err.(errtypes.IsTooEarly) + _, isInternal := err.(errtypes.IsInternalError) + return isTooEarly || isInternal +} + +func (c *Cache) retryPersist(ctx context.Context, userID, spaceID string, persistFunc func() error) error { + log := appctx.GetLogger(ctx).With(). + Str("hostname", os.Getenv("HOSTNAME")). + Str("userID", userID). + Str("spaceID", spaceID).Logger() + + var err error + for attempt := 0; attempt < 20; attempt++ { + select { + case <-ctx.Done(): + return ctx.Err() + default: + } + err = persistFunc() + switch err.(type) { + case nil: + return nil + case errtypes.Aborted: + // this is the expected status code from the server when the if-match etag check fails + // continue with sync below + log.Debug().Int("attempt", attempt).Msg("CAS failed: Aborted (etag changed), retrying") + case errtypes.PreconditionFailed: + // actually, this is the wrong status code and we treat it like errtypes.Aborted because of inconsistencies on the server side + // continue with sync below + log.Debug().Int("attempt", attempt).Msg("CAS failed: PreconditionFailed (etag changed), retrying") + case errtypes.AlreadyExists: + // CS3 uses an already exists error instead of precondition failed when using an If-None-Match=* header / IfExists flag in the InitiateFileUpload call. + // Thas happens when the cache thinks there is no file. + // continue with sync below + log.Debug().Int("attempt", attempt).Msg("CAS failed: AlreadyExists (file created concurrently), retrying") + case errtypes.TooEarly: + // storage-system has an upload in progress for this node; wait for it to finish + // continue with sync below + log.Debug().Int("attempt", attempt).Msg("CAS failed: TooEarly (upload in progress), retrying") + default: + log.Error().Int("attempt", attempt).Err(err).Msg("persisting received share failed, giving up") + return err + } + timer := time.NewTimer(expBackoff(attempt)) + select { + case <-timer.C: + case <-ctx.Done(): + timer.Stop() + return ctx.Err() + } + if serr := c.syncIfStale(ctx, userID); serr != nil { + if !isSyncTransient(serr) { + log.Error().Int("attempt", attempt).Err(serr).Msg("lost update: re-read failed, aborting") + return serr + } + log.Warn().Int("attempt", attempt).Err(serr).Msg("lost update: re-read before retry") + } + } + return err +} + +// syncIfStale pulls the authoritative state from storage when the local replica is stale; caller must hold the user lock. +func (c *Cache) syncIfStale(ctx context.Context, userID string) error { + ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "SyncIfStale") defer span.End() span.SetAttributes(attribute.String("cs3.userid", userID)) @@ -307,13 +308,20 @@ func (c *Cache) syncWithLock(ctx context.Context, userID string) error { span.AddEvent("updating local cache") case errtypes.NotFound: span.SetStatus(codes.Ok, "") + if err := c.persist(ctx, userID); err != nil { + log.Warn().Err(err).Msg("failed to create empty received share cache file") + } return nil case errtypes.NotModified: span.SetStatus(codes.Ok, "") return nil default: - span.SetStatus(codes.Error, fmt.Sprintf("Failed to download the received share: %s", err.Error())) - log.Error().Err(err).Msg("Failed to download the received share") + span.SetStatus(codes.Error, err.Error()) + if isSyncTransient(err) { + log.Warn().Err(err).Msg("lost update: re-read transient error") + } else { + log.Error().Err(err).Msg("lost update: re-read failed") + } return err } @@ -374,11 +382,21 @@ func (c *Cache) persist(ctx context.Context, userID string) error { return err } rss.etag = res.Etag - span.SetStatus(codes.Ok, "") return nil } +// expBackoff returns full-jitter delay: rand(0, min(100ms, 2^attempt ms)). +// attempt: 0 1 2 3 4 5 6 7+ +// max ms: 1 2 4 8 16 32 64 100 +func expBackoff(attempt int) time.Duration { + base := time.Duration(1< 100*time.Millisecond { + base = 100 * time.Millisecond + } + return time.Duration(rand.Int64N(int64(base) + 1)) +} + func userJSONPath(userID string) string { return filepath.Join("/users", userID, "received.json") } diff --git a/vendor/github.com/owncloud/reva/v2/pkg/storage/cache/cache.go b/vendor/github.com/owncloud/reva/v2/pkg/storage/cache/cache.go index 1829ede4c01..0264d4a4fff 100644 --- a/vendor/github.com/owncloud/reva/v2/pkg/storage/cache/cache.go +++ b/vendor/github.com/owncloud/reva/v2/pkg/storage/cache/cache.go @@ -21,6 +21,7 @@ package cache import ( "context" "fmt" + "strconv" "strings" "sync" "time" @@ -51,6 +52,9 @@ type Config struct { DisablePersistence bool `mapstructure:"cache_disable_persistence"` AuthUsername string `mapstructure:"cache_auth_username"` AuthPassword string `mapstructure:"cache_auth_password"` + EnableTLS bool `mapstructure:"cache_enable_tls"` + TLSInsecure bool `mapstructure:"cache_tls_insecure"` + TLSRootCACert string `mapstructure:"cache_tls_root_ca_certificate"` } // Cache handles key value operations on caches @@ -86,13 +90,19 @@ type FileMetadataCache interface { RemoveMetadata(path string) error } +func cacheKey(cfg Config) string { + return strings.Join(append(append([]string{cfg.Store}, cfg.Nodes...), + cfg.Database, cfg.Table, + strconv.FormatBool(cfg.EnableTLS)+":"+strconv.FormatBool(cfg.TLSInsecure)+":"+cfg.TLSRootCACert), ":") +} + // GetStatCache will return an existing StatCache for the given store, nodes, database and table // If it does not exist yet it will be created, different TTLs are ignored func GetStatCache(cfg Config) StatCache { mutex.Lock() defer mutex.Unlock() - key := strings.Join(append(append([]string{cfg.Store}, cfg.Nodes...), cfg.Database, cfg.Table), ":") + key := cacheKey(cfg) if statCaches[key] == nil { statCaches[key] = NewStatCache(cfg) } @@ -105,7 +115,7 @@ func GetProviderCache(cfg Config) ProviderCache { mutex.Lock() defer mutex.Unlock() - key := strings.Join(append(append([]string{cfg.Store}, cfg.Nodes...), cfg.Database, cfg.Table), ":") + key := cacheKey(cfg) if providerCaches[key] == nil { providerCaches[key] = NewProviderCache(cfg) } @@ -118,7 +128,7 @@ func GetFileMetadataCache(cfg Config) FileMetadataCache { mutex.Lock() defer mutex.Unlock() - key := strings.Join(append(append([]string{cfg.Store}, cfg.Nodes...), cfg.Database, cfg.Table), ":") + key := cacheKey(cfg) if fileMetadataCaches[key] == nil { fileMetadataCaches[key] = NewFileMetadataCache(cfg) } @@ -202,5 +212,6 @@ func getStore(cfg Config) microstore.Store { store.Size(cfg.Size), store.DisablePersistence(cfg.DisablePersistence), store.Authentication(cfg.AuthUsername, cfg.AuthPassword), + store.TLS(cfg.EnableTLS, cfg.TLSInsecure, cfg.TLSRootCACert), ) } diff --git a/vendor/github.com/owncloud/reva/v2/pkg/storage/fs/posix/lookup/store_idcache.go b/vendor/github.com/owncloud/reva/v2/pkg/storage/fs/posix/lookup/store_idcache.go index 78c25cf6c86..d18cc798253 100644 --- a/vendor/github.com/owncloud/reva/v2/pkg/storage/fs/posix/lookup/store_idcache.go +++ b/vendor/github.com/owncloud/reva/v2/pkg/storage/fs/posix/lookup/store_idcache.go @@ -44,6 +44,7 @@ func NewStoreIDCache(o *options.Options) *StoreIDCache { microstore.Table(o.IDCache.Table), store.DisablePersistence(o.IDCache.DisablePersistence), store.Authentication(o.IDCache.AuthUsername, o.IDCache.AuthPassword), + store.TLS(o.IDCache.EnableTLS, o.IDCache.TLSInsecure, o.IDCache.TLSRootCACert), ), } } diff --git a/vendor/github.com/owncloud/reva/v2/pkg/storage/fs/posix/posix.go b/vendor/github.com/owncloud/reva/v2/pkg/storage/fs/posix/posix.go index 03cf89ce7ee..ecb68fe2cd2 100644 --- a/vendor/github.com/owncloud/reva/v2/pkg/storage/fs/posix/posix.go +++ b/vendor/github.com/owncloud/reva/v2/pkg/storage/fs/posix/posix.go @@ -112,6 +112,7 @@ func New(m map[string]interface{}, stream events.Stream, log *zerolog.Logger) (s microstore.Table(o.IDCache.Table), store.DisablePersistence(o.IDCache.DisablePersistence), store.Authentication(o.IDCache.AuthUsername, o.IDCache.AuthPassword), + store.TLS(o.IDCache.EnableTLS, o.IDCache.TLSInsecure, o.IDCache.TLSRootCACert), ), log) if err != nil { return nil, err diff --git a/vendor/github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/decomposedfs.go b/vendor/github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/decomposedfs.go index 29f6a1dcf36..16ed9ccdd5a 100644 --- a/vendor/github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/decomposedfs.go +++ b/vendor/github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/decomposedfs.go @@ -161,6 +161,7 @@ func NewDefault(m map[string]interface{}, bs tree.Blobstore, es events.Stream, l microstore.Table(o.IDCache.Table), store.DisablePersistence(o.IDCache.DisablePersistence), store.Authentication(o.IDCache.AuthUsername, o.IDCache.AuthPassword), + store.TLS(o.IDCache.EnableTLS, o.IDCache.TLSInsecure, o.IDCache.TLSRootCACert), ), log) permissionsSelector, err := pool.PermissionsSelector(o.PermissionsSVC, pool.WithTLSMode(o.PermTLSMode)) diff --git a/vendor/github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/tree/tree.go b/vendor/github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/tree/tree.go index 8c4ea410568..5a9559cf181 100644 --- a/vendor/github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/tree/tree.go +++ b/vendor/github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/tree/tree.go @@ -704,6 +704,9 @@ func (t *Tree) InitNewNode(ctx context.Context, n *node.Node, fsize uint64) (met h, err := os.OpenFile(n.InternalPath(), os.O_CREATE|os.O_EXCL, 0600) subspan.End() if err != nil { + if errors.Is(err, fs.ErrExist) { + return unlock, errtypes.AlreadyExists(n.Name) + } return unlock, err } h.Close() diff --git a/vendor/github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/upload.go b/vendor/github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/upload.go index 1f08b38636b..fac96b70632 100644 --- a/vendor/github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/upload.go +++ b/vendor/github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/upload.go @@ -135,6 +135,7 @@ func (fs *Decomposedfs) InitiateUpload(ctx context.Context, ref *provider.Refere _, span := tracer.Start(ctx, "InitiateUpload") defer span.End() log := appctx.GetLogger(ctx) + log.Debug().Interface("ref", ref).Msg("decomposedfs:InitiateUpload:start") // remember the path from the reference refpath := ref.GetPath() @@ -335,6 +336,7 @@ func (fs *Decomposedfs) InitiateUpload(ctx context.Context, ref *provider.Refere } } + log.Debug().Str("uploadid", session.ID()).Msg("decomposedfs:InitiateUpload:complete") return map[string]string{ "simple": session.ID(), "tus": session.ID(), diff --git a/vendor/github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/upload/upload.go b/vendor/github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/upload/upload.go index 1a42f20878b..ed50600f56e 100644 --- a/vendor/github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/upload/upload.go +++ b/vendor/github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/upload/upload.go @@ -114,12 +114,13 @@ func (session *OcisSession) GetReader(ctx context.Context) (io.ReadCloser, error // implements tusd.DataStore interface // returns tusd errors func (session *OcisSession) FinishUpload(ctx context.Context) error { + log := appctx.GetLogger(ctx) + log.Debug().Msg("decomposedfs:FinishUpload:start") err := session.FinishUploadDecomposed(ctx) if err != nil { // this is part of the tusd integration and we might be able to // log the error in another place - log := appctx.GetLogger(ctx) log.Error().Err(err).Msg("failed to finish upload") } @@ -140,6 +141,7 @@ func (session *OcisSession) FinishUploadDecomposed(ctx context.Context) error { ctx, span := tracer.Start(session.Context(ctx), "FinishUpload") defer span.End() log := appctx.GetLogger(ctx) + log.Debug().Str("session", session.ID()).Msg("decomposedfs:FinishUploadDecomposed:start") ctx = ctxpkg.ContextSetInitiator(ctx, session.InitiatorID()) @@ -246,6 +248,7 @@ func (session *OcisSession) FinishUploadDecomposed(ctx context.Context) error { metrics.UploadSessionsFinalized.Inc() } + log.Debug().Str("session", session.ID()).Msg("decomposedfs:FinishUploadDecomposed:complete") return session.store.tp.Propagate(ctx, n, session.SizeDiff()) } diff --git a/vendor/github.com/owncloud/reva/v2/pkg/storage/utils/metadata/cs3.go b/vendor/github.com/owncloud/reva/v2/pkg/storage/utils/metadata/cs3.go index 939b929f59f..f32f758bcbd 100644 --- a/vendor/github.com/owncloud/reva/v2/pkg/storage/utils/metadata/cs3.go +++ b/vendor/github.com/owncloud/reva/v2/pkg/storage/utils/metadata/cs3.go @@ -39,6 +39,7 @@ import ( "google.golang.org/grpc/metadata" "github.com/owncloud/reva/v2/internal/http/services/owncloud/ocdav/net" + "github.com/owncloud/reva/v2/pkg/appctx" ctxpkg "github.com/owncloud/reva/v2/pkg/ctx" "github.com/owncloud/reva/v2/pkg/errtypes" "github.com/owncloud/reva/v2/pkg/rgrpc/todo/pool" @@ -64,6 +65,7 @@ type CS3 struct { dataGatewayClient *http.Client } + // NewCS3 returns a new CS3 instance. Use an authenticated context and be sure to define SpaceRoot manually. func NewCS3(gwAddr, providerAddr string) (s *CS3) { return &CS3{ @@ -162,6 +164,8 @@ func (cs3 *CS3) SimpleUpload(ctx context.Context, uploadpath string, content []b ctx, span := tracer.Start(ctx, "SimpleUpload") defer span.End() + log := appctx.GetLogger(ctx) + log.Debug().Str("path", uploadpath).Msg("cs3.SimpleUpload.start") _, err := cs3.Upload(ctx, UploadRequest{ Path: uploadpath, Content: content, @@ -174,6 +178,9 @@ func (cs3 *CS3) Upload(ctx context.Context, req UploadRequest) (*UploadResponse, ctx, span := tracer.Start(ctx, "Upload") defer span.End() + log := appctx.GetLogger(ctx) + log.Debug().Str("path", req.Path).Msg("cs3.Upload.start") + client, err := cs3.providerClient() if err != nil { return nil, err @@ -238,6 +245,8 @@ func (cs3 *CS3) Upload(ctx context.Context, req UploadRequest) (*UploadResponse, return nil, errors.New("metadata storage doesn't support the simple upload protocol") } + log.Debug().Str("path", req.Path).Str("endpoint", endpoint).Msg("cs3.Upload.initiate_done") + httpReq, err := http.NewRequest(http.MethodPut, endpoint, bytes.NewReader(req.Content)) if err != nil { return nil, err @@ -253,6 +262,7 @@ func (cs3 *CS3) Upload(ctx context.Context, req UploadRequest) (*UploadResponse, return nil, err } defer resp.Body.Close() + log.Debug().Str("path", req.Path).Int("status", resp.StatusCode).Msg("cs3.Upload.put_done") if err := errtypes.NewErrtypeFromHTTPStatusCode(resp.StatusCode, httpReq.URL.Path); err != nil { return nil, err } @@ -260,6 +270,7 @@ func (cs3 *CS3) Upload(ctx context.Context, req UploadRequest) (*UploadResponse, if ocEtag := resp.Header.Get("OC-ETag"); ocEtag != "" { etag = ocEtag } + log.Debug().Str("path", req.Path).Str("etag", etag).Msg("cs3.Upload.complete") return &UploadResponse{ Etag: etag, FileID: resp.Header.Get("OC-Fileid"), diff --git a/vendor/github.com/owncloud/reva/v2/pkg/store/options.go b/vendor/github.com/owncloud/reva/v2/pkg/store/options.go index 75ba99c6bbe..0fa8d82453f 100644 --- a/vendor/github.com/owncloud/reva/v2/pkg/store/options.go +++ b/vendor/github.com/owncloud/reva/v2/pkg/store/options.go @@ -25,6 +25,8 @@ import ( "go-micro.dev/v4/store" ) +type tlsContextKey struct{} + type typeContextKey struct{} // Store determines the implementation: @@ -103,3 +105,21 @@ func Authentication(username, password string) store.Option { o.Context = context.WithValue(o.Context, authenticationContextKey{}, []string{username, password}) } } + +type tlsOptions struct { + enable bool + insecure bool + rootCACert string +} + +// TLS configures TLS for the nats-js and nats-js-kv store backends. +// enable activates TLS; insecure skips certificate verification (for self-signed certs); +// rootCACert is an optional path to a PEM file used to validate the server certificate. +func TLS(enable bool, insecure bool, rootCACert string) store.Option { + return func(o *store.Options) { + if o.Context == nil { + o.Context = context.Background() + } + o.Context = context.WithValue(o.Context, tlsContextKey{}, tlsOptions{enable, insecure, rootCACert}) + } +} diff --git a/vendor/github.com/owncloud/reva/v2/pkg/store/store.go b/vendor/github.com/owncloud/reva/v2/pkg/store/store.go index e405a0ed15b..474f451f4df 100644 --- a/vendor/github.com/owncloud/reva/v2/pkg/store/store.go +++ b/vendor/github.com/owncloud/reva/v2/pkg/store/store.go @@ -20,6 +20,9 @@ package store import ( "context" + "crypto/tls" + "crypto/x509" + "os" "strings" "time" @@ -66,6 +69,12 @@ func Create(opts ...microstore.Option) microstore.Store { storeType, _ := options.Context.Value(typeContextKey{}).(string) + if tlsOpts, ok := options.Context.Value(tlsContextKey{}).(tlsOptions); ok && tlsOpts.enable && + storeType != TypeNatsJS && storeType != TypeNatsJSKV { + logger.Logf(logger.WarnLevel, + "reva-store: TLS requested but store type %q does not support TLS — settings ignored", storeType) + } + switch storeType { case TypeNoop: return microstore.NewNoopStore(opts...) @@ -125,12 +134,7 @@ func Create(opts ...microstore.Option) microstore.Store { // TODO nats needs a DefaultTTL option as it does not support per Write TTL ... // FIXME nats has restrictions on the key, we cannot use slashes AFAICT // host, port, clusterid - natsOptions := nats.GetDefaultOptions() - natsOptions.Name = "TODO" // we can pass in the service name to allow identifying the client, but that requires adding a custom context option - if auth, ok := options.Context.Value(authenticationContextKey{}).([]string); ok && len(auth) == 2 { - natsOptions.User = auth[0] - natsOptions.Password = auth[1] - } + natsOptions := defaultNatsOptions(options) return natsjs.NewStore( append(opts, natsjs.NatsOptions(natsOptions), // always pass in properly initialized default nats options @@ -143,12 +147,7 @@ func Create(opts ...microstore.Option) microstore.Store { opts = append(opts, natsjskv.DefaultMemory()) } - natsOptions := nats.GetDefaultOptions() - natsOptions.Name = "TODO" // we can pass in the service name to allow identifying the client, but that requires adding a custom context option - if auth, ok := options.Context.Value(authenticationContextKey{}).([]string); ok && len(auth) == 2 { - natsOptions.User = auth[0] - natsOptions.Password = auth[1] - } + natsOptions := defaultNatsOptions(options) return natsjskv.NewStore( append(opts, natsjskv.NatsOptions(natsOptions), // always pass in properly initialized default nats options @@ -166,3 +165,58 @@ func Create(opts ...microstore.Option) microstore.Store { return microstore.NewMemoryStore(opts...) } } + +// defaultNatsOptions builds the nats.Options shared by the nats-js and +// nats-js-kv store backends. It overrides the NATS client defaults so the +// client never permanently gives up on a closed connection: the default +// MaxReconnect (60) combined with the default ReconnectWait (2s) means any +// NATS outage longer than ~2 minutes leaves the client permanently closed, +// which the store plugins then surface as "nats: connection closed" on every +// subsequent operation. Reconnecting forever, together with the connection +// state handlers, keeps the client alive and makes the transitions visible. +func defaultNatsOptions(options *microstore.Options) nats.Options { + natsOptions := nats.GetDefaultOptions() + natsOptions.Name = "reva-store" + natsOptions.MaxReconnect = -1 // reconnect forever; the default of 60 gives up after ~2 minutes + natsOptions.ReconnectWait = 5 * time.Second + if auth, ok := options.Context.Value(authenticationContextKey{}).([]string); ok && len(auth) == 2 { + natsOptions.User = auth[0] + natsOptions.Password = auth[1] + } + if tlsOpts, ok := options.Context.Value(tlsContextKey{}).(tlsOptions); ok && tlsOpts.enable { + natsOptions.TLSConfig = BuildNatsTLSConfig(tlsOpts.insecure, tlsOpts.rootCACert) + natsOptions.Secure = true + } + natsOptions.DisconnectedErrCB = func(_ *nats.Conn, err error) { + logger.Logf(logger.WarnLevel, "reva-store: nats connection disconnected: %v", err) + } + natsOptions.ReconnectedCB = func(c *nats.Conn) { + logger.Logf(logger.InfoLevel, "reva-store: nats connection reconnected to %s", c.ConnectedUrl()) + } + natsOptions.ClosedCB = func(_ *nats.Conn) { + logger.Logf(logger.ErrorLevel, "reva-store: nats connection closed") + } + return natsOptions +} + +// BuildNatsTLSConfig constructs a tls.Config for NATS client connections. +// insecure skips certificate verification; rootCACert is an optional path to a +// PEM file whose CA is used to validate the server certificate. +func BuildNatsTLSConfig(insecure bool, rootCACert string) *tls.Config { + tlsConf := &tls.Config{MinVersion: tls.VersionTLS12, InsecureSkipVerify: insecure} //nolint:gosec + if rootCACert != "" { + b, err := os.ReadFile(rootCACert) + if err != nil { + logger.Logf(logger.WarnLevel, "reva-store: failed to read TLS root CA cert %q: %v", rootCACert, err) + } else { + pool := x509.NewCertPool() + if pool.AppendCertsFromPEM(b) { + tlsConf.RootCAs = pool + tlsConf.InsecureSkipVerify = false + } else { + logger.Logf(logger.WarnLevel, "reva-store: no valid PEM certificates found in %q", rootCACert) + } + } + } + return tlsConf +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 7fb514c9d4c..90725389ae9 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1325,7 +1325,7 @@ github.com/orcaman/concurrent-map # github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245 ## explicit; go 1.18 github.com/owncloud/libre-graph-api-go -# github.com/owncloud/reva/v2 v2.0.0-20260803145357-624c8ac70757 +# github.com/owncloud/reva/v2 v2.0.0-20260813081421-ca7fa1632ddf ## explicit; go 1.25.7 github.com/owncloud/reva/v2/cmd/revad/internal/grace github.com/owncloud/reva/v2/cmd/revad/runtime