-
Notifications
You must be signed in to change notification settings - Fork 492
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
golangci-lint: update to latest version & related tweaks #5737
base: main
Are you sure you want to change the base?
Conversation
.golangci.yml
Outdated
@@ -32,3 +36,6 @@ linters-settings: | |||
rules: | |||
- name: unused-parameter | |||
disabled: true | |||
gosec: | |||
excludes: | |||
- G115 # "Potential integer overflow when converting between integer types"; TODO re-enable eventually |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally think that it would be better to either exclude this individually in each line that it's observed today and we know that it's safe, or find a solution for the current instances.
I'm worried that we can keep this forever and hide real issues in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair. I can look into using https://github.com/ccoVeille/go-safecast to properly address these issues (i.e. to add the required checks), if adding that dependency seems acceptable? If not, we could implement equivalent functionality in some simpler helpers ourselves.
7a8d88b
to
c244717
Compare
Hm, I'm puzzled by the Windows-only integration test failure. The relevant part of the error is:
I got this error previously, but fixed it. The relevant source code line, spire/pkg/agent/plugin/keymanager/v1.go Line 122 in c244717
This should not cause the error. Of note, the Linux version of that integration test runs successfully. Also of note is that the relevant code is already covered by unit tests, which succeed correctly on both Linux and Windows. Before the last couple of force-pushes, I did have a different version of the above line, which indeed caused the error (I noticed it when running tests locally): spire/pkg/agent/plugin/keymanager/v1.go Line 122 in 41da0f7
But I inspected the claimed git commit that the Windows integration test is running against and it has the new, fixed version of the code. And this happened twice now, with both of the most recent force-pushes. So it feels like some kind of caching is going on that is not seeing the latest version of the code. Is there any kind of state in the CI runner that could be cleared? Could the cache-deps CI step be causing this somehow? |
Anyway, aside from this strange CI failure, this PR now addresses all the integer conversion issues found by |
Ok, rebasing against |
Having looked at the https://github.com/ccoVeille/go-safecast package a bit more closely, I actually think we're better off implementing the functionality we need from it ourselves, at least for now. Specifically, the issue is that I'll update this PR accordingly (though eventually maybe the go-safecast package can also be improved). |
The latest golangci-lint version comes with two new detected issues, both of which we choose to silence here: 1) staticcheck: Deprecation of (crypto/x509).CertPool.Subjects(): This is still useful to us in the tests and there seems to be no good alternative (we use it merely to count the number of certs). 2) gosec: Potential integer overflow: This is a potentially useful check, but I didn't want to address this as part of this PR. https://github.com/ccoVeille/go-safecast might be useful for this (in fact it looks like it was inspired by the recent addition of this gosec rule). Additionally, change the Makefile to tell golangci-lint to emit all lints, as opposed to imposing its default limits. Those limits could actually be misleading, as it could e.g. lead to someone disabling lints without having seen all the reported issues. Signed-off-by: Carlo Teubner <carlo@cteubner.net>
Signed-off-by: Carlo Teubner <carlo@cteubner.net>
Signed-off-by: Carlo Teubner <carlo@cteubner.net>
Silence these complaints only in test code. Signed-off-by: Carlo Teubner <carlo@cteubner.net>
...with our own implementation that is more typesafe and more convenient. Signed-off-by: Carlo Teubner <carlo@cteubner.net>
I've now updated this PR as indicated above, with our owned checked-int-cast helper function. |
The latest golangci-lint version comes with two new detected issues:
staticcheck: Deprecation of
(crypto/x509).CertPool.Subjects()
:This is still useful to us in the tests and there seems to be no good alternative (we use it merely to count the number of certs).
gosec: Potential integer overflow:
I'm addressing this using some new helpers I'm introducing for checked casting between int types. Inspired by https://github.com/ccoVeille/go-safecast but simpler and more suitable for our purposes.
Additionally, change the Makefile to tell golangci-lint to emit all lints, as opposed to imposing its default limits. Those limits could actually be misleading, as it could e.g. lead to someone disabling lints without having seen all the reported issues.
For completeness – full list of staticcheck CertPool.Subjects() reports:
And full list of gosec integer overflow reports: