Skip to content

Commit 5c24c8f

Browse files
deads2kbertinatto
authored andcommitted
UPSTREAM: <carry>: openshift-kube-apiserver: add openshift-kube-apiserver code
UPSTREAM: <carry>: openshift-kube-apiserver: enabled conversion gen for admission configs UPSTREAM: <carry>: openshift-kube-apiserver/admission: fix featuregates resource name UPSTREAM: <carry>: openshift-kube-apiserver/admission: add missing FeatureSets UPSTREAM: <carry>: openshift-kube-apiserver: use github.com/openshift/apiserver-library-go/pkg/labelselector UPSTREAM: <carry>: openshift authenticator: don't allow old-style tokens UPSTREAM: <carry>: oauth-authn: support sha256 prefixed tokens UPSTREAM: <carry>: oauth-token-authn: switch to sha256~ prefix UPSTREAM: <carry>: oauth-token-authn: add sha256~ support to bootstrap authenticator UPSTREAM: <drop>: remove the openshift authenticator from the apiserver In 4.8, we moved the authenticator to be configured via webhookTokenAuthenticators to an endpoint in the oauth-apiserver, this should now be safe to remove. UPSTREAM: <carry>: set ResourceQuotaValidationOptions to true When PodAffinityNamespaceSelector goes to beta or GA this might affect how our ClusterResourceQuota might work UPSTREAM: <carry>: simplify the authorizer patch to allow the flags to function UPSTREAM: <carry>: eliminate unnecessary closure in openshift configuration wiring UPSTREAM: <carry>: add crdvalidation for apiserver.spec.tlsSecurityProfile UPSTREAM: <carry>: openshift-kube-apiserver: Add custom resource validation for network spec UPSTREAM: <carry>: stop overriding flags that are explicitly set UPSTREAM: <carry>: add readyz check for openshift apiserver availability UPSTREAM: <carry>: wait for oauth-apiserver accessibility UPSTREAM: <carry>: provide a new admission plugin to mutate management pods CPUs requests The ManagementCPUOverride admission plugin replaces pod container CPU requests with a new management resource. It applies to all pods that: 1. are in an allowed namespace 2. and have the workload annotation. It also sets the new management resource request and limit and set resource annotation that CRI-O can recognize and apply the relevant changes. For more information, see - openshift/enhancements#703 Conditions for CPUs requests deletion: 1. The namespace should have allowed annotation "workload.openshift.io/allowed": "management" 2. The pod should have management annotation: "workload.openshift.io/management": "{"effect": "PreferredDuringScheduling"}" 3. All nodes under the cluster should have new management resource - "management.workload.openshift.io/cores" 4. The CPU request deletion will not change the pod QoS class UPSTREAM: <carry>: Does not prevent pod creation because of no nodes reason when it runs under the regular cluster Check the `cluster` infrastructure resource status to be sure that we run on top of a SNO cluster and in case if the pod runs on top of regular cluster, exit before node existence check. UPSTREAM: <carry>: do not mutate pods when it has a container with both CPU request and limit Removing the CPU request from the container that has a CPU limit will result in the defaulter to set the CPU request back equals to the CPU limit. UPSTREAM: <carry>: Reject the pod creation when we can not decide the cluster type It is possible a race condition between pod creation and the update of the infrastructure resource status with correct values under Status.ControlPlaneTopology and Status.InfrastructureTopology. UPSTREAM: <carry>: add CRD validation for dnses Add an admission plugin that validates the dnses.operator.openshift.io custom resource. For now, the plugin only validates the DNS pod node-placement parameters. This commit fixes bug 1967745. https://bugzilla.redhat.com/show_bug.cgi?id=1967745 * openshift-kube-apiserver/admission/customresourcevalidation/attributes.go (init): Install operatorv1 into supportedObjectsScheme. * openshift-kube-apiserver/admission/customresourcevalidation/customresourcevalidationregistration/cr_validation_registration.go (AllCustomResourceValidators, RegisterCustomResourceValidation): Register the new plugin. * openshift-kube-apiserver/admission/customresourcevalidation/dns/validate_dns.go: New file. (PluginName): New const. (Register): New function. Register the plugin. (toDNSV1): New function. Convert a runtime object to a versioned DNS. (dnsV1): New type to represent a runtime object that is validated as a versioned DNS. (ValidateCreate, ValidateUpdate, ValidateStatusUpdate): New methods. Implement the ObjectValidator interface, using the validateDNSSpecCreate and validateDNSSpecUpdate helpers. (validateDNSSpecCreate, validateDNSSpecUpdate): New functions. Validate a DNS, using the validateDNSSpec helper. (validateDNSSpec): New function. Validate the spec field of a DNS, using the validateDNSNodePlacement helper. (validateDNSNodePlacement): New function. Validate the node selector and tolerations in a DNS's node-placement parameters, using validateTolerations. (validateTolerations): New function. Validate a slice of corev1.Toleration. * openshift-kube-apiserver/admission/customresourcevalidation/dns/validate_dns_test.go: New file. (TestFailValidateDNSSpec): Verify that validateDNSSpec rejects invalid DNS specs. (TestSucceedValidateDNSSpec): Verify that validateDNSSpec accepts valid DNS specs. * vendor/*: Regenerate. UPSTREAM: <carry>: prevent the kubecontrollermanager service-ca from getting less secure UPSTREAM: <carry>: allow SCC to be disabled on a per-namespace basis UPSTREAM: <carry>: verify required http2 cipher suites In the Apiserver admission, we need to return an error if the required http2 cipher suites are missing from a custom tlsSecurityProfile. Currently, custom cipher suites missing ECDHE_RSA_WITH_AES_128_GCM_SHA256 or ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 result in invalid http2 Server configuration causing the apiservers to crash. See: go/x/net/http2.ConfigureServer for futher information. UPSTREAM: <carry>: drop the warning to use --keep-annotations When a user runs the `oc debug` command for the pod with the management resource, we will inform him that he should pass `--keep-annotations` parameter to the debug command. UPSTREAM: <carry>: admission/managementcpusoverride: cover the roll-back case During the upgrade and roll-back flow 4.7->4.8->4.7, the topology related fields under the infrastructure can be empty because the old API does not support them. The code will equal the empty infrastructure section with the current one. When the status has some other non-empty field, and topology fields are empty, we assume that the cluster currently passes via roll-back and not via the clean install. UPSTREAM: <carry>: Remove pod warning annotation when workload partitioning is disabled UPSTREAM: <carry>: use new access token inactivity timeout field. UPSTREAM: <carry>: apirequestcount validation UPSTREAM: <carry>: Added config node object validation for extreme latency profiles UPSTREAM: <carry>: Add Upstream validation in the DNS admission check patches UPSTREAM: <carry>: Make RestrictedEndpointsAdmission check NotReadyAddresses UPSTREAM: <carry>: Make RestrictedEndpointsAdmission restrict EndpointSlices as well Moved SkipSystemMasterAuthorizers to the authorizer. UPSTREAM: <carry>: Add validation plugin for CRD-based route parity. UPSTREAM: <carry>: Add host assignment plugin for CRD-based routes. UPSTREAM: <carry>: Apply shared defaulters to CRD-based routes. Signed-off-by: Artyom Lukianov <[email protected]> Signed-off-by: Damien Grisonnet <[email protected]> Signed-off-by: Swarup Ghosh <[email protected]> OpenShift-Rebase-Source: 932411e OpenShift-Rebase-Source: 1899555 OpenShift-Rebase-Source: 453583e OpenShift-Rebase-Source: bf7e23e UPSTREAM: <carry>: STOR-829: Add CSIInlineVolumeSecurity admission plugin The CSIInlineVolumeSecurity admission plugin inspects inline CSI volumes on pod creation and compares the security.openshift.io/csi-ephemeral-volume-profile label on the CSIDriver object to the pod security profile on the namespace. OpenShift-Rebase-Source: a65c34b UPSTREAM: <carry>: add icsp,idms,itms validation reject creating icsp with idms/itms exist Reject icsp with idms.itms resources exists. According to the discuusion resolution https://docs.google.com/document/d/13h6IJn8wlzXdiPMvCWlMEHOXXqEZ9_GYOl02Wldb3z8/edit?usp=sharing, one of current icsp or new mirror setting crd should be rejected if a user tries to use them on the same cluster. UPSTREAM: <carry>: node admission plugin for cpu partitioning The ManagedNode admission plugin makes the Infrastructure.Status.CPUPartitioning field authoritative. This validates that nodes that wish to join the cluster are first configured to properly handle workload pinning For more information see - openshift/enhancements#1213 UPSTREAM: <carry>: kube-apiserver: allow injection of kube-apiserver options UPSTREAM: <carry>: kube-apiserver: allow rewiring OpenShift-Rebase-Source: 56b49c9 OpenShift-Rebase-Source: bcf574c UPSTREAM: <carry>: STOR-1270: Admission plugin to deny deletion of storages.operator.openshift.io UPSTREAM: <carry>: support for both icsp and idms objects Revert: #1310 Add support for ICSP and IDMS objects living at the same time. UPSTREAM: <carry>: openshift-kube-apiserver: add openshift-kube-apisever code UPSTREAM: <carry>: featureset validation moved to CEL UPSTREAM: <carry>: Add context to ObjectValidator TODO: add router validation logic to implement ctx add in ObjectValidator UPSTREAM: <carry>: loosen authentication.spec.type validation UPSTREAM: <carry>: openshift-kube-apiserver: add kube-apiserver patches pod .spec.nodeName should not override project node selector in podNodeEnvironment admission plugin UPSTREAM: <carry>: Fix sets.String and sets.Set[string] type mismatch libray-go uses the genetic Set while upstream still uses the deprecated sets.String in some part of its codes. UPSTREAM: <carry>: Add RouteExternalCertificate validation in Route ObjectValidator UPSTREAM: <carry>: Fix incorrect type casting in admission validate_apiserver UPSTREAM: <carry>: react to library-go changes UPSTREAM: <carry>: Update RouteExternalCertificate validation in Route ObjectValidator UPSTREAM: <carry>: APIRequestCount Handler OpenShift-Rebase-Source: 4d74b77
1 parent 67e2ddc commit 5c24c8f

File tree

183 files changed

+21379
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

183 files changed

+21379
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package admissionenablement
2+
3+
import (
4+
"k8s.io/kubernetes/cmd/kube-apiserver/app/options"
5+
"k8s.io/kubernetes/openshift-kube-apiserver/admission/customresourcevalidation/customresourcevalidationregistration"
6+
)
7+
8+
func InstallOpenShiftAdmissionPlugins(o *options.ServerRunOptions) {
9+
existingAdmissionOrder := o.Admission.GenericAdmission.RecommendedPluginOrder
10+
o.Admission.GenericAdmission.RecommendedPluginOrder = NewOrderedKubeAdmissionPlugins(existingAdmissionOrder)
11+
RegisterOpenshiftKubeAdmissionPlugins(o.Admission.GenericAdmission.Plugins)
12+
customresourcevalidationregistration.RegisterCustomResourceValidation(o.Admission.GenericAdmission.Plugins)
13+
existingDefaultOff := o.Admission.GenericAdmission.DefaultOffPlugins
14+
o.Admission.GenericAdmission.DefaultOffPlugins = NewDefaultOffPluginsFunc(existingDefaultOff)()
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package admissionenablement
2+
3+
import (
4+
"time"
5+
6+
"github.com/openshift/library-go/pkg/apiserver/admission/admissiontimeout"
7+
"k8s.io/apimachinery/pkg/labels"
8+
"k8s.io/apiserver/pkg/admission"
9+
"k8s.io/client-go/informers"
10+
"k8s.io/client-go/kubernetes"
11+
"k8s.io/kubernetes/openshift-kube-apiserver/admission/namespaceconditions"
12+
controlplaneapiserver "k8s.io/kubernetes/pkg/controlplane/apiserver/options"
13+
)
14+
15+
const disableSCCLevelLabel = "security.openshift.io/disable-securitycontextconstraints"
16+
17+
var enforceSCCSelector labels.Selector
18+
19+
func init() {
20+
var err error
21+
enforceSCCSelector, err = labels.Parse(disableSCCLevelLabel + " != true")
22+
if err != nil {
23+
panic(err)
24+
}
25+
}
26+
27+
func SetAdmissionDefaults(o *controlplaneapiserver.CompletedOptions, informers informers.SharedInformerFactory, kubeClient kubernetes.Interface) {
28+
// set up the decorators we need. This is done late and out of order because our decorators currently require informers which are not
29+
// present until we start running
30+
namespaceLabelDecorator := namespaceconditions.NamespaceLabelConditions{
31+
NamespaceClient: kubeClient.CoreV1(),
32+
NamespaceLister: informers.Core().V1().Namespaces().Lister(),
33+
34+
SkipLevelZeroNames: SkipRunLevelZeroPlugins,
35+
SkipLevelOneNames: SkipRunLevelOnePlugins,
36+
}
37+
sccLabelDecorator := namespaceconditions.NewConditionalAdmissionPlugins(
38+
kubeClient.CoreV1(), informers.Core().V1().Namespaces().Lister(), enforceSCCSelector,
39+
"security.openshift.io/SecurityContextConstraint", "security.openshift.io/SCCExecRestrictions")
40+
41+
o.Admission.GenericAdmission.Decorators = append(o.Admission.GenericAdmission.Decorators,
42+
admission.Decorators{
43+
// SCC can be skipped by setting a namespace label `security.openshift.io/disable-securitycontextconstraints = true`
44+
// This is useful for disabling SCC and using PodSecurity admission instead.
45+
admission.DecoratorFunc(sccLabelDecorator.WithNamespaceLabelSelector),
46+
47+
admission.DecoratorFunc(namespaceLabelDecorator.WithNamespaceLabelConditions),
48+
admission.DecoratorFunc(admissiontimeout.AdmissionTimeout{Timeout: 13 * time.Second}.WithTimeout),
49+
},
50+
)
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
package admissionenablement
2+
3+
import (
4+
"k8s.io/apimachinery/pkg/util/sets"
5+
"k8s.io/apiserver/pkg/admission"
6+
"k8s.io/apiserver/pkg/admission/plugin/resourcequota"
7+
mutatingwebhook "k8s.io/apiserver/pkg/admission/plugin/webhook/mutating"
8+
9+
"github.com/openshift/apiserver-library-go/pkg/admission/imagepolicy"
10+
imagepolicyapiv1 "github.com/openshift/apiserver-library-go/pkg/admission/imagepolicy/apis/imagepolicy/v1"
11+
quotaclusterresourcequota "github.com/openshift/apiserver-library-go/pkg/admission/quota/clusterresourcequota"
12+
"github.com/openshift/apiserver-library-go/pkg/securitycontextconstraints/sccadmission"
13+
authorizationrestrictusers "k8s.io/kubernetes/openshift-kube-apiserver/admission/authorization/restrictusers"
14+
quotaclusterresourceoverride "k8s.io/kubernetes/openshift-kube-apiserver/admission/autoscaling/clusterresourceoverride"
15+
"k8s.io/kubernetes/openshift-kube-apiserver/admission/autoscaling/managednode"
16+
"k8s.io/kubernetes/openshift-kube-apiserver/admission/autoscaling/managementcpusoverride"
17+
quotarunonceduration "k8s.io/kubernetes/openshift-kube-apiserver/admission/autoscaling/runonceduration"
18+
"k8s.io/kubernetes/openshift-kube-apiserver/admission/customresourcevalidation/customresourcevalidationregistration"
19+
"k8s.io/kubernetes/openshift-kube-apiserver/admission/network/externalipranger"
20+
"k8s.io/kubernetes/openshift-kube-apiserver/admission/network/restrictedendpoints"
21+
ingressadmission "k8s.io/kubernetes/openshift-kube-apiserver/admission/route"
22+
"k8s.io/kubernetes/openshift-kube-apiserver/admission/route/hostassignment"
23+
projectnodeenv "k8s.io/kubernetes/openshift-kube-apiserver/admission/scheduler/nodeenv"
24+
schedulerpodnodeconstraints "k8s.io/kubernetes/openshift-kube-apiserver/admission/scheduler/podnodeconstraints"
25+
"k8s.io/kubernetes/openshift-kube-apiserver/admission/storage/csiinlinevolumesecurity"
26+
)
27+
28+
func RegisterOpenshiftKubeAdmissionPlugins(plugins *admission.Plugins) {
29+
authorizationrestrictusers.Register(plugins)
30+
hostassignment.Register(plugins)
31+
imagepolicy.Register(plugins)
32+
ingressadmission.Register(plugins)
33+
managementcpusoverride.Register(plugins)
34+
managednode.Register(plugins)
35+
projectnodeenv.Register(plugins)
36+
quotaclusterresourceoverride.Register(plugins)
37+
quotaclusterresourcequota.Register(plugins)
38+
quotarunonceduration.Register(plugins)
39+
schedulerpodnodeconstraints.Register(plugins)
40+
sccadmission.Register(plugins)
41+
sccadmission.RegisterSCCExecRestrictions(plugins)
42+
externalipranger.RegisterExternalIP(plugins)
43+
restrictedendpoints.RegisterRestrictedEndpoints(plugins)
44+
csiinlinevolumesecurity.Register(plugins)
45+
}
46+
47+
var (
48+
49+
// these are admission plugins that cannot be applied until after the kubeapiserver starts.
50+
// TODO if nothing comes to mind in 3.10, kill this
51+
SkipRunLevelZeroPlugins = sets.NewString()
52+
// these are admission plugins that cannot be applied until after the openshiftapiserver apiserver starts.
53+
SkipRunLevelOnePlugins = sets.NewString(
54+
imagepolicyapiv1.PluginName, // "image.openshift.io/ImagePolicy"
55+
"quota.openshift.io/ClusterResourceQuota",
56+
"security.openshift.io/SecurityContextConstraint",
57+
"security.openshift.io/SCCExecRestrictions",
58+
)
59+
60+
// openshiftAdmissionPluginsForKubeBeforeMutating are the admission plugins to add after kube admission, before mutating webhooks
61+
openshiftAdmissionPluginsForKubeBeforeMutating = []string{
62+
"autoscaling.openshift.io/ClusterResourceOverride",
63+
managementcpusoverride.PluginName, // "autoscaling.openshift.io/ManagementCPUsOverride"
64+
"authorization.openshift.io/RestrictSubjectBindings",
65+
"autoscaling.openshift.io/RunOnceDuration",
66+
"scheduling.openshift.io/PodNodeConstraints",
67+
"scheduling.openshift.io/OriginPodNodeEnvironment",
68+
"network.openshift.io/ExternalIPRanger",
69+
"network.openshift.io/RestrictedEndpointsAdmission",
70+
imagepolicyapiv1.PluginName, // "image.openshift.io/ImagePolicy"
71+
"security.openshift.io/SecurityContextConstraint",
72+
"security.openshift.io/SCCExecRestrictions",
73+
"route.openshift.io/IngressAdmission",
74+
hostassignment.PluginName, // "route.openshift.io/RouteHostAssignment"
75+
csiinlinevolumesecurity.PluginName, // "storage.openshift.io/CSIInlineVolumeSecurity"
76+
managednode.PluginName, // "autoscaling.openshift.io/ManagedNode"
77+
}
78+
79+
// openshiftAdmissionPluginsForKubeAfterResourceQuota are the plugins to add after ResourceQuota plugin
80+
openshiftAdmissionPluginsForKubeAfterResourceQuota = []string{
81+
"quota.openshift.io/ClusterResourceQuota",
82+
}
83+
84+
// additionalDefaultOnPlugins is a list of plugins we turn on by default that core kube does not.
85+
additionalDefaultOnPlugins = sets.NewString(
86+
"NodeRestriction",
87+
"OwnerReferencesPermissionEnforcement",
88+
"PodNodeSelector",
89+
"PodTolerationRestriction",
90+
"Priority",
91+
imagepolicyapiv1.PluginName, // "image.openshift.io/ImagePolicy"
92+
"StorageObjectInUseProtection",
93+
)
94+
)
95+
96+
func NewOrderedKubeAdmissionPlugins(kubeAdmissionOrder []string) []string {
97+
ret := []string{}
98+
for _, curr := range kubeAdmissionOrder {
99+
if curr == mutatingwebhook.PluginName {
100+
ret = append(ret, openshiftAdmissionPluginsForKubeBeforeMutating...)
101+
ret = append(ret, customresourcevalidationregistration.AllCustomResourceValidators...)
102+
}
103+
104+
ret = append(ret, curr)
105+
106+
if curr == resourcequota.PluginName {
107+
ret = append(ret, openshiftAdmissionPluginsForKubeAfterResourceQuota...)
108+
}
109+
}
110+
return ret
111+
}
112+
113+
func NewDefaultOffPluginsFunc(kubeDefaultOffAdmission sets.Set[string]) func() sets.Set[string] {
114+
return func() sets.Set[string] {
115+
kubeOff := sets.New[string](kubeDefaultOffAdmission.UnsortedList()...)
116+
kubeOff.Delete(additionalDefaultOnPlugins.List()...)
117+
kubeOff.Delete(openshiftAdmissionPluginsForKubeBeforeMutating...)
118+
kubeOff.Delete(openshiftAdmissionPluginsForKubeAfterResourceQuota...)
119+
kubeOff.Delete(customresourcevalidationregistration.AllCustomResourceValidators...)
120+
return kubeOff
121+
}
122+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package admissionenablement
2+
3+
import (
4+
"reflect"
5+
"testing"
6+
7+
"k8s.io/apimachinery/pkg/util/sets"
8+
"k8s.io/apiserver/pkg/admission"
9+
genericapiserver "k8s.io/apiserver/pkg/server"
10+
"k8s.io/kubernetes/pkg/kubeapiserver/options"
11+
12+
"github.com/openshift/library-go/pkg/apiserver/admission/admissionregistrationtesting"
13+
"k8s.io/kubernetes/openshift-kube-apiserver/admission/customresourcevalidation/customresourcevalidationregistration"
14+
)
15+
16+
func TestAdmissionRegistration(t *testing.T) {
17+
orderedAdmissionChain := NewOrderedKubeAdmissionPlugins(options.AllOrderedPlugins)
18+
defaultOffPlugins := NewDefaultOffPluginsFunc(options.DefaultOffAdmissionPlugins())()
19+
registerAllAdmissionPlugins := func(plugins *admission.Plugins) {
20+
genericapiserver.RegisterAllAdmissionPlugins(plugins)
21+
options.RegisterAllAdmissionPlugins(plugins)
22+
RegisterOpenshiftKubeAdmissionPlugins(plugins)
23+
customresourcevalidationregistration.RegisterCustomResourceValidation(plugins)
24+
}
25+
plugins := admission.NewPlugins()
26+
registerAllAdmissionPlugins(plugins)
27+
28+
err := admissionregistrationtesting.AdmissionRegistrationTest(plugins, orderedAdmissionChain, sets.Set[string](defaultOffPlugins))
29+
if err != nil {
30+
t.Fatal(err)
31+
}
32+
}
33+
34+
// TestResourceQuotaBeforeClusterResourceQuota simply test wheather ResourceQuota plugin is before ClusterResourceQuota plugin
35+
func TestResourceQuotaBeforeClusterResourceQuota(t *testing.T) {
36+
orderedAdmissionChain := NewOrderedKubeAdmissionPlugins(options.AllOrderedPlugins)
37+
38+
expectedOrderedAdmissionSubChain := []string{"ResourceQuota", "quota.openshift.io/ClusterResourceQuota", "AlwaysDeny"}
39+
actualOrderedAdmissionChain := extractSubChain(orderedAdmissionChain, expectedOrderedAdmissionSubChain[0])
40+
41+
if !reflect.DeepEqual(actualOrderedAdmissionChain, expectedOrderedAdmissionSubChain) {
42+
t.Fatalf("expected %v, got %v ", expectedOrderedAdmissionSubChain, actualOrderedAdmissionChain)
43+
}
44+
}
45+
46+
func extractSubChain(admissionChain []string, takeFrom string) []string {
47+
indexOfTake := 0
48+
for index, admission := range admissionChain {
49+
if admission == takeFrom {
50+
indexOfTake = index
51+
break
52+
}
53+
}
54+
return admissionChain[indexOfTake:]
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package restrictusers
2+
3+
import (
4+
userv1 "github.com/openshift/api/user/v1"
5+
)
6+
7+
type fakeGroupCache struct {
8+
groups []userv1.Group
9+
}
10+
11+
func (g fakeGroupCache) GroupsFor(user string) ([]*userv1.Group, error) {
12+
ret := []*userv1.Group{}
13+
for i := range g.groups {
14+
group := &g.groups[i]
15+
for _, currUser := range group.Users {
16+
if user == currUser {
17+
ret = append(ret, group)
18+
break
19+
}
20+
}
21+
22+
}
23+
return ret, nil
24+
}
25+
26+
func (g fakeGroupCache) HasSynced() bool {
27+
return true
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package restrictusers
2+
3+
import (
4+
"k8s.io/apiserver/pkg/admission"
5+
6+
userinformer "github.com/openshift/client-go/user/informers/externalversions"
7+
)
8+
9+
func NewInitializer(userInformer userinformer.SharedInformerFactory) admission.PluginInitializer {
10+
return &localInitializer{userInformer: userInformer}
11+
}
12+
13+
type WantsUserInformer interface {
14+
SetUserInformer(userinformer.SharedInformerFactory)
15+
admission.InitializationValidator
16+
}
17+
18+
type localInitializer struct {
19+
userInformer userinformer.SharedInformerFactory
20+
}
21+
22+
// Initialize will check the initialization interfaces implemented by each plugin
23+
// and provide the appropriate initialization data
24+
func (i *localInitializer) Initialize(plugin admission.Interface) {
25+
if wants, ok := plugin.(WantsUserInformer); ok {
26+
wants.SetUserInformer(i.userInformer)
27+
}
28+
}

0 commit comments

Comments
 (0)