mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
rebase: update kubernetes to latest
updating the kubernetes release to the latest in main go.mod Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
committed by
mergify[bot]
parent
63c4c05b35
commit
5a66991bb3
137
vendor/k8s.io/apiserver/plugin/pkg/authorizer/webhook/webhook.go
generated
vendored
137
vendor/k8s.io/apiserver/plugin/pkg/authorizer/webhook/webhook.go
generated
vendored
@ -32,14 +32,16 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/selection"
|
||||
"k8s.io/apimachinery/pkg/util/cache"
|
||||
utilnet "k8s.io/apimachinery/pkg/util/net"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/apiserver/pkg/apis/apiserver"
|
||||
apiservervalidation "k8s.io/apiserver/pkg/apis/apiserver/validation"
|
||||
"k8s.io/apiserver/pkg/authentication/user"
|
||||
"k8s.io/apiserver/pkg/authorization/authorizer"
|
||||
authorizationcel "k8s.io/apiserver/pkg/authorization/cel"
|
||||
"k8s.io/apiserver/pkg/features"
|
||||
genericfeatures "k8s.io/apiserver/pkg/features"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
"k8s.io/apiserver/pkg/util/webhook"
|
||||
"k8s.io/apiserver/plugin/pkg/authorizer/webhook/metrics"
|
||||
@ -195,15 +197,7 @@ func (w *WebhookAuthorizer) Authorize(ctx context.Context, attr authorizer.Attri
|
||||
}
|
||||
|
||||
if attr.IsResourceRequest() {
|
||||
r.Spec.ResourceAttributes = &authorizationv1.ResourceAttributes{
|
||||
Namespace: attr.GetNamespace(),
|
||||
Verb: attr.GetVerb(),
|
||||
Group: attr.GetAPIGroup(),
|
||||
Version: attr.GetAPIVersion(),
|
||||
Resource: attr.GetResource(),
|
||||
Subresource: attr.GetSubresource(),
|
||||
Name: attr.GetName(),
|
||||
}
|
||||
r.Spec.ResourceAttributes = resourceAttributesFrom(attr)
|
||||
} else {
|
||||
r.Spec.NonResourceAttributes = &authorizationv1.NonResourceAttributes{
|
||||
Path: attr.GetPath(),
|
||||
@ -211,7 +205,7 @@ func (w *WebhookAuthorizer) Authorize(ctx context.Context, attr authorizer.Attri
|
||||
}
|
||||
}
|
||||
// skipping match when feature is not enabled
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.StructuredAuthorizationConfiguration) {
|
||||
if utilfeature.DefaultFeatureGate.Enabled(genericfeatures.StructuredAuthorizationConfiguration) {
|
||||
// Process Match Conditions before calling the webhook
|
||||
matches, err := w.match(ctx, r)
|
||||
// If at least one matchCondition evaluates to an error (but none are FALSE):
|
||||
@ -251,7 +245,7 @@ func (w *WebhookAuthorizer) Authorize(ctx context.Context, attr authorizer.Attri
|
||||
metricsResult = "success"
|
||||
case ctx.Err() != nil:
|
||||
metricsResult = "canceled"
|
||||
case errors.Is(sarErr, context.DeadlineExceeded) || apierrors.IsTimeout(sarErr) || statusCode == http.StatusGatewayTimeout:
|
||||
case utilnet.IsTimeout(sarErr) || errors.Is(sarErr, context.DeadlineExceeded) || apierrors.IsTimeout(sarErr) || statusCode == http.StatusGatewayTimeout:
|
||||
metricsResult = "timeout"
|
||||
default:
|
||||
metricsResult = "error"
|
||||
@ -304,6 +298,109 @@ func (w *WebhookAuthorizer) Authorize(ctx context.Context, attr authorizer.Attri
|
||||
|
||||
}
|
||||
|
||||
func resourceAttributesFrom(attr authorizer.Attributes) *authorizationv1.ResourceAttributes {
|
||||
ret := &authorizationv1.ResourceAttributes{
|
||||
Namespace: attr.GetNamespace(),
|
||||
Verb: attr.GetVerb(),
|
||||
Group: attr.GetAPIGroup(),
|
||||
Version: attr.GetAPIVersion(),
|
||||
Resource: attr.GetResource(),
|
||||
Subresource: attr.GetSubresource(),
|
||||
Name: attr.GetName(),
|
||||
}
|
||||
|
||||
if utilfeature.DefaultFeatureGate.Enabled(genericfeatures.AuthorizeWithSelectors) {
|
||||
// If we are able to get any requirements while parsing selectors, use them, even if there's an error.
|
||||
// This is because selectors only narrow, so if a subset of selector requirements are available, the request can be allowed.
|
||||
if selectorRequirements, _ := fieldSelectorToAuthorizationAPI(attr); len(selectorRequirements) > 0 {
|
||||
ret.FieldSelector = &authorizationv1.FieldSelectorAttributes{
|
||||
Requirements: selectorRequirements,
|
||||
}
|
||||
}
|
||||
|
||||
if selectorRequirements, _ := labelSelectorToAuthorizationAPI(attr); len(selectorRequirements) > 0 {
|
||||
ret.LabelSelector = &authorizationv1.LabelSelectorAttributes{
|
||||
Requirements: selectorRequirements,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func fieldSelectorToAuthorizationAPI(attr authorizer.Attributes) ([]metav1.FieldSelectorRequirement, error) {
|
||||
requirements, getFieldSelectorErr := attr.GetFieldSelector()
|
||||
if len(requirements) == 0 {
|
||||
return nil, getFieldSelectorErr
|
||||
}
|
||||
|
||||
retRequirements := []metav1.FieldSelectorRequirement{}
|
||||
for _, requirement := range requirements {
|
||||
retRequirement := metav1.FieldSelectorRequirement{}
|
||||
switch {
|
||||
case requirement.Operator == selection.Equals || requirement.Operator == selection.DoubleEquals || requirement.Operator == selection.In:
|
||||
retRequirement.Operator = metav1.FieldSelectorOpIn
|
||||
retRequirement.Key = requirement.Field
|
||||
retRequirement.Values = []string{requirement.Value}
|
||||
case requirement.Operator == selection.NotEquals || requirement.Operator == selection.NotIn:
|
||||
retRequirement.Operator = metav1.FieldSelectorOpNotIn
|
||||
retRequirement.Key = requirement.Field
|
||||
retRequirement.Values = []string{requirement.Value}
|
||||
default:
|
||||
// ignore this particular requirement. since requirements are AND'd, it is safe to ignore unknown requirements
|
||||
// for authorization since the resulting check will only be as broad or broader than the intended.
|
||||
continue
|
||||
}
|
||||
retRequirements = append(retRequirements, retRequirement)
|
||||
}
|
||||
|
||||
if len(retRequirements) == 0 {
|
||||
// this means that all requirements were dropped (likely due to unknown operators), so we are checking the broader
|
||||
// unrestricted action.
|
||||
return nil, getFieldSelectorErr
|
||||
}
|
||||
return retRequirements, getFieldSelectorErr
|
||||
}
|
||||
|
||||
func labelSelectorToAuthorizationAPI(attr authorizer.Attributes) ([]metav1.LabelSelectorRequirement, error) {
|
||||
requirements, getLabelSelectorErr := attr.GetLabelSelector()
|
||||
if len(requirements) == 0 {
|
||||
return nil, getLabelSelectorErr
|
||||
}
|
||||
|
||||
retRequirements := []metav1.LabelSelectorRequirement{}
|
||||
for _, requirement := range requirements {
|
||||
retRequirement := metav1.LabelSelectorRequirement{
|
||||
Key: requirement.Key(),
|
||||
}
|
||||
if values := requirement.ValuesUnsorted(); len(values) > 0 {
|
||||
retRequirement.Values = values
|
||||
}
|
||||
switch requirement.Operator() {
|
||||
case selection.Equals, selection.DoubleEquals, selection.In:
|
||||
retRequirement.Operator = metav1.LabelSelectorOpIn
|
||||
case selection.NotEquals, selection.NotIn:
|
||||
retRequirement.Operator = metav1.LabelSelectorOpNotIn
|
||||
case selection.Exists:
|
||||
retRequirement.Operator = metav1.LabelSelectorOpExists
|
||||
case selection.DoesNotExist:
|
||||
retRequirement.Operator = metav1.LabelSelectorOpDoesNotExist
|
||||
default:
|
||||
// ignore this particular requirement. since requirements are AND'd, it is safe to ignore unknown requirements
|
||||
// for authorization since the resulting check will only be as broad or broader than the intended.
|
||||
continue
|
||||
}
|
||||
retRequirements = append(retRequirements, retRequirement)
|
||||
}
|
||||
|
||||
if len(retRequirements) == 0 {
|
||||
// this means that all requirements were dropped (likely due to unknown operators), so we are checking the broader
|
||||
// unrestricted action.
|
||||
return nil, getLabelSelectorErr
|
||||
}
|
||||
return retRequirements, getLabelSelectorErr
|
||||
}
|
||||
|
||||
// TODO: need to finish the method to get the rules when using webhook mode
|
||||
func (w *WebhookAuthorizer) RulesFor(user user.Info, namespace string) ([]authorizer.ResourceRuleInfo, []authorizer.NonResourceRuleInfo, bool, error) {
|
||||
var (
|
||||
@ -474,13 +571,15 @@ func v1ResourceAttributesToV1beta1ResourceAttributes(in *authorizationv1.Resourc
|
||||
return nil
|
||||
}
|
||||
return &authorizationv1beta1.ResourceAttributes{
|
||||
Namespace: in.Namespace,
|
||||
Verb: in.Verb,
|
||||
Group: in.Group,
|
||||
Version: in.Version,
|
||||
Resource: in.Resource,
|
||||
Subresource: in.Subresource,
|
||||
Name: in.Name,
|
||||
Namespace: in.Namespace,
|
||||
Verb: in.Verb,
|
||||
Group: in.Group,
|
||||
Version: in.Version,
|
||||
Resource: in.Resource,
|
||||
Subresource: in.Subresource,
|
||||
Name: in.Name,
|
||||
FieldSelector: in.FieldSelector,
|
||||
LabelSelector: in.LabelSelector,
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user