Skip to content

Commit

Permalink
undo add of infoaccesskey
Browse files Browse the repository at this point in the history
  • Loading branch information
taran-p committed Sep 16, 2024
1 parent 8199c1b commit dcd29f5
Showing 1 changed file with 0 additions and 110 deletions.
110 changes: 0 additions & 110 deletions cmd/admin-handlers-users.go
Original file line number Diff line number Diff line change
Expand Up @@ -1974,116 +1974,6 @@ func (a adminAPIHandlers) AttachDetachPolicyBuiltin(w http.ResponseWriter, r *ht
writeSuccessResponseJSON(w, encryptedData)
}

// InfoAccessKey - GET /minio/admin/v3/info-access-key?access-key=<access-key>
func (a adminAPIHandlers) InfoAccessKey(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

// Get current object layer instance.
objectAPI := newObjectLayerFn()
if objectAPI == nil || globalNotificationSys == nil {
writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrServerNotInitialized), r.URL)
return
}

cred, owner, s3Err := validateAdminSignature(ctx, r, "")
if s3Err != ErrNone {
writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(s3Err), r.URL)
return
}

accessKey := mux.Vars(r)["accessKey"]
if accessKey == "" {
writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrInvalidRequest), r.URL)
return
}

isTemp := false
targetAccount, sessionPolicy, err := globalIAMSys.GetServiceAccount(ctx, accessKey)
if err != nil && errors.Is(err, errNoSuchServiceAccount) {
isTemp = true
targetAccount, sessionPolicy, err = globalIAMSys.GetTemporaryAccount(ctx, accessKey)
}

policyArgs := policy.Args{
AccountName: cred.AccessKey,
Groups: cred.Groups,
Action: policy.ListServiceAccountsAdminAction,
ConditionValues: getConditionValues(r, "", cred),
IsOwner: owner,
Claims: cred.Claims,
DenyOnly: (targetAccount.ParentUser == cred.AccessKey || targetAccount.ParentUser == cred.ParentUser),
}

if !globalIAMSys.IsAllowed(policyArgs) {
writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrAccessDenied), r.URL)
return
}

// Only return error after checking if access is allowed.
if err != nil {
if errors.Is(err, errNoSuchServiceAccount) || errors.Is(err, errNoSuchTempAccount) {
err = errNoSuchAccessKey
}
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
return
}

// if session policy is nil or empty, then it is implied policy
impliedPolicy := sessionPolicy == nil || (sessionPolicy.Version == "" && len(sessionPolicy.Statements) == 0)

var accountPolicy policy.Policy

if !impliedPolicy {
accountPolicy = *sessionPolicy
} else {
policiesNames, err := globalIAMSys.PolicyDBGet(targetAccount.ParentUser, targetAccount.Groups...)
if err != nil {
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
return
}
if isTemp && len(policiesNames) == 0 {
policySet, _ := policyArgs.GetPolicies(iamPolicyClaimNameOpenID())
policiesNames = policySet.ToSlice()
}
accountPolicy = globalIAMSys.GetCombinedPolicy(policiesNames...)
}

policyJSON, err := json.MarshalIndent(accountPolicy, "", " ")
if err != nil {
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
return
}

var expiration *time.Time
if isTemp || (!targetAccount.Expiration.IsZero() && !targetAccount.Expiration.Equal(timeSentinel)) {
expiration = &targetAccount.Expiration
}

infoResp := madmin.InfoServiceAccountResp{
ParentUser: targetAccount.ParentUser,
Name: targetAccount.Name,
Description: targetAccount.Description,
AccountStatus: targetAccount.Status,
ImpliedPolicy: impliedPolicy,
Policy: string(policyJSON),
Expiration: expiration,
}

data, err := json.Marshal(infoResp)
if err != nil {
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
return
}

encryptedData, err := madmin.EncryptData(cred.SecretKey, data)
if err != nil {
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
return
}

writeSuccessResponseJSON(w, encryptedData)
}

const (
allPoliciesFile = "policies.json"
allUsersFile = "users.json"
Expand Down

0 comments on commit dcd29f5

Please sign in to comment.