Skip to content

Commit 6adf13f

Browse files
committed
Add new commands for openid and ldap configuration
This change also hides the following commands and adds a deprecation notice: mc admin idp set|ls|rm|info
1 parent a4a9b8f commit 6adf13f

24 files changed

+1238
-202
lines changed

cmd/admin-idp-info.go

Lines changed: 6 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,8 @@
1818
package cmd
1919

2020
import (
21-
"fmt"
22-
"strings"
23-
24-
"github.com/charmbracelet/lipgloss"
2521
"github.com/minio/cli"
26-
json "github.com/minio/colorjson"
2722
"github.com/minio/madmin-go"
28-
"github.com/minio/mc/pkg/probe"
2923
)
3024

3125
var adminIDPInfoCmd = cli.Command{
@@ -34,6 +28,7 @@ var adminIDPInfoCmd = cli.Command{
3428
Before: setGlobalsFromContext,
3529
Action: mainAdminIDPGet,
3630
OnUsageError: onUsageError,
31+
Hidden: true,
3732
Flags: globalFlags,
3833
CustomHelpTemplate: `NAME:
3934
{{.HelpName}} - {{.Usage}}
@@ -43,6 +38,9 @@ USAGE:
4338
4439
ID_TYPE must be one of 'ldap' or 'openid'.
4540
41+
**DEPRECATED**: This command will be removed in a future version. Please use
42+
"mc admin idp ldap|openid" instead.
43+
4644
FLAGS:
4745
{{range .VisibleFlags}}{{.}}
4846
{{end}}
@@ -62,78 +60,14 @@ func mainAdminIDPGet(ctx *cli.Context) error {
6260
}
6361

6462
args := ctx.Args()
65-
aliasedURL := args.Get(0)
66-
67-
// Create a new MinIO Admin Client
68-
client, err := newAdminClient(aliasedURL)
69-
fatalIf(err, "Unable to initialize admin connection.")
70-
7163
idpType := args.Get(1)
7264
validateIDType(idpType)
65+
isOpenID := idpType == madmin.OpenidIDPCfg
7366

7467
var cfgName string
7568
if len(args) == 3 {
7669
cfgName = args.Get(2)
7770
}
7871

79-
result, e := client.GetIDPConfig(globalContext, idpType, cfgName)
80-
fatalIf(probe.NewError(e), "Unable to get IDP config for '%s' to server", idpType)
81-
82-
// Print set config result
83-
printMsg(idpConfig(result))
84-
85-
return nil
86-
}
87-
88-
type idpConfig madmin.IDPConfig
89-
90-
func (i idpConfig) JSON() string {
91-
bs, e := json.MarshalIndent(i, "", " ")
92-
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
93-
94-
return string(bs)
95-
}
96-
97-
func (i idpConfig) String() string {
98-
// Determine required width for key column.
99-
fieldColWidth := 0
100-
for _, kv := range i.Info {
101-
if fieldColWidth < len(kv.Key) {
102-
fieldColWidth = len(kv.Key)
103-
}
104-
}
105-
// Add 1 for the colon-suffix in each entry.
106-
fieldColWidth++
107-
108-
fieldColStyle := lipgloss.NewStyle().
109-
Width(fieldColWidth).
110-
Foreground(lipgloss.Color("#04B575")). // green
111-
Bold(true).
112-
Align(lipgloss.Right)
113-
valueColStyle := lipgloss.NewStyle().
114-
PaddingLeft(1).
115-
Align(lipgloss.Left)
116-
envMarkStyle := lipgloss.NewStyle().
117-
Foreground(lipgloss.Color("201")). // pinkish-red
118-
PaddingLeft(1)
119-
120-
var lines []string
121-
for _, kv := range i.Info {
122-
envStr := ""
123-
if kv.IsCfg && kv.IsEnv {
124-
envStr = " (environment)"
125-
}
126-
lines = append(lines, fmt.Sprintf("%s%s%s",
127-
fieldColStyle.Render(kv.Key+":"),
128-
valueColStyle.Render(kv.Value),
129-
envMarkStyle.Render(envStr),
130-
))
131-
}
132-
133-
boxContent := strings.Join(lines, "\n")
134-
135-
boxStyle := lipgloss.NewStyle().
136-
BorderStyle(lipgloss.RoundedBorder())
137-
138-
return boxStyle.Render(boxContent)
72+
return adminIDPInfo(ctx, isOpenID, cfgName)
13973
}

cmd/admin-idp-ldap-add.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Copyright (c) 2015-2022 MinIO, Inc.
2+
//
3+
// This file is part of MinIO Object Storage stack
4+
//
5+
// This program is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU Affero General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU Affero General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Affero General Public License
16+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
18+
package cmd
19+
20+
import (
21+
"strings"
22+
23+
"github.com/minio/cli"
24+
"github.com/minio/madmin-go"
25+
"github.com/minio/mc/pkg/probe"
26+
)
27+
28+
var adminIDPLdapAddCmd = cli.Command{
29+
Name: "add",
30+
Usage: "Create an LDAP IDP server configuration",
31+
Action: mainAdminIDPLDAPAdd,
32+
Before: setGlobalsFromContext,
33+
Flags: globalFlags,
34+
OnUsageError: onUsageError,
35+
CustomHelpTemplate: `NAME:
36+
{{.HelpName}} - {{.Usage}}
37+
38+
USAGE:
39+
{{.HelpName}} TARGET [CFG_NAME] [CFG_PARAMS...]
40+
41+
FLAGS:
42+
{{range .VisibleFlags}}{{.}}
43+
{{end}}
44+
EXAMPLES:
45+
1. Create a default LDAP IDP configuration (CFG_NAME is omitted).
46+
{{.Prompt}} {{.HelpName}} myminio/ \
47+
server_addr=myldapserver:636 \
48+
lookup_bind_dn=cn=admin,dc=min,dc=io \
49+
lookup_bind_password=somesecret \
50+
user_dn_search_base_dn=dc=min,dc=io \
51+
user_dn_search_filter="(uid=%s)" \
52+
group_search_base_dn=ou=swengg,dc=min,dc=io \
53+
group_search_filter="(&(objectclass=groupofnames)(member=%d))"
54+
`,
55+
}
56+
57+
func mainAdminIDPLDAPAdd(ctx *cli.Context) error {
58+
if len(ctx.Args()) < 2 {
59+
showCommandHelpAndExit(ctx, 1)
60+
}
61+
62+
args := ctx.Args()
63+
64+
aliasedURL := args.Get(0)
65+
66+
// Create a new MinIO Admin Client
67+
client, err := newAdminClient(aliasedURL)
68+
fatalIf(err, "Unable to initialize admin connection.")
69+
70+
cfgName := madmin.Default
71+
input := args[1:]
72+
if !strings.Contains(args.Get(1), "=") {
73+
cfgName = args.Get(1)
74+
input = args[2:]
75+
}
76+
77+
inputCfg := strings.Join(input, " ")
78+
79+
restart, e := client.AddOrUpdateIDPConfig(globalContext, madmin.LDAPIDPCfg, cfgName, inputCfg, false)
80+
fatalIf(probe.NewError(e), "Unable to add LDAP IDP config to server")
81+
82+
// Print set config result
83+
printMsg(configSetMessage{
84+
targetAlias: aliasedURL,
85+
restart: restart,
86+
})
87+
88+
return nil
89+
}

cmd/admin-idp-ldap-disable.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (c) 2015-2022 MinIO, Inc.
2+
//
3+
// This file is part of MinIO Object Storage stack
4+
//
5+
// This program is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU Affero General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU Affero General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Affero General Public License
16+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
18+
package cmd
19+
20+
import (
21+
"github.com/minio/cli"
22+
)
23+
24+
var adminIDPLdapDisableCmd = cli.Command{
25+
Name: "disable",
26+
Usage: "Disable an LDAP IDP server configuration",
27+
Action: mainAdminIDPLDAPDisable,
28+
Before: setGlobalsFromContext,
29+
Flags: globalFlags,
30+
OnUsageError: onUsageError,
31+
CustomHelpTemplate: `NAME:
32+
{{.HelpName}} - {{.Usage}}
33+
34+
USAGE:
35+
{{.HelpName}} TARGET [CFG_NAME]
36+
37+
FLAGS:
38+
{{range .VisibleFlags}}{{.}}
39+
{{end}}
40+
EXAMPLES:
41+
1. Disable the default LDAP IDP configuration (CFG_NAME is omitted).
42+
{{.Prompt}} {{.HelpName}} play/
43+
2. Disable LDAP IDP configuration named "dex_test".
44+
{{.Prompt}} {{.HelpName}} play/ dex_test
45+
`,
46+
}
47+
48+
func mainAdminIDPLDAPDisable(ctx *cli.Context) error {
49+
isOpenID, enable := false, false
50+
return adminIDPEnableDisable(ctx, isOpenID, enable)
51+
}

cmd/admin-idp-ldap-enable.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (c) 2015-2022 MinIO, Inc.
2+
//
3+
// This file is part of MinIO Object Storage stack
4+
//
5+
// This program is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU Affero General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU Affero General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Affero General Public License
16+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
18+
package cmd
19+
20+
import (
21+
"github.com/minio/cli"
22+
)
23+
24+
var adminIDPLdapEnableCmd = cli.Command{
25+
Name: "enable",
26+
Usage: "manage LDAP IDP server configuration",
27+
Action: mainAdminIDPLDAPEnable,
28+
Before: setGlobalsFromContext,
29+
Flags: globalFlags,
30+
OnUsageError: onUsageError,
31+
CustomHelpTemplate: `NAME:
32+
{{.HelpName}} - {{.Usage}}
33+
34+
USAGE:
35+
{{.HelpName}} TARGET [CFG_NAME]
36+
37+
FLAGS:
38+
{{range .VisibleFlags}}{{.}}
39+
{{end}}
40+
EXAMPLES:
41+
1. Enable the default LDAP IDP configuration (CFG_NAME is omitted).
42+
{{.Prompt}} {{.HelpName}} play/
43+
2. Enable LDAP IDP configuration named "dex_test".
44+
{{.Prompt}} {{.HelpName}} play/ dex_test
45+
`,
46+
}
47+
48+
func mainAdminIDPLDAPEnable(ctx *cli.Context) error {
49+
isOpenID, enable := false, true
50+
return adminIDPEnableDisable(ctx, isOpenID, enable)
51+
}

cmd/admin-idp-ldap-info.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright (c) 2015-2022 MinIO, Inc.
2+
//
3+
// This file is part of MinIO Object Storage stack
4+
//
5+
// This program is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU Affero General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU Affero General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Affero General Public License
16+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
18+
package cmd
19+
20+
import (
21+
"github.com/minio/cli"
22+
)
23+
24+
var adminIDPLdapInfoCmd = cli.Command{
25+
Name: "info",
26+
Usage: "get LDAP IDP server configuration info",
27+
Action: mainAdminIDPLDAPInfo,
28+
Before: setGlobalsFromContext,
29+
Flags: globalFlags,
30+
OnUsageError: onUsageError,
31+
CustomHelpTemplate: `NAME:
32+
{{.HelpName}} - {{.Usage}}
33+
34+
USAGE:
35+
{{.HelpName}} TARGET [CFG_NAME]
36+
37+
FLAGS:
38+
{{range .VisibleFlags}}{{.}}
39+
{{end}}
40+
EXAMPLES:
41+
1. Get configuration info on the default LDAP IDP configuration (CFG_NAME is omitted).
42+
{{.Prompt}} {{.HelpName}} play/
43+
2. Get configuration info on LDAP IDP configuration named "dex_test".
44+
{{.Prompt}} {{.HelpName}} play/ dex_test
45+
`,
46+
}
47+
48+
func mainAdminIDPLDAPInfo(ctx *cli.Context) error {
49+
if len(ctx.Args()) < 1 || len(ctx.Args()) > 2 {
50+
showCommandHelpAndExit(ctx, 1)
51+
}
52+
53+
args := ctx.Args()
54+
var cfgName string
55+
if len(args) == 2 {
56+
cfgName = args.Get(1)
57+
}
58+
59+
return adminIDPInfo(ctx, false, cfgName)
60+
}

0 commit comments

Comments
 (0)