Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authenticate Requests from ApiServerSources #7452

Merged
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
e2092b0
Add the task planning toughts to the PR
Leo6Leo Nov 15, 2023
2369d50
Merge branch 'main' into authenticate-request-from-apiserversource
Leo6Leo Nov 15, 2023
48c349f
add the auth header to all the send and request to the adapter
Leo6Leo Nov 15, 2023
0e83dbc
Merge branch 'main' into authenticate-request-from-apiserversource
Leo6Leo Nov 17, 2023
e7b38a8
Adding the env var for K_AUDIENCE
Leo6Leo Nov 20, 2023
8efcee8
Adding the rekt test
Leo6Leo Nov 20, 2023
aea806a
Merge the upstream main branch
Leo6Leo Nov 23, 2023
e11c5e9
Adding the rolebinding for create_oidc
Leo6Leo Nov 24, 2023
8b4463c
Adding the rolebinding for create_oidc
Leo6Leo Nov 24, 2023
ef855c8
Update the env variable
Leo6Leo Nov 24, 2023
5c134b3
Revert the automated change to the file
Leo6Leo Nov 24, 2023
4d3caec
Update pkg/adapter/apiserver/delegate.go
Leo6Leo Nov 24, 2023
0cab4e5
Apply suggestions from code review
Leo6Leo Nov 24, 2023
c6a9d54
Merge the upstream main branch
Leo6Leo Nov 29, 2023
7190e7e
Save the working progress - 2
Leo6Leo Dec 4, 2023
8863654
Save the work progress, as everything is working right now. Next, wil…
Leo6Leo Dec 4, 2023
5b9fbc2
Fix the format issue (wrong indentation) the yaml file
Leo6Leo Dec 5, 2023
f49c7fc
Refactored and test passed
Leo6Leo Dec 5, 2023
012dece
Refactored and test passed
Leo6Leo Dec 5, 2023
fb01dde
Remove all the logs
Leo6Leo Dec 5, 2023
08780d4
Go imports
Leo6Leo Dec 5, 2023
31756fd
Merge branch 'main' into authenticate-request-from-apiserversource
Leo6Leo Dec 5, 2023
72735a3
revert the wrong format change during the merging
Leo6Leo Dec 5, 2023
8bfb205
Self sanity check before requesting review
Leo6Leo Dec 5, 2023
d125209
Fix the failed unit test
Leo6Leo Dec 5, 2023
34f0f2c
Merge branch 'main' into authenticate-request-from-apiserversource
Leo6Leo Dec 5, 2023
55e5c30
Fix the review comments
Leo6Leo Dec 5, 2023
a3c9ca8
Update test/auth/features/oidc/apiserversource.go
Leo6Leo Dec 5, 2023
a924341
Apply suggestions from code review
Leo6Leo Dec 5, 2023
751deaa
Fix the nit error
Leo6Leo Dec 5, 2023
37e41a8
Move the MakeOIDCRoleBinding() and MakeOIDCRole() to a separate file
Leo6Leo Dec 5, 2023
6861c83
Handle the role and rolebinding update
Leo6Leo Dec 6, 2023
610ba92
Merge branch 'main' into authenticate-request-from-apiserversource
Leo6Leo Dec 6, 2023
af5e3c0
Fix the typo
Leo6Leo Dec 6, 2023
dcc0dd0
Update pkg/adapter/v2/cloudevents.go
Leo6Leo Dec 6, 2023
8474dbe
Update pkg/adapter/v2/cloudevents.go
Leo6Leo Dec 6, 2023
be9f52d
Update pkg/adapter/v2/config.go
Leo6Leo Dec 6, 2023
12cbf55
Update pkg/reconciler/apiserversource/resources/oidc_rolebinding.go
Leo6Leo Dec 6, 2023
43dbcfb
Update pkg/reconciler/apiserversource/resources/receive_adapter.go
Leo6Leo Dec 6, 2023
2e3191c
Update pkg/adapter/v2/config.go
Leo6Leo Dec 6, 2023
d8a8b53
Update pkg/adapter/v2/config.go
Leo6Leo Dec 6, 2023
a746850
Update pkg/reconciler/apiserversource/resources/oidc_rolebinding.go
Leo6Leo Dec 6, 2023
0630d3a
Fix the majority of the review comments except for the role lister.
Leo6Leo Dec 6, 2023
8961e96
Fix the majority of the review comments except for the role lister.
Leo6Leo Dec 7, 2023
6821cd0
Gofmt and goimports
Leo6Leo Dec 7, 2023
7b87e70
Update the injection dependency
Leo6Leo Dec 7, 2023
4a68425
Use roleLister and roleBindingLister
Leo6Leo Dec 7, 2023
13cc267
Apply suggestions from code review
Leo6Leo Dec 11, 2023
36e70be
Update the nit function name change
Leo6Leo Dec 11, 2023
277af48
Fix the failed unit test by adding the OIDC component, and add the ne…
Leo6Leo Dec 11, 2023
c1248ea
Pass in the fake kubeclinet to apiserversource
Leo6Leo Dec 11, 2023
da14390
Apply suggestions from code review
Leo6Leo Dec 11, 2023
3f0265d
nit fix
Leo6Leo Dec 11, 2023
d599e64
nit fix
Leo6Leo Dec 11, 2023
d0b400e
Fix the failed unit test: no audience is passed in
Leo6Leo Dec 11, 2023
f67e906
nit: boilerplate format
Leo6Leo Dec 11, 2023
a9ec39e
Merge branch 'main' into authenticate-request-from-apiserversource
Leo6Leo Dec 11, 2023
bf4c727
Change the comment and re-order the code according to the review comment
Leo6Leo Dec 12, 2023
81b54c4
Merge the main branch and resolve the merge conflict
Leo6Leo Dec 12, 2023
479aa7f
Change to use the filtered informer, and add the informer eventhandle…
Leo6Leo Dec 13, 2023
35c43b6
Change to use the filtered informer, and add the informer eventhandle…
Leo6Leo Dec 13, 2023
757880e
Merge branch 'main' into authenticate-request-from-apiserversource
Leo6Leo Dec 14, 2023
c8254e5
Inject the oidcSelector in the main.go
Leo6Leo Dec 14, 2023
30b7d22
Add the owner reference to the role and rolebinding
Leo6Leo Dec 14, 2023
72b37ed
Update the tests
Leo6Leo Dec 14, 2023
55c1724
Update the tests
Leo6Leo Dec 15, 2023
0d053b3
nit fix
Leo6Leo Dec 15, 2023
c082ede
register the selectors
Leo6Leo Dec 15, 2023
62fe570
nit: fix the go imports
Leo6Leo Dec 15, 2023
a8de8b8
Merge branch 'main' into authenticate-request-from-apiserversource
Leo6Leo Dec 18, 2023
f8b4795
nit: renaming the variables and only filter on the labelKey (e.g. by …
Leo6Leo Dec 18, 2023
a73a26b
nit: renaming the variables and only filter on the labelKey (e.g. by …
Leo6Leo Dec 18, 2023
8890c5d
nit: fix the naming and add - to the create-oidc-token
Leo6Leo Dec 18, 2023
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: 4 additions & 2 deletions SECURITY.md
Leo6Leo marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Knative Security Policy

We're extremely grateful for security researchers and users that report vulnerabilities to the Knative Open Source Community. All reports are thoroughly investigated by a set of community volunteers.
We're extremely grateful for security researchers and users that report vulnerabilities to the Knative Open Source
Community. All reports are thoroughly investigated by a set of community volunteers.

To make a report, please email the private security@knative.team list with the security details and the details expected for all Knative bug reports.
To make a report, please email the private security@knative.team list with the security details and the details expected
for all Knative bug reports.

See [Knative Security and Disclosure Information](https://knative.dev/docs/reference/security/) for more details.
27 changes: 26 additions & 1 deletion pkg/adapter/apiserver/delegate.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check failure on line 1 in pkg/adapter/apiserver/delegate.go

View workflow job for this annotation

GitHub Actions / style / Golang / Auto-format and Check

Please run goimports. diff --git a/pkg/adapter/apiserver/delegate.go b/pkg/adapter/apiserver/delegate.go index f1f595e..2d48c21 100644 --- a/pkg/adapter/apiserver/delegate.go +++ b/pkg/adapter/apiserver/delegate.go @@ -18,6 +18,7 @@ package apiserver import ( "context" + cloudevents "github.com/cloudevents/sdk-go/v2" "github.com/google/uuid" "go.uber.org/zap"
Copyright 2020 The Knative Authors

Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -18,7 +18,6 @@

import (
"context"
Leo6Leo marked this conversation as resolved.
Show resolved Hide resolved

cloudevents "github.com/cloudevents/sdk-go/v2"
"github.com/google/uuid"
"go.uber.org/zap"
Expand Down Expand Up @@ -75,6 +74,32 @@
subject := event.Context.GetSubject()
a.logger.Debugf("sending cloudevent id: %s, source: %s, subject: %s", event.ID(), source, subject)

// Decide whether to request the JWT token or not
// Condition: if the sink has audience or not
// ?? Question: where can we get the sink audience? As we don't specify the destination in the cloudevent

// If the sink has audience, then we need to request the JWT token
// In order to request the JWT token, we need to get the service account name and namespace from the sink
Leo6Leo marked this conversation as resolved.
Show resolved Hide resolved
// And also need to pass in OIDC token provider
// ?? Question again: where can we get the sink audience? And how to pass in OIDC token provider?

// If the sink doesn't have audience, then we don't need to request the JWT token

// If the sink has audience, and we have the JWT token, then we need to add the JWT token to the cloudevent
// Easy to do this, just add the JWT token as the bearer auth header to the cloudevent header

// Discovery:
// ReceiveAdapter -> ResourceDelegate -> MakeAddEvent -> MakeEvent -> MakeCloudEvent -> SendCloudEvent
// Receive adapter is the entry point of the adapter, it receives the k8s api event
// ResourceDelegate is the cache.Store, it receives the k8s api event from the receive adapter

//ApiServerSource will listen to the k8s api event, and then send the cloudevent to the sink when the k8s api event is created, updated or deleted

// Prepare the headers
//headers := http.HeaderFrom(ctx)
//jwt := auth.GetJWT(ctx)
//headers.Set("Authentication", fmt.Print("Bearer %s", jwt))

if result := a.ce.Send(ctx, event); !cloudevents.IsACK(result) {
a.logger.Errorw("failed to send cloudevent", zap.Error(result), zap.String("source", source),
zap.String("subject", subject), zap.String("id", event.ID()))
Expand Down
41 changes: 41 additions & 0 deletions pkg/adapter/v2/cloudevents.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check failure on line 1 in pkg/adapter/v2/cloudevents.go

View workflow job for this annotation

GitHub Actions / style / Golang / Auto-format and Check

Please run goimports. diff --git a/pkg/adapter/v2/cloudevents.go b/pkg/adapter/v2/cloudevents.go index 2e43c17..3e81603 100644 --- a/pkg/adapter/v2/cloudevents.go +++ b/pkg/adapter/v2/cloudevents.go @@ -20,12 +20,13 @@ import ( "context" "errors" "fmt" - "k8s.io/apimachinery/pkg/types" - "knative.dev/eventing/pkg/auth" nethttp "net/http" "net/url" "time" + "k8s.io/apimachinery/pkg/types" + "knative.dev/eventing/pkg/auth" + cloudevents "github.com/cloudevents/sdk-go/v2" ceclient "github.com/cloudevents/sdk-go/v2/client" "github.com/cloudevents/sdk-go/v2/event"
Copyright 2020 The Knative Authors

Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -20,6 +20,8 @@
"context"
"errors"
"fmt"
"k8s.io/apimachinery/pkg/types"
Leo6Leo marked this conversation as resolved.
Show resolved Hide resolved
"knative.dev/eventing/pkg/auth"
nethttp "net/http"
"net/url"
"time"
Expand Down Expand Up @@ -105,6 +107,7 @@
}

type ClientConfig struct {
Context context.Context
Leo6Leo marked this conversation as resolved.
Show resolved Hide resolved
Env EnvConfigAccessor
CeOverrides *duckv1.CloudEventOverrides
Reporter source.StatsReporter
Expand Down Expand Up @@ -195,6 +198,8 @@
ceOverrides: ceOverrides,
reporter: cfg.Reporter,
crStatusEventClient: cfg.CrStatusEventClient,
oidcTokenProvider: auth.NewOIDCTokenProvider(cfg.Context),
audience: cfg.Env.GetAudience(),
}, nil
}

Expand All @@ -217,6 +222,10 @@
reporter source.StatsReporter
crStatusEventClient *crstatusevent.CRStatusEventClient
closeIdler closeIdler

oidcTokenProvider *auth.OIDCTokenProvider
audience *string
serviceAccountName types.NamespacedName
}

func (c *client) CloseIdleConnections() {
Expand All @@ -228,6 +237,22 @@
// Send implements client.Send
func (c *client) Send(ctx context.Context, out event.Event) protocol.Result {
c.applyOverrides(&out)

// If the sink has audience, then we need to request the JWT token
if c.audience != nil {
// Request the JWT token for the given service account
jwt, err := c.oidcTokenProvider.GetJWT(c.serviceAccountName, *c.audience)

if err != nil {
return protocol.NewResult("%w", err)
}

// Appending the auth token to the outgoing request
headers := http.HeaderFrom(ctx)
headers.Set("Authentication", fmt.Sprintf("Bearer %s", jwt))
ctx = http.WithCustomHeader(ctx, headers)
}

res := c.ceClient.Send(ctx, out)
c.reportMetrics(ctx, out, res)
return res
Expand All @@ -236,6 +261,22 @@
// Request implements client.Request
func (c *client) Request(ctx context.Context, out event.Event) (*event.Event, protocol.Result) {
c.applyOverrides(&out)

// If the sink has audience, then we need to request the JWT token
if c.audience != nil {
// Request the JWT token for the given service account
jwt, err := c.oidcTokenProvider.GetJWT(c.serviceAccountName, *c.audience)

if err != nil {
return nil, protocol.NewResult("%w", err)
}

// Appending the auth token to the outgoing request
headers := http.HeaderFrom(ctx)
headers.Set("Authentication", fmt.Sprintf("Bearer %s", jwt))
ctx = http.WithCustomHeader(ctx, headers)
}

resp, res := c.ceClient.Request(ctx, out)
c.reportMetrics(ctx, out, res)
return resp, res
Expand Down
10 changes: 10 additions & 0 deletions pkg/adapter/v2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ type EnvConfig struct {
// Sink is the URI messages will be sent.
Sink string `envconfig:"K_SINK"`

// Audience is the audience of the target sink.
Audience *string `envconfig:"K_AUDIENCE"`

// CACerts are the Certification Authority (CA) certificates in PEM format
// according to https://www.rfc-editor.org/rfc/rfc7468.
// +optional
Expand Down Expand Up @@ -113,6 +116,9 @@ type EnvConfigAccessor interface {
// GetCACerts gets the CACerts of the Sink.
GetCACerts() *string

// Get the audience of the target sink.
Leo6Leo marked this conversation as resolved.
Show resolved Hide resolved
GetAudience() *string

// Get the namespace of the adapter.
GetNamespace() string

Expand Down Expand Up @@ -176,6 +182,10 @@ func (e *EnvConfig) GetCACerts() *string {
return e.CACerts
}

func (e *EnvConfig) GetAudience() *string {
return e.Audience
}

func (e *EnvConfig) GetNamespace() string {
return e.Namespace
}
Expand Down
1 change: 1 addition & 0 deletions pkg/adapter/v2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ func MainWithInformers(ctx context.Context, component string, env EnvConfigAcces
}

clientConfig := ClientConfig{
Context: ctx,
Env: env,
Reporter: reporter,
CrStatusEventClient: crStatusEventClient,
Expand Down
100 changes: 100 additions & 0 deletions pkg/auth/serviceaccount.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check failure on line 1 in pkg/auth/serviceaccount.go

View workflow job for this annotation

GitHub Actions / style / Golang / Auto-format and Check

Please run goimports. diff --git a/pkg/auth/serviceaccount.go b/pkg/auth/serviceaccount.go index 4c81189..37f37fd 100644 --- a/pkg/auth/serviceaccount.go +++ b/pkg/auth/serviceaccount.go @@ -19,9 +19,10 @@ package auth import ( "context" "fmt" - rbacv1 "k8s.io/api/rbac/v1" "strings" + rbacv1 "k8s.io/api/rbac/v1" + "go.uber.org/zap" v1 "k8s.io/api/core/v1" apierrs "k8s.io/apimachinery/pkg/api/errors"
Copyright 2023 The Knative Authors

Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -19,6 +19,7 @@
import (
"context"
"fmt"
rbacv1 "k8s.io/api/rbac/v1"
"strings"

"go.uber.org/zap"
Expand Down Expand Up @@ -94,3 +95,102 @@

return nil
}

// EnsureOIDCServiceAccountRoleBindingExistsForResource
// makes sure the given resource has an OIDC service account role binding with
// an owner reference to the resource set.
func EnsureOIDCServiceAccountRoleBindingExistsForResource(ctx context.Context, kubeclient kubernetes.Interface, gvk schema.GroupVersionKind, objectMeta metav1.ObjectMeta) error {
roleName := fmt.Sprintf("create-oidc-token")

Check failure on line 103 in pkg/auth/serviceaccount.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

S1039: unnecessary use of fmt.Sprintf (gosimple)
roleBindingName := fmt.Sprintf("create-oidc-token", objectMeta.GetName())

Check failure on line 104 in pkg/auth/serviceaccount.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

printf: fmt.Sprintf call has arguments but no formatting directives (govet)

Check failure on line 104 in pkg/auth/serviceaccount.go

View workflow job for this annotation

GitHub Actions / test / Unit Tests

fmt.Sprintf call has arguments but no formatting directives
roleBinding, err := kubeclient.RbacV1().RoleBindings(objectMeta.Namespace).Get(ctx, roleBindingName, metav1.GetOptions{})

// If the resource doesn't exist, we'll create it.
if apierrs.IsNotFound(err) {
logging.FromContext(ctx).Debugw("Creating OIDC service account role binding", zap.Error(err))

// Create the "create-oidc-token" role
CreateRoleForServiceAccount(ctx, kubeclient, gvk, objectMeta)

roleBinding := &rbacv1.RoleBinding{
ObjectMeta: metav1.ObjectMeta{
Name: roleBindingName,
Namespace: objectMeta.GetNamespace(),
Annotations: map[string]string{
"description": fmt.Sprintf("Role Binding for OIDC Authentication for %s %q", gvk.GroupKind().Kind, objectMeta.Name),
},
},
RoleRef: rbacv1.RoleRef{
APIGroup: "rbac.authorization.k8s.io",
Kind: "Role",
Name: roleName,
},
Subjects: []rbacv1.Subject{
{
Kind: "ServiceAccount",
Namespace: objectMeta.GetNamespace(),
Name: GetOIDCServiceAccountNameForResource(gvk, objectMeta),
},
},
}
creydr marked this conversation as resolved.
Show resolved Hide resolved

_, err = kubeclient.RbacV1().RoleBindings(objectMeta.Namespace).Create(ctx, roleBinding, metav1.CreateOptions{})
if err != nil {
return fmt.Errorf("could not create OIDC service account role binding %s/%s for %s: %w", objectMeta.Name, objectMeta.Namespace, gvk.Kind, err)
}

return nil
}

if err != nil {
return fmt.Errorf("could not get OIDC service account role binding %s/%s for %s: %w", objectMeta.Name, objectMeta.Namespace, gvk.Kind, err)

}

if !metav1.IsControlledBy(&roleBinding.ObjectMeta, &objectMeta) {
return fmt.Errorf("role binding %s not owned by %s %s", roleBinding.Name, gvk.Kind, objectMeta.Name)
}

return nil
}

// Create the create-oidc-token role for the service account
func CreateRoleForServiceAccount(ctx context.Context, kubeclient kubernetes.Interface, gvk schema.GroupVersionKind, objectMeta metav1.ObjectMeta) error {
roleName := fmt.Sprintf("create-oidc-token")

Check failure on line 158 in pkg/auth/serviceaccount.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

S1039: unnecessary use of fmt.Sprintf (gosimple)
role, err := kubeclient.RbacV1().Roles(objectMeta.Namespace).Get(ctx, roleName, metav1.GetOptions{})

// If the resource doesn't exist, we'll create it.
if apierrs.IsNotFound(err) && role == nil {
logging.FromContext(ctx).Debugw("Creating OIDC service account role", zap.Error(err))

role := &rbacv1.Role{
ObjectMeta: metav1.ObjectMeta{
Name: roleName,
Namespace: objectMeta.GetNamespace(),
Annotations: map[string]string{
"description": fmt.Sprintf("Role for OIDC Authentication for %s %q", gvk.GroupKind().Kind, objectMeta.Name),
},
},
Rules: []rbacv1.PolicyRule{
rbacv1.PolicyRule{
APIGroups: []string{""},
ResourceNames: []string{objectMeta.Name},
Resources: []string{"serviceaccounts/token"},
Verbs: []string{"create"},
},
},
}

_, err = kubeclient.RbacV1().Roles(objectMeta.Namespace).Create(ctx, role, metav1.CreateOptions{})
if err != nil {
return fmt.Errorf("could not create OIDC service account role %s/%s for %s: %w", objectMeta.Name, objectMeta.Namespace, gvk.Kind, err)
}

return nil
}

if err != nil {
return fmt.Errorf("could not get OIDC service account role %s/%s for %s: %w", objectMeta.Name, objectMeta.Namespace, gvk.Kind, err)

}
return nil
}
1 change: 1 addition & 0 deletions pkg/kncloudevents/event_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ func (d *Dispatcher) createRequest(ctx context.Context, message binding.Message,
request.Header[key] = val
}

// saw something interesting here, it is similar to what we want to do in this PR
if oidcServiceAccount != nil {
if target.Audience != nil && *target.Audience != "" {
jwt, err := d.oidcTokenProvider.GetJWT(*oidcServiceAccount, *target.Audience)
Expand Down
17 changes: 17 additions & 0 deletions pkg/reconciler/apiserversource/apiserversource.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,20 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, source *v1.ApiServerSour
ServiceAccountName: &saName,
}

// set the role for the service account

if err := auth.EnsureOIDCServiceAccountExistsForResource(ctx, r.serviceAccountLister, r.kubeClientSet, v1.SchemeGroupVersion.WithKind("ApiServerSource"), source.ObjectMeta); err != nil {
source.Status.MarkOIDCIdentityCreatedFailed("Unable to resolve service account for OIDC authentication", "%v", err)
return err
}
source.Status.MarkOIDCIdentityCreatedSucceeded()

// TODO: add the role binding
if err := auth.EnsureOIDCServiceAccountRoleBindingExistsForResource(ctx, r.kubeClientSet, v1.SchemeGroupVersion.WithKind("ApiServerSource"), source.ObjectMeta); err != nil {
source.Status.MarkOIDCIdentityCreatedFailed("Unable to resolve role binding for OIDC authentication", "%v", err)
return err
}

} else {
source.Status.Auth = nil
source.Status.MarkOIDCIdentityCreatedSucceededWithReason(fmt.Sprintf("%s feature disabled", feature.OIDCAuthentication), "")
Expand Down Expand Up @@ -204,12 +213,18 @@ func (r *Reconciler) createReceiveAdapter(ctx context.Context, src *v1.ApiServer
// return nil, err
// }

fmt.Printf("haha sinkAddr: %v\n", sinkAddr)
fmt.Printf("haha sinkAddr.URL: %v\n", sinkAddr.URL)
fmt.Printf("haha sinkAddr.URL.String(): %v\n", sinkAddr.URL.String())
fmt.Printf("haha sinkAddr.audience: %v\n", sinkAddr.Audience)

adapterArgs := resources.ReceiveAdapterArgs{
Image: r.receiveAdapterImage,
Source: src,
Labels: resources.Labels(src.Name),
CACerts: sinkAddr.CACerts,
SinkURI: sinkAddr.URL.String(),
Audience: sinkAddr.Audience,
Configs: r.configs,
Namespaces: namespaces,
AllNamespaces: allNamespaces,
Expand Down Expand Up @@ -348,3 +363,5 @@ func (r *Reconciler) createCloudEventAttributes(src *v1.ApiServerSource) ([]duck
}
return ceAttributes, nil
}

// TODO: adding the rolebinding function to the resource folder and the role to the auth folder
17 changes: 16 additions & 1 deletion pkg/reconciler/apiserversource/resources/receive_adapter.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check failure on line 1 in pkg/reconciler/apiserversource/resources/receive_adapter.go

View workflow job for this annotation

GitHub Actions / style / Golang / Auto-format and Check

Please run goimports. diff --git a/pkg/reconciler/apiserversource/resources/receive_adapter.go b/pkg/reconciler/apiserversource/resources/receive_adapter.go index 2c48292..edc8f81 100644 --- a/pkg/reconciler/apiserversource/resources/receive_adapter.go +++ b/pkg/reconciler/apiserversource/resources/receive_adapter.go @@ -19,6 +19,7 @@ package resources import ( "encoding/json" "fmt" + "knative.dev/eventing/pkg/adapter/v2" appsv1 "k8s.io/api/apps/v1"
Copyright 2020 The Knative Authors

Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -19,7 +19,6 @@
import (
"encoding/json"
"fmt"

"knative.dev/eventing/pkg/adapter/v2"

appsv1 "k8s.io/api/apps/v1"
Expand All @@ -44,6 +43,7 @@
Image string
Source *v1.ApiServerSource
Labels map[string]string
Audience *string
SinkURI string
CACerts *string
Configs reconcilersource.ConfigAccessor
Expand Down Expand Up @@ -120,6 +120,7 @@
}

func makeEnv(args *ReceiveAdapterArgs) ([]corev1.EnvVar, error) {
fmt.Printf("haha geting started make Env")
cfg := &apiserver.Config{
Namespaces: args.Namespaces,
Resources: make([]apiserver.ResourceWatch, 0, len(args.Source.Spec.Resources)),
Expand Down Expand Up @@ -181,6 +182,20 @@
})
}

fmt.Printf("haha receive_adapter: trying to add the k_audience env var\n")
if args.Audience != nil {
fmt.Printf("haha receive_adapter: adding the k_audience env var\n")
envs = append(envs, corev1.EnvVar{
Name: "K_AUDIENCE",
creydr marked this conversation as resolved.
Show resolved Hide resolved
Value: *args.Audience,
})
} else {
envs = append(envs, corev1.EnvVar{
Name: "K_AUDIENCE",
Value: "0000",
})
}

envs = append(envs, args.Configs.ToEnvVars()...)

if args.Source.Spec.CloudEventOverrides != nil {
Expand Down
Loading
Loading