Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Hunt <[email protected]>
  • Loading branch information
haircommander committed Dec 2, 2024
1 parent c864fc7 commit 6677ace
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"k8s.io/client-go/informers"
corev1listers "k8s.io/client-go/listers/core/v1"
"k8s.io/component-base/featuregate"
"k8s.io/klog/v2"
"k8s.io/kubernetes/openshift-kube-apiserver/admission/customresourcevalidation"
)

Expand Down Expand Up @@ -146,6 +147,10 @@ func (c *configNodeV1) validateMinimumKubeletVersion(obj *configv1.Node) *field.
return field.InternalError(fieldPath, fmt.Errorf("caches not synchronized, cannot validate minimumKubeletVersion"))
}

if c.nodeLister() == nil {
klog.Infof("XXXXXXX node lister nil")
}

nodes, err := c.nodeLister().List(labels.Everything())
if err != nil {
return field.Forbidden(fieldPath, fmt.Sprintf("Getting nodes to compare minimum version %v", err.Error()))
Expand Down Expand Up @@ -189,12 +194,15 @@ func (c *validateCustomResourceWithNodeLister) SetExternalKubeInformerFactory(ku
nodeInformer := kubeInformers.Core().V1().Nodes()
c.nodeLister = nodeInformer.Lister()
c.SetReadyFunc(nodeInformer.Informer().HasSynced)
klog.Infof("XXXXXXX initialized")
}

func (c *validateCustomResourceWithNodeLister) ValidateInitialization() error {
if c.nodeLister == nil {
klog.Infof("XXXXXXX node lister nil")
return fmt.Errorf("%s needs a nodes", PluginName)
}
klog.Infof("XXXXXXX node lister not nil")

return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
v1listers "k8s.io/client-go/listers/core/v1"
cache "k8s.io/client-go/tools/cache"
"k8s.io/component-base/featuregate"
"k8s.io/klog/v2"
api "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/auth/nodeidentifier"
)
Expand Down Expand Up @@ -47,16 +48,19 @@ func NewMinimumKubeletVersion(minVersion *semver.Version,

func (m *minimumKubeletVersionAuth) Authorize(ctx context.Context, attrs authorizer.Attributes) (authorizer.Decision, string, error) {
if m.minVersion == nil {
klog.Infof("XXXXXXXX min version nil")
return authorizer.DecisionNoOpinion, "", nil
}

nodeName, isNode := m.nodeIdentifier.NodeIdentity(attrs.GetUser())
if !isNode {
// ignore requests from non-nodes
klog.Infof("XXXXXXXX not a node %v", attrs.GetUser())
return authorizer.DecisionNoOpinion, "", nil
}

if len(nodeName) == 0 {
klog.Infof("XXXXXXXX empty node name %v", attrs.GetUser())
return authorizer.DecisionNoOpinion, fmt.Sprintf("unknown node for user %q", attrs.GetUser().GetName()), nil
}

Expand All @@ -67,26 +71,32 @@ func (m *minimumKubeletVersionAuth) Authorize(ctx context.Context, attrs authori
switch requestResource {
case api.Resource("nodes"):
if v := attrs.GetVerb(); v == "get" || v == "update" {
klog.Infof("XXXXXXXX node get or update")
return authorizer.DecisionNoOpinion, "", nil
}
// TODO(haircommander): do we need other flavors of access reviews here?
case api.Resource("subjectaccessreviews"):
klog.Infof("XXXXXXXX SAR")
return authorizer.DecisionNoOpinion, "", nil
}
}

if !m.hasNodeInformerSyncedFn() {
klog.Infof("XXXXXXXX not synced")
return authorizer.DecisionNoOpinion, fmt.Sprintf("node informer not synced, cannot check if node %s is new enough", nodeName), nil
}

node, err := m.nodeLister.Get(nodeName)
if err != nil {
klog.Infof("XXXXXXXX failed to get node %s", nodeName)
return authorizer.DecisionNoOpinion, fmt.Sprintf("failed to get node %s: %v", nodeName, err), nil
}

if err := nodelib.IsNodeTooOld(node, m.minVersion); err != nil {
klog.Infof("XXXXXXXX node too old %s", nodeName)
return authorizer.DecisionDeny, err.Error(), nil
}

klog.Infof("XXXXXXXX OK")
return authorizer.DecisionNoOpinion, "", nil
}

0 comments on commit 6677ace

Please sign in to comment.