import ( "k8s.io/kubernetes/pkg/auth/authorizer" ) func myAuthFunc(a authorizer.Attributes) (bool, error) { user := a.GetUser() // use the user details for custom authorization logic // ... }
import ( "k8s.io/apiserver/pkg/authentication/authenticator" "k8s.io/kubernetes/pkg/auth/authorizer" ) func myAuthzHandler(w http.ResponseWriter, r *http.Request) { authAttr, err := authenticator.FromRequest(r) if err != nil { // handle error } authorized, err := authorizer.Authorize(authAttr) if err != nil { // handle error } if !authorized { // handle unauthorized request } user := authAttr.GetUser() // use the user details for custom authorization logic // ... }In this example, the GetUser method is used to get the user details from the authorization Attributes returned by the authenticator.FromRequest function. The user details can then be used for further authorization logic. The authorizer.Authorize function is used to perform the actual authorization check.