Repository navigation
chore: Hive76 secret-scanning template (pre-commit gitleaks + Action) #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6a6eb5d
chore: Hive76 secret-scanning template (pre-commit gitleaks + Action)
b69952f
ci: gitleaks workflow token read-only (CodeQL)
4840273
chore: pre-push hook blocks force-push/delete of main
9d86821
ci: report checks under the names branch protection requires
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| name: gitleaks | ||
|
|
||
| on: | ||
| push: | ||
| pull_request: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| scan: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| - name: Install gitleaks | ||
| run: | | ||
| curl -sSfL https://github.com/gitleaks/gitleaks/releases/download/v8.28.0/gitleaks_8.28.0_linux_x64.tar.gz | tar -xz gitleaks | ||
| sudo mv gitleaks /usr/local/bin/ | ||
| - name: Scan full history | ||
| run: gitleaks detect --source . --config .gitleaks.toml --no-banner --redact --log-opts=--all | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #!/usr/bin/env bash | ||
| # Block commits that contain secrets. Installed with: git config core.hooksPath git-hooks | ||
| set -euo pipefail | ||
| # Hooks and runuser get a minimal PATH; the pinned gitleaks lives in /usr/local/bin. | ||
| export PATH="$PATH:/usr/local/bin:/opt/homebrew/bin" | ||
|
|
||
| if ! command -v gitleaks >/dev/null 2>&1; then | ||
| echo "pre-commit: gitleaks is not installed; refusing to commit unscanned changes." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| root=$(git rev-parse --show-toplevel) | ||
| cfg=() | ||
| [ -f "$root/.gitleaks.toml" ] && cfg=(--config "$root/.gitleaks.toml") | ||
|
|
||
| if ! gitleaks protect --staged "${cfg[@]}" --no-banner --redact; then | ||
| echo "pre-commit: possible secret in staged changes. Secrets belong in /etc/hive76/secrets/, never in git." >&2 | ||
| exit 1 | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #!/usr/bin/env bash | ||
| # Refuse to force-push or delete main. GitHub's free org plan can't protect branches in | ||
| # private repos, so this hook is the guard. Installed with: git config core.hooksPath git-hooks | ||
| set -euo pipefail | ||
|
|
||
| zero=0000000000000000000000000000000000000000 | ||
| status=0 | ||
| while read -r _local_ref local_sha remote_ref remote_sha; do | ||
| [ "$remote_ref" = refs/heads/main ] || continue | ||
| if [ "${local_sha//0/}" = "" ]; then | ||
| echo "pre-push: refusing to delete main." >&2 | ||
| status=1 | ||
| elif [ "$remote_sha" != "$zero" ] && ! git merge-base --is-ancestor "$remote_sha" "$local_sha" 2>/dev/null; then | ||
| echo "pre-push: refusing to force-push main (it would drop commits already on GitHub)." >&2 | ||
| echo "pre-push: run 'git pull' and push again; to undo a pushed commit, use 'git revert'." >&2 | ||
| status=1 | ||
| fi | ||
| done | ||
| exit $status |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.