diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md
index d4348123..186f83dc 100644
--- a/.github/ISSUE_TEMPLATE.md
+++ b/.github/ISSUE_TEMPLATE.md
@@ -1,8 +1,8 @@
-## Expected behaviour
+## Expected behavior
-## Actual behaviour
+## Actual behavior
-## Steps to reproduce the behaviour
+## Steps to reproduce the behavior
## mc version
- (paste output of `mc version`)
diff --git a/buildscripts/checkdeps.sh b/buildscripts/checkdeps.sh
index 54ff6d59..c3dc5745 100755
--- a/buildscripts/checkdeps.sh
+++ b/buildscripts/checkdeps.sh
@@ -34,7 +34,7 @@ _init() {
## FIXME:
## In OSX, 'readlink -f' option does not exist, hence
-## we have our own readlink -f behaviour here.
+## we have our own readlink -f behavior here.
## Once OSX has the option, below function is good enough.
##
## readlink() {
diff --git a/cmd/admin-credentials.go b/cmd/admin-credentials.go
index ce52829f..db700719 100644
--- a/cmd/admin-credentials.go
+++ b/cmd/admin-credentials.go
@@ -1,5 +1,5 @@
/*
- * Minio Client (C) 2016, 2017 Minio, Inc.
+ * Minio Client (C) 2016, 2017, 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.
@@ -29,7 +29,7 @@ const credsCmdName = "credentials"
var adminCredsCmd = cli.Command{
Name: credsCmdName,
- Usage: "Change server access and secret keys",
+ Usage: "Change Admin server access and secret keys",
Action: mainAdminCreds,
Flags: append(adminCredsFlags, globalFlags...),
CustomHelpTemplate: `NAME:
@@ -42,8 +42,8 @@ FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}
EXAMPLES:
- 1. Set new credentials of a Minio server represented by its alias 'play'.
- $ {{.HelpName}} play/ minio minio123
+ 1. Set new **admin** credentials of a Minio server represented by its alias 'alias'.
+ $ {{.HelpName}} alias/ minio minio123
`,
}
@@ -74,7 +74,7 @@ func mainAdminCreds(ctx *cli.Context) error {
fatalIf(err, "Cannot get a configured admin connection.")
// Change the credentials of the specified Minio server
- e := client.SetCredentials(accessKey, secretKey)
+ e := client.SetAdminCredentials(accessKey, secretKey)
fatalIf(probe.NewError(e), "Unable to set new credentials to '"+aliasedURL+"'.")
return nil
diff --git a/cmd/admin-main.go b/cmd/admin-main.go
index 037f927a..143bbd79 100644
--- a/cmd/admin-main.go
+++ b/cmd/admin-main.go
@@ -32,6 +32,8 @@ var adminCmd = cli.Command{
Subcommands: []cli.Command{
adminServiceCmd,
adminInfoCmd,
+ adminUsersCmd,
+ adminPoliciesCmd,
adminCredsCmd,
adminConfigCmd,
adminHealCmd,
diff --git a/cmd/admin-policies-add.go b/cmd/admin-policies-add.go
new file mode 100644
index 00000000..f4d10f84
--- /dev/null
+++ b/cmd/admin-policies-add.go
@@ -0,0 +1,123 @@
+/*
+ * Minio Client (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/json"
+ "io/ioutil"
+
+ "github.com/fatih/color"
+ "github.com/minio/cli"
+ "github.com/minio/mc/pkg/console"
+ "github.com/minio/mc/pkg/probe"
+)
+
+var adminPoliciesAddCmd = cli.Command{
+ Name: "add",
+ Usage: "Add new policies",
+ Action: mainAdminPoliciesAdd,
+ Before: setGlobalsFromContext,
+ Flags: globalFlags,
+ CustomHelpTemplate: `NAME:
+ {{.HelpName}} - {{.Usage}}
+
+USAGE:
+ {{.HelpName}} TARGET POLICYNAME POLICYFILE
+
+POLICYNAME:
+ Name of the canned policy on Minio server.
+
+POLICYFILE:
+ Name of the policy file associated with the policy name.
+
+FLAGS:
+ {{range .VisibleFlags}}{{.}}
+ {{end}}
+EXAMPLES:
+ 1. Add a new canned policy 'writeonly'.
+ $ {{.HelpName}} myminio writeonly /tmp/writeonly.json
+ `,
+}
+
+// checkAdminPoliciesAddSyntax - validate all the passed arguments
+func checkAdminPoliciesAddSyntax(ctx *cli.Context) {
+ if len(ctx.Args()) != 3 {
+ cli.ShowCommandHelpAndExit(ctx, "add", 1) // last argument is exit code
+ }
+}
+
+// userPolicyMessage container for content message structure
+type userPolicyMessage struct {
+ op string
+ Status string `json:"status"`
+ Policy string `json:"policy,omitempty"`
+ PolicyJSON []byte `json:"policyJSON,omitempty"`
+}
+
+func (u userPolicyMessage) String() string {
+ switch u.op {
+ case "list":
+ if len(u.PolicyJSON) > 0 {
+ return string(u.PolicyJSON)
+ }
+ policyFieldMaxLen := 20
+ // Create a new pretty table with cols configuration
+ return newPrettyTable(" ",
+ Field{"Policy", policyFieldMaxLen},
+ ).buildRow(u.Policy)
+ case "remove":
+ return console.Colorize("PolicyMessage", "Removed policy `"+u.Policy+"` successfully.")
+ case "add":
+ return console.Colorize("PolicyMessage", "Added policy `"+u.Policy+"` successfully.")
+ }
+ return ""
+}
+
+func (u userPolicyMessage) JSON() string {
+ u.Status = "success"
+ jsonMessageBytes, e := json.Marshal(u)
+ fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
+
+ return string(jsonMessageBytes)
+}
+
+// mainAdminPoliciesAdd is the handle for "mc admin users add" command.
+func mainAdminPoliciesAdd(ctx *cli.Context) error {
+ checkAdminPoliciesAddSyntax(ctx)
+
+ console.SetColor("PolicyMessage", color.New(color.FgGreen))
+
+ // Get the alias parameter from cli
+ args := ctx.Args()
+ aliasedURL := args.Get(0)
+
+ policy, e := ioutil.ReadFile(args.Get(2))
+ fatalIf(probe.NewError(e).Trace(args...), "Unable to get policy")
+
+ // Create a new Minio Admin Client
+ client, err := newAdminClient(aliasedURL)
+ fatalIf(err, "Cannot get a configured admin connection.")
+
+ fatalIf(probe.NewError(client.AddCannedPolicy(args.Get(1), string(policy))).Trace(args...), "Cannot add new policy")
+
+ printMsg(userPolicyMessage{
+ op: "add",
+ Policy: args.Get(1),
+ })
+
+ return nil
+}
diff --git a/cmd/admin-policies-list.go b/cmd/admin-policies-list.go
new file mode 100644
index 00000000..264f34fd
--- /dev/null
+++ b/cmd/admin-policies-list.go
@@ -0,0 +1,93 @@
+/*
+ * Minio Client (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 (
+ "github.com/fatih/color"
+ "github.com/minio/cli"
+ "github.com/minio/mc/pkg/console"
+ "github.com/minio/mc/pkg/probe"
+)
+
+var adminPoliciesListCmd = cli.Command{
+ Name: "list",
+ Usage: "List policies",
+ Action: mainAdminPoliciesList,
+ Before: setGlobalsFromContext,
+ Flags: globalFlags,
+ CustomHelpTemplate: `NAME:
+ {{.HelpName}} - {{.Usage}}
+
+USAGE:
+ {{.HelpName}} TARGET POLICYNAME
+
+POLICYNAME:
+ Name of the canned policy on Minio server.
+
+FLAGS:
+ {{range .VisibleFlags}}{{.}}
+ {{end}}
+EXAMPLES:
+ 1. List all policies.
+ $ {{.HelpName}} myminio
+
+ 2. List only one policy.
+ $ {{.HelpName}} myminio writeonly
+`,
+}
+
+// checkAdminPoliciesListSyntax - validate all the passed arguments
+func checkAdminPoliciesListSyntax(ctx *cli.Context) {
+ if len(ctx.Args()) < 1 || len(ctx.Args()) > 2 {
+ cli.ShowCommandHelpAndExit(ctx, "list", 1) // last argument is exit code
+ }
+}
+
+// mainAdminPoliciesList is the handle for "mc admin users add" command.
+func mainAdminPoliciesList(ctx *cli.Context) error {
+ checkAdminPoliciesListSyntax(ctx)
+
+ console.SetColor("PolicyMessage", color.New(color.FgGreen))
+ console.SetColor("Policy", color.New(color.FgBlue))
+
+ // Get the alias parameter from cli
+ args := ctx.Args()
+ aliasedURL := args.Get(0)
+
+ // Create a new Minio Admin Client
+ client, err := newAdminClient(aliasedURL)
+ fatalIf(err, "Cannot get a configured admin connection.")
+
+ policies, e := client.ListCannedPolicies()
+ fatalIf(probe.NewError(e).Trace(args...), "Cannot list policies")
+
+ if policyName := args.Get(1); policyName != "" {
+ printMsg(userPolicyMessage{
+ op: "list",
+ Policy: policyName,
+ PolicyJSON: policies[policyName],
+ })
+ } else {
+ for k := range policies {
+ printMsg(userPolicyMessage{
+ op: "list",
+ Policy: k,
+ })
+ }
+ }
+ return nil
+}
diff --git a/cmd/admin-policies-remove.go b/cmd/admin-policies-remove.go
new file mode 100644
index 00000000..da94eed9
--- /dev/null
+++ b/cmd/admin-policies-remove.go
@@ -0,0 +1,79 @@
+/*
+ * Minio Client (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 (
+ "github.com/fatih/color"
+ "github.com/minio/cli"
+ "github.com/minio/mc/pkg/console"
+ "github.com/minio/mc/pkg/probe"
+)
+
+var adminPoliciesRemoveCmd = cli.Command{
+ Name: "remove",
+ Usage: "Remove policies",
+ Action: mainAdminPoliciesRemove,
+ Before: setGlobalsFromContext,
+ Flags: globalFlags,
+ CustomHelpTemplate: `NAME:
+ {{.HelpName}} - {{.Usage}}
+
+USAGE:
+ {{.HelpName}} TARGET POLICYNAME
+
+POLICYNAME:
+ Name of the canned policy on Minio server.
+
+FLAGS:
+ {{range .VisibleFlags}}{{.}}
+ {{end}}
+EXAMPLES:
+ 1. Remove a canned policy 'writeonly'.
+ $ {{.HelpName}} myminio writeonly
+`,
+}
+
+// checkAdminPoliciesRemoveSyntax - validate all the passed arguments
+func checkAdminPoliciesRemoveSyntax(ctx *cli.Context) {
+ if len(ctx.Args()) != 2 {
+ cli.ShowCommandHelpAndExit(ctx, "remove", 1) // last argument is exit code
+ }
+}
+
+// mainAdminPoliciesRemove is the handle for "mc admin users add" command.
+func mainAdminPoliciesRemove(ctx *cli.Context) error {
+ checkAdminPoliciesRemoveSyntax(ctx)
+
+ console.SetColor("PolicyMessage", color.New(color.FgGreen))
+
+ // Get the alias parameter from cli
+ args := ctx.Args()
+ aliasedURL := args.Get(0)
+
+ // Create a new Minio Admin Client
+ client, err := newAdminClient(aliasedURL)
+ fatalIf(err, "Cannot get a configured admin connection.")
+
+ fatalIf(probe.NewError(client.RemoveCannedPolicy(args.Get(1))).Trace(args...), "Cannot remove policy")
+
+ printMsg(userPolicyMessage{
+ op: "remove",
+ Policy: args.Get(1),
+ })
+
+ return nil
+}
diff --git a/cmd/admin-policies.go b/cmd/admin-policies.go
new file mode 100644
index 00000000..2d2c48e2
--- /dev/null
+++ b/cmd/admin-policies.go
@@ -0,0 +1,40 @@
+/*
+ * Minio Client (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 "github.com/minio/cli"
+
+var adminPoliciesCmd = cli.Command{
+ Name: "policies",
+ Usage: "Manage canned policies",
+ Action: mainAdminPolicies,
+ Before: setGlobalsFromContext,
+ Flags: globalFlags,
+ Subcommands: []cli.Command{
+ adminPoliciesAddCmd,
+ adminPoliciesRemoveCmd,
+ adminPoliciesListCmd,
+ },
+ HideHelpCommand: true,
+}
+
+// mainAdminPolicies is the handle for "mc admin config" command.
+func mainAdminPolicies(ctx *cli.Context) error {
+ cli.ShowCommandHelp(ctx, ctx.Args().First())
+ return nil
+ // Sub-commands like "get", "set" have their own main.
+}
diff --git a/cmd/admin-users-add.go b/cmd/admin-users-add.go
new file mode 100644
index 00000000..f671cf68
--- /dev/null
+++ b/cmd/admin-users-add.go
@@ -0,0 +1,130 @@
+/*
+ * Minio Client (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/json"
+
+ "github.com/fatih/color"
+ "github.com/minio/cli"
+ "github.com/minio/mc/pkg/console"
+ "github.com/minio/mc/pkg/probe"
+)
+
+var adminUsersAddCmd = cli.Command{
+ Name: "add",
+ Usage: "Add new users",
+ Action: mainAdminUsersAdd,
+ Before: setGlobalsFromContext,
+ Flags: globalFlags,
+ CustomHelpTemplate: `NAME:
+ {{.HelpName}} - {{.Usage}}
+
+USAGE:
+ {{.HelpName}} TARGET USERNAME PASSWORD POLICYNAME
+
+POLICYNAME:
+ Name of the canned policies created on Minio server.
+
+FLAGS:
+ {{range .VisibleFlags}}{{.}}
+ {{end}}
+EXAMPLES:
+ 1. Add a new user 'newuser' to Minio server with canned policy 'writeonly'.
+ $ set -o history
+ $ {{.HelpName}} myminio newuser newuser123 writeonly
+ $ set +o history
+`,
+}
+
+// checkAdminUsersAddSyntax - validate all the passed arguments
+func checkAdminUsersAddSyntax(ctx *cli.Context) {
+ if len(ctx.Args()) != 4 {
+ cli.ShowCommandHelpAndExit(ctx, "add", 1) // last argument is exit code
+ }
+}
+
+// userMessage container for content message structure
+type userMessage struct {
+ op string
+ Status string `json:"status"`
+ AccessKey string `json:"accessKey,omitempty"`
+ SecretKey string `json:"secretKey,omitempty"`
+ PolicyName string `json:"policyName,omitempty"`
+ UserStatus string `json:"userStatus,omitempty"`
+}
+
+func (u userMessage) String() string {
+ switch u.op {
+ case "list":
+ userFieldMaxLen := 9
+ accessFieldMaxLen := 20
+ policyFieldMaxLen := 20
+
+ // Create a new pretty table with cols configuration
+ return newPrettyTable(" ",
+ Field{"UserStatus", userFieldMaxLen},
+ Field{"AccessKey", accessFieldMaxLen},
+ Field{"PolicyName", policyFieldMaxLen},
+ ).buildRow(u.UserStatus, u.AccessKey, u.PolicyName)
+ case "remove":
+ return console.Colorize("UserMessage", "Removed user `"+u.AccessKey+"` successfully.")
+ case "disable":
+ return console.Colorize("UserMessage", "Disabled user `"+u.AccessKey+"` successfully.")
+ case "enable":
+ return console.Colorize("UserMessage", "Enabled user `"+u.AccessKey+"` successfully.")
+ case "add":
+ return console.Colorize("UserMessage", "Added used `"+u.AccessKey+"` successfully.")
+ }
+ return ""
+}
+
+func (u userMessage) JSON() string {
+ u.Status = "success"
+ jsonMessageBytes, e := json.Marshal(u)
+ fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
+
+ return string(jsonMessageBytes)
+}
+
+// mainAdminUsersAdd is the handle for "mc admin users add" command.
+func mainAdminUsersAdd(ctx *cli.Context) error {
+ checkAdminUsersAddSyntax(ctx)
+
+ console.SetColor("UserMessage", color.New(color.FgGreen))
+
+ // Get the alias parameter from cli
+ args := ctx.Args()
+ aliasedURL := args.Get(0)
+
+ // Create a new Minio Admin Client
+ client, err := newAdminClient(aliasedURL)
+ fatalIf(err, "Cannot get a configured admin connection.")
+
+ fatalIf(probe.NewError(client.AddUser(args.Get(1), args.Get(2))).Trace(args...), "Cannot add new user")
+
+ fatalIf(probe.NewError(client.SetUserPolicy(args.Get(1), args.Get(3))).Trace(args...), "Cannot set user policy for new user")
+
+ printMsg(userMessage{
+ op: "add",
+ AccessKey: args.Get(1),
+ SecretKey: args.Get(2),
+ UserStatus: "enabled",
+ })
+
+ return nil
+}
diff --git a/cmd/admin-users-disable.go b/cmd/admin-users-disable.go
new file mode 100644
index 00000000..3577111b
--- /dev/null
+++ b/cmd/admin-users-disable.go
@@ -0,0 +1,78 @@
+/*
+ * Minio Client (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 (
+ "github.com/fatih/color"
+ "github.com/minio/cli"
+ "github.com/minio/mc/pkg/console"
+ "github.com/minio/mc/pkg/probe"
+ "github.com/minio/minio/pkg/madmin"
+)
+
+var adminUsersDisableCmd = cli.Command{
+ Name: "disable",
+ Usage: "Disable users",
+ Action: mainAdminUsersDisable,
+ Before: setGlobalsFromContext,
+ Flags: globalFlags,
+ CustomHelpTemplate: `NAME:
+ {{.HelpName}} - {{.Usage}}
+
+USAGE:
+ {{.HelpName}} TARGET USERNAME
+
+FLAGS:
+ {{range .VisibleFlags}}{{.}}
+ {{end}}
+EXAMPLES:
+ 1. Disable a user 'newuser' for Minio server.
+ $ {{.HelpName}} myminio newuser
+`,
+}
+
+// checkAdminUsersDisableSyntax - validate all the passed arguments
+func checkAdminUsersDisableSyntax(ctx *cli.Context) {
+ if len(ctx.Args()) != 2 {
+ cli.ShowCommandHelpAndExit(ctx, "disable", 1) // last argument is exit code
+ }
+}
+
+// mainAdminUsersDisable is the handle for "mc admin users disable" command.
+func mainAdminUsersDisable(ctx *cli.Context) error {
+ checkAdminUsersDisableSyntax(ctx)
+
+ console.SetColor("UserMessage", color.New(color.FgGreen))
+
+ // Get the alias parameter from cli
+ args := ctx.Args()
+ aliasedURL := args.Get(0)
+
+ // Create a new Minio Admin Client
+ client, err := newAdminClient(aliasedURL)
+ fatalIf(err, "Cannot get a configured admin connection.")
+
+ e := client.SetUserStatus(args.Get(1), madmin.AccountDisabled)
+ fatalIf(probe.NewError(e).Trace(args...), "Cannot disable user")
+
+ printMsg(userMessage{
+ op: "disable",
+ AccessKey: args.Get(1),
+ })
+
+ return nil
+}
diff --git a/cmd/admin-users-enable.go b/cmd/admin-users-enable.go
new file mode 100644
index 00000000..e792b8d9
--- /dev/null
+++ b/cmd/admin-users-enable.go
@@ -0,0 +1,78 @@
+/*
+ * Minio Client (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 (
+ "github.com/fatih/color"
+ "github.com/minio/cli"
+ "github.com/minio/mc/pkg/console"
+ "github.com/minio/mc/pkg/probe"
+ "github.com/minio/minio/pkg/madmin"
+)
+
+var adminUsersEnableCmd = cli.Command{
+ Name: "enable",
+ Usage: "Enable users",
+ Action: mainAdminUsersEnable,
+ Before: setGlobalsFromContext,
+ Flags: globalFlags,
+ CustomHelpTemplate: `NAME:
+ {{.HelpName}} - {{.Usage}}
+
+USAGE:
+ {{.HelpName}} TARGET USERNAME
+
+FLAGS:
+ {{range .VisibleFlags}}{{.}}
+ {{end}}
+EXAMPLES:
+ 1. Enable a disabled user 'newuser' for Minio server.
+ $ {{.HelpName}} myminio newuser
+`,
+}
+
+// checkAdminUsersEnableSyntax - validate all the passed arguments
+func checkAdminUsersEnableSyntax(ctx *cli.Context) {
+ if len(ctx.Args()) != 2 {
+ cli.ShowCommandHelpAndExit(ctx, "enable", 1) // last argument is exit code
+ }
+}
+
+// mainAdminUsersEnable is the handle for "mc admin users enable" command.
+func mainAdminUsersEnable(ctx *cli.Context) error {
+ checkAdminUsersEnableSyntax(ctx)
+
+ console.SetColor("UserMessage", color.New(color.FgGreen))
+
+ // Get the alias parameter from cli
+ args := ctx.Args()
+ aliasedURL := args.Get(0)
+
+ // Create a new Minio Admin Client
+ client, err := newAdminClient(aliasedURL)
+ fatalIf(err, "Cannot get a configured admin connection.")
+
+ e := client.SetUserStatus(args.Get(1), madmin.AccountEnabled)
+ fatalIf(probe.NewError(e).Trace(args...), "Cannot enable user")
+
+ printMsg(userMessage{
+ op: "enable",
+ AccessKey: args.Get(1),
+ })
+
+ return nil
+}
diff --git a/cmd/admin-users-list.go b/cmd/admin-users-list.go
new file mode 100644
index 00000000..9d8152d3
--- /dev/null
+++ b/cmd/admin-users-list.go
@@ -0,0 +1,84 @@
+/*
+ * Minio Client (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 (
+ "github.com/fatih/color"
+ "github.com/minio/cli"
+ "github.com/minio/mc/pkg/console"
+ "github.com/minio/mc/pkg/probe"
+)
+
+var adminUsersListCmd = cli.Command{
+ Name: "list",
+ Usage: "List all users",
+ Action: mainAdminUsersList,
+ Before: setGlobalsFromContext,
+ Flags: globalFlags,
+ CustomHelpTemplate: `NAME:
+ {{.HelpName}} - {{.Usage}}
+
+USAGE:
+ {{.HelpName}} TARGET
+
+FLAGS:
+ {{range .VisibleFlags}}{{.}}
+ {{end}}
+EXAMPLES:
+ 1. List all users on Minio server.
+ $ {{.HelpName}} myminio
+`,
+}
+
+// checkAdminUsersListSyntax - validate all the passed arguments
+func checkAdminUsersListSyntax(ctx *cli.Context) {
+ if len(ctx.Args()) != 1 {
+ cli.ShowCommandHelpAndExit(ctx, "list", 1) // last argument is exit code
+ }
+}
+
+// mainAdminUsersList is the handle for "mc admin users list" command.
+func mainAdminUsersList(ctx *cli.Context) error {
+ checkAdminUsersListSyntax(ctx)
+
+ // Additional command speific theme customization.
+ console.SetColor("UserMessage", color.New(color.FgGreen))
+ console.SetColor("AccessKey", color.New(color.FgBlue))
+ console.SetColor("PolicyName", color.New(color.FgYellow))
+ console.SetColor("UserStatus", color.New(color.FgCyan))
+
+ // Get the alias parameter from cli
+ args := ctx.Args()
+ aliasedURL := args.Get(0)
+
+ // Create a new Minio Admin Client
+ client, err := newAdminClient(aliasedURL)
+ fatalIf(err, "Cannot get a configured admin connection.")
+
+ users, e := client.ListUsers()
+ fatalIf(probe.NewError(e).Trace(args...), "Cannot list user")
+
+ for k, v := range users {
+ printMsg(userMessage{
+ op: "list",
+ AccessKey: k,
+ PolicyName: v.PolicyName,
+ UserStatus: string(v.Status),
+ })
+ }
+ return nil
+}
diff --git a/cmd/admin-users-remove.go b/cmd/admin-users-remove.go
new file mode 100644
index 00000000..3ded6a37
--- /dev/null
+++ b/cmd/admin-users-remove.go
@@ -0,0 +1,77 @@
+/*
+ * Minio Client (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 (
+ "github.com/fatih/color"
+ "github.com/minio/cli"
+ "github.com/minio/mc/pkg/console"
+ "github.com/minio/mc/pkg/probe"
+)
+
+var adminUsersRemoveCmd = cli.Command{
+ Name: "remove",
+ Usage: "Remove users",
+ Action: mainAdminUsersRemove,
+ Before: setGlobalsFromContext,
+ Flags: globalFlags,
+ CustomHelpTemplate: `NAME:
+ {{.HelpName}} - {{.Usage}}
+
+USAGE:
+ {{.HelpName}} TARGET USERNAME
+
+FLAGS:
+ {{range .VisibleFlags}}{{.}}
+ {{end}}
+EXAMPLES:
+ 1. Remove a user 'newuser' from Minio server.
+ $ {{.HelpName}} myminio newuser
+`,
+}
+
+// checkAdminUsersRemoveSyntax - validate all the passed arguments
+func checkAdminUsersRemoveSyntax(ctx *cli.Context) {
+ if len(ctx.Args()) != 2 {
+ cli.ShowCommandHelpAndExit(ctx, "remove", 1) // last argument is exit code
+ }
+}
+
+// mainAdminUsersRemove is the handle for "mc admin users remove" command.
+func mainAdminUsersRemove(ctx *cli.Context) error {
+ checkAdminUsersRemoveSyntax(ctx)
+
+ console.SetColor("UserMessage", color.New(color.FgGreen))
+
+ // Get the alias parameter from cli
+ args := ctx.Args()
+ aliasedURL := args.Get(0)
+
+ // Create a new Minio Admin Client
+ client, err := newAdminClient(aliasedURL)
+ fatalIf(err, "Cannot get a configured admin connection.")
+
+ e := client.RemoveUser(args.Get(1))
+ fatalIf(probe.NewError(e).Trace(args...), "Cannot remove new user")
+
+ printMsg(userMessage{
+ op: "remove",
+ AccessKey: args.Get(1),
+ })
+
+ return nil
+}
diff --git a/cmd/admin-users.go b/cmd/admin-users.go
new file mode 100644
index 00000000..8a2a914d
--- /dev/null
+++ b/cmd/admin-users.go
@@ -0,0 +1,42 @@
+/*
+ * Minio Client (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 "github.com/minio/cli"
+
+var adminUsersCmd = cli.Command{
+ Name: "users",
+ Usage: "Manage regular users",
+ Action: mainAdminUsers,
+ Before: setGlobalsFromContext,
+ Flags: globalFlags,
+ Subcommands: []cli.Command{
+ adminUsersAddCmd,
+ adminUsersDisableCmd,
+ adminUsersEnableCmd,
+ adminUsersRemoveCmd,
+ adminUsersListCmd,
+ },
+ HideHelpCommand: true,
+}
+
+// mainAdminUsers is the handle for "mc admin config" command.
+func mainAdminUsers(ctx *cli.Context) error {
+ cli.ShowCommandHelp(ctx, ctx.Args().First())
+ return nil
+ // Sub-commands like "get", "set" have their own main.
+}
diff --git a/cmd/find.go b/cmd/find.go
index 5f2b39f5..5996efca 100644
--- a/cmd/find.go
+++ b/cmd/find.go
@@ -243,7 +243,7 @@ func find(ctx *findContext, fileContent contentMessage) {
// all the input parameters.
func doFind(ctx *findContext) error {
// If watch is enabled we will wait on the prefix perpetually
- // for all I/O events until cancelled by user, if watch is not enabled
+ // for all I/O events until canceled by user, if watch is not enabled
// following defer is a no-op.
defer watchFind(ctx)
@@ -301,7 +301,7 @@ func doFind(ctx *findContext) error {
}
// Success, notice watch will execute in defer only if enabled and this call
- // will return after watch is cancelled.
+ // will return after watch is canceled.
return nil
}
diff --git a/docs/minio-admin-complete-guide.md b/docs/minio-admin-complete-guide.md
index 98a81a8e..1576744f 100644
--- a/docs/minio-admin-complete-guide.md
+++ b/docs/minio-admin-complete-guide.md
@@ -212,7 +212,9 @@ Skip SSL certificate verification.
|:---|
|[**service** - Start, stop or get the status of Minio server](#service) |
|[**info** - Display Minio server information](#info) |
-|[**credentials** - Change server access and secret keys](#credentials) |
+|[**users** - Manage users](#users) |
+|[**policies** - Manage policies](#policies) |
+|[**credentials** - Change **admin** server access and secret keys](#credentials) |
|[**config** - Manage server configuration file](#config)|
|[**heal** - Heal disks, buckets and objects on Minio server](#heal) |
@@ -242,7 +244,7 @@ Uptime: 1 days 19 hours 57 minutes 39 seconds.
*Example: Restart remote minio service.*
-NOTE: `restart` and `stop` sub-commands are disruptive operations for your Minio service, any on-going API operations will be forcibly cancelled. So, it should be used only under certain circumstances. Please use it with caution.
+NOTE: `restart` and `stop` sub-commands are disruptive operations for your Minio service, any on-going API operations will be forcibly canceled. So, it should be used only under certain circumstances. Please use it with caution.
```sh
mc admin service restart play
@@ -264,6 +266,7 @@ FLAGS:
*Example: Display Minio server information.*
```sh
+mc admin info play
● play.minio.io:9000
Uptime : online since 1 day ago
Version : 2018-05-28T04:31:38Z
@@ -273,19 +276,105 @@ FLAGS:
Storage : Used 8.2GiB
```
-
-### Command `credentials` - Change server access and secret keys
-`credentials` command to set new credentials of a Minio server.
+
+### Command `policies` - Manage user policies
+`policies` command to add, remove, list policies on Minio server.
```sh
NAME:
- mc admin credentials - Change server access and secret keys
+ mc admin policies - Manage policies
+
+FLAGS:
+ --help, -h Show help.
+
+COMMANDS:
+ add Add new policies
+ remove Remove policies
+ list List all policies
+```
+
+*Example: Add a new policy 'newpolicy' on Minio, with policy from /tmp/newpolicy.json.*
+
+```sh
+mc admin policies add myminio/ newpolicy /tmp/newpolicy.json
+```
+
+*Example: Remove policy 'newpolicy' on Minio.*
+
+```sh
+mc admin policies remove myminio/ newpolicy
+```
+
+*Example: List all policies on Minio.*
+
+```sh
+mc admin policies list --json myminio/
+{"status":"success","policy":"newpolicy"}
+```
+
+
+### Command `users` - Manage regular users
+`users` command to add, remove, enable, disable, list users on Minio server.
+
+```sh
+NAME:
+ mc admin users - Manage regular users
+
+FLAGS:
+ --help, -h Show help.
+
+COMMANDS:
+ add Add new users
+ disable Disable users
+ enable Enable users
+ remove Remove users
+ list List all users
+```
+
+*Example: Add a new user 'newuser' on Minio, with 'newpolicy' policy.*
+
+```sh
+mc admin users add myminio/ newuser newuser123 newpolicy
+```
+
+*Example: Disable a user 'newuser' on Minio.*
+
+```sh
+mc admin users disable myminio/ newuser
+```
+
+*Example: Enable a user 'newuser' on Minio.*
+
+```sh
+mc admin users enable myminio/ newuser
+```
+
+*Example: Remove user 'newuser' on Minio.*
+
+```sh
+mc admin users remove myminio/ newuser
+```
+
+*Example: List all users on Minio.*
+
+```sh
+mc admin users list --json myminio/
+{"status":"success","accessKey":"newuser","userStatus":"enabled"}
+```
+
+
+### Command `credentials` - Change server **admin** access and secret keys
+`credentials` command to set new **admin** credentials of a Minio server.
+
+```sh
+NAME:
+ mc admin credentials - Change server **admin** access and secret keys
FLAGS:
--help, -h Show help.
```
-*Example: Set new credentials of a Minio server represented by its alias 'myminio'.*
+*Example: Set new admin credentials of a Minio server represented by its alias 'myminio'.*
```sh
mc admin credentials myminio/ minio minio123
diff --git a/functional-tests.sh b/functional-tests.sh
index f6aff713..20d19f8c 100755
--- a/functional-tests.sh
+++ b/functional-tests.sh
@@ -17,7 +17,7 @@
################################################################################
#
-# This script is usable by mc functional tests, mint tests and minio verfication
+# This script is usable by mc functional tests, mint tests and minio verification
# tests.
#
# * As mc functional tests, just run this script. It uses mc executable binary
diff --git a/vendor/github.com/minio/minio/pkg/madmin/API.md b/vendor/github.com/minio/minio/pkg/madmin/API.md
index 93064eb6..75469df5 100644
--- a/vendor/github.com/minio/minio/pkg/madmin/API.md
+++ b/vendor/github.com/minio/minio/pkg/madmin/API.md
@@ -36,12 +36,12 @@ func main() {
```
-| Service operations | Info operations | Healing operations | Config operations | Misc |
-|:----------------------------|:----------------------------|:--------------------------------------|:--------------------------|:------------------------------------|
-| [`ServiceStatus`](#ServiceStatus) | [`ServerInfo`](#ServerInfo) | [`Heal`](#Heal) | [`GetConfig`](#GetConfig) | [`SetCredentials`](#SetCredentials) |
-| [`ServiceSendAction`](#ServiceSendAction) | | | [`SetConfig`](#SetConfig) | |
-| | | | [`GetConfigKeys`](#GetConfigKeys) | |
-| | | | [`SetConfigKeys`](#SetConfigKeys) | |
+| Service operations | Info operations | Healing operations | Config operations | IAM operations | Misc |
+|:----------------------------|:----------------------------|:--------------------------------------|:--------------------------|:------------------------------------|:------------------------------------|
+| [`ServiceStatus`](#ServiceStatus) | [`ServerInfo`](#ServerInfo) | [`Heal`](#Heal) | [`GetConfig`](#GetConfig) | [`AddUser`](#AddUser) | [`SetAdminCredentials`](#SetAdminCredentials) |
+| [`ServiceSendAction`](#ServiceSendAction) | | | [`SetConfig`](#SetConfig) | [`SetUserPolicy`](#SetUserPolicy) | [`StartProfiling`](#StartProfiling) |
+| | | | [`GetConfigKeys`](#GetConfigKeys) | [`ListUsers`](#ListUsers) | [`DownloadProfilingData`](#DownloadProfilingData) |
+| | | | [`SetConfigKeys`](#SetConfigKeys) | [`AddCannedPolicy`](#AddCannedPolicy) | |
## 1. Constructor
@@ -273,7 +273,7 @@ __Example__
### GetConfig() ([]byte, error)
-Get config.json of a minio setup.
+Get current `config.json` of a Minio server.
__Example__
@@ -295,37 +295,17 @@ __Example__
-### SetConfig(config io.Reader) (SetConfigResult, error)
-Set config.json of a minio setup and restart setup for configuration
-change to take effect.
-
-
-| Param | Type | Description |
-|---|---|---|
-|`st.Status` | _bool_ | true if set-config succeeded, false otherwise. |
-|`st.NodeSummary.Name` | _string_ | Network address of the node. |
-|`st.NodeSummary.ErrSet` | _bool_ | Bool representation indicating if an error is encountered with the node.|
-|`st.NodeSummary.ErrMsg` | _string_ | String representation of the error (if any) on the node.|
-
+### SetConfig(config io.Reader) error
+Set a new `config.json` for a Minio server.
__Example__
``` go
config := bytes.NewReader([]byte(`config.json contents go here`))
- result, err := madmClnt.SetConfig(config)
- if err != nil {
+ if err := madmClnt.SetConfig(config); err != nil {
log.Fatalf("failed due to: %v", err)
}
-
- var buf bytes.Buffer
- enc := json.NewEncoder(&buf)
- enc.SetEscapeHTML(false)
- enc.SetIndent("", "\t")
- err = enc.Encode(result)
- if err != nil {
- log.Fatalln(err)
- }
- log.Println("SetConfig: ", string(buf.Bytes()))
+ log.Println("SetConfig was successful")
```
@@ -367,21 +347,128 @@ __Example__
log.Println("New configuration successfully set")
```
+## 8. IAM operations
+
+### AddCannedPolicy(policyName string, policy string) error
+Create a new canned policy on Minio server.
-## 8. Misc operations
+__Example__
-
-### SetCredentials() error
+```
+ policy := `{"Version": "2012-10-17","Statement": [{"Action": ["s3:GetObject"],"Effect": "Allow","Resource": ["arn:aws:s3:::my-bucketname/*"],"Sid": ""}]}`
+
+ if err = madmClnt.AddCannedPolicy("get-only", policy); err != nil {
+ log.Fatalln(err)
+ }
+```
+
+
+### AddUser(user string, secret string) error
+Add a new user on a Minio server.
+
+__Example__
+
+``` go
+ if err = madmClnt.AddUser("newuser", "newstrongpassword"); err != nil {
+ log.Fatalln(err)
+ }
+```
+
+
+### SetUserPolicy(user string, policyName string) error
+Enable a canned policy `get-only` for a given user on Minio server.
+
+__Example__
+
+``` go
+ if err = madmClnt.SetUserPolicy("newuser", "get-only"); err != nil {
+ log.Fatalln(err)
+ }
+```
+
+
+### ListUsers() (map[string]UserInfo, error)
+Lists all users on Minio server.
+
+__Example__
+
+``` go
+ users, err := madmClnt.ListUsers();
+ if err != nil {
+ log.Fatalln(err)
+ }
+ for k, v := range users {
+ fmt.Printf("User %s Status %s\n", k, v.Status)
+ }
+```
+
+## 9. Misc operations
+
+
+### SetAdminCredentials() error
Set new credentials of a Minio setup.
__Example__
``` go
- err = madmClnt.SetCredentials("YOUR-NEW-ACCESSKEY", "YOUR-NEW-SECRETKEY")
+ err = madmClnt.SetAdminCredentials("YOUR-NEW-ACCESSKEY", "YOUR-NEW-SECRETKEY")
if err != nil {
log.Fatalln(err)
}
log.Println("New credentials successfully set.")
```
+
+
+### StartProfiling(profiler string) error
+Ask all nodes to start profiling using the specified profiler mode
+
+__Example__
+
+``` go
+ startProfilingResults, err = madmClnt.StartProfiling("cpu")
+ if err != nil {
+ log.Fatalln(err)
+ }
+ for _, result := range startProfilingResults {
+ if !result.Success {
+ log.Printf("Unable to start profiling on node `%s`, reason = `%s`\n", result.NodeName, result.Error)
+ } else {
+ log.Printf("Profiling successfully started on node `%s`\n", result.NodeName)
+ }
+ }
+
+```
+
+
+### DownloadProfilingData() ([]byte, error)
+Download profiling data of all nodes in a zip format.
+
+__Example__
+
+``` go
+ profilingData, err := madmClnt.DownloadProfilingData()
+ if err != nil {
+ log.Fatalln(err)
+ }
+
+ profilingFile, err := os.Create("/tmp/profiling-data.zip")
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ if _, err := io.Copy(profilingFile, profilingData); err != nil {
+ log.Fatal(err)
+ }
+
+ if err := profilingFile.Close(); err != nil {
+ log.Fatal(err)
+ }
+
+ if err := profilingData.Close(); err != nil {
+ log.Fatal(err)
+ }
+
+ log.Println("Profiling data successfully downloaded.")
+```
diff --git a/vendor/github.com/minio/minio/pkg/madmin/api-error-response.go b/vendor/github.com/minio/minio/pkg/madmin/api-error-response.go
index c85c0bfb..1cd1ff54 100644
--- a/vendor/github.com/minio/minio/pkg/madmin/api-error-response.go
+++ b/vendor/github.com/minio/minio/pkg/madmin/api-error-response.go
@@ -73,6 +73,7 @@ func httpRespToErrorResponse(resp *http.Response) error {
Message: "Failed to parse server response.",
}
}
+ closeResponse(resp)
return errResp
}
diff --git a/vendor/github.com/minio/minio/pkg/madmin/api.go b/vendor/github.com/minio/minio/pkg/madmin/api.go
index 6c95f6d6..6ed79d80 100644
--- a/vendor/github.com/minio/minio/pkg/madmin/api.go
+++ b/vendor/github.com/minio/minio/pkg/madmin/api.go
@@ -176,7 +176,7 @@ func (c *AdminClient) TraceOff() {
type requestData struct {
customHeaders http.Header
queryValues url.Values
- relPath string // Url path relative to admin API base endpoint
+ relPath string // URL path relative to admin API base endpoint
content []byte
}
diff --git a/vendor/github.com/minio/minio/pkg/madmin/config-commands.go b/vendor/github.com/minio/minio/pkg/madmin/config-commands.go
index 4dc10bb0..46427fe3 100644
--- a/vendor/github.com/minio/minio/pkg/madmin/config-commands.go
+++ b/vendor/github.com/minio/minio/pkg/madmin/config-commands.go
@@ -19,61 +19,16 @@ package madmin
import (
"bytes"
- "crypto/rand"
"encoding/base64"
"encoding/json"
"errors"
- "fmt"
"io"
- "io/ioutil"
"net/http"
"net/url"
"github.com/minio/minio/pkg/quick"
- "github.com/minio/sio"
- "golang.org/x/crypto/argon2"
)
-// EncryptServerConfigData - encrypts server config data.
-func EncryptServerConfigData(password string, data []byte) ([]byte, error) {
- salt := make([]byte, 32)
- if _, err := io.ReadFull(rand.Reader, salt); err != nil {
- return nil, err
- }
-
- // derive an encryption key from the master key and the nonce
- var key [32]byte
- copy(key[:], argon2.IDKey([]byte(password), salt, 1, 64*1024, 4, 32))
-
- encrypted, err := sio.EncryptReader(bytes.NewReader(data), sio.Config{
- Key: key[:]},
- )
- if err != nil {
- return nil, err
- }
- edata, err := ioutil.ReadAll(encrypted)
- return append(salt, edata...), err
-}
-
-// DecryptServerConfigData - decrypts server config data.
-func DecryptServerConfigData(password string, data io.Reader) ([]byte, error) {
- salt := make([]byte, 32)
- if _, err := io.ReadFull(data, salt); err != nil {
- return nil, err
- }
- // derive an encryption key from the master key and the nonce
- var key [32]byte
- copy(key[:], argon2.IDKey([]byte(password), salt, 1, 64*1024, 4, 32))
-
- decrypted, err := sio.DecryptReader(data, sio.Config{
- Key: key[:]},
- )
- if err != nil {
- return nil, err
- }
- return ioutil.ReadAll(decrypted)
-}
-
// GetConfig - returns the config.json of a minio setup, incoming data is encrypted.
func (adm *AdminClient) GetConfig() ([]byte, error) {
// Execute GET on /minio/admin/v1/config to get config of a setup.
@@ -89,16 +44,11 @@ func (adm *AdminClient) GetConfig() ([]byte, error) {
}
defer closeResponse(resp)
- return DecryptServerConfigData(adm.secretAccessKey, resp.Body)
+ return DecryptData(adm.secretAccessKey, resp.Body)
}
// GetConfigKeys - returns partial json or json value from config.json of a minio setup.
func (adm *AdminClient) GetConfigKeys(keys []string) ([]byte, error) {
- // No TLS?
- if !adm.secure {
- // return nil, fmt.Errorf("credentials/configuration cannot be retrieved over an insecure connection")
- }
-
queryVals := make(url.Values)
for _, k := range keys {
queryVals.Add(k, "")
@@ -119,7 +69,7 @@ func (adm *AdminClient) GetConfigKeys(keys []string) ([]byte, error) {
return nil, httpRespToErrorResponse(resp)
}
- return DecryptServerConfigData(adm.secretAccessKey, resp.Body)
+ return DecryptData(adm.secretAccessKey, resp.Body)
}
// SetConfig - set config supplied as config.json for the setup.
@@ -130,7 +80,7 @@ func (adm *AdminClient) SetConfig(config io.Reader) (err error) {
configBuf := make([]byte, maxConfigJSONSize+1)
n, err := io.ReadFull(config, configBuf)
if err == nil {
- return fmt.Errorf("too large file")
+ return bytes.ErrTooLarge
}
if err != io.ErrUnexpectedEOF {
return err
@@ -156,7 +106,7 @@ func (adm *AdminClient) SetConfig(config io.Reader) (err error) {
return errors.New("Duplicate key in json file: " + err.Error())
}
- econfigBytes, err := EncryptServerConfigData(adm.secretAccessKey, configBytes)
+ econfigBytes, err := EncryptData(adm.secretAccessKey, configBytes)
if err != nil {
return err
}
@@ -185,7 +135,7 @@ func (adm *AdminClient) SetConfig(config io.Reader) (err error) {
func (adm *AdminClient) SetConfigKeys(params map[string]string) error {
queryVals := make(url.Values)
for k, v := range params {
- encryptedVal, err := EncryptServerConfigData(adm.secretAccessKey, []byte(v))
+ encryptedVal, err := EncryptData(adm.secretAccessKey, []byte(v))
if err != nil {
return err
}
diff --git a/vendor/github.com/minio/minio/pkg/madmin/encrypt.go b/vendor/github.com/minio/minio/pkg/madmin/encrypt.go
new file mode 100644
index 00000000..1b596019
--- /dev/null
+++ b/vendor/github.com/minio/minio/pkg/madmin/encrypt.go
@@ -0,0 +1,68 @@
+/*
+ * 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 madmin
+
+import (
+ "bytes"
+ "crypto/rand"
+ "io"
+ "io/ioutil"
+
+ "github.com/minio/sio"
+ "golang.org/x/crypto/argon2"
+)
+
+// EncryptData - encrypts server config data.
+func EncryptData(password string, data []byte) ([]byte, error) {
+ salt := make([]byte, 32)
+ if _, err := io.ReadFull(rand.Reader, salt); err != nil {
+ return nil, err
+ }
+
+ // derive an encryption key from the master key and the nonce
+ var key [32]byte
+ copy(key[:], argon2.IDKey([]byte(password), salt, 1, 64*1024, 4, 32))
+
+ encrypted, err := sio.EncryptReader(bytes.NewReader(data), sio.Config{
+ Key: key[:]},
+ )
+ if err != nil {
+ return nil, err
+ }
+ edata, err := ioutil.ReadAll(encrypted)
+ return append(salt, edata...), err
+}
+
+// DecryptData - decrypts server config data.
+func DecryptData(password string, data io.Reader) ([]byte, error) {
+ salt := make([]byte, 32)
+ if _, err := io.ReadFull(data, salt); err != nil {
+ return nil, err
+ }
+ // derive an encryption key from the master key and the nonce
+ var key [32]byte
+ copy(key[:], argon2.IDKey([]byte(password), salt, 1, 64*1024, 4, 32))
+
+ decrypted, err := sio.DecryptReader(data, sio.Config{
+ Key: key[:]},
+ )
+ if err != nil {
+ return nil, err
+ }
+ return ioutil.ReadAll(decrypted)
+}
diff --git a/vendor/github.com/minio/minio/pkg/madmin/generic-commands.go b/vendor/github.com/minio/minio/pkg/madmin/generic-commands.go
index 5843355c..86ba781b 100644
--- a/vendor/github.com/minio/minio/pkg/madmin/generic-commands.go
+++ b/vendor/github.com/minio/minio/pkg/madmin/generic-commands.go
@@ -28,16 +28,16 @@ type SetCredsReq struct {
SecretKey string `json:"secretKey"`
}
-// SetCredentials - Call Set Credentials API to set new access and
+// SetAdminCredentials - Call Set Credentials API to set new access and
// secret keys in the specified Minio server
-func (adm *AdminClient) SetCredentials(access, secret string) error {
+func (adm *AdminClient) SetAdminCredentials(access, secret string) error {
// Setup request's body
body, err := json.Marshal(SetCredsReq{access, secret})
if err != nil {
return err
}
- ebody, err := EncryptServerConfigData(adm.secretAccessKey, body)
+ ebody, err := EncryptData(adm.secretAccessKey, body)
if err != nil {
return err
}
diff --git a/vendor/github.com/minio/minio/pkg/madmin/policy-commands.go b/vendor/github.com/minio/minio/pkg/madmin/policy-commands.go
new file mode 100644
index 00000000..210a994c
--- /dev/null
+++ b/vendor/github.com/minio/minio/pkg/madmin/policy-commands.go
@@ -0,0 +1,107 @@
+/*
+ * 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 madmin
+
+import (
+ "encoding/json"
+ "io/ioutil"
+ "net/http"
+ "net/url"
+)
+
+// ListCannedPolicies - list all configured canned policies.
+func (adm *AdminClient) ListCannedPolicies() (map[string][]byte, error) {
+ reqData := requestData{
+ relPath: "/v1/list-canned-policies",
+ }
+
+ // Execute GET on /minio/admin/v1/list-canned-policies
+ resp, err := adm.executeMethod("GET", reqData)
+
+ defer closeResponse(resp)
+ if err != nil {
+ return nil, err
+ }
+
+ if resp.StatusCode != http.StatusOK {
+ return nil, httpRespToErrorResponse(resp)
+ }
+
+ respBytes, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ return nil, err
+ }
+
+ var policies = make(map[string][]byte)
+ if err = json.Unmarshal(respBytes, &policies); err != nil {
+ return nil, err
+ }
+
+ return policies, nil
+}
+
+// RemoveCannedPolicy - remove a policy for a canned.
+func (adm *AdminClient) RemoveCannedPolicy(policyName string) error {
+ queryValues := url.Values{}
+ queryValues.Set("name", policyName)
+
+ reqData := requestData{
+ relPath: "/v1/remove-canned-policy",
+ queryValues: queryValues,
+ }
+
+ // Execute DELETE on /minio/admin/v1/remove-canned-policy to remove policy.
+ resp, err := adm.executeMethod("DELETE", reqData)
+
+ defer closeResponse(resp)
+ if err != nil {
+ return err
+ }
+
+ if resp.StatusCode != http.StatusOK {
+ return httpRespToErrorResponse(resp)
+ }
+
+ return nil
+}
+
+// AddCannedPolicy - adds a policy for a canned.
+func (adm *AdminClient) AddCannedPolicy(policyName, policy string) error {
+ queryValues := url.Values{}
+ queryValues.Set("name", policyName)
+
+ reqData := requestData{
+ relPath: "/v1/add-canned-policy",
+ queryValues: queryValues,
+ content: []byte(policy),
+ }
+
+ // Execute PUT on /minio/admin/v1/add-canned-policy to set policy.
+ resp, err := adm.executeMethod("PUT", reqData)
+
+ defer closeResponse(resp)
+ if err != nil {
+ return err
+ }
+
+ if resp.StatusCode != http.StatusOK {
+ return httpRespToErrorResponse(resp)
+ }
+
+ return nil
+}
diff --git a/vendor/github.com/minio/minio/pkg/madmin/profiling-commands.go b/vendor/github.com/minio/minio/pkg/madmin/profiling-commands.go
new file mode 100644
index 00000000..ab686a1c
--- /dev/null
+++ b/vendor/github.com/minio/minio/pkg/madmin/profiling-commands.go
@@ -0,0 +1,105 @@
+/*
+ * Minio Cloud Storage, (C) 2017, 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 madmin
+
+import (
+ "encoding/json"
+ "errors"
+ "fmt"
+ "io"
+ "io/ioutil"
+ "net/http"
+ "net/url"
+)
+
+// ProfilerType represents the profiler type
+// passed to the profiler subsystem.
+type ProfilerType string
+
+// Different supported profiler types.
+const (
+ ProfilerCPU ProfilerType = "cpu" // represents CPU profiler type
+ ProfilerMEM = "mem" // represents MEM profiler type
+ ProfilerBlock = "block" // represents Block profiler type
+ ProfilerMutex = "mutex" // represents Mutex profiler type
+ ProfilerTrace = "trace" // represents Trace profiler type
+)
+
+// StartProfilingResult holds the result of starting
+// profiler result in a given node.
+type StartProfilingResult struct {
+ NodeName string `json:"nodeName"`
+ Success bool `json:"success"`
+ Error string `json:"error"`
+}
+
+// StartProfiling makes an admin call to remotely start profiling on a standalone
+// server or the whole cluster in case of a distributed setup.
+func (adm *AdminClient) StartProfiling(profiler ProfilerType) ([]StartProfilingResult, error) {
+ v := url.Values{}
+ v.Set("profilerType", string(profiler))
+ resp, err := adm.executeMethod("POST", requestData{
+ relPath: "/v1/profiling/start",
+ queryValues: v,
+ })
+ defer closeResponse(resp)
+ if err != nil {
+ return nil, err
+ }
+
+ if resp.StatusCode != http.StatusOK {
+ return nil, httpRespToErrorResponse(resp)
+ }
+
+ jsonResult, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ return nil, err
+ }
+
+ var startResults []StartProfilingResult
+ err = json.Unmarshal(jsonResult, &startResults)
+ if err != nil {
+ return nil, err
+ }
+
+ return startResults, nil
+}
+
+// DownloadProfilingData makes an admin call to download profiling data of a standalone
+// server or of the whole cluster in case of a distributed setup.
+func (adm *AdminClient) DownloadProfilingData() (io.ReadCloser, error) {
+ path := fmt.Sprintf("/v1/profiling/download")
+ resp, err := adm.executeMethod("GET", requestData{
+ relPath: path,
+ })
+
+ if err != nil {
+ closeResponse(resp)
+ return nil, err
+ }
+
+ if resp.StatusCode != http.StatusOK {
+ return nil, httpRespToErrorResponse(resp)
+ }
+
+ if resp.Body == nil {
+ return nil, errors.New("body is nil")
+ }
+
+ return resp.Body, nil
+}
diff --git a/vendor/github.com/minio/minio/pkg/madmin/user-commands.go b/vendor/github.com/minio/minio/pkg/madmin/user-commands.go
new file mode 100644
index 00000000..a413f7d6
--- /dev/null
+++ b/vendor/github.com/minio/minio/pkg/madmin/user-commands.go
@@ -0,0 +1,191 @@
+/*
+ * 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 madmin
+
+import (
+ "encoding/json"
+ "net/http"
+ "net/url"
+)
+
+// AccountStatus - account status.
+type AccountStatus string
+
+// Account status per user.
+const (
+ AccountEnabled AccountStatus = "enabled"
+ AccountDisabled AccountStatus = "disabled"
+)
+
+// UserInfo carries information about long term users.
+type UserInfo struct {
+ SecretKey string `json:"secretKey,omitempty"`
+ PolicyName string `json:"policyName,omitempty"`
+ Status AccountStatus `json:"status"`
+}
+
+// RemoveUser - remove a user.
+func (adm *AdminClient) RemoveUser(accessKey string) error {
+ queryValues := url.Values{}
+ queryValues.Set("accessKey", accessKey)
+
+ reqData := requestData{
+ relPath: "/v1/remove-user",
+ queryValues: queryValues,
+ }
+
+ // Execute DELETE on /minio/admin/v1/remove-user to remove a user.
+ resp, err := adm.executeMethod("DELETE", reqData)
+
+ defer closeResponse(resp)
+ if err != nil {
+ return err
+ }
+
+ if resp.StatusCode != http.StatusOK {
+ return httpRespToErrorResponse(resp)
+ }
+
+ return nil
+}
+
+// ListUsers - list all users.
+func (adm *AdminClient) ListUsers() (map[string]UserInfo, error) {
+ reqData := requestData{
+ relPath: "/v1/list-users",
+ }
+
+ // Execute GET on /minio/admin/v1/list-users
+ resp, err := adm.executeMethod("GET", reqData)
+
+ defer closeResponse(resp)
+ if err != nil {
+ return nil, err
+ }
+
+ if resp.StatusCode != http.StatusOK {
+ return nil, httpRespToErrorResponse(resp)
+ }
+
+ data, err := DecryptData(adm.secretAccessKey, resp.Body)
+ if err != nil {
+ return nil, err
+ }
+
+ var users = make(map[string]UserInfo)
+ if err = json.Unmarshal(data, &users); err != nil {
+ return nil, err
+ }
+
+ return users, nil
+}
+
+// SetUser - sets a user info.
+func (adm *AdminClient) SetUser(accessKey, secretKey string, status AccountStatus) error {
+ data, err := json.Marshal(UserInfo{
+ SecretKey: secretKey,
+ Status: status,
+ })
+ if err != nil {
+ return err
+ }
+ econfigBytes, err := EncryptData(adm.secretAccessKey, data)
+ if err != nil {
+ return err
+ }
+
+ queryValues := url.Values{}
+ queryValues.Set("accessKey", accessKey)
+
+ reqData := requestData{
+ relPath: "/v1/add-user",
+ queryValues: queryValues,
+ content: econfigBytes,
+ }
+
+ // Execute PUT on /minio/admin/v1/add-user to set a user.
+ resp, err := adm.executeMethod("PUT", reqData)
+
+ defer closeResponse(resp)
+ if err != nil {
+ return err
+ }
+
+ if resp.StatusCode != http.StatusOK {
+ return httpRespToErrorResponse(resp)
+ }
+
+ return nil
+}
+
+// AddUser - adds a user.
+func (adm *AdminClient) AddUser(accessKey, secretKey string) error {
+ return adm.SetUser(accessKey, secretKey, AccountEnabled)
+}
+
+// SetUserPolicy - adds a policy for a user.
+func (adm *AdminClient) SetUserPolicy(accessKey, policyName string) error {
+ queryValues := url.Values{}
+ queryValues.Set("accessKey", accessKey)
+ queryValues.Set("name", policyName)
+
+ reqData := requestData{
+ relPath: "/v1/set-user-policy",
+ queryValues: queryValues,
+ }
+
+ // Execute PUT on /minio/admin/v1/set-user-policy to set policy.
+ resp, err := adm.executeMethod("PUT", reqData)
+
+ defer closeResponse(resp)
+ if err != nil {
+ return err
+ }
+
+ if resp.StatusCode != http.StatusOK {
+ return httpRespToErrorResponse(resp)
+ }
+
+ return nil
+}
+
+// SetUserStatus - adds a status for a user.
+func (adm *AdminClient) SetUserStatus(accessKey string, status AccountStatus) error {
+ queryValues := url.Values{}
+ queryValues.Set("accessKey", accessKey)
+ queryValues.Set("status", string(status))
+
+ reqData := requestData{
+ relPath: "/v1/set-user-status",
+ queryValues: queryValues,
+ }
+
+ // Execute PUT on /minio/admin/v1/set-user-status to set status.
+ resp, err := adm.executeMethod("PUT", reqData)
+
+ defer closeResponse(resp)
+ if err != nil {
+ return err
+ }
+
+ if resp.StatusCode != http.StatusOK {
+ return httpRespToErrorResponse(resp)
+ }
+
+ return nil
+}
diff --git a/vendor/vendor.json b/vendor/vendor.json
index eea8392e..419e9d6f 100644
--- a/vendor/vendor.json
+++ b/vendor/vendor.json
@@ -134,10 +134,10 @@
"revisionTime": "2018-09-25T09:12:15Z"
},
{
- "checksumSHA1": "s4yonsbtYU6uuqV3v3Xu7NHHDpY=",
+ "checksumSHA1": "/5zp4gweRyx0NTrMTEwhCqdMaDA=",
"path": "github.com/minio/minio/pkg/madmin",
- "revision": "fd8749f42ab9939deebc0ed3f0e6804269b3854b",
- "revisionTime": "2018-09-06T19:31:12Z"
+ "revision": "79e0add0e50323873b5d30fb41ef70584a9b6f22",
+ "revisionTime": "2018-10-16T19:47:06Z"
},
{
"checksumSHA1": "flg07CqTxM9togozKRQiJugao4s=",