fix: Address CodeQL security alert for untrusted checkout
Fixes CodeQL alert "Potential execution of untrusted code on a
privileged workflow" by implementing the principle of least privilege.
Changes:
- Set top-level permissions to read-all (most restrictive by default)
- Made contents permission conditional:
- Read-only for pull_request events (prevents untrusted code execution)
- Write permission only for releases (needed to attach SBOMs)
- Simplified checkout to use default behavior for PRs instead of
explicitly checking out head_ref (safer)
This ensures PRs from forks cannot execute with write permissions,
mitigating the security risk while maintaining functionality for
release SBOM publishing.
Security: Addresses actions/untrusted-checkout/high