Skip to content

Import Gitlab projects as DefectDojo products fix Issue #1984 - #2211

Merged
valentijnscholten merged 36 commits into
DefectDojo:devfrom
christophe226:patch-1
Jan 13, 2021
Merged

valentijnscholten merged 36 commits into
DefectDojo:devfrom
christophe226:patch-1

Conversation

@christophe226

@christophe226 christophe226 commented Apr 17, 2020 •

Copy link
Copy Markdown
Contributor

This PR resolves issue #1984 (now closed), here is the original description :

It is now possible to use Gitlab for authentication. It would be great to use it for allowing a user to find on DefectDojo a list of products matching his list of Gitlab projects, so that reports imported into DefectDojo can be related to the right product.

As a user, when I log with Gitlab, I would like :

To find my Gitlab projects as DefectDojo products (products being created automatically)
Have the same visibility on DefectDojo products as on Gitlab projects, i.e.:
If I am authorized to see a Gitlab project, I see the matching DefectDojo product
If I am not authorized anymore to see a Gitlab project, I do not see the matching DefectDojo product

@christophe226

christophe226 commented Apr 17, 2020 •

Copy link
Copy Markdown
Contributor Author

Documented in Documentation PR 86

@christophe226
christophe226 marked this pull request as ready for review April 17, 2020 16:31
@valentijnscholten

Copy link
Copy Markdown
Member

Thank you for contributing. Is your setup in such a way that there is a 1-1 mapping between gitlab repositories and defect dojo products? I have a lot of products that have multiple git repositories. For examples a backend repo + front-end repo and sometimes a separate repo with cms plugins etc. So it makes me think that how I could map that onto gitlab, because I like the idea of having some kind of integration there including permissions. Maybe in the future we could add an option to map gitlab groups onto defect dojo products and repositories onto engagements?

For now it would be good to have something added as unit test or integration tests. For example, will the UI, metrics etc still work if there are products that have no product type?

@christophe226

Copy link
Copy Markdown
Contributor Author

Thank you for contributing. Is your setup in such a way that there is a 1-1 mapping between gitlab repositories and defect dojo products? I have a lot of products that have multiple git repositories. For examples a backend repo + front-end repo and sometimes a separate repo with cms plugins etc. So it makes me think that how I could map that onto gitlab, because I like the idea of having some kind of integration there including permissions. Maybe in the future we could add an option to map gitlab groups onto defect dojo products and repositories onto engagements?

For now it would be good to have something added as unit test or integration tests. For example, will the UI, metrics etc still work if there are products that have no product type?

Thanks for your feedback. Now I specify a product type to avoid the ambiguous case where products had no product type.

Regarding mapping between Gitlab repositories and Defect Dojo products, I agree that it could be a good thing in the future to manage more complicated cases than the current 1-1 mapping.

@madchap

madchap commented Apr 25, 2020

Copy link
Copy Markdown
Contributor

Links to #1984

@bgoareguer bgoareguer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The python-gitlab dependency needs to be added to requirements.txt

@christophe226

Copy link
Copy Markdown
Contributor Author

Python 3.6 or more recent is necessary for the current PR. This is linked with a python-gitlab version issue: in requirements.txt, when I specify an old version of python-gitlab (like 1.15), Snyk tests fail. When I specify the 2.2.0 (or any 2.x) version for python-gitlab, Travis CI build fails, very probably because python-gitlab 2.x need Python 3.6+.
PR #2178 has been reverted, so it seems that no integration of Python 3.6+ is planned for any future release. What is the best way to encourage this Python version update ?

@valentijnscholten

Copy link
Copy Markdown
Member

Can you include the python update here in this PR so we can see what Travis thinks? I think travis was doing fine with 3.6 until we added specific sha256 docker image hashes. If you update the Dockerfile(s) likein 2178 we can give it another try and you can check your (this) PR against it.

@christophe226

Copy link
Copy Markdown
Contributor Author

@valentijnscholten Is there a way to help this PR to be reviewed ?

@madchap
madchap requested a review from a team July 21, 2020 14:47
@christophe226

Copy link
Copy Markdown
Contributor Author

In my gitlab instance I have access to over 200 repositories. So on each login, there will be over 200 database queries to find those repos/products in defect dojo. So what I meant is instead of Product.objects.get_or_create(name=project_name, prod_type=product_type) use something like Product.objects.filter(prod_type=product_type) to retrieve them all at once. And then have a loop in python to add/remove any permissions if needed.

I agree, and this is what we do now in pipeline.py, don't we ?

@valentijnscholten

valentijnscholten commented Dec 17, 2020 •

Copy link
Copy Markdown
Member

Not that I can see. You are retrieving products 1 by 1 in a for loop.

@christophe226

Copy link
Copy Markdown
Contributor Author

@valentijnscholten On which line of pipeline.py do you see this issue ? Maybe we don't see the same version, but according to what I see, only lines 84 and 90 call get or get_or_create on Products. Those lines are not executed at each login, but only when you have a new project or you lose an old project.

@valentijnscholten

Copy link
Copy Markdown
Member

Oops, didn't realize that query was at the top. One thing though, users can also be authorized on the product type level, so that query should be extended a little to include products for which the user is authorized that way.

@christophe226

Copy link
Copy Markdown
Contributor Author

Oops, didn't realize that query was at the top. One thing though, users can also be authorized on the product type level, so that query should be extended a little to include products for which the user is authorized that way.

OK, thanks for the suggestion, I think we now include such products

@christophe226

Copy link
Copy Markdown
Contributor Author

Hello @valentijnscholten, after you closed/reopened the issue, one integration test failed (I don't know why), but know it's OK, all checks have passed. Only 1 review is missing

@christophe226

Copy link
Copy Markdown
Contributor Author

Hello @madchap, only 1 review is missing for the current PR. If you can help validating this PR, thanks in advance

@valentijnscholten

Copy link
Copy Markdown
Member

I think it will help if you describe what the PR does and why this feature is needed, what usecase it is providing/solving.

@christophe226

Copy link
Copy Markdown
Contributor Author

I think it will help if you describe what the PR does and why this feature is needed, what usecase it is providing/solving.

Actually, this PR resolves issue #1984 (now closed), here is the original description :

It is now possible to use Gitlab for authentication. It would be great to use it for allowing a user to find on DefectDojo a list of products matching his list of Gitlab projects, so that reports imported into DefectDojo can be related to the right product.

As a user, when I log with Gitlab, I would like :

To find my Gitlab projects as DefectDojo products (products being created automatically)
Have the same visibility on DefectDojo products as on Gitlab projects, i.e.:
If I am authorized to see a Gitlab project, I see the matching DefectDojo product
If I am not authorized anymore to see a Gitlab project, I do not see the matching DefectDojo product

@valentijnscholten

Copy link
Copy Markdown
Member

Please update the PR description.

@valentijnscholten

Copy link
Copy Markdown
Member

Please update the PR description.

I see it already is updated. I removed the template/checklist stuff to make it more clear. And I have asked for reviewers on Slack. Are you on Slack?

@christophe226

Copy link
Copy Markdown
Contributor Author

Please update the PR description.

I see it already is updated. I removed the template/checklist stuff to make it more clear. And I have asked for reviewers on Slack. Are you on Slack?

Thanks. I just created an account on Slack

Comment thread requirements.txt Outdated
Python-jose==3.2.0
gitpython>=2.1.13
ptvsd==4.3.2
ptvsd>=4.3.2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you fix a version ? not fixing version will break something in the futur

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

dependabot should keep us up to date.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree dependabot is a more reliable system. it test only one upgrade and create the PR

@madchap
madchap self-requested a review January 8, 2021 17:29
@mtesauro

Copy link
Copy Markdown
Contributor

I don't have a Gitlab to test this against so I'll defer to @madchap or @damiencarol as they've commented on this already so I'm assuming they are in a better place to eval this than me.

@damiencarol damiencarol left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We will need to fix the requirement ptvsd>=4.3.2 to a fixed version

@valentijnscholten
valentijnscholten merged commit a62349e into DefectDojo:dev Jan 13, 2021
@madchap madchap mentioned this pull request Jan 19, 2021
9alexx3 pushed a commit to 9alexx3/django-DefectDojo that referenced this pull request Aug 12, 2026
… (DefectDojo#2211)

* Update pipeline.py to fix Issue DefectDojo#1984

* Param to enable Gitlab project import as product

* Useless import

* create and assign a product type to our product

* add python-gitlab requirement

* fix python-gitlab version

* update to python 3.6

* update to python 3.6

* add update_product_access in social auth pipeline

* social auth pipeline: add update_product_access

* add comments in pipeline.py

* add comment in modify_permissions

* Update python-gitlab version to 2.4.0

* Update pipeline.py

Add add_test permission

* add missing whitespace after ,

* change comment

* Update pipeline.py

* Update pipeline.py

* Update pipeline.py

* Add products with correct product type

* Add white space

* Modify comment

* Fix ptvsd version

Co-authored-by: Cody Maffucci <46459665+Maffooch@users.noreply.github.com>
Co-authored-by: valentijnscholten <valentijnscholten@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants