-
Notifications
You must be signed in to change notification settings - Fork 611
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AuthZ conformance e2e test suite (#8150)
* Add authz test suite for addressables * Run ./hack/update-deps.sh --upgrade to get latest reconciler-test changes * Use eventshub.OIDCSubject(sub) * Fix Broker EventPolicy status condition set * Enable NotReady checks again * Fix style issues * Update test/rekt/features/authz/addressable_authz_conformance.go Co-authored-by: Calum Murray <cmurray@redhat.com> * Update test/rekt/features/authz/addressable_authz_conformance.go Co-authored-by: Calum Murray <cmurray@redhat.com> --------- Co-authored-by: Calum Murray <cmurray@redhat.com>
- Loading branch information
Showing
4 changed files
with
159 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
test/rekt/features/authz/addressable_authz_conformance.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
/* | ||
Copyright 2024 The Knative Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package authz | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"knative.dev/eventing/test/rekt/resources/eventpolicy" | ||
"knative.dev/eventing/test/rekt/resources/pingsource" | ||
"knative.dev/reconciler-test/pkg/environment" | ||
|
||
"knative.dev/eventing/test/rekt/features/featureflags" | ||
|
||
"github.com/cloudevents/sdk-go/v2/test" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"knative.dev/reconciler-test/pkg/eventshub" | ||
eventassert "knative.dev/reconciler-test/pkg/eventshub/assert" | ||
"knative.dev/reconciler-test/pkg/feature" | ||
"knative.dev/reconciler-test/pkg/k8s" | ||
) | ||
|
||
func AddressableAuthZConformance(gvr schema.GroupVersionResource, kind, name string) *feature.FeatureSet { | ||
fs := feature.FeatureSet{ | ||
Name: fmt.Sprintf("%s handles authorization in requests correctly", kind), | ||
Features: []*feature.Feature{ | ||
addressableAllowsAuthorizedRequest(gvr, kind, name), | ||
addressableRejectsUnauthorizedRequest(gvr, kind, name), | ||
addressableBecomesUnreadyOnUnreadyEventPolicy(gvr, kind, name), | ||
}, | ||
} | ||
return &fs | ||
} | ||
|
||
func addressableAllowsAuthorizedRequest(gvr schema.GroupVersionResource, kind, name string) *feature.Feature { | ||
f := feature.NewFeatureNamed(fmt.Sprintf("%s accepts authorized request", kind)) | ||
|
||
f.Prerequisite("OIDC authentication is enabled", featureflags.AuthenticationOIDCEnabled()) | ||
f.Prerequisite("transport encryption is strict", featureflags.TransportEncryptionStrict()) | ||
f.Prerequisite("should not run when Istio is enabled", featureflags.IstioDisabled()) | ||
|
||
source := feature.MakeRandomK8sName("source") | ||
eventPolicy := feature.MakeRandomK8sName("eventpolicy") | ||
sourceSubject := feature.MakeRandomK8sName("source-oidc-identity") | ||
|
||
event := test.FullEvent() | ||
|
||
// Install event policy | ||
f.Setup("Install the EventPolicy", func(ctx context.Context, t feature.T) { | ||
namespace := environment.FromContext(ctx).Namespace() | ||
eventpolicy.Install( | ||
eventPolicy, | ||
eventpolicy.WithToRef( | ||
gvr.GroupVersion().WithKind(kind), | ||
name), | ||
eventpolicy.WithFromSubject(fmt.Sprintf("system:serviceaccount:%s:%s", namespace, sourceSubject)), | ||
)(ctx, t) | ||
}) | ||
f.Setup(fmt.Sprintf("EventPolicy for %s %s is ready", kind, name), k8s.IsReady(gvr, name)) | ||
|
||
// Install source | ||
f.Requirement("install source", eventshub.Install( | ||
source, | ||
eventshub.StartSenderToResourceTLS(gvr, name, nil), | ||
eventshub.InputEvent(event), | ||
eventshub.OIDCSubject(sourceSubject), | ||
)) | ||
|
||
f.Alpha(kind). | ||
Must("event sent", eventassert.OnStore(source).MatchSentEvent(test.HasId(event.ID())).Exact(1)). | ||
Must("get 202 on response", eventassert.OnStore(source).Match(eventassert.MatchStatusCode(202)).AtLeast(1)) | ||
|
||
return f | ||
} | ||
|
||
func addressableRejectsUnauthorizedRequest(gvr schema.GroupVersionResource, kind, name string) *feature.Feature { | ||
f := feature.NewFeatureNamed(fmt.Sprintf("%s rejects unauthorized request", kind)) | ||
|
||
f.Prerequisite("OIDC authentication is enabled", featureflags.AuthenticationOIDCEnabled()) | ||
f.Prerequisite("transport encryption is strict", featureflags.TransportEncryptionStrict()) | ||
f.Prerequisite("should not run when Istio is enabled", featureflags.IstioDisabled()) | ||
|
||
source := feature.MakeRandomK8sName("source") | ||
eventPolicy := feature.MakeRandomK8sName("eventpolicy") | ||
|
||
event := test.FullEvent() | ||
|
||
// Install event policy | ||
f.Setup("Install the EventPolicy with from subject that does not match", eventpolicy.Install( | ||
eventPolicy, | ||
eventpolicy.WithToRef( | ||
gvr.GroupVersion().WithKind(kind), | ||
name), | ||
eventpolicy.WithFromSubject("system:serviceaccount:default:unknown-identity"), | ||
)) | ||
f.Setup(fmt.Sprintf("EventPolicy for %s %s is ready", kind, name), k8s.IsReady(gvr, name)) | ||
|
||
// Install source | ||
f.Requirement("install source", eventshub.Install( | ||
source, | ||
eventshub.StartSenderToResourceTLS(gvr, name, nil), | ||
eventshub.InputEvent(event), | ||
eventshub.InitialSenderDelay(10*time.Second), | ||
)) | ||
|
||
f.Alpha(kind). | ||
Must("event sent", eventassert.OnStore(source).MatchSentEvent(test.HasId(event.ID())).Exact(1)). | ||
Must("get 403 on response", eventassert.OnStore(source).Match(eventassert.MatchStatusCode(403)).AtLeast(1)) | ||
|
||
return f | ||
} | ||
|
||
func addressableBecomesUnreadyOnUnreadyEventPolicy(gvr schema.GroupVersionResource, kind, name string) *feature.Feature { | ||
f := feature.NewFeatureNamed(fmt.Sprintf("%s becomes NotReady when EventPolicy is NotReady", kind)) | ||
|
||
f.Prerequisite("OIDC authentication is enabled", featureflags.AuthenticationOIDCEnabled()) | ||
f.Prerequisite("transport encryption is strict", featureflags.TransportEncryptionStrict()) | ||
f.Prerequisite("should not run when Istio is enabled", featureflags.IstioDisabled()) | ||
|
||
eventPolicy := feature.MakeRandomK8sName("eventpolicy") | ||
|
||
f.Setup(fmt.Sprintf("%s is ready initially", kind), k8s.IsReady(gvr, name)) | ||
|
||
// Install event policy | ||
f.Requirement("Install the EventPolicy", eventpolicy.Install( | ||
eventPolicy, | ||
eventpolicy.WithToRef( | ||
gvr.GroupVersion().WithKind(kind), | ||
name), | ||
eventpolicy.WithFromRef(pingsource.Gvr().GroupVersion().WithKind("PingSource"), "doesnt-exist", "doesnt-exist"), | ||
)) | ||
f.Requirement(fmt.Sprintf("EventPolicy for %s %s is NotReady", kind, name), k8s.IsNotReady(gvr, name)) | ||
|
||
f.Alpha(kind).Must("become NotReady with NotReady EventPolicy ", k8s.IsNotReady(gvr, name)) | ||
|
||
return f | ||
} |
This file was deleted.
Oops, something went wrong.