You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

205 lines
6.7 KiB

7 years ago
7 years ago
4 years ago
3 years ago
4 years ago
7 years ago
6 years ago
7 years ago
FEATURE: add JWT to HTTP endpoints of Filer and use them in S3 Client - one JWT for reading and one for writing, analogous to how the JWT between Master and Volume Server works - I did not implement IP `whiteList` parameter on the filer Additionally, because http_util.DownloadFile now sets the JWT, the `download` command should now work when `jwt.signing.read` is configured. By looking at the code, I think this case did not work before. ## Docs to be adjusted after a release Page `Amazon-S3-API`: ``` # Authentication with Filer You can use mTLS for the gRPC connection between S3-API-Proxy and the filer, as explained in [Security-Configuration](Security-Configuration) - controlled by the `grpc.*` configuration in `security.toml`. Starting with version XX, it is also possible to authenticate the HTTP operations between the S3-API-Proxy and the Filer (especially uploading new files). This is configured by setting `filer_jwt.signing.key` and `filer_jwt.signing.read.key` in `security.toml`. With both configurations (gRPC and JWT), it is possible to have Filer and S3 communicate in fully authenticated fashion; so Filer will reject any unauthenticated communication. ``` Page `Security Overview`: ``` The following items are not covered, yet: - master server http REST services Starting with version XX, the Filer HTTP REST services can be secured with a JWT, by setting `filer_jwt.signing.key` and `filer_jwt.signing.read.key` in `security.toml`. ... Before version XX: "weed filer -disableHttp", disable http operations, only gRPC operations are allowed. This works with "weed mount" by FUSE. It does **not work** with the [S3 Gateway](Amazon S3 API), as this does HTTP calls to the Filer. Starting with version XX: secured by JWT, by setting `filer_jwt.signing.key` and `filer_jwt.signing.read.key` in `security.toml`. **This now works with the [S3 Gateway](Amazon S3 API).** ... # Securing Filer HTTP with JWT To enable JWT-based access control for the Filer, 1. generate `security.toml` file by `weed scaffold -config=security` 2. set `filer_jwt.signing.key` to a secret string - and optionally filer_jwt.signing.read.key` as well to a secret string 3. copy the same `security.toml` file to the filers and all S3 proxies. If `filer_jwt.signing.key` is configured: When sending upload/update/delete HTTP operations to a filer server, the request header `Authorization` should be the JWT string (`Authorization: Bearer [JwtToken]`). The operation is authorized after the filer validates the JWT with `filer_jwt.signing.key`. If `filer_jwt.signing.read.key` is configured: When sending GET or HEAD requests to a filer server, the request header `Authorization` should be the JWT string (`Authorization: Bearer [JwtToken]`). The operation is authorized after the filer validates the JWT with `filer_jwt.signing.read.key`. The S3 API Gateway reads the above JWT keys and sends authenticated HTTP requests to the filer. ``` Page `Security Configuration`: ``` (update scaffold file) ... [filer_jwt.signing] key = "blahblahblahblah" [filer_jwt.signing.read] key = "blahblahblahblah" ``` Resolves: #158
3 years ago
4 years ago
FEATURE: add JWT to HTTP endpoints of Filer and use them in S3 Client - one JWT for reading and one for writing, analogous to how the JWT between Master and Volume Server works - I did not implement IP `whiteList` parameter on the filer Additionally, because http_util.DownloadFile now sets the JWT, the `download` command should now work when `jwt.signing.read` is configured. By looking at the code, I think this case did not work before. ## Docs to be adjusted after a release Page `Amazon-S3-API`: ``` # Authentication with Filer You can use mTLS for the gRPC connection between S3-API-Proxy and the filer, as explained in [Security-Configuration](Security-Configuration) - controlled by the `grpc.*` configuration in `security.toml`. Starting with version XX, it is also possible to authenticate the HTTP operations between the S3-API-Proxy and the Filer (especially uploading new files). This is configured by setting `filer_jwt.signing.key` and `filer_jwt.signing.read.key` in `security.toml`. With both configurations (gRPC and JWT), it is possible to have Filer and S3 communicate in fully authenticated fashion; so Filer will reject any unauthenticated communication. ``` Page `Security Overview`: ``` The following items are not covered, yet: - master server http REST services Starting with version XX, the Filer HTTP REST services can be secured with a JWT, by setting `filer_jwt.signing.key` and `filer_jwt.signing.read.key` in `security.toml`. ... Before version XX: "weed filer -disableHttp", disable http operations, only gRPC operations are allowed. This works with "weed mount" by FUSE. It does **not work** with the [S3 Gateway](Amazon S3 API), as this does HTTP calls to the Filer. Starting with version XX: secured by JWT, by setting `filer_jwt.signing.key` and `filer_jwt.signing.read.key` in `security.toml`. **This now works with the [S3 Gateway](Amazon S3 API).** ... # Securing Filer HTTP with JWT To enable JWT-based access control for the Filer, 1. generate `security.toml` file by `weed scaffold -config=security` 2. set `filer_jwt.signing.key` to a secret string - and optionally filer_jwt.signing.read.key` as well to a secret string 3. copy the same `security.toml` file to the filers and all S3 proxies. If `filer_jwt.signing.key` is configured: When sending upload/update/delete HTTP operations to a filer server, the request header `Authorization` should be the JWT string (`Authorization: Bearer [JwtToken]`). The operation is authorized after the filer validates the JWT with `filer_jwt.signing.key`. If `filer_jwt.signing.read.key` is configured: When sending GET or HEAD requests to a filer server, the request header `Authorization` should be the JWT string (`Authorization: Bearer [JwtToken]`). The operation is authorized after the filer validates the JWT with `filer_jwt.signing.read.key`. The S3 API Gateway reads the above JWT keys and sends authenticated HTTP requests to the filer. ``` Page `Security Configuration`: ``` (update scaffold file) ... [filer_jwt.signing] key = "blahblahblahblah" [filer_jwt.signing.read] key = "blahblahblahblah" ``` Resolves: #158
3 years ago
FEATURE: add JWT to HTTP endpoints of Filer and use them in S3 Client - one JWT for reading and one for writing, analogous to how the JWT between Master and Volume Server works - I did not implement IP `whiteList` parameter on the filer Additionally, because http_util.DownloadFile now sets the JWT, the `download` command should now work when `jwt.signing.read` is configured. By looking at the code, I think this case did not work before. ## Docs to be adjusted after a release Page `Amazon-S3-API`: ``` # Authentication with Filer You can use mTLS for the gRPC connection between S3-API-Proxy and the filer, as explained in [Security-Configuration](Security-Configuration) - controlled by the `grpc.*` configuration in `security.toml`. Starting with version XX, it is also possible to authenticate the HTTP operations between the S3-API-Proxy and the Filer (especially uploading new files). This is configured by setting `filer_jwt.signing.key` and `filer_jwt.signing.read.key` in `security.toml`. With both configurations (gRPC and JWT), it is possible to have Filer and S3 communicate in fully authenticated fashion; so Filer will reject any unauthenticated communication. ``` Page `Security Overview`: ``` The following items are not covered, yet: - master server http REST services Starting with version XX, the Filer HTTP REST services can be secured with a JWT, by setting `filer_jwt.signing.key` and `filer_jwt.signing.read.key` in `security.toml`. ... Before version XX: "weed filer -disableHttp", disable http operations, only gRPC operations are allowed. This works with "weed mount" by FUSE. It does **not work** with the [S3 Gateway](Amazon S3 API), as this does HTTP calls to the Filer. Starting with version XX: secured by JWT, by setting `filer_jwt.signing.key` and `filer_jwt.signing.read.key` in `security.toml`. **This now works with the [S3 Gateway](Amazon S3 API).** ... # Securing Filer HTTP with JWT To enable JWT-based access control for the Filer, 1. generate `security.toml` file by `weed scaffold -config=security` 2. set `filer_jwt.signing.key` to a secret string - and optionally filer_jwt.signing.read.key` as well to a secret string 3. copy the same `security.toml` file to the filers and all S3 proxies. If `filer_jwt.signing.key` is configured: When sending upload/update/delete HTTP operations to a filer server, the request header `Authorization` should be the JWT string (`Authorization: Bearer [JwtToken]`). The operation is authorized after the filer validates the JWT with `filer_jwt.signing.key`. If `filer_jwt.signing.read.key` is configured: When sending GET or HEAD requests to a filer server, the request header `Authorization` should be the JWT string (`Authorization: Bearer [JwtToken]`). The operation is authorized after the filer validates the JWT with `filer_jwt.signing.read.key`. The S3 API Gateway reads the above JWT keys and sends authenticated HTTP requests to the filer. ``` Page `Security Configuration`: ``` (update scaffold file) ... [filer_jwt.signing] key = "blahblahblahblah" [filer_jwt.signing.read] key = "blahblahblahblah" ``` Resolves: #158
3 years ago
5 years ago
4 years ago
4 years ago
  1. package weed_server
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  6. "net/http"
  7. "os"
  8. "sync"
  9. "time"
  10. "github.com/chrislusf/seaweedfs/weed/stats"
  11. "google.golang.org/grpc"
  12. "github.com/chrislusf/seaweedfs/weed/util/grace"
  13. "github.com/chrislusf/seaweedfs/weed/operation"
  14. "github.com/chrislusf/seaweedfs/weed/pb"
  15. "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
  16. "github.com/chrislusf/seaweedfs/weed/util"
  17. "github.com/chrislusf/seaweedfs/weed/filer"
  18. _ "github.com/chrislusf/seaweedfs/weed/filer/arangodb"
  19. _ "github.com/chrislusf/seaweedfs/weed/filer/cassandra"
  20. _ "github.com/chrislusf/seaweedfs/weed/filer/elastic/v7"
  21. _ "github.com/chrislusf/seaweedfs/weed/filer/etcd"
  22. _ "github.com/chrislusf/seaweedfs/weed/filer/hbase"
  23. _ "github.com/chrislusf/seaweedfs/weed/filer/leveldb"
  24. _ "github.com/chrislusf/seaweedfs/weed/filer/leveldb2"
  25. _ "github.com/chrislusf/seaweedfs/weed/filer/leveldb3"
  26. _ "github.com/chrislusf/seaweedfs/weed/filer/mongodb"
  27. _ "github.com/chrislusf/seaweedfs/weed/filer/mysql"
  28. _ "github.com/chrislusf/seaweedfs/weed/filer/mysql2"
  29. _ "github.com/chrislusf/seaweedfs/weed/filer/postgres"
  30. _ "github.com/chrislusf/seaweedfs/weed/filer/postgres2"
  31. _ "github.com/chrislusf/seaweedfs/weed/filer/redis"
  32. _ "github.com/chrislusf/seaweedfs/weed/filer/redis2"
  33. _ "github.com/chrislusf/seaweedfs/weed/filer/redis3"
  34. _ "github.com/chrislusf/seaweedfs/weed/filer/sqlite"
  35. "github.com/chrislusf/seaweedfs/weed/glog"
  36. "github.com/chrislusf/seaweedfs/weed/notification"
  37. _ "github.com/chrislusf/seaweedfs/weed/notification/aws_sqs"
  38. _ "github.com/chrislusf/seaweedfs/weed/notification/gocdk_pub_sub"
  39. _ "github.com/chrislusf/seaweedfs/weed/notification/google_pub_sub"
  40. _ "github.com/chrislusf/seaweedfs/weed/notification/kafka"
  41. _ "github.com/chrislusf/seaweedfs/weed/notification/log"
  42. "github.com/chrislusf/seaweedfs/weed/security"
  43. )
  44. type FilerOption struct {
  45. Masters map[string]pb.ServerAddress
  46. FilerGroup string
  47. Collection string
  48. DefaultReplication string
  49. DisableDirListing bool
  50. MaxMB int
  51. DirListingLimit int
  52. DataCenter string
  53. Rack string
  54. DataNode string
  55. DefaultLevelDbDir string
  56. DisableHttp bool
  57. Host pb.ServerAddress
  58. recursiveDelete bool
  59. Cipher bool
  60. SaveToFilerLimit int64
  61. ConcurrentUploadLimit int64
  62. }
  63. type FilerServer struct {
  64. filer_pb.UnimplementedSeaweedFilerServer
  65. option *FilerOption
  66. secret security.SigningKey
  67. filer *filer.Filer
  68. filerGuard *security.Guard
  69. grpcDialOption grpc.DialOption
  70. // metrics read from the master
  71. metricsAddress string
  72. metricsIntervalSec int
  73. // notifying clients
  74. listenersLock sync.Mutex
  75. listenersCond *sync.Cond
  76. // track known metadata listeners
  77. knownListenersLock sync.Mutex
  78. knownListeners map[int32]struct{}
  79. brokers map[string]map[string]bool
  80. brokersLock sync.Mutex
  81. inFlightDataSize int64
  82. inFlightDataLimitCond *sync.Cond
  83. }
  84. func NewFilerServer(defaultMux, readonlyMux *http.ServeMux, option *FilerOption) (fs *FilerServer, err error) {
  85. v := util.GetViper()
  86. signingKey := v.GetString("jwt.filer_signing.key")
  87. v.SetDefault("jwt.filer_signing.expires_after_seconds", 10)
  88. expiresAfterSec := v.GetInt("jwt.filer_signing.expires_after_seconds")
  89. readSigningKey := v.GetString("jwt.filer_signing.read.key")
  90. v.SetDefault("jwt.filer_signing.read.expires_after_seconds", 60)
  91. readExpiresAfterSec := v.GetInt("jwt.filer_signing.read.expires_after_seconds")
  92. fs = &FilerServer{
  93. option: option,
  94. grpcDialOption: security.LoadClientTLS(util.GetViper(), "grpc.filer"),
  95. knownListeners: make(map[int32]struct{}),
  96. brokers: make(map[string]map[string]bool),
  97. inFlightDataLimitCond: sync.NewCond(new(sync.Mutex)),
  98. }
  99. fs.listenersCond = sync.NewCond(&fs.listenersLock)
  100. if len(option.Masters) == 0 {
  101. glog.Fatal("master list is required!")
  102. }
  103. fs.filer = filer.NewFiler(option.Masters, fs.grpcDialOption, option.Host, option.FilerGroup, option.Collection, option.DefaultReplication, option.DataCenter, func() {
  104. fs.listenersCond.Broadcast()
  105. })
  106. fs.filer.Cipher = option.Cipher
  107. // we do not support IP whitelist right now
  108. fs.filerGuard = security.NewGuard([]string{}, signingKey, expiresAfterSec, readSigningKey, readExpiresAfterSec)
  109. fs.checkWithMaster()
  110. go stats.LoopPushingMetric("filer", string(fs.option.Host), fs.metricsAddress, fs.metricsIntervalSec)
  111. go fs.filer.KeepMasterClientConnected()
  112. if !util.LoadConfiguration("filer", false) {
  113. v.SetDefault("leveldb2.enabled", true)
  114. v.SetDefault("leveldb2.dir", option.DefaultLevelDbDir)
  115. _, err := os.Stat(option.DefaultLevelDbDir)
  116. if os.IsNotExist(err) {
  117. os.MkdirAll(option.DefaultLevelDbDir, 0755)
  118. }
  119. glog.V(0).Infof("default to create filer store dir in %s", option.DefaultLevelDbDir)
  120. } else {
  121. glog.Warningf("skipping default store dir in %s", option.DefaultLevelDbDir)
  122. }
  123. util.LoadConfiguration("notification", false)
  124. fs.option.recursiveDelete = v.GetBool("filer.options.recursive_delete")
  125. v.SetDefault("filer.options.buckets_folder", "/buckets")
  126. fs.filer.DirBucketsPath = v.GetString("filer.options.buckets_folder")
  127. // TODO deprecated, will be be removed after 2020-12-31
  128. // replaced by https://github.com/chrislusf/seaweedfs/wiki/Path-Specific-Configuration
  129. // fs.filer.FsyncBuckets = v.GetStringSlice("filer.options.buckets_fsync")
  130. fs.filer.LoadConfiguration(v)
  131. notification.LoadConfiguration(v, "notification.")
  132. handleStaticResources(defaultMux)
  133. if !option.DisableHttp {
  134. defaultMux.HandleFunc("/", fs.filerHandler)
  135. }
  136. if defaultMux != readonlyMux {
  137. handleStaticResources(readonlyMux)
  138. readonlyMux.HandleFunc("/", fs.readonlyFilerHandler)
  139. }
  140. fs.filer.AggregateFromPeers(option.Host)
  141. fs.filer.LoadBuckets()
  142. fs.filer.LoadFilerConf()
  143. fs.filer.LoadRemoteStorageConfAndMapping()
  144. grace.OnInterrupt(func() {
  145. fs.filer.Shutdown()
  146. })
  147. return fs, nil
  148. }
  149. func (fs *FilerServer) checkWithMaster() {
  150. isConnected := false
  151. for !isConnected {
  152. for _, master := range fs.option.Masters {
  153. readErr := operation.WithMasterServerClient(false, master, fs.grpcDialOption, func(masterClient master_pb.SeaweedClient) error {
  154. resp, err := masterClient.GetMasterConfiguration(context.Background(), &master_pb.GetMasterConfigurationRequest{})
  155. if err != nil {
  156. return fmt.Errorf("get master %s configuration: %v", master, err)
  157. }
  158. fs.metricsAddress, fs.metricsIntervalSec = resp.MetricsAddress, int(resp.MetricsIntervalSeconds)
  159. if fs.option.DefaultReplication == "" {
  160. fs.option.DefaultReplication = resp.DefaultReplication
  161. }
  162. return nil
  163. })
  164. if readErr == nil {
  165. isConnected = true
  166. } else {
  167. time.Sleep(7 * time.Second)
  168. }
  169. }
  170. }
  171. }