Files

395 lines
11 KiB
Go
Raw Permalink Normal View History

2022-03-08 17:35:55 +01:00
package defaults
import (
"os"
"path"
"path/filepath"
2022-03-08 17:35:55 +01:00
"strings"
2023-03-22 15:21:57 +01:00
"time"
2022-05-04 14:49:59 +02:00
"github.com/owncloud/ocis/v2/ocis-pkg/config/defaults"
2022-10-12 15:48:54 +02:00
"github.com/owncloud/ocis/v2/ocis-pkg/shared"
2023-03-03 00:39:00 +01:00
"github.com/owncloud/ocis/v2/ocis-pkg/structs"
2022-06-20 16:49:06 +02:00
"github.com/owncloud/ocis/v2/services/proxy/pkg/config"
)
2023-03-06 17:38:47 +01:00
// FullDefaultConfig returns a fully initialized default configuration
func FullDefaultConfig() *config.Config {
cfg := DefaultConfig()
EnsureDefaults(cfg)
Sanitize(cfg)
return cfg
}
2023-03-06 17:38:47 +01:00
// DefaultConfig returns a basic default configuration
2022-03-08 17:35:55 +01:00
func DefaultConfig() *config.Config {
return &config.Config{
Debug: config.Debug{
2022-01-03 08:15:46 +01:00
Addr: "127.0.0.1:9205",
Token: "",
},
2022-03-08 17:35:55 +01:00
HTTP: config.HTTP{
Addr: "0.0.0.0:9200",
Root: "/",
Namespace: "com.owncloud.web",
TLSCert: path.Join(defaults.BaseDataPath(), "proxy", "server.crt"),
TLSKey: path.Join(defaults.BaseDataPath(), "proxy", "server.key"),
TLS: true,
},
2022-03-08 17:35:55 +01:00
Service: config.Service{
Name: "proxy",
},
2022-03-08 17:35:55 +01:00
OIDC: config.OIDC{
2022-09-16 12:36:45 +02:00
Issuer: "https://localhost:9200",
AccessTokenVerifyMethod: config.AccessTokenVerificationJWT,
2023-08-23 10:36:05 +02:00
SkipUserInfo: false,
2023-03-22 15:21:57 +01:00
UserinfoCache: &config.Cache{
2023-12-13 12:47:59 +01:00
Store: "memory",
2023-12-07 11:59:03 +01:00
Nodes: []string{"127.0.0.1:9233"},
2023-11-23 12:34:01 +01:00
Database: "cache-userinfo",
2023-03-22 15:21:57 +01:00
TTL: time.Second * 10,
},
JWKS: config.JWKS{
RefreshInterval: 60, // minutes
RefreshRateLimit: 60, // seconds
RefreshTimeout: 10, // seconds
RefreshUnknownKID: true,
},
},
PolicySelector: nil,
2023-03-15 18:59:25 +01:00
RoleAssignment: config.RoleAssignment{
Driver: "default",
// this default is only relevant when Driver is set to "oidc"
OIDCRoleMapper: config.OIDCRoleMapper{
RoleClaim: "roles",
RolesMap: []config.RoleMapping{
2023-08-23 10:36:05 +02:00
{RoleName: "admin", ClaimValue: "ocisAdmin"},
{RoleName: "spaceadmin", ClaimValue: "ocisSpaceAdmin"},
{RoleName: "user", ClaimValue: "ocisUser"},
{RoleName: "user-light", ClaimValue: "ocisGuest"},
2023-03-15 18:59:25 +01:00
},
},
},
Reva: shared.DefaultRevaConfig(),
2022-03-08 17:35:55 +01:00
PreSignedURL: config.PreSignedURL{
AllowedHTTPMethods: []string{"GET"},
Enabled: true,
SigningKeys: &config.SigningKeys{
Store: "nats-js-kv", // signing keys are written by ocs, so we cannot use memory. It is not shared.
Nodes: []string{"127.0.0.1:9233"},
TTL: time.Hour * 12,
DisablePersistence: true,
},
},
2022-03-09 11:42:51 +01:00
AccountBackend: "cs3",
UserOIDCClaim: "preferred_username",
UserCS3Claim: "username",
AutoprovisionAccounts: false,
AutoProvisionClaims: config.AutoProvisionClaims{
Username: "preferred_username",
Email: "email",
DisplayName: "name",
Groups: "",
},
EnableBasicAuth: false,
InsecureBackends: false,
CSPConfigFileLocation: "",
2024-06-25 10:59:00 +02:00
Events: config.Events{
Endpoint: "127.0.0.1:9233",
Cluster: "ocis-cluster",
EnableTLS: false,
},
2025-09-17 12:03:10 +02:00
MultiFactorAuthentication: config.MFAConfig{
AuthLevelNames: []string{"advanced"},
SessionDuration: 3600,
2025-09-17 12:03:10 +02:00
},
}
}
2023-03-06 17:38:47 +01:00
// DefaultPolicies returns the default proxy policies.
2022-03-08 17:35:55 +01:00
func DefaultPolicies() []config.Policy {
return []config.Policy{
{
Name: "ocis",
2022-03-08 17:35:55 +01:00
Routes: []config.Route{
{
2022-08-25 23:29:47 +02:00
Endpoint: "/",
Service: "com.owncloud.web.web",
2022-08-25 23:29:47 +02:00
Unprotected: true,
},
2024-08-14 21:53:55 +02:00
{
Endpoint: "/.well-known/ocm",
Service: "com.owncloud.web.ocm",
Unprotected: true,
},
{
2023-02-13 11:05:20 +01:00
Endpoint: "/.well-known/webfinger",
Service: "com.owncloud.web.webfinger",
Unprotected: true,
},
{
Endpoint: "/.well-known/openid-configuration",
Service: "com.owncloud.web.idp",
2022-08-25 23:29:47 +02:00
Unprotected: true,
},
2023-02-09 16:18:44 +01:00
{
Endpoint: "/branding/logo",
Service: "com.owncloud.web.web",
},
{
2022-08-25 23:29:47 +02:00
Endpoint: "/konnect/",
Service: "com.owncloud.web.idp",
2022-08-25 23:29:47 +02:00
Unprotected: true,
},
{
2022-08-25 23:29:47 +02:00
Endpoint: "/signin/",
Service: "com.owncloud.web.idp",
2022-08-25 23:29:47 +02:00
Unprotected: true,
},
{
Endpoint: "/archiver",
Service: "com.owncloud.web.frontend",
},
2023-08-18 11:05:03 +02:00
{
// reroute oc10 notifications endpoint to userlog service
Endpoint: "/ocs/v2.php/apps/notifications/api/v1/notifications/sse",
Service: "com.owncloud.sse.sse",
},
2023-02-08 12:38:04 +01:00
{
// reroute oc10 notifications endpoint to userlog service
Endpoint: "/ocs/v2.php/apps/notifications/api/v1/notifications",
Service: "com.owncloud.web.userlog",
2023-02-08 12:38:04 +01:00
},
{
2022-03-08 17:35:55 +01:00
Type: config.RegexRoute,
2022-05-10 12:44:52 +02:00
Endpoint: "/ocs/v[12].php/cloud/user/signing-key", // only `user/signing-key` is left in ocis-ocs
Service: "com.owncloud.web.ocs",
},
{
Type: config.RegexRoute,
Endpoint: "/ocs/v[12].php/config",
Service: "com.owncloud.web.frontend",
Unprotected: true,
},
{
Endpoint: "/sciencemesh/",
Service: "com.owncloud.web.ocm",
},
{
Endpoint: "/ocm/",
Service: "com.owncloud.web.ocm",
},
{
Endpoint: "/ocs/",
Service: "com.owncloud.web.frontend",
},
{
2022-03-08 17:35:55 +01:00
Type: config.QueryRoute,
Endpoint: "/remote.php/?preview=1",
Service: "com.owncloud.web.webdav",
},
2025-09-24 10:32:37 +02:00
{
Type: config.QueryRoute,
Endpoint: "/?preview=1",
Service: "com.owncloud.web.webdav",
},
// TODO the actual REPORT goes to /dav/files/{username}, which is user specific ... how would this work in a spaces world?
// TODO what paths are returned? the href contains the full path so it should be possible to return urls from other spaces?
// TODO or we allow a REPORT on /dav/spaces to search all spaces and /dav/space/{spaceid} to search a specific space
// send webdav REPORT requests to search service
{
2023-07-31 15:11:03 +02:00
Type: config.RegexRoute,
Method: "REPORT",
2023-07-31 15:11:03 +02:00
Endpoint: "(/remote.php)?/(web)?dav",
Service: "com.owncloud.web.webdav",
2022-09-27 10:38:15 +02:00
},
{
Type: config.QueryRoute,
Endpoint: "/dav/?preview=1",
Service: "com.owncloud.web.webdav",
},
{
Type: config.QueryRoute,
Endpoint: "/webdav/?preview=1",
Service: "com.owncloud.web.webdav",
},
{
Endpoint: "/remote.php/",
2022-05-06 15:19:29 +02:00
Service: "com.owncloud.web.ocdav",
},
{
Endpoint: "/dav/",
2022-05-06 15:19:29 +02:00
Service: "com.owncloud.web.ocdav",
},
{
Endpoint: "/webdav/",
2022-05-06 15:19:29 +02:00
Service: "com.owncloud.web.ocdav",
},
{
Endpoint: "/webdav",
Service: "com.owncloud.web.ocdav",
},
2022-05-16 13:43:21 +02:00
{
Endpoint: "/status",
Service: "com.owncloud.web.ocdav",
Unprotected: true,
2022-05-16 13:43:21 +02:00
},
{
Endpoint: "/status.php",
Service: "com.owncloud.web.ocdav",
Unprotected: true,
},
{
Endpoint: "/index.php/",
2022-05-06 15:19:29 +02:00
Service: "com.owncloud.web.ocdav",
},
{
Endpoint: "/apps/",
2022-05-06 15:19:29 +02:00
Service: "com.owncloud.web.ocdav",
},
{
Endpoint: "/data",
Service: "com.owncloud.web.frontend",
Unprotected: true,
},
{
2022-08-30 16:26:59 +02:00
Endpoint: "/app/list",
Service: "com.owncloud.web.frontend",
2022-08-30 16:26:59 +02:00
Unprotected: true,
},
{
Endpoint: "/app/", // /app or /apps? ocdav only handles /apps
Service: "com.owncloud.web.frontend",
},
2024-06-11 16:42:52 +02:00
{
Endpoint: "/graph/v1beta1/extensions/org.libregraph/activities",
2024-06-11 16:42:52 +02:00
Service: "com.owncloud.web.activitylog",
},
2023-03-01 13:24:28 +00:00
{
Endpoint: "/graph/v1.0/invitations",
Service: "com.owncloud.web.invitations",
2023-03-01 13:24:28 +00:00
},
{
Endpoint: "/graph/",
Service: "com.owncloud.web.graph",
2026-05-15 16:53:05 +02:00
},
{
Endpoint: "/vault/graph/v1beta1/extensions/org.libregraph/activities",
Service: "com.owncloud.web.activitylog",
},
{
Endpoint: "/vault/graph/v1.0/invitations",
Service: "com.owncloud.web.invitations",
},
2026-05-15 16:53:05 +02:00
{
Endpoint: "/vault/graph/",
Service: "com.owncloud.web.graph",
},
{
Endpoint: "/api/v0/settings",
Service: "com.owncloud.web.settings",
},
{
Endpoint: "/auth-app/tokens",
2024-08-07 10:47:20 +02:00
Service: "com.owncloud.web.auth-app",
},
},
},
}
}
2022-03-08 17:35:55 +01:00
2022-09-27 10:38:15 +02:00
// EnsureDefaults adds default values to the configuration if they are not set yet
2022-03-08 17:35:55 +01:00
func EnsureDefaults(cfg *config.Config) {
2022-07-14 16:24:06 +02:00
// provide with defaults for shared logging, since we need a valid destination address for "envdecode".
2022-03-08 17:35:55 +01:00
if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil {
cfg.Log = &config.Log{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Log == nil {
cfg.Log = &config.Log{}
}
2022-07-14 16:24:06 +02:00
// provide with defaults for shared tracing, since we need a valid destination address for "envdecode".
2022-03-08 17:35:55 +01:00
if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil {
cfg.Tracing = &config.Tracing{
Enabled: cfg.Commons.Tracing.Enabled,
Type: cfg.Commons.Tracing.Type,
Endpoint: cfg.Commons.Tracing.Endpoint,
Collector: cfg.Commons.Tracing.Collector,
}
} else if cfg.Tracing == nil {
cfg.Tracing = &config.Tracing{}
}
2023-03-22 15:21:57 +01:00
if cfg.OIDC.UserinfoCache == nil && cfg.Commons != nil && cfg.Commons.Cache != nil {
cfg.OIDC.UserinfoCache = &config.Cache{
Store: cfg.Commons.Cache.Store,
Nodes: cfg.Commons.Cache.Nodes,
}
} else if cfg.OIDC.UserinfoCache == nil {
cfg.OIDC.UserinfoCache = &config.Cache{}
}
2022-04-26 10:18:12 +02:00
if cfg.MachineAuthAPIKey == "" && cfg.Commons != nil && cfg.Commons.MachineAuthAPIKey != "" {
cfg.MachineAuthAPIKey = cfg.Commons.MachineAuthAPIKey
}
2023-03-03 00:39:00 +01:00
if cfg.Reva == nil && cfg.Commons != nil {
cfg.Reva = structs.CopyOrZeroValue(cfg.Commons.Reva)
}
2023-03-03 00:39:00 +01:00
if cfg.GRPCClientTLS == nil && cfg.Commons != nil {
cfg.GRPCClientTLS = structs.CopyOrZeroValue(cfg.Commons.GRPCClientTLS)
}
if cfg.GRPCClientOptions == nil && cfg.Commons != nil {
cfg.GRPCClientOptions = structs.CopyOrZeroValue(cfg.Commons.GRPCClientOptions)
}
2022-03-08 17:35:55 +01:00
}
2022-09-27 10:38:15 +02:00
// Sanitize sanitizes the configuration
2022-03-08 17:35:55 +01:00
func Sanitize(cfg *config.Config) {
if cfg.Policies == nil {
2023-11-16 15:41:27 +01:00
cfg.Policies = mergePolicies(DefaultPolicies(), cfg.AdditionalPolicies)
2022-03-08 17:35:55 +01:00
}
if cfg.PolicySelector == nil {
cfg.PolicySelector = &config.PolicySelector{
Static: &config.StaticSelectorConf{
Policy: "ocis",
},
}
}
2022-03-08 17:35:55 +01:00
if cfg.HTTP.Root != "/" {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
}
// if the CSP config file path is not set, we check if the default file exists and set it if it does
if cfg.CSPConfigFileLocation == "" {
defaultCSPConfigFilePath := filepath.Join(defaults.BaseDataPath(), "proxy", "csp.yaml")
if _, err := os.Stat(defaultCSPConfigFilePath); err == nil {
cfg.CSPConfigFileLocation = defaultCSPConfigFilePath
}
}
2022-03-08 17:35:55 +01:00
}
2023-11-16 15:41:27 +01:00
func mergePolicies(policies []config.Policy, additionalPolicies []config.Policy) []config.Policy {
for _, p := range additionalPolicies {
found := false
for i, po := range policies {
if po.Name == p.Name {
po.Routes = append(po.Routes, p.Routes...)
policies[i] = po
found = true
break
}
}
if !found {
policies = append(policies, p)
}
}
return policies
}