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

Refactor permission system + rename whitelist to allowlist #936

Merged

Conversation

mfocko
Copy link
Member

@mfocko mfocko commented Jan 28, 2021

TODO

  • what about Koji?
    resolution: keeping as is
  • GitLab namespace (they are multi-part, we probably want to support allowlisting redhat, but accepting all nested namespaces, e.g. redhat/rpms)
    • safest would be iteratively stripping subnamespace from right and checking against DB
  • we need to differentiate between users with permissions on GitLab and GitHub
  • Switch on allowlisting for GitLab (turned off right now; all events are processed)
    resolution: turned on for MRs, push and issue comments
  • add migration script for allowlist model
    resolution: done, not pushed, may be merged together with enum for gitlab/github

Differentiating GitLab/GitHub allowed users (with related not done TODOs) will be done in follow-up PR

Changes

  • permissions on pull requests:
    • before:
      write access > ( Packit admins OR allowlisted namespace of repository OR user that triggered event )
    • after:
      Packit admins > ( allowlisted namespace AND ( author of pull request OR write access ) )
  • issue comments:
    • before: allowlisted user OR namespace
    • after: allowlisted namespace AND write permissions of user
  • checking of administrator is moved to allowlist
  • checking of write permissions of user on repository is moved to allowlist
  • renamed whitelist to allowlist

Fixes #920
Fixes #937

@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

@TomasTomecek
Copy link
Member

yes, please let's leave koji as it is now and do this only for the CI PR builds

Copy link
Member

@TomasTomecek TomasTomecek left a comment

Choose a reason for hiding this comment

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

nice, LGTM!

interesting that no tests need an update 🤔

@mfocko
Copy link
Member Author

mfocko commented Jan 28, 2021

nice, LGTM!

interesting that no tests need an update 🤔

removed code is unreachable, it gets denied even sooner 🙃😪

@csomh csomh changed the base branch from master to main January 28, 2021 17:27
@mfocko
Copy link
Member Author

mfocko commented Jan 29, 2021

@TomasTomecek @lachmanfrantisek please check, there is also description of allow/deny changes in last commit

Edit: small correction:

  • Change behaviour on pull requests
    • Priority before:
      write access > Packit admins OR (allowlisted namespace or repository namespace of repository OR user that triggered event)
    • Priotiry Priority now:
      Packit admins > allowlisted namespace AND (author of PR or write access)

@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

@lachmanfrantisek
Copy link
Member

GitLab namespace

BTW, do we differentiate between git-forges? What about GitLab namespace, that matches the name of the GitHub one that is whitelisted...

@mfocko
Copy link
Member Author

mfocko commented Jan 29, 2021

GitLab namespace

BTW, do we differentiate between git-forges? What about GitLab namespace, that matches the name of the GitHub one that is whitelisted...

there's no difference between user and namespace either; which probably makes sense? (even though if we enforce allowing namespace and write/pr author, there's no reason to manipulate with users)


shouldn't be a big problem to fix, since it's only github right now (gitlab and pagure is not checked against database)

Copy link
Member

@lachmanfrantisek lachmanfrantisek 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 making it more straightforward!

Comment on lines -3 to +7
DOCS_URL = "https://packit.dev/packit-as-a-service/"
FAQ_URL = f"{DOCS_URL}#faq"
DOCS_URL = "https://packit.dev/docs"
FAQ_URL = f"{DOCS_URL}/faq"
FAQ_URL_HOW_TO_RETRIGGER = (
f"{DOCS_URL}#how-to-re-trigger-packit-service-actions-in-your-pull-request"
f"{DOCS_URL}/packit-as-a-service/"
"#how-to-re-trigger-packit-service-actions-in-your-pull-request"
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for fixing that!

packit_service/worker/jobs.py Outdated Show resolved Hide resolved
# whitelist checks dont apply to CentOS (Pagure, Gitlab)
if isinstance(
event,
for callback, related_events in (
Copy link
Member

Choose a reason for hiding this comment

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

What about some mapping, this is becoming too magical to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

it is a mapping, without map :D i'll add it

Copy link
Member

Choose a reason for hiding this comment

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

My point was more about readability. Just that it's really clear what is going on here.

@mfocko
Copy link
Member Author

mfocko commented Jan 29, 2021

also I could probably switch the naming of whitelist since I'm probably going to touch the database because of github vs gitlab

@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

@softwarefactory-project-zuul
Copy link
Contributor

Build failed.

Copy link
Member

@lachmanfrantisek lachmanfrantisek left a comment

Choose a reason for hiding this comment

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

Sorry for another group of comments...

packit_service/worker/allowlist.py Outdated Show resolved Hide resolved
)
]

def unchecked_event(
Copy link
Member

Choose a reason for hiding this comment

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

What about some prefix for those methods? Something like validate_unchecked_event, validate_release_push_event,...

for related_events, callback in CALLBACKS.items():
if isinstance(event, related_events):
return callback(event, project, service_config, job_configs)
Copy link
Member

Choose a reason for hiding this comment

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

Personally, I like that approach, but tbh, I am still not sure about the readability of this.

But let's use this and improve later if someone complains...;)

packit_service/worker/jobs.py Outdated Show resolved Hide resolved
@mfocko
Copy link
Member Author

mfocko commented Jan 29, 2021

Sorry for another group of comments...

definitely won't be last one till finish :D

@mfocko mfocko changed the title Disable checking of write permissions on PRs Refactor permission system + rename whitelist to allowlist Jan 29, 2021
@softwarefactory-project-zuul
Copy link
Contributor

Build failed.

@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

Copy link
Member

@lachmanfrantisek lachmanfrantisek left a comment

Choose a reason for hiding this comment

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

Thanks! That was a huge amount of work. 🚀

Disables checking of user's write permissions in the repository that PR
is created against.

Fixes packit#920

Signed-off-by: Matej Focko <mfocko@redhat.com>
Signed-off-by: Matej Focko <mfocko@redhat.com>
Signed-off-by: Matej Focko <mfocko@redhat.com>
- Separate handling of events into methods
- Move check for write access to repository from job processing to allowlisting
- Fix tests
- Change behaviour on pull requests
  - Priority before:
    write access > Packit admins > (allowlisted namespace OR repository)
  - Priority now:
    Packit admins > allowlisted namespace > (author of pr OR write access)

Signed-off-by: Matej Focko <mfocko@redhat.com>
- Add specific types to event callbacks
- Enable checking permissions on GitLab
- Move callbacks to dictionary

Signed-off-by: Matej Focko <mfocko@redhat.com>
Fixes packit#937

Signed-off-by: Matej Focko <mfocko@redhat.com>
@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

@mfocko mfocko added the mergeit When set, zuul wil gate and merge the PR. label Feb 3, 2021
@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded (gate pipeline).

@softwarefactory-project-zuul softwarefactory-project-zuul bot merged commit e59d45d into packit:main Feb 3, 2021
@mfocko mfocko deleted the disable-repo-permissions branch February 12, 2021 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mergeit When set, zuul wil gate and merge the PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rename whitelist to allowlist Don't require /packit build by user with write permissions
3 participants