Fix auth bug restricting access to unauthorised endpoints (#1405)
Co-authored-by: Ben Toogood <ben@micro.mu>
This commit is contained in:
parent
0e56382107
commit
35e2a68a98
@ -184,13 +184,15 @@ func AuthHandler(fn func() auth.Auth, srvName string) server.HandlerWrapper {
|
|||||||
// Inspect the token and get the account
|
// Inspect the token and get the account
|
||||||
account, err := a.Inspect(token)
|
account, err := a.Inspect(token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Unauthorized("go.micro.auth", "Unauthorised call made to %v", req.Endpoint())
|
account = &auth.Account{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify the caller has access to the resource
|
// Verify the caller has access to the resource
|
||||||
resource := &auth.Resource{Type: "service", Name: srvName, Endpoint: req.Endpoint()}
|
err = a.Verify(account, &auth.Resource{Type: "service", Name: srvName, Endpoint: req.Endpoint()})
|
||||||
if err := a.Verify(account, resource); err != nil {
|
if err != nil && len(account.ID) > 0 {
|
||||||
return errors.Forbidden("go.micro.auth", "Forbidden call made to %v %v by %v", srvName, req.Endpoint(), account.ID)
|
return errors.Forbidden("go.micro.auth", "Forbidden call made to %v:%v by %v", srvName, req.Endpoint(), account.ID)
|
||||||
|
} else if err != nil {
|
||||||
|
return errors.Unauthorized("go.micro.auth", "Unauthorised call made to %v:%v", srvName, req.Endpoint())
|
||||||
}
|
}
|
||||||
|
|
||||||
// There is an account, set it in the context
|
// There is an account, set it in the context
|
||||||
|
Loading…
Reference in New Issue
Block a user