Skip to content

chore: add bandit (static security analysis) to pre-commit - #295

Closed
fstagni wants to merge 3 commits into
DIRACGrid:develfrom
fstagni:bandit
Closed

fstagni wants to merge 3 commits into
DIRACGrid:develfrom
fstagni:bandit

Conversation

@fstagni

@fstagni fstagni commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Part of DIRACGrid/.github#5. Stacked on #294.

Adds the bandit hook to pre-commit, matching DIRAC's setup: configuration read from pyproject.toml ([tool.bandit]), tests excluded.

Skips are documented inline in pyproject.toml: the pilot bootstraps itself on worker nodes, so downloading files over URLs (B310) and starting processes (B404/B602/B603/B605/B607) is its core function by design; B110 (try_except_pass) is skipped as best-effort cleanup must never abort the pilot.

Clean run: 0 findings after the skips.

Replace the semantic.yml commit message check with the org-standard
setup (as in diracx):

- drop semantic.yml and the archived gsactions/commit-message-checker
- extend .pre-commit-config.yaml with the conventional-pre-commit hook
  (commit-msg stage, like diracx) plus default_install_hook_types, so
  contributors get the convention enforced at commit time
- release notes are unaffected: they are taken from the PR description,
  not from commit messages

Note: with merge commits kept in the history, individual commit
messages are no longer gated by CI - the convention is enforced locally
only (accepted decision, DIRACGrid/.github#5).

Part of DIRACGrid/.github#5.
Matches DIRAC's setup: configuration read from pyproject.toml, tests
excluded. Skips are documented inline: the pilot bootstraps itself on
worker nodes, so downloading files over URLs (B310) and starting
processes (B404/B602/B603/B605/B607) is its core function; B110
(try_except_pass) is skipped as best-effort cleanup must never abort
the pilot.

Part of DIRACGrid/.github#5.
Only the import_subprocess check stays skipped repo-wide; the shell,
URL and process findings are marked with nosec on their lines, so new
code is still checked.

Assisted-by: Claude:claude-opus-5-5
@fstagni

fstagni commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favour of ruff's S (flake8-bandit) ruleset: this repo already lints with ruff, so the bandit checks come from ruff instead of a separate bandit hook — same as DIRACGrid/mkdocs-diracx-plugin#12, and matching diracx, intercede and signurlarity. The equivalent setup (same skips, documented inline in pyproject.toml) is in #296.

@fstagni fstagni closed this Nov 20, 2026
fstagni added a commit to fstagni/Pilot that referenced this pull request Nov 20, 2026
Replaces the bandit-based approach of DIRACGrid#295 (closed): the repos already
linting with ruff get bandit's checks from ruff's S (flake8-bandit)
ruleset instead, like diracx, intercede and signurlarity.

- add S to the ruff select, with documented ignores mirroring the
  bandit skips: the pilot bootstraps itself on worker nodes, so
  downloading over URLs and starting processes is its core function by
  design; S110 (try-except-pass) is skipped as best-effort cleanup must
  never abort the pilot
- S311 is allowed in tests only (pseudo-random test data)
- migrate lint settings to [tool.ruff.lint] (the old top-level layout
  is deprecated) and ignore B905 (zip strict= needs Python 3.10)
- make ruff check clean: sort imports and drop an unused import in
  tests, noqa the retStatus placeholder kept for its TODO
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