mirror of https://github.com/minio/minio.git
Added new API errors for LDAP (#19415)
* change internal errors to named errors * Change names
This commit is contained in:
parent
8ff2a7a2b9
commit
9d63bb1b41
|
@ -20,7 +20,6 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -104,6 +103,12 @@ func (a adminAPIHandlers) AttachDetachPolicyLDAP(w http.ResponseWriter, r *http.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fail if ldap is not enabled
|
||||||
|
if !globalIAMSys.LDAPConfig.Enabled() {
|
||||||
|
writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrAdminLDAPNotEnabled), r.URL)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if r.ContentLength > maxEConfigJSONSize || r.ContentLength == -1 {
|
if r.ContentLength > maxEConfigJSONSize || r.ContentLength == -1 {
|
||||||
// More than maxConfigSize bytes were available
|
// More than maxConfigSize bytes were available
|
||||||
writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrAdminConfigTooLarge), r.URL)
|
writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrAdminConfigTooLarge), r.URL)
|
||||||
|
@ -191,7 +196,7 @@ func (a adminAPIHandlers) AddServiceAccountLDAP(w http.ResponseWriter, r *http.R
|
||||||
|
|
||||||
// fail if ldap is not enabled
|
// fail if ldap is not enabled
|
||||||
if !globalIAMSys.LDAPConfig.Enabled() {
|
if !globalIAMSys.LDAPConfig.Enabled() {
|
||||||
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, errors.New("LDAP not enabled")), r.URL)
|
writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrAdminLDAPNotEnabled), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,13 +263,18 @@ func (a adminAPIHandlers) AddServiceAccountLDAP(w http.ResponseWriter, r *http.R
|
||||||
// The target user may be supplied as a (short) username or a DN.
|
// The target user may be supplied as a (short) username or a DN.
|
||||||
// However, for now, we only support using the short username.
|
// However, for now, we only support using the short username.
|
||||||
|
|
||||||
|
isDN := globalIAMSys.LDAPConfig.ParsesAsDN(targetUser)
|
||||||
opts.claims[ldapUserN] = targetUser // simple username
|
opts.claims[ldapUserN] = targetUser // simple username
|
||||||
targetUser, targetGroups, err = globalIAMSys.LDAPConfig.LookupUserDN(targetUser)
|
targetUser, targetGroups, err = globalIAMSys.LDAPConfig.LookupUserDN(targetUser)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// if not found, check if DN
|
// if not found, check if DN
|
||||||
if strings.Contains(err.Error(), "not found") && globalIAMSys.LDAPConfig.ParsesAsDN(targetUser) {
|
if strings.Contains(err.Error(), "User DN not found for:") {
|
||||||
// warn user that DNs are not allowed
|
if isDN {
|
||||||
err = fmt.Errorf("Must use short username to add service account. %w", err)
|
// warn user that DNs are not allowed
|
||||||
|
writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErrWithErr(ErrAdminLDAPExpectedLoginName, err), r.URL)
|
||||||
|
} else {
|
||||||
|
writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErrWithErr(ErrAdminNoSuchUser, err), r.URL)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
||||||
return
|
return
|
||||||
|
|
|
@ -278,6 +278,7 @@ const (
|
||||||
ErrMalformedJSON
|
ErrMalformedJSON
|
||||||
ErrAdminNoSuchUser
|
ErrAdminNoSuchUser
|
||||||
ErrAdminNoSuchUserLDAPWarn
|
ErrAdminNoSuchUserLDAPWarn
|
||||||
|
ErrAdminLDAPExpectedLoginName
|
||||||
ErrAdminNoSuchGroup
|
ErrAdminNoSuchGroup
|
||||||
ErrAdminGroupNotEmpty
|
ErrAdminGroupNotEmpty
|
||||||
ErrAdminGroupDisabled
|
ErrAdminGroupDisabled
|
||||||
|
@ -300,6 +301,7 @@ const (
|
||||||
ErrAdminConfigIDPCfgNameDoesNotExist
|
ErrAdminConfigIDPCfgNameDoesNotExist
|
||||||
ErrInsecureClientRequest
|
ErrInsecureClientRequest
|
||||||
ErrObjectTampered
|
ErrObjectTampered
|
||||||
|
ErrAdminLDAPNotEnabled
|
||||||
|
|
||||||
// Site-Replication errors
|
// Site-Replication errors
|
||||||
ErrSiteReplicationInvalidRequest
|
ErrSiteReplicationInvalidRequest
|
||||||
|
@ -2079,7 +2081,16 @@ var errorCodes = errorCodeMap{
|
||||||
Description: "Invalid attribute name specified.",
|
Description: "Invalid attribute name specified.",
|
||||||
HTTPStatusCode: http.StatusBadRequest,
|
HTTPStatusCode: http.StatusBadRequest,
|
||||||
},
|
},
|
||||||
// Add your error structure here.
|
ErrAdminLDAPNotEnabled: {
|
||||||
|
Code: "XMinioLDAPNotEnabled",
|
||||||
|
Description: "LDAP is not enabled. LDAP must be enabled to make LDAP requests.",
|
||||||
|
HTTPStatusCode: http.StatusNotImplemented,
|
||||||
|
},
|
||||||
|
ErrAdminLDAPExpectedLoginName: {
|
||||||
|
Code: "XMinioLDAPExpectedLoginName",
|
||||||
|
Description: "Expected LDAP short username but was given full DN.",
|
||||||
|
HTTPStatusCode: http.StatusBadRequest,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// toAPIErrorCode - Converts embedded errors. Convenience
|
// toAPIErrorCode - Converts embedded errors. Convenience
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue