mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-12-01 07:05:24 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8adb1e0c87 | ||
|
|
16fb52ed3e |
+4
-4
@@ -23,17 +23,17 @@ RUN apk add --no-cache \
|
||||
&& update-ca-certificates
|
||||
|
||||
# Install Trivy for container scanning
|
||||
RUN curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin
|
||||
RUN curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/v0.76.2/contrib/install.sh | sh -s -- -b /usr/local/bin v0.76.2
|
||||
|
||||
# Install Grype for vulnerability scanning
|
||||
RUN curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b /usr/local/bin
|
||||
RUN curl -sSfL https://raw.githubusercontent.com/anchore/grype/v0.121.2/install.sh | sh -s -- -b /usr/local/bin v0.121.2
|
||||
|
||||
# Install govulncheck for Go vulnerability scanning
|
||||
RUN go install golang.org/x/vuln/cmd/govulncheck@latest && \
|
||||
RUN go install golang.org/x/vuln/cmd/govulncheck@v1.9.0 && \
|
||||
mv /root/go/bin/govulncheck /usr/local/bin/
|
||||
|
||||
# Install pip-audit for Python package vulnerability scanning
|
||||
RUN pip3 install --no-cache-dir pip-audit --break-system-packages
|
||||
RUN pip3 install --no-cache-dir pip-audit==2.10.1 --break-system-packages
|
||||
|
||||
# Create non-root user
|
||||
RUN addgroup -g 1000 scanner && \
|
||||
|
||||
@@ -113,6 +113,8 @@ security:
|
||||
# When a scan fails on infrastructure (timeout, upstream 5xx) the package is served and the
|
||||
# scan is retried every scan_retry_interval. Set fail_closed to refuse such packages instead.
|
||||
fail_closed: false
|
||||
# How long a first download waits for its scan before it is served (or refused with fail_closed). Default 30s.
|
||||
scan_wait_timeout: "30s"
|
||||
scan_retry_interval: "5m"
|
||||
update_db_on_startup: false # Update vulnerability databases on startup
|
||||
allowed_packages: [] # Packages that bypass security checks (format: "registry/name@version")
|
||||
|
||||
@@ -242,6 +242,7 @@ func (a *App) initializeComponents() error {
|
||||
DeletedRetention: a.config.Cache.DeletedRetention,
|
||||
MaxPackageSize: a.config.Security.Scanners.Static.MaxPackageSize,
|
||||
FailClosed: a.config.Security.FailClosed,
|
||||
ScanWaitTimeout: a.config.Security.ScanWaitTimeout,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to initialize cache: %w", err)
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/lukaszraczylo/gohoarder/pkg/cache"
|
||||
"github.com/lukaszraczylo/gohoarder/pkg/config"
|
||||
"github.com/lukaszraczylo/gohoarder/pkg/errors"
|
||||
)
|
||||
|
||||
// security.scan_wait_timeout bounds how long a first download waits for its scan; with
|
||||
// fail_closed a slow scan is refused at that bound instead of the 30s default.
|
||||
func TestScanWaitTimeoutComesFromConfig(t *testing.T) {
|
||||
release := make(chan struct{})
|
||||
osv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
<-release
|
||||
_, _ = w.Write([]byte(`{"vulns":[]}`))
|
||||
}))
|
||||
defer osv.Close()
|
||||
defer close(release)
|
||||
|
||||
a := newTestApp(t, func(c *config.Config) {
|
||||
c.Security.Enabled = true
|
||||
c.Security.FailClosed = true
|
||||
c.Security.ScanWaitTimeout = 150 * time.Millisecond
|
||||
c.Security.Scanners.OSV.Enabled = true
|
||||
c.Security.Scanners.OSV.APIURL = osv.URL
|
||||
})
|
||||
|
||||
fetch := func(context.Context) (*cache.FetchResult, error) {
|
||||
return &cache.FetchResult{Data: io.NopCloser(strings.NewReader("tarball"))}, nil
|
||||
}
|
||||
start := time.Now()
|
||||
_, err := a.cache.Get(context.Background(), "npm", "left-pad", "1.3.0", fetch)
|
||||
elapsed := time.Since(start)
|
||||
|
||||
var ghErr *errors.Error
|
||||
if err == nil || !asError(err, &ghErr) || ghErr.Code != errors.ErrCodeServiceUnavailable {
|
||||
t.Fatalf("Get = %v, want a service-unavailable refusal", err)
|
||||
}
|
||||
if elapsed > 5*time.Second {
|
||||
t.Fatalf("refusal took %s; the configured 150ms wait was not applied", elapsed)
|
||||
}
|
||||
}
|
||||
|
||||
func asError(err error, target **errors.Error) bool {
|
||||
e, ok := err.(*errors.Error)
|
||||
if ok {
|
||||
*target = e
|
||||
}
|
||||
return ok
|
||||
}
|
||||
@@ -181,6 +181,7 @@ type SecurityConfig struct {
|
||||
BlockThresholds VulnerabilityThresholds `mapstructure:"block_thresholds" json:"block_thresholds"`
|
||||
RescanInterval time.Duration `mapstructure:"rescan_interval" json:"rescan_interval"`
|
||||
ScanRetryInterval time.Duration `mapstructure:"scan_retry_interval" json:"scan_retry_interval"` // wait before retrying a scan that failed on infrastructure; 0 = 5m
|
||||
ScanWaitTimeout time.Duration `mapstructure:"scan_wait_timeout" json:"scan_wait_timeout"` // how long a first download waits for its scan; 0 = 30s
|
||||
FailClosed bool `mapstructure:"fail_closed" json:"fail_closed"` // refuse packages whose scan failed on infrastructure
|
||||
Enabled bool `mapstructure:"enabled" json:"enabled"`
|
||||
ScanOnDownload bool `mapstructure:"scan_on_download" json:"scan_on_download"`
|
||||
|
||||
Reference in New Issue
Block a user