2018-07-18 17:37:09 +08:00
|
|
|
package s3api
|
|
|
|
|
|
|
|
import (
|
2022-03-07 18:00:14 +08:00
|
|
|
"context"
|
2020-07-28 23:47:24 +08:00
|
|
|
"fmt"
|
2022-03-07 18:00:14 +08:00
|
|
|
"net"
|
2020-02-10 06:30:02 +08:00
|
|
|
"net/http"
|
2020-10-21 23:48:51 +08:00
|
|
|
"strings"
|
2020-12-07 16:10:29 +08:00
|
|
|
"time"
|
2020-02-10 06:30:02 +08:00
|
|
|
|
2023-12-21 08:21:11 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/filer"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/s3_pb"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/util/grace"
|
|
|
|
|
2018-07-18 17:37:09 +08:00
|
|
|
"github.com/gorilla/mux"
|
2022-07-29 15:17:28 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
|
|
|
. "github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/s3api/s3err"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/security"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
2019-02-19 04:11:52 +08:00
|
|
|
"google.golang.org/grpc"
|
2018-07-18 17:37:09 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type S3ApiServerOption struct {
|
2022-03-31 01:46:13 +08:00
|
|
|
Filer pb.ServerAddress
|
|
|
|
Port int
|
|
|
|
Config string
|
|
|
|
DomainName string
|
2023-12-21 08:21:11 +08:00
|
|
|
AllowedOrigins []string
|
2022-03-31 01:46:13 +08:00
|
|
|
BucketsPath string
|
|
|
|
GrpcDialOption grpc.DialOption
|
|
|
|
AllowEmptyFolder bool
|
|
|
|
AllowDeleteBucketNotEmpty bool
|
2022-09-02 01:33:23 +08:00
|
|
|
LocalFilerSocket string
|
2022-08-05 08:35:00 +08:00
|
|
|
DataCenter string
|
2023-05-17 00:39:43 +08:00
|
|
|
FilerGroup string
|
2018-07-18 17:37:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type S3ApiServer struct {
|
2022-05-15 15:43:37 +08:00
|
|
|
s3_pb.UnimplementedSeaweedS3Server
|
2021-12-30 16:23:57 +08:00
|
|
|
option *S3ApiServerOption
|
|
|
|
iam *IdentityAccessManagement
|
2022-06-15 21:07:55 +08:00
|
|
|
cb *CircuitBreaker
|
2021-12-30 16:23:57 +08:00
|
|
|
randomClientId int32
|
2022-01-02 17:07:30 +08:00
|
|
|
filerGuard *security.Guard
|
2022-03-07 18:00:14 +08:00
|
|
|
client *http.Client
|
2022-09-30 03:29:01 +08:00
|
|
|
bucketRegistry *BucketRegistry
|
2018-07-18 17:37:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewS3ApiServer(router *mux.Router, option *S3ApiServerOption) (s3ApiServer *S3ApiServer, err error) {
|
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
2021-12-30 02:47:53 +08:00
|
|
|
v := util.GetViper()
|
|
|
|
signingKey := v.GetString("jwt.filer_signing.key")
|
|
|
|
v.SetDefault("jwt.filer_signing.expires_after_seconds", 10)
|
|
|
|
expiresAfterSec := v.GetInt("jwt.filer_signing.expires_after_seconds")
|
|
|
|
|
|
|
|
readSigningKey := v.GetString("jwt.filer_signing.read.key")
|
|
|
|
v.SetDefault("jwt.filer_signing.read.expires_after_seconds", 60)
|
|
|
|
readExpiresAfterSec := v.GetInt("jwt.filer_signing.read.expires_after_seconds")
|
|
|
|
|
2023-12-21 08:21:11 +08:00
|
|
|
v.SetDefault("cors.allowed_origins.values", "*")
|
|
|
|
|
|
|
|
if (option.AllowedOrigins == nil) || (len(option.AllowedOrigins) == 0) {
|
|
|
|
allowedOrigins := v.GetString("cors.allowed_origins.values")
|
|
|
|
domains := strings.Split(allowedOrigins, ",")
|
|
|
|
option.AllowedOrigins = domains
|
|
|
|
}
|
|
|
|
|
2018-07-18 17:37:09 +08:00
|
|
|
s3ApiServer = &S3ApiServer{
|
2021-12-30 16:23:57 +08:00
|
|
|
option: option,
|
|
|
|
iam: NewIdentityAccessManagement(option),
|
|
|
|
randomClientId: util.RandomInt32(),
|
2022-01-02 17:07:30 +08:00
|
|
|
filerGuard: security.NewGuard([]string{}, signingKey, expiresAfterSec, readSigningKey, readExpiresAfterSec),
|
2022-06-15 21:07:55 +08:00
|
|
|
cb: NewCircuitBreaker(option),
|
2018-07-18 17:37:09 +08:00
|
|
|
}
|
2023-10-19 14:26:49 +08:00
|
|
|
if option.Config != "" {
|
|
|
|
grace.OnReload(func() {
|
|
|
|
if err := s3ApiServer.iam.loadS3ApiConfigurationFromFile(option.Config); err != nil {
|
|
|
|
glog.Errorf("fail to load config file %s: %v", option.Config, err)
|
|
|
|
} else {
|
2023-10-19 23:10:33 +08:00
|
|
|
glog.V(0).Infof("Loaded %d identities from config file %s", len(s3ApiServer.iam.identities), option.Config)
|
2023-10-19 14:26:49 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-09-30 03:29:01 +08:00
|
|
|
s3ApiServer.bucketRegistry = NewBucketRegistry(s3ApiServer)
|
2022-09-02 01:33:23 +08:00
|
|
|
if option.LocalFilerSocket == "" {
|
2022-03-07 18:00:14 +08:00
|
|
|
s3ApiServer.client = &http.Client{Transport: &http.Transport{
|
|
|
|
MaxIdleConns: 1024,
|
|
|
|
MaxIdleConnsPerHost: 1024,
|
|
|
|
}}
|
|
|
|
} else {
|
|
|
|
s3ApiServer.client = &http.Client{
|
|
|
|
Transport: &http.Transport{
|
|
|
|
DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
|
2022-09-02 01:33:23 +08:00
|
|
|
return net.Dial("unix", option.LocalFilerSocket)
|
2022-03-07 18:00:14 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2018-07-18 17:37:09 +08:00
|
|
|
|
|
|
|
s3ApiServer.registerRouter(router)
|
|
|
|
|
2022-09-30 03:29:01 +08:00
|
|
|
go s3ApiServer.subscribeMetaEvents("s3", time.Now().UnixNano(), filer.DirectoryEtcRoot, []string{option.BucketsPath})
|
2018-07-18 17:37:09 +08:00
|
|
|
return s3ApiServer, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s3a *S3ApiServer) registerRouter(router *mux.Router) {
|
|
|
|
// API Router
|
|
|
|
apiRouter := router.PathPrefix("/").Subrouter()
|
2021-08-10 18:42:46 +08:00
|
|
|
|
|
|
|
// Readiness Probe
|
2024-07-01 16:00:39 +08:00
|
|
|
apiRouter.Methods(http.MethodGet).Path("/status").HandlerFunc(s3a.StatusHandler)
|
2021-08-10 18:42:46 +08:00
|
|
|
|
2024-07-01 16:00:39 +08:00
|
|
|
apiRouter.Methods(http.MethodOptions).HandlerFunc(
|
2022-08-23 14:39:34 +08:00
|
|
|
func(w http.ResponseWriter, r *http.Request) {
|
2023-12-21 08:21:11 +08:00
|
|
|
origin := r.Header.Get("Origin")
|
|
|
|
if origin != "" {
|
|
|
|
if s3a.option.AllowedOrigins == nil || len(s3a.option.AllowedOrigins) == 0 || s3a.option.AllowedOrigins[0] == "*" {
|
|
|
|
origin = "*"
|
|
|
|
} else {
|
|
|
|
originFound := false
|
|
|
|
for _, allowedOrigin := range s3a.option.AllowedOrigins {
|
|
|
|
if origin == allowedOrigin {
|
|
|
|
originFound = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !originFound {
|
|
|
|
writeFailureResponse(w, r, http.StatusForbidden)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
w.Header().Set("Access-Control-Allow-Origin", origin)
|
2022-08-23 14:39:34 +08:00
|
|
|
w.Header().Set("Access-Control-Expose-Headers", "*")
|
|
|
|
w.Header().Set("Access-Control-Allow-Methods", "*")
|
|
|
|
w.Header().Set("Access-Control-Allow-Headers", "*")
|
2022-08-22 23:21:38 +08:00
|
|
|
writeSuccessResponseEmpty(w, r)
|
|
|
|
})
|
|
|
|
|
2018-07-18 17:37:09 +08:00
|
|
|
var routers []*mux.Router
|
|
|
|
if s3a.option.DomainName != "" {
|
2020-10-21 23:48:51 +08:00
|
|
|
domainNames := strings.Split(s3a.option.DomainName, ",")
|
|
|
|
for _, domainName := range domainNames {
|
|
|
|
routers = append(routers, apiRouter.Host(
|
|
|
|
fmt.Sprintf("%s.%s:%d", "{bucket:.+}", domainName, s3a.option.Port)).Subrouter())
|
|
|
|
routers = append(routers, apiRouter.Host(
|
|
|
|
fmt.Sprintf("%s.%s", "{bucket:.+}", domainName)).Subrouter())
|
|
|
|
}
|
2018-07-18 17:37:09 +08:00
|
|
|
}
|
|
|
|
routers = append(routers, apiRouter.PathPrefix("/{bucket}").Subrouter())
|
|
|
|
|
|
|
|
for _, bucket := range routers {
|
2018-07-22 01:39:02 +08:00
|
|
|
|
2022-02-04 20:14:48 +08:00
|
|
|
// each case should follow the next rule:
|
|
|
|
// - requesting object with query must precede any other methods
|
|
|
|
// - requesting object must precede any methods with buckets
|
|
|
|
// - requesting bucket with query must precede raw methods with buckets
|
|
|
|
// - requesting bucket must be processed in the end
|
|
|
|
|
|
|
|
// objects with query
|
2018-07-22 17:04:07 +08:00
|
|
|
|
2020-01-31 16:11:08 +08:00
|
|
|
// CopyObjectPart
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodPut).Path("/{object:.+}").HeadersRegexp("X-Amz-Copy-Source", `.*?(\/|%2F).*?`).HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.CopyObjectPartHandler, ACTION_WRITE)), "PUT")).Queries("partNumber", "{partNumber:[0-9]+}", "uploadId", "{uploadId:.*}")
|
2018-09-04 02:38:10 +08:00
|
|
|
// PutObjectPart
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodPut).Path("/{object:.+}").HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.PutObjectPartHandler, ACTION_WRITE)), "PUT")).Queries("partNumber", "{partNumber:[0-9]+}", "uploadId", "{uploadId:.*}")
|
2018-09-04 02:38:10 +08:00
|
|
|
// CompleteMultipartUpload
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodPost).Path("/{object:.+}").HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.CompleteMultipartUploadHandler, ACTION_WRITE)), "POST")).Queries("uploadId", "{uploadId:.*}")
|
2018-09-04 02:38:10 +08:00
|
|
|
// NewMultipartUpload
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodPost).Path("/{object:.+}").HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.NewMultipartUploadHandler, ACTION_WRITE)), "POST")).Queries("uploads", "")
|
2018-09-04 02:38:10 +08:00
|
|
|
// AbortMultipartUpload
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodDelete).Path("/{object:.+}").HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.AbortMultipartUploadHandler, ACTION_WRITE)), "DELETE")).Queries("uploadId", "{uploadId:.*}")
|
2018-09-04 02:38:10 +08:00
|
|
|
// ListObjectParts
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodGet).Path("/{object:.+}").HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.ListObjectPartsHandler, ACTION_READ)), "GET")).Queries("uploadId", "{uploadId:.*}")
|
2018-09-04 02:38:10 +08:00
|
|
|
// ListMultipartUploads
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodGet).HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.ListMultipartUploadsHandler, ACTION_READ)), "GET")).Queries("uploads", "")
|
2018-09-04 02:38:10 +08:00
|
|
|
|
2020-10-03 13:21:51 +08:00
|
|
|
// GetObjectTagging
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodGet).Path("/{object:.+}").HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.GetObjectTaggingHandler, ACTION_READ)), "GET")).Queries("tagging", "")
|
2020-10-03 13:21:51 +08:00
|
|
|
// PutObjectTagging
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodPut).Path("/{object:.+}").HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.PutObjectTaggingHandler, ACTION_TAGGING)), "PUT")).Queries("tagging", "")
|
2020-10-03 13:21:51 +08:00
|
|
|
// DeleteObjectTagging
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodDelete).Path("/{object:.+}").HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.DeleteObjectTaggingHandler, ACTION_TAGGING)), "DELETE")).Queries("tagging", "")
|
2020-10-03 13:21:51 +08:00
|
|
|
|
2021-09-19 18:24:47 +08:00
|
|
|
// PutObjectACL
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodPut).Path("/{object:.+}").HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.PutObjectAclHandler, ACTION_WRITE_ACP)), "PUT")).Queries("acl", "")
|
2021-09-19 18:24:47 +08:00
|
|
|
// PutObjectRetention
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodPut).Path("/{object:.+}").HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.PutObjectRetentionHandler, ACTION_WRITE)), "PUT")).Queries("retention", "")
|
2021-09-19 18:24:47 +08:00
|
|
|
// PutObjectLegalHold
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodPut).Path("/{object:.+}").HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.PutObjectLegalHoldHandler, ACTION_WRITE)), "PUT")).Queries("legal-hold", "")
|
2021-09-19 18:24:47 +08:00
|
|
|
// PutObjectLockConfiguration
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodPut).Path("/{object:.+}").HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.PutObjectLockConfigurationHandler, ACTION_WRITE)), "PUT")).Queries("object-lock", "")
|
2021-09-19 18:24:47 +08:00
|
|
|
|
2022-02-04 20:14:48 +08:00
|
|
|
// GetObjectACL
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodGet).Path("/{object:.+}").HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.GetObjectAclHandler, ACTION_READ_ACP)), "GET")).Queries("acl", "")
|
2022-02-04 20:14:48 +08:00
|
|
|
|
|
|
|
// objects with query
|
|
|
|
|
|
|
|
// raw objects
|
|
|
|
|
|
|
|
// HeadObject
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodHead).Path("/{object:.+}").HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.HeadObjectHandler, ACTION_READ)), "GET"))
|
2022-02-04 20:14:48 +08:00
|
|
|
|
|
|
|
// GetObject, but directory listing is not supported
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodGet).Path("/{object:.+}").HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.GetObjectHandler, ACTION_READ)), "GET"))
|
2022-02-04 20:14:48 +08:00
|
|
|
|
2020-01-31 16:11:08 +08:00
|
|
|
// CopyObject
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodPut).Path("/{object:.+}").HeadersRegexp("X-Amz-Copy-Source", ".*?(\\/|%2F).*?").HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.CopyObjectHandler, ACTION_WRITE)), "COPY"))
|
2018-09-12 15:46:12 +08:00
|
|
|
// PutObject
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodPut).Path("/{object:.+}").HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.PutObjectHandler, ACTION_WRITE)), "PUT"))
|
2018-07-22 09:49:47 +08:00
|
|
|
// DeleteObject
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodDelete).Path("/{object:.+}").HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.DeleteObjectHandler, ACTION_WRITE)), "DELETE"))
|
2018-07-18 17:37:09 +08:00
|
|
|
|
2022-02-04 20:14:48 +08:00
|
|
|
// raw objects
|
2018-07-22 16:14:36 +08:00
|
|
|
|
2022-02-04 20:14:48 +08:00
|
|
|
// buckets with query
|
2020-09-20 11:14:19 +08:00
|
|
|
|
2018-09-04 15:42:44 +08:00
|
|
|
// DeleteMultipleObjects
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodPost).HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.DeleteMultipleObjectsHandler, ACTION_WRITE)), "DELETE")).Queries("delete", "")
|
2021-10-11 18:03:56 +08:00
|
|
|
|
|
|
|
// GetBucketACL
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodGet).HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.GetBucketAclHandler, ACTION_READ_ACP)), "GET")).Queries("acl", "")
|
2022-02-03 22:17:05 +08:00
|
|
|
// PutBucketACL
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodPut).HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.PutBucketAclHandler, ACTION_WRITE_ACP)), "PUT")).Queries("acl", "")
|
2022-02-03 22:17:05 +08:00
|
|
|
|
2022-02-04 20:14:48 +08:00
|
|
|
// GetBucketPolicy
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodGet).HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.GetBucketPolicyHandler, ACTION_READ)), "GET")).Queries("policy", "")
|
2022-02-03 22:17:05 +08:00
|
|
|
// PutBucketPolicy
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodPut).HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.PutBucketPolicyHandler, ACTION_WRITE)), "PUT")).Queries("policy", "")
|
2022-02-03 22:17:05 +08:00
|
|
|
// DeleteBucketPolicy
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodDelete).HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.DeleteBucketPolicyHandler, ACTION_WRITE)), "DELETE")).Queries("policy", "")
|
2022-02-03 22:17:05 +08:00
|
|
|
|
|
|
|
// GetBucketCors
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodGet).HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.GetBucketCorsHandler, ACTION_READ)), "GET")).Queries("cors", "")
|
2022-02-03 22:17:05 +08:00
|
|
|
// PutBucketCors
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodPut).HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.PutBucketCorsHandler, ACTION_WRITE)), "PUT")).Queries("cors", "")
|
2022-02-03 22:17:05 +08:00
|
|
|
// DeleteBucketCors
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodDelete).HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.DeleteBucketCorsHandler, ACTION_WRITE)), "DELETE")).Queries("cors", "")
|
2022-02-04 20:14:48 +08:00
|
|
|
|
|
|
|
// GetBucketLifecycleConfiguration
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodGet).HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.GetBucketLifecycleConfigurationHandler, ACTION_READ)), "GET")).Queries("lifecycle", "")
|
2022-02-04 20:14:48 +08:00
|
|
|
// PutBucketLifecycleConfiguration
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodPut).HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.PutBucketLifecycleConfigurationHandler, ACTION_WRITE)), "PUT")).Queries("lifecycle", "")
|
2022-02-04 20:14:48 +08:00
|
|
|
// DeleteBucketLifecycleConfiguration
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodDelete).HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.DeleteBucketLifecycleHandler, ACTION_WRITE)), "DELETE")).Queries("lifecycle", "")
|
2022-02-03 22:17:05 +08:00
|
|
|
|
|
|
|
// GetBucketLocation
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodGet).HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.GetBucketLocationHandler, ACTION_READ)), "GET")).Queries("location", "")
|
2022-02-03 22:17:05 +08:00
|
|
|
|
|
|
|
// GetBucketRequestPayment
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodGet).HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.GetBucketRequestPaymentHandler, ACTION_READ)), "GET")).Queries("requestPayment", "")
|
2021-10-11 18:03:56 +08:00
|
|
|
|
2023-11-13 18:25:17 +08:00
|
|
|
// GetBucketVersioning
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodGet).HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.GetBucketVersioningHandler, ACTION_READ)), "GET")).Queries("versioning", "")
|
|
|
|
bucket.Methods(http.MethodPut).HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.PutBucketVersioningHandler, ACTION_WRITE)), "PUT")).Queries("versioning", "")
|
2023-11-13 18:25:17 +08:00
|
|
|
|
2022-02-04 20:14:48 +08:00
|
|
|
// ListObjectsV2
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodGet).HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.ListObjectsV2Handler, ACTION_LIST)), "LIST")).Queries("list-type", "2")
|
2021-10-11 18:03:56 +08:00
|
|
|
|
2022-02-04 20:14:48 +08:00
|
|
|
// buckets with query
|
2022-10-02 10:18:00 +08:00
|
|
|
// PutBucketOwnershipControls
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodPut).HandlerFunc(track(s3a.iam.Auth(s3a.PutBucketOwnershipControls, ACTION_ADMIN), "PUT")).Queries("ownershipControls", "")
|
2022-10-02 10:18:00 +08:00
|
|
|
|
|
|
|
//GetBucketOwnershipControls
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodGet).HandlerFunc(track(s3a.iam.Auth(s3a.GetBucketOwnershipControls, ACTION_READ), "GET")).Queries("ownershipControls", "")
|
2022-10-02 10:18:00 +08:00
|
|
|
|
|
|
|
//DeleteBucketOwnershipControls
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodDelete).HandlerFunc(track(s3a.iam.Auth(s3a.DeleteBucketOwnershipControls, ACTION_ADMIN), "DELETE")).Queries("ownershipControls", "")
|
2021-10-11 18:03:56 +08:00
|
|
|
|
2022-02-04 20:14:48 +08:00
|
|
|
// raw buckets
|
2021-10-11 18:03:56 +08:00
|
|
|
|
2022-02-04 20:14:48 +08:00
|
|
|
// PostPolicy
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodPost).HeadersRegexp("Content-Type", "multipart/form-data*").HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.PostPolicyBucketHandler, ACTION_WRITE)), "POST"))
|
2022-02-04 20:14:48 +08:00
|
|
|
|
|
|
|
// HeadBucket
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodHead).HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.HeadBucketHandler, ACTION_READ)), "GET"))
|
2021-10-28 21:30:33 +08:00
|
|
|
|
|
|
|
// PutBucket
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodPut).HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.PutBucketHandler, ACTION_ADMIN)), "PUT"))
|
2024-02-19 19:07:48 +08:00
|
|
|
|
2021-10-28 21:30:33 +08:00
|
|
|
// DeleteBucket
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodDelete).HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.DeleteBucketHandler, ACTION_DELETE_BUCKET)), "DELETE"))
|
2022-02-04 20:14:48 +08:00
|
|
|
|
|
|
|
// ListObjectsV1 (Legacy)
|
2024-07-01 16:00:39 +08:00
|
|
|
bucket.Methods(http.MethodGet).HandlerFunc(track(s3a.iam.Auth(s3a.cb.Limit(s3a.ListObjectsV1Handler, ACTION_LIST)), "LIST"))
|
2022-02-04 20:14:48 +08:00
|
|
|
|
|
|
|
// raw buckets
|
|
|
|
|
2018-07-18 17:37:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListBuckets
|
2024-07-01 16:00:39 +08:00
|
|
|
apiRouter.Methods(http.MethodGet).Path("/").HandlerFunc(track(s3a.ListBucketsHandler, "LIST"))
|
2018-07-18 17:37:09 +08:00
|
|
|
|
|
|
|
// NotFound
|
2021-06-11 12:50:21 +08:00
|
|
|
apiRouter.NotFoundHandler = http.HandlerFunc(s3err.NotFoundHandler)
|
2018-07-18 17:37:09 +08:00
|
|
|
|
|
|
|
}
|