From 0e976834601776da9d788d1c9fd18c6ead342d85 Mon Sep 17 00:00:00 2001 From: Aditya Manthramurthy Date: Sat, 18 Mar 2023 16:38:27 -0700 Subject: [PATCH] fix: ldap commands don't accept config name (#4499) --- cmd/admin-idp-ldap-add.go | 10 ++++++-- cmd/admin-idp-ldap-disable.go | 10 +++++--- cmd/admin-idp-ldap-enable.go | 10 +++++--- cmd/admin-idp-ldap-info.go | 16 ++++-------- cmd/admin-idp-ldap-remove.go | 18 ++++++------- cmd/admin-idp-ldap-update.go | 48 ++++++++++++++++++++++++++++++++--- 6 files changed, 78 insertions(+), 34 deletions(-) diff --git a/cmd/admin-idp-ldap-add.go b/cmd/admin-idp-ldap-add.go index 0172021d..cc3ad37b 100644 --- a/cmd/admin-idp-ldap-add.go +++ b/cmd/admin-idp-ldap-add.go @@ -18,6 +18,7 @@ package cmd import ( + "errors" "strings" "github.com/minio/cli" @@ -36,13 +37,13 @@ var adminIDPLdapAddCmd = cli.Command{ {{.HelpName}} - {{.Usage}} USAGE: - {{.HelpName}} TARGET [CFG_NAME] [CFG_PARAMS...] + {{.HelpName}} TARGET [CFG_PARAMS...] FLAGS: {{range .VisibleFlags}}{{.}} {{end}} EXAMPLES: - 1. Create a default LDAP IDP configuration (CFG_NAME is omitted). + 1. Create LDAP IDentity Provider configuration. {{.Prompt}} {{.HelpName}} myminio/ \ server_addr=myldapserver:636 \ lookup_bind_dn=cn=admin,dc=min,dc=io \ @@ -74,6 +75,11 @@ func mainAdminIDPLDAPAdd(ctx *cli.Context) error { 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) diff --git a/cmd/admin-idp-ldap-disable.go b/cmd/admin-idp-ldap-disable.go index ae53be12..6afe84d5 100644 --- a/cmd/admin-idp-ldap-disable.go +++ b/cmd/admin-idp-ldap-disable.go @@ -32,20 +32,22 @@ var adminIDPLdapDisableCmd = cli.Command{ {{.HelpName}} - {{.Usage}} USAGE: - {{.HelpName}} TARGET [CFG_NAME] + {{.HelpName}} TARGET FLAGS: {{range .VisibleFlags}}{{.}} {{end}} EXAMPLES: - 1. Disable the default LDAP IDP configuration (CFG_NAME is omitted). + 1. Disable the default LDAP IDP configuration. {{.Prompt}} {{.HelpName}} play/ - 2. Disable LDAP IDP configuration named "dex_test". - {{.Prompt}} {{.HelpName}} play/ dex_test `, } func mainAdminIDPLDAPDisable(ctx *cli.Context) error { + if len(ctx.Args()) != 1 { + showCommandHelpAndExit(ctx, 1) + } + isOpenID, enable := false, false return adminIDPEnableDisable(ctx, isOpenID, enable) } diff --git a/cmd/admin-idp-ldap-enable.go b/cmd/admin-idp-ldap-enable.go index 8cb89d15..c934be49 100644 --- a/cmd/admin-idp-ldap-enable.go +++ b/cmd/admin-idp-ldap-enable.go @@ -32,20 +32,22 @@ var adminIDPLdapEnableCmd = cli.Command{ {{.HelpName}} - {{.Usage}} USAGE: - {{.HelpName}} TARGET [CFG_NAME] + {{.HelpName}} TARGET FLAGS: {{range .VisibleFlags}}{{.}} {{end}} EXAMPLES: - 1. Enable the default LDAP IDP configuration (CFG_NAME is omitted). + 1. Enable the LDAP IDP configuration. {{.Prompt}} {{.HelpName}} play/ - 2. Enable LDAP IDP configuration named "dex_test". - {{.Prompt}} {{.HelpName}} play/ dex_test `, } func mainAdminIDPLDAPEnable(ctx *cli.Context) error { + if len(ctx.Args()) != 1 { + showCommandHelpAndExit(ctx, 1) + } + isOpenID, enable := false, true return adminIDPEnableDisable(ctx, isOpenID, enable) } diff --git a/cmd/admin-idp-ldap-info.go b/cmd/admin-idp-ldap-info.go index 91fe7b24..b14572af 100644 --- a/cmd/admin-idp-ldap-info.go +++ b/cmd/admin-idp-ldap-info.go @@ -19,6 +19,7 @@ package cmd import ( "github.com/minio/cli" + "github.com/minio/madmin-go/v2" ) var adminIDPLdapInfoCmd = cli.Command{ @@ -32,29 +33,22 @@ var adminIDPLdapInfoCmd = cli.Command{ {{.HelpName}} - {{.Usage}} USAGE: - {{.HelpName}} TARGET [CFG_NAME] + {{.HelpName}} TARGET FLAGS: {{range .VisibleFlags}}{{.}} {{end}} EXAMPLES: - 1. Get configuration info on the default LDAP IDP configuration (CFG_NAME is omitted). + 1. Get configuration info on the LDAP IDP configuration. {{.Prompt}} {{.HelpName}} play/ - 2. Get configuration info on LDAP IDP configuration named "dex_test". - {{.Prompt}} {{.HelpName}} play/ dex_test `, } func mainAdminIDPLDAPInfo(ctx *cli.Context) error { - if len(ctx.Args()) < 1 || len(ctx.Args()) > 2 { + if len(ctx.Args()) != 1 { showCommandHelpAndExit(ctx, 1) } - args := ctx.Args() - var cfgName string - if len(args) == 2 { - cfgName = args.Get(1) - } - + var cfgName string = madmin.Default return adminIDPInfo(ctx, false, cfgName) } diff --git a/cmd/admin-idp-ldap-remove.go b/cmd/admin-idp-ldap-remove.go index a507ce7d..c8182302 100644 --- a/cmd/admin-idp-ldap-remove.go +++ b/cmd/admin-idp-ldap-remove.go @@ -17,7 +17,10 @@ package cmd -import "github.com/minio/cli" +import ( + "github.com/minio/cli" + "github.com/minio/madmin-go/v2" +) var adminIDPLdapRemoveCmd = cli.Command{ Name: "remove", @@ -30,27 +33,22 @@ var adminIDPLdapRemoveCmd = cli.Command{ {{.HelpName}} - {{.Usage}} USAGE: - {{.HelpName}} TARGET [CFG_NAME] + {{.HelpName}} TARGET FLAGS: {{range .VisibleFlags}}{{.}} {{end}} EXAMPLES: - 1. Remove the default LDAP IDP configuration (CFG_NAME is omitted). + 1. Remove the default LDAP IDP configuration. {{.Prompt}} {{.HelpName}} play/ `, } func mainAdminIDPLDAPRemove(ctx *cli.Context) error { - if len(ctx.Args()) < 1 || len(ctx.Args()) > 2 { + if len(ctx.Args()) != 1 { showCommandHelpAndExit(ctx, 1) } - args := ctx.Args() - - var cfgName string - if len(args) == 2 { - cfgName = args.Get(1) - } + var cfgName string = madmin.Default return adminIDPRemove(ctx, false, cfgName) } diff --git a/cmd/admin-idp-ldap-update.go b/cmd/admin-idp-ldap-update.go index 09c4ae87..573b4c8c 100644 --- a/cmd/admin-idp-ldap-update.go +++ b/cmd/admin-idp-ldap-update.go @@ -17,7 +17,14 @@ package cmd -import "github.com/minio/cli" +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", @@ -30,13 +37,13 @@ var adminIDPLdapUpdateCmd = cli.Command{ {{.HelpName}} - {{.Usage}} USAGE: - {{.HelpName}} TARGET [CFG_NAME] [CFG_PARAMS...] + {{.HelpName}} TARGET [CFG_PARAMS...] FLAGS: {{range .VisibleFlags}}{{.}} {{end}} EXAMPLES: - 1. Create/Update the default LDAP IDP configuration (CFG_NAME is omitted). + 1. Update the LDAP IDP configuration. {{.Prompt}} {{.HelpName}} play/ \ lookup_bind_dn=cn=admin,dc=min,dc=io \ lookup_bind_password=somesecret @@ -44,5 +51,40 @@ EXAMPLES: } 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 }