aboutsummaryrefslogtreecommitdiff
path: root/weed/server
diff options
context:
space:
mode:
authorKonstantin Lebedev <9497591+kmlebedev@users.noreply.github.com>2024-12-02 23:38:10 +0500
committerGitHub <noreply@github.com>2024-12-02 10:38:10 -0800
commitb65eb2ec4569891495ae184bf6090e0e500961e3 (patch)
tree92b75ea55a544a066f657e12fc9745a78f26baa5 /weed/server
parentb2ba7d7408500bb450884a288327a1fb53e67fae (diff)
downloadseaweedfs-b65eb2ec4569891495ae184bf6090e0e500961e3.tar.xz
seaweedfs-b65eb2ec4569891495ae184bf6090e0e500961e3.zip
[security] reload whiteList on http seerver (#6302)
* reload whiteList * white_list add to scaffold
Diffstat (limited to 'weed/server')
-rw-r--r--weed/server/filer_server.go16
-rw-r--r--weed/server/master_server.go13
-rw-r--r--weed/server/volume_server.go12
3 files changed, 36 insertions, 5 deletions
diff --git a/weed/server/filer_server.go b/weed/server/filer_server.go
index ee052579c..6855a4745 100644
--- a/weed/server/filer_server.go
+++ b/weed/server/filer_server.go
@@ -152,8 +152,8 @@ func NewFilerServer(defaultMux, readonlyMux *http.ServeMux, option *FilerOption)
}
})
fs.filer.Cipher = option.Cipher
- // we do not support IP whitelist right now
- fs.filerGuard = security.NewGuard([]string{}, signingKey, expiresAfterSec, readSigningKey, readExpiresAfterSec)
+ whiteList := util.StringSplit(v.GetString("guard.white_list"), ",")
+ fs.filerGuard = security.NewGuard(whiteList, signingKey, expiresAfterSec, readSigningKey, readExpiresAfterSec)
fs.volumeGuard = security.NewGuard([]string{}, volumeSigningKey, volumeExpiresAfterSec, volumeReadSigningKey, volumeReadExpiresAfterSec)
fs.checkWithMaster()
@@ -187,12 +187,12 @@ func NewFilerServer(defaultMux, readonlyMux *http.ServeMux, option *FilerOption)
handleStaticResources(defaultMux)
if !option.DisableHttp {
defaultMux.HandleFunc("/healthz", fs.filerHealthzHandler)
- defaultMux.HandleFunc("/", fs.filerHandler)
+ defaultMux.HandleFunc("/", fs.filerGuard.WhiteList(fs.filerHandler))
}
if defaultMux != readonlyMux {
handleStaticResources(readonlyMux)
readonlyMux.HandleFunc("/healthz", fs.filerHealthzHandler)
- readonlyMux.HandleFunc("/", fs.readonlyFilerHandler)
+ readonlyMux.HandleFunc("/", fs.filerGuard.WhiteList(fs.readonlyFilerHandler))
}
existingNodes := fs.filer.ListExistingPeerUpdates(context.Background())
@@ -209,6 +209,7 @@ func NewFilerServer(defaultMux, readonlyMux *http.ServeMux, option *FilerOption)
fs.filer.LoadRemoteStorageConfAndMapping()
+ grace.OnReload(fs.Reload)
grace.OnInterrupt(func() {
fs.filer.Shutdown()
})
@@ -239,5 +240,12 @@ func (fs *FilerServer) checkWithMaster() {
}
}
}
+}
+
+func (fs *FilerServer) Reload() {
+ glog.V(0).Infoln("Reload filer server...")
+ util.LoadConfiguration("security", false)
+ v := util.GetViper()
+ fs.filerGuard.UpdateWhiteList(util.StringSplit(v.GetString("guard.white_list"), ","))
}
diff --git a/weed/server/master_server.go b/weed/server/master_server.go
index fa45053dd..c6cb7762d 100644
--- a/weed/server/master_server.go
+++ b/weed/server/master_server.go
@@ -104,6 +104,7 @@ func NewMasterServer(r *mux.Router, option *MasterOption, peers map[string]pb.Se
topology.VolumeGrowStrategy.Copy3Count = v.GetUint32("master.volume_growth.copy_3")
topology.VolumeGrowStrategy.CopyOtherCount = v.GetUint32("master.volume_growth.copy_other")
topology.VolumeGrowStrategy.Threshold = v.GetFloat64("master.volume_growth.threshold")
+ whiteList := util.StringSplit(v.GetString("guard.white_list"), ",")
var preallocateSize int64
if option.VolumePreallocate {
@@ -133,7 +134,7 @@ func NewMasterServer(r *mux.Router, option *MasterOption, peers map[string]pb.Se
ms.vg = topology.NewDefaultVolumeGrowth()
glog.V(0).Infoln("Volume Size Limit is", ms.option.VolumeSizeLimitMB, "MB")
- ms.guard = security.NewGuard(ms.option.WhiteList, signingKey, expiresAfterSec, readSigningKey, readExpiresAfterSec)
+ ms.guard = security.NewGuard(append(ms.option.WhiteList, whiteList...), signingKey, expiresAfterSec, readSigningKey, readExpiresAfterSec)
handleStaticResources2(r)
r.HandleFunc("/", ms.proxyToLeader(ms.uiStatusHandler))
@@ -410,3 +411,13 @@ func (ms *MasterServer) Shutdown() {
}
ms.Topo.HashicorpRaft.Shutdown()
}
+
+func (ms *MasterServer) Reload() {
+ glog.V(0).Infoln("Reload master server...")
+
+ util.LoadConfiguration("security", false)
+ v := util.GetViper()
+ ms.guard.UpdateWhiteList(append(ms.option.WhiteList,
+ util.StringSplit(v.GetString("guard.white_list"), ",")...),
+ )
+}
diff --git a/weed/server/volume_server.go b/weed/server/volume_server.go
index 5d7e5c7b0..a3f072eb7 100644
--- a/weed/server/volume_server.go
+++ b/weed/server/volume_server.go
@@ -32,6 +32,7 @@ type VolumeServer struct {
readBufferSizeMB int
SeedMasterNodes []pb.ServerAddress
+ whiteList []string
currentMaster pb.ServerAddress
pulseSeconds int
dataCenter string
@@ -102,7 +103,10 @@ func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string,
hasSlowRead: hasSlowRead,
readBufferSizeMB: readBufferSizeMB,
ldbTimout: ldbTimeout,
+ whiteList: whiteList,
}
+
+ whiteList = append(whiteList, util.StringSplit(v.GetString("guard.white_list"), ",")...)
vs.SeedMasterNodes = masterNodes
vs.checkWithMaster()
@@ -150,3 +154,11 @@ func (vs *VolumeServer) Shutdown() {
vs.store.Close()
glog.V(0).Infoln("Shut down successfully!")
}
+
+func (vs *VolumeServer) Reload() {
+ glog.V(0).Infoln("Reload volume server...")
+
+ util.LoadConfiguration("security", false)
+ v := util.GetViper()
+ vs.guard.UpdateWhiteList(append(vs.whiteList, util.StringSplit(v.GetString("guard.white_list"), ",")...))
+}