mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 11:07:31 +01:00
mini: bind WebDAV to loopback unless Basic Auth is set
weed mini starts WebDAV by default on -ip.bind, which is 0.0.0.0, so anyone on the network could read, write and delete all bucket data even with S3 IAM on. Without [webdav.basic_auth], bind it to 127.0.0.1, as is done for the unauthenticated Admin UI. -webdav.allowInsecureBind keeps the network bind. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
495c40c6aa
commit
1f048ae956
3 files changed
+55
-4
No files matched your search
+22
-3
@@ -74,6 +74,7 @@ var (
|
||||
// captured before the saved options file is applied
|
||||
explicitFlags map[string]bool
|
||||
miniEnableWebDAV *bool
|
||||
miniWebDavAllowInsecureBind *bool
|
||||
miniEnableS3 *bool
|
||||
miniEnableAdminUI *bool
|
||||
miniAdminWorkerBindIP *string
|
||||
@@ -594,6 +595,7 @@ func initMiniWebDAVFlags() {
|
||||
miniWebDavOptions.maxMB = cmdMini.Flag.Int("webdav.maxMB", 4, "split files larger than the limit")
|
||||
miniWebDavOptions.filerRootPath = cmdMini.Flag.String("webdav.filer.path", "/", "use this remote path from filer server")
|
||||
miniWebDavOptions.idleTimeout = cmdMini.Flag.Int("webdav.idleTimeout", 10, "connection idle seconds")
|
||||
miniWebDavAllowInsecureBind = cmdMini.Flag.Bool("webdav.allowInsecureBind", false, "INSECURE: allow WebDAV without [webdav.basic_auth] to bind to -ip.bind instead of loopback")
|
||||
}
|
||||
|
||||
// initMiniAdminFlags initializes Admin server flag options
|
||||
@@ -1032,6 +1034,9 @@ func ensureAllPortsAvailableOnIP(bindIp string, listenOnLocalhost bool) error {
|
||||
if config.name == "Admin" {
|
||||
checkIP = adminBindIP
|
||||
}
|
||||
if config.name == "WebDAV" {
|
||||
checkIP = miniWebDavBindIP(bindIp)
|
||||
}
|
||||
original := *config.port
|
||||
unavailablePorts := maps.Clone(reservedPorts)
|
||||
for port, flag := range chosenPorts {
|
||||
@@ -1540,7 +1545,11 @@ func runMini(cmd *Command, args []string) bool {
|
||||
miniS3Options.ip = miniIp
|
||||
miniS3Options.bindIp = miniBindIp
|
||||
miniS3Options.listenOnLocalhost = &listenOnLocalhost
|
||||
miniWebDavOptions.ipBind = miniBindIp
|
||||
webDavBindIP := miniWebDavBindIP(*miniBindIp)
|
||||
if *miniEnableWebDAV && webDavBindIP != *miniBindIp {
|
||||
glog.Warningf("WebDAV has no authentication; binding it to %s instead of %s. Set [webdav.basic_auth] in security.toml, or use -webdav.allowInsecureBind to keep the network bind.", webDavBindIP, *miniBindIp)
|
||||
}
|
||||
miniWebDavOptions.ipBind = &webDavBindIP
|
||||
miniOptions.v.ip = miniIp
|
||||
miniOptions.v.bindIp = miniBindIp
|
||||
miniOptions.v.listenOnLocalhost = &listenOnLocalhost
|
||||
@@ -1859,7 +1868,7 @@ func startMiniServices(miniWhiteList []string, allServicesReady chan struct{}) {
|
||||
}
|
||||
}
|
||||
if *miniEnableWebDAV {
|
||||
waitForServiceReady("WebDAV", *miniWebDavOptions.port, bindIp)
|
||||
waitForServiceReady("WebDAV", *miniWebDavOptions.port, *miniWebDavOptions.ipBind)
|
||||
}
|
||||
|
||||
// Start Admin with worker (depends on master, filer, S3, WebDAV)
|
||||
@@ -1934,6 +1943,12 @@ func miniAdminBindIP(requestedIP string, passwordConfigured, mtlsConfigured, all
|
||||
return "127.0.0.1"
|
||||
}
|
||||
|
||||
// miniWebDavBindIP keeps WebDAV on loopback unless [webdav.basic_auth] or
|
||||
// -webdav.allowInsecureBind permits the requested address.
|
||||
func miniWebDavBindIP(requestedIP string) string {
|
||||
return miniAdminBindIP(requestedIP, webDavBasicAuth() != nil, false, *miniWebDavAllowInsecureBind)
|
||||
}
|
||||
|
||||
func miniAdminEffectiveBindIP(requestedIP string) string {
|
||||
hasMTLS := util.GetViper().GetString("https.admin.key") != "" &&
|
||||
util.GetViper().GetString("https.admin.ca") != ""
|
||||
@@ -2357,7 +2372,11 @@ func printWelcomeMessage() {
|
||||
fmt.Fprintf(&sb, " Volume Server: http://%s:%d\n", *miniIp, *miniOptions.v.port)
|
||||
fmt.Fprintf(&sb, " Filer UI: http://%s:%d\n", *miniIp, *miniFilerOptions.port)
|
||||
if *miniEnableWebDAV {
|
||||
fmt.Fprintf(&sb, " WebDAV: http://%s:%d\n", *miniIp, *miniWebDavOptions.port)
|
||||
webDavIP := *miniIp
|
||||
if isLoopbackIp(*miniWebDavOptions.ipBind) {
|
||||
webDavIP = *miniWebDavOptions.ipBind
|
||||
}
|
||||
fmt.Fprintf(&sb, " WebDAV: http://%s:%d\n", webDavIP, *miniWebDavOptions.port)
|
||||
}
|
||||
if *miniEnableS3 {
|
||||
fmt.Fprintf(&sb, " S3 Endpoint: http://%s:%d\n", *miniIp, *miniS3Options.port)
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package command
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestMiniWebDavBindIP(t *testing.T) {
|
||||
allow := *miniWebDavAllowInsecureBind
|
||||
t.Cleanup(func() { *miniWebDavAllowInsecureBind = allow })
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
requestedIP string
|
||||
password string
|
||||
allowInsecure bool
|
||||
want string
|
||||
}{
|
||||
{name: "unauthenticated wildcard binds to loopback", requestedIP: "0.0.0.0", want: "127.0.0.1"},
|
||||
{name: "unauthenticated host address binds to loopback", requestedIP: "10.0.0.5", want: "127.0.0.1"},
|
||||
{name: "existing loopback bind is preserved", requestedIP: "127.0.0.1", want: "127.0.0.1"},
|
||||
{name: "basic auth permits requested bind", requestedIP: "0.0.0.0", password: "secret", want: "0.0.0.0"},
|
||||
{name: "explicit insecure opt-out permits requested bind", requestedIP: "0.0.0.0", allowInsecure: true, want: "0.0.0.0"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Setenv("WEED_WEBDAV_BASIC_AUTH_PASSWORD", tt.password)
|
||||
*miniWebDavAllowInsecureBind = tt.allowInsecure
|
||||
if got := miniWebDavBindIP(tt.requestedIP); got != tt.want {
|
||||
t.Fatalf("miniWebDavBindIP(%q) = %q, want %q", tt.requestedIP, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,8 @@ password = ""
|
||||
|
||||
# HTTP Basic Auth on the WebDAV gateway (weed webdav, weed server -webdav,
|
||||
# weed mini). Without a password, anyone who can reach the WebDAV port reads,
|
||||
# writes and deletes everything under its -filer.path.
|
||||
# writes and deletes everything under its -filer.path, and weed mini binds
|
||||
# WebDAV to 127.0.0.1 unless -webdav.allowInsecureBind is set.
|
||||
# Env: WEED_WEBDAV_BASIC_AUTH_USER, WEED_WEBDAV_BASIC_AUTH_PASSWORD
|
||||
[webdav.basic_auth]
|
||||
user = ""
|
||||
|
||||
Reference in new issue
Block a user