Files
seaweedfs/weed/command/mini_webdav_bind_test.go
T
Chris LuandClaude Opus 5.5 1f1d6d057b webdav: optional Basic Auth; mini keeps unauthenticated WebDAV on loopback (#12956)
* webdav: optional HTTP Basic Auth from [webdav.basic_auth]

WebDAV reaches the filer over gRPC, so neither the filer JWT nor the
filer's Basic Auth covers it, and it had no authentication of its own.
With a password set in [webdav.basic_auth], every request needs it.
Without one, startup warns when the gateway listens beyond loopback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* 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>

* command: treat a bracketed IPv6 loopback as loopback

-ip.bind='[::1]' failed net.ParseIP, so mini moved an unauthenticated
WebDAV or Admin listener off it to 127.0.0.1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* security.toml: note TLS for WebDAV Basic Auth

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 12:57:50 -08:00

34 lines
1.3 KiB
Go

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: "bracketed IPv6 loopback bind is preserved", requestedIP: "[::1]", want: "[::1]"},
{name: "bracketed IPv6 wildcard binds to loopback", requestedIP: "[::]", 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)
}
})
}
}