Skip to content

armgit / ente

Public Imported from GitHub
0

💚 End-to-end encrypted cloud for everything.

[server] Support for configuring trusted client ip header

Neeraj Gupta25cea569da14
diff --git a/docs/docs/self-hosting/installation/config.md b/docs/docs/self-hosting/installation/config.md
index 656feaeeab..5d5a845717 100644
--- a/docs/docs/self-hosting/installation/config.md
+++ b/docs/docs/self-hosting/installation/config.md
@@ -199,6 +199,7 @@ smtp:
| Variable | Description | Default |
| -------------------------------------------- | --------------------------------------------- | ------- |
| `internal.silent` | Suppress external effects (e.g. email alerts) | `false` |
+| `internal.trusted-client-ip-header` | Request header trusted by gin’s `TrustedPlatform` when the server runs behind a proxy | `CF-Connecting-IP` |
| `internal.health-check-url` | External healthcheck URL | |
| `internal.hardcoded-ott` | Predefined OTPs for testing | |
| `internal.hardcoded-ott.emails` | E-mail addresses with hardcoded OTTs | `[]` |
diff --git a/server/cmd/museum/main.go b/server/cmd/museum/main.go
index 2a3ee266cd..618ae0c0b3 100644
--- a/server/cmd/museum/main.go
+++ b/server/cmd/museum/main.go
@@ -104,6 +104,8 @@ func main() {
viper.SetDefault("apps.accounts", "https://accounts.ente.io")
viper.SetDefault("apps.cast", "https://cast.ente.io")
viper.SetDefault("apps.family", "https://family.ente.io")
+ // For existing users, we were defaulting to CF-Connecting-IP. Unless there's a good reason to change it, we should keep it same.
+ viper.SetDefault("internal.trusted-client-ip-header", "CF-Connecting-IP")
setupLogger(environment)
log.Infof("Booting up %s server with commit #%s", environment, os.Getenv("GIT_COMMIT"))
@@ -388,6 +390,11 @@ func main() {
}
server := gin.New()
+ clientIPHeader := viper.GetString("internal.trusted-client-ip-header")
+ if clientIPHeader != "" {
+ server.TrustedPlatform = clientIPHeader
+ }
+
p := ginprometheus.NewPrometheus("museum")
p.ReqCntURLLabelMappingFn = urlSanitizer
server.Use(p.HandlerFunc())
@@ -852,6 +859,9 @@ func runServer(environment string, server *gin.Engine) {
port = viper.GetInt("http.port")
}
log.Infof("starting server on port %d", port)
+ if server.TrustedPlatform != "" {
+ log.Infof("trusted platform header: %s", server.TrustedPlatform)
+ }
server.Run(fmt.Sprintf(":%d", port))
}
}
diff --git a/server/configurations/local.yaml b/server/configurations/local.yaml
index ed33189716..a4202f1efd 100644
--- a/server/configurations/local.yaml
+++ b/server/configurations/local.yaml
@@ -345,6 +345,9 @@ internal:
# restoration test, where we want to be able to access data but otherwise
# minimize external side effects.
silent: false
+ # Header gin will trust for resolving the original client IP when requests are proxied.
+ # Defaults to CF-Connecting-IP; uncomment and change if your proxy uses another header.
+ # trusted-client-ip-header: CF-Connecting-IP
# If provided, this external healthcheck url is periodically pinged.
health-check-url:
# Hardcoded verification codes, useful for logging in when developing.
diff --git a/server/pkg/utils/network/network.go b/server/pkg/utils/network/network.go
index 5b881044b1..54aa32397d 100644
--- a/server/pkg/utils/network/network.go
+++ b/server/pkg/utils/network/network.go
@@ -6,11 +6,7 @@ import (
)
func GetClientIP(c *gin.Context) string {
- ip := c.GetHeader("CF-Connecting-IP")
- if ip == "" {
- ip = c.ClientIP()
- }
- return ip
+ return c.ClientIP()
}
func IsCFWorkerIP(ip string) bool {