Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
17c775a
#7320 WIP
Zazzscoot Dec 24, 2023
acdba24
added missing address attributes to unit tests
Zazzscoot Dec 24, 2023
36c0f81
added serviceaccoutns/token to pingsource role
Zazzscoot Jan 5, 2024
1518b67
added rule for service accounts (token)
Zazzscoot Jan 8, 2024
709f368
wrote e2e tests for pingsource OIDC
Zazzscoot Jan 8, 2024
16e5faa
removed dynamic role adding
Zazzscoot Jan 8, 2024
4f3c536
removed unnecessary packages
Zazzscoot Jan 8, 2024
c28078e
Merge branch 'knative:main' into main
Zazzscoot Jan 8, 2024
cdbb2b5
Merge branch 'knative:main' into main
Zazzscoot Jan 10, 2024
6531a80
defined tokenprovider, set audience/OIDCServiceAcc
Zazzscoot Jan 10, 2024
6b1c2f8
Merge branch 'main' into main
Zazzscoot Jan 11, 2024
0a5396b
added check for source.Status.Auth
Zazzscoot Jan 11, 2024
3e3cf30
Merge branch 'knative:main' into main
Zazzscoot Jan 12, 2024
7bef2bc
testing for pr
yijie-04 Jan 15, 2024
396bf6c
Merge branch 'knative:main' into main
Zazzscoot Jan 16, 2024
f1d4428
reran runner.go
Zazzscoot Jan 16, 2024
23e898c
added oidc
yijie-04 Jan 16, 2024
f9185dd
removed testing
yijie-04 Jan 16, 2024
00c2a92
added oidc in pingsource test
yijie-04 Jan 16, 2024
c5e26e7
Merge pull request #1 from yijie-04/pingsource_auth_request
Zazzscoot Jan 16, 2024
292ecb6
Merge branch 'knative:main' into main
Zazzscoot Jan 17, 2024
de55635
added audience nil check and specified destination in auth test
Zazzscoot Jan 17, 2024
5e92caa
added duckv1 to imports for test file
Zazzscoot Jan 17, 2024
c687fd6
ran goimports
Zazzscoot Jan 17, 2024
4ac3395
removed dupe ceode from mtping/runner.go
Zazzscoot Jan 17, 2024
1eb1883
ran goimportrs on test/auth/oidc_test.go
Zazzscoot Jan 17, 2024
aa3569e
fixing boilerplate for test/auth/features/oidc/pingsource.go
Zazzscoot Jan 17, 2024
99ed180
removed format.sh
Zazzscoot Jan 17, 2024
5bfe16f
Merge branch 'knative:main' into main
Zazzscoot Jan 18, 2024
9352fa8
removed unnecessary comments
Zazzscoot Jan 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config/core/roles/pingsource-mt-adapter-clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ rules:
- "get"
- "list"
- "watch"
- apiGroups:
- ""
resources:
- "serviceaccounts/token"
verbs:
- "create"
- apiGroups:
- sources.knative.dev
resources:
Expand Down
6 changes: 6 additions & 0 deletions pkg/adapter/mtping/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ func (a *cronJobsRunner) newPingSourceClient(source *sourcesv1.PingSource) (adap
Namespace: source.GetNamespace(),
Name: a.clientConfig.Env.GetName(),
EnvSinkTimeout: fmt.Sprintf("%d", a.clientConfig.Env.GetSinktimeout()),
Audience: source.Status.SinkAudience,
}

if source.Status.Auth != nil {
env.OIDCServiceAccountName = source.Status.Auth.ServiceAccountName
}
}

Expand All @@ -215,6 +220,7 @@ func (a *cronJobsRunner) newPingSourceClient(source *sourcesv1.PingSource) (adap
CrStatusEventClient: a.clientConfig.CrStatusEventClient,
Options: a.clientConfig.Options,
TrustBundleConfigMapLister: a.clientConfig.TrustBundleConfigMapLister,
TokenProvider: a.clientConfig.TokenProvider,
}

return adapter.NewClient(cfg)
Expand Down
22 changes: 18 additions & 4 deletions pkg/reconciler/pingsource/pingsource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ var (
Name: &sinkURL.Scheme,
URL: sinkURL,
}
sinkAudience = "sink-oidc-audience"
sinkOIDCAddressable = &duckv1.Addressable{
Name: &sinkURL.Scheme,
URL: sinkURL,
Audience: &sinkAudience,
}
sinkOIDCDest = duckv1.Destination{
Ref: &duckv1.KReference{
Name: sinkName,
Kind: "Channel",
APIVersion: "messaging.knative.dev/v1",
},
Audience: &sinkAudience,
}
)

const (
Expand Down Expand Up @@ -518,15 +532,15 @@ func TestAllCases(t *testing.T) {
ContentType: testContentType,
Data: testData,
SourceSpec: duckv1.SourceSpec{
Sink: sinkDest,
Sink: sinkOIDCDest,
},
}),
rtv1.WithPingSource(sourceUID),
rtv1.WithPingSourceObjectMetaGeneration(generation),
),
rtv1.NewChannel(sinkName, testNS,
rtv1.WithInitChannelConditions,
rtv1.WithChannelAddress(sinkAddressable),
rtv1.WithChannelAddress(sinkOIDCAddressable),
),
makeAvailableMTAdapter(),
},
Expand All @@ -538,15 +552,15 @@ func TestAllCases(t *testing.T) {
ContentType: testContentType,
Data: testData,
SourceSpec: duckv1.SourceSpec{
Sink: sinkDest,
Sink: sinkOIDCDest,
},
}),
rtv1.WithPingSource(sourceUID),
rtv1.WithPingSourceObjectMetaGeneration(generation),
// Status Update:
rtv1.WithInitPingSourceConditions,
rtv1.WithPingSourceDeployed,
rtv1.WithPingSourceSink(sinkAddressable),
rtv1.WithPingSourceSink(sinkOIDCAddressable),
rtv1.WithPingSourceCloudEventAttributes,
rtv1.WithPingSourceStatusObservedGeneration(generation),
rtv1.WithPingSourceOIDCIdentityCreatedSucceeded(),
Expand Down
51 changes: 51 additions & 0 deletions test/auth/features/oidc/pingsource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright 2021 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 oidc

import (
"github.com/cloudevents/sdk-go/v2/test"
"knative.dev/eventing/test/rekt/resources/pingsource"
duckv1 "knative.dev/pkg/apis/duck/v1"
"knative.dev/reconciler-test/pkg/eventshub"
"knative.dev/reconciler-test/pkg/eventshub/assert"
"knative.dev/reconciler-test/pkg/feature"
"knative.dev/reconciler-test/pkg/resources/service"
)

func PingSourceSendEventWithSinkRefOIDC() *feature.Feature {
source := feature.MakeRandomK8sName("pingsource")
sink := feature.MakeRandomK8sName("sink")
sinkAudience := "audience"
f := feature.NewFeature()

f.Setup("install sink", eventshub.Install(sink,
eventshub.OIDCReceiverAudience(sinkAudience),
eventshub.StartReceiver))

f.Requirement("install pingsource",
pingsource.Install(source, pingsource.WithSink(&duckv1.Destination{
Ref: service.AsKReference(sink),
Audience: &sinkAudience,
})))
f.Requirement("pingsource goes ready", pingsource.IsReady(source))

f.Stable("pingsource as event source").
Must("delivers events",
assert.OnStore(sink).MatchEvent(test.HasType("dev.knative.sources.ping")).AtLeast(1))

return f
}
13 changes: 13 additions & 0 deletions test/auth/oidc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,19 @@ func TestContainerSourceSendsEventsWithOIDCSupport(t *testing.T) {
env.Test(ctx, t, oidc.SendsEventsWithSinkRefOIDC())
}

func TestPingSourceSendsEventsWithOIDC(t *testing.T) {
t.Parallel()

ctx, env := global.Environment(
knative.WithKnativeNamespace(system.Namespace()),
knative.WithLoggingConfig,
knative.WithTracingConfig,
k8s.WithEventListener,
environment.Managed(t),
)

env.Test(ctx, t, oidc.PingSourceSendEventWithSinkRefOIDC())
}
func TestSequenceSendsEventsWithOIDCSupport(t *testing.T) {
t.Parallel()

Expand Down
5 changes: 4 additions & 1 deletion test/rekt/resources/pingsource/pingsource.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ func WithSink(dest *duckv1.Destination) manifest.CfgFn {
// Replace "new line" with "new line + spaces".
sink["CACerts"] = strings.ReplaceAll(*dest.CACerts, "\n", "\n ")
}

if dest.Audience != nil {
sink["audience"] = *dest.Audience
}
if uri != nil {
sink["uri"] = uri.String()
}
Expand All @@ -89,6 +91,7 @@ func WithSink(dest *duckv1.Destination) manifest.CfgFn {
}
sref["name"] = ref.Name
}

}
}

Expand Down
3 changes: 3 additions & 0 deletions test/rekt/resources/pingsource/pingsource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@ spec:
CACerts: |-
{{ .sink.CACerts }}
{{ end }}
{{if .sink.audience }}
audience: {{ .sink.audience}}
{{ end }}
{{ end }}