mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-08-23 16:39:18 +00:00
6527bc971b
Scan-policy deploy gates can now block on a known-exploited CVE (CISA KEV) and on a fixable Critical/High finding, in addition to an optional severity threshold. New policies default risk-first (KEV and fixable on, severity off); existing policies keep their severity-only behavior. CVSS stays captured for context but is never the sole basis for a block, and a finding whose exploitability cannot be confirmed is treated as risky rather than safe (incomplete scan detail fails closed on KEV/fixable inputs). The decision logic is shared between the pre-deploy gate and the informational post-scan banner via a pure helper, so the two never disagree. Block messages and the block dialog now name the conditions an image matched. Backend and frontend gates move together, the new inputs replicate across the fleet, and a blocking policy with no active input is rejected on both sides.
111 lines
4.1 KiB
TypeScript
111 lines
4.1 KiB
TypeScript
/**
|
|
* Pins the replica-side filtering of `getScanPoliciesForUi`.
|
|
*
|
|
* On a replica the security-settings panel must only render policies that
|
|
* apply to that replica. Replicated rows with a node_identity targeting a
|
|
* sibling replica are filtered out so an operator cannot enumerate other
|
|
* replicas' identity-scoped rules.
|
|
*/
|
|
import { describe, it, expect, beforeAll, afterAll, beforeEach } from 'vitest';
|
|
import { setupTestDb, cleanupTestDb } from './helpers/setupTestDb';
|
|
|
|
let tmpDir: string;
|
|
let DatabaseService: typeof import('../services/DatabaseService').DatabaseService;
|
|
|
|
beforeAll(async () => {
|
|
tmpDir = await setupTestDb();
|
|
({ DatabaseService } = await import('../services/DatabaseService'));
|
|
});
|
|
|
|
afterAll(() => {
|
|
cleanupTestDb(tmpDir);
|
|
});
|
|
|
|
beforeEach(() => {
|
|
const db = DatabaseService.getInstance();
|
|
// Wipe all replicated and local rows between tests so each scenario starts clean.
|
|
db.clearReplicatedRows();
|
|
for (const p of db.getScanPolicies()) {
|
|
db.deleteScanPolicy(p.id);
|
|
}
|
|
});
|
|
|
|
function seedFleetWideReplicated(name: string): void {
|
|
DatabaseService.getInstance().replaceReplicatedScanPolicies([
|
|
{
|
|
id: 0,
|
|
name,
|
|
node_id: null,
|
|
node_identity: '',
|
|
stack_pattern: '*',
|
|
max_severity: 'HIGH',
|
|
block_on_deploy: 0, block_on_severity: 1, block_on_kev: 0, block_on_fixable: 0,
|
|
enabled: 1,
|
|
replicated_from_control: 1,
|
|
created_at: Date.now(),
|
|
updated_at: Date.now(),
|
|
},
|
|
]);
|
|
}
|
|
|
|
function seedReplicaScopedReplicated(name: string, nodeIdentity: string): void {
|
|
const db = DatabaseService.getInstance();
|
|
// Append-style: read existing replicated rows + the new scoped one.
|
|
const existing = db.getScanPolicies().filter((p) => p.replicated_from_control === 1);
|
|
db.replaceReplicatedScanPolicies([
|
|
...existing,
|
|
{
|
|
id: 0,
|
|
name,
|
|
node_id: null,
|
|
node_identity: nodeIdentity,
|
|
stack_pattern: '*',
|
|
max_severity: 'CRITICAL',
|
|
block_on_deploy: 0, block_on_severity: 1, block_on_kev: 0, block_on_fixable: 0,
|
|
enabled: 1,
|
|
replicated_from_control: 1,
|
|
created_at: Date.now(),
|
|
updated_at: Date.now(),
|
|
},
|
|
]);
|
|
}
|
|
|
|
describe('getScanPoliciesForUi', () => {
|
|
it('returns the full set on a control instance', () => {
|
|
const db = DatabaseService.getInstance();
|
|
seedFleetWideReplicated('fleet-wide');
|
|
seedReplicaScopedReplicated('targets-other', 'https://other.example');
|
|
const result = db.getScanPoliciesForUi('control', 'local');
|
|
expect(result.map((p) => p.name).sort()).toEqual(['fleet-wide', 'targets-other']);
|
|
});
|
|
|
|
it('hides identity-scoped replicated rows that target a different replica', () => {
|
|
const db = DatabaseService.getInstance();
|
|
seedFleetWideReplicated('fleet-wide');
|
|
seedReplicaScopedReplicated('targets-other', 'https://other.example');
|
|
seedReplicaScopedReplicated('targets-self', 'https://me.example');
|
|
const result = db.getScanPoliciesForUi('replica', 'https://me.example');
|
|
const names = result.map((p) => p.name).sort();
|
|
expect(names).toEqual(['fleet-wide', 'targets-self']);
|
|
});
|
|
|
|
it('always includes locally created rows on a replica', () => {
|
|
const db = DatabaseService.getInstance();
|
|
seedReplicaScopedReplicated('targets-other', 'https://other.example');
|
|
db.createScanPolicy({
|
|
name: 'local-on-replica',
|
|
node_id: null,
|
|
node_identity: '',
|
|
stack_pattern: null,
|
|
max_severity: 'CRITICAL',
|
|
block_on_deploy: 0, block_on_severity: 1, block_on_kev: 0, block_on_fixable: 0,
|
|
enabled: 1,
|
|
replicated_from_control: 0,
|
|
});
|
|
const result = db.getScanPoliciesForUi('replica', 'https://me.example');
|
|
const names = result.map((p) => p.name).sort();
|
|
expect(names).toContain('local-on-replica');
|
|
expect(names).not.toContain('targets-other');
|
|
});
|
|
});
|