-
Notifications
You must be signed in to change notification settings - Fork 18
Bai 2223 generalise scanners away from security #3139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
IR96334
merged 40 commits into
main
from
BAI-2223-generalise-scanners-away-from-security
Feb 19, 2026
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
5ddd3f6
Some unfinished changes to basic typing
IR96334 e205d23
More scanner generalisation and some small changes/fixes to fileScanning
IR96334 d67ed54
More file scanning alterations
IR96334 f9a7edf
Mass renaing in file scanning files, fixed tests, edited config, edit…
IR96334 5a93031
More extensive config alterations
IR96334 0d21bba
Fixed old property names and renamed directory from fileScanning to a…
IR96334 c8d2004
fixed more tests
IR96334 9c292ca
edited doc file
IR96334 7cf5b04
Fixed mocking
IR96334 0104eb0
temporary fix to wrapper.startScans
IR96334 ae92311
Added vulnerability table functionality for generalisation
IR96334 0f95d09
removed commented out code
IR96334 bf9b353
fixed filescanobject bug
IR96334 1bee2a7
straggling av and virus references
IR96334 36f59bc
fixed tests
IR96334 8ab65d1
Removed the now unnecessary isVulnerable
IR96334 fe8c0b9
Fixed scan chips to update properly, removed repeated functionality, …
IR96334 5deaccb
Migration script, scan result type changes, and coincidental frontend…
IR96334 7b8d166
Added reminder comment
IR96334 c15db7c
more name refactoring
IR96334 c5d306d
Test fixes
IR96334 2359eed
Addressed PR comments
IR96334 a58f7da
solved merge conflicts
IR96334 41c3007
Changes as per PR
IR96334 ff7165f
merge conflict
IR96334 126f925
fixed test
IR96334 3234b7e
Fixed more tests
IR96334 52da255
Addressed PR comments, mostly
IR96334 9b50d51
frontend changes, now included
IR96334 02a5421
Fixed bugs
IR96334 04152a4
revert scope creep
IR96334 7862e53
small change
IR96334 df1d4db
Merge branch 'main' into BAI-2223-generalise-scanners-away-from-security
IR96334 56bf632
fix
IR96334 1e7d2a5
Fix ui issue
IR96334 5076a7e
fixes as pr
IR96334 0c3eb63
test fixes
IR96334 aa6b3cc
fix tests
IR96334 9a76042
Merge branch 'main' into BAI-2223-generalise-scanners-away-from-security
IR96334 31eb60d
Small changes as per PR comments
IR96334 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import PQueue from 'p-queue' | ||
|
|
||
| import { FileInterface } from '../../models/File.js' | ||
| import { ImageRefInterface } from '../../models/Release.js' | ||
| import { ScanInterface } from '../../models/Scan.js' | ||
| import log from '../../services/log.js' | ||
| import { ArtefactTypeKeys } from '../../types/types.js' | ||
|
|
||
| export type ArtefactScanResult = Pick< | ||
| ScanInterface, | ||
| 'toolName' | 'scannerVersion' | 'state' | 'summary' | 'additionalInfo' | 'lastRunAt' | ||
| > | ||
|
|
||
| //NOTE: This is a placeholder, in preparation towards image scanning implementation | ||
| export type ArtefactInterface = FileInterface | ImageRefInterface | ||
|
|
||
| export const ArtefactScanState = { | ||
| NotScanned: 'notScanned', | ||
| InProgress: 'inProgress', | ||
| Complete: 'complete', | ||
| Error: 'error', | ||
| } as const | ||
| export type ArtefactScanStateKeys = (typeof ArtefactScanState)[keyof typeof ArtefactScanState] | ||
|
|
||
| export type ArtefactScanningConnectorInfo = Pick<ArtefactScanResult, 'toolName' | 'scannerVersion'> | ||
|
|
||
| export abstract class ArtefactBaseScanningConnector { | ||
| abstract readonly toolName: string | ||
| abstract readonly version: string | undefined | ||
| abstract readonly queue: PQueue | ||
| abstract artefactType: ArtefactTypeKeys | ||
|
|
||
| info(): ArtefactScanningConnectorInfo { | ||
| return { toolName: this.toolName, scannerVersion: this.version } | ||
| } | ||
|
|
||
| abstract init() | ||
|
|
||
| abstract _scan(artefact: ArtefactInterface): Promise<ArtefactScanResult> | ||
|
|
||
| async scan(artefact: ArtefactInterface): Promise<ArtefactScanResult> { | ||
| log.debug({ artefact, ...this.info(), queueSize: this.queue.size }, 'Queueing scan.') | ||
| const scanResult = await this.queue | ||
| .add(() => this._scan(artefact)) | ||
| .catch((error) => { | ||
| return this.scanError('Queued scan threw an error.', { error, artefact }) | ||
| }) | ||
| // return type of `queue.add()` is Promise<void | ...> so reject void responses | ||
| if (scanResult === null || typeof scanResult !== 'object') { | ||
| return this.scanError('Queued scan failed to correctly return.', { artefact }) | ||
| } | ||
| return scanResult | ||
| } | ||
|
|
||
| async scanError(message: string, context?: object): Promise<ArtefactScanResult> { | ||
| const scannerInfo = this.info() | ||
| log.error({ ...context, ...scannerInfo }, message) | ||
| return { | ||
| ...scannerInfo, | ||
| state: ArtefactScanState.Error, | ||
| lastRunAt: new Date(), | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import config from '../../utils/config.js' | ||
| import { ConfigurationError } from '../../utils/error.js' | ||
| import { ArtefactBaseScanningConnector } from './Base.js' | ||
| import { ClamAvFileScanningConnector } from './clamAv.js' | ||
| import { ModelScanFileScanningConnector } from './modelScan.js' | ||
| import { ArtefactScanningWrapper } from './wrapper.js' | ||
|
|
||
| export const ArtefactScanKind = { | ||
| ClamAv: 'clamAV', | ||
| ModelScan: 'modelScan', | ||
| } as const | ||
| export type ArtefactScanKindKeys = (typeof ArtefactScanKind)[keyof typeof ArtefactScanKind] | ||
|
|
||
| const artefactScanConnectors: Set<ArtefactBaseScanningConnector> = new Set<ArtefactBaseScanningConnector>() | ||
| let scannerWrapper: undefined | ArtefactScanningWrapper = undefined | ||
|
|
||
| async function addArtefactScanners(cache = true): Promise<ArtefactScanningWrapper> { | ||
| if (scannerWrapper && cache) { | ||
| return scannerWrapper | ||
| } | ||
| artefactScanConnectors.clear() | ||
| for (const artefactScanner of config.connectors.artefactScanners.kinds) { | ||
| switch (artefactScanner) { | ||
| case ArtefactScanKind.ClamAv: | ||
| try { | ||
| const scanner = new ClamAvFileScanningConnector() | ||
| artefactScanConnectors.add(scanner) | ||
| } catch (error) { | ||
| throw ConfigurationError('Could not configure or initialise Clam AV', { error }) | ||
| } | ||
| break | ||
| case ArtefactScanKind.ModelScan: | ||
| try { | ||
| const scanner = new ModelScanFileScanningConnector() | ||
| artefactScanConnectors.add(scanner) | ||
| } catch (error) { | ||
| throw ConfigurationError('Could not configure or initialise ModelScan', { error }) | ||
| } | ||
| break | ||
| default: | ||
| throw ConfigurationError(`'${artefactScanner}' is not a valid file scanning kind.`, { | ||
| validKinds: Object.values(ArtefactScanKind), | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| scannerWrapper = new ArtefactScanningWrapper(artefactScanConnectors) | ||
| await scannerWrapper.initialiseScanners() | ||
| return scannerWrapper | ||
| } | ||
|
|
||
| export default await addArtefactScanners() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.