mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-08-15 05:03:14 +00:00
fcd44f5693
* fix(security): tie fixable CVE posture to image-update evidence Stop treating Trivy fixed_version alone as an Update affected images CTA. Reuse persisted ImageUpdateService status so Security only offers Review update when an applicable image update is confirmed, and otherwise surfaces waiting or uncertain remediation with truthful affordances. * fix(security): move image-update recheck helper out of OverviewTab Satisfy react-refresh/only-export-components so Frontend lint passes. * fix(security): preserve posture reason image targets in Images drill-down Carry affected image refs on overview reasons so public exposure and related CTAs open a clearable targeted Images list instead of an unfiltered hunt. * fix(security): attach Networking exposure intent to posture targets Preserve stack/service context and intentional classification on network-exposed Security reasons without suppressing risk or claiming Internet reachability. * fix(security): persist Images exposure intent and triage scope Standing image summaries carry Networking intent context with cap-safe aggregates, Anatomy Networking links, and scan-sheet triage that defaults to the current image. * fix(security): clear CI lint errors for exposure helpers * fix(security): stop intentional exposure from forcing Action needed Separate exposure fact, intent correctness, and vulnerability drivers so package fixed_version cannot recreate a permanent public_exposure blocker. * fix(security): define Monitoring residual-risk narrative * fix(security): define Secure via residual Crit/High triage Replace triage-blind raw Crit/High Secure gating with residual material risk so accepted and ignored stay Monitoring, while not_affected, false positive, and fixed can clear residual without claiming no detections. * fix(security): exclude rollback-hold images from Security scans Hold-only sencho-rb tags are recovery state; keep them out of Trivy node scans, Security inventory, and Overview posture while dual-tagged images remain under their registry tag. * fix(security): keep authoritative no-update rows after preview Opening a stack page must not delete ok+false stack_update_status evidence; Security treats a missing row as uncertain and would flip waiting-upstream to unknown.
270 lines
8.7 KiB
TypeScript
270 lines
8.7 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
||
import {
|
||
classifyImageRemediation,
|
||
buildUpdateServiceIndex,
|
||
} from '../services/securityImageRemediation';
|
||
import type { StackServiceStatus, StackUpdateDetail } from '../services/DatabaseService';
|
||
|
||
const HOUR = 60 * 60 * 1000;
|
||
const NOW = 1_700_000_000_000;
|
||
const FRESH_WINDOW = 4 * HOUR;
|
||
|
||
function service(partial: Partial<StackServiceStatus> & Pick<StackServiceStatus, 'service'>): StackServiceStatus {
|
||
return {
|
||
image: 'nginx:1.25',
|
||
hasUpdate: false,
|
||
checkStatus: 'ok',
|
||
lastError: null,
|
||
...partial,
|
||
};
|
||
}
|
||
|
||
function detail(
|
||
services: StackServiceStatus[],
|
||
opts: { checkedAt?: number; hasUpdate?: boolean; checkStatus?: 'ok' | 'partial' | 'failed' } = {},
|
||
): StackUpdateDetail {
|
||
return {
|
||
hasUpdate: opts.hasUpdate ?? services.some((s) => s.hasUpdate),
|
||
checkStatus: opts.checkStatus ?? 'ok',
|
||
lastError: null,
|
||
checkedAt: opts.checkedAt ?? NOW - HOUR,
|
||
services,
|
||
};
|
||
}
|
||
|
||
describe('buildUpdateServiceIndex', () => {
|
||
it('indexes declared image and runtimeImages through normalizeImageRef', () => {
|
||
const index = buildUpdateServiceIndex({
|
||
web: detail([
|
||
service({
|
||
service: 'app',
|
||
image: 'docker.io/library/nginx',
|
||
runtimeImages: ['nginx:1.25'],
|
||
}),
|
||
]),
|
||
});
|
||
expect(index.has('nginx:latest')).toBe(true);
|
||
expect(index.has('nginx:1.25')).toBe(true);
|
||
});
|
||
});
|
||
|
||
describe('classifyImageRemediation', () => {
|
||
it('counts confirmed updates only when hasUpdate and checkStatus are ok', () => {
|
||
const facts = classifyImageRemediation({
|
||
findings: [{ image_ref: 'nginx:1.25', count: 3 }],
|
||
details: {
|
||
web: detail([service({ service: 'app', image: 'nginx:1.25', hasUpdate: true, checkStatus: 'ok' })]),
|
||
},
|
||
checksEnabled: true,
|
||
freshnessWindowMs: FRESH_WINDOW,
|
||
now: NOW,
|
||
});
|
||
expect(facts).toEqual({
|
||
fixableWithImageUpdate: 3,
|
||
fixableWaitingUpstream: 0,
|
||
fixableUpdateUnknown: 0,
|
||
updateChecksDisabled: false,
|
||
imageRefsUpdateAvailable: ['nginx:1.25'],
|
||
imageRefsWaitingUpstream: [],
|
||
imageRefsUpdateUnknown: [],
|
||
});
|
||
});
|
||
|
||
it('treats sticky partial hasUpdate as uncertain, never update_available', () => {
|
||
const facts = classifyImageRemediation({
|
||
findings: [{ image_ref: 'nginx:1.25', count: 2 }],
|
||
details: {
|
||
web: detail([service({ service: 'app', image: 'nginx:1.25', hasUpdate: true, checkStatus: 'partial' })]),
|
||
},
|
||
checksEnabled: true,
|
||
freshnessWindowMs: FRESH_WINDOW,
|
||
now: NOW,
|
||
});
|
||
expect(facts.fixableWithImageUpdate).toBe(0);
|
||
expect(facts.fixableUpdateUnknown).toBe(2);
|
||
expect(facts.fixableWaitingUpstream).toBe(0);
|
||
});
|
||
|
||
it('treats not_checkable as uncertain, never waiting_upstream', () => {
|
||
const facts = classifyImageRemediation({
|
||
findings: [{ image_ref: 'myapp:local', count: 1 }],
|
||
details: {
|
||
web: detail([service({
|
||
service: 'app',
|
||
image: 'myapp:local',
|
||
hasUpdate: false,
|
||
checkStatus: 'not_checkable',
|
||
})]),
|
||
},
|
||
checksEnabled: true,
|
||
freshnessWindowMs: FRESH_WINDOW,
|
||
now: NOW,
|
||
});
|
||
expect(facts.fixableWaitingUpstream).toBe(0);
|
||
expect(facts.fixableUpdateUnknown).toBe(1);
|
||
});
|
||
|
||
it('authoritative negative becomes waiting_upstream when fresh', () => {
|
||
const facts = classifyImageRemediation({
|
||
findings: [{ image_ref: 'nginx:1.25', count: 4 }],
|
||
details: {
|
||
web: detail([service({ service: 'app', image: 'nginx:1.25', hasUpdate: false, checkStatus: 'ok' })]),
|
||
},
|
||
checksEnabled: true,
|
||
freshnessWindowMs: FRESH_WINDOW,
|
||
now: NOW,
|
||
});
|
||
expect(facts.fixableWaitingUpstream).toBe(4);
|
||
expect(facts.fixableWithImageUpdate).toBe(0);
|
||
expect(facts.fixableUpdateUnknown).toBe(0);
|
||
});
|
||
|
||
it('stale stack-level checkedAt yields uncertain, not waiting (R4)', () => {
|
||
const facts = classifyImageRemediation({
|
||
findings: [{ image_ref: 'nginx:1.25', count: 1 }],
|
||
details: {
|
||
web: detail(
|
||
[service({ service: 'app', image: 'nginx:1.25', hasUpdate: false, checkStatus: 'ok' })],
|
||
{ checkedAt: NOW - (FRESH_WINDOW + 1) },
|
||
),
|
||
},
|
||
checksEnabled: true,
|
||
freshnessWindowMs: FRESH_WINDOW,
|
||
now: NOW,
|
||
});
|
||
expect(facts.fixableWaitingUpstream).toBe(0);
|
||
expect(facts.fixableUpdateUnknown).toBe(1);
|
||
});
|
||
|
||
it('digest-pinned finding does not match tag-declared service (uncertain)', () => {
|
||
const facts = classifyImageRemediation({
|
||
findings: [{ image_ref: 'nginx@sha256:abc', count: 1 }],
|
||
details: {
|
||
web: detail([service({ service: 'app', image: 'nginx:1.25', hasUpdate: false, checkStatus: 'ok' })]),
|
||
},
|
||
checksEnabled: true,
|
||
freshnessWindowMs: FRESH_WINDOW,
|
||
now: NOW,
|
||
});
|
||
expect(facts.fixableWaitingUpstream).toBe(0);
|
||
expect(facts.fixableUpdateUnknown).toBe(1);
|
||
});
|
||
|
||
it('disabled checks put all package-fix findings in uncertain', () => {
|
||
const facts = classifyImageRemediation({
|
||
findings: [{ image_ref: 'nginx:1.25', count: 5 }],
|
||
details: {
|
||
web: detail([service({ service: 'app', image: 'nginx:1.25', hasUpdate: true, checkStatus: 'ok' })]),
|
||
},
|
||
checksEnabled: false,
|
||
freshnessWindowMs: FRESH_WINDOW,
|
||
now: NOW,
|
||
});
|
||
expect(facts).toEqual({
|
||
fixableWithImageUpdate: 0,
|
||
fixableWaitingUpstream: 0,
|
||
fixableUpdateUnknown: 5,
|
||
updateChecksDisabled: true,
|
||
imageRefsUpdateAvailable: [],
|
||
imageRefsWaitingUpstream: [],
|
||
imageRefsUpdateUnknown: ['nginx:1.25'],
|
||
});
|
||
});
|
||
|
||
it('missing stack membership is uncertain', () => {
|
||
const facts = classifyImageRemediation({
|
||
findings: [{ image_ref: 'orphan:1', count: 2 }],
|
||
details: {},
|
||
checksEnabled: true,
|
||
freshnessWindowMs: FRESH_WINDOW,
|
||
now: NOW,
|
||
});
|
||
expect(facts.fixableUpdateUnknown).toBe(2);
|
||
});
|
||
|
||
it('matches via runtimeImages when declared image differs', () => {
|
||
const facts = classifyImageRemediation({
|
||
findings: [{ image_ref: 'nginx:1.25.3', count: 1 }],
|
||
details: {
|
||
web: detail([service({
|
||
service: 'app',
|
||
image: 'nginx:1.25',
|
||
runtimeImages: ['nginx:1.25.3'],
|
||
hasUpdate: true,
|
||
checkStatus: 'ok',
|
||
})]),
|
||
},
|
||
checksEnabled: true,
|
||
freshnessWindowMs: FRESH_WINDOW,
|
||
now: NOW,
|
||
});
|
||
expect(facts.fixableWithImageUpdate).toBe(1);
|
||
});
|
||
|
||
it('cron-sized freshness window still allows authoritative negatives', () => {
|
||
// Daily cron → 2×24h = 48h window (clamped max). A check from 12h ago is fresh.
|
||
const cronWindow = 48 * HOUR;
|
||
const facts = classifyImageRemediation({
|
||
findings: [{ image_ref: 'nginx:1.25', count: 1 }],
|
||
details: {
|
||
web: detail(
|
||
[service({ service: 'app', image: 'nginx:1.25', hasUpdate: false, checkStatus: 'ok' })],
|
||
{ checkedAt: NOW - 12 * HOUR },
|
||
),
|
||
},
|
||
checksEnabled: true,
|
||
freshnessWindowMs: cronWindow,
|
||
now: NOW,
|
||
});
|
||
expect(facts.fixableWaitingUpstream).toBe(1);
|
||
});
|
||
|
||
it('confirmed update on one stack wins over sibling partial sticky hasUpdate', () => {
|
||
const facts = classifyImageRemediation({
|
||
findings: [{ image_ref: 'nginx:1.25', count: 1 }],
|
||
details: {
|
||
web: detail([service({ service: 'app', image: 'nginx:1.25', hasUpdate: true, checkStatus: 'ok' })]),
|
||
api: detail([service({ service: 'app', image: 'nginx:1.25', hasUpdate: true, checkStatus: 'partial' })]),
|
||
},
|
||
checksEnabled: true,
|
||
freshnessWindowMs: FRESH_WINDOW,
|
||
now: NOW,
|
||
});
|
||
expect(facts.fixableWithImageUpdate).toBe(1);
|
||
expect(facts.fixableUpdateUnknown).toBe(0);
|
||
});
|
||
|
||
it('partial-only sticky hasUpdate stays uncertain', () => {
|
||
const facts = classifyImageRemediation({
|
||
findings: [{ image_ref: 'nginx:1.25', count: 1 }],
|
||
details: {
|
||
api: detail([service({ service: 'app', image: 'nginx:1.25', hasUpdate: true, checkStatus: 'partial' })]),
|
||
},
|
||
checksEnabled: true,
|
||
freshnessWindowMs: FRESH_WINDOW,
|
||
now: NOW,
|
||
});
|
||
expect(facts.fixableWithImageUpdate).toBe(0);
|
||
expect(facts.fixableUpdateUnknown).toBe(1);
|
||
});
|
||
|
||
it('returns raw finding image_ref even when stack match used normalizeImageRef', () => {
|
||
const facts = classifyImageRemediation({
|
||
findings: [{ image_ref: 'nginx:1.14', count: 2 }],
|
||
details: {
|
||
web: detail([service({
|
||
service: 'app',
|
||
image: 'docker.io/library/nginx:1.14',
|
||
hasUpdate: true,
|
||
checkStatus: 'ok',
|
||
})]),
|
||
},
|
||
checksEnabled: true,
|
||
freshnessWindowMs: FRESH_WINDOW,
|
||
now: NOW,
|
||
});
|
||
expect(facts.fixableWithImageUpdate).toBe(2);
|
||
expect(facts.imageRefsUpdateAvailable).toEqual(['nginx:1.14']);
|
||
});
|
||
});
|