-
Notifications
You must be signed in to change notification settings - Fork 588
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Guess go main module version based on binary contents #2608
Conversation
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Question for reviewers: since this has the potential to raise up an incorrect version on a package, should this at least have a configuration option that a user can opt out of this heuristic? |
A config option seems like a good idea to me; however should it also apply or have subcomponents to also enable/disable the parsing of version from ldflags etc since that also has the potential to be incorrect? |
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
I've added configuration options for all version guessing heuristics since they can all really have downsides. They all default to enabled. |
@@ -37,15 +38,16 @@ var ( | |||
// inject the correct version into the main module of the build process | |||
|
|||
knownBuildFlagPatterns = []*regexp.Regexp{ | |||
regexp.MustCompile(`(?m)\.([gG]it)?([bB]uild)?[vV]ersion=(\S+/)*(?P<version>v?\d+.\d+.\d+[-\w]*)`), | |||
regexp.MustCompile(`(?m)\.([gG]it)?([bB]uild)?[vV]er(sion)?=(\S+/)*(?P<version>v?\d+.\d+.\d+[-\w]*)`), |
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.
adjusts the pattern to be more permissive based on examples in the field. This allows for us to depend on the (probably more dependable) LD flags instead of the binary contents pattern matching in more cases.
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
* guess go main module version based on binary contents Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * add configuration options for golang main module version heuristics Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix test setup for go bin cataloger Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix unit test Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix incorrect test assert ordering Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * handle error from seek Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> --------- Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
* guess go main module version based on binary contents Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * add configuration options for golang main module version heuristics Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix test setup for go bin cataloger Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix unit test Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix incorrect test assert ordering Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * handle error from seek Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> --------- Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Today the go main module version cannot be determined in all cases. We have a few heuristics in place to try and guess what the main module version is (by looking at ldflags and build setting info), however, there are still cases that are missed:
This PR adds an additional heuristic to look at the binary contents and use a simple semver regex pattern matcher like we do with the binary cataloger to find matching version strings:
You'll note that it seems like it only "kind of" worked -- now we have two
k8s.io/ingress-nginx
packages, one that is correct and another that still showsdevel
. In this particular case, this is the best we can do. Let's look at what was found in detail:There are three different binaries that have the same
k8s.io/ingress-nginx
package:/nginx-ingress-controller
,/wait-shutdown
,/dbg
.It seems that only the main
/nginx-ingress-controller
binary has any indication of a version baked into the binary:In the future we might be able to correlate claimed package h1 information across all main packages discovered to try and get a better answer for all packages, but that is out of scope for this particular enhancement (and may be questionable to do , thus requires some discussion first).-- nevermind, I forgot there is no h1 digest for the main module