Skip to content

gha: add CodeQL Analysis workflow#47034

Merged
thaJeztah merged 1 commit intomoby:masterfrom
thaJeztah:add_codeql
Sep 19, 2024
Merged

gha: add CodeQL Analysis workflow#47034
thaJeztah merged 1 commit intomoby:masterfrom
thaJeztah:add_codeql

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

copied from https://github.com/docker/cli/blob/88e6474350e644495a8009e9e1437332aa828a17/.github/workflows/codeql.yml

- What I did

- How I did it

- How to verify it

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

Comment thread .github/workflows/codeql.yml Outdated
@github-advanced-security
Copy link
Copy Markdown

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.

@thaJeztah
Copy link
Copy Markdown
Member Author

Ah, this probably requires some additional trickery to make it work;

2024/01/07 12:00:22 Warning: encountered errors extracting package `github.com/moby/moby/api/server/backend/build`:
2024/01/07 12:00:22   -: code in directory /home/runner/work/moby/moby/root/src/github.com/moby/moby/api/server/backend/build expects import "github.com/docker/docker/api/server/backend/build"
Error: 2024/01/07 12:00:22   /home/runner/work/moby/moby/root/src/github.com/moby/moby/api/server/backend/build/backend.go:48:27: cannot use s (variable of type *"github.com/moby/moby/vendor/google.golang.org/grpc".Server) as *"github.com/docker/docker/vendor/google.golang.org/grpc".Server value in argument to b.buildkit.RegisterGRPC

- cron: '0 9 * * 4'

jobs:
codeql:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should have a matrix to analyze both dockerd and docker-proxy. Mainly because "Autobuild" will not build any of them so would need to set https://github.com/github/codeql-action/blob/8516954d603e47049b34f3da4dfac83009fcd450/autobuild/action.yml#L9 to ./cmd/dockerd and ./cmd/docker-proxy using a matrix. Can be done in follow-up.

Edit: Actually it will run make so should be fine: https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages#autobuild-for-go

@thaJeztah
Copy link
Copy Markdown
Member Author

@crazy-max I added the symlink go.mod -> vendor.mod trick that I had in docker/cli, and I THINK it's working correctly now; PTAL; https://github.com/moby/moby/actions/runs/10910306702/job/30280453719?pr=47034

@thaJeztah
Copy link
Copy Markdown
Member Author

LOL.. well, almost;

Error: /workflows/codeql.yml:14:14: [error] trailing spaces (trailing-spaces)
Error: /workflows/codeql.yml:15:17: [error] trailing spaces (trailing-spaces)
Error: /workflows/codeql.yml:16:24: [error] trailing spaces (trailing-spaces)
Error: /workflows/codeql.yml:17:10: [error] trailing spaces (trailing-spaces)
Error: /workflows/codeql.yml:18:13: [error] trailing spaces (trailing-spaces)
Error: /workflows/codeql.yml:21:16: [error] too many spaces inside brackets (brackets)
Error: /workflows/codeql.yml:21:25: [error] too many spaces inside brackets (brackets)
Error: /workflows/codeql.yml:42:1: [error] trailing spaces (trailing-spaces)
make: *** [Makefile:256: validate-yamllint] Error 1
Error: Process completed with exit code 2.

@thaJeztah
Copy link
Copy Markdown
Member Author

OK, I think it worked; at least it indicates it scanned;

CodeQL scanned 1118 out of 2032 Go files in this invocation. Check the status page for overall coverage information: https://github.com/moby/moby/security/code-scanning/tools/CodeQL/status/
Analysis produced the following diagnostic information:
Go files were found but not processed (1 result)
    * [Specify a custom build command](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-the-codeql-workflow-for-compiled-languages) that includes one or more `go build` commands to build the `.go` files to be analyzed.

The "files were found but not processed" are very likely the same reason as we have this on docker/cli; CodeQL ignores _test.go files, and as such will skip ~50% of files we have;

Copy link
Copy Markdown
Member

@crazy-max crazy-max left a comment

Choose a reason for hiding this comment

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

- name: Update Go
uses: actions/setup-go@v5
with:
go-version: 1.22.7
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe put go version as global env similar to other workflows

GO_VERSION: "1.22.7"
?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, we should consider doing so; I'll look at that in a follow-up!

Comment thread .github/workflows/codeql.yml Outdated
jobs:
codeql:
runs-on: 'ubuntu-latest'
timeout-minutes: 360
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not needed for this repo

Copy link
Copy Markdown
Member Author

@thaJeztah thaJeztah Sep 19, 2024

Choose a reason for hiding this comment

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

Ah, yes; for public repos we wouldn't be charged; mostly considering that;

  • I've seen some runaway actions running for hours
  • We may at times have a private fork to work on security releases; those are charged

I can make this a lot shorter though!

Screenshot 2024-09-19 at 11 00 54

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

put it to 10 minutes, which (based on the above) should be enough currently (we can update if that turns out to be too short)

Comment thread .github/workflows/codeql.yml Outdated
Comment on lines +38 to +41
permissions:
actions: read
contents: read
security-events: write
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This can just be put as global perms

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

As discussed on slack; my thinking here was that we set a default at the top (contents: read), and to override only in places where it’s needed.

Slightly on the defensive side in cased (e.g.) someone decides “let’s merge these two workflows in a single YAML, and now not copying the permissions. Or vice-versa; “let’s add some other jobs to this file” which now would have more permissions than needed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sure fine by me!

Comment thread .github/workflows/codeql.yml Outdated
Comment thread .github/workflows/codeql.yml Outdated
Signed-off-by: Sebastiaan van Stijn <[email protected]>
Copy link
Copy Markdown
Member

@crazy-max crazy-max left a comment

Choose a reason for hiding this comment

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

LGTM

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.

3 participants