For non-canned policies, show policy status as custom (#2716)
This commit is contained in:
@@ -40,4 +40,5 @@ const (
|
||||
accessDownload = accessPerms("download")
|
||||
accessUpload = accessPerms("upload")
|
||||
accessPublic = accessPerms("public")
|
||||
accessCustom = accessPerms("custom")
|
||||
)
|
||||
|
||||
+8
-8
@@ -893,28 +893,28 @@ func (f *fsClient) GetAccessRules() (map[string]string, *probe.Error) {
|
||||
}
|
||||
|
||||
// GetAccess - get access policy permissions.
|
||||
func (f *fsClient) GetAccess() (access string, err *probe.Error) {
|
||||
func (f *fsClient) GetAccess() (access string, policyJSON string, err *probe.Error) {
|
||||
// For windows this feature is not implemented.
|
||||
if runtime.GOOS == "windows" {
|
||||
return "", probe.NewError(APINotImplemented{API: "GetAccess", APIType: "filesystem"})
|
||||
return "", "", probe.NewError(APINotImplemented{API: "GetAccess", APIType: "filesystem"})
|
||||
}
|
||||
st, err := f.fsStat(false)
|
||||
if err != nil {
|
||||
return "", err.Trace(f.PathURL.String())
|
||||
return "", "", err.Trace(f.PathURL.String())
|
||||
}
|
||||
if !st.Mode().IsDir() {
|
||||
return "", probe.NewError(APINotImplemented{API: "GetAccess", APIType: "filesystem"})
|
||||
return "", "", probe.NewError(APINotImplemented{API: "GetAccess", APIType: "filesystem"})
|
||||
}
|
||||
// Mask with os.ModePerm to get only inode permissions
|
||||
switch st.Mode() & os.ModePerm {
|
||||
case os.FileMode(0777):
|
||||
return "readwrite", nil
|
||||
return "readwrite", "", nil
|
||||
case os.FileMode(0555):
|
||||
return "readonly", nil
|
||||
return "readonly", "", nil
|
||||
case os.FileMode(0333):
|
||||
return "writeonly", nil
|
||||
return "writeonly", "", nil
|
||||
}
|
||||
return "none", nil
|
||||
return "none", "", nil
|
||||
}
|
||||
|
||||
// SetAccess - set access policy permissions.
|
||||
|
||||
@@ -231,7 +231,7 @@ func (s *TestSuite) TestBucketACLFails(c *C) {
|
||||
err = fsClient.SetAccess("readonly", false)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
_, err = fsClient.GetAccess()
|
||||
_, _, err = fsClient.GetAccess()
|
||||
c.Assert(err, IsNil)
|
||||
}
|
||||
}
|
||||
|
||||
+10
-6
@@ -1050,23 +1050,27 @@ func (c *s3Client) GetAccessRules() (map[string]string, *probe.Error) {
|
||||
}
|
||||
|
||||
// GetAccess get access policy permissions.
|
||||
func (c *s3Client) GetAccess() (string, *probe.Error) {
|
||||
func (c *s3Client) GetAccess() (string, string, *probe.Error) {
|
||||
bucket, object := c.url2BucketAndObject()
|
||||
if bucket == "" {
|
||||
return "", probe.NewError(BucketNameEmpty{})
|
||||
return "", "", probe.NewError(BucketNameEmpty{})
|
||||
}
|
||||
policyStr, e := c.api.GetBucketPolicy(bucket)
|
||||
if e != nil {
|
||||
return "", probe.NewError(e)
|
||||
return "", "", probe.NewError(e)
|
||||
}
|
||||
if policyStr == "" {
|
||||
return string(policy.BucketPolicyNone), nil
|
||||
return string(policy.BucketPolicyNone), policyStr, nil
|
||||
}
|
||||
var p policy.BucketAccessPolicy
|
||||
if e = json.Unmarshal([]byte(policyStr), &p); e != nil {
|
||||
return "", probe.NewError(e)
|
||||
return "", "", probe.NewError(e)
|
||||
}
|
||||
return string(policy.GetPolicy(p.Statements, bucket, object)), nil
|
||||
pType := string(policy.GetPolicy(p.Statements, bucket, object))
|
||||
if pType == string(policy.BucketPolicyNone) && policyStr != "" {
|
||||
pType = "custom"
|
||||
}
|
||||
return pType, policyStr, nil
|
||||
}
|
||||
|
||||
// SetAccess set access policy permissions.
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ type Client interface {
|
||||
MakeBucket(region string, ignoreExisting bool) *probe.Error
|
||||
|
||||
// Access policy operations.
|
||||
GetAccess() (access string, error *probe.Error)
|
||||
GetAccess() (access string, policyJSON string, error *probe.Error)
|
||||
GetAccessRules() (policyRules map[string]string, error *probe.Error)
|
||||
SetAccess(access string, isJSON bool) *probe.Error
|
||||
|
||||
|
||||
+1
-1
@@ -618,7 +618,7 @@ func copyBucketPolicies(srcClt, dstClt Client, isOverwrite bool) *probe.Error {
|
||||
}
|
||||
// Set found rules to target bucket if permitted
|
||||
for _, r := range rules {
|
||||
originalRule, err := dstClt.GetAccess()
|
||||
originalRule, _, err := dstClt.GetAccess()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+23
-11
@@ -113,10 +113,11 @@ func (s policyRules) JSON() string {
|
||||
|
||||
// policyMessage is container for policy command on bucket success and failure messages.
|
||||
type policyMessage struct {
|
||||
Operation string `json:"operation"`
|
||||
Status string `json:"status"`
|
||||
Bucket string `json:"bucket"`
|
||||
Perms accessPerms `json:"permission"`
|
||||
Operation string `json:"operation"`
|
||||
Status string `json:"status"`
|
||||
Bucket string `json:"bucket"`
|
||||
Perms accessPerms `json:"permission"`
|
||||
Policy map[string]interface{} `json:"policy,omitempty"`
|
||||
}
|
||||
|
||||
// String colorized access message.
|
||||
@@ -216,6 +217,8 @@ func accessPermToString(perm accessPerms) string {
|
||||
policy = "writeonly"
|
||||
case accessPublic:
|
||||
policy = "readwrite"
|
||||
case accessCustom:
|
||||
policy = "custom"
|
||||
}
|
||||
return policy
|
||||
}
|
||||
@@ -275,21 +278,23 @@ func stringToAccessPerm(perm string) accessPerms {
|
||||
policy = accessUpload
|
||||
case "readwrite":
|
||||
policy = accessPublic
|
||||
case "custom":
|
||||
policy = accessCustom
|
||||
}
|
||||
return policy
|
||||
}
|
||||
|
||||
// doGetAccess do get access.
|
||||
func doGetAccess(targetURL string) (perms accessPerms, err *probe.Error) {
|
||||
func doGetAccess(targetURL string) (perms accessPerms, policyStr string, err *probe.Error) {
|
||||
clnt, err := newClient(targetURL)
|
||||
if err != nil {
|
||||
return "", err.Trace(targetURL)
|
||||
return "", "", err.Trace(targetURL)
|
||||
}
|
||||
perm, err := clnt.GetAccess()
|
||||
perm, policyJSON, err := clnt.GetAccess()
|
||||
if err != nil {
|
||||
return "", err.Trace(targetURL)
|
||||
return "", "", err.Trace(targetURL)
|
||||
}
|
||||
return stringToAccessPerm(perm), nil
|
||||
return stringToAccessPerm(perm), policyJSON, nil
|
||||
}
|
||||
|
||||
// doGetAccessRules do get access rules.
|
||||
@@ -388,7 +393,7 @@ func runPolicyLinksCmd(ctx *cli.Context) {
|
||||
|
||||
// Run policy cmd to fetch set permission
|
||||
func runPolicyCmd(ctx *cli.Context) {
|
||||
var operation string
|
||||
var operation, policyStr string
|
||||
var probeErr *probe.Error
|
||||
perms := accessPerms(ctx.Args().First())
|
||||
targetURL := ctx.Args().Last()
|
||||
@@ -400,7 +405,7 @@ func runPolicyCmd(ctx *cli.Context) {
|
||||
operation = "setJSON"
|
||||
} else {
|
||||
targetURL = ctx.Args().First()
|
||||
perms, probeErr = doGetAccess(targetURL)
|
||||
perms, policyStr, probeErr = doGetAccess(targetURL)
|
||||
operation = "get"
|
||||
}
|
||||
// Upon error exit.
|
||||
@@ -413,11 +418,18 @@ func runPolicyCmd(ctx *cli.Context) {
|
||||
"Unable to "+operation+" policy `"+string(perms)+"` for `"+targetURL+"`.")
|
||||
}
|
||||
}
|
||||
policyJSON := map[string]interface{}{}
|
||||
if policyStr != "" {
|
||||
e := json.Unmarshal([]byte(policyStr), &policyJSON)
|
||||
fatalIf(probe.NewError(e), "Cannot unmarshal custom policy file.")
|
||||
}
|
||||
|
||||
printMsg(policyMessage{
|
||||
Status: "success",
|
||||
Operation: operation,
|
||||
Bucket: targetURL,
|
||||
Perms: perms,
|
||||
Policy: policyJSON,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -91,7 +91,7 @@ ENVIRONMENT VARIABLES:
|
||||
MC_ENCRYPT_KEY: list of comma delimited prefix=secret values
|
||||
|
||||
SERIALIZATION OPTIONS:
|
||||
For query serialization options, refer to https://docs.minio.io/docs/minio-client-complete-guide#sql
|
||||
For query serialization options, refer to https://docs.minio.io/docs/minio-client-complete-guide#sql
|
||||
|
||||
EXAMPLES:
|
||||
1. Run a query on a set of objects recursively on AWS S3.
|
||||
|
||||
Reference in New Issue
Block a user