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

Add owner flag validation during provider enrollment #4107

Merged
merged 1 commit into from
Aug 21, 2024

Conversation

psekar
Copy link
Contributor

@psekar psekar commented Aug 9, 2024

Summary

***Provide a brief overview of the changes and the issue being addressed.
This PR addresses the issue #2723 . When enrolling a provider, the owner flag is not validated. Incase the owner flag is invalid or the token has no access to the owner/organization during provider enrollment, the repo registration will fail which is a later step in the process. The change includes checking for a valid GH organization (passed as owner flag) that matches the owner flag and ensure the token has access to the GH organization.

Explain the rationale and any background necessary for understanding the changes.
List dependencies required by this change, if any.***
I created a type struct to make Git API calls prior to actual provider enrollment flow, also created an interface to be able to mock the tests. The intent of the existing types seems to be useful post provider enrollment so decided to create a new type.

Fixes #(related issue)
#2723

Change Type

Mark the type of change your PR introduces:

  • Bug fix (resolves an issue without affecting existing features)
  • Feature (adds new functionality without breaking changes)
  • Breaking change (may impact existing functionalities or require documentation updates)
  • Documentation (updates or additions to documentation)
  • Refactoring or test improvements (no bug fixes or new functionality)

Testing

Outline how the changes were tested, including steps to reproduce and any relevant configurations.
Attach screenshots if helpful.

👉 Existing tests will validate the valid owner path.
👉 Added the unit tests to validate the invalid owner flag code path.
👉 Provide a valid owner flag (a GH org) and provider enrollment is successful
👉 Provide an invalid owner flag and provider enrollment fails during the oauth flow with clear error message about the owner flag.

Review Checklist:

  • Reviewed my own code for quality and clarity.
  • Added comments to complex or tricky code sections.
  • Updated any affected documentation.
  • Included tests that validate the fix or feature.
  • Checked that related changes are merged.

@psekar psekar requested a review from a team as a code owner August 9, 2024 00:51
@psekar psekar changed the title Add ownerFilter validation during provider create Add owner flag validation during provider creation Aug 9, 2024
@psekar psekar changed the title Add owner flag validation during provider creation Add owner flag validation during provider enrollment Aug 9, 2024
@eleftherias eleftherias self-assigned this Aug 9, 2024
Copy link
Contributor

@eleftherias eleftherias left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @psekar!

This approach looks good to me! I've added a few comments inline with suggestions that will simplify the code.
Feel free to reach out if you have any questions.

@psekar psekar requested a review from eleftherias August 10, 2024 13:29
Copy link
Contributor

@eleftherias eleftherias left a comment

Choose a reason for hiding this comment

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

Thanks for the updates @psekar!

I've added a few follow-up comments.
You can also run make lint before committing to makes sure the code passes the lint rules.

@psekar
Copy link
Contributor Author

psekar commented Aug 13, 2024

Thanks for the updates @psekar!

I've added a few follow-up comments. You can also run make lint before committing to makes sure the code passes the lint rules.

I am still very new to Go and your review has been super useful 🙏

@psekar psekar requested a review from eleftherias August 13, 2024 04:25
@coveralls
Copy link

coveralls commented Aug 13, 2024

Coverage Status

coverage: 53.817% (+0.07%) from 53.752%
when pulling f1c2350 on tinytrail:validate-owner-filter
into 9a3fc94 on stacklok:main.

Copy link
Contributor

@eleftherias eleftherias left a comment

Choose a reason for hiding this comment

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

Thanks for the quick updates again @psekar!

I've left some final comments about cleanup / linting changes.

Copy link
Contributor

@eleftherias eleftherias left a comment

Choose a reason for hiding this comment

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

I also noticed that the mocks need to be updated. You can run make gen in the root directory before committing your code and that will update them.

@psekar psekar force-pushed the validate-owner-filter branch 3 times, most recently from 1a1cc4a to 155261a Compare August 15, 2024 05:10
@psekar
Copy link
Contributor Author

psekar commented Aug 15, 2024

Coverage Status

coverage: 53.872% (-0.03%) from 53.899% when pulling 94472cb on tinytrail:validate-owner-filter into e438848 on stacklok:main.

Will add more test coverage and send it back for review tomorrow.

@psekar psekar force-pushed the validate-owner-filter branch 3 times, most recently from a8a1e9d to 25dbdac Compare August 17, 2024 15:51
@psekar psekar requested a review from eleftherias August 17, 2024 15:52
@psekar
Copy link
Contributor Author

psekar commented Aug 17, 2024

Coverage Status
coverage: 53.872% (-0.03%) from 53.899% when pulling 94472cb on tinytrail:validate-owner-filter into e438848 on stacklok:main.

Will add more test coverage and send it back for review tomorrow.

Fixed the linter issues and added more test coverage now. @eleftherias Appreciate your review 👍

Copy link
Contributor

@eleftherias eleftherias left a comment

Choose a reason for hiding this comment

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

Thank you for your patience on this @psekar!
The cyclomatic complexity of processOAuthCallback is still high, I've proposed a change inline that will fix it. After this change, we should be ready to merge.

@psekar psekar force-pushed the validate-owner-filter branch from 25dbdac to f1c2350 Compare August 21, 2024 04:26
@psekar psekar requested a review from eleftherias August 21, 2024 04:27
Copy link
Contributor

@eleftherias eleftherias left a comment

Choose a reason for hiding this comment

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

Thank you @psekar!

@eleftherias eleftherias merged commit b2a9a00 into mindersec:main Aug 21, 2024
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants