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

mt-broker ingress: Reject unauthorized requests #8105

Merged
merged 3 commits into from
Jul 23, 2024

Conversation

joyxxi
Copy link
Contributor

@joyxxi joyxxi commented Jul 18, 2024

Fixes #7980

Proposed Changes

  • Replace the logic of deprecated function VerifyJWTFromRequest with VerifyRequest in ingress_handler
  • Handle both AuthN and AuthZ in the request
  • Check broker.Status.Address.audience before proceeding verification

Pre-review Checklist

  • At least 80% unit test coverage
  • E2E tests for any new behavior
  • Docs PR for any user-facing impact
  • Spec PR for any new API feature
  • Conformance test for any change to the spec

Release Note


Docs

@knative-prow knative-prow bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 18, 2024
Copy link

linux-foundation-easycla bot commented Jul 18, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link

knative-prow bot commented Jul 18, 2024

Welcome @joyxxi! It looks like this is your first PR to knative/eventing 🎉

@knative-prow knative-prow bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 18, 2024
Copy link

knative-prow bot commented Jul 18, 2024

Hi @joyxxi. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@knative-prow knative-prow bot requested review from aslom and Leo6Leo July 18, 2024 19:12
@joyxxi
Copy link
Contributor Author

joyxxi commented Jul 18, 2024

@Cali0707 Hi Calum, the unit tests start to fail from “valid (happy path POST)“, and here is the error message:

=== RUN   TestHandler_ServeHTTP/valid_(happy_path_POST)
    /Users/nanwang/go/src/knative.dev/eventing/pkg/broker/ingress/logger.go:146: 2024-07-17T19:00:58.411-0700 ERRORauth/token_verifier.go:68       could not initialize provider. You can ignore this message, when the authentication-oidc feature is disabled{error 26 0  could not load Kubernetes OIDC discovery information: could not get response: Get "https://kubernetes.default.svc/.well-known/openid-configuration": EOF}        {"component": "oidc-token-handler"}
--- FAIL: TestHandler_ServeHTTP/valid_(happy_path_POST) (0.16s)
--- FAIL: TestHandler_ServeHTTP (1.08s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x18 pc=0x105ce8298]

goroutine 40 [running]:
testing.tRunner.func1.2({0x106217ae0, 0x10757ec50})
        /usr/local/go/src/testing/testing.go:1631 +0x1c4
testing.tRunner.func1()
        /usr/local/go/src/testing/testing.go:1634 +0x33c
panic({0x106217ae0?, 0x10757ec50?})
        /usr/local/go/src/runtime/panic.go:770 +0x124
knative.dev/eventing/pkg/broker/ingress.(*Handler).ServeHTTP(0x1400027ec80, {0x1065389f0, 0x1400068c600}, 0x14000682b40)
        /Users/nanwang/go/src/knative.dev/eventing/pkg/broker/ingress/ingress_handler.go:234 +0xa08
knative.dev/eventing/pkg/broker/ingress.TestHandler_ServeHTTP.func1(0x1400059e1a0)
        /Users/nanwang/go/src/knative.dev/eventing/pkg/broker/ingress/ingress_handler_test.go:309 +0x56c
testing.tRunner(0x1400059e1a0, 0x1400000ee88)
        /usr/local/go/src/testing/testing.go:1689 +0xec
created by testing.(*T).Run in goroutine 11
        /usr/local/go/src/testing/testing.go:1742 +0x318
FAIL    knative.dev/eventing/pkg/broker/ingress 1.704s

I tried to trace the error, and it occurrs when calling VerifyRequest -> NewOIDCTokenVerifier -> initOIDCProvider -> getKubernetesOIDCDiscovery. I get the CertificateVerificationError when getting the resp, with message: “could not get response: Get \“https://kubernetes.default.svc/.well-known/openid-configuration\“: tls: failed to verify certificate: x509: certificate is valid for *.nextplaysearch.com, nextplaysearch.com, not kubernetes.default.svc”.

In the previous setup, the logic bypassed the verification step because features.IsOIDCAuthentication() returned false, so it never triggered h.tokenVerifier.VerifyJWTFromRequest, allowing the test to pass. When I isolated that function to run the test independently, I encountered the same error related to being unable to initialize the provider and received an invalid memory address error.

I’m currently unsure whether this issue arises from my local environment settings, the configuration in the test file, or if there are other underlying problems. 🤔

@Cali0707 Cali0707 requested review from Cali0707 and removed request for aslom July 18, 2024 20:12
@joyxxi joyxxi marked this pull request as ready for review July 19, 2024 18:16
@knative-prow knative-prow bot requested a review from pierDipi July 19, 2024 18:16
@joyxxi joyxxi changed the title [WIP] mt-broker ingress: Reject unauthorized requests mt-broker ingress: Reject unauthorized requests Jul 19, 2024
@knative-prow knative-prow bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 19, 2024
@Leo6Leo
Copy link
Member

Leo6Leo commented Jul 19, 2024

/ok-to-test

@knative-prow knative-prow bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 19, 2024
Copy link

codecov bot commented Jul 19, 2024

Codecov Report

Attention: Patch coverage is 28.57143% with 5 lines in your changes missing coverage. Please review.

Project coverage is 67.88%. Comparing base (57b52ea) to head (a9a3cb8).
Report is 9 commits behind head on main.

Files Patch % Lines
pkg/broker/ingress/ingress_handler.go 28.57% 3 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8105      +/-   ##
==========================================
+ Coverage   67.80%   67.88%   +0.08%     
==========================================
  Files         367      368       +1     
  Lines       17373    17554     +181     
==========================================
+ Hits        11779    11917     +138     
- Misses       4859     4891      +32     
- Partials      735      746      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@pierDipi pierDipi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @joyxxi left a small comment

Co-authored-by: Pierangelo Di Pilato <pierangelodipilato@gmail.com>
@joyxxi
Copy link
Contributor Author

joyxxi commented Jul 22, 2024

/retest

@pierDipi
Copy link
Member

/test reconciler-tests

Copy link
Member

@pierDipi pierDipi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Jul 23, 2024
Copy link

knative-prow bot commented Jul 23, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: joyxxi, pierDipi

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 23, 2024
@dsimansk
Copy link
Contributor

/easycla

@knative-prow knative-prow bot merged commit c3baeda into knative:main Jul 23, 2024
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mt-broker ingress: Reject unauthorized requests
4 participants