2022-03-08 17:35:55 +01:00
|
|
|
package defaults
|
2021-12-17 11:47:18 +01:00
|
|
|
|
|
|
|
|
import (
|
2024-09-23 16:12:48 +02:00
|
|
|
"os"
|
2021-12-17 11:47:18 +01:00
|
|
|
"path"
|
2024-09-23 16:12:48 +02:00
|
|
|
"path/filepath"
|
2022-03-08 17:35:55 +01:00
|
|
|
"strings"
|
2023-03-22 15:21:57 +01:00
|
|
|
"time"
|
2021-12-17 11:47:18 +01:00
|
|
|
|
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"
|
2021-12-17 11:47:18 +01:00
|
|
|
)
|
|
|
|
|
|
2023-03-06 17:38:47 +01:00
|
|
|
// FullDefaultConfig returns a fully initialized default configuration
|
2022-04-28 17:38:07 +02:00
|
|
|
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",
|
2021-12-17 11:47:18 +01:00
|
|
|
Token: "",
|
|
|
|
|
},
|
2022-03-08 17:35:55 +01:00
|
|
|
HTTP: config.HTTP{
|
2021-12-17 11:47:18 +01:00
|
|
|
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{
|
2021-12-17 11:47:18 +01:00
|
|
|
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",
|
|
|
|
|
|
2022-07-20 17:45:43 +02:00
|
|
|
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,
|
2021-12-17 11:47:18 +01:00
|
|
|
},
|
2022-07-22 15:01:25 +02:00
|
|
|
JWKS: config.JWKS{
|
|
|
|
|
RefreshInterval: 60, // minutes
|
|
|
|
|
RefreshRateLimit: 60, // seconds
|
|
|
|
|
RefreshTimeout: 10, // seconds
|
|
|
|
|
RefreshUnknownKID: true,
|
|
|
|
|
},
|
2021-12-17 11:47:18 +01:00
|
|
|
},
|
|
|
|
|
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",
|
2023-04-13 13:40:14 +02:00
|
|
|
RolesMap: []config.RoleMapping{
|
2023-08-23 10:36:05 +02:00
|
|
|
{RoleName: "admin", ClaimValue: "ocisAdmin"},
|
|
|
|
|
{RoleName: "spaceadmin", ClaimValue: "ocisSpaceAdmin"},
|
|
|
|
|
{RoleName: "user", ClaimValue: "ocisUser"},
|
2024-02-27 15:53:42 +01:00
|
|
|
{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{
|
2021-12-17 11:47:18 +01:00
|
|
|
AllowedHTTPMethods: []string{"GET"},
|
|
|
|
|
Enabled: true,
|
2024-02-26 16:08:03 +01:00
|
|
|
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,
|
|
|
|
|
},
|
2021-12-17 11:47:18 +01:00
|
|
|
},
|
2022-03-09 11:42:51 +01:00
|
|
|
AccountBackend: "cs3",
|
2023-06-01 08:23:48 +02:00
|
|
|
UserOIDCClaim: "preferred_username",
|
|
|
|
|
UserCS3Claim: "username",
|
2021-12-17 11:47:18 +01:00
|
|
|
AutoprovisionAccounts: false,
|
2024-04-24 15:46:46 +02:00
|
|
|
AutoProvisionClaims: config.AutoProvisionClaims{
|
|
|
|
|
Username: "preferred_username",
|
|
|
|
|
Email: "email",
|
|
|
|
|
DisplayName: "name",
|
2026-07-09 10:21:56 +02:00
|
|
|
Groups: "",
|
2024-04-24 15:46:46 +02:00
|
|
|
},
|
2021-12-17 11:47:18 +01:00
|
|
|
EnableBasicAuth: false,
|
|
|
|
|
InsecureBackends: false,
|
2024-04-26 09:10:35 +02:00
|
|
|
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{
|
2026-05-21 15:32:26 +02:00
|
|
|
AuthLevelNames: []string{"advanced"},
|
|
|
|
|
SessionDuration: 3600,
|
2025-09-17 12:03:10 +02:00
|
|
|
},
|
2021-12-17 11:47:18 +01: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{
|
2021-12-17 11:47:18 +01:00
|
|
|
{
|
|
|
|
|
Name: "ocis",
|
2022-03-08 17:35:55 +01:00
|
|
|
Routes: []config.Route{
|
2021-12-17 11:47:18 +01:00
|
|
|
{
|
2022-08-25 23:29:47 +02:00
|
|
|
Endpoint: "/",
|
2022-10-27 16:01:20 +02:00
|
|
|
Service: "com.owncloud.web.web",
|
2022-08-25 23:29:47 +02:00
|
|
|
Unprotected: true,
|
2021-12-17 11:47:18 +01:00
|
|
|
},
|
2024-08-14 21:53:55 +02:00
|
|
|
{
|
|
|
|
|
Endpoint: "/.well-known/ocm",
|
|
|
|
|
Service: "com.owncloud.web.ocm",
|
|
|
|
|
Unprotected: true,
|
|
|
|
|
},
|
2021-12-17 11:47:18 +01:00
|
|
|
{
|
2023-02-13 11:05:20 +01:00
|
|
|
Endpoint: "/.well-known/webfinger",
|
|
|
|
|
Service: "com.owncloud.web.webfinger",
|
|
|
|
|
Unprotected: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Endpoint: "/.well-known/openid-configuration",
|
2022-10-27 16:01:20 +02:00
|
|
|
Service: "com.owncloud.web.idp",
|
2022-08-25 23:29:47 +02:00
|
|
|
Unprotected: true,
|
2021-12-17 11:47:18 +01:00
|
|
|
},
|
2023-02-09 16:18:44 +01:00
|
|
|
{
|
|
|
|
|
Endpoint: "/branding/logo",
|
|
|
|
|
Service: "com.owncloud.web.web",
|
|
|
|
|
},
|
2021-12-17 11:47:18 +01:00
|
|
|
{
|
2022-08-25 23:29:47 +02:00
|
|
|
Endpoint: "/konnect/",
|
2022-10-27 16:01:20 +02:00
|
|
|
Service: "com.owncloud.web.idp",
|
2022-08-25 23:29:47 +02:00
|
|
|
Unprotected: true,
|
2021-12-17 11:47:18 +01:00
|
|
|
},
|
|
|
|
|
{
|
2022-08-25 23:29:47 +02:00
|
|
|
Endpoint: "/signin/",
|
2022-10-27 16:01:20 +02:00
|
|
|
Service: "com.owncloud.web.idp",
|
2022-08-25 23:29:47 +02:00
|
|
|
Unprotected: true,
|
2021-12-17 11:47:18 +01:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Endpoint: "/archiver",
|
2022-10-27 16:01:20 +02:00
|
|
|
Service: "com.owncloud.web.frontend",
|
2021-12-17 11:47:18 +01:00
|
|
|
},
|
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",
|
2024-05-13 17:04:01 +02:00
|
|
|
Service: "com.owncloud.web.userlog",
|
2023-02-08 12:38:04 +01:00
|
|
|
},
|
2021-12-17 11:47:18 +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
|
2022-10-27 16:01:20 +02:00
|
|
|
Service: "com.owncloud.web.ocs",
|
2021-12-17 11:47:18 +01:00
|
|
|
},
|
2022-08-30 12:30:12 +02:00
|
|
|
{
|
|
|
|
|
Type: config.RegexRoute,
|
|
|
|
|
Endpoint: "/ocs/v[12].php/config",
|
2022-10-27 16:01:20 +02:00
|
|
|
Service: "com.owncloud.web.frontend",
|
2022-08-30 12:30:12 +02:00
|
|
|
Unprotected: true,
|
|
|
|
|
},
|
2023-10-13 10:04:04 +02:00
|
|
|
{
|
|
|
|
|
Endpoint: "/sciencemesh/",
|
|
|
|
|
Service: "com.owncloud.web.ocm",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Endpoint: "/ocm/",
|
|
|
|
|
Service: "com.owncloud.web.ocm",
|
|
|
|
|
},
|
2021-12-17 11:47:18 +01:00
|
|
|
{
|
|
|
|
|
Endpoint: "/ocs/",
|
2022-10-27 16:01:20 +02:00
|
|
|
Service: "com.owncloud.web.frontend",
|
2021-12-17 11:47:18 +01:00
|
|
|
},
|
|
|
|
|
{
|
2022-03-08 17:35:55 +01:00
|
|
|
Type: config.QueryRoute,
|
2021-12-17 11:47:18 +01:00
|
|
|
Endpoint: "/remote.php/?preview=1",
|
2022-10-27 16:01:20 +02:00
|
|
|
Service: "com.owncloud.web.webdav",
|
2021-12-17 11:47:18 +01:00
|
|
|
},
|
2025-09-24 10:32:37 +02:00
|
|
|
{
|
|
|
|
|
Type: config.QueryRoute,
|
|
|
|
|
Endpoint: "/?preview=1",
|
|
|
|
|
Service: "com.owncloud.web.webdav",
|
|
|
|
|
},
|
2022-07-06 15:58:26 +02:00
|
|
|
// 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
|
2022-04-12 14:51:16 +00:00
|
|
|
{
|
2023-07-31 15:11:03 +02:00
|
|
|
Type: config.RegexRoute,
|
2022-04-12 14:51:16 +00:00
|
|
|
Method: "REPORT",
|
2023-07-31 15:11:03 +02:00
|
|
|
Endpoint: "(/remote.php)?/(web)?dav",
|
2022-10-27 16:01:20 +02:00
|
|
|
Service: "com.owncloud.web.webdav",
|
2022-09-27 10:38:15 +02:00
|
|
|
},
|
2022-04-22 11:13:10 +02:00
|
|
|
{
|
|
|
|
|
Type: config.QueryRoute,
|
|
|
|
|
Endpoint: "/dav/?preview=1",
|
2022-10-27 16:01:20 +02:00
|
|
|
Service: "com.owncloud.web.webdav",
|
2022-04-22 11:13:10 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: config.QueryRoute,
|
|
|
|
|
Endpoint: "/webdav/?preview=1",
|
2022-10-27 16:01:20 +02:00
|
|
|
Service: "com.owncloud.web.webdav",
|
2022-04-22 11:13:10 +02:00
|
|
|
},
|
2021-12-17 11:47:18 +01:00
|
|
|
{
|
|
|
|
|
Endpoint: "/remote.php/",
|
2022-05-06 15:19:29 +02:00
|
|
|
Service: "com.owncloud.web.ocdav",
|
2021-12-17 11:47:18 +01:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Endpoint: "/dav/",
|
2022-05-06 15:19:29 +02:00
|
|
|
Service: "com.owncloud.web.ocdav",
|
2021-12-17 11:47:18 +01:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Endpoint: "/webdav/",
|
2022-05-06 15:19:29 +02:00
|
|
|
Service: "com.owncloud.web.ocdav",
|
2025-09-22 10:52:52 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Endpoint: "/webdav",
|
|
|
|
|
Service: "com.owncloud.web.ocdav",
|
2021-12-17 11:47:18 +01:00
|
|
|
},
|
2022-05-16 13:43:21 +02:00
|
|
|
{
|
2022-08-30 12:30:12 +02:00
|
|
|
Endpoint: "/status",
|
|
|
|
|
Service: "com.owncloud.web.ocdav",
|
|
|
|
|
Unprotected: true,
|
2022-05-16 13:43:21 +02:00
|
|
|
},
|
2021-12-17 11:47:18 +01:00
|
|
|
{
|
2022-08-30 12:30:12 +02:00
|
|
|
Endpoint: "/status.php",
|
|
|
|
|
Service: "com.owncloud.web.ocdav",
|
|
|
|
|
Unprotected: true,
|
2021-12-17 11:47:18 +01:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Endpoint: "/index.php/",
|
2022-05-06 15:19:29 +02:00
|
|
|
Service: "com.owncloud.web.ocdav",
|
2022-04-12 11:27:24 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Endpoint: "/apps/",
|
2022-05-06 15:19:29 +02:00
|
|
|
Service: "com.owncloud.web.ocdav",
|
2021-12-17 11:47:18 +01:00
|
|
|
},
|
|
|
|
|
{
|
2022-08-30 12:30:12 +02:00
|
|
|
Endpoint: "/data",
|
2022-10-27 16:01:20 +02:00
|
|
|
Service: "com.owncloud.web.frontend",
|
2022-08-30 12:30:12 +02:00
|
|
|
Unprotected: true,
|
2021-12-17 11:47:18 +01:00
|
|
|
},
|
|
|
|
|
{
|
2022-08-30 16:26:59 +02:00
|
|
|
Endpoint: "/app/list",
|
2022-10-27 16:01:20 +02:00
|
|
|
Service: "com.owncloud.web.frontend",
|
2022-08-30 16:26:59 +02:00
|
|
|
Unprotected: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Endpoint: "/app/", // /app or /apps? ocdav only handles /apps
|
2022-10-27 16:01:20 +02:00
|
|
|
Service: "com.owncloud.web.frontend",
|
2021-12-17 11:47:18 +01:00
|
|
|
},
|
2024-06-11 16:42:52 +02:00
|
|
|
{
|
2024-06-18 12:13:13 +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",
|
2024-05-13 17:04:01 +02:00
|
|
|
Service: "com.owncloud.web.invitations",
|
2023-03-01 13:24:28 +00:00
|
|
|
},
|
2021-12-17 11:47:18 +01:00
|
|
|
{
|
|
|
|
|
Endpoint: "/graph/",
|
2024-05-13 17:04:01 +02:00
|
|
|
Service: "com.owncloud.web.graph",
|
2026-05-15 16:53:05 +02:00
|
|
|
},
|
2026-10-13 15:15:20 +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",
|
2021-12-17 11:47:18 +01:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Endpoint: "/api/v0/settings",
|
2022-10-27 16:01:20 +02:00
|
|
|
Service: "com.owncloud.web.settings",
|
2021-12-17 11:47:18 +01:00
|
|
|
},
|
2024-08-07 10:29:54 +02:00
|
|
|
{
|
|
|
|
|
Endpoint: "/auth-app/tokens",
|
2024-08-07 10:47:20 +02:00
|
|
|
Service: "com.owncloud.web.auth-app",
|
2024-08-07 10:29:54 +02:00
|
|
|
},
|
2021-12-17 11:47:18 +01:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
|
|
}
|
2022-04-27 13:58:59 +02:00
|
|
|
|
2023-03-03 00:39:00 +01:00
|
|
|
if cfg.Reva == nil && cfg.Commons != nil {
|
|
|
|
|
cfg.Reva = structs.CopyOrZeroValue(cfg.Commons.Reva)
|
2022-04-27 13:58:59 +02:00
|
|
|
}
|
2022-11-03 10:17:08 +01:00
|
|
|
|
2023-03-03 00:39:00 +01:00
|
|
|
if cfg.GRPCClientTLS == nil && cfg.Commons != nil {
|
|
|
|
|
cfg.GRPCClientTLS = structs.CopyOrZeroValue(cfg.Commons.GRPCClientTLS)
|
2022-11-03 10:17:08 +01:00
|
|
|
}
|
2026-10-06 17:21:46 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2022-03-29 15:05:52 +02: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, "/")
|
|
|
|
|
}
|
2024-09-23 16:12:48 +02:00
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
}
|