2018-05-10 00:02:26 -04:00
|
|
|
/*
|
|
|
|
* Minio Cloud Storage, (C) 2018 Minio, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/xml"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2018-10-12 15:25:59 -04:00
|
|
|
"github.com/minio/minio/cmd/logger"
|
2018-05-10 00:02:26 -04:00
|
|
|
"github.com/minio/minio/pkg/policy"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2018-11-02 21:40:08 -04:00
|
|
|
defer logger.AuditLog(ctx, w, 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 {
|
|
|
|
writeErrorResponse(w, ErrServerNotInitialized, r.URL)
|
|
|
|
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 {
|
|
|
|
writeErrorResponse(w, s3Error, r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Before proceeding validate if bucket exists.
|
|
|
|
_, err := objAPI.GetBucketInfo(ctx, bucket)
|
|
|
|
if err != nil {
|
|
|
|
writeErrorResponse(w, toAPIErrorCode(err), r.URL)
|
|
|
|
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 {
|
|
|
|
writeErrorResponse(w, toAPIErrorCode(err), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
w.(http.Flusher).Flush()
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2018-11-02 21:40:08 -04:00
|
|
|
defer logger.AuditLog(ctx, w, r)
|
2018-10-12 15:25:59 -04:00
|
|
|
|
2018-05-10 00:02:26 -04:00
|
|
|
vars := mux.Vars(r)
|
|
|
|
bucket := vars["bucket"]
|
|
|
|
object := vars["object"]
|
|
|
|
|
|
|
|
objAPI := api.ObjectAPI()
|
|
|
|
if objAPI == nil {
|
|
|
|
writeErrorResponse(w, ErrServerNotInitialized, r.URL)
|
|
|
|
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 {
|
|
|
|
writeErrorResponse(w, s3Error, r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Before proceeding validate if object exists.
|
2018-09-10 12:42:43 -04:00
|
|
|
_, err := objAPI.GetObjectInfo(ctx, bucket, object, ObjectOptions{})
|
2018-05-10 00:02:26 -04:00
|
|
|
if err != nil {
|
|
|
|
writeErrorResponse(w, toAPIErrorCode(err), r.URL)
|
|
|
|
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 {
|
|
|
|
writeErrorResponse(w, toAPIErrorCode(err), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
w.(http.Flusher).Flush()
|
|
|
|
}
|