Files
Karl Persson 43f56c5ca1 Apiserver: Refactor authenticator and authorizers (#101449)
* Clean up authenticator

* Cleanup authorizers and replace org_id and stack_id with namespace authorizer

* Remove dependency on org service

* Extract orgID from /apis/ urls and validate stack id
2025-03-06 16:01:12 +01:00

31 lines
973 B
Go

package authenticator
import (
"net/http"
"k8s.io/apiserver/pkg/authentication/authenticator"
"k8s.io/apiserver/pkg/authentication/request/union"
"k8s.io/klog/v2"
"github.com/grafana/grafana/pkg/apimachinery/identity"
)
func NewAuthenticator(authRequestHandlers ...authenticator.Request) authenticator.Request {
handlers := append([]authenticator.Request{authenticator.RequestFunc(identityAuthenticator)}, authRequestHandlers...)
return union.New(handlers...)
}
var _ authenticator.RequestFunc = identityAuthenticator
// identityAuthenticator check if we have any identity set in context.
// If not we delegate authentication to next authenticator in the chain.
func identityAuthenticator(req *http.Request) (*authenticator.Response, bool, error) {
ident, err := identity.GetRequester(req.Context())
if err != nil {
klog.V(5).Info("no idenitty in context", "err", err)
return nil, false, nil
}
return &authenticator.Response{User: ident}, true, nil
}