mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-11-25 06:35:21 +00:00
fix(app): start the rescan worker
The app created the rescan worker when security.rescan_interval was set but never started it; only Shutdown called Stop. A scan lost to a restart therefore left its package unscanned for good, and old results were never refreshed with new CVEs. startWorkers now starts the worker. The ledger records it as GH-24.
This commit is contained in:
@@ -28,6 +28,7 @@ Currency: `sh lean4/scripts/check_currency.sh origin/main`.
|
|||||||
| GH-21 | scan retry | a scan retry on S3 or SMB storage reads the stored blob instead of a removed temp file | correctness | low (file-based scanners on remote storage) | `Security.old_remote_retry_unreadable`, `fixed_retry_always_readable` / `TestScanRetryOnRemoteStorageReadsBlobAgain` | 31db940 |
|
| GH-21 | scan retry | a scan retry on S3 or SMB storage reads the stored blob instead of a removed temp file | correctness | low (file-based scanners on remote storage) | `Security.old_remote_retry_unreadable`, `fixed_retry_always_readable` / `TestScanRetryOnRemoteStorageReadsBlobAgain` | 31db940 |
|
||||||
| GH-22 | dashboard API | an OIDC-logged-in browser can call `/api` with a long URL; the proxy hop neither forwards session cookies nor exceeds the read buffer | availability | medium (every `/api` call returned 431 for OIDC users) | not modelled (header size, no decision logic) / `TestLargeRequestHeadersAreAccepted`, `TestReadBufferSizeIsConfigurable`, `scripts/check_frontend_cookie_strip.sh` | 536f35a |
|
| GH-22 | dashboard API | an OIDC-logged-in browser can call `/api` with a long URL; the proxy hop neither forwards session cookies nor exceeds the read buffer | availability | medium (every `/api` call returned 431 for OIDC users) | not modelled (header size, no decision logic) / `TestLargeRequestHeadersAreAccepted`, `TestReadBufferSizeIsConfigurable`, `scripts/check_frontend_cookie_strip.sh` | 536f35a |
|
||||||
| GH-23 | PyPI sidecar | pip's PEP 658 request (`<link>.metadata`, suffix on `original_url`) is served as its wheel's sidecar; another file's sidecar is still refused | correctness (pip install failed with 400) | medium (every pip install through the proxy) | `Access.pip_form_keeps_key_binding`, `pip_sidecar_of_other_file_rejected`, `pip_sidecar_of_same_file_accepted` / `TestPipSidecarFormIsStreamed`, `TestHandlePackageFile_OriginalURLFilenameBound` | 501bf1a |
|
| GH-23 | PyPI sidecar | pip's PEP 658 request (`<link>.metadata`, suffix on `original_url`) is served as its wheel's sidecar; another file's sidecar is still refused | correctness (pip install failed with 400) | medium (every pip install through the proxy) | `Access.pip_form_keeps_key_binding`, `pip_sidecar_of_other_file_rejected`, `pip_sidecar_of_same_file_accepted` / `TestPipSidecarFormIsStreamed`, `TestHandlePackageFile_OriginalURLFilenameBound` | 501bf1a |
|
||||||
|
| GH-24 | rescan | with `security.rescan_interval` set, artifacts whose scan never completed are scanned and old results refreshed | correctness (scans lost to a restart stayed unscanned; new CVEs never picked up) | medium | not modelled (worker wiring) / `TestWorkersStartTheRescanWorker` | this change |
|
||||||
|
|
||||||
### Exploit paths and reach
|
### Exploit paths and reach
|
||||||
|
|
||||||
|
|||||||
@@ -617,6 +617,11 @@ func (a *App) startWorkers(ctx context.Context) {
|
|||||||
// Start periodic stats broadcaster (every 30s) so connected WS clients
|
// Start periodic stats broadcaster (every 30s) so connected WS clients
|
||||||
// see live counter updates without polling.
|
// see live counter updates without polling.
|
||||||
go a.startStatsBroadcaster(ctx)
|
go a.startStatsBroadcaster(ctx)
|
||||||
|
|
||||||
|
// Re-scans artifacts whose scan was lost to a restart and refreshes old results.
|
||||||
|
if a.rescanWorker != nil {
|
||||||
|
go a.rescanWorker.Start(ctx)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) Run() error {
|
func (a *App) Run() error {
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/lukaszraczylo/gohoarder/pkg/config"
|
||||||
|
"github.com/lukaszraczylo/gohoarder/pkg/metadata"
|
||||||
|
)
|
||||||
|
|
||||||
|
// A cached artifact whose scan never completed (lost to a restart) is scanned once the
|
||||||
|
// workers start, when security.rescan_interval is set.
|
||||||
|
func TestWorkersStartTheRescanWorker(t *testing.T) {
|
||||||
|
osv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
_, _ = w.Write([]byte(`{"vulns":[]}`))
|
||||||
|
}))
|
||||||
|
defer osv.Close()
|
||||||
|
|
||||||
|
a := newTestApp(t, func(c *config.Config) {
|
||||||
|
c.Security.Enabled = true
|
||||||
|
c.Security.RescanInterval = time.Hour
|
||||||
|
c.Security.Scanners.OSV.Enabled = true
|
||||||
|
c.Security.Scanners.OSV.APIURL = osv.URL
|
||||||
|
})
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
const key = "npm/left-pad/1.3.0"
|
||||||
|
if err := a.storage.Put(ctx, key, strings.NewReader("tarball"), nil); err != nil {
|
||||||
|
t.Fatalf("storage.Put: %v", err)
|
||||||
|
}
|
||||||
|
now := time.Now()
|
||||||
|
err := a.metadata.SavePackage(ctx, &metadata.Package{
|
||||||
|
Registry: "npm", Name: "left-pad", Version: "1.3.0", StorageKey: key,
|
||||||
|
Size: 7, CachedAt: now, LastAccessed: now,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("SavePackage: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
a.startWorkers(ctx)
|
||||||
|
|
||||||
|
deadline := time.Now().Add(20 * time.Second)
|
||||||
|
for time.Now().Before(deadline) {
|
||||||
|
if _, err := a.metadata.GetScanResult(ctx, "npm", "left-pad", "1.3.0"); err == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
time.Sleep(50 * time.Millisecond)
|
||||||
|
}
|
||||||
|
t.Fatal("no scan result after the workers started; the rescan worker never ran")
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user