Skip to content

Commit 51a9482

Browse files
authored
Fixes issue that prevents LDAP users to authenticate (#605)
1 parent d01eeb4 commit 51a9482

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

DEVELOPMENT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Run the `billy.ldif` file using `ldapadd` command to create a new user and assig
1212

1313
```
1414
$ docker cp console/docs/ldap/billy.ldif my-openldap-container:/container/service/slapd/assets/test/billy.ldif
15-
$ docker exec my-openldap-container ldapadd -x -D "cn=admin,dc=example,dc=org" -w admin -f /container/service/slapd/assets/test/billy.ldif -H ldap://localhost -ZZ
15+
$ docker exec my-openldap-container ldapadd -x -D "cn=admin,dc=example,dc=org" -w admin -f /container/service/slapd/assets/test/billy.ldif -H ldap://localhost
1616
```
1717

1818
Query the ldap server to check the user billy was created correctly and got assigned to the consoleAdmin group, you should get a list

restapi/user_account.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func getChangePasswordResponse(session *models.Principal, params user_api.Accoun
8080
}
8181
// user credentials are updated at this point, we need to generate a new admin client and authenticate using
8282
// the new credentials
83-
credentials, err := getConsoleCredentials(ctx, accessKey, newSecretKey, "")
83+
credentials, err := getConsoleCredentials(ctx, accessKey, newSecretKey)
8484
if err != nil {
8585
return nil, prepareError(errInvalidCredentials, nil, err)
8686
}

restapi/user_login.go

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,27 @@ func getAccountPolicy(ctx context.Context, client MinioAdmin) (*iampolicy.Policy
113113
}
114114

115115
// getConsoleCredentials will return consoleCredentials interface including the associated policy of the current account
116-
func getConsoleCredentials(ctx context.Context, accessKey, secretKey, sessionToken string) (*consoleCredentials, error) {
116+
func getConsoleCredentials(ctx context.Context, accessKey, secretKey string) (*consoleCredentials, error) {
117+
creds, err := newConsoleCredentials(accessKey, secretKey, MinioRegion)
118+
if err != nil {
119+
return nil, err
120+
}
121+
// cCredentials will be sts credentials, account credentials will be need it in the scenario the user wish
122+
// to change its password
123+
cCredentials := &consoleCredentials{
124+
consoleCredentials: creds,
125+
accountAccessKey: accessKey,
126+
accountSecretKey: secretKey,
127+
}
128+
tokens, err := cCredentials.Get()
129+
if err != nil {
130+
return nil, err
131+
}
132+
// initialize admin client
117133
mAdminClient, err := newMAdminClient(&models.Principal{
118-
STSAccessKeyID: accessKey,
119-
STSSecretAccessKey: secretKey,
120-
STSSessionToken: sessionToken,
134+
STSAccessKeyID: tokens.AccessKeyID,
135+
STSSecretAccessKey: tokens.SecretAccessKey,
136+
STSSessionToken: tokens.SessionToken,
121137
})
122138
if err != nil {
123139
return nil, err
@@ -137,25 +153,16 @@ func getConsoleCredentials(ctx context.Context, accessKey, secretKey, sessionTok
137153
if policy != nil {
138154
actions = acl.GetActionsStringFromPolicy(policy)
139155
}
140-
credentials, err := newConsoleCredentials(accessKey, secretKey, MinioRegion)
141-
if err != nil {
142-
return nil, err
143-
}
144-
// consoleCredentials will be sts credentials, account credentials will be need it in the scenario the user wish
145-
return &consoleCredentials{
146-
consoleCredentials: credentials,
147-
accountAccessKey: accessKey,
148-
accountSecretKey: secretKey,
149-
actions: actions,
150-
}, nil
156+
cCredentials.actions = actions
157+
return cCredentials, nil
151158
}
152159

153160
// getLoginResponse performs login() and serializes it to the handler's output
154161
func getLoginResponse(lr *models.LoginRequest) (*models.LoginResponse, *models.Error) {
155162
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
156163
defer cancel()
157164
// prepare console credentials
158-
consolCreds, err := getConsoleCredentials(ctx, *lr.AccessKey, *lr.SecretKey, "")
165+
consolCreds, err := getConsoleCredentials(ctx, *lr.AccessKey, *lr.SecretKey)
159166
if err != nil {
160167
return nil, prepareError(errInvalidCredentials, nil, err)
161168
}

0 commit comments

Comments
 (0)