Skip to content
This repository has been archived by the owner on Dec 20, 2022. It is now read-only.

Commit

Permalink
[patch] add log on authZ error (#96)
Browse files Browse the repository at this point in the history
* [patch] add log on authZ error

* update

* fix

* fix
  • Loading branch information
t4niwa committed Nov 14, 2022
1 parent ee9293f commit 9d1e128
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions authorizerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ func (a *authority) authorize(ctx context.Context, m mode, tok, act, res, query
case roleToken:
rt, err := a.roleProcessor.ParseAndValidateRoleToken(tok)
if err != nil {
glg.Debugf("error parse and validate role token, err: %v", err)
glg.Infof("error parse and validate role token, err: %v", err)
return nil, errors.Wrap(err, "error authorize role token")
}
domain = rt.Domain
Expand All @@ -423,7 +423,7 @@ func (a *authority) authorize(ctx context.Context, m mode, tok, act, res, query
case accessToken:
ac, err := a.accessProcessor.ParseAndValidateOAuth2AccessToken(tok, cert)
if err != nil {
glg.Debugf("error parse and validate access token, err: %v", err)
glg.Infof("error parse and validate access token, err: %v", err)
return nil, errors.Wrap(err, "error authorize access token")
}
domain = ac.Audience
Expand All @@ -445,14 +445,15 @@ func (a *authority) authorize(ctx context.Context, m mode, tok, act, res, query
var err error
act, res, err = a.translator.Translate(domain, act, res, query)
if err != nil {
glg.Infof("translator error, err: %v, principal: %s, action: %s, resource: %s", err, p.Name(), act, res)
return nil, err
}
}

res = a.resourcePrefix + res
authorizedRoles, err := a.policyd.CheckPolicyRoles(ctx, domain, roles, act, res)
if err != nil {
glg.Debugf("error check, err: %v", err)
glg.Infof("check policy error, err: %v, principal: %s, action: %s, resource: %s", err, p.Name(), act, res)
return nil, errors.Wrap(err, "token unauthorized")
}

Expand Down
4 changes: 2 additions & 2 deletions role/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ func (r *rtp) parseToken(tok string) (*Token, error) {

func (r *rtp) validate(rt *Token) error {
if rt.Expired() {
return errors.Wrapf(ErrRoleTokenExpired, "token expired")
return errors.Wrapf(ErrRoleTokenExpired, "token expired. principal %s", rt.Principal)
}
ver := r.pkp(pubkey.EnvZTS, rt.KeyID)
if ver == nil {
return errors.Wrapf(ErrRoleTokenInvalid, "invalid role token key ID %s", rt.KeyID)
return errors.Wrapf(ErrRoleTokenInvalid, "invalid role token key ID %s. principal %s", rt.KeyID, rt.Principal)
}
return ver.Verify(rt.UnsignedToken, rt.Signature)
}

0 comments on commit 9d1e128

Please sign in to comment.