Skip to content

Commit

Permalink
Do not allow adding root user to IAM subsystem
Browse files Browse the repository at this point in the history
A user with sufficient admin level priviledges can
add the root user into the IAM subsystem, which would
lead to permanently disabled access for root
credentials.

The problem exists since RELEASE.2020-12-23T02-24-12Z
release onwards, a similar also was introduced in the IAM
import API since RELEASE.2022-06-25T15-50-16Z

This PR fixes both scenarios.
  • Loading branch information
harshavardhana committed Mar 13, 2023
1 parent cde7eeb commit 1d1b209
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmd/admin-handlers-users.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ func (a adminAPIHandlers) AddUser(w http.ResponseWriter, r *http.Request) {
}

// Not allowed to add a user with same access key as root credential
if owner && accessKey == cred.AccessKey {
if accessKey == globalActiveCred.AccessKey {
writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrAddUserInvalidArgument), r.URL)
return
}
Expand Down Expand Up @@ -2297,7 +2297,7 @@ func (a adminAPIHandlers) ImportIAM(w http.ResponseWriter, r *http.Request) {
}
for accessKey, ureq := range userAccts {
// Not allowed to add a user with same access key as root credential
if owner && accessKey == cred.AccessKey {
if accessKey == globalActiveCred.AccessKey {
writeErrorResponseJSON(ctx, w, importErrorWithAPIErr(ctx, ErrAddUserInvalidArgument, err, allUsersFile, accessKey), r.URL)
return
}
Expand Down
5 changes: 5 additions & 0 deletions cmd/sts-handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,11 @@ func (s *TestSuiteIAM) TestSTSForRoot(c *check) {
if !gotBuckets.Equals(shouldHaveBuckets) {
c.Fatalf("root user should have access to all buckets")
}

// This must fail.
if err := userAdmClient.AddUser(ctx, globalActiveCred.AccessKey, globalActiveCred.SecretKey); err == nil {
c.Fatal("AddUser() for root credential must fail via root STS creds")
}
}

// SetUpLDAP - expects to setup an LDAP test server using the test LDAP
Expand Down

0 comments on commit 1d1b209

Please sign in to comment.