Граф коммитов

31 Коммитов

Автор SHA1 Сообщение Дата
Tatiana Bradley 10c3808cf5 all, internal/report: refactor logic to read reports from vulndb repo
Package the logic to read reports from a vulndb-like repo into
a Client, and update all callers.

For now, the behavior under the hood is basically the same as it was, but
the callers do not need to carry around the specific maps needed
to access certain information.

Change-Id: I7bd28bfbf2a40d5d2bc37453051f866517086f23
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/562177
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-02-21 15:53:16 +00:00
Tatiana Bradley 0d95d59155 internal/{cveutils,worker}: use pkgsite client
Use the new pkgsite client instead of making direct calls to pkgsite.

Change-Id: I8d7f107740679ea1e2475f44b666824b8548b8b0
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/554356
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
2024-01-08 17:41:05 +00:00
Tatiana Bradley 7e379daf96 internal/{cveutils,worker}: move CVE triage to cveutils
Move existing logic to triage v4 CVEs to the cveutils package.
This will make it easier to add tests and implement triage for v5 CVEs.

Change-Id: I4872af391a33500dd7236795a910ad3a6998b5e0
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/550857
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
2024-01-08 17:40:54 +00:00
Jonathan Amsterdam b2b721ddeb internal/worker/log: use slog
Use the log/slog package instead of golang.org/x/event.

This removes x/event from the repo.

Until Go 1.22 comes out, use golang.org/x/exp/slog, because
we still test one version back (Go 1.20), and log/slog appeared
in Go 1.21.

Change-Id: Ia0f645069c778741ebb8c359161816a303a2175b
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/552675
TryBot-Result: Gopher Robot <gobot@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Tatiana Bradley <tatianabradley@google.com>
2024-01-08 16:23:52 +00:00
Tatiana Bradley 0d85f0110f deploy,cmd/worker: use go1.21 in deploy files
Change-Id: I5b5c9b71f0c8bc1ab37bc92103e8ba0b2abfe9c5
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/551467
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
2023-12-19 20:22:45 +00:00
Tatiana Bradley 2c25500406 internal/cvelistrepo: add test data for cvelistv5
Adds the ability to pull in fresh test data for v5 CVEs, and uses this
to add a test repo file containing v5 data.

For golang/go#49289

Change-Id: I36f516c75f2a1a241f614db7f5bb69555be096fc
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/545299
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
2023-12-04 18:38:54 +00:00
Tatiana Bradley 44ab8d2a6b internal,proxy, all: replace proxy.DefaultClient with NewDefaultClient()
Instead of exposing a global public variable, require that users of the
proxy package instantiate their own proxy client. This makes the package
harder to misuse, and makes it clearer where we are using a real client
vs. a test client.

Change-Id: I2f0f5895065e6efec1d50b3ac34cb04847e3b002
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/524457
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-11 18:20:25 +00:00
Tatiana Bradley 24e908f28a all: minimize use of proxy.DefaultClient
Plumb an explicit proxy client through as many functions as possible,
using the default client only in tests and top-level code.

This will allow us to identify and clean up tests that use real proxy
calls and should use mocks.

Change-Id: Ibd6423ea77c2007424c4539fe25f78c5b1f4764a
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/524135
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
2023-09-11 16:11:15 +00:00
Tatiana Bradley 5c064e0c02 all: (cleanup) remove unnecessary words from function names
No-op refactor to remove redundant words like "get" from function names.

Change-Id: I899556dbbe8caa790593bee8d952d1b3f557387b
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/497499
Run-TryBot: Tatiana Bradley <tatianabradley@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-05-25 15:11:04 +00:00
Tatiana Bradley bd7dc9dc74 internal/worker: remove scan-modules code
Removes code to scan modules for vulnerabilities, as it is now obsolete.

Change-Id: Ib5fe0f34f2d53709fe05db582e74e94b930b37a5
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/459836
Reviewed-by: Tatiana Bradley <tatiana@golang.org>
Run-TryBot: Tatiana Bradley <tatiana@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-12-29 18:22:30 +00:00
Tatiana Bradley 7c32a36c39 internal/issues: add ctx to NewClient and expose struct fields
Change-Id: Ic4b4f9bff9fba1f914d99f61360b33d14a34d899
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/459640
Reviewed-by: Julie Qiu <julieqiu@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Tatiana Bradley <tatiana@golang.org>
Reviewed-by: Tatiana Bradley <tatiana@golang.org>
2022-12-28 21:09:15 +00:00
Julie Qiu fb3d0670e4 internal/ghsa: refactor client
Instead of initializing a new client in every function call, move the
functions in internal/ghsa to methods on a client.

This will make it easier to add unit tests in a follow up CL.

Change-Id: Ifdd7ee04e884822a94d489d4f6fde3035441f152
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/458202
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Tatiana Bradley <tatiana@golang.org>
Run-TryBot: Julie Qiu <julie@golang.org>
Reviewed-by: Julie Qiu <julieqiu@google.com>
2022-12-27 19:56:46 +00:00
Julie Qiu 9700ce4c71 cmd,internal: replace fakeClient with mock test setup
Previously, issue.Client was an interface, so that we could use a fake
client for testing.

This made it difficult to jump to definition, when debugging issues with
the client. Additionally, the tests weren't very effective, since they
didn't traverse the githubClient code path at all.

Replace the test setup with a mock http server, and make issues.Client
to a struct.

Change-Id: I878846ce69c2979b45ff6e8494bc0f7c020055ea
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/458203
Run-TryBot: Julie Qiu <julie@golang.org>
Reviewed-by: Julie Qiu <julie@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Tatiana Bradley <tatiana@golang.org>
2022-12-27 18:45:57 +00:00
Maceo Thompson 1f31c08356 internal/worker: worker now includes cross references in newly filed issue descriptions
Whenever the worker files a new issue on the tracker for a GHSA or CVE, it includes cross references (shared CVEs, GHSAs, or modules exluding std and cmd) in the issue description.

Change-Id: I8c10e2f9835c7ddae7ad0427c219edc04a9a7ef6
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/453501
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Maceo Thompson <maceothompson@google.com>
Reviewed-by: Tatiana Bradley <tatiana@golang.org>
2022-12-01 20:04:53 +00:00
Tatiana Bradley 1e09d094d7 cmd/worker: upgrade worker to Go 1.19
Change-Id: If18753652694b42590100e5099fe682e7bad387a
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/434616
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Tatiana Bradley <tatiana@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-26 21:03:53 +00:00
Tatiana Bradley c9514b27c8 internal/worker: do not skip GHSAs that have CVEs
The worker was missing some GHSAs because it always filtered out GHSAs with CVEs (and sometimes CVEs are miscategorized as not Go vulns, aren't published yet, etc).

This change modifies the logic to look at all GHSAs and create an issue if there is not yet an issue for the associated CVE.

Note that this leaves a gap (which will be fixed in a subsequent CL) in which a CVE that is later found by the worker will have a duplicate issue created for it.

Change-Id: I54008c2b2772ee6de9ece2f129de8668e80bed27
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/432095
Run-TryBot: Tatiana Bradley <tatiana@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2022-09-21 19:28:18 +00:00
cui fliter c957d8f9cd all: replace io/ioutil with io and os package
Change-Id: I3c6860d1758ac49b13fbb545e1e1957e345153ae
GitHub-Last-Rev: 9f43b2bf41
GitHub-Pull-Request: golang/vulndb#997
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/430855
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
2022-09-15 00:44:45 +00:00
Jonathan Amsterdam 30165f294f cmd/worker/Dockerfile: switch to 1.18
Use Go 1.18 to build and run the vuln worker.

Change-Id: I1dc24ce515feb8e22c5488ef4ae0f714a4495011
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/393838
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-18 19:49:06 +00:00
Jonathan Amsterdam 67f3261336 internal/worker: add force option to ScanModules
Normally, a module isn't scanned if there is a record of the scan
in the DB. Providing a "force" query parameter or command-line flag
overrides that.

Change-Id: I1d8836cd011060feb0ef2cf33e033abb2dbe9e67
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/393835
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
2022-03-18 19:30:53 +00:00
Jonathan Amsterdam 42c2e01940 {cmd,internal}/worker: scan modules
Complete support for scanning modules.

- Add scan-modules command to cmd/worker.
- Remember modules we scanned in the Store.
- Track the last-modified vuln DB time to avoid unnecessary re-scanning.

Change-Id: Id2b6d3b2d91c6617d31f4fe6997babba2db220bd
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/393695
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
2022-03-17 19:43:49 +00:00
Jonathan Amsterdam 8621c06bab internal/worker: scan modules for vulnerabilities
This is the first CL for a new task for the vuln worker: to scan
a selected set of modules for vulnerabilities.

Establish a new server endpoint, /scan-modules, to do that.
Currently visiting that endpoint scans the list of modules unconditionally.
A future CL will skip the scan if the vuln DB hasn't changed.

Hardcode a list of modules in the golang.org/x namespace.
Fetch each one from the proxy, and run vulncheck on it.

At present we just log any vulnerabilities we find. Later we'll
file issues to a GitHub repo.

Lastly, change the base image for the service to one that
has the go toolchain, since go/packages requires it.

Change-Id: I1de571d24d683b080542c5c40b55767967dbe8a5
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/393174
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
2022-03-16 22:37:40 +00:00
Jonathan Amsterdam 074a259630 internal/ghsa: allow listing advisories with CVEs
The List method previously listed only security advisories that did
not correspond to CVEs. Add an argument that allows the caller to
choose this behavior or the opposite, to list the advisories that do
have CVEs.

Change-Id: I286d4671d7bebe729eeef224acf8ce3fda9c21df
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/388674
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
2022-03-01 21:31:56 +00:00
Jonathan Amsterdam 0e62b48164 {cmd,internal}/worker: update GitHub security advisories
Add code to update the store state with information from GitHub's API
about its security advisories.

Since we can process the entire set of advisories in one transaction
(there are only 34 non-CVE Go-related advisories as of this writing),
this update process is considerably simpler than that for CVEs.  We
don't need to worry about concurrent updates, for one thing.  So we
avoid a separate record for each run, as we have with the
CommitUpdateRecord for CVEs.

Change-Id: I913864b4c83e39144af84da9447b33870c8cc5f0
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/384214
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
2022-02-28 14:34:01 +00:00
Jonathan Amsterdam 30b381d770 internal/worker/store: allow service account impersonation
The Firestore client now supports service account impersonation.
This is needed to run tests against our Firestore database.

Change-Id: I7803b4713564a8320361ae88bc76ff6189463a76
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/384094
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
2022-02-17 23:55:19 +00:00
Jonathan Amsterdam 821b6d568a internal/worker: add tracing
Add support for OpenTelemetry tracing of certain
important functions, using the event package.

We don't have a burning need for traces, but they
are nice to have, and this was an important exercise
for validating the approach of the event package.

Change-Id: I37d1f56f06f425f3b1eb885877a0d2f5ac85a098
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/380440
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
2022-02-01 15:12:36 +00:00
Jonathan Amsterdam 77392fc97f cmd/worker,devtools: put image tag in docker container
Set the DOCKER_IMAGE environment variable in the container to
be the image tag.

Change-Id: Iec4c9214d9a2ae296d8c2271a729135863f2ca93
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/376296
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Julie Qiu <julie@golang.org>
2022-01-07 17:21:56 +00:00
Jonathan Amsterdam 5ec67cc353 internal: move ParseGitHubRepo to gitrepo package
Change-Id: I792436f9106a1e4f1f43a68f6104892eaa8d3fe4
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/375717
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Julie Qiu <julie@golang.org>
2022-01-05 23:58:13 +00:00
Jonathan Amsterdam 12508860a4 internal/cvelistrepo: package for the cvelist repo
Create a package for working with github.com/CVEProject/cvelist.

Change-Id: Iadac53c0f13ba658bc20a9bd4f74d58ade5a4f44
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/375716
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Julie Qiu <julie@golang.org>
2022-01-05 23:58:01 +00:00
Jonathan Amsterdam 35689b6c2a internal: move useful things out of worker
Move the issue client code from internal/worker to its own package, internal/issues.

Move the ParseGitHubRepo function to the internal package.

Change-Id: I68cdb69a3273f541620a5c96f90fc66c0628e8fc
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/375715
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Julie Qiu <julie@golang.org>
2022-01-05 21:20:26 +00:00
Jonathan Amsterdam 81b4a2e117 internal/worker: combine structured and printf logging
Previously, the worker used structured logging almost completely:
anything that would have been a format string parameter was made a
label instead.

This led to a poor experience with the GCP logging UI.  You could see
the message of each log entry at a glance, but it took two clicks to
look at the labels. For example, when the worker created a GitHub
issue for a CVE, you'd see "created issue", but you wouldn't know the
CVE or number of the issue unless you opened the log entry.

This CL rethinks the log "frontend" -- the API that programmers
actually use to write log messages -- to allow a mix of labels
and printf-style formatting. The previous approach made it easy
to do one or the other, but not to mix both in a single log entry.
You could either write

   log.Info(message, labels...)

or

    log.Infof(format, args...)

but not both, since you can't have two "..." parameters in a function.
In this CL's design, one can write

    log.With(namesAndValues...).Infof(format, args...)

To further improve the ergonomics, the With function takes key-value
pairs rather than labels. Thus

    event.Int64("limit", int64(limit))

becomes

    log.With("limit", limit)

The performance is significantly worse, but for this server it
doesn't matter.

The CL also revisits each log message and makes a choice about whether
to display a value in the message, or to make a label out of it, or
both. As I said, putting the value in the message lets you see it at a
glance. The advantage of a label is you can easily query on it.

Most values only make sense as one or the other. For example, we'd
like to see the number of CVEs added during an update, but it doesn't
seem interesting to query the logs on that field. So that was put into
the message.

Change-Id: Iba2c70a14ea951c4d74335da6ac4e8265d652ded
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/373894
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Julie Qiu <julie@golang.org>
2021-12-22 14:06:59 +00:00
Julie Qiu 5b3cf6b695 cmd,internal: add tools and worker code
golang.org/x/vuln/srv is moved to this repository. Originally, the
motivation for creating x/vuln was to split the YAML reports and Go code
into two separate repositories. However, this resulted in a few
issues:

1. The structure of the YAML reports is tightly coupled with the structs
   in internal/report, and changing one without the other would result
   in errors when linting the reports.
2. The vlint package itself needed to be exported, even though the only
   consumer was the test in x/vulndb.
3. The deploy/build.yaml script depends on cmd/gendb@latest, so updating
   that command could easily break the script (for example, submitting
   CL 373004 without changing the reference in deploy/build.yaml).

Additionally, the original location of this code was x/vuln, which
contained two types of packages.

(1) Packages meant for consumption by other clients (for example,
x/vuln/client), and
(2) Internal packages that were only meant for use to spin up the
worker.

The internal packages resulted in many dependencies since they pulled in
GCP, which we don't want clients of the vulncheck library to
have to pull in. This problem was originally solved by creating a nested
module inside x/vuln, but nicer separation that would also solve the
issues above is the following:

* x/vuln: contains Go code meant to be imported by others
* x/vulndb: contains internal code only used to maintain the vulndb

For golang/go#50247

Change-Id: I74a7b7f9b8fc5b0ad48a45fc3156f93c08aa9955
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/373495
Trust: Julie Qiu <julie@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2021-12-20 22:08:22 +00:00