dockerls 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dockerls/__init__.py +31 -0
- dockerls/application/__init__.py +0 -0
- dockerls/application/dto/__init__.py +3 -0
- dockerls/application/dto/analysis.py +257 -0
- dockerls/application/services/__init__.py +0 -0
- dockerls/application/services/alternatives_lookup.py +167 -0
- dockerls/application/services/composite_repository.py +106 -0
- dockerls/application/services/cross_validation.py +233 -0
- dockerls/application/services/ecosystems.py +350 -0
- dockerls/application/services/fallback_scanner.py +97 -0
- dockerls/application/services/hardening_analysis.py +174 -0
- dockerls/application/services/migration.py +297 -0
- dockerls/application/services/progress.py +56 -0
- dockerls/application/services/remediation.py +321 -0
- dockerls/application/services/scan_history_store.py +88 -0
- dockerls/application/services/scanner_factory.py +88 -0
- dockerls/application/services/source_registry.py +151 -0
- dockerls/application/services/tag_history_store.py +76 -0
- dockerls/application/services/teardown.py +50 -0
- dockerls/application/services/verdict.py +298 -0
- dockerls/application/services/version_discovery.py +108 -0
- dockerls/application/use_cases/__init__.py +0 -0
- dockerls/application/use_cases/analyze_dockerfile.py +103 -0
- dockerls/application/use_cases/analyze_image.py +173 -0
- dockerls/application/use_cases/build_image.py +1795 -0
- dockerls/application/use_cases/compare_images.py +91 -0
- dockerls/application/use_cases/fleet_scan.py +240 -0
- dockerls/application/use_cases/recommend_images.py +1078 -0
- dockerls/application/use_cases/registry_audit.py +133 -0
- dockerls/application/use_cases/search_images.py +23 -0
- dockerls/application/use_cases/upgrade_base.py +167 -0
- dockerls/cache/__init__.py +0 -0
- dockerls/cache/sqlite_cache.py +184 -0
- dockerls/cli/__init__.py +0 -0
- dockerls/cli/analysis_baseline.py +98 -0
- dockerls/cli/app.py +294 -0
- dockerls/cli/commands/__init__.py +0 -0
- dockerls/cli/commands/advisor.py +262 -0
- dockerls/cli/commands/alternatives.py +291 -0
- dockerls/cli/commands/analyze.py +429 -0
- dockerls/cli/commands/analyze_dockerfile.py +104 -0
- dockerls/cli/commands/base_cmd.py +244 -0
- dockerls/cli/commands/base_image.py +551 -0
- dockerls/cli/commands/build.py +1300 -0
- dockerls/cli/commands/cache_cmd.py +104 -0
- dockerls/cli/commands/compare.py +177 -0
- dockerls/cli/commands/controls.py +110 -0
- dockerls/cli/commands/doctor.py +566 -0
- dockerls/cli/commands/export.py +81 -0
- dockerls/cli/commands/fleet.py +159 -0
- dockerls/cli/commands/health.py +84 -0
- dockerls/cli/commands/login.py +53 -0
- dockerls/cli/commands/policy_cmd.py +111 -0
- dockerls/cli/commands/provenance_cmd.py +162 -0
- dockerls/cli/commands/recommend.py +761 -0
- dockerls/cli/commands/registry_audit_cmd.py +103 -0
- dockerls/cli/commands/sbom.py +144 -0
- dockerls/cli/commands/search.py +86 -0
- dockerls/cli/commands/verify.py +115 -0
- dockerls/cli/commands/version.py +12 -0
- dockerls/cli/commands/vex_cmd.py +117 -0
- dockerls/cli/dependencies.py +530 -0
- dockerls/cli/image_names.py +79 -0
- dockerls/cli/options.py +42 -0
- dockerls/cli/progress.py +145 -0
- dockerls/cli/publish_prompt.py +123 -0
- dockerls/cli/rendering.py +214 -0
- dockerls/cli/runtime.py +65 -0
- dockerls/cli/scan_failure.py +71 -0
- dockerls/cli/text.py +39 -0
- dockerls/cli/validators.py +35 -0
- dockerls/cli/vulnerability_view.py +154 -0
- dockerls/domain/__init__.py +0 -0
- dockerls/domain/entities/__init__.py +75 -0
- dockerls/domain/entities/declared_metadata.py +147 -0
- dockerls/domain/entities/dockerfile_analysis.py +318 -0
- dockerls/domain/entities/image.py +109 -0
- dockerls/domain/entities/image_facts.py +137 -0
- dockerls/domain/entities/recommendation.py +33 -0
- dockerls/domain/entities/scan_result.py +129 -0
- dockerls/domain/entities/vulnerability.py +232 -0
- dockerls/domain/interfaces/__init__.py +17 -0
- dockerls/domain/interfaces/cache_store.py +18 -0
- dockerls/domain/interfaces/dockerfile_validator.py +99 -0
- dockerls/domain/interfaces/eol_checker.py +11 -0
- dockerls/domain/interfaces/image_repository.py +15 -0
- dockerls/domain/interfaces/scanner.py +15 -0
- dockerls/domain/security_controls.py +362 -0
- dockerls/domain/value_objects/__init__.py +49 -0
- dockerls/domain/value_objects/attack_surface.py +198 -0
- dockerls/domain/value_objects/base_recipe.py +600 -0
- dockerls/domain/value_objects/base_upgrade.py +292 -0
- dockerls/domain/value_objects/build_labels.py +99 -0
- dockerls/domain/value_objects/build_policy.py +412 -0
- dockerls/domain/value_objects/confidence.py +156 -0
- dockerls/domain/value_objects/fleet.py +174 -0
- dockerls/domain/value_objects/gate.py +327 -0
- dockerls/domain/value_objects/hardening.py +303 -0
- dockerls/domain/value_objects/image_reference.py +90 -0
- dockerls/domain/value_objects/inheritance.py +352 -0
- dockerls/domain/value_objects/network_policy.py +280 -0
- dockerls/domain/value_objects/production_readiness.py +145 -0
- dockerls/domain/value_objects/provenance.py +211 -0
- dockerls/domain/value_objects/recipe_diff.py +188 -0
- dockerls/domain/value_objects/registry_audit.py +195 -0
- dockerls/domain/value_objects/registry_target.py +225 -0
- dockerls/domain/value_objects/remediation_score.py +62 -0
- dockerls/domain/value_objects/scan_history.py +183 -0
- dockerls/domain/value_objects/scan_plan.py +193 -0
- dockerls/domain/value_objects/scanner_db.py +143 -0
- dockerls/domain/value_objects/security_score.py +160 -0
- dockerls/domain/value_objects/security_tier.py +122 -0
- dockerls/domain/value_objects/tag_history.py +180 -0
- dockerls/domain/value_objects/tool_release.py +253 -0
- dockerls/domain/value_objects/tristate.py +47 -0
- dockerls/domain/value_objects/vex.py +249 -0
- dockerls/exit_codes.py +23 -0
- dockerls/exporters/__init__.py +0 -0
- dockerls/exporters/base.py +17 -0
- dockerls/exporters/csv_exporter.py +85 -0
- dockerls/exporters/factory.py +31 -0
- dockerls/exporters/html_exporter.py +105 -0
- dockerls/exporters/json_exporter.py +19 -0
- dockerls/exporters/markdown_exporter.py +84 -0
- dockerls/exporters/sarif_exporter.py +245 -0
- dockerls/infrastructure/__init__.py +0 -0
- dockerls/infrastructure/config/__init__.py +0 -0
- dockerls/infrastructure/config/policy_file.py +165 -0
- dockerls/infrastructure/config/settings.py +197 -0
- dockerls/infrastructure/database/__init__.py +0 -0
- dockerls/infrastructure/database/models.py +78 -0
- dockerls/infrastructure/dockerfile_validator.py +1899 -0
- dockerls/infrastructure/evidence.py +99 -0
- dockerls/infrastructure/hashing.py +165 -0
- dockerls/infrastructure/logging/__init__.py +0 -0
- dockerls/infrastructure/logging/setup.py +98 -0
- dockerls/infrastructure/network/__init__.py +0 -0
- dockerls/infrastructure/network/guarded_client.py +107 -0
- dockerls/infrastructure/network/host_guard.py +117 -0
- dockerls/infrastructure/redaction.py +135 -0
- dockerls/infrastructure/templates/hardening/alpine.dockerfile +44 -0
- dockerls/infrastructure/templates/hardening/debian.dockerfile +45 -0
- dockerls/infrastructure/templates/hardening/distroless.dockerfile +34 -0
- dockerls/infrastructure/templates/hardening/go-alpine.dockerfile +52 -0
- dockerls/infrastructure/templates/hardening/go-debian.dockerfile +54 -0
- dockerls/infrastructure/templates/hardening/go-distroless.dockerfile +43 -0
- dockerls/infrastructure/templates/hardening/go-scratch.dockerfile +48 -0
- dockerls/infrastructure/templates/hardening/go.dockerfile +50 -0
- dockerls/infrastructure/templates/hardening/gradle-alpine.dockerfile +51 -0
- dockerls/infrastructure/templates/hardening/gradle.dockerfile +52 -0
- dockerls/infrastructure/templates/hardening/java-alpine.dockerfile +50 -0
- dockerls/infrastructure/templates/hardening/java-debian.dockerfile +50 -0
- dockerls/infrastructure/templates/hardening/java-distroless.dockerfile +39 -0
- dockerls/infrastructure/templates/hardening/java-ubuntu.dockerfile +54 -0
- dockerls/infrastructure/templates/hardening/java.dockerfile +60 -0
- dockerls/infrastructure/templates/hardening/maven-alpine.dockerfile +56 -0
- dockerls/infrastructure/templates/hardening/maven.dockerfile +57 -0
- dockerls/infrastructure/templates/hardening/node-alpine.dockerfile +47 -0
- dockerls/infrastructure/templates/hardening/node-debian.dockerfile +54 -0
- dockerls/infrastructure/templates/hardening/node-distroless.dockerfile +46 -0
- dockerls/infrastructure/templates/hardening/node-ubuntu.dockerfile +63 -0
- dockerls/infrastructure/templates/hardening/node.dockerfile +61 -0
- dockerls/infrastructure/templates/hardening/php-alpine.dockerfile +45 -0
- dockerls/infrastructure/templates/hardening/php-debian.dockerfile +45 -0
- dockerls/infrastructure/templates/hardening/php-ubuntu.dockerfile +49 -0
- dockerls/infrastructure/templates/hardening/php.dockerfile +44 -0
- dockerls/infrastructure/templates/hardening/python-alpine.dockerfile +51 -0
- dockerls/infrastructure/templates/hardening/python-debian.dockerfile +54 -0
- dockerls/infrastructure/templates/hardening/python-distroless.dockerfile +51 -0
- dockerls/infrastructure/templates/hardening/python-ubuntu.dockerfile +60 -0
- dockerls/infrastructure/templates/hardening/python.dockerfile +58 -0
- dockerls/infrastructure/templates/hardening/ruby-alpine.dockerfile +48 -0
- dockerls/infrastructure/templates/hardening/ruby-debian.dockerfile +50 -0
- dockerls/infrastructure/templates/hardening/rust-alpine.dockerfile +50 -0
- dockerls/infrastructure/templates/hardening/rust-debian.dockerfile +48 -0
- dockerls/infrastructure/templates/hardening/rust-scratch.dockerfile +44 -0
- dockerls/infrastructure/templates/hardening/rust.dockerfile +54 -0
- dockerls/infrastructure/templates/hardening/ubuntu.dockerfile +49 -0
- dockerls/infrastructure/toolchain/__init__.py +0 -0
- dockerls/infrastructure/toolchain/db_metadata.py +115 -0
- dockerls/infrastructure/toolchain/installer.py +435 -0
- dockerls/integrations/__init__.py +0 -0
- dockerls/integrations/dhi/__init__.py +0 -0
- dockerls/integrations/dhi/catalog.py +457 -0
- dockerls/integrations/dhi/definition.py +151 -0
- dockerls/integrations/dhi/repository.py +238 -0
- dockerls/integrations/dockerhub/__init__.py +0 -0
- dockerls/integrations/dockerhub/client.py +318 -0
- dockerls/integrations/dockerhub/urls.py +75 -0
- dockerls/integrations/endoflife/__init__.py +0 -0
- dockerls/integrations/endoflife/checker.py +216 -0
- dockerls/integrations/engine/__init__.py +0 -0
- dockerls/integrations/engine/batch.py +197 -0
- dockerls/integrations/engine/client.py +330 -0
- dockerls/integrations/engine/locator.py +96 -0
- dockerls/integrations/exploitdb/__init__.py +0 -0
- dockerls/integrations/exploitdb/client.py +271 -0
- dockerls/integrations/grype/__init__.py +0 -0
- dockerls/integrations/grype/scanner.py +336 -0
- dockerls/integrations/registry/__init__.py +0 -0
- dockerls/integrations/registry/hardened.py +284 -0
- dockerls/integrations/registry/inspector.py +420 -0
- dockerls/integrations/registry/oci.py +259 -0
- dockerls/integrations/registry/private.py +79 -0
- dockerls/integrations/registry/urls.py +36 -0
- dockerls/integrations/scan_errors.py +67 -0
- dockerls/integrations/scan_target.py +57 -0
- dockerls/integrations/signing/__init__.py +0 -0
- dockerls/integrations/signing/cosign.py +484 -0
- dockerls/integrations/threat_intel/__init__.py +0 -0
- dockerls/integrations/threat_intel/client.py +290 -0
- dockerls/integrations/trivy/__init__.py +0 -0
- dockerls/integrations/trivy/cache_pool.py +176 -0
- dockerls/integrations/trivy/scanner.py +447 -0
- dockerls/utils/__init__.py +0 -0
- dockerls/utils/auth.py +108 -0
- dockerls/utils/executables.py +39 -0
- dockerls/utils/ignore_file.py +130 -0
- dockerls/utils/rate_limit.py +130 -0
- dockerls/utils/resources.py +183 -0
- dockerls/utils/retry.py +31 -0
- dockerls/utils/safe_yaml.py +166 -0
- dockerls/utils/subprocess_runner.py +216 -0
- dockerls/utils/validation.py +72 -0
- dockerls-1.0.0.dist-info/METADATA +563 -0
- dockerls-1.0.0.dist-info/RECORD +230 -0
- dockerls-1.0.0.dist-info/WHEEL +5 -0
- dockerls-1.0.0.dist-info/entry_points.txt +2 -0
- dockerls-1.0.0.dist-info/licenses/LICENSE +21 -0
- dockerls-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Dockerfile.hardened.php-ubuntu
|
|
2
|
+
# Hardened template for PHP 8.3 (Ubuntu 24.04 LTS)
|
|
3
|
+
|
|
4
|
+
ARG UBUNTU_VERSION=24.04
|
|
5
|
+
ARG COMPOSER_VERSION=2
|
|
6
|
+
|
|
7
|
+
# Stage 1: Composer dependencies
|
|
8
|
+
FROM composer:${COMPOSER_VERSION} AS vendor
|
|
9
|
+
|
|
10
|
+
WORKDIR /app
|
|
11
|
+
COPY composer.json composer.lock ./
|
|
12
|
+
RUN composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader || true
|
|
13
|
+
|
|
14
|
+
# Stage 2: PHP Runtime
|
|
15
|
+
FROM ubuntu:${UBUNTU_VERSION}
|
|
16
|
+
|
|
17
|
+
LABEL security.scanner="dockerls"
|
|
18
|
+
LABEL security.hardened="true"
|
|
19
|
+
LABEL maintainer="security@company.com"
|
|
20
|
+
LABEL security.cve-contact="security@company.com"
|
|
21
|
+
|
|
22
|
+
ENV DEBIAN_FRONTEND=noninteractive
|
|
23
|
+
|
|
24
|
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
25
|
+
php-cli php-fpm php-mbstring php-xml php-curl ca-certificates \
|
|
26
|
+
&& groupadd -g 10001 appgroup \
|
|
27
|
+
&& useradd -u 10001 -g appgroup -s /usr/sbin/nologin -m appuser \
|
|
28
|
+
&& apt-get clean \
|
|
29
|
+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
|
30
|
+
|
|
31
|
+
WORKDIR /app
|
|
32
|
+
|
|
33
|
+
COPY --from=vendor --chown=appuser:appgroup /app/vendor ./vendor
|
|
34
|
+
COPY --chown=appuser:appgroup . .
|
|
35
|
+
|
|
36
|
+
ARG GIT_SHA=unknown
|
|
37
|
+
ARG BUILD_TIME=unknown
|
|
38
|
+
LABEL org.opencontainers.image.revision="${GIT_SHA}"
|
|
39
|
+
LABEL org.opencontainers.image.created="${BUILD_TIME}"
|
|
40
|
+
|
|
41
|
+
USER appuser
|
|
42
|
+
|
|
43
|
+
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
|
|
44
|
+
CMD php -v || exit 1
|
|
45
|
+
|
|
46
|
+
EXPOSE 8000
|
|
47
|
+
|
|
48
|
+
ENTRYPOINT ["php"]
|
|
49
|
+
CMD ["-S", "0.0.0.0:8000", "-t", "public"]
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Dockerfile.hardened.php
|
|
2
|
+
# Hardened template for PHP 8.3 - Production Ready
|
|
3
|
+
|
|
4
|
+
# Stage 1: Composer Builder
|
|
5
|
+
FROM composer:2 AS composer_stage
|
|
6
|
+
|
|
7
|
+
WORKDIR /app
|
|
8
|
+
COPY composer.json composer.lock* ./
|
|
9
|
+
RUN composer install --no-dev --prefer-dist --no-interaction --optimize-autoloader --no-scripts || true
|
|
10
|
+
|
|
11
|
+
# Stage 2: Runtime PHP 8.3 Alpine
|
|
12
|
+
FROM php:8.3-cli-alpine
|
|
13
|
+
|
|
14
|
+
LABEL security.scanner="dockerls"
|
|
15
|
+
LABEL security.hardened="true"
|
|
16
|
+
LABEL maintainer="your-team@company.com"
|
|
17
|
+
LABEL security.cve-contact="security@company.com"
|
|
18
|
+
|
|
19
|
+
# Opcache and secure extensions
|
|
20
|
+
RUN docker-php-ext-enable opcache || true
|
|
21
|
+
|
|
22
|
+
RUN addgroup -g 10001 appgroup && \
|
|
23
|
+
adduser -D -u 10001 -G appgroup -h /home/appuser appuser
|
|
24
|
+
|
|
25
|
+
WORKDIR /app
|
|
26
|
+
|
|
27
|
+
COPY --from=composer_stage --chown=appuser:appgroup /app/vendor /app/vendor
|
|
28
|
+
COPY --chown=appuser:appgroup . .
|
|
29
|
+
|
|
30
|
+
# Build metadata
|
|
31
|
+
ARG GIT_SHA=unknown
|
|
32
|
+
ARG BUILD_TIME=unknown
|
|
33
|
+
LABEL org.opencontainers.image.revision="${GIT_SHA}"
|
|
34
|
+
LABEL org.opencontainers.image.created="${BUILD_TIME}"
|
|
35
|
+
|
|
36
|
+
USER appuser
|
|
37
|
+
|
|
38
|
+
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
|
39
|
+
CMD php -v || exit 1
|
|
40
|
+
|
|
41
|
+
EXPOSE 8000
|
|
42
|
+
|
|
43
|
+
ENTRYPOINT ["php"]
|
|
44
|
+
CMD ["-S", "0.0.0.0:8000", "-t", "public"]
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Dockerfile.hardened.python-alpine
|
|
2
|
+
# Hardened template for Python 3.12 (Alpine Linux musl)
|
|
3
|
+
|
|
4
|
+
ARG PYTHON_VERSION=3.12-alpine
|
|
5
|
+
|
|
6
|
+
# Stage 1: Builder
|
|
7
|
+
FROM python:${PYTHON_VERSION} AS builder
|
|
8
|
+
|
|
9
|
+
WORKDIR /app
|
|
10
|
+
|
|
11
|
+
RUN apk add --no-cache gcc musl-dev libffi-dev openssl-dev
|
|
12
|
+
|
|
13
|
+
COPY requirements*.txt ./
|
|
14
|
+
RUN pip install --no-cache-dir --user -r requirements.txt
|
|
15
|
+
|
|
16
|
+
# Stage 2: Runtime
|
|
17
|
+
FROM python:${PYTHON_VERSION}
|
|
18
|
+
|
|
19
|
+
LABEL security.scanner="dockerls"
|
|
20
|
+
LABEL security.hardened="true"
|
|
21
|
+
LABEL maintainer="security@company.com"
|
|
22
|
+
LABEL security.cve-contact="security@company.com"
|
|
23
|
+
|
|
24
|
+
ENV PYTHONUNBUFFERED=1 \
|
|
25
|
+
PYTHONDONTWRITEBYTECODE=1 \
|
|
26
|
+
PATH=/home/appuser/.local/bin:$PATH
|
|
27
|
+
|
|
28
|
+
RUN addgroup -g 10001 appgroup \
|
|
29
|
+
&& adduser -u 10001 -G appgroup -s /sbin/nologin -D appuser \
|
|
30
|
+
&& apk update && apk upgrade --no-cache \
|
|
31
|
+
&& rm -rf /var/cache/apk/*
|
|
32
|
+
|
|
33
|
+
WORKDIR /app
|
|
34
|
+
|
|
35
|
+
COPY --from=builder --chown=appuser:appgroup /root/.local /home/appuser/.local
|
|
36
|
+
COPY --chown=appuser:appgroup . .
|
|
37
|
+
|
|
38
|
+
ARG GIT_SHA=unknown
|
|
39
|
+
ARG BUILD_TIME=unknown
|
|
40
|
+
LABEL org.opencontainers.image.revision="${GIT_SHA}"
|
|
41
|
+
LABEL org.opencontainers.image.created="${BUILD_TIME}"
|
|
42
|
+
|
|
43
|
+
USER appuser
|
|
44
|
+
|
|
45
|
+
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
|
46
|
+
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health', timeout=3)" || exit 1
|
|
47
|
+
|
|
48
|
+
EXPOSE 8000
|
|
49
|
+
|
|
50
|
+
ENTRYPOINT ["python"]
|
|
51
|
+
CMD ["-u", "main.py"]
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Dockerfile.hardened.python-debian
|
|
2
|
+
# Hardened template for Python 3.12 (Debian Bookworm Slim - glibc)
|
|
3
|
+
|
|
4
|
+
ARG PYTHON_VERSION=3.12-slim-bookworm
|
|
5
|
+
|
|
6
|
+
# Stage 1: Builder
|
|
7
|
+
FROM python:${PYTHON_VERSION} AS builder
|
|
8
|
+
|
|
9
|
+
WORKDIR /app
|
|
10
|
+
|
|
11
|
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
12
|
+
build-essential ca-certificates \
|
|
13
|
+
&& rm -rf /var/lib/apt/lists/*
|
|
14
|
+
|
|
15
|
+
COPY requirements*.txt ./
|
|
16
|
+
RUN pip install --no-cache-dir --user -r requirements.txt
|
|
17
|
+
|
|
18
|
+
# Stage 2: Runtime
|
|
19
|
+
FROM python:${PYTHON_VERSION}
|
|
20
|
+
|
|
21
|
+
LABEL security.scanner="dockerls"
|
|
22
|
+
LABEL security.hardened="true"
|
|
23
|
+
LABEL maintainer="security@company.com"
|
|
24
|
+
LABEL security.cve-contact="security@company.com"
|
|
25
|
+
|
|
26
|
+
ENV PYTHONUNBUFFERED=1 \
|
|
27
|
+
PYTHONDONTWRITEBYTECODE=1 \
|
|
28
|
+
PATH=/home/appuser/.local/bin:$PATH
|
|
29
|
+
|
|
30
|
+
RUN apt-get update && apt-get upgrade -y \
|
|
31
|
+
&& apt-get install -y --no-install-recommends ca-certificates \
|
|
32
|
+
&& groupadd -g 10001 appgroup \
|
|
33
|
+
&& useradd -u 10001 -g appgroup -s /usr/sbin/nologin -m appuser \
|
|
34
|
+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
|
35
|
+
|
|
36
|
+
WORKDIR /app
|
|
37
|
+
|
|
38
|
+
COPY --from=builder --chown=appuser:appgroup /root/.local /home/appuser/.local
|
|
39
|
+
COPY --chown=appuser:appgroup . .
|
|
40
|
+
|
|
41
|
+
ARG GIT_SHA=unknown
|
|
42
|
+
ARG BUILD_TIME=unknown
|
|
43
|
+
LABEL org.opencontainers.image.revision="${GIT_SHA}"
|
|
44
|
+
LABEL org.opencontainers.image.created="${BUILD_TIME}"
|
|
45
|
+
|
|
46
|
+
USER appuser
|
|
47
|
+
|
|
48
|
+
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
|
49
|
+
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health', timeout=3)" || exit 1
|
|
50
|
+
|
|
51
|
+
EXPOSE 8000
|
|
52
|
+
|
|
53
|
+
ENTRYPOINT ["python"]
|
|
54
|
+
CMD ["-u", "main.py"]
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Dockerfile.hardened.python-distroless
|
|
2
|
+
# Hardened template for Python 3.12 (Google Distroless - No Shell)
|
|
3
|
+
|
|
4
|
+
ARG DEBIAN_VERSION=bookworm-slim
|
|
5
|
+
|
|
6
|
+
# Stage 1: Builder
|
|
7
|
+
FROM debian:${DEBIAN_VERSION} AS builder
|
|
8
|
+
|
|
9
|
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
10
|
+
python3 python3-pip python3-venv ca-certificates \
|
|
11
|
+
&& rm -rf /var/lib/apt/lists/*
|
|
12
|
+
|
|
13
|
+
WORKDIR /app
|
|
14
|
+
|
|
15
|
+
RUN python3 -m venv /opt/venv
|
|
16
|
+
ENV PATH="/opt/venv/bin:$PATH"
|
|
17
|
+
|
|
18
|
+
COPY requirements*.txt ./
|
|
19
|
+
RUN pip install --no-cache-dir -r requirements.txt
|
|
20
|
+
|
|
21
|
+
COPY . .
|
|
22
|
+
|
|
23
|
+
# Stage 2: Distroless Runtime (No Shell)
|
|
24
|
+
FROM gcr.io/distroless/python3-debian12:nonroot
|
|
25
|
+
|
|
26
|
+
LABEL security.scanner="dockerls"
|
|
27
|
+
LABEL security.hardened="true"
|
|
28
|
+
LABEL maintainer="security@company.com"
|
|
29
|
+
LABEL security.cve-contact="security@company.com"
|
|
30
|
+
|
|
31
|
+
ENV PYTHONUNBUFFERED=1 \
|
|
32
|
+
PYTHONDONTWRITEBYTECODE=1 \
|
|
33
|
+
PATH="/opt/venv/bin:$PATH"
|
|
34
|
+
|
|
35
|
+
WORKDIR /app
|
|
36
|
+
|
|
37
|
+
COPY --from=builder /opt/venv /opt/venv
|
|
38
|
+
COPY --from=builder /app /app
|
|
39
|
+
|
|
40
|
+
ARG GIT_SHA=unknown
|
|
41
|
+
ARG BUILD_TIME=unknown
|
|
42
|
+
LABEL org.opencontainers.image.revision="${GIT_SHA}"
|
|
43
|
+
LABEL org.opencontainers.image.created="${BUILD_TIME}"
|
|
44
|
+
|
|
45
|
+
# nonroot user in Distroless is 65532:65532
|
|
46
|
+
USER 65532:65532
|
|
47
|
+
|
|
48
|
+
EXPOSE 8000
|
|
49
|
+
|
|
50
|
+
ENTRYPOINT ["/usr/bin/python3"]
|
|
51
|
+
CMD ["-u", "main.py"]
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Dockerfile.hardened.python-ubuntu
|
|
2
|
+
# Hardened template for Python 3.12 (Ubuntu 24.04 LTS)
|
|
3
|
+
|
|
4
|
+
ARG UBUNTU_VERSION=24.04
|
|
5
|
+
|
|
6
|
+
# Stage 1: Builder
|
|
7
|
+
FROM ubuntu:${UBUNTU_VERSION} AS builder
|
|
8
|
+
|
|
9
|
+
ENV DEBIAN_FRONTEND=noninteractive
|
|
10
|
+
|
|
11
|
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
12
|
+
python3 python3-pip python3-venv build-essential ca-certificates \
|
|
13
|
+
&& rm -rf /var/lib/apt/lists/*
|
|
14
|
+
|
|
15
|
+
WORKDIR /app
|
|
16
|
+
|
|
17
|
+
RUN python3 -m venv /opt/venv
|
|
18
|
+
ENV PATH="/opt/venv/bin:$PATH"
|
|
19
|
+
|
|
20
|
+
COPY requirements*.txt ./
|
|
21
|
+
RUN pip install --no-cache-dir -r requirements.txt
|
|
22
|
+
|
|
23
|
+
# Stage 2: Runtime
|
|
24
|
+
FROM ubuntu:${UBUNTU_VERSION}
|
|
25
|
+
|
|
26
|
+
LABEL security.scanner="dockerls"
|
|
27
|
+
LABEL security.hardened="true"
|
|
28
|
+
LABEL maintainer="security@company.com"
|
|
29
|
+
LABEL security.cve-contact="security@company.com"
|
|
30
|
+
|
|
31
|
+
ENV DEBIAN_FRONTEND=noninteractive \
|
|
32
|
+
PYTHONUNBUFFERED=1 \
|
|
33
|
+
PYTHONDONTWRITEBYTECODE=1 \
|
|
34
|
+
PATH="/opt/venv/bin:$PATH"
|
|
35
|
+
|
|
36
|
+
RUN apt-get update && apt-get upgrade -y \
|
|
37
|
+
&& apt-get install -y --no-install-recommends python3 ca-certificates \
|
|
38
|
+
&& groupadd -g 10001 appgroup \
|
|
39
|
+
&& useradd -u 10001 -g appgroup -s /usr/sbin/nologin -m appuser \
|
|
40
|
+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
|
41
|
+
|
|
42
|
+
WORKDIR /app
|
|
43
|
+
|
|
44
|
+
COPY --from=builder /opt/venv /opt/venv
|
|
45
|
+
COPY --chown=appuser:appgroup . .
|
|
46
|
+
|
|
47
|
+
ARG GIT_SHA=unknown
|
|
48
|
+
ARG BUILD_TIME=unknown
|
|
49
|
+
LABEL org.opencontainers.image.revision="${GIT_SHA}"
|
|
50
|
+
LABEL org.opencontainers.image.created="${BUILD_TIME}"
|
|
51
|
+
|
|
52
|
+
USER appuser
|
|
53
|
+
|
|
54
|
+
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
|
55
|
+
CMD python3 -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health', timeout=3)" || exit 1
|
|
56
|
+
|
|
57
|
+
EXPOSE 8000
|
|
58
|
+
|
|
59
|
+
ENTRYPOINT ["python3"]
|
|
60
|
+
CMD ["-u", "main.py"]
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Dockerfile.hardened.python
|
|
2
|
+
# Hardened template for Python - Production Ready
|
|
3
|
+
|
|
4
|
+
ARG PYTHON_VERSION=3.12-alpine
|
|
5
|
+
|
|
6
|
+
# Stage 1: Builder
|
|
7
|
+
FROM python:${PYTHON_VERSION} AS builder
|
|
8
|
+
|
|
9
|
+
WORKDIR /app
|
|
10
|
+
|
|
11
|
+
# Install temporary build dependencies
|
|
12
|
+
RUN apk add --no-cache \
|
|
13
|
+
gcc \
|
|
14
|
+
musl-dev \
|
|
15
|
+
libffi-dev \
|
|
16
|
+
&& rm -rf /var/cache/apk/*
|
|
17
|
+
|
|
18
|
+
COPY requirements.txt .
|
|
19
|
+
RUN pip install --user --no-cache-dir -r requirements.txt
|
|
20
|
+
|
|
21
|
+
# Stage 2: Runtime
|
|
22
|
+
FROM python:${PYTHON_VERSION}
|
|
23
|
+
|
|
24
|
+
LABEL security.scanner="dockerls"
|
|
25
|
+
LABEL security.hardened="true"
|
|
26
|
+
LABEL maintainer="your-team@company.com"
|
|
27
|
+
LABEL security.cve-contact="security@company.com"
|
|
28
|
+
|
|
29
|
+
# Secure environment variables for Python
|
|
30
|
+
ENV PYTHONUNBUFFERED=1 \
|
|
31
|
+
PYTHONDONTWRITEBYTECODE=1 \
|
|
32
|
+
PATH=/home/appuser/.local/bin:$PATH
|
|
33
|
+
|
|
34
|
+
RUN addgroup -g 10001 appgroup && \
|
|
35
|
+
adduser -D -u 10001 -G appgroup -h /home/appuser appuser
|
|
36
|
+
|
|
37
|
+
WORKDIR /app
|
|
38
|
+
|
|
39
|
+
COPY --from=builder --chown=appuser:appgroup /root/.local /home/appuser/.local
|
|
40
|
+
COPY --chown=appuser:appgroup . .
|
|
41
|
+
|
|
42
|
+
# Build metadata
|
|
43
|
+
ARG GIT_SHA=unknown
|
|
44
|
+
ARG BUILD_TIME=unknown
|
|
45
|
+
LABEL org.opencontainers.image.revision="${GIT_SHA}"
|
|
46
|
+
LABEL org.opencontainers.image.created="${BUILD_TIME}"
|
|
47
|
+
|
|
48
|
+
USER appuser
|
|
49
|
+
|
|
50
|
+
# Health check using the standard library (urllib) -- no external dependencies
|
|
51
|
+
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
|
52
|
+
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health', timeout=3)" || exit 1
|
|
53
|
+
|
|
54
|
+
EXPOSE 8000
|
|
55
|
+
|
|
56
|
+
# No shell - exec form
|
|
57
|
+
ENTRYPOINT ["python"]
|
|
58
|
+
CMD ["-u", "main.py"]
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Dockerfile.hardened.ruby-alpine
|
|
2
|
+
# Hardened template for Ruby 3.3 (Alpine Linux)
|
|
3
|
+
|
|
4
|
+
ARG RUBY_VERSION=3.3-alpine
|
|
5
|
+
|
|
6
|
+
# Stage 1: Builder
|
|
7
|
+
FROM ruby:${RUBY_VERSION} AS builder
|
|
8
|
+
|
|
9
|
+
WORKDIR /app
|
|
10
|
+
|
|
11
|
+
RUN apk add --no-cache build-base
|
|
12
|
+
|
|
13
|
+
COPY Gemfile Gemfile.lock* ./
|
|
14
|
+
RUN bundle config set --local without 'development test' \
|
|
15
|
+
&& bundle install --jobs=4 --retry=3
|
|
16
|
+
|
|
17
|
+
# Stage 2: Runtime
|
|
18
|
+
FROM ruby:${RUBY_VERSION}
|
|
19
|
+
|
|
20
|
+
LABEL security.scanner="dockerls"
|
|
21
|
+
LABEL security.hardened="true"
|
|
22
|
+
LABEL maintainer="security@company.com"
|
|
23
|
+
LABEL security.cve-contact="security@company.com"
|
|
24
|
+
|
|
25
|
+
RUN apk update && apk upgrade --no-cache \
|
|
26
|
+
&& addgroup -g 10001 appgroup \
|
|
27
|
+
&& adduser -u 10001 -G appgroup -s /sbin/nologin -D appuser \
|
|
28
|
+
&& rm -rf /var/cache/apk/*
|
|
29
|
+
|
|
30
|
+
WORKDIR /app
|
|
31
|
+
|
|
32
|
+
COPY --from=builder --chown=appuser:appgroup /usr/local/bundle /usr/local/bundle
|
|
33
|
+
COPY --chown=appuser:appgroup . .
|
|
34
|
+
|
|
35
|
+
ARG GIT_SHA=unknown
|
|
36
|
+
ARG BUILD_TIME=unknown
|
|
37
|
+
LABEL org.opencontainers.image.revision="${GIT_SHA}"
|
|
38
|
+
LABEL org.opencontainers.image.created="${BUILD_TIME}"
|
|
39
|
+
|
|
40
|
+
USER appuser
|
|
41
|
+
|
|
42
|
+
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
|
43
|
+
CMD ruby -v || exit 1
|
|
44
|
+
|
|
45
|
+
EXPOSE 3000
|
|
46
|
+
|
|
47
|
+
ENTRYPOINT ["bundle", "exec"]
|
|
48
|
+
CMD ["ruby", "app.rb"]
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Dockerfile.hardened.ruby-debian
|
|
2
|
+
# Hardened template for Ruby 3.3 (Debian Bookworm Slim)
|
|
3
|
+
|
|
4
|
+
ARG RUBY_VERSION=3.3-slim-bookworm
|
|
5
|
+
|
|
6
|
+
# Stage 1: Builder
|
|
7
|
+
FROM ruby:${RUBY_VERSION} AS builder
|
|
8
|
+
|
|
9
|
+
WORKDIR /app
|
|
10
|
+
|
|
11
|
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
12
|
+
build-essential ca-certificates \
|
|
13
|
+
&& rm -rf /var/lib/apt/lists/*
|
|
14
|
+
|
|
15
|
+
COPY Gemfile Gemfile.lock* ./
|
|
16
|
+
RUN bundle config set --local without 'development test' \
|
|
17
|
+
&& bundle install --jobs=4 --retry=3
|
|
18
|
+
|
|
19
|
+
# Stage 2: Runtime
|
|
20
|
+
FROM ruby:${RUBY_VERSION}
|
|
21
|
+
|
|
22
|
+
LABEL security.scanner="dockerls"
|
|
23
|
+
LABEL security.hardened="true"
|
|
24
|
+
LABEL maintainer="security@company.com"
|
|
25
|
+
LABEL security.cve-contact="security@company.com"
|
|
26
|
+
|
|
27
|
+
RUN apt-get update && apt-get upgrade -y \
|
|
28
|
+
&& groupadd -g 10001 appgroup \
|
|
29
|
+
&& useradd -u 10001 -g appgroup -s /usr/sbin/nologin -m appuser \
|
|
30
|
+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
|
31
|
+
|
|
32
|
+
WORKDIR /app
|
|
33
|
+
|
|
34
|
+
COPY --from=builder --chown=appuser:appgroup /usr/local/bundle /usr/local/bundle
|
|
35
|
+
COPY --chown=appuser:appgroup . .
|
|
36
|
+
|
|
37
|
+
ARG GIT_SHA=unknown
|
|
38
|
+
ARG BUILD_TIME=unknown
|
|
39
|
+
LABEL org.opencontainers.image.revision="${GIT_SHA}"
|
|
40
|
+
LABEL org.opencontainers.image.created="${BUILD_TIME}"
|
|
41
|
+
|
|
42
|
+
USER appuser
|
|
43
|
+
|
|
44
|
+
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
|
45
|
+
CMD ruby -v || exit 1
|
|
46
|
+
|
|
47
|
+
EXPOSE 3000
|
|
48
|
+
|
|
49
|
+
ENTRYPOINT ["bundle", "exec"]
|
|
50
|
+
CMD ["ruby", "app.rb"]
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Dockerfile.hardened.rust-alpine
|
|
2
|
+
# Hardened template for Rust (Alpine Linux)
|
|
3
|
+
|
|
4
|
+
ARG RUST_VERSION=1.82-alpine
|
|
5
|
+
ARG ALPINE_VERSION=3.20
|
|
6
|
+
|
|
7
|
+
# Stage 1: Builder
|
|
8
|
+
FROM rust:${RUST_VERSION} AS builder
|
|
9
|
+
|
|
10
|
+
RUN apk update && apk add --no-cache musl-dev
|
|
11
|
+
|
|
12
|
+
WORKDIR /app
|
|
13
|
+
|
|
14
|
+
COPY Cargo.toml Cargo.lock ./
|
|
15
|
+
COPY src ./src
|
|
16
|
+
|
|
17
|
+
RUN cargo build --release \
|
|
18
|
+
&& cp /app/target/release/app /app/binary || cp /app/target/release/* /app/binary
|
|
19
|
+
|
|
20
|
+
# Stage 2: Alpine Runtime
|
|
21
|
+
FROM alpine:${ALPINE_VERSION}
|
|
22
|
+
|
|
23
|
+
LABEL security.scanner="dockerls"
|
|
24
|
+
LABEL security.hardened="true"
|
|
25
|
+
LABEL maintainer="security@company.com"
|
|
26
|
+
LABEL security.cve-contact="security@company.com"
|
|
27
|
+
|
|
28
|
+
RUN apk update && apk upgrade --no-cache \
|
|
29
|
+
&& apk add --no-cache ca-certificates tzdata \
|
|
30
|
+
&& addgroup -g 10001 appgroup \
|
|
31
|
+
&& adduser -u 10001 -G appgroup -s /sbin/nologin -D appuser \
|
|
32
|
+
&& rm -rf /var/cache/apk/*
|
|
33
|
+
|
|
34
|
+
WORKDIR /app
|
|
35
|
+
|
|
36
|
+
COPY --from=builder /app/binary /app/binary
|
|
37
|
+
|
|
38
|
+
ARG GIT_SHA=unknown
|
|
39
|
+
ARG BUILD_TIME=unknown
|
|
40
|
+
LABEL org.opencontainers.image.revision="${GIT_SHA}"
|
|
41
|
+
LABEL org.opencontainers.image.created="${BUILD_TIME}"
|
|
42
|
+
|
|
43
|
+
USER appuser
|
|
44
|
+
|
|
45
|
+
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
|
|
46
|
+
CMD [ -f /app/binary ] || exit 1
|
|
47
|
+
|
|
48
|
+
EXPOSE 8080
|
|
49
|
+
|
|
50
|
+
ENTRYPOINT ["/app/binary"]
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Dockerfile.hardened.rust-debian
|
|
2
|
+
# Hardened template for Rust (Debian Bookworm Slim)
|
|
3
|
+
|
|
4
|
+
ARG RUST_VERSION=1.82-bookworm
|
|
5
|
+
ARG DEBIAN_VERSION=bookworm-slim
|
|
6
|
+
|
|
7
|
+
# Stage 1: Builder
|
|
8
|
+
FROM rust:${RUST_VERSION} AS builder
|
|
9
|
+
|
|
10
|
+
WORKDIR /app
|
|
11
|
+
|
|
12
|
+
COPY Cargo.toml Cargo.lock ./
|
|
13
|
+
COPY src ./src
|
|
14
|
+
|
|
15
|
+
RUN cargo build --release \
|
|
16
|
+
&& cp /app/target/release/app /app/binary || cp /app/target/release/* /app/binary
|
|
17
|
+
|
|
18
|
+
# Stage 2: Debian Runtime
|
|
19
|
+
FROM debian:${DEBIAN_VERSION}
|
|
20
|
+
|
|
21
|
+
LABEL security.scanner="dockerls"
|
|
22
|
+
LABEL security.hardened="true"
|
|
23
|
+
LABEL maintainer="security@company.com"
|
|
24
|
+
LABEL security.cve-contact="security@company.com"
|
|
25
|
+
|
|
26
|
+
RUN apt-get update && apt-get upgrade -y \
|
|
27
|
+
&& apt-get install -y --no-install-recommends ca-certificates tzdata \
|
|
28
|
+
&& groupadd -g 10001 appgroup \
|
|
29
|
+
&& useradd -u 10001 -g appgroup -s /usr/sbin/nologin -m appuser \
|
|
30
|
+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
|
31
|
+
|
|
32
|
+
WORKDIR /app
|
|
33
|
+
|
|
34
|
+
COPY --from=builder /app/binary /app/binary
|
|
35
|
+
|
|
36
|
+
ARG GIT_SHA=unknown
|
|
37
|
+
ARG BUILD_TIME=unknown
|
|
38
|
+
LABEL org.opencontainers.image.revision="${GIT_SHA}"
|
|
39
|
+
LABEL org.opencontainers.image.created="${BUILD_TIME}"
|
|
40
|
+
|
|
41
|
+
USER appuser
|
|
42
|
+
|
|
43
|
+
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
|
|
44
|
+
CMD [ -f /app/binary ] || exit 1
|
|
45
|
+
|
|
46
|
+
EXPOSE 8080
|
|
47
|
+
|
|
48
|
+
ENTRYPOINT ["/app/binary"]
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Dockerfile.hardened.rust-scratch
|
|
2
|
+
# Hardened template for Rust (Scratch - Zero OS CVEs)
|
|
3
|
+
|
|
4
|
+
ARG RUST_VERSION=1.82-alpine
|
|
5
|
+
|
|
6
|
+
# Stage 1: Builder (Alpine musl static compilation)
|
|
7
|
+
FROM rust:${RUST_VERSION} AS builder
|
|
8
|
+
|
|
9
|
+
RUN apk update && apk add --no-cache musl-dev ca-certificates tzdata \
|
|
10
|
+
&& rustup target add x86_64-unknown-linux-musl
|
|
11
|
+
|
|
12
|
+
WORKDIR /app
|
|
13
|
+
|
|
14
|
+
COPY Cargo.toml Cargo.lock ./
|
|
15
|
+
COPY src ./src
|
|
16
|
+
|
|
17
|
+
# Secure static compilation
|
|
18
|
+
RUN RUSTFLAGS="-C target-feature=+crt-static" \
|
|
19
|
+
cargo build --release --target x86_64-unknown-linux-musl \
|
|
20
|
+
&& cp /app/target/x86_64-unknown-linux-musl/release/app /app/binary || cp /app/target/x86_64-unknown-linux-musl/release/* /app/binary
|
|
21
|
+
|
|
22
|
+
# Stage 2: Scratch Runtime
|
|
23
|
+
FROM scratch
|
|
24
|
+
|
|
25
|
+
LABEL security.scanner="dockerls"
|
|
26
|
+
LABEL security.hardened="true"
|
|
27
|
+
LABEL maintainer="security@company.com"
|
|
28
|
+
LABEL security.cve-contact="security@company.com"
|
|
29
|
+
|
|
30
|
+
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
|
31
|
+
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
|
|
32
|
+
COPY --from=builder /app/binary /app/binary
|
|
33
|
+
|
|
34
|
+
ARG GIT_SHA=unknown
|
|
35
|
+
ARG BUILD_TIME=unknown
|
|
36
|
+
LABEL org.opencontainers.image.revision="${GIT_SHA}"
|
|
37
|
+
LABEL org.opencontainers.image.created="${BUILD_TIME}"
|
|
38
|
+
|
|
39
|
+
# nobody user (UID 65534:65534)
|
|
40
|
+
USER 65534:65534
|
|
41
|
+
|
|
42
|
+
EXPOSE 8080
|
|
43
|
+
|
|
44
|
+
ENTRYPOINT ["/app/binary"]
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Dockerfile.hardened.rust
|
|
2
|
+
# Hardened template for Rust - Production Ready Static Binary
|
|
3
|
+
|
|
4
|
+
# Stage 1: Builder
|
|
5
|
+
FROM rust:1.82-alpine AS builder
|
|
6
|
+
|
|
7
|
+
WORKDIR /app
|
|
8
|
+
|
|
9
|
+
# musl build dependencies
|
|
10
|
+
RUN apk add --no-cache musl-dev ca-certificates && rm -rf /var/cache/apk/*
|
|
11
|
+
|
|
12
|
+
COPY Cargo.toml Cargo.lock* ./
|
|
13
|
+
|
|
14
|
+
# Copy source code
|
|
15
|
+
COPY src ./src
|
|
16
|
+
|
|
17
|
+
# Static release compilation
|
|
18
|
+
RUN RUSTFLAGS="-C target-feature=+crt-static" cargo build --release --target x86_64-unknown-linux-musl || \
|
|
19
|
+
cargo build --release
|
|
20
|
+
|
|
21
|
+
# Locate the generated binary
|
|
22
|
+
RUN if [ -f target/x86_64-unknown-linux-musl/release/app ]; then \
|
|
23
|
+
cp target/x86_64-unknown-linux-musl/release/app /app/binary; \
|
|
24
|
+
else \
|
|
25
|
+
find target/release -maxdepth 1 -type f -executable -exec cp {} /app/binary \; ; \
|
|
26
|
+
fi
|
|
27
|
+
|
|
28
|
+
# Stage 2: Runtime minimal (scratch)
|
|
29
|
+
FROM scratch
|
|
30
|
+
|
|
31
|
+
LABEL security.scanner="dockerls"
|
|
32
|
+
LABEL security.hardened="true"
|
|
33
|
+
LABEL maintainer="your-team@company.com"
|
|
34
|
+
LABEL security.cve-contact="security@company.com"
|
|
35
|
+
|
|
36
|
+
# Build metadata
|
|
37
|
+
ARG GIT_SHA=unknown
|
|
38
|
+
ARG BUILD_TIME=unknown
|
|
39
|
+
LABEL org.opencontainers.image.revision="${GIT_SHA}"
|
|
40
|
+
LABEL org.opencontainers.image.created="${BUILD_TIME}"
|
|
41
|
+
|
|
42
|
+
# Copy SSL root certificates
|
|
43
|
+
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
|
44
|
+
|
|
45
|
+
# Copy the application binary
|
|
46
|
+
COPY --from=builder /app/binary /app
|
|
47
|
+
|
|
48
|
+
EXPOSE 8080
|
|
49
|
+
|
|
50
|
+
# Non-root user (nobody)
|
|
51
|
+
USER 65534:65534
|
|
52
|
+
|
|
53
|
+
# Formato exec
|
|
54
|
+
ENTRYPOINT ["/app"]
|