2021-04-18 15:41:13 -04:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-05-10 00:02:26 -04:00
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/xml"
|
2020-02-16 01:07:52 -05:00
|
|
|
"io"
|
2018-05-10 00:02:26 -04:00
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2021-06-01 17:59:40 -04:00
|
|
|
xhttp "github.com/minio/minio/internal/http"
|
|
|
|
"github.com/minio/minio/internal/logger"
|
2021-05-30 00:16:42 -04:00
|
|
|
"github.com/minio/pkg/bucket/policy"
|
2018-05-10 00:02:26 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// Data types used for returning dummy access control
|
|
|
|
// policy XML, these variables shouldn't be used elsewhere
|
|
|
|
// they are only defined to be used in this file alone.
|
|
|
|
type grantee struct {
|
|
|
|
XMLNS string `xml:"xmlns:xsi,attr"`
|
|
|
|
XMLXSI string `xml:"xsi:type,attr"`
|
|
|
|
Type string `xml:"Type"`
|
|
|
|
ID string `xml:"ID,omitempty"`
|
|
|
|
DisplayName string `xml:"DisplayName,omitempty"`
|
|
|
|
URI string `xml:"URI,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type grant struct {
|
|
|
|
Grantee grantee `xml:"Grantee"`
|
|
|
|
Permission string `xml:"Permission"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type accessControlPolicy struct {
|
|
|
|
XMLName xml.Name `xml:"AccessControlPolicy"`
|
|
|
|
Owner Owner `xml:"Owner"`
|
|
|
|
AccessControlList struct {
|
|
|
|
Grants []grant `xml:"Grant"`
|
|
|
|
} `xml:"AccessControlList"`
|
|
|
|
}
|
|
|
|
|
2020-02-16 01:07:52 -05:00
|
|
|
// PutBucketACLHandler - PUT Bucket ACL
|
|
|
|
// -----------------
|
|
|
|
// This operation uses the ACL subresource
|
|
|
|
// to set ACL for a bucket, this is a dummy call
|
|
|
|
// only responds success if the ACL is private.
|
|
|
|
func (api objectAPIHandlers) PutBucketACLHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
ctx := newContext(r, w, "PutBucketACL")
|
|
|
|
|
2021-01-26 16:21:51 -05:00
|
|
|
defer logger.AuditLog(ctx, w, r, mustGetClaimsFromToken(r))
|
2020-02-16 01:07:52 -05:00
|
|
|
|
|
|
|
vars := mux.Vars(r)
|
|
|
|
bucket := vars["bucket"]
|
|
|
|
|
|
|
|
objAPI := api.ObjectAPI()
|
|
|
|
if objAPI == nil {
|
2021-04-29 22:01:43 -04:00
|
|
|
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrServerNotInitialized), r.URL, guessIsBrowserReq(r))
|
2020-02-16 01:07:52 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allow putBucketACL if policy action is set, since this is a dummy call
|
|
|
|
// we are simply re-purposing the bucketPolicyAction.
|
|
|
|
if s3Error := checkRequestAuthType(ctx, r, policy.PutBucketPolicyAction, bucket, ""); s3Error != ErrNone {
|
2021-04-29 22:01:43 -04:00
|
|
|
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(s3Error), r.URL, guessIsBrowserReq(r))
|
2020-02-16 01:07:52 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Before proceeding validate if bucket exists.
|
|
|
|
_, err := objAPI.GetBucketInfo(ctx, bucket)
|
|
|
|
if err != nil {
|
2021-04-29 22:01:43 -04:00
|
|
|
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r))
|
2020-02-16 01:07:52 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
aclHeader := r.Header.Get(xhttp.AmzACL)
|
|
|
|
if aclHeader == "" {
|
|
|
|
acl := &accessControlPolicy{}
|
|
|
|
if err = xmlDecoder(r.Body, acl, r.ContentLength); err != nil {
|
|
|
|
if err == io.EOF {
|
|
|
|
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrMissingSecurityHeader),
|
2021-04-29 22:01:43 -04:00
|
|
|
r.URL, guessIsBrowserReq(r))
|
2020-02-16 01:07:52 -05:00
|
|
|
return
|
|
|
|
}
|
2021-04-29 22:01:43 -04:00
|
|
|
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r))
|
2020-02-16 01:07:52 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(acl.AccessControlList.Grants) == 0 {
|
2021-04-29 22:01:43 -04:00
|
|
|
writeErrorResponse(ctx, w, toAPIError(ctx, NotImplemented{}), r.URL, guessIsBrowserReq(r))
|
2020-02-16 01:07:52 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if acl.AccessControlList.Grants[0].Permission != "FULL_CONTROL" {
|
2021-04-29 22:01:43 -04:00
|
|
|
writeErrorResponse(ctx, w, toAPIError(ctx, NotImplemented{}), r.URL, guessIsBrowserReq(r))
|
2020-02-16 01:07:52 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if aclHeader != "" && aclHeader != "private" {
|
2021-04-29 22:01:43 -04:00
|
|
|
writeErrorResponse(ctx, w, toAPIError(ctx, NotImplemented{}), r.URL, guessIsBrowserReq(r))
|
2020-02-16 01:07:52 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
w.(http.Flusher).Flush()
|
|
|
|
}
|
|
|
|
|
2018-05-10 00:02:26 -04:00
|
|
|
// GetBucketACLHandler - GET Bucket ACL
|
|
|
|
// -----------------
|
|
|
|
// This operation uses the ACL
|
|
|
|
// subresource to return the ACL of a specified bucket.
|
|
|
|
func (api objectAPIHandlers) GetBucketACLHandler(w http.ResponseWriter, r *http.Request) {
|
2018-07-20 21:46:32 -04:00
|
|
|
ctx := newContext(r, w, "GetBucketACL")
|
2018-05-10 00:02:26 -04:00
|
|
|
|
2021-01-26 16:21:51 -05:00
|
|
|
defer logger.AuditLog(ctx, w, r, mustGetClaimsFromToken(r))
|
2018-10-12 15:25:59 -04:00
|
|
|
|
2018-05-10 00:02:26 -04:00
|
|
|
vars := mux.Vars(r)
|
|
|
|
bucket := vars["bucket"]
|
|
|
|
|
|
|
|
objAPI := api.ObjectAPI()
|
|
|
|
if objAPI == nil {
|
2021-04-29 22:01:43 -04:00
|
|
|
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrServerNotInitialized), r.URL, guessIsBrowserReq(r))
|
2018-05-10 00:02:26 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allow getBucketACL if policy action is set, since this is a dummy call
|
|
|
|
// we are simply re-purposing the bucketPolicyAction.
|
|
|
|
if s3Error := checkRequestAuthType(ctx, r, policy.GetBucketPolicyAction, bucket, ""); s3Error != ErrNone {
|
2021-04-29 22:01:43 -04:00
|
|
|
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(s3Error), r.URL, guessIsBrowserReq(r))
|
2018-05-10 00:02:26 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Before proceeding validate if bucket exists.
|
|
|
|
_, err := objAPI.GetBucketInfo(ctx, bucket)
|
|
|
|
if err != nil {
|
2021-04-29 22:01:43 -04:00
|
|
|
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r))
|
2018-05-10 00:02:26 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
acl := &accessControlPolicy{}
|
|
|
|
acl.AccessControlList.Grants = append(acl.AccessControlList.Grants, grant{
|
|
|
|
Grantee: grantee{
|
2018-05-31 22:43:50 -04:00
|
|
|
XMLNS: "http://www.w3.org/2001/XMLSchema-instance",
|
|
|
|
XMLXSI: "CanonicalUser",
|
|
|
|
Type: "CanonicalUser",
|
2018-05-10 00:02:26 -04:00
|
|
|
},
|
|
|
|
Permission: "FULL_CONTROL",
|
|
|
|
})
|
2020-05-19 16:53:54 -04:00
|
|
|
|
2018-05-10 00:02:26 -04:00
|
|
|
if err := xml.NewEncoder(w).Encode(acl); err != nil {
|
2021-04-29 22:01:43 -04:00
|
|
|
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r))
|
2018-05-10 00:02:26 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
w.(http.Flusher).Flush()
|
|
|
|
}
|
|
|
|
|
2020-02-16 01:07:52 -05:00
|
|
|
// PutObjectACLHandler - PUT Object ACL
|
|
|
|
// -----------------
|
|
|
|
// This operation uses the ACL subresource
|
|
|
|
// to set ACL for a bucket, this is a dummy call
|
|
|
|
// only responds success if the ACL is private.
|
|
|
|
func (api objectAPIHandlers) PutObjectACLHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
ctx := newContext(r, w, "PutObjectACL")
|
|
|
|
|
2021-01-26 16:21:51 -05:00
|
|
|
defer logger.AuditLog(ctx, w, r, mustGetClaimsFromToken(r))
|
2020-02-16 01:07:52 -05:00
|
|
|
|
|
|
|
vars := mux.Vars(r)
|
|
|
|
bucket := vars["bucket"]
|
2021-03-09 15:58:22 -05:00
|
|
|
object, err := unescapePath(vars["object"])
|
2020-02-16 01:07:52 -05:00
|
|
|
if err != nil {
|
2021-04-29 22:01:43 -04:00
|
|
|
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r))
|
2020-02-16 01:07:52 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
objAPI := api.ObjectAPI()
|
|
|
|
if objAPI == nil {
|
2021-04-29 22:01:43 -04:00
|
|
|
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrServerNotInitialized), r.URL, guessIsBrowserReq(r))
|
2020-02-16 01:07:52 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allow putObjectACL if policy action is set, since this is a dummy call
|
|
|
|
// we are simply re-purposing the bucketPolicyAction.
|
|
|
|
if s3Error := checkRequestAuthType(ctx, r, policy.PutBucketPolicyAction, bucket, ""); s3Error != ErrNone {
|
2021-04-29 22:01:43 -04:00
|
|
|
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(s3Error), r.URL, guessIsBrowserReq(r))
|
2020-02-16 01:07:52 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Before proceeding validate if object exists.
|
|
|
|
_, err = objAPI.GetObjectInfo(ctx, bucket, object, ObjectOptions{})
|
|
|
|
if err != nil {
|
2021-04-29 22:01:43 -04:00
|
|
|
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r))
|
2020-02-16 01:07:52 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
aclHeader := r.Header.Get(xhttp.AmzACL)
|
|
|
|
if aclHeader == "" {
|
|
|
|
acl := &accessControlPolicy{}
|
|
|
|
if err = xmlDecoder(r.Body, acl, r.ContentLength); err != nil {
|
2021-04-29 22:01:43 -04:00
|
|
|
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r))
|
2020-02-16 01:07:52 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(acl.AccessControlList.Grants) == 0 {
|
2021-04-29 22:01:43 -04:00
|
|
|
writeErrorResponse(ctx, w, toAPIError(ctx, NotImplemented{}), r.URL, guessIsBrowserReq(r))
|
2020-02-16 01:07:52 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if acl.AccessControlList.Grants[0].Permission != "FULL_CONTROL" {
|
2021-04-29 22:01:43 -04:00
|
|
|
writeErrorResponse(ctx, w, toAPIError(ctx, NotImplemented{}), r.URL, guessIsBrowserReq(r))
|
2020-02-16 01:07:52 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if aclHeader != "" && aclHeader != "private" {
|
2021-04-29 22:01:43 -04:00
|
|
|
writeErrorResponse(ctx, w, toAPIError(ctx, NotImplemented{}), r.URL, guessIsBrowserReq(r))
|
2020-02-16 01:07:52 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
w.(http.Flusher).Flush()
|
|
|
|
}
|
|
|
|
|
2018-05-10 00:02:26 -04:00
|
|
|
// GetObjectACLHandler - GET Object ACL
|
|
|
|
// -----------------
|
|
|
|
// This operation uses the ACL
|
|
|
|
// subresource to return the ACL of a specified object.
|
|
|
|
func (api objectAPIHandlers) GetObjectACLHandler(w http.ResponseWriter, r *http.Request) {
|
2018-07-20 21:46:32 -04:00
|
|
|
ctx := newContext(r, w, "GetObjectACL")
|
2018-05-10 00:02:26 -04:00
|
|
|
|
2021-01-26 16:21:51 -05:00
|
|
|
defer logger.AuditLog(ctx, w, r, mustGetClaimsFromToken(r))
|
2018-10-12 15:25:59 -04:00
|
|
|
|
2018-05-10 00:02:26 -04:00
|
|
|
vars := mux.Vars(r)
|
|
|
|
bucket := vars["bucket"]
|
2021-03-09 15:58:22 -05:00
|
|
|
object, err := unescapePath(vars["object"])
|
2020-02-11 22:38:02 -05:00
|
|
|
if err != nil {
|
2021-04-29 22:01:43 -04:00
|
|
|
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r))
|
2020-02-11 22:38:02 -05:00
|
|
|
return
|
|
|
|
}
|
2018-05-10 00:02:26 -04:00
|
|
|
|
|
|
|
objAPI := api.ObjectAPI()
|
|
|
|
if objAPI == nil {
|
2021-04-29 22:01:43 -04:00
|
|
|
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrServerNotInitialized), r.URL, guessIsBrowserReq(r))
|
2018-05-10 00:02:26 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allow getObjectACL if policy action is set, since this is a dummy call
|
|
|
|
// we are simply re-purposing the bucketPolicyAction.
|
|
|
|
if s3Error := checkRequestAuthType(ctx, r, policy.GetBucketPolicyAction, bucket, ""); s3Error != ErrNone {
|
2021-04-29 22:01:43 -04:00
|
|
|
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(s3Error), r.URL, guessIsBrowserReq(r))
|
2018-05-10 00:02:26 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Before proceeding validate if object exists.
|
2020-02-11 22:38:02 -05:00
|
|
|
_, err = objAPI.GetObjectInfo(ctx, bucket, object, ObjectOptions{})
|
2018-05-10 00:02:26 -04:00
|
|
|
if err != nil {
|
2021-04-29 22:01:43 -04:00
|
|
|
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r))
|
2018-05-10 00:02:26 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
acl := &accessControlPolicy{}
|
|
|
|
acl.AccessControlList.Grants = append(acl.AccessControlList.Grants, grant{
|
|
|
|
Grantee: grantee{
|
2018-05-31 22:43:50 -04:00
|
|
|
XMLNS: "http://www.w3.org/2001/XMLSchema-instance",
|
|
|
|
XMLXSI: "CanonicalUser",
|
|
|
|
Type: "CanonicalUser",
|
2018-05-10 00:02:26 -04:00
|
|
|
},
|
|
|
|
Permission: "FULL_CONTROL",
|
|
|
|
})
|
|
|
|
if err := xml.NewEncoder(w).Encode(acl); err != nil {
|
2021-04-29 22:01:43 -04:00
|
|
|
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r))
|
2018-05-10 00:02:26 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
w.(http.Flusher).Flush()
|
|
|
|
}
|