mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-11-26 18:16:47 -05:00
chi's ClientIPFrom* header middlewares trust the header from anyone who can
reach us. Pick the middleware per request instead: headers are only read
when the peer is a trusted proxy, everyone else gets their network address.
- PROXY_TRUSTED_PROXIES, defaults to loopback and private ranges
- PROXY_CLIENT_IP_HEADER, defaults to X-Forwarded-For, e.g. CF-Connecting-IP
- drop the strategy setting and xff_trusted_hops
- pass the client address to the services in X-Forwarded-For instead of
X-Client-Ip, reva reads it e.g. for OCM
- same check in collaboration, traefik routes to it directly
- OC_TRUSTED_PROXIES and OC_CLIENT_IP_HEADER set both services
- the other services only drop RealIP, none of them reads the address
Taken from #3864 and https://github.com/opencloud-eu/opencloud/pull/3464#issuecomment-6494799883
# Conflicts:
# services/proxy/README.md
68 lines
2.2 KiB
Go
68 lines
2.2 KiB
Go
package parser
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"net/url"
|
|
|
|
occfg "github.com/opencloud-eu/opencloud/pkg/config"
|
|
ocdefaults "github.com/opencloud-eu/opencloud/pkg/config/defaults"
|
|
"github.com/opencloud-eu/opencloud/pkg/config/envdecode"
|
|
"github.com/opencloud-eu/opencloud/pkg/middleware"
|
|
"github.com/opencloud-eu/opencloud/pkg/shared"
|
|
"github.com/opencloud-eu/opencloud/services/collaboration/pkg/config"
|
|
"github.com/opencloud-eu/opencloud/services/collaboration/pkg/config/defaults"
|
|
)
|
|
|
|
// ParseConfig loads configuration from known paths.
|
|
func ParseConfig(cfg *config.Config) error {
|
|
err := occfg.BindSourcesToStructs(cfg.Service.Name, cfg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
defaults.EnsureDefaults(cfg)
|
|
|
|
// load all env variables relevant to the config in the current context.
|
|
if err := envdecode.Decode(cfg); err != nil {
|
|
// no environment variable set for this config is an expected "error"
|
|
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
|
|
return err
|
|
}
|
|
}
|
|
|
|
defaults.Sanitize(cfg)
|
|
|
|
return Validate(cfg)
|
|
}
|
|
|
|
// Validate validates the configuration
|
|
func Validate(cfg *config.Config) error {
|
|
if cfg.TokenManager.JWTSecret == "" {
|
|
return shared.MissingJWTTokenError(cfg.Service.Name)
|
|
}
|
|
if cfg.Wopi.Secret == "" {
|
|
return shared.MissingWOPISecretError(cfg.Service.Name)
|
|
}
|
|
if _, err := middleware.ParseTrustedProxies(cfg.HTTP.TrustedProxies); err != nil {
|
|
return fmt.Errorf("invalid COLLABORATION_HTTP_TRUSTED_PROXIES in service %s: %w", cfg.Service.Name, err)
|
|
}
|
|
url, err := url.Parse(cfg.Wopi.WopiSrc)
|
|
if err != nil {
|
|
return fmt.Errorf("The WOPI Src has not been set properly in your config for %s. "+
|
|
"Make sure your %s config contains the proper values "+
|
|
"(e.g. by running opencloud init or setting it manually in "+
|
|
"the config/corresponding environment variable): %s",
|
|
cfg.Service.Name, ocdefaults.BaseConfigPath(), err.Error())
|
|
}
|
|
if url.Path != "" {
|
|
return fmt.Errorf("The WOPI Src must not contain a path in your config for %s. "+
|
|
"Make sure your %s config contains the proper values "+
|
|
"(e.g. by running opencloud init or setting it manually in "+
|
|
"the config/corresponding environment variable)",
|
|
cfg.Service.Name, ocdefaults.BaseConfigPath())
|
|
}
|
|
|
|
return nil
|
|
}
|