Skip to content

refactor: resolve Trivy/Hadolint findings and standardize Dockerfiles & configs - #498

Open
Diogo-Rego wants to merge 18 commits into
MISP:masterfrom
Diogo-Rego:refactor/dockerfiles-lint-and-security
Open

Diogo-Rego wants to merge 18 commits into
MISP:masterfrom
Diogo-Rego:refactor/dockerfiles-lint-and-security

Conversation

@Diogo-Rego

@Diogo-Rego Diogo-Rego commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

This PR addresses security misconfigurations and lint issues identified by Trivy and Hadolint across all service Dockerfiles (nginx, modules, guard, and core). It introduces an automated CI workflow for linting and security checks, and standardizes configuration formatting, JSON indentation, and trailing whitespaces throughout the codebase.


Key Changes

CI / CD Integration

  • Workflow (.github/workflows/lint.yml): Added an automated GitHub Actions workflow running on pushes and pull requests to master:
    • Hadolint (hadolint/hadolint-action@v3.5.0): Recursively lints all Dockerfiles against best practices with failure-threshold: warning.
    • Trivy (aquasecurity/trivy-action@v0.36.0): Scans filesystem (trivy fs) for Dockerfile misconfigurations, vulnerabilities, and accidental secret/token leaks.
  • Linter Configurations:
    • .hadolint.yaml: Configured to ignore non-applicable package pinning rules (DL3008, DL3013, DL3009, DL4006).
    • trivy.yaml: Scoped to Dockerfile misconfiguration and secret scanners with exit-code: 1.
    • .trivyignore: Documented exception for DS-0002 (root user in core and guard containers, which run as root by design).

Dockerfiles Lint & Security

  • nginx/Dockerfile:
    • Replaced directory switching in RUN with explicit WORKDIR (DS-0013).
    • Ensured correct ownership (101:101) for /var/www to fix rootless Podman/Buildah build compatibility.
    • Formatted HEALTHCHECK CMD to JSON array format (DL3025) and pinned numeric user IDs (DL3066).
    • Switched from [ ! -z ... ] to idiomatic [ -n ... ] (SC2236).
  • modules/Dockerfile:
    • Replaced cd with WORKDIR for repository checkouts (DS-0013).
    • Added EXPOSE 6666 and container HEALTHCHECK (DS-0026).
    • Standardized heredoc indentation and addressed Hadolint recommendations (useradd -l, USER ${MISP_UID}, and pip install --no-cache-dir).
    • Switched from [ ! -z ... ] to [ -n ... ] (SC2236).
  • guard/Dockerfile & guard/config.json:
    • Replaced cd with WORKDIR (DS-0013).
    • Added EXPOSE 8888 and container HEALTHCHECK (DS-0026).
    • Switched from [ ! -z ... ] to [ -n ... ] (SC2236).
    • Formatted config.json with 2-space indentation.
  • core/Dockerfile:
    • Replaced cd with WORKDIR for repository checkout (DS-0013).
    • Added EXPOSE 9002 and FastCGI HEALTHCHECK (DS-0026).
    • Consolidated RUN directives in the final stage.
    • Switched from [ ! -z ... ] to [ -n ... ] (SC2236).
    • Quoted loop variables "${mod}" and "${mod_version}" to prevent word splitting (SC2086).

Code Style & Documentation

  • Standardized JSON indentation to 2 spaces in core/files/etc/misp-docker/s3.*.json.
  • Removed trailing whitespaces and ensured trailing newlines across supervisor configurations, utilities.sh, and index.php.
  • Standardized shell command indentation in docker-compose.yml.
  • Cleaned markdown formatting and trailing whitespace across docs/ and README.md.

- Use WORKDIR /srv/misp-modules to avoid cd in RUN (Trivy DS-0013)
- Add HEALTHCHECK instruction on port 6666 (Trivy DS-0026)
- Add -l flag to useradd (Hadolint DL3046)
- Use numeric UID for USER instruction (Hadolint DL3066)
- Use WORKDIR /srv/misp-guard to avoid cd in RUN (Trivy DS-0013)
- Add HEALTHCHECK instruction on port 8888 (Trivy DS-0026)
- Standardize Dockerfile indentation and format config.json
- Fix warning callout spacing and empty lines in README.md
- Add yaml syntax highlighting and fix list indentations in keycloak guide
- Clean up heading hashes and list bullets in stunnel guide
- Remove trailing whitespace across stunnel examples
- Use WORKDIR instead of cd during git checkouts (DS-0013 / DL3003)
- Add EXPOSE and HEALTHCHECK for FastCGI port 9002 (DS-0026)
- Consolidate RUN directives
- Standardize JSON indentation to 2 spaces in s3.*.json
- Remove trailing whitespace and ensure newline at end of file across
  supervisor configs, utilities.sh and index.php
@Diogo-Rego
Diogo-Rego marked this pull request as draft November 17, 2026 09:07
@ostefano

Copy link
Copy Markdown
Collaborator

Can we run those tools as part of the CI/CD?

@Diogo-Rego

Copy link
Copy Markdown
Contributor Author

Can we run those tools as part of the CI/CD?

Yes, exactly! I'm currently figuring out how to integrate them and checking a build error in misp-core.

Add GitHub Actions workflow to automatically run Hadolint and Trivy
misconfiguration scans on all Dockerfiles on push and pull requests.
- Add GitHub Actions workflow for Hadolint and Trivy scans
- Set Hadolint failure threshold to warning with .hadolint.yaml rules
- Enable Trivy filesystem scanning for misconfigurations,
  vulnerabilities, and secrets
- Add .trivyignore for accepted non-root user exceptions (core and
  guard)
- Bump hadolint/hadolint-action from v3.1.0 to v3.5.0
- Pin aquasecurity/trivy-action to v0.36.0
@Diogo-Rego

Copy link
Copy Markdown
Contributor Author

@ostefano, I've prepared a dedicated GitHub Actions workflow running both Hadolint and Trivy:

  • Hadolint (hadolint/hadolint-action): Recursively checks all Dockerfiles against Docker best practices with failure-threshold: warning, using .hadolint.yaml to ignore non-applicable rules (such as package version pinning for apt/pip).
  • Trivy (aquasecurity/trivy-action): Runs a filesystem scan (trivy fs --include-dev-deps --scanners vuln,misconfig,secret) with severity: CRITICAL,HIGH,MEDIUM. It checks Dockerfile misconfigurations, catches accidental secret/token leaks, and will automatically scan dependency lockfiles if introduced, using .trivyignore for accepted project designs (such as core/guard running as root).

Both checks run in ~20 seconds and pass cleanly. I have this ready on a separate branch (feat/ci-trivy-hadolint).

Would you prefer me to include this workflow in this PR, or should I open a dedicated follow-up PR right after this one is merged?

@ostefano

Copy link
Copy Markdown
Collaborator

Add the workflows in this PR, flag it as ready for review, so we can test run them here.

ci: add Hadolint and Trivy workflow with ShellCheck fixes
@Diogo-Rego
Diogo-Rego marked this pull request as ready for review November 17, 2026 17:00
@Diogo-Rego

Copy link
Copy Markdown
Contributor Author

@ostefano I've applied the changes and tested the images with docker-compose, everything is running smoothly without issues. Feel free to review and validate the PR!

@ostefano ostefano left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see many changes on actual code, so we want to test it thoroughly.

I also think we should a section in the README with instructions how to run the linters locally so we catch issues (and fix them) before committing.

Comment thread core/Dockerfile Resolved
@Diogo-Rego
Diogo-Rego requested a review from ostefano November 18, 2026 13:18
@ostefano

Copy link
Copy Markdown
Collaborator

I see many changes on actual code, so we want to test it thoroughly.

I also think we should a section in the README with instructions how to run the linters locally so we catch issues (and fix them) before committing.

@Diogo-Rego this the only actionable comment from my review.

@Diogo-Rego

Copy link
Copy Markdown
Contributor Author

@ostefano Sorry, I hadn't noticed your review comment earlier!

I have addressed it:

  • Added a dedicated section to the README.md ("Running Linters and Security Checks Locally") detailing how to execute Hadolint and Trivy locally using Docker, Podman, and native CLIs.
  • Reverted the RUN consolidation in core/Dockerfile back to separate instructions as well.

Feel free to take another look whenever you have time. Thanks!

@ostefano

ostefano commented Nov 19, 2026 via email

Copy link
Copy Markdown
Collaborator

@Diogo-Rego

Diogo-Rego commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks, just note that reverting was not mandatory (as per my other comment). Feel free to revert the revert :)
…

@ostefano Reverted the revert! :) Keeps the layers down and Hadolint happy. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants