From bbfe577d2e7465f2b5288acd6240a250dc24592f Mon Sep 17 00:00:00 2001 From: Anis Eleuch Date: Sun, 15 Sep 2024 04:56:26 +0100 Subject: [PATCH] idp-ldap: Fix create-with-login command (#5036) Currently, LDAP create-with-login command is not working properly when the LDAP user does not have admin:CreateServiceAccount permission. The permission is normally not needed since a user is allowed to create a service account for itself. In that case, a temporary account should be created and a new service account should be issued to the temporary account access key, and not to the LDAP username as what the code currently does. This commit will send the correct target user in that case to make create-with-login always successful. Co-authored-by: Anis Eleuch --- cmd/idp-ldap-accesskey-create-with-login.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/idp-ldap-accesskey-create-with-login.go b/cmd/idp-ldap-accesskey-create-with-login.go index 4e458f51..7bddd5ce 100644 --- a/cmd/idp-ldap-accesskey-create-with-login.go +++ b/cmd/idp-ldap-accesskey-create-with-login.go @@ -90,6 +90,9 @@ func mainIDPLdapAccesskeyCreateWithLogin(ctx *cli.Context) error { func loginLDAPAccesskey(ctx *cli.Context) (*madmin.AdminClient, madmin.AddServiceAccountReq) { urlStr := ctx.Args().First() + u, e := url.Parse(urlStr) + fatalIf(probe.NewError(e), "unable to parse server URL") + console.SetColor(cred, color.New(color.FgYellow, color.Italic)) reader := bufio.NewReader(os.Stdin) @@ -107,8 +110,8 @@ func loginLDAPAccesskey(ctx *cli.Context) (*madmin.AdminClient, madmin.AddServic stsCreds, e := credentials.NewLDAPIdentity(urlStr, username, password) fatalIf(probe.NewError(e), "unable to initialize LDAP identity") - u, e := url.Parse(urlStr) - fatalIf(probe.NewError(e), "unable to parse server URL") + tempCreds, e := stsCreds.Get() + fatalIf(probe.NewError(e), "unable to create a temporary account from LDAP identity") client, e := madmin.NewWithOptions(u.Host, &madmin.Options{ Creds: stsCreds, @@ -116,5 +119,5 @@ func loginLDAPAccesskey(ctx *cli.Context) (*madmin.AdminClient, madmin.AddServic }) fatalIf(probe.NewError(e), "unable to initialize admin connection") - return client, accessKeyCreateOpts(ctx, username) + return client, accessKeyCreateOpts(ctx, tempCreds.AccessKeyID) }