Skip to content

Commit 51079a3

Browse files
authored
Merge pull request #2709 from gchq/dev/improve-scanner-logs
Improve Scanner logs & update config
2 parents 564fa49 + 2597431 commit 51079a3

File tree

6 files changed

+20
-17
lines changed

6 files changed

+20
-17
lines changed

backend/config/default.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,13 @@ module.exports = {
184184

185185
avScanning: {
186186
clamdscan: {
187-
concurrency: 4,
187+
concurrency: 2,
188188
host: '127.0.0.1',
189189
port: 3310,
190190
},
191191

192192
modelscan: {
193-
concurrency: 4,
193+
concurrency: 2,
194194
protocol: 'http',
195195
host: '127.0.0.1',
196196
port: 3311,

backend/src/connectors/fileScanning/Base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export abstract class BaseQueueFileScanningConnector extends BaseFileScanningCon
4949
abstract _scan(file: FileInterface): Promise<FileScanResult[]>
5050

5151
async scan(file: FileInterface): Promise<FileScanResult[]> {
52-
log.debug({ file, toolName: this.toolName, ...(this.version && { version: this.version }) }, 'Queueing scan.')
52+
log.debug({ file, ...this.info(), queueSize: this.queue.size }, 'Queueing scan.')
5353
const scanResult = await this.queue
5454
.add(async () => this._scan(file))
5555
.catch((error) => {

backend/src/connectors/fileScanning/clamAv.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,30 @@ export class ClamAvFileScanningConnector extends BaseQueueFileScanningConnector
3434
this.av = await new NodeClam().init({ clamdscan: config.avScanning.clamdscan })
3535
const scannerVersion = await this.av.getVersion()
3636
this.version = safeParseVersion(scannerVersion)
37-
log.debug({ version: this.version }, 'Initialised Clam AV scanner')
37+
log.debug({ ...this.info() }, 'Initialised Clam AV scanner')
3838
return this
3939
}
4040

4141
async _scan(file: FileInterfaceDoc): Promise<FileScanResult[]> {
42+
const scannerInfo = this.info()
4243
if (!this.av) {
43-
return await this.scanError(`Could not use ${this.toolName} as it is not been correctly initialised.`)
44+
return await this.scanError(`Could not use ${this.toolName} as it is not been correctly initialised.`, {
45+
...scannerInfo,
46+
})
4447
}
4548

4649
const getObjectStreamResponse = await getObjectStream(file.path)
4750
const s3Stream = getObjectStreamResponse.Body as Readable | null
4851
if (!s3Stream) {
49-
return await this.scanError(`Stream for file ${file.path} is not available`)
52+
return await this.scanError(`Stream for file ${file.path} is not available`, { file, ...scannerInfo })
5053
}
5154

5255
try {
5356
const { isInfected, viruses } = await this.av.scanStream(s3Stream)
54-
log.info(
55-
{ modelId: file.modelId, fileId: file._id.toString(), name: file.name, result: { isInfected, viruses } },
56-
'Scan complete.',
57-
)
57+
log.debug({ file, result: { isInfected, viruses }, ...scannerInfo }, 'Scan complete.')
5858
return [
5959
{
60-
...this.info(),
60+
...scannerInfo,
6161
state: ScanState.Complete,
6262
isInfected,
6363
viruses,
@@ -68,6 +68,7 @@ export class ClamAvFileScanningConnector extends BaseQueueFileScanningConnector
6868
return this.scanError(`This file could not be scanned due to an error caused by ${this.toolName}`, {
6969
error,
7070
file,
71+
...scannerInfo,
7172
})
7273
} finally {
7374
if (s3Stream) {

backend/src/connectors/fileScanning/modelScan.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ export class ModelScanFileScanningConnector extends BaseQueueFileScanningConnect
2727
await this.init()
2828
const scannerInfo = this.info()
2929
if (!scannerInfo.scannerVersion) {
30-
return await this.scanError('Could not use ModelScan as it is not running.')
30+
return await this.scanError('Could not use ModelScan as it is not running.', { ...scannerInfo })
3131
}
3232

3333
const getObjectStreamResponse = await getObjectStream(file.path)
3434
const s3Stream = getObjectStreamResponse.Body as Readable | null
3535
if (!s3Stream) {
36-
return await this.scanError(`Stream for file ${file.path} is not available`)
36+
return await this.scanError(`Stream for file ${file.path} is not available`, { file, ...scannerInfo })
3737
}
3838

3939
try {
@@ -43,6 +43,7 @@ export class ModelScanFileScanningConnector extends BaseQueueFileScanningConnect
4343
return this.scanError(`This file could not be scanned due to an error caused by ${this.toolName}`, {
4444
errors: scanResults.errors,
4545
file,
46+
...scannerInfo,
4647
})
4748
}
4849

@@ -51,10 +52,7 @@ export class ModelScanFileScanningConnector extends BaseQueueFileScanningConnect
5152
const viruses: string[] = isInfected
5253
? scanResults.issues.map((issue) => `${issue.severity}: ${issue.description}. ${issue.scanner}`)
5354
: []
54-
log.info(
55-
{ modelId: file.modelId, fileId: file._id.toString(), name: file.name, result: { isInfected, viruses } },
56-
'Scan complete.',
57-
)
55+
log.debug({ file, result: { isInfected, viruses }, ...scannerInfo }, 'Scan complete.')
5856
return [
5957
{
6058
...scannerInfo,

infrastructure/helm/bailo/templates/bailo/bailo.configmap.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@ data:
6464
6565
avScanning: {
6666
clamdscan: {
67+
concurrency: '{{ .Values.clamav.concurrency }}'
6768
host: '{{ include "bailo.fullname" . }}-clamav',
6869
port: {{ .Values.clamav.port }},
6970
},
7071
7172
modelscan: {
73+
concurrency: '{{ .Values.modelscan.concurrency }}'
7274
host: '{{ include "bailo.fullname" . }}-modelscan',
7375
port: {{ .Values.modelscan.port }},
7476
protocol: '{{ .Values.modelscan.protocol }}',

infrastructure/helm/bailo/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,15 @@ clamav:
328328
enabled: false
329329
runAsUser: 1002
330330
image: clamav/clamav:1.4.3_base # https://docs.clamav.net/manual/Installing/Docker.html#the-official-images-on-docker-hub
331+
concurrency: 2
331332
port: 3310
332333
accessModes:
333334
- ReadWriteOnce
334335
size: 10G
335336

336337
modelscan:
337338
enabled: false
339+
concurrency: 2
338340
protocol: http
339341
port: 3311
340342
accessModes:

0 commit comments

Comments
 (0)