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

[infra/deploy] ci: Harden GitHub Actions #10479

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

step-security-bot
Copy link

@step-security-bot step-security-bot commented Jan 22, 2025

Summary

I'm onboarding our new CI/CD security tool: HardenRunner. A few lines are added to certain workflow files to enable the scanners.

It will scan for anomalies on the CI/CD side without making any changes (unless manually requested).

part of https://github.com/neondatabase/cloud/issues/21253

@step-security-bot step-security-bot requested a review from a team as a code owner January 22, 2025 13:06
@github-actions github-actions bot added the external A PR or Issue is created by an external user label Jan 22, 2025
@areyou1or0 areyou1or0 changed the title [StepSecurity] Apply security best practices [infra/deploy] ci: Harden GitHub Actions Jan 22, 2025
@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

Copy link
Member

@jcgruenhage jcgruenhage left a comment

Choose a reason for hiding this comment

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

The changes here can be split in a few different categories:

  1. "Harden Runner" which sets up network egress monitoring
  2. pinning sha hashes for container images and actions
  3. setting the default permission to contents: read
  4. add a dependabot config
  5. add a pre-commit config
  6. add a scorecards workflow
  7. add a codeql workflow
  8. add a dependency review workflow

I think 1 and 2 are good and should be merged. 3 is questionable, as you can set that globally, as documented in https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication#permissions-for-the-github_token. 4 sounds good as well. 5 is a bit complicated, as we now have pre-commit hooks defined in multiple places, which we should unify, and the chosen hooks are a weird selection, that don't really fit the work happening in this repo. 6 and 7 I'm not sure about, I don't know these and don't know what value they provide. 8 is a bit complicated: We already check dependencies with cargo-deny, and I haven't found what languages this new action supports from a quick glance at the readme.

Comment on lines +11 to +13
permissions:
contents: read

Copy link
Member

Choose a reason for hiding this comment

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

Do we need to duplicate this in every workflow file? If restricting the default permissions is something we want to do, then github has an enterprise level default permission that we can set to restricted: https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication#permissions-for-the-github_token

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, but it wouldn't work in certain occasions like the following comment you dropped which requires write permissions. Not sure if it'd break stuff.

Copy link
Member

Choose a reason for hiding this comment

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

In those cases we can still be more permissive with the permissions field in the workflow. If we want to default to read only permissions (which is good IMO), I'd prefer if we did that in a global setting instead of replicating this snippet everywhere.

.github/workflows/_create-release-pr.yml Outdated Show resolved Hide resolved
.pre-commit-config.yaml Outdated Show resolved Hide resolved
Copy link
Member

@jcgruenhage jcgruenhage left a comment

Choose a reason for hiding this comment

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

I'm still unsure about the permissions thing. I'd really prefer setting that globally and only overwriting the default in the workflow file where it's necessary to get more permissions, like with the workflow for creating release PRs.

My opinion on this is not strong enough to click "request changes" again, but it's not an approval either. Can someone else also weigh in on this?

@areyou1or0
Copy link
Contributor

I don't have a strong opinion on this, open to hear what the rest of the team thinks.

If agreed upon, I can change the files accordingly, just let me know.

@jcgruenhage jcgruenhage added the approved-for-ci-run Changes are safe to trigger CI for the PR label Jan 23, 2025
@github-actions github-actions bot removed the approved-for-ci-run Changes are safe to trigger CI for the PR label Jan 23, 2025
@jcgruenhage
Copy link
Member

I've discussed this with @fedordikarev, and the result was to go with it as is to not slow things down, and maybe revisit the global setting in the future. When we merge this, we need to announce it so that people are aware of this, because I'm fairly certain a few workflows will break due to permission, and not all of them will be caught before the merge. The devprod oncall can handle fixing permissions where they arise though, so that should be fine, as long as people know to reach out to us.

I think we can merge this as soon as CI passes - if that's today I'd announce it in the platform sync so that people know about it.

@fedordikarev
Copy link
Contributor

yeah, still waiting for answers in Slack, to have final agreement.
meanwhile, lets check that CI will be also happy and follow on any issues found

@areyou1or0
Copy link
Contributor

Thank you both, as I told @fedordikarev I'm totally flexible, I don't wanna cause issues. We can merge it as it is, if it causes issues, we can remove certain scans or look for an alternative implementation.

Copy link
Member

@jcgruenhage jcgruenhage left a comment

Choose a reason for hiding this comment

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

Approving so that CI can run

@jcgruenhage jcgruenhage added the approved-for-ci-run Changes are safe to trigger CI for the PR label Jan 23, 2025
@github-actions github-actions bot removed the approved-for-ci-run Changes are safe to trigger CI for the PR label Jan 23, 2025
Copy link
Contributor

@fedordikarev fedordikarev left a comment

Choose a reason for hiding this comment

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

with all the discussions and caveats, lets approve and check CI run
it should work and will take a closer look after merged

@fedordikarev fedordikarev added the approved-for-ci-run Changes are safe to trigger CI for the PR label Jan 23, 2025
@github-actions github-actions bot removed the approved-for-ci-run Changes are safe to trigger CI for the PR label Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external A PR or Issue is created by an external user
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants