Thanks to visit codestin.com
Credit goes to github.com

Skip to content

MAINT: Apply security best practices #23131

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

Conversation

step-security-bot
Copy link
Contributor

@step-security-bot step-security-bot commented Jan 30, 2023

Summary

This pull request is created by Secure Workflows at the request of @charris. Please merge the Pull Request to incorporate the requested changes. Please tag @charris on your message if you have any questions related to the PR. You can also engage with the StepSecurity team by tagging @step-security-bot.

Security Fixes

Pinned Dependencies

A pinned dependency is a dependency that is explicitly set to a specific hashed version instead of a mutable version. Pinned dependencis ensure that development and deployment are done with the same software versions which reduces deployment risks, and enables reproducibility. It can help mitigate compromised dependencies from undermining the security of the project in certain scenarios. The dependencies were pinned using Secure WorkFlows

Harden Runner

Harden-Runner is an open-source security agent for the GitHub-hosted runner to prevent software supply chain attacks. It prevents exfiltration of credentials, detects tampering of source code during build, and enables running jobs without sudo access.

Harden runner usage

You can find link to view insights and policy recommendation in the build log

Please refer to documentation to find more details.

Keeping your actions up to date with Dependabot

The package ecosystem to update github-actions is added using Secure WorkFlows. This is recommended by GitHub as well as The Open Source Security Foundation (OpenSSF).

Detect Vulnerabilities with SAST Workflow

Static Code Analysis (also known as Source Code Analysis) is usually performed as part of a Code Review (also known as clear-box testing) and is carried out at the Implementation phase of a Security Development Lifecycle (SDL). Static Code Analysis commonly refers to the running of Static Code Analysis tools that attempt to highlight possible vulnerabilities within ‘static’ (non-running) source code by using techniques such as Taint Analysis and Data Flow Analysis.

Feedback

For bug reports, feature requests, and general feedback; please create an issue in step-security/secure-workflows. To create such PRs, please visit https://app.stepsecurity.io/securerepo.

Signed-off-by: StepSecurity Bot [email protected]

Let's see what StepSecurity does.

Signed-off-by: StepSecurity Bot <[email protected]>
@charris
Copy link
Member

charris commented Jan 30, 2023

We probably want to remove dependabot from this, and maybe CodeQL as well. Not sure what harden-runner does, but I don't have a problem with specifying the hashes if it is best practice.

@charris
Copy link
Member

charris commented Jan 30, 2023

I generated this security PR to see what it did, motivated by the alerts in the security tab.

@varunsh-coder
Copy link

varunsh-coder commented Jan 30, 2023

We probably want to remove dependabot from this, and maybe CodeQL as well. Not sure what harden-runner does, but I don't have a problem with specifying the hashes if it is best practice.

Hi @charris, thanks for using https://github.com/step-security/secure-workflows to create the PR. I am the maintainer for that project.

I am curious why you don't want to add CodeQL and Dependabot. Those changes increase the OpenSSF Scorecard score. Moreover, if dependabot.yml or some other updating mechanism is not used, the pinned hashes for Actions will not get updated (using a dependabot PR) when there is a new version.

w.r.t harden-runner, you can get more details here: https://github.com/step-security/harden-runner

To not add any of the best practices, you can uncheck the issue type before creating the PR at http://app.stepsecurity.io/securerepo. There is also a feature to preview the PR. Thanks!

Also adding @pnacht since I saw they initiated a discussion about Scorecard.

@charris
Copy link
Member

charris commented Jan 30, 2023

@varunsh-coder

We dropped dependabot because is was spamming all the numpy forks. It was a known problem, but it never got fixed AFAICT.

Not sure about CodeQL, it could be useful. If we dismiss an alert, does it stay dismissed?

@pnacht
Copy link
Contributor

pnacht commented Jan 30, 2023

We dropped dependabot because is was spamming all the numpy forks. It was a known problem, but it never got fixed AFAICT.

I see dependabot was removed in #20268, which was in November 2021. However, dependabot has recently become default-off for forks (November 2022).

@varunsh-coder
Copy link

@varunsh-coder

We dropped dependabot because is was spamming all the numpy forks. It was a known problem, but it never got fixed AFAICT.

Not sure about CodeQL, it could be useful. If we dismiss an alert, does it stay dismissed?

w.r.t CodeQL, yes, my experience has been that once an alert is dismissed in the Code Scanning UI, it stays dismissed.
https://docs.github.com/en/enterprise-cloud@latest/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/managing-code-scanning-alerts-for-your-repository#dismissing--alerts

@mattip
Copy link
Member

mattip commented Jan 31, 2023

I'm not sure I understand. Where did step-security-bot come from, who is behind it?

Can we make each addition a separate PR? I would like to think about each tool separately. Here are a few thoughts but again I think they should be dealt with one-at-a-time:

  • dependabot: what are our runtime dependencies? We have build dependencies and test dependencies and documentation dependencies. I get that keeping runtime dependencies updated is good for security, but in what scenario is a DDOS vulnerability in a tool used in building docs a liability? When we had dependabot turned on, it generated weekly PRs that were really not helpful: they required time to research what changed and how it might break other parts of the project. Has the UX experience improved?
  • Pinning dependencies in workflows to a hash instead of a version number: This feels weird. Why version software anymore, if we are supposed to link to hashes? Perhaps github actions should have clearer guidance here. When is a version number good enough and when is a hash required? How will we know when to update the hash?
  • CodeQL: we have tried static code verification and we get various false positives along side helpful true positives. The suggestions require a deep dive in order to review and are quite time consuming. I don't know anything about CodeQL, but past attempts have felt more like we are beta testers for not-production-ready software than consumers of a valuable product. We run valgrind before a release. Did CodeQL actually find any actionable problems in the codebase? Is there a reason to prefer CodeQL over any of the other alternatives?

At the end of the day, the OpenSSF Scorecard is just another measure by a third-party service who may value certain measures of security without considering the maintainer burden they add. Does OpenSSF do any kind of cost-benefit analysis on their reccomendations? (I asked this question in ossf/scorecard#2627 Each new tool comes with more maintainer burden, more discussions about the validity of its recommendations. As more of these automated tools become available via bots, and more organizations develop measures that recommend their use, the maintainer workload keeps growing.

@varunsh-coder
Copy link

I'm not sure I understand. Where did step-security-bot come from, who is behind it?

Hi @mattip, this semi-automated PR was created using https://github.com/step-security/secure-workflows. I am the maintainer of that project. The project helps to apply security best practices using automation. Even though step-security-bot account created the PR, it can only be initiated by someone who has already contributed to a project. In this case, @charris used it to apply best practices using automation, whereas making these changes manually would have taken much longer. While creating PR, one can choose what best practices to apply, so it is possible to create separate PR for separate issue types. Hope this answers your questions. Please let me know if you have any other questions related to this.

Can we make each addition a separate PR? I would like to think about each tool separately. Here are a few thoughts but again I think they should be dealt with one-at-a-time:

  • dependabot: what are our runtime dependencies? We have build dependencies and test dependencies and documentation dependencies. I get that keeping runtime dependencies updated is good for security, but in what scenario is a DDOS vulnerability in a tool used in building docs a liability? When we had dependabot turned on, it generated weekly PRs that were really not helpful: they required time to research what changed and how it might break other parts of the project. Has the UX experience improved?
  • Pinning dependencies in workflows to a hash instead of a version number: This feels weird. Why version software anymore, if we are supposed to link to hashes? Perhaps github actions should have clearer guidance here. When is a version number good enough and when is a hash required? How will we know when to update the hash?

GitHub does recommend pinning 3rd party Actions. Dependabot can then update the hash when a new version is released. The tag of the new version is stored as a comment and that also gets updated by Dependabot.

  • CodeQL: we have tried static code verification and we get various false positives along side helpful true positives. The suggestions require a deep dive in order to review and are quite time consuming. I don't know anything about CodeQL, but past attempts have felt more like we are beta testers for not-production-ready software than consumers of a valuable product. We run valgrind before a release. Did CodeQL actually find any actionable problems in the codebase? Is there a reason to prefer CodeQL over any of the other alternatives?

CodeQL is from GitHub https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/about-code-scanning-with-codeql.

At the end of the day, the OpenSSF Scorecard is just another measure by a third-party service who may value certain measures of security without considering the maintainer burden they add. Does OpenSSF do any kind of cost-benefit analysis on their reccomendations? (I asked this question in ossf/scorecard#2627 Each new tool comes with more maintainer burden, more discussions about the validity of its recommendations. As more of these automated tools become available via bots, and more organizations develop measures that recommend their use, the maintainer workload keeps growing.

@pnacht feel free to add to what I wrote.

@mattip
Copy link
Member

mattip commented Feb 1, 2023

The project helps to apply security best practices using automation.

This concept is problematic. Security best practices cannot be applied without context. What in one area may be considered best practices may be overkill in other areas. Here is an example. A CVE was filed against setuptools claiming it could suffer from a DOS in a crafted package or custom PackageIndex page. But for the vast majority of the uses of setuptools (including the one in this repo NumPy), that CVE is not relevant since they do not use a custom PackageIndex. That CVE puts users of NumPy in an impossible situation: if they use automated tools to detect vulnerabilities, those tools will flag NumPy as unsafe and prevent its use. There currently is no released version of NumPy that can be used under that CVE. Well, except that:

  • setuptools is only used for the build process of NumPy, not in the runtime.
  • the use does not fall under the terms of the CVE since only PyPI is used as a PackageIndex

Ahh, but wait, what if someone sets an environment variable to target a private PackageIndex. Then is NumPy susceptible to the CVE or not? Well, then is the problem only going to affect NumPy or is it going to apply to the entire python environment they are using?

In short, in my opinion, adoption of automated tools to blindly apply security vulnerability data bases or automated tools for static code analysis to python code could have unintended consequences. For one such doomsday outcome, take a look at this discussion thread to ban python use in a corporate environment.

@varunsh-coder
Copy link

Security best practices cannot be applied without context.

@mattip I agree with you. I want to clarify that best practices are only being applied with the intent of a contributor. As you can see from @charris's comment,

I generated this security PR to see what it did, motivated by the alerts in the security tab.

Using https://github.com/step-security/secure-workflows, a contributor can choose what best practices they want to apply using a PR; each best practice can be de-selected using a checkbox. The contributor must then click on a button to generate a PR and can even create a preview of the PR to see the changes.

I hope that clarifies that the bot is not creating the PR independently with a fixed set of best practices. A contributor can choose what they think will help based on the context of the project and apply them. I'm sorry if this caused confusion, and if you believe the PR text can be improved to clarify this, I can take that action item. Please let me know. Thanks!

@rgommers
Copy link
Member

rgommers commented Feb 1, 2023

I see dependabot was removed in #20268, which was in November 2021. However, dependabot has recently become default-off for forks (November 2022).

That's great - finally, took them 3+ years - but please don't bother adding Dependabot back. They've been godawful, and until there is much more evidence that they have changed, I am a very hard -1 on re-enabling it.

Copy link
Member

@rgommers rgommers 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 PR. I'll have a closer look at this soon. The change to hashes for GitHub Actions seems good in principle (like, actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0). It's not entirely clear that this is useful for actions made by GitHub itself (the actions repo) - there is some discussion about this in the Tidelift security scorecard channel that I'll revisit. But in general, where we use actions from individuals that we don't really know, it seems like a clear improvement.

@charris
Copy link
Member

charris commented Feb 1, 2023

each best practice can be de-selected using a checkbox.

I'll note that I de-selected some of the checks, saving them for later.

@charris
Copy link
Member

charris commented Feb 1, 2023

I am a very hard -1 on re-enabling it [dependabot].

Dependabot does run, you can see the results in the security tab, so it isn't like it is completely disabled. I used the results for #23130.

EDIT: Maybe we can set it up to only notify for security alerts. But we pretty much already have that with the security tab.

@rgommers
Copy link
Member

rgommers commented Feb 1, 2023

I am a very hard -1 on re-enabling it [dependabot].

Dependabot does run, you can see the results in the security tab, so it isn't like it is completely disabled.

It's like one of those prickly weeds in your garden - no matter how hard you work to get rid of it, you never fully succeed ...

@charris
Copy link
Member

charris commented Feb 2, 2023

you never fully succeed

I thought the security upgrades/pins were useful, it didn't bother alerting releases otherwise, which was nice. However, it did keep adding the same alerts to the list, so it has grown rather lengthy ...

@seberg
Copy link
Member

seberg commented Feb 3, 2023

If the code quality comments mainly/only show up as annotations on changed lines, I am happy with them, should be rare enough to ignore them (i.e. none of the ones currently there seem really important, a more efficient regex may be nice, but really isn't a priority).
I do agree that historically issues being opened via the use of static tools were likely more churn than useful.

No opinion on dependabot, pinning hashes seems fine in general (seems a bit like it makes more sense with rare auto-updates). Would it be possible to schedule dependabot on a very slow schedule to keep the hashes up-to date but otherwise hear nothing from it for months at a time?

@charris
Copy link
Member

charris commented Feb 3, 2023

Would it be possible to schedule dependabot on a very slow schedule

I'm happy to leave it under the security tab, but we do need to take a look now and then.

should be rare enough to ignore them

You can dismiss them and they should stay dismissed. That said, I think we could make issues of the current ones, they could be improved for clarity if nothing else.

Harden-Runner is a bit of a mystery to me and is a third party app. More information is at https://github.com/marketplace/actions/harden-runner.

@varunsh-coder
Copy link

Harden-Runner is a bit of a mystery to me and is a third party app. More information is at https://github.com/marketplace/actions/harden-runner.

@charris I am also the maintainer for harden-runner, so let me know if you have any questions about it.
It gives a view of outbound traffic and source code overwrite during the job run, and then suggests and enables setting a policy to restrict outbound traffic and run job without sudo access.
As an example, here is the insights view for one of the jobs in this PR:
https://app.stepsecurity.io/github/numpy/numpy/actions/runs/4047433631
These insights links are available in the job summary and build log, e.g.
https://github.com/numpy/numpy/actions/runs/4047433631/jobs/6961444166#step:3:12

@charris
Copy link
Member

charris commented Mar 4, 2023

Will regenerate to resolve conflicts.

@charris charris closed this Mar 4, 2023
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.

7 participants