Skip to content

Commit cffbec8

Browse files
committed
feat(security): skip stopped containers by default in scan task
1 parent 9419154 commit cffbec8

File tree

6 files changed

+57
-17
lines changed

6 files changed

+57
-17
lines changed

.github/renovate.json

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,17 @@
11
{
22
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
3-
"extends": [
4-
"config:recommended",
5-
"docker:pinDigests",
6-
"group:allNonMajor",
7-
"group:allDigest"
8-
],
3+
"extends": ["config:recommended", "docker:pinDigests"],
4+
"ignorePaths": ["**/compose.yml"],
95
"customManagers": [
106
{
117
"customType": "regex",
12-
"managerFilePatterns": [
13-
"/(^|/)Dockerfile$/"
14-
],
15-
"matchStrings": [
16-
"# renovate: datasource=(?<datasource>.*?) lookupName=(?<packageName>.*?)(?: versioning=(?<versioning>.*?))?\\s+ARG\\s+(?<depName>.*?)_VERSION=(?<currentValue>.*)\\s"
17-
]
8+
"managerFilePatterns": ["(^|/)Dockerfile$"],
9+
"matchStrings": ["# renovate: datasource=(?<datasource>.*?) lookupName=(?<packageName>.*?)(?: versioning=(?<versioning>.*?))?\\s+ARG\\s+(?<depName>.*?)_VERSION=(?<currentValue>.*)\\s"]
1810
}
1911
],
2012
"packageRules": [
2113
{
22-
"matchUpdateTypes": [
23-
"major"
24-
],
14+
"matchUpdateTypes": ["major"],
2515
"minimumReleaseAge": "30 days"
2616
}
2717
]

docker/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ ARG COMMIT_MSG=unknown
1414
ENV ATTACHED_DEVICES_PERMS="/var/run/docker.sock"
1515

1616
# Add yq for YAML processing
17+
# renovate: datasource=github-releases lookupName=mikefarah/yq
1718
ARG YQ_VERSION=v4.52.4
1819
RUN curl -sSf -L -o /usr/local/bin/yq "https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_${TARGETARCH}" \
1920
&& chmod +x /usr/local/bin/yq
2021

2122
# Add regctl for container digest checks
23+
# renovate: datasource=github-releases lookupName=regclient/regclient
2224
ARG REGCTL_VERSION=v0.11.2
2325
RUN curl -sSf -L -o /usr/local/bin/regctl "https://github.com/regclient/regclient/releases/download/${REGCTL_VERSION}/regctl-linux-${TARGETARCH}" \
2426
&& chmod +x /usr/local/bin/regctl
@@ -30,6 +32,7 @@ COPY --from=aquasec/trivy:0.69.3@sha256:bcc376de8d77cfe086a917230e818dc9f8528e3c
3032
RUN curl -sSfL https://get.anchore.io/grype | sh -s -- -b /usr/local/bin
3133

3234
# Add snyk for container vulnerability scanning
35+
# renovate: datasource=github-releases lookupName=snyk/cli
3336
ARG SNYK_VERSION=v1.1303.2
3437
RUN SNYK_BINARY=$( [ "$TARGETARCH" = "amd64" ] && echo "snyk-alpine" || echo "snyk-alpine-arm64" ) && \
3538
curl -sSf -L -o /usr/local/bin/snyk "https://github.com/snyk/cli/releases/download/${SNYK_VERSION}/${SNYK_BINARY}" && \

docker/compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ services:
3636
volumes:
3737
- ./nginx.conf:/config/nginx/site-confs/default.conf:ro
3838
restart: unless-stopped
39-
image: lscr.io/linuxserver/nginx:1.28.2@sha256:83e770521fa9370ae98f2e24029d235482b70858002515bdc56f7fad33ab6ae9
39+
image: ghcr.io/linuxserver/nginx:1.28.2
4040

4141
networks:
4242
isolated_nw:

root/app/www/public/ajax/settings.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,13 @@
331331
</td>
332332
<td class="bg-secondary">How long to store past scan files (min 2 days)</td>
333333
</tr>
334+
<tr class="border border-dark border-top-0 border-start-0 border-end-0">
335+
<td class="bg-secondary" scope="row">Skip stopped containers</td>
336+
<td class="bg-secondary">
337+
<input class="form-check-input" type="checkbox" id="globalSetting-securitySkipStopped" <?= $settingsTable['securitySkipStopped'] ? 'checked' : '' ?>>
338+
</td>
339+
<td class="bg-secondary">Do not automatically scan containers that are currently inactive</td>
340+
</tr>
334341
</tbody>
335342
</table>
336343
</div>

root/app/www/public/crons/security.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444
$nameHash = md5($container['name']);
4545
$hash = substr(preg_replace('/sha256\:/', '', $docker->getImageHash($container['image'])), 0, 4);
4646

47-
if (in_array($hash, $imagesScanned)) {
47+
if (in_array($hash, $imagesScanned) || !str_contains($container['status'], 'running') && $settingsTable['securitySkipStopped']) {
48+
logger(CRON_SECURITY_LOG, ' skipped image ' . $container['image']);
49+
echo date(format: 'c') . ' skipped image ' . $container['image'] . "\n";
4850
continue;
4951
}
5052
$imagesScanned[] = $hash;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/*
3+
----------------------------------
4+
------ Created: 032926 ------
5+
------ nzxl ------
6+
----------------------------------
7+
*/
8+
9+
$q = [];
10+
11+
//-- ADD SKIP CONTAINER OPTION AND DELETE OLD TRIVY STUFF
12+
$q[] = "INSERT INTO " . SETTINGS_TABLE . "
13+
(`name`, `value`)
14+
VALUES
15+
('securitySkipStopped', '1')";
16+
$q[] = "DELETE FROM " . SETTINGS_TABLE . "
17+
WHERE name = 'trivyEnabled'";
18+
$q[] = "DELETE FROM " . SETTINGS_TABLE . "
19+
WHERE name = 'trivyScanHour'";
20+
$q[] = "DELETE FROM " . SETTINGS_TABLE . "
21+
WHERE name = 'trivyScanLength'";
22+
23+
//-- ALWAYS NEED TO BUMP THE MIGRATION ID
24+
$q[] = "UPDATE " . SETTINGS_TABLE . "
25+
SET value = '021'
26+
WHERE name = 'migration'";
27+
28+
foreach ($q as $query) {
29+
logger(MIGRATION_LOG, '<span class="text-success">[Q]</span> ' . preg_replace('!\s+!', ' ', $query));
30+
31+
$database->query($query);
32+
33+
if ($database->error() != 'not an error') {
34+
logger(MIGRATION_LOG, '<span class="text-info">[R]</span> ' . $database->error(), 'error');
35+
} else {
36+
logger(MIGRATION_LOG, '<span class="text-info">[R]</span> query applied!');
37+
}
38+
}

0 commit comments

Comments
 (0)