mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
rebase authenticators onto new interface.
This commit is contained in:
@@ -221,7 +221,7 @@ func NewServer(
|
||||
func (s *Server) InstallAuthFilter() {
|
||||
s.restfulCont.Filter(func(req *restful.Request, resp *restful.Response, chain *restful.FilterChain) {
|
||||
// Authenticate
|
||||
u, ok, err := s.auth.AuthenticateRequest(req.Request)
|
||||
info, ok, err := s.auth.AuthenticateRequest(req.Request)
|
||||
if err != nil {
|
||||
glog.Errorf("Unable to authenticate the request due to an error: %v", err)
|
||||
resp.WriteErrorString(http.StatusUnauthorized, "Unauthorized")
|
||||
@@ -233,18 +233,18 @@ func (s *Server) InstallAuthFilter() {
|
||||
}
|
||||
|
||||
// Get authorization attributes
|
||||
attrs := s.auth.GetRequestAttributes(u, req.Request)
|
||||
attrs := s.auth.GetRequestAttributes(info.User, req.Request)
|
||||
|
||||
// Authorize
|
||||
decision, _, err := s.auth.Authorize(attrs)
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("Authorization error (user=%s, verb=%s, resource=%s, subresource=%s)", u.GetName(), attrs.GetVerb(), attrs.GetResource(), attrs.GetSubresource())
|
||||
msg := fmt.Sprintf("Authorization error (user=%s, verb=%s, resource=%s, subresource=%s)", attrs.GetUser().GetName(), attrs.GetVerb(), attrs.GetResource(), attrs.GetSubresource())
|
||||
glog.Errorf(msg, err)
|
||||
resp.WriteErrorString(http.StatusInternalServerError, msg)
|
||||
return
|
||||
}
|
||||
if decision != authorizer.DecisionAllow {
|
||||
msg := fmt.Sprintf("Forbidden (user=%s, verb=%s, resource=%s, subresource=%s)", u.GetName(), attrs.GetVerb(), attrs.GetResource(), attrs.GetSubresource())
|
||||
msg := fmt.Sprintf("Forbidden (user=%s, verb=%s, resource=%s, subresource=%s)", attrs.GetUser().GetName(), attrs.GetVerb(), attrs.GetResource(), attrs.GetSubresource())
|
||||
glog.V(2).Info(msg)
|
||||
resp.WriteErrorString(http.StatusForbidden, msg)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user