diff --git a/CI/security/bundler-audit.yml b/CI/security/bundler-audit.yml new file mode 100644 index 0000000..b074700 --- /dev/null +++ b/CI/security/bundler-audit.yml @@ -0,0 +1,35 @@ +bundler-audit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: "3.3" + + - name: Install bundler-audit + run: gem install bundler-audit -v 0.9.2 + + - name: Run bundler-audit + run: | + set -euo pipefail + + if ! command -v bundle-audit &> /dev/null; then + echo "::error::bundle-audit not found. Install it before running this script." + exit 1 + fi + + if [[ ! -f "Gemfile.lock" ]]; then + echo "::error::No Gemfile.lock found. Run 'bundle install' to generate one." + exit 1 + fi + + echo "ℹ️ Running bundle-audit..." + + bundle-audit update + if bundle-audit check; then + echo "✅ bundler-audit passed" + else + echo "❌ bundler-audit found vulnerabilities" + exit 1 + fi diff --git a/README.md b/README.md index 7733a7d..f8a4941 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ that projects compose into their own workflows. | Tool | Category | File | |------|----------|------| +| bundler-audit | security | [CI/security/bundler-audit.yml](https://github.com/prog-time/workflows/blob/main/CI/security/bundler-audit.yml) | | gitleaks | security | [CI/security/gitleaks.yml](https://github.com/prog-time/workflows/blob/main/CI/security/gitleaks.yml) | | pip-audit | security | [CI/security/pip-audit.yml](https://github.com/prog-time/workflows/blob/main/CI/security/pip-audit.yml) | | semgrep | security | [CI/security/semgrep.yml](https://github.com/prog-time/workflows/blob/main/CI/security/semgrep.yml) | @@ -92,6 +93,7 @@ Workflows/ │ │ │ ├── tflint.yml │ │ │ └── yamllint.yml │ │ ├── security/ +│ │ │ ├── bundler-audit.yml │ │ │ ├── gitleaks.yml │ │ │ ├── pip-audit.yml │ │ │ ├── semgrep.yml @@ -127,6 +129,7 @@ Workflows/ │ │ ├── tflint.sh │ │ └── yamllint.sh │ ├── security/ +│ │ ├── bundler-audit.sh │ │ ├── gitleaks.sh │ │ ├── pip-audit.sh │ │ ├── semgrep.sh @@ -154,6 +157,7 @@ Workflows/ │ │ ├── tflint.bats │ │ └── yamllint.bats │ ├── security/ +│ │ ├── bundler-audit.bats │ │ ├── gitleaks.bats │ │ ├── pip-audit.bats │ │ ├── semgrep.bats @@ -232,6 +236,7 @@ shellcheck: | Snippet | Tool | What it checks | |---------|------|----------------| +| `CI/security/bundler-audit.yml` | [bundler-audit](https://github.com/rubysec/bundler-audit) | CVEs in Ruby gem dependencies via the Ruby Advisory Database | | `CI/security/gitleaks.yml` | [gitleaks](https://github.com/gitleaks/gitleaks) | Hardcoded secrets, tokens, and API keys | | `CI/security/pip-audit.yml` | [pip-audit](https://github.com/pypa/pip-audit) | CVEs in Python dependencies via the PyPI Advisory Database | | `CI/security/semgrep.yml` | [semgrep](https://semgrep.dev) | OWASP Top 10 patterns and insecure coding patterns across Python, JS/TS, Go, Java, Ruby, and more | diff --git a/scripts/CI/security/bundler-audit.yml b/scripts/CI/security/bundler-audit.yml new file mode 100644 index 0000000..78ddb9d --- /dev/null +++ b/scripts/CI/security/bundler-audit.yml @@ -0,0 +1,14 @@ +bundler-audit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: "3.3" + + - name: Install bundler-audit + run: gem install bundler-audit -v 0.9.2 + + - name: Run bundler-audit + run: bash scripts/shell/security/bundler-audit.sh diff --git a/scripts/shell/security/bundler-audit.sh b/scripts/shell/security/bundler-audit.sh new file mode 100644 index 0000000..df05237 --- /dev/null +++ b/scripts/shell/security/bundler-audit.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +set -euo pipefail + +if ! command -v bundle-audit &> /dev/null; then + echo "::error::bundle-audit not found. Install it before running this script." + exit 1 +fi + +if [[ ! -f "Gemfile.lock" ]]; then + echo "::error::No Gemfile.lock found. Run 'bundle install' to generate one." + exit 1 +fi + +echo "ℹ️ Running bundle-audit..." + +bundle-audit update +if bundle-audit check; then + echo "✅ bundler-audit passed" +else + echo "❌ bundler-audit found vulnerabilities" + exit 1 +fi diff --git a/tests/security/bundler-audit.bats b/tests/security/bundler-audit.bats new file mode 100644 index 0000000..010c7c6 --- /dev/null +++ b/tests/security/bundler-audit.bats @@ -0,0 +1,61 @@ +#!/usr/bin/env bats + +load "../helpers/common" + +SCRIPT="$BATS_TEST_DIRNAME/../../scripts/shell/security/bundler-audit.sh" + +setup() { + setup_test_dir + mkdir -p "$TEST_DIR/bin" + export PATH="$TEST_DIR/bin:$PATH" +} + +teardown() { + teardown_test_dir +} + +make_bundle_audit_stub() { + local check_exit_code="$1" + cat > "$TEST_DIR/bin/bundle-audit" <