mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-07-22 06:20:09 +00:00
Multi-agent audit + fix pass covering bugs, security, dead config wiring,
and missing features. All quality gates green: build/vet/test -race/govulncheck/
golangci-lint. Frontend tests 47/47.
SECURITY & CORRECTNESS
- Scanner pipeline fail-closed: cache.go scan timeout now 503 (was goto servePkg);
scanner.go all-scanners-fail saves ScanStatusError; CheckVulnerabilities blocks
on missing/error result instead of allowing.
- Scanner argv corrections: govulncheck source-mode + go.mod discovery;
npm-audit generates lockfile via npm install --package-lock-only --ignore-scripts;
pip-audit per-extension dispatch (wheel direct / sdist extract+pyproject).
- GHSA version-range filtering implemented (was always-include); url.QueryEscape
on package name.
- pypi SSRF closed via host allowlist on original_url; url.QueryEscape on
rewriteURL output.
- Path traversal: cache temp file uses os.CreateTemp; smb keyToPath sanitized;
filesystem keyToPath returns error + filepath.Abs prefix-verify.
- Goroutine leaks plugged: cache.cleanupWorker stop channel; auth.ValidationCache
Stop() with sync.Once; ws.unregister buffered with non-blocking send.
- WebSocket double-close panic fixed via sync.Once Client.closeSend().
- Race conditions: gormstore.registryCache sync.RWMutex (was concurrent map
panic); auth.LastUsedAt no longer mutated under RLock; analytics strict
lock-ordering invariant (statsMu before downloadsMu).
- Auth validator fails CLOSED on transport/unknown-status errors (was returning
true,err 'allow cache fallback').
- Credential cache hash full SHA256 (was 8-byte truncate; eliminates 2^32
collision risk).
- filesystem.fs.used incremented after successful rename (no quota inflation
race).
- gormstore aggregation events deleted in same tx as insert (no double-counting).
- gormstore.SavePackage uses Updates(map) so zero-value security flags
(RequiresAuth=false) can be cleared.
- partition_manager validates partition name regex before DROP TABLE.
- vcs/git: version regex validation rejects --option-injection; checkout uses
--detach -- separator; removed TrimPrefix(repo,'v') that corrupted vault/
vitess/vim-go.
- WebSocket CheckOrigin allowlist (was return true; CSWSH closed); same-origin
default + ServerConfig.AllowedOrigins.
- fiber CVE GO-2026-4543 patched (v2.52.10 -> v2.52.12).
FUNCTIONAL FEATURES
- API key DB persistence: APIKeyModel + migration 202604280002, full CRUD,
async LastUsedAt updates with WaitGroup-tracked goroutines drained on Close.
- Admin bootstrap via GOHOARDER_BOOTSTRAP_ADMIN_KEY env var; idempotent
(skipped when non-revoked admin already exists).
- Auth middleware factory in pkg/app: RequireAuth, RequireRole, RequirePermission,
OptionalAuth. Mounted on proxy + read APIs when Auth.Enabled=true.
DELETE /api/packages/* requires admin role. /health public for k8s probes.
- NFS storage backend: pkg/storage/nfs wraps filesystem with /proc/mounts
detection (Linux), post-write fsync, read-after-write health probe.
- WebSocket real-time pipeline: pkg/events Broadcaster interface; cache + scanner
managers emit EventPackageCached / EventPackageDownloaded / EventScanComplete;
app.go runs 30s EventStatsUpdate ticker. Frontend has full WS client (reconnect
with exponential backoff 1s->30s, 25s heartbeat, subscriber pattern), Pinia
realtime store, Dashboard live indicator + activity feed + reactive stats
override.
- TLS termination: fiber.ListenTLS when Server.TLS.Enabled.
- Pre-warming: Prewarming.Enabled flag wired (was hardcoded false); Interval,
MaxConcurrent, TopPackages plumbed.
- NetworkConfig wired (timeouts, retry, rate-limit, circuit-breaker).
- AuthConfig.BcryptCost wired.
- Security.Scanners.Static.MaxPackageSize plumbed to cache.io.LimitReader.
- Handlers.{Go,NPM,PyPI}.Enabled gates route mounting.
- Graceful shutdown: authManager.Close drains async writes.
LINT/HYGIENE
- 80 golangci-lint issues resolved: errcheck (Close/Write/RemoveAll wrapped),
gofmt, gosec G104/G306, govet shadow renames + fieldalignment reorders,
staticcheck ST1000 pkg comments + QF1003 tagged switches + QF1008 embedded
field selectors + QF1001 De Morgan's law.
BEHAVIOR CHANGES
- Scanner now fail-closed: deployments without scanner binaries
(trivy/govulncheck/npm-audit/pip-audit/grype) BLOCK packages instead of
serving unscanned. Add binaries or plan a future allow-on-scan-error flag.
- WS origin defaults to same-origin; cross-origin dashboards must set
server.allowed_origins.
- Validator no longer fails open; private packages won't serve from cache when
validation can't be performed.
- download_events retention dropped from 24h to ~5min (deleted in agg tx).
Migration 202604280001 purges pre-upgrade events.
- DELETE /api/packages/* requires admin role when auth enabled.
NEW PACKAGES
- pkg/events - Broadcaster interface
- pkg/storage/nfs - NFS-aware filesystem wrapper
DEFERRED (out of scope this pass)
- Static scanner implementation (config defines AllowedLicenses/MaxPackageSize/
BlockSuspicious but pkg/scanner/static/ does not exist).
- AuthConfig.AuditLog wiring (no audit log infra yet).
- CacheConfig.TTLOverrides passthrough (would touch cache.Config beyond
integrator scope).
411 lines
14 KiB
Vue
411 lines
14 KiB
Vue
<template>
|
|
<div>
|
|
<div class="flex items-center justify-between mb-8">
|
|
<h2 class="text-3xl font-bold text-gray-900">Dashboard</h2>
|
|
<div
|
|
class="flex items-center gap-2 px-3 py-1 rounded-full border text-xs font-medium"
|
|
:class="
|
|
rt.connected
|
|
? 'bg-emerald-50 border-emerald-200 text-emerald-700'
|
|
: 'bg-gray-100 border-gray-200 text-gray-500'
|
|
"
|
|
data-testid="ws-live-indicator"
|
|
>
|
|
<span
|
|
class="w-2 h-2 rounded-full"
|
|
:class="rt.connected ? 'bg-emerald-500 animate-pulse' : 'bg-gray-400'"
|
|
></span>
|
|
{{ rt.connected ? 'Live' : 'Offline' }}
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Error Alert -->
|
|
<Alert v-if="error" variant="destructive" class="mb-4">
|
|
<i class="fas fa-exclamation-circle mr-2"></i>
|
|
<AlertDescription>{{ error }}</AlertDescription>
|
|
</Alert>
|
|
|
|
<!-- Loading State -->
|
|
<div v-if="loading" class="text-center py-12">
|
|
<i class="fas fa-spinner fa-spin text-4xl text-primary-600"></i>
|
|
<p class="mt-4 text-gray-600">Loading statistics...</p>
|
|
</div>
|
|
|
|
<!-- Stats Grid -->
|
|
<div v-else class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-10">
|
|
<Card class="border-0 shadow-lg hover:shadow-xl transition-shadow">
|
|
<CardContent class="p-6">
|
|
<div class="flex items-start justify-between">
|
|
<div class="space-y-2">
|
|
<p class="text-sm font-medium text-muted-foreground">Total Packages</p>
|
|
<p class="text-3xl font-bold text-foreground tracking-tight">
|
|
{{ formatNumber(displayStats?.total_packages || 0) }}
|
|
</p>
|
|
</div>
|
|
<div class="w-12 h-12 bg-slate-100 rounded-xl flex items-center justify-center">
|
|
<i class="fas fa-boxes text-slate-700 text-lg"></i>
|
|
</div>
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
|
|
<Card class="border-0 shadow-lg hover:shadow-xl transition-shadow">
|
|
<CardContent class="p-6">
|
|
<div class="flex items-start justify-between">
|
|
<div class="space-y-2">
|
|
<p class="text-sm font-medium text-muted-foreground">Total Size</p>
|
|
<p class="text-3xl font-bold text-foreground tracking-tight">
|
|
{{ formatBytes(displayStats?.total_size || 0) }}
|
|
</p>
|
|
</div>
|
|
<div class="w-12 h-12 bg-sky-50 rounded-xl flex items-center justify-center">
|
|
<i class="fas fa-hard-drive text-sky-600 text-lg"></i>
|
|
</div>
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
|
|
<Card class="border-0 shadow-lg hover:shadow-xl transition-shadow">
|
|
<CardContent class="p-6">
|
|
<div class="flex items-start justify-between">
|
|
<div class="space-y-2">
|
|
<p class="text-sm font-medium text-muted-foreground">Total Downloads</p>
|
|
<p class="text-3xl font-bold text-foreground tracking-tight">
|
|
{{ formatNumber(displayStats?.total_downloads || 0) }}
|
|
</p>
|
|
</div>
|
|
<div class="w-12 h-12 bg-emerald-50 rounded-xl flex items-center justify-center">
|
|
<i class="fas fa-download text-emerald-600 text-lg"></i>
|
|
</div>
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
|
|
<Card class="border-0 shadow-lg hover:shadow-xl transition-shadow">
|
|
<CardContent class="p-6">
|
|
<div class="flex items-start justify-between">
|
|
<div class="space-y-2">
|
|
<p class="text-sm font-medium text-muted-foreground">Scanned Packages</p>
|
|
<p class="text-3xl font-bold text-foreground tracking-tight">
|
|
{{ formatNumber(displayStats?.scanned_packages || 0) }}
|
|
</p>
|
|
</div>
|
|
<div class="w-12 h-12 bg-violet-50 rounded-xl flex items-center justify-center">
|
|
<i class="fas fa-shield-alt text-violet-600 text-lg"></i>
|
|
</div>
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
|
|
<!-- Realtime Feed -->
|
|
<Card v-if="recentRealtimeEvents.length > 0" class="border-0 shadow-lg mb-10" data-testid="ws-event-feed">
|
|
<CardContent class="p-6">
|
|
<h3 class="text-xl font-semibold text-foreground mb-4">
|
|
<i class="fas fa-bolt mr-2 text-amber-500"></i>Live Activity
|
|
</h3>
|
|
<ul class="space-y-2">
|
|
<li
|
|
v-for="(evt, idx) in recentRealtimeEvents"
|
|
:key="`${evt.timestamp}-${idx}`"
|
|
class="flex items-center gap-3 text-sm"
|
|
>
|
|
<component :is="iconForEvent(evt.type)" class="w-4 h-4 text-muted-foreground" />
|
|
<span class="font-medium">{{ labelForEvent(evt.type) }}</span>
|
|
<span class="text-muted-foreground truncate">
|
|
{{ describeEvent(evt) }}
|
|
</span>
|
|
<span class="ml-auto text-xs text-muted-foreground">
|
|
{{ formatTimestamp(evt.timestamp) }}
|
|
</span>
|
|
</li>
|
|
</ul>
|
|
</CardContent>
|
|
</Card>
|
|
|
|
<!-- Downloads Chart -->
|
|
<Card class="border-0 shadow-lg mb-10">
|
|
<CardContent class="p-6">
|
|
<div class="flex items-center justify-between mb-6">
|
|
<h3 class="text-xl font-semibold text-foreground">Download Activity</h3>
|
|
<div class="flex gap-2">
|
|
<Button
|
|
v-for="period in chartPeriods"
|
|
:key="period.value"
|
|
@click="selectedPeriod = period.value"
|
|
:variant="selectedPeriod === period.value ? 'default' : 'outline'"
|
|
size="sm"
|
|
>
|
|
{{ period.label }}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
<div class="h-64 flex items-end justify-between gap-2">
|
|
<div
|
|
v-for="(value, index) in chartData"
|
|
:key="index"
|
|
class="flex-1 flex flex-col items-center gap-2"
|
|
>
|
|
<div class="w-full bg-slate-100 rounded-t-lg relative" :style="{ height: `${(value / maxChartValue) * 100}%` }">
|
|
<div class="absolute inset-0 bg-gradient-to-t from-slate-700 to-slate-500 rounded-t-lg"></div>
|
|
</div>
|
|
<span class="text-xs text-muted-foreground">{{ getChartLabel(index) }}</span>
|
|
</div>
|
|
</div>
|
|
<div v-if="chartLoading || chartData.length === 0" class="mt-4 text-center">
|
|
<p class="text-sm text-muted-foreground">
|
|
<i class="fas fa-info-circle mr-1"></i>
|
|
{{ chartLoading ? 'Loading chart data...' : 'No download activity in this period' }}
|
|
</p>
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
|
|
<!-- Recent Packages -->
|
|
<Card><CardContent class="p-6">
|
|
<h3 class="text-xl font-semibold text-gray-900 mb-4">
|
|
<i class="fas fa-clock mr-2"></i>Recent Packages
|
|
</h3>
|
|
<div v-if="packages.length === 0" class="text-center py-8 text-gray-500">
|
|
<i class="fas fa-inbox text-4xl mb-4"></i>
|
|
<p>No packages cached yet</p>
|
|
</div>
|
|
<div v-else class="overflow-x-auto">
|
|
<table class="min-w-full divide-y divide-gray-200">
|
|
<thead>
|
|
<tr>
|
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
Package
|
|
</th>
|
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
Version
|
|
</th>
|
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
Registry
|
|
</th>
|
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
Size
|
|
</th>
|
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
Downloads
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="bg-white divide-y divide-gray-200">
|
|
<tr v-for="pkg in recentPackages" :key="pkg.id">
|
|
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
|
|
{{ pkg.name }}
|
|
</td>
|
|
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
|
{{ pkg.version }}
|
|
</td>
|
|
<td class="px-6 py-4 whitespace-nowrap">
|
|
<Badge variant="outline" :class="getRegistryBadgeClass(pkg.registry)">
|
|
{{ pkg.registry }}
|
|
</Badge>
|
|
</td>
|
|
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
|
{{ formatBytes(pkg.size) }}
|
|
</td>
|
|
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
|
{{ formatNumber(pkg.download_count) }}
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { computed, onMounted, ref, watch, type Component } from 'vue'
|
|
import { storeToRefs } from 'pinia'
|
|
import axios from 'axios'
|
|
import {
|
|
Package as PackageIcon,
|
|
Download as DownloadIcon,
|
|
Trash2 as TrashIcon,
|
|
ShieldCheck as ShieldIcon,
|
|
Activity as ActivityIcon,
|
|
} from 'lucide-vue-next'
|
|
import { usePackageStore } from '../stores/packages'
|
|
import { useRealtimeStore } from '../stores/realtime'
|
|
import type { EventType, RealtimeEvent } from '@/lib/ws'
|
|
import { Alert, AlertDescription } from '@/components/ui/alert'
|
|
import { Card, CardContent } from '@/components/ui/card'
|
|
import { Badge } from '@/components/ui/badge'
|
|
import { Button } from '@/components/ui/button'
|
|
import { getRegistryBadgeClass } from '@/composables/useBadgeStyles'
|
|
|
|
const store = usePackageStore()
|
|
const { packages, stats, loading, error } = storeToRefs(store)
|
|
|
|
const rt = useRealtimeStore()
|
|
const { lastStats, events: rtEvents } = storeToRefs(rt)
|
|
|
|
// Realtime stats override polled stats when available; otherwise fall back.
|
|
const displayStats = computed(() => lastStats.value ?? stats.value)
|
|
|
|
const recentRealtimeEvents = computed<RealtimeEvent[]>(() => {
|
|
const list = rtEvents.value
|
|
return list.slice(Math.max(list.length - 5, 0)).reverse()
|
|
})
|
|
|
|
const EVENT_LABELS: Record<EventType, string> = {
|
|
package_cached: 'Cached',
|
|
package_deleted: 'Deleted',
|
|
package_downloaded: 'Downloaded',
|
|
scan_complete: 'Scan complete',
|
|
stats_update: 'Stats update',
|
|
}
|
|
|
|
const EVENT_ICONS: Record<EventType, Component> = {
|
|
package_cached: PackageIcon,
|
|
package_deleted: TrashIcon,
|
|
package_downloaded: DownloadIcon,
|
|
scan_complete: ShieldIcon,
|
|
stats_update: ActivityIcon,
|
|
}
|
|
|
|
function iconForEvent(type: EventType): Component {
|
|
return EVENT_ICONS[type] ?? ActivityIcon
|
|
}
|
|
|
|
function labelForEvent(type: EventType): string {
|
|
return EVENT_LABELS[type] ?? type
|
|
}
|
|
|
|
function describeEvent(evt: RealtimeEvent): string {
|
|
const p = evt.payload
|
|
const name = typeof p.name === 'string' ? p.name : ''
|
|
const version = typeof p.version === 'string' ? `@${p.version}` : ''
|
|
const registry = typeof p.registry === 'string' ? `[${p.registry}] ` : ''
|
|
if (evt.type === 'stats_update') return ''
|
|
if (name) return `${registry}${name}${version}`
|
|
return ''
|
|
}
|
|
|
|
function formatTimestamp(ts: number): string {
|
|
if (!ts) return ''
|
|
return new Date(ts).toLocaleTimeString()
|
|
}
|
|
|
|
// Chart periods and data
|
|
const selectedPeriod = ref<string>('1day')
|
|
const chartPeriods = [
|
|
{ value: '1h', label: '1 Hour' },
|
|
{ value: '1day', label: '24 Hours' },
|
|
{ value: '7day', label: '7 Days' },
|
|
{ value: '30day', label: '30 Days' },
|
|
]
|
|
|
|
// Time-series data from API
|
|
interface TimeSeriesDataPoint {
|
|
timestamp: string
|
|
value: number
|
|
}
|
|
|
|
interface TimeSeriesStats {
|
|
period: string
|
|
registry: string
|
|
data_points: TimeSeriesDataPoint[]
|
|
}
|
|
|
|
const timeSeriesData = ref<TimeSeriesStats | null>(null)
|
|
const chartLoading = ref(false)
|
|
|
|
// Fetch time-series data from API
|
|
async function fetchTimeSeriesData() {
|
|
chartLoading.value = true
|
|
try {
|
|
const response = await axios.get(`/api/stats/timeseries?period=${selectedPeriod.value}`)
|
|
timeSeriesData.value = response.data
|
|
} catch (err) {
|
|
console.error('Failed to fetch time-series data:', err)
|
|
timeSeriesData.value = null
|
|
} finally {
|
|
chartLoading.value = false
|
|
}
|
|
}
|
|
|
|
// Extract chart values from time-series data
|
|
const chartData = computed(() => {
|
|
if (!timeSeriesData.value || !timeSeriesData.value.data_points) {
|
|
return []
|
|
}
|
|
return timeSeriesData.value.data_points.map(point => point.value)
|
|
})
|
|
|
|
const maxChartValue = computed(() => {
|
|
if (chartData.value.length === 0) return 100
|
|
const max = Math.max(...chartData.value)
|
|
return max === 0 ? 100 : max
|
|
})
|
|
|
|
function getChartLabel(index: number): string {
|
|
// Use timestamp from data if available
|
|
if (timeSeriesData.value && timeSeriesData.value.data_points[index]) {
|
|
const date = new Date(timeSeriesData.value.data_points[index].timestamp)
|
|
|
|
switch (selectedPeriod.value) {
|
|
case '1h':
|
|
return date.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' })
|
|
case '1day':
|
|
return date.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' })
|
|
case '7day':
|
|
return date.toLocaleDateString('en-US', { weekday: 'short' })
|
|
case '30day':
|
|
return date.toLocaleDateString('en-US', { day: 'numeric' })
|
|
default:
|
|
return `${index}`
|
|
}
|
|
}
|
|
|
|
// Fallback to index-based labels
|
|
const labels: Record<string, (i: number) => string> = {
|
|
'1h': (i) => `${i * 5}m`,
|
|
'1day': (i) => `${i}:00`,
|
|
'7day': (i) => ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'][i] || `Day ${i + 1}`,
|
|
'30day': (i) => `${i + 1}`,
|
|
}
|
|
return labels[selectedPeriod.value]?.(index) || `${index}`
|
|
}
|
|
|
|
// API returns clean, deduplicated data - just sort and limit
|
|
const recentPackages = computed(() => {
|
|
return packages.value
|
|
.slice()
|
|
.sort((a, b) => new Date(b.cached_at).getTime() - new Date(a.cached_at).getTime())
|
|
.slice(0, 10)
|
|
})
|
|
|
|
// Watch for period changes and fetch new data
|
|
watch(selectedPeriod, () => {
|
|
fetchTimeSeriesData()
|
|
})
|
|
|
|
onMounted(async () => {
|
|
// Connect to realtime stream first so we can pick up live events while
|
|
// initial polling resolves. Singleton survives navigation, so we
|
|
// intentionally do not disconnect on unmount.
|
|
rt.connect()
|
|
await store.fetchStats()
|
|
await store.fetchPackages()
|
|
await fetchTimeSeriesData()
|
|
})
|
|
|
|
function formatNumber(num: number): string {
|
|
return new Intl.NumberFormat().format(num)
|
|
}
|
|
|
|
function formatBytes(bytes: number): string {
|
|
if (bytes === 0) return '0 B'
|
|
const k = 1024
|
|
const sizes = ['B', 'KB', 'MB', 'GB', 'TB']
|
|
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
|
return Math.round(bytes / Math.pow(k, i) * 100) / 100 + ' ' + sizes[i]
|
|
}
|
|
</script>
|