Files
opencloud/services/collaboration/pkg/config/defaults/defaultconfig.go
T
micbar 4e7ebd4f8c fix: only trust forwarding headers from trusted reverse proxies
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
2026-10-30 15:15:22 +01:00

104 lines
2.7 KiB
Go

package defaults
import (
"path/filepath"
"time"
"github.com/opencloud-eu/opencloud/pkg/config/defaults"
"github.com/opencloud-eu/opencloud/pkg/middleware"
"github.com/opencloud-eu/opencloud/pkg/shared"
"github.com/opencloud-eu/opencloud/pkg/structs"
"github.com/opencloud-eu/opencloud/services/collaboration/pkg/config"
)
// FullDefaultConfig returns a fully initialized default configuration
func FullDefaultConfig() *config.Config {
cfg := DefaultConfig()
EnsureDefaults(cfg)
Sanitize(cfg)
return cfg
}
// DefaultConfig returns a basic default configuration
func DefaultConfig() *config.Config {
return &config.Config{
Service: config.Service{
Name: "collaboration",
},
App: config.App{
Name: "Collabora",
Description: "Open office documents with Collabora",
Icon: "image-edit",
Addr: "https://127.0.0.1:9980",
Insecure: false,
ProofKeys: config.ProofKeys{
// they'll be enabled by default
Duration: "12h",
},
},
Font: config.Font{
AssetPath: filepath.Join(defaults.BaseDataPath(), "collaboration/fonts"),
PreviewText: "OpenCloud",
},
Store: config.Store{
Store: "nats-js-kv",
Nodes: []string{"127.0.0.1:9233"},
Database: "collaboration",
Table: "",
TTL: 30 * time.Minute,
},
GRPC: config.GRPC{
Addr: "127.0.0.1:9301",
Protocol: "tcp",
Namespace: "eu.opencloud.api",
},
HTTP: config.HTTP{
Addr: "127.0.0.1:9300",
Namespace: "eu.opencloud.web",
TrustedProxies: middleware.DefaultTrustedProxies(),
ClientIPHeader: middleware.DefaultClientIPHeader,
},
Debug: config.Debug{
Addr: "127.0.0.1:9304",
Token: "",
Pprof: false,
Zpages: false,
},
Wopi: config.Wopi{
WopiSrc: "https://localhost:9300",
},
CS3Api: config.CS3Api{
Gateway: config.Gateway{
Name: shared.DefaultRevaConfig().Address,
},
DataGateway: config.DataGateway{
Insecure: false,
},
APPRegistrationInterval: 30 * time.Second,
},
}
}
// EnsureDefaults adds default values to the configuration if they are not set yet
func EnsureDefaults(cfg *config.Config) {
if cfg.LogLevel == "" {
cfg.LogLevel = "error"
}
if cfg.TokenManager == nil && cfg.Commons != nil && cfg.Commons.TokenManager != nil {
cfg.TokenManager = &config.TokenManager{
JWTSecret: cfg.Commons.TokenManager.JWTSecret,
}
} else if cfg.TokenManager == nil {
cfg.TokenManager = &config.TokenManager{}
}
if cfg.CS3Api.GRPCClientTLS == nil && cfg.Commons != nil {
cfg.CS3Api.GRPCClientTLS = structs.CopyOrZeroValue(cfg.Commons.GRPCClientTLS)
}
}
// Sanitize sanitized the configuration
func Sanitize(cfg *config.Config) {
// sanitize config
}