Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

Allow whitelisting by CIDR range, not just literally.

Steve Kemp2a777a970cf5
diff --git a/go/security/guard.go b/go/security/guard.go
index bde938dba3..b938454484 100644
--- a/go/security/guard.go
+++ b/go/security/guard.go
@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"net"
+ "regexp"
"net/http"
"github.com/chrislusf/seaweedfs/go/glog"
@@ -88,6 +89,26 @@ func (g *Guard) checkWhiteList(w http.ResponseWriter, r *http.Request) error {
host, _, err := net.SplitHostPort(r.RemoteAddr)
if err == nil {
for _, ip := range g.whiteList {
+
+ // If the whitelist entry contains a "/" it
+ // is a CIDR range, and we should check the
+ // remote host is within it
+ match, _ := regexp.MatchString("/", ip)
+ if ( match ) {
+ _, cidrnet, err := net.ParseCIDR(ip)
+ if err != nil {
+ panic(err)
+ }
+ remote := net.ParseIP(host)
+ if cidrnet.Contains(remote) {
+ return nil
+ }
+ }
+
+
+ //
+ // Otherwise we're looking for a literal match.
+ //
if ip == host {
return nil
}