diff --git a/cmd/admin-handlers-users.go b/cmd/admin-handlers-users.go index ecc7f6689..93d27d5c6 100644 --- a/cmd/admin-handlers-users.go +++ b/cmd/admin-handlers-users.go @@ -21,6 +21,7 @@ import ( "bytes" "encoding/json" "errors" + "fmt" "io" "net/http" "os" @@ -680,6 +681,17 @@ func (a adminAPIHandlers) AddServiceAccount(w http.ResponseWriter, r *http.Reque requestorIsDerivedCredential = true } + if globalIAMSys.GetUsersSysType() == MinIOUsersSysType && targetUser != cred.AccessKey { + // For internal IDP, ensure that the targetUser's parent account exists. + // It could be a regular user account or the root account. + _, isRegularUser := globalIAMSys.GetUser(ctx, targetUser) + if !isRegularUser && targetUser != globalActiveCred.AccessKey { + writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, + fmt.Errorf("parent user %s does not exist. Cannot create service account", targetUser)), r.URL) + return + } + } + // Check if we are creating svc account for request sender. isSvcAccForRequestor := false if targetUser == requestorUser || targetUser == requestorParentUser { diff --git a/cmd/admin-handlers-users_test.go b/cmd/admin-handlers-users_test.go index cee6094b5..cecdc974c 100644 --- a/cmd/admin-handlers-users_test.go +++ b/cmd/admin-handlers-users_test.go @@ -1136,7 +1136,7 @@ func (s *TestSuiteIAM) TestAccMgmtPlugin(c *check) { c.assertSvcAccDeletion(ctx, s, userAdmClient, accessKey, bucket) // 6. Check that service account **can** be created for some other user. - // This is possible because of the policy enforced in the plugin. + // This is possible because the policy enforced in the plugin. c.mustCreateSvcAccount(ctx, globalActiveCred.AccessKey, userAdmClient) }