Skip to content

Comments

Introduce Makefile For All Scanners#601

Closed
EndPositive wants to merge 18 commits intosecureCodeBox:mainfrom
EndPositive:makefiles
Closed

Introduce Makefile For All Scanners#601
EndPositive wants to merge 18 commits intosecureCodeBox:mainfrom
EndPositive:makefiles

Conversation

@EndPositive
Copy link
Contributor

@EndPositive EndPositive commented Aug 18, 2021

Description

This PR continues @fuhrmeistery 's work on the scanner Makefiles.

I have moved the Makefile for Amass into the project's root directory. From each scanner, we include the root Makefile and override configuration variables (such as scanner name) or whether a scanner container needs to be built. Each scanner can specify what demo target dependencies it has.

https://github.com/EndPositive/secureCodeBox/blob/eec9b75edb70b347af1e47dcdbc7cb7e14562e2b/scanners/zap/Makefile#L8-L13

Finally, in this manner, we can also completely override the root makefile's behaviour. Zap-advanced's Makefile, for example, redirects the parser-related targets to zap's makefile. Kubeaudit overrides the helm deploy target such that it can set extra helm values.

Checklist

  • Reduce the amount of duplicated code in the makefiles by using 'some sort of inheritence'
  • Adapt Makefile to add make targets for building custom/third party scanners
  • Add unit tests for scanners (detect java/python)
  • Replace CI amass job by Github Matrix / run them one by one in a single job (open for discussion; I believe kind cluster create is pretty expensive in the pipeline and a matrix job might explode that time..; on the other hand matrix would reduce oveall pipeline duration if the pipeline has enough resources)
  • Test your changes as thoroughly as possible before you commit them. Preferably, automate your test by unit/integration tests.
  • Make sure npm test runs for the whole project.
  • Make codeclimate checks happy

…le testing retry libraries

Signed-off-by: Jop Zitman <[email protected]>
…s a dependency of integration-tests (only manually)

Signed-off-by: Jop Zitman <[email protected]>
…able docker push in Makefile builds

Signed-off-by: Jop Zitman <[email protected]>
@EndPositive
Copy link
Contributor Author

EndPositive commented Aug 18, 2021

Extra note of caution: the latest commit ec8c8f6 updates the CI so that all scanners are built with the new Makefiles. It would be really nice if someone could give it a review and trigger a run.

Some more thoughts:

  • I remember that in the previous set-up, the integration tests for some scanners were disabled. Do we want to keep that behavior?
  • In the ZAP advanced makefile, the ZAP parser is automatically built in the docker-build target. In the pipeline, we instead use the docker build push action and detect whether to build the parser/scanner based on the presence of their Dockerfile. Any good ideas to ensure that in the pipeline the ZAP parser is built before the ZAP advanced job starts?

@J12934 J12934 self-requested a review August 19, 2021 07:51
@J12934
Copy link
Member

J12934 commented Aug 19, 2021

Replace CI amass job by Github Matrix / run them one by one in a single job (open for discussion; I believe kind cluster create is pretty expensive in the pipeline and a matrix job might explode that time..; on the other hand matrix would reduce oveall pipeline duration if the pipeline has enough resources)

Yes good point. We've planned to change the pipeline so that it looks for changed files in the relevant folder. So that we would only run the builds for a specific scanner if files for it were changed, or if a central component e.g. operator, lurker, parser-sdk were changed. This should speed this up quite a lot as most pipelines would only run the build and tests for the changed scanner(s).

I remember that in the previous set-up, the integration tests for some scanners were disabled. Do we want to keep that behavior?

I think the only intentionally disabled integration-tests are the ones for the zap-advanced as they were just taking too long to run the scans. That should hopefully also be kinda solved by only running the tests only when the acutal zap-advanced code was changed.

In the ZAP advanced makefile, the ZAP parser is automatically built in the docker-build target. In the pipeline, we instead use the docker build push action and detect whether to build the parser/scanner based on the presence of their Dockerfile. Any good ideas to ensure that in the pipeline the ZAP parser is built before the ZAP advanced job starts?

Ah yes, thats a kind of edge case 🤔 Could we overwrite the build parser make targets in the zap-advanced makefile enought to just build the parser form the zap folder? I think this would be easier than reusing the image build for zap.

Checked the pr out and tried the nmap makefile looks great already 🥳
I think there needs to be a small fix to the parser js test imports, will push these and trigger the ci.

J12934 added 2 commits August 19, 2021 11:43
… docker_meta

Also use the same condition to chcek if the docker-meta action should be run for scanner as is used in the dependend docker build & push action. Both should be run together or not at all.

Signed-off-by: Jannik Hollenbach <[email protected]>
Integrations tests section should hoperfully soon be deleted as they should be handled by the makefiles

Signed-off-by: Jannik Hollenbach <[email protected]>
Comment on lines 364 to 365
if: hashFiles(format('./scanners/{0}/scanner/Dockerfile', matrix.unit)) != ''
uses: crazy-max/ghaction-docker-meta@v1
if: contains(fromJson('["angularjs-csti-scanner", "gitleaks", "kube-hunter", "kubeaudit", "ncrack", "nmap"]'), matrix.unit)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe this manual check was necessary. For example, the git-repo-scanner has its own Dockerfile but is always tagged with the secureCodeBox tag, and not the appVersion (which is 1.0 for git-repo-scanner).

In the old Pipeline, there was a distinction between third-party scanners and custom scanners. Both have a Dockerfile, but third-party scanners follow their own versioning, and custom scanners follow secureCodeBox versioning.

Signed-off-by: Jannik Hollenbach <[email protected]>
@EndPositive
Copy link
Contributor Author

EndPositive commented Aug 19, 2021

Yes good point. We've planned to change the pipeline so that it looks for changed files in the relevant folder. So that we would only run the builds for a specific scanner if files for it were changed, or if a central component e.g. operator, lurker, parser-sdk were changed. This should speed this up quite a lot as most pipelines would only run the build and tests for the changed scanner(s).

That would be awesome. For now, lets keep this PR with a matrix job and once we're fully over to Makefiles, we can do the extra magic.

I think the only intentionally disabled integration-tests are the ones for the zap-advanced as they were just taking too long to run the scans. That should hopefully also be kinda solved by only running the tests only when the acutal zap-advanced code was changed.

You're right that zap-advanced was manually disabled, however I noticed that git-repo-scanner was never included. I can imagine that was due to GitHub rate-limiting?

Ah yes, thats a kind of edge case thinking Could we overwrite the build parser make targets in the zap-advanced makefile enought to just build the parser form the zap folder? I think this would be easier than reusing the image build for zap.

Yep, that's currently what happens in the Makefile for zap-advanced, check it out! However, in the pipeline, we make use of the docker action, skipping the Makefile's build target altogether. For your proposal to work in the pipeline, we would have to get rid of the Docker build action. Do you know if the ubuntu-latest VM runs docker build commands properly? In any case, that would also require the Makefile to also manage the tags and pushes right?

Checked the pr out and tried the nmap makefile looks great already partying_face
I think there needs to be a small fix to the parser js test imports, will push these and trigger the ci.

Great!

J12934 added 2 commits August 19, 2021 13:07
This will need to be more complicated as it should also only push on tagged releases

Signed-off-by: Jannik Hollenbach <[email protected]>
@J12934
Copy link
Member

J12934 commented Aug 19, 2021

You're right that zap-advanced was manually disabled, however I noticed that git-repo-scanner was never included. I can imagine that was due to GitHub rate-limiting?

yeah rate limiting is a problem, also we try to keep the integration test completly offline, that pretty hard to do with the git-repo-scanner. We should "just" be able to disable these tests for now by overwriting the integration-tests make target in the makefiles for these scanners to a empty script, right? As a temporary workaround, running these only when the code was changed should hopefully decrease the number of requests enough to be pretty stable.

Yep, that's currently what happens in the Makefile for zap-advanced, check it out! However, in the pipeline, we make use of the docker action, skipping the Makefile's build target altogether. For your proposal to work in the pipeline, we would have to get rid of the Docker build action. Do you know if the ubuntu-latest VM runs docker build commands properly? In any case, that would also require the Makefile to also manage the tags and pushes right?

Mhh yeah... I'm not sure how easily we can / should migrate from the action, i does a lot of neat stuff in the background. I'll try to see if I can came up with a good solution to this 🤔

@EndPositive
Copy link
Contributor Author

EndPositive commented Aug 26, 2021

I'll try to see if I can came up with a good solution to this 🤔

@J12934 how's that going? I would like to finish the PR.

@J12934
Copy link
Member

J12934 commented Aug 26, 2021

Hi @EndPositive
thanks for the reminder 🙏

I think the best way forward is, to do it like you suggested it by splitting out the "release docker build" to a seperate release pipeline and use the makefile builds in the normal commit / (and future pr) pipeline. Pushed this to a seperate branch just in case: https://github.com/secureCodeBox/secureCodeBox/tree/makefiles-split-pipeline
Looking pretty good already. Release pipeline will probably require a few test / beta releases to get completely right.

Will talk this over with some other team members tomorrow, and will create separate github issues to track and organize the remaining work on this feature.

@EndPositive
Copy link
Contributor Author

@J12934 that sound good 😄.

Some points for your tracker:

  • Migrate unit-tests to Makefiles completely (including CodeClimate support ?)
  • Create Makefiles for hooks
  • Ensure DockerHub descriptions are only updated on release
  • Add Makefiles for Nikto (special case)
  • Optionally add Makefiles for newly introduced scanners (WhatWeb, TYPO3, and Nuclei)
  • Update secureCodeBox documentation related to integration tests and creating new scanners.

Let me know how the team meeting goes 😃

@J12934 J12934 added architecture Architecture changes ci Changes to the continuous integration setup enhancement New feature or request labels Aug 27, 2021
@J12934 J12934 linked an issue Aug 27, 2021 that may be closed by this pull request
16 tasks
@J12934
Copy link
Member

J12934 commented Aug 27, 2021

👋

Talked this over with my coworkers today, they are all exited about the makefiles and their possibilities and were all on board with the proposed changes.
I've opened up the related issues #610 , #611 , #612 , #613 plus we already had makefiles related issues the "old issues" #477 & #478.

Which unit tests are not yet migrated to the makefiles?
Just the zap-advanced & git-repo-scanner python tests?

I'm not sure if there is a good way to integrate code-climate into the makefiles, maybe the underlying linting tools it uses under the hood (like eslint) but I'm not sure how easy that would be to setup correctly (especially for the different languages we have in use)

@EndPositive
Copy link
Contributor Author

Awesome work @J12934 !

Do you guys want to make a release (with the new scanners) before we start messing up main and the pipeline?

Also, let's try to keep the work a bit separated, so contributing becomes easier. Keep this PR only on creating makefiles for scanners (no pipeline changes) and then I'll create another PR for hook makefiles. Maybe you can then look at updating the pipeline, since I'm unable to properly test not being authorized to trigger pipelines.

@EndPositive
Copy link
Contributor Author

Since this PR has gotten too bloated with further pipeline testing, I've decided to completely separate the changes for Makefiles and those for the pipeline. I'll close this PR in favor of #622 and further PR's.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

architecture Architecture changes ci Changes to the continuous integration setup enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Makefile For All Scanners

2 participants