Move mc admin idp to mc idp (#4574)
This commit is contained in:
@@ -1,95 +0,0 @@
|
||||
// Copyright (c) 2015-2022 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/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/madmin-go/v2"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
|
||||
var adminIDPLdapAddCmd = cli.Command{
|
||||
Name: "add",
|
||||
Usage: "Create an LDAP IDP server configuration",
|
||||
Action: mainAdminIDPLDAPAdd,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET [CFG_PARAMS...]
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Create LDAP IDentity Provider configuration.
|
||||
{{.Prompt}} {{.HelpName}} myminio/ \
|
||||
server_addr=myldapserver:636 \
|
||||
lookup_bind_dn=cn=admin,dc=min,dc=io \
|
||||
lookup_bind_password=somesecret \
|
||||
user_dn_search_base_dn=dc=min,dc=io \
|
||||
user_dn_search_filter="(uid=%s)" \
|
||||
group_search_base_dn=ou=swengg,dc=min,dc=io \
|
||||
group_search_filter="(&(objectclass=groupofnames)(member=%d))"
|
||||
`,
|
||||
}
|
||||
|
||||
func mainAdminIDPLDAPAdd(ctx *cli.Context) error {
|
||||
if len(ctx.Args()) < 2 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
args := ctx.Args()
|
||||
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
cfgName := madmin.Default
|
||||
input := args[1:]
|
||||
if !strings.Contains(args.Get(1), "=") {
|
||||
cfgName = args.Get(1)
|
||||
input = args[2:]
|
||||
}
|
||||
|
||||
if cfgName != madmin.Default {
|
||||
fatalIf(probe.NewError(errors.New("all config parameters must be of the form \"key=value\"")),
|
||||
"Bad LDAP IDP configuration")
|
||||
}
|
||||
|
||||
inputCfg := strings.Join(input, " ")
|
||||
|
||||
restart, e := client.AddOrUpdateIDPConfig(globalContext, madmin.LDAPIDPCfg, cfgName, inputCfg, false)
|
||||
fatalIf(probe.NewError(e), "Unable to add LDAP IDP config to server")
|
||||
|
||||
// Print set config result
|
||||
printMsg(configSetMessage{
|
||||
targetAlias: aliasedURL,
|
||||
restart: restart,
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
// Copyright (c) 2015-2022 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/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/minio/cli"
|
||||
)
|
||||
|
||||
var adminIDPLdapDisableCmd = cli.Command{
|
||||
Name: "disable",
|
||||
Usage: "Disable an LDAP IDP server configuration",
|
||||
Action: mainAdminIDPLDAPDisable,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Disable the default LDAP IDP configuration.
|
||||
{{.Prompt}} {{.HelpName}} play/
|
||||
`,
|
||||
}
|
||||
|
||||
func mainAdminIDPLDAPDisable(ctx *cli.Context) error {
|
||||
if len(ctx.Args()) != 1 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
isOpenID, enable := false, false
|
||||
return adminIDPEnableDisable(ctx, isOpenID, enable)
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
// Copyright (c) 2015-2022 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/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/minio/cli"
|
||||
)
|
||||
|
||||
var adminIDPLdapEnableCmd = cli.Command{
|
||||
Name: "enable",
|
||||
Usage: "manage LDAP IDP server configuration",
|
||||
Action: mainAdminIDPLDAPEnable,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Enable the LDAP IDP configuration.
|
||||
{{.Prompt}} {{.HelpName}} play/
|
||||
`,
|
||||
}
|
||||
|
||||
func mainAdminIDPLDAPEnable(ctx *cli.Context) error {
|
||||
if len(ctx.Args()) != 1 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
isOpenID, enable := false, true
|
||||
return adminIDPEnableDisable(ctx, isOpenID, enable)
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
// Copyright (c) 2015-2022 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/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/madmin-go/v2"
|
||||
)
|
||||
|
||||
var adminIDPLdapInfoCmd = cli.Command{
|
||||
Name: "info",
|
||||
Usage: "get LDAP IDP server configuration info",
|
||||
Action: mainAdminIDPLDAPInfo,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Get configuration info on the LDAP IDP configuration.
|
||||
{{.Prompt}} {{.HelpName}} play/
|
||||
`,
|
||||
}
|
||||
|
||||
func mainAdminIDPLDAPInfo(ctx *cli.Context) error {
|
||||
if len(ctx.Args()) != 1 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
var cfgName string = madmin.Default
|
||||
return adminIDPInfo(ctx, false, cfgName)
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
// Copyright (c) 2015-2022 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/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import "github.com/minio/cli"
|
||||
|
||||
var adminIDPLdapListCmd = cli.Command{
|
||||
Name: "list",
|
||||
ShortName: "ls",
|
||||
Usage: "list LDAP IDP server configuration(s)",
|
||||
Action: mainAdminIDPLDAPList,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. List configurations for LDAP IDP.
|
||||
{{.Prompt}} {{.HelpName}} play/
|
||||
`,
|
||||
}
|
||||
|
||||
func mainAdminIDPLDAPList(ctx *cli.Context) error {
|
||||
if len(ctx.Args()) != 1 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
return adminIDPListCommon(ctx, false)
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
// Copyright (c) 2015-2022 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/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go/v2"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
|
||||
var adminIDPLdapPolicyAttachFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "user, u",
|
||||
Usage: "attach policy to user by DN or by login name",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "group, g",
|
||||
Usage: "attach policy to LDAP Group DN",
|
||||
},
|
||||
}
|
||||
|
||||
var adminIDPLdapPolicyAttachCmd = cli.Command{
|
||||
Name: "attach",
|
||||
Usage: "attach a policy to an entity",
|
||||
Action: mainAdminIDPLdapPolicyAttach,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(adminIDPLdapPolicyAttachFlags, globalFlags...),
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] TARGET POLICY [POLICY...] [ --user=USER | --group=GROUP ]
|
||||
|
||||
Exactly one "--user" or "--group" flag is required.
|
||||
|
||||
POLICY:
|
||||
Name of a policy on the MinIO server.
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Attach policy "mypolicy" to a user
|
||||
{{.Prompt}} {{.HelpName}} play/ mypolicy --user='uid=bobfisher,ou=people,ou=hwengg,dc=min,dc=io'
|
||||
2. Attach policies "policy1" and "policy2" to a group
|
||||
{{.Prompt}} {{.HelpName}} play/ policy1 policy2 --group='cn=projectb,ou=groups,ou=swengg,dc=min,dc=io'
|
||||
`,
|
||||
}
|
||||
|
||||
// Quote from AWS policy naming requirement (ref:
|
||||
// https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_iam-quotas.html):
|
||||
//
|
||||
// Names of users, groups, roles, policies, instance profiles, and server
|
||||
// certificates must be alphanumeric, including the following common characters:
|
||||
// plus (+), equal (=), comma (,), period (.), at (@), underscore (_), and
|
||||
// hyphen (-).
|
||||
|
||||
func mainAdminIDPLdapPolicyAttach(ctx *cli.Context) error {
|
||||
// We need exactly one alias, and at least one policy.
|
||||
if len(ctx.Args()) < 2 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
user := ctx.String("user")
|
||||
group := ctx.String("group")
|
||||
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
policies := args[1:]
|
||||
req := madmin.PolicyAssociationReq{
|
||||
Policies: policies,
|
||||
User: user,
|
||||
Group: group,
|
||||
}
|
||||
fatalIf(probe.NewError(req.IsValid()), "Invalid policy attach arguments.")
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
res, e := client.AttachPolicyLDAP(globalContext, req)
|
||||
fatalIf(probe.NewError(e), "Unable to make LDAP policy association")
|
||||
|
||||
m := policyAssociationMessage{
|
||||
attach: true,
|
||||
Status: "success",
|
||||
PoliciesAttached: res.PoliciesAttached,
|
||||
User: user,
|
||||
Group: group,
|
||||
}
|
||||
printMsg(m)
|
||||
return nil
|
||||
}
|
||||
|
||||
type policyAssociationMessage struct {
|
||||
attach bool
|
||||
Status string `json:"status"`
|
||||
PoliciesAttached []string `json:"policiesAttached,omitempty"`
|
||||
PoliciesDetached []string `json:"policiesDetached,omitempty"`
|
||||
User string `json:"user,omitempty"`
|
||||
Group string `json:"group,omitempty"`
|
||||
}
|
||||
|
||||
func (m policyAssociationMessage) String() string {
|
||||
style := lipgloss.NewStyle().Foreground(lipgloss.Color("#04B575")) // green
|
||||
|
||||
policiesS := style.Render("Attached Policies:")
|
||||
entityS := style.Render("To User:")
|
||||
policies := m.PoliciesAttached
|
||||
entity := m.User
|
||||
switch {
|
||||
case m.User != "" && m.attach:
|
||||
case m.User != "" && !m.attach:
|
||||
policiesS = style.Render("Detached Policies:")
|
||||
policies = m.PoliciesDetached
|
||||
entityS = style.Render("From User:")
|
||||
case m.Group != "" && m.attach:
|
||||
entityS = style.Render("To Group:")
|
||||
entity = m.Group
|
||||
case m.Group != "" && !m.attach:
|
||||
policiesS = style.Render("Detached Policies:")
|
||||
policies = m.PoliciesDetached
|
||||
entityS = style.Render("From Group:")
|
||||
entity = m.Group
|
||||
}
|
||||
return fmt.Sprintf("%s %v\n%s %s\n", policiesS, policies, entityS, entity)
|
||||
}
|
||||
|
||||
func (m policyAssociationMessage) JSON() string {
|
||||
jsonMessageBytes, e := json.MarshalIndent(m, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(jsonMessageBytes)
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
// Copyright (c) 2015-2022 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/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/madmin-go/v2"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
|
||||
var adminIDPLdapPolicyDetachFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "user, u",
|
||||
Usage: "attach policy to user by DN or by login name",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "group, g",
|
||||
Usage: "attach policy to LDAP Group DN",
|
||||
},
|
||||
}
|
||||
|
||||
var adminIDPLdapPolicyDetachCmd = cli.Command{
|
||||
Name: "detach",
|
||||
Usage: "detach a policy from an entity",
|
||||
Action: mainAdminIDPLdapPolicyDetach,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(adminIDPLdapPolicyDetachFlags, globalFlags...),
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] TARGET POLICY [POLICY...] [ --user=USER | --group=GROUP ]
|
||||
|
||||
Exactly one of "--user" or "--group" is required.
|
||||
|
||||
POLICY:
|
||||
Name of a policy on the MinIO server.
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Detach policy "mypolicy" from a user
|
||||
{{.Prompt}} {{.HelpName}} play/ mypolicy --user='uid=bobfisher,ou=people,ou=hwengg,dc=min,dc=io'
|
||||
2. Detach policies "policy1" and "policy2" from a group
|
||||
{{.Prompt}} {{.HelpName}} play/ policy1 policy2 --group='cn=projectb,ou=groups,ou=swengg,dc=min,dc=io'
|
||||
`,
|
||||
}
|
||||
|
||||
// Quote from AWS policy naming requirement (ref:
|
||||
// https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_iam-quotas.html):
|
||||
//
|
||||
// Names of users, groups, roles, policies, instance profiles, and server
|
||||
// certificates must be alphanumeric, including the following common characters:
|
||||
// plus (+), equal (=), comma (,), period (.), at (@), underscore (_), and
|
||||
// hyphen (-).
|
||||
|
||||
func mainAdminIDPLdapPolicyDetach(ctx *cli.Context) error {
|
||||
// We need exactly one alias, and at least one policy.
|
||||
if len(ctx.Args()) < 2 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
user := ctx.String("user")
|
||||
group := ctx.String("group")
|
||||
|
||||
if user == "" && group == "" {
|
||||
e := errors.New("at least one of --user or --group is required.")
|
||||
fatalIf(probe.NewError(e), "Missing flag in command")
|
||||
}
|
||||
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
policies := args[1:]
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
res, e := client.DetachPolicyLDAP(globalContext,
|
||||
madmin.PolicyAssociationReq{
|
||||
Policies: policies,
|
||||
User: user,
|
||||
Group: group,
|
||||
})
|
||||
fatalIf(probe.NewError(e), "Unable to make LDAP policy association")
|
||||
|
||||
m := policyAssociationMessage{
|
||||
attach: false,
|
||||
Status: "success",
|
||||
PoliciesDetached: res.PoliciesDetached,
|
||||
User: user,
|
||||
Group: group,
|
||||
}
|
||||
printMsg(m)
|
||||
return nil
|
||||
}
|
||||
@@ -1,193 +0,0 @@
|
||||
// Copyright (c) 2015-2022 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/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go/v2"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
|
||||
var adminIDPLdapPolicyEntitiesFlags = []cli.Flag{
|
||||
cli.StringSliceFlag{
|
||||
Name: "user, u",
|
||||
Usage: "list policies associated with user(s)",
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
Name: "group, g",
|
||||
Usage: "list policies associated with group(s)",
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
Name: "policy, p",
|
||||
Usage: "list users or groups associated with policy",
|
||||
},
|
||||
}
|
||||
|
||||
var adminIDPLdapPolicyEntitiesCmd = cli.Command{
|
||||
Name: "entities",
|
||||
Usage: "list policy association entities",
|
||||
Action: mainAdminIDPLdapPolicyEntities,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(adminIDPLdapPolicyEntitiesFlags, globalFlags...),
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. List all LDAP entities associated with all policies
|
||||
{{.Prompt}} {{.HelpName}} play/
|
||||
2. List all LDAP entities associated with the policies 'finteam-policy' and 'mlteam-policy'
|
||||
{{.Prompt}} {{.HelpName}} play/ --policy finteam-policy --policy mlteam-policy
|
||||
3. List all policies associated with a pair of User LDAP entities
|
||||
{{.Prompt}} {{.HelpName}} play/ \
|
||||
--user 'uid=bobfisher,ou=people,ou=hwengg,dc=min,dc=io' \
|
||||
--user 'uid=fahim,ou=people,ou=swengg,dc=min,dc=io'
|
||||
4. List all policies associated with a pair of Group LDAP entities
|
||||
{{.Prompt}} {{.HelpName}} play/ \
|
||||
--group 'cn=projecta,ou=groups,ou=swengg,dc=min,dc=io' \
|
||||
--group 'cn=projectb,ou=groups,ou=swengg,dc=min,dc=io'
|
||||
5. List all entities associated with a policy, group and user
|
||||
{{.Prompt}} {{.HelpName}} play/ \
|
||||
--policy finteam-policy
|
||||
--user 'uid=bobfisher,ou=people,ou=hwengg,dc=min,dc=io' \
|
||||
--group 'cn=projectb,ou=groups,ou=swengg,dc=min,dc=io'
|
||||
`,
|
||||
}
|
||||
|
||||
func mainAdminIDPLdapPolicyEntities(ctx *cli.Context) error {
|
||||
if len(ctx.Args()) != 1 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
usersToQuery := ctx.StringSlice("user")
|
||||
groupsToQuery := ctx.StringSlice("group")
|
||||
policiesToQuery := ctx.StringSlice("policy")
|
||||
|
||||
args := ctx.Args()
|
||||
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
res, e := client.GetLDAPPolicyEntities(globalContext,
|
||||
madmin.PolicyEntitiesQuery{
|
||||
Users: usersToQuery,
|
||||
Groups: groupsToQuery,
|
||||
Policy: policiesToQuery,
|
||||
})
|
||||
fatalIf(probe.NewError(e), "Unable to fetch LDAP policy entities")
|
||||
|
||||
printMsg(policyEntitiesFrom(res))
|
||||
return nil
|
||||
}
|
||||
|
||||
type policyEntities struct {
|
||||
Status string `json:"status"`
|
||||
Result madmin.PolicyEntitiesResult `json:"result"`
|
||||
}
|
||||
|
||||
func policyEntitiesFrom(r madmin.PolicyEntitiesResult) policyEntities {
|
||||
return policyEntities{
|
||||
Status: "success",
|
||||
Result: r,
|
||||
}
|
||||
}
|
||||
|
||||
func (p policyEntities) JSON() string {
|
||||
bs, e := json.MarshalIndent(p, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(bs)
|
||||
}
|
||||
|
||||
func iFmt(n int, fmtStr string, a ...any) string {
|
||||
indentStr := ""
|
||||
if n > 0 {
|
||||
s := make([]rune, n)
|
||||
for i := range s {
|
||||
s[i] = ' '
|
||||
}
|
||||
indentStr = string(s)
|
||||
}
|
||||
return fmt.Sprintf(indentStr+fmtStr, a...)
|
||||
}
|
||||
|
||||
func (p policyEntities) String() string {
|
||||
labelStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("#04B575")) // green
|
||||
o := strings.Builder{}
|
||||
|
||||
o.WriteString(iFmt(0, "%s %s\n",
|
||||
labelStyle.Render("Query time:"),
|
||||
p.Result.Timestamp.Format(time.RFC3339)))
|
||||
|
||||
if len(p.Result.UserMappings) > 0 {
|
||||
o.WriteString(iFmt(0, "%s\n", labelStyle.Render("User -> Policy Mappings:")))
|
||||
|
||||
for _, u := range p.Result.UserMappings {
|
||||
o.WriteString(iFmt(2, "%s %s\n", labelStyle.Render("User:"), u.User))
|
||||
for _, p := range u.Policies {
|
||||
o.WriteString(iFmt(4, "%s\n", p))
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(p.Result.GroupMappings) > 0 {
|
||||
o.WriteString(iFmt(0, "%s\n", labelStyle.Render("Group -> Policy Mappings:")))
|
||||
|
||||
for _, u := range p.Result.GroupMappings {
|
||||
o.WriteString(iFmt(2, "%s %s\n", labelStyle.Render("Group:"), u.Group))
|
||||
for _, p := range u.Policies {
|
||||
o.WriteString(iFmt(4, "%s\n", p))
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(p.Result.PolicyMappings) > 0 {
|
||||
o.WriteString(iFmt(0, "%s\n", labelStyle.Render("Policy -> Entity Mappings:")))
|
||||
|
||||
for _, u := range p.Result.PolicyMappings {
|
||||
o.WriteString(iFmt(2, "%s %s\n", labelStyle.Render("Policy:"), u.Policy))
|
||||
if len(u.Users) > 0 {
|
||||
o.WriteString(iFmt(4, "%s\n", labelStyle.Render("User Mappings:")))
|
||||
for _, p := range u.Users {
|
||||
o.WriteString(iFmt(6, "%s\n", p))
|
||||
}
|
||||
}
|
||||
if len(u.Groups) > 0 {
|
||||
o.WriteString(iFmt(4, "%s\n", labelStyle.Render("Group Mappings:")))
|
||||
for _, p := range u.Groups {
|
||||
o.WriteString(iFmt(6, "%s\n", p))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return o.String()
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
// Copyright (c) 2015-2022 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/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/madmin-go/v2"
|
||||
)
|
||||
|
||||
var adminIDPLdapRemoveCmd = cli.Command{
|
||||
Name: "remove",
|
||||
ShortName: "rm",
|
||||
Usage: "remove LDAP IDP server configuration",
|
||||
Action: mainAdminIDPLDAPRemove,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Remove the default LDAP IDP configuration.
|
||||
{{.Prompt}} {{.HelpName}} play/
|
||||
`,
|
||||
}
|
||||
|
||||
func mainAdminIDPLDAPRemove(ctx *cli.Context) error {
|
||||
if len(ctx.Args()) != 1 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
var cfgName string = madmin.Default
|
||||
return adminIDPRemove(ctx, false, cfgName)
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
// Copyright (c) 2015-2022 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/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/madmin-go/v2"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
|
||||
var adminIDPLdapUpdateCmd = cli.Command{
|
||||
Name: "update",
|
||||
Usage: "Update an LDAP IDP configuration",
|
||||
Action: mainAdminIDPLDAPUpdate,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET [CFG_PARAMS...]
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Update the LDAP IDP configuration.
|
||||
{{.Prompt}} {{.HelpName}} play/ \
|
||||
lookup_bind_dn=cn=admin,dc=min,dc=io \
|
||||
lookup_bind_password=somesecret
|
||||
`,
|
||||
}
|
||||
|
||||
func mainAdminIDPLDAPUpdate(ctx *cli.Context) error {
|
||||
if len(ctx.Args()) < 2 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
args := ctx.Args()
|
||||
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
cfgName := madmin.Default
|
||||
input := args[1:]
|
||||
if !strings.Contains(args.Get(1), "=") {
|
||||
cfgName = args.Get(1)
|
||||
input = args[2:]
|
||||
}
|
||||
|
||||
if cfgName != madmin.Default {
|
||||
fatalIf(probe.NewError(errors.New("all config parameters must be of the form \"key=value\"")),
|
||||
"Bad LDAP IDP configuration")
|
||||
}
|
||||
|
||||
inputCfg := strings.Join(input, " ")
|
||||
|
||||
restart, e := client.AddOrUpdateIDPConfig(globalContext, madmin.LDAPIDPCfg, cfgName, inputCfg, true)
|
||||
fatalIf(probe.NewError(e), "Unable to update LDAP IDP configuration")
|
||||
|
||||
// Print set config result
|
||||
printMsg(configSetMessage{
|
||||
targetAlias: aliasedURL,
|
||||
restart: restart,
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
// Copyright (c) 2015-2022 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/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/minio/cli"
|
||||
)
|
||||
|
||||
var adminIDPLsCmd = cli.Command{
|
||||
Name: "list",
|
||||
ShortName: "ls",
|
||||
Usage: "List IDP configurations",
|
||||
Before: setGlobalsFromContext,
|
||||
Action: mainAdminIDPList,
|
||||
OnUsageError: onUsageError,
|
||||
Hidden: true,
|
||||
Flags: globalFlags,
|
||||
CustomHelpTemplate: `This command is DEPRECATED.
|
||||
|
||||
Please use "mc admin idp ldap|openid" instead.
|
||||
`,
|
||||
}
|
||||
|
||||
func mainAdminIDPList(_ *cli.Context) error {
|
||||
deprecatedError("mc admin idp ldap|openid")
|
||||
return nil
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
// Copyright (c) 2015-2022 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/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/madmin-go/v2"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
|
||||
var adminIDPOpenidAddCmd = cli.Command{
|
||||
Name: "add",
|
||||
Usage: "Create an OpenID IDP server configuration",
|
||||
Action: mainAdminIDPOpenIDAdd,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET [CFG_NAME] [CFG_PARAMS...]
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Create a default OpenID IDP configuration (CFG_NAME is omitted).
|
||||
{{.Prompt}} {{.HelpName}} play/ \
|
||||
client_id=minio-client-app \
|
||||
client_secret=minio-client-app-secret \
|
||||
config_url="http://localhost:5556/dex/.well-known/openid-configuration" \
|
||||
scopes="openid,groups" \
|
||||
redirect_uri="http://127.0.0.1:10000/oauth_callback" \
|
||||
role_policy="consoleAdmin"
|
||||
2. Create OpenID IDP configuration named "dex_test".
|
||||
{{.Prompt}} {{.HelpName}} play/ dex_test \
|
||||
client_id=minio-client-app \
|
||||
client_secret=minio-client-app-secret \
|
||||
config_url="http://localhost:5556/dex/.well-known/openid-configuration" \
|
||||
scopes="openid,groups" \
|
||||
redirect_uri="http://127.0.0.1:10000/oauth_callback" \
|
||||
role_policy="consoleAdmin"
|
||||
`,
|
||||
}
|
||||
|
||||
func mainAdminIDPOpenIDAdd(ctx *cli.Context) error {
|
||||
return mainAdminIDPOpenIDAddOrUpdate(ctx, false)
|
||||
}
|
||||
|
||||
func mainAdminIDPOpenIDAddOrUpdate(ctx *cli.Context, update bool) error {
|
||||
if len(ctx.Args()) < 2 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
args := ctx.Args()
|
||||
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
cfgName := madmin.Default
|
||||
input := args[1:]
|
||||
if !strings.Contains(args.Get(1), "=") {
|
||||
cfgName = args.Get(1)
|
||||
input = args[2:]
|
||||
}
|
||||
|
||||
inputCfg := strings.Join(input, " ")
|
||||
|
||||
restart, e := client.AddOrUpdateIDPConfig(globalContext, madmin.OpenidIDPCfg, cfgName, inputCfg, update)
|
||||
fatalIf(probe.NewError(e), "Unable to add OpenID IDP config to server")
|
||||
|
||||
// Print set config result
|
||||
printMsg(configSetMessage{
|
||||
targetAlias: aliasedURL,
|
||||
restart: restart,
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
// Copyright (c) 2015-2022 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/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/minio/cli"
|
||||
)
|
||||
|
||||
var adminIDPOpenidDisableCmd = cli.Command{
|
||||
Name: "disable",
|
||||
Usage: "Disable an OpenID IDP server configuration",
|
||||
Action: mainAdminIDPOpenIDDisable,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET [CFG_NAME]
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Disable the default OpenID IDP configuration (CFG_NAME is omitted).
|
||||
{{.Prompt}} {{.HelpName}} play/
|
||||
2. Disable OpenID IDP configuration named "dex_test".
|
||||
{{.Prompt}} {{.HelpName}} play/ dex_test
|
||||
`,
|
||||
}
|
||||
|
||||
func mainAdminIDPOpenIDDisable(ctx *cli.Context) error {
|
||||
isOpenID, enable := true, false
|
||||
return adminIDPEnableDisable(ctx, isOpenID, enable)
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
// Copyright (c) 2015-2022 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/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/madmin-go/v2"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
|
||||
var adminIDPOpenidEnableCmd = cli.Command{
|
||||
Name: "enable",
|
||||
Usage: "enable an OpenID IDP server configuration",
|
||||
Action: mainAdminIDPOpenIDEnable,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET [CFG_NAME]
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Enable the default OpenID IDP configuration (CFG_NAME is omitted).
|
||||
{{.Prompt}} {{.HelpName}} play/
|
||||
2. Enable OpenID IDP configuration named "dex_test".
|
||||
{{.Prompt}} {{.HelpName}} play/ dex_test
|
||||
`,
|
||||
}
|
||||
|
||||
func mainAdminIDPOpenIDEnable(ctx *cli.Context) error {
|
||||
isOpenID, enable := true, true
|
||||
return adminIDPEnableDisable(ctx, isOpenID, enable)
|
||||
}
|
||||
|
||||
func adminIDPEnableDisable(ctx *cli.Context, isOpenID bool, enable bool) error {
|
||||
if len(ctx.Args()) < 1 || len(ctx.Args()) > 2 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
args := ctx.Args()
|
||||
cfgName := madmin.Default
|
||||
if len(args) == 2 {
|
||||
cfgName = args.Get(1)
|
||||
}
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
idpType := madmin.LDAPIDPCfg
|
||||
if isOpenID {
|
||||
idpType = madmin.OpenidIDPCfg
|
||||
}
|
||||
|
||||
configBody := "enable=on"
|
||||
if !enable {
|
||||
configBody = "enable=off"
|
||||
}
|
||||
|
||||
restart, e := client.AddOrUpdateIDPConfig(globalContext, idpType, cfgName, configBody, true)
|
||||
fatalIf(probe.NewError(e), "Unable to remove %s IDP config '%s'", idpType, cfgName)
|
||||
|
||||
printMsg(configSetMessage{
|
||||
targetAlias: aliasedURL,
|
||||
restart: restart,
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,142 +0,0 @@
|
||||
// Copyright (c) 2015-2022 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/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go/v2"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
|
||||
var adminIDPOpenidInfoCmd = cli.Command{
|
||||
Name: "info",
|
||||
Usage: "get OpenID IDP server configuration info",
|
||||
Action: mainAdminIDPOpenIDInfo,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET [CFG_NAME]
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Get configuration info on the default OpenID IDP configuration (CFG_NAME is omitted).
|
||||
{{.Prompt}} {{.HelpName}} play/
|
||||
2. Get configuration info on OpenID IDP configuration named "dex_test".
|
||||
{{.Prompt}} {{.HelpName}} play/ dex_test
|
||||
`,
|
||||
}
|
||||
|
||||
func mainAdminIDPOpenIDInfo(ctx *cli.Context) error {
|
||||
if len(ctx.Args()) < 1 || len(ctx.Args()) > 2 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
args := ctx.Args()
|
||||
var cfgName string
|
||||
if len(args) == 2 {
|
||||
cfgName = args.Get(1)
|
||||
}
|
||||
|
||||
return adminIDPInfo(ctx, true, cfgName)
|
||||
}
|
||||
|
||||
func adminIDPInfo(ctx *cli.Context, isOpenID bool, cfgName string) error {
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
idpType := madmin.LDAPIDPCfg
|
||||
if isOpenID {
|
||||
idpType = madmin.OpenidIDPCfg
|
||||
}
|
||||
|
||||
result, e := client.GetIDPConfig(globalContext, idpType, cfgName)
|
||||
fatalIf(probe.NewError(e), "Unable to get %s IDP config from server", idpType)
|
||||
|
||||
// Print set config result
|
||||
printMsg(idpConfig(result))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type idpConfig madmin.IDPConfig
|
||||
|
||||
func (i idpConfig) JSON() string {
|
||||
bs, e := json.MarshalIndent(i, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(bs)
|
||||
}
|
||||
|
||||
func (i idpConfig) String() string {
|
||||
// Determine required width for key column.
|
||||
fieldColWidth := 0
|
||||
for _, kv := range i.Info {
|
||||
if fieldColWidth < len(kv.Key) {
|
||||
fieldColWidth = len(kv.Key)
|
||||
}
|
||||
}
|
||||
// Add 1 for the colon-suffix in each entry.
|
||||
fieldColWidth++
|
||||
|
||||
fieldColStyle := lipgloss.NewStyle().
|
||||
Width(fieldColWidth).
|
||||
Foreground(lipgloss.Color("#04B575")). // green
|
||||
Bold(true).
|
||||
Align(lipgloss.Right)
|
||||
valueColStyle := lipgloss.NewStyle().
|
||||
PaddingLeft(1).
|
||||
Align(lipgloss.Left)
|
||||
envMarkStyle := lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("201")). // pinkish-red
|
||||
PaddingLeft(1)
|
||||
|
||||
var lines []string
|
||||
for _, kv := range i.Info {
|
||||
envStr := ""
|
||||
if kv.IsCfg && kv.IsEnv {
|
||||
envStr = " (environment)"
|
||||
}
|
||||
lines = append(lines, fmt.Sprintf("%s%s%s",
|
||||
fieldColStyle.Render(kv.Key+":"),
|
||||
valueColStyle.Render(kv.Value),
|
||||
envMarkStyle.Render(envStr),
|
||||
))
|
||||
}
|
||||
|
||||
boxContent := strings.Join(lines, "\n")
|
||||
|
||||
boxStyle := lipgloss.NewStyle().
|
||||
BorderStyle(lipgloss.RoundedBorder())
|
||||
|
||||
return boxStyle.Render(boxContent)
|
||||
}
|
||||
@@ -1,173 +0,0 @@
|
||||
// Copyright (c) 2015-2022 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/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go/v2"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
|
||||
var adminIDPOpenidListCmd = cli.Command{
|
||||
Name: "list",
|
||||
ShortName: "ls",
|
||||
Usage: "list OpenID IDP server configuration(s)",
|
||||
Action: mainAdminIDPOpenIDList,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. List configurations for OpenID IDP.
|
||||
{{.Prompt}} {{.HelpName}} play/
|
||||
`,
|
||||
}
|
||||
|
||||
func mainAdminIDPOpenIDList(ctx *cli.Context) error {
|
||||
if len(ctx.Args()) != 1 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
return adminIDPListCommon(ctx, true)
|
||||
}
|
||||
|
||||
func adminIDPListCommon(ctx *cli.Context, isOpenID bool) error {
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
idpType := madmin.LDAPIDPCfg
|
||||
if isOpenID {
|
||||
idpType = madmin.OpenidIDPCfg
|
||||
}
|
||||
result, e := client.ListIDPConfig(globalContext, idpType)
|
||||
fatalIf(probe.NewError(e), "Unable to list IDP config for '%s'", idpType)
|
||||
|
||||
printMsg(idpCfgList(result))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type idpCfgList []madmin.IDPListItem
|
||||
|
||||
func (i idpCfgList) JSON() string {
|
||||
bs, e := json.MarshalIndent(i, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(bs)
|
||||
}
|
||||
|
||||
func (i idpCfgList) String() string {
|
||||
maxNameWidth := len("Name")
|
||||
maxRoleARNWidth := len("RoleArn")
|
||||
for _, item := range i {
|
||||
name := item.Name
|
||||
if name == "_" {
|
||||
name = "(default)" // for the un-named config, don't show `_`
|
||||
}
|
||||
if maxNameWidth < len(name) {
|
||||
maxNameWidth = len(name)
|
||||
}
|
||||
if maxRoleARNWidth < len(item.RoleARN) {
|
||||
maxRoleARNWidth = len(item.RoleARN)
|
||||
}
|
||||
}
|
||||
enabledWidth := 5
|
||||
// Add 2 for padding
|
||||
maxNameWidth += 2
|
||||
maxRoleARNWidth += 2
|
||||
|
||||
enabledColStyle := lipgloss.NewStyle().
|
||||
Align(lipgloss.Center).
|
||||
PaddingLeft(1).
|
||||
PaddingRight(1).
|
||||
Width(enabledWidth)
|
||||
nameColStyle := lipgloss.NewStyle().
|
||||
Align(lipgloss.Right).
|
||||
PaddingLeft(1).
|
||||
PaddingRight(1).
|
||||
Width(maxNameWidth)
|
||||
arnColStyle := lipgloss.NewStyle().
|
||||
Align(lipgloss.Left).
|
||||
PaddingLeft(1).
|
||||
PaddingRight(1).
|
||||
Foreground(lipgloss.Color("#04B575")). // green
|
||||
Width(maxRoleARNWidth)
|
||||
|
||||
styles := []lipgloss.Style{enabledColStyle, nameColStyle, arnColStyle}
|
||||
|
||||
headers := []string{"On?", "Name", "RoleARN"}
|
||||
headerRow := []string{}
|
||||
|
||||
// Override some style settings for the header
|
||||
for ii, hdr := range headers {
|
||||
headerRow = append(headerRow,
|
||||
styles[ii].Copy().
|
||||
Bold(true).
|
||||
Foreground(lipgloss.Color("#6495ed")). // green
|
||||
Align(lipgloss.Center).
|
||||
Render(hdr),
|
||||
)
|
||||
}
|
||||
|
||||
lines := []string{strings.Join(headerRow, "")}
|
||||
|
||||
enabledOff := "🔴"
|
||||
enabledOn := "🟢"
|
||||
|
||||
for _, item := range i {
|
||||
enabled := enabledOff
|
||||
if item.Enabled {
|
||||
enabled = enabledOn
|
||||
}
|
||||
|
||||
line := []string{
|
||||
styles[0].Render(enabled),
|
||||
styles[1].Render(item.Name),
|
||||
styles[2].Render(item.RoleARN),
|
||||
}
|
||||
if item.Name == "_" {
|
||||
// For default config, don't display `_` and make it look faint.
|
||||
line[1] = styles[1].Copy().
|
||||
Faint(true).
|
||||
Render("(default)")
|
||||
}
|
||||
lines = append(lines, strings.Join(line, ""))
|
||||
}
|
||||
|
||||
boxContent := strings.Join(lines, "\n")
|
||||
boxStyle := lipgloss.NewStyle().
|
||||
BorderStyle(lipgloss.RoundedBorder())
|
||||
|
||||
return boxStyle.Render(boxContent)
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
// Copyright (c) 2015-2022 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/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/madmin-go/v2"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
|
||||
var adminIDPOpenidRemoveCmd = cli.Command{
|
||||
Name: "remove",
|
||||
ShortName: "rm",
|
||||
Usage: "remove OpenID IDP server configuration",
|
||||
Action: mainAdminIDPOpenIDRemove,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET [CFG_NAME]
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Remove the default OpenID IDP configuration (CFG_NAME is omitted).
|
||||
{{.Prompt}} {{.HelpName}} play/
|
||||
2. Remove OpenID IDP configuration named "dex_test".
|
||||
{{.Prompt}} {{.HelpName}} play/ dex_test
|
||||
`,
|
||||
}
|
||||
|
||||
func mainAdminIDPOpenIDRemove(ctx *cli.Context) error {
|
||||
if len(ctx.Args()) < 1 || len(ctx.Args()) > 2 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
args := ctx.Args()
|
||||
|
||||
var cfgName string
|
||||
if len(args) == 2 {
|
||||
cfgName = args.Get(1)
|
||||
}
|
||||
return adminIDPRemove(ctx, true, cfgName)
|
||||
}
|
||||
|
||||
func adminIDPRemove(ctx *cli.Context, isOpenID bool, cfgName string) error {
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
idpType := madmin.LDAPIDPCfg
|
||||
if isOpenID {
|
||||
idpType = madmin.OpenidIDPCfg
|
||||
}
|
||||
|
||||
restart, e := client.DeleteIDPConfig(globalContext, idpType, cfgName)
|
||||
fatalIf(probe.NewError(e), "Unable to remove %s IDP config '%s'", idpType, cfgName)
|
||||
|
||||
printMsg(configSetMessage{
|
||||
targetAlias: aliasedURL,
|
||||
restart: restart,
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
// Copyright (c) 2015-2022 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/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import "github.com/minio/cli"
|
||||
|
||||
var adminIDPOpenidUpdateCmd = cli.Command{
|
||||
Name: "update",
|
||||
Usage: "Update an OpenID IDP configuration",
|
||||
Action: mainAdminIDPOpenIDUpdate,
|
||||
Before: setGlobalsFromContext,
|
||||
OnUsageError: onUsageError,
|
||||
Flags: globalFlags,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET [CFG_NAME] [CFG_PARAMS...]
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Update the default OpenID IDP configuration (CFG_NAME is omitted).
|
||||
{{.Prompt}} {{.HelpName}} play/
|
||||
scopes="openid,groups" \
|
||||
role_policy="consoleAdmin"
|
||||
2. Update configuration for OpenID IDP configuration named "dex_test".
|
||||
{{.Prompt}} {{.HelpName}} play/ dex_test \
|
||||
scopes="openid,groups" \
|
||||
role_policy="consoleAdmin"
|
||||
`,
|
||||
}
|
||||
|
||||
func mainAdminIDPOpenIDUpdate(ctx *cli.Context) error {
|
||||
return mainAdminIDPOpenIDAddOrUpdate(ctx, true)
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
// Copyright (c) 2015-2022 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/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/minio/cli"
|
||||
)
|
||||
|
||||
var adminIDPRmCmd = cli.Command{
|
||||
Name: "remove",
|
||||
ShortName: "rm",
|
||||
Usage: "Remove an IDP configuration",
|
||||
Before: setGlobalsFromContext,
|
||||
Action: mainAdminIDPRemove,
|
||||
Hidden: true,
|
||||
OnUsageError: onUsageError,
|
||||
Flags: globalFlags,
|
||||
CustomHelpTemplate: `This command is DEPRECATED.
|
||||
|
||||
Please use "mc admin idp ldap|openid" instead.
|
||||
`,
|
||||
}
|
||||
|
||||
func mainAdminIDPRemove(_ *cli.Context) error {
|
||||
deprecatedError("mc admin idp ldap|openid")
|
||||
return nil
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
// Copyright (c) 2015-2022 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/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/minio/cli"
|
||||
)
|
||||
|
||||
var adminIDPSetCmd = cli.Command{
|
||||
Name: "set",
|
||||
Usage: "Create/Update an IDP server configuration",
|
||||
Before: setGlobalsFromContext,
|
||||
Action: mainAdminIDPSet,
|
||||
Hidden: true,
|
||||
OnUsageError: onUsageError,
|
||||
Flags: globalFlags,
|
||||
CustomHelpTemplate: `This command is DEPRECATED.
|
||||
|
||||
Please use commands under 'mc admin idp ldap|openid' instead.
|
||||
`,
|
||||
}
|
||||
|
||||
func mainAdminIDPSet(_ *cli.Context) error {
|
||||
deprecatedError("mc admin idp ldap|openid")
|
||||
return nil
|
||||
}
|
||||
+7
-12
@@ -19,26 +19,21 @@ package cmd
|
||||
|
||||
import "github.com/minio/cli"
|
||||
|
||||
var adminIDPSubcommands = []cli.Command{
|
||||
adminIDPOpenidCmd,
|
||||
adminIDPLdapCmd,
|
||||
adminIDPSetCmd,
|
||||
adminIDPInfoCmd,
|
||||
adminIDPLsCmd,
|
||||
adminIDPRmCmd,
|
||||
}
|
||||
|
||||
var adminIDPCmd = cli.Command{
|
||||
Name: "idp",
|
||||
Usage: "manage MinIO IDentity Provider server configuration",
|
||||
Action: mainAdminIDP,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
Subcommands: adminIDPSubcommands,
|
||||
HideHelpCommand: true,
|
||||
Hidden: true,
|
||||
CustomHelpTemplate: `This command's functionality has moved and this command is DEPRECATED.
|
||||
|
||||
Please use commands under 'mc idp ldap|openid' instead.
|
||||
`,
|
||||
}
|
||||
|
||||
func mainAdminIDP(ctx *cli.Context) error {
|
||||
commandNotFound(ctx, adminIDPSubcommands)
|
||||
func mainAdminIDP(_ *cli.Context) error {
|
||||
deprecatedError("mc idp ldap|openid")
|
||||
return nil
|
||||
}
|
||||
|
||||
+17
-22
@@ -361,30 +361,25 @@ var completeCmds = map[string]complete.Predictor{
|
||||
"/admin/profile/start": aliasCompleter,
|
||||
"/admin/profile/stop": aliasCompleter,
|
||||
|
||||
"/admin/idp/set": aliasCompleter,
|
||||
"/admin/idp/info": aliasCompleter,
|
||||
"/admin/idp/list": aliasCompleter,
|
||||
"/admin/idp/remove": aliasCompleter,
|
||||
"/idp/openid/add": aliasCompleter,
|
||||
"/idp/openid/update": aliasCompleter,
|
||||
"/idp/openid/remove": aliasCompleter,
|
||||
"/idp/openid/list": aliasCompleter,
|
||||
"/idp/openid/info": aliasCompleter,
|
||||
"/idp/openid/enable": aliasCompleter,
|
||||
"/idp/openid/disable": aliasCompleter,
|
||||
|
||||
"/admin/idp/openid/add": aliasCompleter,
|
||||
"/admin/idp/openid/update": aliasCompleter,
|
||||
"/admin/idp/openid/remove": aliasCompleter,
|
||||
"/admin/idp/openid/list": aliasCompleter,
|
||||
"/admin/idp/openid/info": aliasCompleter,
|
||||
"/admin/idp/openid/enable": aliasCompleter,
|
||||
"/admin/idp/openid/disable": aliasCompleter,
|
||||
"/idp/ldap/add": aliasCompleter,
|
||||
"/idp/ldap/update": aliasCompleter,
|
||||
"/idp/ldap/remove": aliasCompleter,
|
||||
"/idp/ldap/list": aliasCompleter,
|
||||
"/idp/ldap/info": aliasCompleter,
|
||||
"/idp/ldap/enable": aliasCompleter,
|
||||
"/idp/ldap/disable": aliasCompleter,
|
||||
|
||||
"/admin/idp/ldap/add": aliasCompleter,
|
||||
"/admin/idp/ldap/update": aliasCompleter,
|
||||
"/admin/idp/ldap/remove": aliasCompleter,
|
||||
"/admin/idp/ldap/list": aliasCompleter,
|
||||
"/admin/idp/ldap/info": aliasCompleter,
|
||||
"/admin/idp/ldap/enable": aliasCompleter,
|
||||
"/admin/idp/ldap/disable": aliasCompleter,
|
||||
|
||||
"/admin/idp/ldap/policy/entities": aliasCompleter,
|
||||
"/admin/idp/ldap/policy/attach": aliasCompleter,
|
||||
"/admin/idp/ldap/policy/detach": aliasCompleter,
|
||||
"/idp/ldap/policy/entities": aliasCompleter,
|
||||
"/idp/ldap/policy/attach": aliasCompleter,
|
||||
"/idp/ldap/policy/detach": aliasCompleter,
|
||||
|
||||
"/admin/policy/info": aliasCompleter,
|
||||
"/admin/policy/update": aliasCompleter,
|
||||
|
||||
@@ -0,0 +1,410 @@
|
||||
// Copyright (c) 2015-2023 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/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go/v2"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
|
||||
var idpLdapPolicyAttachFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "user, u",
|
||||
Usage: "attach policy to user by DN or by login name",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "group, g",
|
||||
Usage: "attach policy to LDAP Group DN",
|
||||
},
|
||||
}
|
||||
|
||||
var idpLdapPolicyAttachCmd = cli.Command{
|
||||
Name: "attach",
|
||||
Usage: "attach a policy to an entity",
|
||||
Action: mainIDPLdapPolicyAttach,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(idpLdapPolicyAttachFlags, globalFlags...),
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] TARGET POLICY [POLICY...] [ --user=USER | --group=GROUP ]
|
||||
|
||||
Exactly one "--user" or "--group" flag is required.
|
||||
|
||||
POLICY:
|
||||
Name of a policy on the MinIO server.
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Attach policy "mypolicy" to a user
|
||||
{{.Prompt}} {{.HelpName}} play/ mypolicy --user='uid=bobfisher,ou=people,ou=hwengg,dc=min,dc=io'
|
||||
2. Attach policies "policy1" and "policy2" to a group
|
||||
{{.Prompt}} {{.HelpName}} play/ policy1 policy2 --group='cn=projectb,ou=groups,ou=swengg,dc=min,dc=io'
|
||||
`,
|
||||
}
|
||||
|
||||
// Quote from AWS policy naming requirement (ref:
|
||||
// https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_iam-quotas.html):
|
||||
//
|
||||
// Names of users, groups, roles, policies, instance profiles, and server
|
||||
// certificates must be alphanumeric, including the following common characters:
|
||||
// plus (+), equal (=), comma (,), period (.), at (@), underscore (_), and
|
||||
// hyphen (-).
|
||||
|
||||
func mainIDPLdapPolicyAttach(ctx *cli.Context) error {
|
||||
// We need exactly one alias, and at least one policy.
|
||||
if len(ctx.Args()) < 2 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
user := ctx.String("user")
|
||||
group := ctx.String("group")
|
||||
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
policies := args[1:]
|
||||
req := madmin.PolicyAssociationReq{
|
||||
Policies: policies,
|
||||
User: user,
|
||||
Group: group,
|
||||
}
|
||||
fatalIf(probe.NewError(req.IsValid()), "Invalid policy attach arguments.")
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
res, e := client.AttachPolicyLDAP(globalContext, req)
|
||||
fatalIf(probe.NewError(e), "Unable to make LDAP policy association")
|
||||
|
||||
m := policyAssociationMessage{
|
||||
attach: true,
|
||||
Status: "success",
|
||||
PoliciesAttached: res.PoliciesAttached,
|
||||
User: user,
|
||||
Group: group,
|
||||
}
|
||||
printMsg(m)
|
||||
return nil
|
||||
}
|
||||
|
||||
type policyAssociationMessage struct {
|
||||
attach bool
|
||||
Status string `json:"status"`
|
||||
PoliciesAttached []string `json:"policiesAttached,omitempty"`
|
||||
PoliciesDetached []string `json:"policiesDetached,omitempty"`
|
||||
User string `json:"user,omitempty"`
|
||||
Group string `json:"group,omitempty"`
|
||||
}
|
||||
|
||||
func (m policyAssociationMessage) String() string {
|
||||
style := lipgloss.NewStyle().Foreground(lipgloss.Color("#04B575")) // green
|
||||
|
||||
policiesS := style.Render("Attached Policies:")
|
||||
entityS := style.Render("To User:")
|
||||
policies := m.PoliciesAttached
|
||||
entity := m.User
|
||||
switch {
|
||||
case m.User != "" && m.attach:
|
||||
case m.User != "" && !m.attach:
|
||||
policiesS = style.Render("Detached Policies:")
|
||||
policies = m.PoliciesDetached
|
||||
entityS = style.Render("From User:")
|
||||
case m.Group != "" && m.attach:
|
||||
entityS = style.Render("To Group:")
|
||||
entity = m.Group
|
||||
case m.Group != "" && !m.attach:
|
||||
policiesS = style.Render("Detached Policies:")
|
||||
policies = m.PoliciesDetached
|
||||
entityS = style.Render("From Group:")
|
||||
entity = m.Group
|
||||
}
|
||||
return fmt.Sprintf("%s %v\n%s %s\n", policiesS, policies, entityS, entity)
|
||||
}
|
||||
|
||||
func (m policyAssociationMessage) JSON() string {
|
||||
jsonMessageBytes, e := json.MarshalIndent(m, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(jsonMessageBytes)
|
||||
}
|
||||
|
||||
var idpLdapPolicyDetachFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "user, u",
|
||||
Usage: "attach policy to user by DN or by login name",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "group, g",
|
||||
Usage: "attach policy to LDAP Group DN",
|
||||
},
|
||||
}
|
||||
|
||||
var idpLdapPolicyDetachCmd = cli.Command{
|
||||
Name: "detach",
|
||||
Usage: "detach a policy from an entity",
|
||||
Action: mainIDPLdapPolicyDetach,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(idpLdapPolicyDetachFlags, globalFlags...),
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] TARGET POLICY [POLICY...] [ --user=USER | --group=GROUP ]
|
||||
|
||||
Exactly one of "--user" or "--group" is required.
|
||||
|
||||
POLICY:
|
||||
Name of a policy on the MinIO server.
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Detach policy "mypolicy" from a user
|
||||
{{.Prompt}} {{.HelpName}} play/ mypolicy --user='uid=bobfisher,ou=people,ou=hwengg,dc=min,dc=io'
|
||||
2. Detach policies "policy1" and "policy2" from a group
|
||||
{{.Prompt}} {{.HelpName}} play/ policy1 policy2 --group='cn=projectb,ou=groups,ou=swengg,dc=min,dc=io'
|
||||
`,
|
||||
}
|
||||
|
||||
// Quote from AWS policy naming requirement (ref:
|
||||
// https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_iam-quotas.html):
|
||||
//
|
||||
// Names of users, groups, roles, policies, instance profiles, and server
|
||||
// certificates must be alphanumeric, including the following common characters:
|
||||
// plus (+), equal (=), comma (,), period (.), at (@), underscore (_), and
|
||||
// hyphen (-).
|
||||
|
||||
func mainIDPLdapPolicyDetach(ctx *cli.Context) error {
|
||||
// We need exactly one alias, and at least one policy.
|
||||
if len(ctx.Args()) < 2 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
user := ctx.String("user")
|
||||
group := ctx.String("group")
|
||||
|
||||
if user == "" && group == "" {
|
||||
e := errors.New("at least one of --user or --group is required.")
|
||||
fatalIf(probe.NewError(e), "Missing flag in command")
|
||||
}
|
||||
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
policies := args[1:]
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
res, e := client.DetachPolicyLDAP(globalContext,
|
||||
madmin.PolicyAssociationReq{
|
||||
Policies: policies,
|
||||
User: user,
|
||||
Group: group,
|
||||
})
|
||||
fatalIf(probe.NewError(e), "Unable to make LDAP policy association")
|
||||
|
||||
m := policyAssociationMessage{
|
||||
attach: false,
|
||||
Status: "success",
|
||||
PoliciesDetached: res.PoliciesDetached,
|
||||
User: user,
|
||||
Group: group,
|
||||
}
|
||||
printMsg(m)
|
||||
return nil
|
||||
}
|
||||
|
||||
var idpLdapPolicyEntitiesFlags = []cli.Flag{
|
||||
cli.StringSliceFlag{
|
||||
Name: "user, u",
|
||||
Usage: "list policies associated with user(s)",
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
Name: "group, g",
|
||||
Usage: "list policies associated with group(s)",
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
Name: "policy, p",
|
||||
Usage: "list users or groups associated with policy",
|
||||
},
|
||||
}
|
||||
|
||||
var idpLdapPolicyEntitiesCmd = cli.Command{
|
||||
Name: "entities",
|
||||
Usage: "list policy association entities",
|
||||
Action: mainIDPLdapPolicyEntities,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(idpLdapPolicyEntitiesFlags, globalFlags...),
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. List all LDAP entities associated with all policies
|
||||
{{.Prompt}} {{.HelpName}} play/
|
||||
2. List all LDAP entities associated with the policies 'finteam-policy' and 'mlteam-policy'
|
||||
{{.Prompt}} {{.HelpName}} play/ --policy finteam-policy --policy mlteam-policy
|
||||
3. List all policies associated with a pair of User LDAP entities
|
||||
{{.Prompt}} {{.HelpName}} play/ \
|
||||
--user 'uid=bobfisher,ou=people,ou=hwengg,dc=min,dc=io' \
|
||||
--user 'uid=fahim,ou=people,ou=swengg,dc=min,dc=io'
|
||||
4. List all policies associated with a pair of Group LDAP entities
|
||||
{{.Prompt}} {{.HelpName}} play/ \
|
||||
--group 'cn=projecta,ou=groups,ou=swengg,dc=min,dc=io' \
|
||||
--group 'cn=projectb,ou=groups,ou=swengg,dc=min,dc=io'
|
||||
5. List all entities associated with a policy, group and user
|
||||
{{.Prompt}} {{.HelpName}} play/ \
|
||||
--policy finteam-policy
|
||||
--user 'uid=bobfisher,ou=people,ou=hwengg,dc=min,dc=io' \
|
||||
--group 'cn=projectb,ou=groups,ou=swengg,dc=min,dc=io'
|
||||
`,
|
||||
}
|
||||
|
||||
func mainIDPLdapPolicyEntities(ctx *cli.Context) error {
|
||||
if len(ctx.Args()) != 1 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
usersToQuery := ctx.StringSlice("user")
|
||||
groupsToQuery := ctx.StringSlice("group")
|
||||
policiesToQuery := ctx.StringSlice("policy")
|
||||
|
||||
args := ctx.Args()
|
||||
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
res, e := client.GetLDAPPolicyEntities(globalContext,
|
||||
madmin.PolicyEntitiesQuery{
|
||||
Users: usersToQuery,
|
||||
Groups: groupsToQuery,
|
||||
Policy: policiesToQuery,
|
||||
})
|
||||
fatalIf(probe.NewError(e), "Unable to fetch LDAP policy entities")
|
||||
|
||||
printMsg(policyEntitiesFrom(res))
|
||||
return nil
|
||||
}
|
||||
|
||||
type policyEntities struct {
|
||||
Status string `json:"status"`
|
||||
Result madmin.PolicyEntitiesResult `json:"result"`
|
||||
}
|
||||
|
||||
func policyEntitiesFrom(r madmin.PolicyEntitiesResult) policyEntities {
|
||||
return policyEntities{
|
||||
Status: "success",
|
||||
Result: r,
|
||||
}
|
||||
}
|
||||
|
||||
func (p policyEntities) JSON() string {
|
||||
bs, e := json.MarshalIndent(p, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(bs)
|
||||
}
|
||||
|
||||
func iFmt(n int, fmtStr string, a ...any) string {
|
||||
indentStr := ""
|
||||
if n > 0 {
|
||||
s := make([]rune, n)
|
||||
for i := range s {
|
||||
s[i] = ' '
|
||||
}
|
||||
indentStr = string(s)
|
||||
}
|
||||
return fmt.Sprintf(indentStr+fmtStr, a...)
|
||||
}
|
||||
|
||||
func (p policyEntities) String() string {
|
||||
labelStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("#04B575")) // green
|
||||
o := strings.Builder{}
|
||||
|
||||
o.WriteString(iFmt(0, "%s %s\n",
|
||||
labelStyle.Render("Query time:"),
|
||||
p.Result.Timestamp.Format(time.RFC3339)))
|
||||
|
||||
if len(p.Result.UserMappings) > 0 {
|
||||
o.WriteString(iFmt(0, "%s\n", labelStyle.Render("User -> Policy Mappings:")))
|
||||
|
||||
for _, u := range p.Result.UserMappings {
|
||||
o.WriteString(iFmt(2, "%s %s\n", labelStyle.Render("User:"), u.User))
|
||||
for _, p := range u.Policies {
|
||||
o.WriteString(iFmt(4, "%s\n", p))
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(p.Result.GroupMappings) > 0 {
|
||||
o.WriteString(iFmt(0, "%s\n", labelStyle.Render("Group -> Policy Mappings:")))
|
||||
|
||||
for _, u := range p.Result.GroupMappings {
|
||||
o.WriteString(iFmt(2, "%s %s\n", labelStyle.Render("Group:"), u.Group))
|
||||
for _, p := range u.Policies {
|
||||
o.WriteString(iFmt(4, "%s\n", p))
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(p.Result.PolicyMappings) > 0 {
|
||||
o.WriteString(iFmt(0, "%s\n", labelStyle.Render("Policy -> Entity Mappings:")))
|
||||
|
||||
for _, u := range p.Result.PolicyMappings {
|
||||
o.WriteString(iFmt(2, "%s %s\n", labelStyle.Render("Policy:"), u.Policy))
|
||||
if len(u.Users) > 0 {
|
||||
o.WriteString(iFmt(4, "%s\n", labelStyle.Render("User Mappings:")))
|
||||
for _, p := range u.Users {
|
||||
o.WriteString(iFmt(6, "%s\n", p))
|
||||
}
|
||||
}
|
||||
if len(u.Groups) > 0 {
|
||||
o.WriteString(iFmt(4, "%s\n", labelStyle.Render("Group Mappings:")))
|
||||
for _, p := range u.Groups {
|
||||
o.WriteString(iFmt(6, "%s\n", p))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return o.String()
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
// Copyright (c) 2015-2023 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -19,23 +19,23 @@ package cmd
|
||||
|
||||
import "github.com/minio/cli"
|
||||
|
||||
var adminIDPLdapPolicySubcommands = []cli.Command{
|
||||
adminIDPLdapPolicyAttachCmd,
|
||||
adminIDPLdapPolicyDetachCmd,
|
||||
adminIDPLdapPolicyEntitiesCmd,
|
||||
var idpLdapPolicySubcommands = []cli.Command{
|
||||
idpLdapPolicyAttachCmd,
|
||||
idpLdapPolicyDetachCmd,
|
||||
idpLdapPolicyEntitiesCmd,
|
||||
}
|
||||
|
||||
var adminIDPLdapPolicyCmd = cli.Command{
|
||||
var idpLdapPolicyCmd = cli.Command{
|
||||
Name: "policy",
|
||||
Usage: "manage policy assignments for LDAP",
|
||||
Action: mainAdminIDPLDAPPolicy,
|
||||
Action: mainIDPLDAPPolicy,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
Subcommands: adminIDPLdapPolicySubcommands,
|
||||
Subcommands: idpLdapPolicySubcommands,
|
||||
HideHelpCommand: true,
|
||||
}
|
||||
|
||||
func mainAdminIDPLDAPPolicy(ctx *cli.Context) error {
|
||||
commandNotFound(ctx, adminIDPLdapPolicySubcommands)
|
||||
func mainIDPLDAPPolicy(ctx *cli.Context) error {
|
||||
commandNotFound(ctx, idpLdapPolicySubcommands)
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,314 @@
|
||||
// Copyright (c) 2015-2023 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/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/madmin-go/v2"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
|
||||
var idpLdapAddCmd = cli.Command{
|
||||
Name: "add",
|
||||
Usage: "Create an LDAP IDP server configuration",
|
||||
Action: mainIDPLDAPAdd,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET [CFG_PARAMS...]
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Create LDAP IDentity Provider configuration.
|
||||
{{.Prompt}} {{.HelpName}} myminio/ \
|
||||
server_addr=myldapserver:636 \
|
||||
lookup_bind_dn=cn=admin,dc=min,dc=io \
|
||||
lookup_bind_password=somesecret \
|
||||
user_dn_search_base_dn=dc=min,dc=io \
|
||||
user_dn_search_filter="(uid=%s)" \
|
||||
group_search_base_dn=ou=swengg,dc=min,dc=io \
|
||||
group_search_filter="(&(objectclass=groupofnames)(member=%d))"
|
||||
`,
|
||||
}
|
||||
|
||||
func mainIDPLDAPAdd(ctx *cli.Context) error {
|
||||
if len(ctx.Args()) < 2 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
args := ctx.Args()
|
||||
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
cfgName := madmin.Default
|
||||
input := args[1:]
|
||||
if !strings.Contains(args.Get(1), "=") {
|
||||
cfgName = args.Get(1)
|
||||
input = args[2:]
|
||||
}
|
||||
|
||||
if cfgName != madmin.Default {
|
||||
fatalIf(probe.NewError(errors.New("all config parameters must be of the form \"key=value\"")),
|
||||
"Bad LDAP IDP configuration")
|
||||
}
|
||||
|
||||
inputCfg := strings.Join(input, " ")
|
||||
|
||||
restart, e := client.AddOrUpdateIDPConfig(globalContext, madmin.LDAPIDPCfg, cfgName, inputCfg, false)
|
||||
fatalIf(probe.NewError(e), "Unable to add LDAP IDP config to server")
|
||||
|
||||
// Print set config result
|
||||
printMsg(configSetMessage{
|
||||
targetAlias: aliasedURL,
|
||||
restart: restart,
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var idpLdapUpdateCmd = cli.Command{
|
||||
Name: "update",
|
||||
Usage: "Update an LDAP IDP configuration",
|
||||
Action: mainIDPLDAPUpdate,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET [CFG_PARAMS...]
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Update the LDAP IDP configuration.
|
||||
{{.Prompt}} {{.HelpName}} play/ \
|
||||
lookup_bind_dn=cn=admin,dc=min,dc=io \
|
||||
lookup_bind_password=somesecret
|
||||
`,
|
||||
}
|
||||
|
||||
func mainIDPLDAPUpdate(ctx *cli.Context) error {
|
||||
if len(ctx.Args()) < 2 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
args := ctx.Args()
|
||||
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
cfgName := madmin.Default
|
||||
input := args[1:]
|
||||
if !strings.Contains(args.Get(1), "=") {
|
||||
cfgName = args.Get(1)
|
||||
input = args[2:]
|
||||
}
|
||||
|
||||
if cfgName != madmin.Default {
|
||||
fatalIf(probe.NewError(errors.New("all config parameters must be of the form \"key=value\"")),
|
||||
"Bad LDAP IDP configuration")
|
||||
}
|
||||
|
||||
inputCfg := strings.Join(input, " ")
|
||||
|
||||
restart, e := client.AddOrUpdateIDPConfig(globalContext, madmin.LDAPIDPCfg, cfgName, inputCfg, true)
|
||||
fatalIf(probe.NewError(e), "Unable to update LDAP IDP configuration")
|
||||
|
||||
// Print set config result
|
||||
printMsg(configSetMessage{
|
||||
targetAlias: aliasedURL,
|
||||
restart: restart,
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var idpLdapRemoveCmd = cli.Command{
|
||||
Name: "remove",
|
||||
ShortName: "rm",
|
||||
Usage: "remove LDAP IDP server configuration",
|
||||
Action: mainIDPLDAPRemove,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Remove the default LDAP IDP configuration.
|
||||
{{.Prompt}} {{.HelpName}} play/
|
||||
`,
|
||||
}
|
||||
|
||||
func mainIDPLDAPRemove(ctx *cli.Context) error {
|
||||
if len(ctx.Args()) != 1 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
var cfgName string = madmin.Default
|
||||
return idpRemove(ctx, false, cfgName)
|
||||
}
|
||||
|
||||
var idpLdapListCmd = cli.Command{
|
||||
Name: "list",
|
||||
ShortName: "ls",
|
||||
Usage: "list LDAP IDP server configuration(s)",
|
||||
Action: mainIDPLDAPList,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. List configurations for LDAP IDP.
|
||||
{{.Prompt}} {{.HelpName}} play/
|
||||
`,
|
||||
}
|
||||
|
||||
func mainIDPLDAPList(ctx *cli.Context) error {
|
||||
if len(ctx.Args()) != 1 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
return idpListCommon(ctx, false)
|
||||
}
|
||||
|
||||
var idpLdapInfoCmd = cli.Command{
|
||||
Name: "info",
|
||||
Usage: "get LDAP IDP server configuration info",
|
||||
Action: mainIDPLDAPInfo,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Get configuration info on the LDAP IDP configuration.
|
||||
{{.Prompt}} {{.HelpName}} play/
|
||||
`,
|
||||
}
|
||||
|
||||
func mainIDPLDAPInfo(ctx *cli.Context) error {
|
||||
if len(ctx.Args()) != 1 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
var cfgName string = madmin.Default
|
||||
return idpInfo(ctx, false, cfgName)
|
||||
}
|
||||
|
||||
var idpLdapEnableCmd = cli.Command{
|
||||
Name: "enable",
|
||||
Usage: "manage LDAP IDP server configuration",
|
||||
Action: mainIDPLDAPEnable,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Enable the LDAP IDP configuration.
|
||||
{{.Prompt}} {{.HelpName}} play/
|
||||
`,
|
||||
}
|
||||
|
||||
func mainIDPLDAPEnable(ctx *cli.Context) error {
|
||||
if len(ctx.Args()) != 1 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
isOpenID, enable := false, true
|
||||
return idpEnableDisable(ctx, isOpenID, enable)
|
||||
}
|
||||
|
||||
var idpLdapDisableCmd = cli.Command{
|
||||
Name: "disable",
|
||||
Usage: "Disable an LDAP IDP server configuration",
|
||||
Action: mainIDPLDAPDisable,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Disable the default LDAP IDP configuration.
|
||||
{{.Prompt}} {{.HelpName}} play/
|
||||
`,
|
||||
}
|
||||
|
||||
func mainIDPLDAPDisable(ctx *cli.Context) error {
|
||||
if len(ctx.Args()) != 1 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
isOpenID, enable := false, false
|
||||
return idpEnableDisable(ctx, isOpenID, enable)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
// Copyright (c) 2015-2023 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -20,28 +20,28 @@ package cmd
|
||||
import "github.com/minio/cli"
|
||||
|
||||
var (
|
||||
adminIDPLdapSubcommands = []cli.Command{
|
||||
adminIDPLdapAddCmd,
|
||||
adminIDPLdapUpdateCmd,
|
||||
adminIDPLdapRemoveCmd,
|
||||
adminIDPLdapListCmd,
|
||||
adminIDPLdapInfoCmd,
|
||||
adminIDPLdapEnableCmd,
|
||||
adminIDPLdapDisableCmd,
|
||||
adminIDPLdapPolicyCmd,
|
||||
idpLdapSubcommands = []cli.Command{
|
||||
idpLdapAddCmd,
|
||||
idpLdapUpdateCmd,
|
||||
idpLdapRemoveCmd,
|
||||
idpLdapListCmd,
|
||||
idpLdapInfoCmd,
|
||||
idpLdapEnableCmd,
|
||||
idpLdapDisableCmd,
|
||||
idpLdapPolicyCmd,
|
||||
}
|
||||
adminIDPLdapCmd = cli.Command{
|
||||
idpLdapCmd = cli.Command{
|
||||
Name: "ldap",
|
||||
Usage: "manage Ldap IDP server configuration",
|
||||
Action: mainAdminIDPLdap,
|
||||
Action: mainIDPLdap,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
Subcommands: adminIDPLdapSubcommands,
|
||||
Subcommands: idpLdapSubcommands,
|
||||
HideHelpCommand: true,
|
||||
}
|
||||
)
|
||||
|
||||
func mainAdminIDPLdap(ctx *cli.Context) error {
|
||||
commandNotFound(ctx, adminIDPLdapSubcommands)
|
||||
func mainIDPLdap(ctx *cli.Context) error {
|
||||
commandNotFound(ctx, idpLdapSubcommands)
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,551 @@
|
||||
// Copyright (c) 2015-2023 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/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go/v2"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
|
||||
var idpOpenidAddCmd = cli.Command{
|
||||
Name: "add",
|
||||
Usage: "Create an OpenID IDP server configuration",
|
||||
Action: mainIDPOpenIDAdd,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET [CFG_NAME] [CFG_PARAMS...]
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Create a default OpenID IDP configuration (CFG_NAME is omitted).
|
||||
{{.Prompt}} {{.HelpName}} play/ \
|
||||
client_id=minio-client-app \
|
||||
client_secret=minio-client-app-secret \
|
||||
config_url="http://localhost:5556/dex/.well-known/openid-configuration" \
|
||||
scopes="openid,groups" \
|
||||
redirect_uri="http://127.0.0.1:10000/oauth_callback" \
|
||||
role_policy="consoleAdmin"
|
||||
2. Create OpenID IDP configuration named "dex_test".
|
||||
{{.Prompt}} {{.HelpName}} play/ dex_test \
|
||||
client_id=minio-client-app \
|
||||
client_secret=minio-client-app-secret \
|
||||
config_url="http://localhost:5556/dex/.well-known/openid-configuration" \
|
||||
scopes="openid,groups" \
|
||||
redirect_uri="http://127.0.0.1:10000/oauth_callback" \
|
||||
role_policy="consoleAdmin"
|
||||
`,
|
||||
}
|
||||
|
||||
func mainIDPOpenIDAdd(ctx *cli.Context) error {
|
||||
return mainIDPOpenIDAddOrUpdate(ctx, false)
|
||||
}
|
||||
|
||||
func mainIDPOpenIDAddOrUpdate(ctx *cli.Context, update bool) error {
|
||||
if len(ctx.Args()) < 2 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
args := ctx.Args()
|
||||
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
cfgName := madmin.Default
|
||||
input := args[1:]
|
||||
if !strings.Contains(args.Get(1), "=") {
|
||||
cfgName = args.Get(1)
|
||||
input = args[2:]
|
||||
}
|
||||
|
||||
inputCfg := strings.Join(input, " ")
|
||||
|
||||
restart, e := client.AddOrUpdateIDPConfig(globalContext, madmin.OpenidIDPCfg, cfgName, inputCfg, update)
|
||||
fatalIf(probe.NewError(e), "Unable to add OpenID IDP config to server")
|
||||
|
||||
// Print set config result
|
||||
printMsg(configSetMessage{
|
||||
targetAlias: aliasedURL,
|
||||
restart: restart,
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var idpOpenidUpdateCmd = cli.Command{
|
||||
Name: "update",
|
||||
Usage: "Update an OpenID IDP configuration",
|
||||
Action: mainIDPOpenIDUpdate,
|
||||
Before: setGlobalsFromContext,
|
||||
OnUsageError: onUsageError,
|
||||
Flags: globalFlags,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET [CFG_NAME] [CFG_PARAMS...]
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Update the default OpenID IDP configuration (CFG_NAME is omitted).
|
||||
{{.Prompt}} {{.HelpName}} play/
|
||||
scopes="openid,groups" \
|
||||
role_policy="consoleAdmin"
|
||||
2. Update configuration for OpenID IDP configuration named "dex_test".
|
||||
{{.Prompt}} {{.HelpName}} play/ dex_test \
|
||||
scopes="openid,groups" \
|
||||
role_policy="consoleAdmin"
|
||||
`,
|
||||
}
|
||||
|
||||
func mainIDPOpenIDUpdate(ctx *cli.Context) error {
|
||||
return mainIDPOpenIDAddOrUpdate(ctx, true)
|
||||
}
|
||||
|
||||
var idpOpenidRemoveCmd = cli.Command{
|
||||
Name: "remove",
|
||||
ShortName: "rm",
|
||||
Usage: "remove OpenID IDP server configuration",
|
||||
Action: mainIDPOpenIDRemove,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET [CFG_NAME]
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Remove the default OpenID IDP configuration (CFG_NAME is omitted).
|
||||
{{.Prompt}} {{.HelpName}} play/
|
||||
2. Remove OpenID IDP configuration named "dex_test".
|
||||
{{.Prompt}} {{.HelpName}} play/ dex_test
|
||||
`,
|
||||
}
|
||||
|
||||
func mainIDPOpenIDRemove(ctx *cli.Context) error {
|
||||
if len(ctx.Args()) < 1 || len(ctx.Args()) > 2 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
args := ctx.Args()
|
||||
|
||||
var cfgName string
|
||||
if len(args) == 2 {
|
||||
cfgName = args.Get(1)
|
||||
}
|
||||
return idpRemove(ctx, true, cfgName)
|
||||
}
|
||||
|
||||
func idpRemove(ctx *cli.Context, isOpenID bool, cfgName string) error {
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
idpType := madmin.LDAPIDPCfg
|
||||
if isOpenID {
|
||||
idpType = madmin.OpenidIDPCfg
|
||||
}
|
||||
|
||||
restart, e := client.DeleteIDPConfig(globalContext, idpType, cfgName)
|
||||
fatalIf(probe.NewError(e), "Unable to remove %s IDP config '%s'", idpType, cfgName)
|
||||
|
||||
printMsg(configSetMessage{
|
||||
targetAlias: aliasedURL,
|
||||
restart: restart,
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var idpOpenidListCmd = cli.Command{
|
||||
Name: "list",
|
||||
ShortName: "ls",
|
||||
Usage: "list OpenID IDP server configuration(s)",
|
||||
Action: mainIDPOpenIDList,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. List configurations for OpenID IDP.
|
||||
{{.Prompt}} {{.HelpName}} play/
|
||||
`,
|
||||
}
|
||||
|
||||
func mainIDPOpenIDList(ctx *cli.Context) error {
|
||||
if len(ctx.Args()) != 1 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
return idpListCommon(ctx, true)
|
||||
}
|
||||
|
||||
func idpListCommon(ctx *cli.Context, isOpenID bool) error {
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
idpType := madmin.LDAPIDPCfg
|
||||
if isOpenID {
|
||||
idpType = madmin.OpenidIDPCfg
|
||||
}
|
||||
result, e := client.ListIDPConfig(globalContext, idpType)
|
||||
fatalIf(probe.NewError(e), "Unable to list IDP config for '%s'", idpType)
|
||||
|
||||
printMsg(idpCfgList(result))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type idpCfgList []madmin.IDPListItem
|
||||
|
||||
func (i idpCfgList) JSON() string {
|
||||
bs, e := json.MarshalIndent(i, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(bs)
|
||||
}
|
||||
|
||||
func (i idpCfgList) String() string {
|
||||
maxNameWidth := len("Name")
|
||||
maxRoleARNWidth := len("RoleArn")
|
||||
for _, item := range i {
|
||||
name := item.Name
|
||||
if name == "_" {
|
||||
name = "(default)" // for the un-named config, don't show `_`
|
||||
}
|
||||
if maxNameWidth < len(name) {
|
||||
maxNameWidth = len(name)
|
||||
}
|
||||
if maxRoleARNWidth < len(item.RoleARN) {
|
||||
maxRoleARNWidth = len(item.RoleARN)
|
||||
}
|
||||
}
|
||||
enabledWidth := 5
|
||||
// Add 2 for padding
|
||||
maxNameWidth += 2
|
||||
maxRoleARNWidth += 2
|
||||
|
||||
enabledColStyle := lipgloss.NewStyle().
|
||||
Align(lipgloss.Center).
|
||||
PaddingLeft(1).
|
||||
PaddingRight(1).
|
||||
Width(enabledWidth)
|
||||
nameColStyle := lipgloss.NewStyle().
|
||||
Align(lipgloss.Right).
|
||||
PaddingLeft(1).
|
||||
PaddingRight(1).
|
||||
Width(maxNameWidth)
|
||||
arnColStyle := lipgloss.NewStyle().
|
||||
Align(lipgloss.Left).
|
||||
PaddingLeft(1).
|
||||
PaddingRight(1).
|
||||
Foreground(lipgloss.Color("#04B575")). // green
|
||||
Width(maxRoleARNWidth)
|
||||
|
||||
styles := []lipgloss.Style{enabledColStyle, nameColStyle, arnColStyle}
|
||||
|
||||
headers := []string{"On?", "Name", "RoleARN"}
|
||||
headerRow := []string{}
|
||||
|
||||
// Override some style settings for the header
|
||||
for ii, hdr := range headers {
|
||||
headerRow = append(headerRow,
|
||||
styles[ii].Copy().
|
||||
Bold(true).
|
||||
Foreground(lipgloss.Color("#6495ed")). // green
|
||||
Align(lipgloss.Center).
|
||||
Render(hdr),
|
||||
)
|
||||
}
|
||||
|
||||
lines := []string{strings.Join(headerRow, "")}
|
||||
|
||||
enabledOff := "🔴"
|
||||
enabledOn := "🟢"
|
||||
|
||||
for _, item := range i {
|
||||
enabled := enabledOff
|
||||
if item.Enabled {
|
||||
enabled = enabledOn
|
||||
}
|
||||
|
||||
line := []string{
|
||||
styles[0].Render(enabled),
|
||||
styles[1].Render(item.Name),
|
||||
styles[2].Render(item.RoleARN),
|
||||
}
|
||||
if item.Name == "_" {
|
||||
// For default config, don't display `_` and make it look faint.
|
||||
line[1] = styles[1].Copy().
|
||||
Faint(true).
|
||||
Render("(default)")
|
||||
}
|
||||
lines = append(lines, strings.Join(line, ""))
|
||||
}
|
||||
|
||||
boxContent := strings.Join(lines, "\n")
|
||||
boxStyle := lipgloss.NewStyle().
|
||||
BorderStyle(lipgloss.RoundedBorder())
|
||||
|
||||
return boxStyle.Render(boxContent)
|
||||
}
|
||||
|
||||
var idpOpenidInfoCmd = cli.Command{
|
||||
Name: "info",
|
||||
Usage: "get OpenID IDP server configuration info",
|
||||
Action: mainIDPOpenIDInfo,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET [CFG_NAME]
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Get configuration info on the default OpenID IDP configuration (CFG_NAME is omitted).
|
||||
{{.Prompt}} {{.HelpName}} play/
|
||||
2. Get configuration info on OpenID IDP configuration named "dex_test".
|
||||
{{.Prompt}} {{.HelpName}} play/ dex_test
|
||||
`,
|
||||
}
|
||||
|
||||
func mainIDPOpenIDInfo(ctx *cli.Context) error {
|
||||
if len(ctx.Args()) < 1 || len(ctx.Args()) > 2 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
args := ctx.Args()
|
||||
var cfgName string
|
||||
if len(args) == 2 {
|
||||
cfgName = args.Get(1)
|
||||
}
|
||||
|
||||
return idpInfo(ctx, true, cfgName)
|
||||
}
|
||||
|
||||
func idpInfo(ctx *cli.Context, isOpenID bool, cfgName string) error {
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
idpType := madmin.LDAPIDPCfg
|
||||
if isOpenID {
|
||||
idpType = madmin.OpenidIDPCfg
|
||||
}
|
||||
|
||||
result, e := client.GetIDPConfig(globalContext, idpType, cfgName)
|
||||
fatalIf(probe.NewError(e), "Unable to get %s IDP config from server", idpType)
|
||||
|
||||
// Print set config result
|
||||
printMsg(idpConfig(result))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type idpConfig madmin.IDPConfig
|
||||
|
||||
func (i idpConfig) JSON() string {
|
||||
bs, e := json.MarshalIndent(i, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(bs)
|
||||
}
|
||||
|
||||
func (i idpConfig) String() string {
|
||||
// Determine required width for key column.
|
||||
fieldColWidth := 0
|
||||
for _, kv := range i.Info {
|
||||
if fieldColWidth < len(kv.Key) {
|
||||
fieldColWidth = len(kv.Key)
|
||||
}
|
||||
}
|
||||
// Add 1 for the colon-suffix in each entry.
|
||||
fieldColWidth++
|
||||
|
||||
fieldColStyle := lipgloss.NewStyle().
|
||||
Width(fieldColWidth).
|
||||
Foreground(lipgloss.Color("#04B575")). // green
|
||||
Bold(true).
|
||||
Align(lipgloss.Right)
|
||||
valueColStyle := lipgloss.NewStyle().
|
||||
PaddingLeft(1).
|
||||
Align(lipgloss.Left)
|
||||
envMarkStyle := lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("201")). // pinkish-red
|
||||
PaddingLeft(1)
|
||||
|
||||
var lines []string
|
||||
for _, kv := range i.Info {
|
||||
envStr := ""
|
||||
if kv.IsCfg && kv.IsEnv {
|
||||
envStr = " (environment)"
|
||||
}
|
||||
lines = append(lines, fmt.Sprintf("%s%s%s",
|
||||
fieldColStyle.Render(kv.Key+":"),
|
||||
valueColStyle.Render(kv.Value),
|
||||
envMarkStyle.Render(envStr),
|
||||
))
|
||||
}
|
||||
|
||||
boxContent := strings.Join(lines, "\n")
|
||||
|
||||
boxStyle := lipgloss.NewStyle().
|
||||
BorderStyle(lipgloss.RoundedBorder())
|
||||
|
||||
return boxStyle.Render(boxContent)
|
||||
}
|
||||
|
||||
var idpOpenidEnableCmd = cli.Command{
|
||||
Name: "enable",
|
||||
Usage: "enable an OpenID IDP server configuration",
|
||||
Action: mainIDPOpenIDEnable,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET [CFG_NAME]
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Enable the default OpenID IDP configuration (CFG_NAME is omitted).
|
||||
{{.Prompt}} {{.HelpName}} play/
|
||||
2. Enable OpenID IDP configuration named "dex_test".
|
||||
{{.Prompt}} {{.HelpName}} play/ dex_test
|
||||
`,
|
||||
}
|
||||
|
||||
func mainIDPOpenIDEnable(ctx *cli.Context) error {
|
||||
isOpenID, enable := true, true
|
||||
return idpEnableDisable(ctx, isOpenID, enable)
|
||||
}
|
||||
|
||||
func idpEnableDisable(ctx *cli.Context, isOpenID bool, enable bool) error {
|
||||
if len(ctx.Args()) < 1 || len(ctx.Args()) > 2 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
args := ctx.Args()
|
||||
cfgName := madmin.Default
|
||||
if len(args) == 2 {
|
||||
cfgName = args.Get(1)
|
||||
}
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
idpType := madmin.LDAPIDPCfg
|
||||
if isOpenID {
|
||||
idpType = madmin.OpenidIDPCfg
|
||||
}
|
||||
|
||||
configBody := "enable=on"
|
||||
if !enable {
|
||||
configBody = "enable=off"
|
||||
}
|
||||
|
||||
restart, e := client.AddOrUpdateIDPConfig(globalContext, idpType, cfgName, configBody, true)
|
||||
fatalIf(probe.NewError(e), "Unable to remove %s IDP config '%s'", idpType, cfgName)
|
||||
|
||||
printMsg(configSetMessage{
|
||||
targetAlias: aliasedURL,
|
||||
restart: restart,
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var idpOpenidDisableCmd = cli.Command{
|
||||
Name: "disable",
|
||||
Usage: "Disable an OpenID IDP server configuration",
|
||||
Action: mainIDPOpenIDDisable,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET [CFG_NAME]
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Disable the default OpenID IDP configuration (CFG_NAME is omitted).
|
||||
{{.Prompt}} {{.HelpName}} play/
|
||||
2. Disable OpenID IDP configuration named "dex_test".
|
||||
{{.Prompt}} {{.HelpName}} play/ dex_test
|
||||
`,
|
||||
}
|
||||
|
||||
func mainIDPOpenIDDisable(ctx *cli.Context) error {
|
||||
isOpenID, enable := true, false
|
||||
return idpEnableDisable(ctx, isOpenID, enable)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
// Copyright (c) 2015-2023 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -20,28 +20,28 @@ package cmd
|
||||
import "github.com/minio/cli"
|
||||
|
||||
var (
|
||||
adminIDPOpenidSubcommands = []cli.Command{
|
||||
adminIDPOpenidAddCmd,
|
||||
adminIDPOpenidUpdateCmd,
|
||||
adminIDPOpenidRemoveCmd,
|
||||
adminIDPOpenidListCmd,
|
||||
adminIDPOpenidInfoCmd,
|
||||
adminIDPOpenidEnableCmd,
|
||||
adminIDPOpenidDisableCmd,
|
||||
// TODO: adminIDPOpenidPolicyCmd,
|
||||
idpOpenidSubcommands = []cli.Command{
|
||||
idpOpenidAddCmd,
|
||||
idpOpenidUpdateCmd,
|
||||
idpOpenidRemoveCmd,
|
||||
idpOpenidListCmd,
|
||||
idpOpenidInfoCmd,
|
||||
idpOpenidEnableCmd,
|
||||
idpOpenidDisableCmd,
|
||||
// TODO: idpOpenidPolicyCmd,
|
||||
}
|
||||
adminIDPOpenidCmd = cli.Command{
|
||||
idpOpenidCmd = cli.Command{
|
||||
Name: "openid",
|
||||
Usage: "manage OpenID IDP server configuration",
|
||||
Action: mainAdminIDPOpenID,
|
||||
Action: mainIDPOpenID,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
Subcommands: adminIDPOpenidSubcommands,
|
||||
Subcommands: idpOpenidSubcommands,
|
||||
HideHelpCommand: true,
|
||||
}
|
||||
)
|
||||
|
||||
func mainAdminIDPOpenID(ctx *cli.Context) error {
|
||||
commandNotFound(ctx, adminIDPOpenidSubcommands)
|
||||
func mainIDPOpenID(ctx *cli.Context) error {
|
||||
commandNotFound(ctx, idpOpenidSubcommands)
|
||||
return nil
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
// Copyright (c) 2015-2023 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -17,25 +17,24 @@
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/minio/cli"
|
||||
)
|
||||
import "github.com/minio/cli"
|
||||
|
||||
var adminIDPInfoCmd = cli.Command{
|
||||
Name: "info",
|
||||
Usage: "Show IDP server config info",
|
||||
Before: setGlobalsFromContext,
|
||||
Action: mainAdminIDPGet,
|
||||
OnUsageError: onUsageError,
|
||||
Hidden: true,
|
||||
Flags: globalFlags,
|
||||
CustomHelpTemplate: `This command is DEPRECATED.
|
||||
|
||||
Please use "mc admin idp ldap|openid" instead.
|
||||
`,
|
||||
var idpSubcommands = []cli.Command{
|
||||
idpOpenidCmd,
|
||||
idpLdapCmd,
|
||||
}
|
||||
|
||||
func mainAdminIDPGet(_ *cli.Context) error {
|
||||
deprecatedError("mc admin idp ldap|openid")
|
||||
var idpCmd = cli.Command{
|
||||
Name: "idp",
|
||||
Usage: "manage MinIO IDentity Provider server configuration",
|
||||
Action: mainIDP,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
Subcommands: idpSubcommands,
|
||||
HideHelpCommand: true,
|
||||
}
|
||||
|
||||
func mainIDP(ctx *cli.Context) error {
|
||||
commandNotFound(ctx, idpSubcommands)
|
||||
return nil
|
||||
}
|
||||
@@ -453,6 +453,7 @@ var appCmds = []cli.Command{
|
||||
diffCmd,
|
||||
replicateCmd,
|
||||
adminCmd,
|
||||
idpCmd,
|
||||
configCmd,
|
||||
updateCmd,
|
||||
readyCmd,
|
||||
|
||||
Reference in New Issue
Block a user