@intentsolutionsio/jeremy-github-actions-gcp 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +25 -0
- package/LICENSE +21 -0
- package/README.md +410 -0
- package/agents/gh-actions-gcp-expert.md +599 -0
- package/hooks/hooks.json +26 -0
- package/package.json +48 -0
- package/scripts/validate-workflow.sh +72 -0
- package/skills/gh-actions-validator/SKILL.md +62 -0
- package/skills/gh-actions-validator/references/ARD.md +72 -0
- package/skills/gh-actions-validator/references/PRD.md +67 -0
- package/skills/gh-actions-validator/references/errors.md +24 -0
- package/skills/gh-actions-validator/references/examples.md +8 -0
- package/skills/gh-actions-validator/scripts/setup-wif.sh +59 -0
- package/skills/gh-actions-validator/scripts/validate-workflow.sh +56 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
#
|
|
3
|
+
# Validate GitHub Actions workflow for Vertex AI / GCP best practices
|
|
4
|
+
# This script is called by hooks before writing/editing workflow files
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
set -e
|
|
8
|
+
|
|
9
|
+
WORKFLOW_FILE="$1"
|
|
10
|
+
|
|
11
|
+
echo "🔍 Validating GitHub Actions workflow: $WORKFLOW_FILE"
|
|
12
|
+
|
|
13
|
+
# Check 1: WIF - Must use workload_identity_provider, NOT credentials_json
|
|
14
|
+
if grep -q "credentials_json" "$WORKFLOW_FILE"; then
|
|
15
|
+
echo "❌ SECURITY VIOLATION: JSON service account keys detected"
|
|
16
|
+
echo " Use Workload Identity Federation (WIF) instead:"
|
|
17
|
+
echo " workload_identity_provider: \${{ secrets.WIF_PROVIDER }}"
|
|
18
|
+
echo " service_account: \${{ secrets.WIF_SERVICE_ACCOUNT }}"
|
|
19
|
+
exit 1
|
|
20
|
+
fi
|
|
21
|
+
|
|
22
|
+
# Check 2: OIDC Permissions - Must have id-token: write for WIF
|
|
23
|
+
if grep -q "workload_identity_provider" "$WORKFLOW_FILE"; then
|
|
24
|
+
if ! grep -q "id-token: write" "$WORKFLOW_FILE"; then
|
|
25
|
+
echo "❌ MISSING REQUIRED PERMISSION: id-token: write"
|
|
26
|
+
echo " Workload Identity Federation requires OIDC token permission:"
|
|
27
|
+
echo ""
|
|
28
|
+
echo " permissions:"
|
|
29
|
+
echo " contents: read"
|
|
30
|
+
echo " id-token: write # REQUIRED for WIF"
|
|
31
|
+
exit 1
|
|
32
|
+
fi
|
|
33
|
+
fi
|
|
34
|
+
|
|
35
|
+
# Check 3: IAM - No overly permissive roles
|
|
36
|
+
if grep -E "roles/owner|roles/editor" "$WORKFLOW_FILE"; then
|
|
37
|
+
echo "❌ SECURITY VIOLATION: Overly permissive IAM roles detected"
|
|
38
|
+
echo " Use least privilege roles instead:"
|
|
39
|
+
echo " - roles/run.admin"
|
|
40
|
+
echo " - roles/iam.serviceAccountUser"
|
|
41
|
+
echo " - roles/aiplatform.user"
|
|
42
|
+
exit 1
|
|
43
|
+
fi
|
|
44
|
+
|
|
45
|
+
# Check 4: Secrets - No hardcoded values
|
|
46
|
+
if grep -E "GOOGLE_APPLICATION_CREDENTIALS.*=|GCP_SA_KEY.*=" "$WORKFLOW_FILE"; then
|
|
47
|
+
echo "❌ SECURITY VIOLATION: Hardcoded credentials detected"
|
|
48
|
+
echo " Use GitHub secrets: \${{ secrets.SECRET_NAME }}"
|
|
49
|
+
exit 1
|
|
50
|
+
fi
|
|
51
|
+
|
|
52
|
+
# Check 5: Vertex AI deployments - Must have post-deployment validation
|
|
53
|
+
if grep -q "vertex" "$WORKFLOW_FILE" || grep -q "aiplatform" "$WORKFLOW_FILE"; then
|
|
54
|
+
if ! grep -q "validate-deployment\|validate-agent" "$WORKFLOW_FILE"; then
|
|
55
|
+
echo "⚠️ WARNING: Vertex AI deployment without validation step"
|
|
56
|
+
echo " Add post-deployment validation:"
|
|
57
|
+
echo " - name: Validate Deployment"
|
|
58
|
+
echo " run: python scripts/validate-deployment.py"
|
|
59
|
+
fi
|
|
60
|
+
fi
|
|
61
|
+
|
|
62
|
+
# Check 6: Security scanning - Recommended for production workflows
|
|
63
|
+
if grep -q "deploy" "$WORKFLOW_FILE"; then
|
|
64
|
+
if ! grep -q "trivy\|trufflehog" "$WORKFLOW_FILE"; then
|
|
65
|
+
echo "⚠️ RECOMMENDATION: Add security scanning before deployment"
|
|
66
|
+
echo " - uses: aquasecurity/trivy-action@master"
|
|
67
|
+
echo " - uses: trufflesecurity/trufflehog@main"
|
|
68
|
+
fi
|
|
69
|
+
fi
|
|
70
|
+
|
|
71
|
+
echo "✅ GitHub Actions workflow validation passed"
|
|
72
|
+
exit 0
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: gh-actions-validator
|
|
3
|
+
description: |
|
|
4
|
+
Validate use when validating GitHub Actions workflows for Google Cloud and Vertex AI deployments. Trigger with phrases like "validate github actions", "setup workload identity federation", "github actions security", "deploy agent with ci/cd", or "automate vertex ai deployment". Enforces Workload Identity Federation (WIF), validates OIDC permissions, ensures least privilege IAM, and implements security best practices.
|
|
5
|
+
allowed-tools: Read, Write, Edit, Grep, Glob, Bash(git:*), Bash(gcloud:*)
|
|
6
|
+
version: 1.0.0
|
|
7
|
+
author: Jeremy Longshore <jeremy@intentsolutions.io>
|
|
8
|
+
license: MIT
|
|
9
|
+
compatible-with: claude-code, codex, openclaw
|
|
10
|
+
tags: [devops, deployment, gcp, security]
|
|
11
|
+
---
|
|
12
|
+
# Gh Actions Validator
|
|
13
|
+
|
|
14
|
+
## Overview
|
|
15
|
+
|
|
16
|
+
Validate and harden GitHub Actions workflows that deploy to Google Cloud (especially Vertex AI) using Workload Identity Federation (OIDC) instead of long-lived service account keys. Use this to audit existing workflows, propose a secure replacement, and add CI checks that prevent common credential and permission mistakes.
|
|
17
|
+
|
|
18
|
+
## Prerequisites
|
|
19
|
+
|
|
20
|
+
Before using this skill, ensure:
|
|
21
|
+
- GitHub repository with Actions enabled
|
|
22
|
+
- Google Cloud project with billing enabled
|
|
23
|
+
- gcloud CLI authenticated with admin permissions
|
|
24
|
+
- Understanding of Workload Identity Federation concepts
|
|
25
|
+
- GitHub repository secrets configured
|
|
26
|
+
- Appropriate IAM roles for CI/CD automation
|
|
27
|
+
|
|
28
|
+
## Instructions
|
|
29
|
+
|
|
30
|
+
1. **Audit Existing Workflows**: Scan .github/workflows/ for security issues
|
|
31
|
+
2. **Validate WIF Usage**: Ensure no JSON service account keys are used
|
|
32
|
+
3. **Check OIDC Permissions**: Verify id-token: write is present
|
|
33
|
+
4. **Review IAM Roles**: Confirm least privilege (no owner/editor roles)
|
|
34
|
+
5. **Add Security Scans**: Include secret detection and vulnerability scanning
|
|
35
|
+
6. **Validate Deployments**: Add post-deployment health checks
|
|
36
|
+
7. **Configure Monitoring**: Set up alerts for deployment failures
|
|
37
|
+
8. **Document WIF Setup**: Provide one-time WIF configuration commands
|
|
38
|
+
|
|
39
|
+
## Output
|
|
40
|
+
|
|
41
|
+
- uses: actions/checkout@v4
|
|
42
|
+
- name: Authenticate to GCP (WIF)
|
|
43
|
+
- name: Deploy to Vertex AI
|
|
44
|
+
--project=${{ secrets.GCP_PROJECT_ID }} \
|
|
45
|
+
--region=us-central1
|
|
46
|
+
- name: Validate Deployment
|
|
47
|
+
|
|
48
|
+
## Error Handling
|
|
49
|
+
|
|
50
|
+
See `${CLAUDE_SKILL_DIR}/references/errors.md` for comprehensive error handling.
|
|
51
|
+
|
|
52
|
+
## Examples
|
|
53
|
+
|
|
54
|
+
See `${CLAUDE_SKILL_DIR}/references/examples.md` for detailed examples.
|
|
55
|
+
|
|
56
|
+
## Resources
|
|
57
|
+
|
|
58
|
+
- Workload Identity Federation: https://cloud.google.com/iam/docs/workload-identity-federation
|
|
59
|
+
- GitHub OIDC: https://docs.github.com/en/actions/deployment/security-hardening-your-deployments
|
|
60
|
+
- Vertex AI Agent Engine: https://cloud.google.com/vertex-ai/docs/agent-engine
|
|
61
|
+
- google-github-actions/auth: https://github.com/google-github-actions/auth
|
|
62
|
+
- WIF setup guide in ${CLAUDE_SKILL_DIR}/docs/wif-setup.md
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# ARD: GH Actions Validator
|
|
2
|
+
|
|
3
|
+
> Part of [Tons of Skills](https://tonsofskills.com) by [Intent Solutions](https://intentsolutions.io) | [jeremylongshore.com](https://jeremylongshore.com)
|
|
4
|
+
|
|
5
|
+
## System Context
|
|
6
|
+
|
|
7
|
+
The GH Actions Validator inspects GitHub Actions workflow files and their associated GCP IAM configuration to ensure secure deployment patterns using Workload Identity Federation.
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
.github/workflows/*.yml
|
|
11
|
+
↓
|
|
12
|
+
[GH Actions Validator]
|
|
13
|
+
├── Reads: workflow YAML files, IAM policies
|
|
14
|
+
├── Scans: auth patterns, permissions, IAM roles
|
|
15
|
+
└── Generates: WIF setup commands, hardened workflows
|
|
16
|
+
↓
|
|
17
|
+
Validation Report + WIF Setup
|
|
18
|
+
├── Security findings (JSON keys, missing OIDC)
|
|
19
|
+
├── IAM role recommendations
|
|
20
|
+
├── WIF setup gcloud commands
|
|
21
|
+
└── Hardened workflow templates
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Data Flow
|
|
25
|
+
|
|
26
|
+
1. **Input**: Repository path containing `.github/workflows/` directory. Optionally a specific workflow file to validate. GCP project ID for IAM audit.
|
|
27
|
+
2. **Processing**: Parse all workflow YAML files. For each workflow: check for JSON key usage patterns, validate `google-github-actions/auth` action configuration, verify `id-token: write` permission, audit IAM roles on the authenticated service account via `gcloud`, check for post-deployment health steps. Generate WIF setup commands if not yet configured.
|
|
28
|
+
3. **Output**: Validation report listing security findings per workflow, IAM role audit results, WIF setup commands (if needed), and optionally a hardened workflow template with WIF auth and security scanning steps.
|
|
29
|
+
|
|
30
|
+
## Key Design Decisions
|
|
31
|
+
|
|
32
|
+
| Decision | Choice | Rationale |
|
|
33
|
+
|----------|--------|-----------|
|
|
34
|
+
| WIF over JSON keys | Require OIDC authentication for all GCP deployments | JSON keys are a security liability: they leak, never expire, and can't be scoped to repo/branch |
|
|
35
|
+
| `google-github-actions/auth@v2` | Standardize on Google's official auth action | Maintained by Google; handles token exchange correctly; supports audience and provider config |
|
|
36
|
+
| Least-privilege IAM audit | Flag owner/editor roles; suggest specific alternatives | Broad roles are the most common security misconfiguration in CI/CD pipelines |
|
|
37
|
+
| YAML-level validation | Parse workflow YAML rather than running workflows | Safe, fast, deterministic; no need for GitHub API tokens or workflow triggers |
|
|
38
|
+
| Idempotent WIF setup | All gcloud commands safe to re-run | Prevents errors when running setup on already-configured projects |
|
|
39
|
+
| Role-to-target mapping | Map deployment targets to minimum IAM roles | Cloud Run needs `roles/run.developer`, Agent Engine needs `roles/aiplatform.user`; prevents over-granting |
|
|
40
|
+
| Auth action version pinning | Require `@v2` not `@v1` or `@main` | Pinned versions are reproducible and auditable; `@main` can introduce breaking changes |
|
|
41
|
+
|
|
42
|
+
## Tool Usage Pattern
|
|
43
|
+
|
|
44
|
+
| Tool | Purpose |
|
|
45
|
+
|------|---------|
|
|
46
|
+
| Read | Parse workflow YAML files, IAM policy exports, and WIF configuration files |
|
|
47
|
+
| Write | Generate hardened workflow templates and WIF setup scripts |
|
|
48
|
+
| Edit | Patch existing workflows to add OIDC permissions, update auth actions, add health checks |
|
|
49
|
+
| Grep | Search for JSON key patterns (`credentials_json`, `GOOGLE_APPLICATION_CREDENTIALS`), IAM role references |
|
|
50
|
+
| Glob | Discover all workflow files in `.github/workflows/` |
|
|
51
|
+
| Bash(git:*) | Check git history for committed credentials or key files |
|
|
52
|
+
| Bash(gcloud:*) | Query IAM policies, list service accounts, check WIF pool/provider configuration |
|
|
53
|
+
|
|
54
|
+
## Error Handling Strategy
|
|
55
|
+
|
|
56
|
+
| Error Class | Detection | Recovery |
|
|
57
|
+
|------------|-----------|----------|
|
|
58
|
+
| Invalid workflow YAML | YAML parse failure on workflow file | Report syntax error location; suggest `yamllint` for detailed diagnostics |
|
|
59
|
+
| Missing OIDC permission | `id-token: write` not in job permissions | Provide the exact `permissions:` block to add to the workflow |
|
|
60
|
+
| WIF pool not configured | `gcloud iam workload-identity-pools describe` returns not found | Generate the complete set of `gcloud` commands to create pool, provider, and IAM binding |
|
|
61
|
+
| Overprivileged IAM role | Service account has `roles/owner` or `roles/editor` | Suggest the minimum required roles for the specific deployment target (e.g., `roles/run.developer`) |
|
|
62
|
+
| Auth action outdated | `google-github-actions/auth@v1` in workflow | Recommend upgrading to `@v2` with the updated parameter names |
|
|
63
|
+
|
|
64
|
+
## Extension Points
|
|
65
|
+
|
|
66
|
+
- Multi-cloud support: extend patterns to validate AWS OIDC or Azure federated credentials
|
|
67
|
+
- Branch-scoped WIF: configure attribute conditions that restrict authentication to specific branches
|
|
68
|
+
- Reusable workflow validation: audit called workflows and composite actions for the same security patterns
|
|
69
|
+
- Policy-as-code: define organization-level security policies that all workflows must satisfy
|
|
70
|
+
- Automated remediation: apply fixes to workflow files with user confirmation
|
|
71
|
+
- Compliance reports: generate audit reports showing WIF adoption percentage across all workflows
|
|
72
|
+
- Team templates: generate organization-level reusable workflows with pre-configured WIF
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# PRD: GH Actions Validator
|
|
2
|
+
|
|
3
|
+
**Version:** 1.0.0
|
|
4
|
+
**Author:** Jeremy Longshore <jeremy@intentsolutions.io>
|
|
5
|
+
**Status:** Active
|
|
6
|
+
**Marketplace:** [tonsofskills.com](https://tonsofskills.com) by [Intent Solutions](https://intentsolutions.io)
|
|
7
|
+
**Portfolio:** [jeremylongshore.com](https://jeremylongshore.com)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Problem Statement
|
|
12
|
+
|
|
13
|
+
GitHub Actions workflows that deploy to Google Cloud commonly use long-lived service account JSON keys stored as repository secrets. This practice violates security best practices: keys can leak, never expire, and grant broad permissions. Migrating to Workload Identity Federation (WIF) with OIDC requires coordinating multiple GCP resources (workload identity pool, provider, IAM bindings) and GitHub workflow changes (id-token permissions, auth action). Developers misconfigure these steps, resulting in authentication failures and insecure fallbacks to JSON keys.
|
|
14
|
+
|
|
15
|
+
## Target Users
|
|
16
|
+
|
|
17
|
+
| User | Context | Primary Need |
|
|
18
|
+
|------|---------|-------------|
|
|
19
|
+
| DevOps Engineer | Setting up CI/CD for GCP deployments from GitHub Actions | Secure WIF configuration with validated OIDC permissions |
|
|
20
|
+
| Security Engineer | Auditing existing workflows for credential hygiene | Detection of JSON key usage and insecure IAM patterns |
|
|
21
|
+
| Platform Engineer | Standardizing deployment pipelines across teams | Reusable, validated workflow templates with least-privilege IAM |
|
|
22
|
+
| Developer | Deploying Vertex AI agents or Cloud Run services via GitHub Actions | Working workflow with WIF auth and post-deployment health checks |
|
|
23
|
+
|
|
24
|
+
## Success Criteria
|
|
25
|
+
|
|
26
|
+
1. Detect 100% of JSON service account key usage in workflow files (secrets or files)
|
|
27
|
+
2. Validate OIDC `id-token: write` permission is present in all deployment workflows
|
|
28
|
+
3. Confirm no `roles/owner` or `roles/editor` IAM bindings in deployment service accounts
|
|
29
|
+
4. Provide complete WIF setup commands that work on first execution
|
|
30
|
+
5. Hardened workflow template includes secret scanning and dependency vulnerability checks
|
|
31
|
+
6. Post-deployment health checks validate endpoint availability before marking success
|
|
32
|
+
|
|
33
|
+
## Functional Requirements
|
|
34
|
+
|
|
35
|
+
1. Scan `.github/workflows/` for all YAML workflow files
|
|
36
|
+
2. Detect JSON service account key usage: `GOOGLE_APPLICATION_CREDENTIALS`, key file references, `credentials_json` inputs
|
|
37
|
+
3. Validate WIF authentication: `google-github-actions/auth@v2` action with `workload_identity_provider` parameter
|
|
38
|
+
4. Check OIDC permissions: `id-token: write` in the `permissions` block of deployment jobs
|
|
39
|
+
5. Review IAM roles on deployment service accounts: flag `roles/owner`, `roles/editor`, and recommend least-privilege alternatives
|
|
40
|
+
6. Add security scanning steps: secret detection, dependency vulnerability scanning
|
|
41
|
+
7. Validate post-deployment health checks exist for each deploy step
|
|
42
|
+
8. Generate WIF one-time setup commands for the GCP project
|
|
43
|
+
|
|
44
|
+
## Non-Functional Requirements
|
|
45
|
+
|
|
46
|
+
- Validation must work on any GitHub Actions YAML regardless of deployment target (Cloud Run, Agent Engine, Functions)
|
|
47
|
+
- WIF setup commands must be idempotent (safe to re-run without side effects)
|
|
48
|
+
- Must handle matrix builds and reusable workflow patterns
|
|
49
|
+
- No modifications to workflows without explicit user consent
|
|
50
|
+
- YAML parsing must handle all GitHub Actions syntax including anchors, aliases, and expressions
|
|
51
|
+
- Validation must complete offline (no GitHub API calls required for YAML analysis)
|
|
52
|
+
|
|
53
|
+
## Dependencies
|
|
54
|
+
|
|
55
|
+
- GitHub repository with Actions enabled and workflow files in `.github/workflows/`
|
|
56
|
+
- Google Cloud project with billing enabled
|
|
57
|
+
- `gcloud` CLI authenticated with admin permissions (for WIF setup)
|
|
58
|
+
- `google-github-actions/auth@v2` action available on GitHub
|
|
59
|
+
|
|
60
|
+
## Out of Scope
|
|
61
|
+
|
|
62
|
+
- Non-GCP deployment targets (AWS, Azure)
|
|
63
|
+
- GitHub Actions runner self-hosting configuration
|
|
64
|
+
- Application-level testing within workflows (unit tests, integration tests)
|
|
65
|
+
- Cost optimization of GitHub Actions minutes
|
|
66
|
+
- GitHub App or OAuth token management
|
|
67
|
+
- Workflow performance optimization (caching, parallelism)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Error Handling Reference
|
|
2
|
+
|
|
3
|
+
**WIF Authentication Failed**
|
|
4
|
+
- Error: "Failed to generate Google Cloud access token"
|
|
5
|
+
- Solution: Verify WIF provider and service account email are correct
|
|
6
|
+
|
|
7
|
+
**OIDC Token Error**
|
|
8
|
+
- Error: "Unable to get ACTIONS_ID_TOKEN_REQUEST_URL env variable"
|
|
9
|
+
- Solution: Add `id-token: write` permission to workflow
|
|
10
|
+
|
|
11
|
+
**IAM Permission Denied**
|
|
12
|
+
- Error: "does not have required permission"
|
|
13
|
+
- Solution: Grant service account minimum required roles (run.admin, aiplatform.user)
|
|
14
|
+
|
|
15
|
+
**Attribute Condition Failed**
|
|
16
|
+
- Error: "Token does not match attribute condition"
|
|
17
|
+
- Solution: Update attribute mapping to include repository restriction
|
|
18
|
+
|
|
19
|
+
**Deployment Validation Failed**
|
|
20
|
+
- Error: "Agent not in RUNNING state"
|
|
21
|
+
- Solution: Check agent configuration and deployment logs
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
*[Tons of Skills](https://tonsofskills.com) by [Intent Solutions](https://intentsolutions.io) | [jeremylongshore.com](https://jeremylongshore.com)*
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Examples
|
|
2
|
+
|
|
3
|
+
**Example: Harden an existing deployment workflow**
|
|
4
|
+
- Input: `.github/workflows/deploy.yml` that uses `credentials_json` or a downloaded service account key.
|
|
5
|
+
- Output: a WIF-based workflow using `google-github-actions/auth@v2`, minimal IAM roles, and a guardrail job that fails PRs when JSON keys appear in workflows.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
*[Tons of Skills](https://tonsofskills.com) by [Intent Solutions](https://intentsolutions.io) | [jeremylongshore.com](https://jeremylongshore.com)*
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# setup-wif.sh - Setup Workload Identity Federation for GitHub Actions
|
|
3
|
+
|
|
4
|
+
set -euo pipefail
|
|
5
|
+
|
|
6
|
+
PROJECT_ID="${1:-}"
|
|
7
|
+
REPO_OWNER="${2:-}"
|
|
8
|
+
REPO_NAME="${3:-}"
|
|
9
|
+
|
|
10
|
+
if [[ -z "$PROJECT_ID" ]] || [[ -z "$REPO_OWNER" ]] || [[ -z "$REPO_NAME" ]]; then
|
|
11
|
+
cat <<EOF
|
|
12
|
+
Usage: $0 <PROJECT_ID> <REPO_OWNER> <REPO_NAME>
|
|
13
|
+
|
|
14
|
+
Setup Workload Identity Federation for GitHub Actions GCP authentication.
|
|
15
|
+
|
|
16
|
+
Example:
|
|
17
|
+
$0 my-project jeremylongshore my-repo
|
|
18
|
+
|
|
19
|
+
EOF
|
|
20
|
+
exit 1
|
|
21
|
+
fi
|
|
22
|
+
|
|
23
|
+
echo "Setting up Workload Identity Federation"
|
|
24
|
+
echo "Project: $PROJECT_ID"
|
|
25
|
+
echo "Repository: $REPO_OWNER/$REPO_NAME"
|
|
26
|
+
echo ""
|
|
27
|
+
|
|
28
|
+
# Create workload identity pool
|
|
29
|
+
echo "Creating workload identity pool..."
|
|
30
|
+
gcloud iam workload-identity-pools create "github-pool" \
|
|
31
|
+
--project="$PROJECT_ID" \
|
|
32
|
+
--location="global" \
|
|
33
|
+
--display-name="GitHub Actions Pool" || echo "Pool may already exist"
|
|
34
|
+
|
|
35
|
+
# Create OIDC provider
|
|
36
|
+
echo "Creating OIDC provider..."
|
|
37
|
+
gcloud iam workload-identity-pools providers create-oidc "github-provider" \
|
|
38
|
+
--project="$PROJECT_ID" \
|
|
39
|
+
--location="global" \
|
|
40
|
+
--workload-identity-pool="github-pool" \
|
|
41
|
+
--issuer-uri="https://token.actions.githubusercontent.com" \
|
|
42
|
+
--attribute-mapping="google.subject=assertion.sub,attribute.repository=assertion.repository" \
|
|
43
|
+
--attribute-condition="assertion.repository=='$REPO_OWNER/$REPO_NAME'" || echo "Provider may already exist"
|
|
44
|
+
|
|
45
|
+
# Get WIF provider name
|
|
46
|
+
WIF_PROVIDER="projects/$(gcloud projects describe "$PROJECT_ID" --format='value(projectNumber)')/locations/global/workloadIdentityPools/github-pool/providers/github-provider"
|
|
47
|
+
|
|
48
|
+
echo ""
|
|
49
|
+
echo "✓ Workload Identity Federation configured"
|
|
50
|
+
echo ""
|
|
51
|
+
echo "Add these secrets to your GitHub repository:"
|
|
52
|
+
echo " WIF_PROVIDER: $WIF_PROVIDER"
|
|
53
|
+
echo " GCP_PROJECT_ID: $PROJECT_ID"
|
|
54
|
+
echo ""
|
|
55
|
+
echo "Create a service account and grant it access:"
|
|
56
|
+
echo " gcloud iam service-accounts create github-actions --project=$PROJECT_ID"
|
|
57
|
+
echo " gcloud iam service-accounts add-iam-policy-binding github-actions@$PROJECT_ID.iam.gserviceaccount.com \\"
|
|
58
|
+
echo " --role=roles/iam.workloadIdentityUser \\"
|
|
59
|
+
echo " --member=\"principalSet://iam.googleapis.com/$WIF_PROVIDER/attribute.repository/$REPO_OWNER/$REPO_NAME\""
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# validate-workflow.sh - Validate GitHub Actions workflows for GCP security
|
|
3
|
+
|
|
4
|
+
set -euo pipefail
|
|
5
|
+
|
|
6
|
+
WORKFLOW_DIR="${1:-.github/workflows}"
|
|
7
|
+
|
|
8
|
+
echo "Validating GitHub Actions Workflows"
|
|
9
|
+
echo "Directory: $WORKFLOW_DIR"
|
|
10
|
+
echo ""
|
|
11
|
+
|
|
12
|
+
ISSUES=0
|
|
13
|
+
|
|
14
|
+
# Check for WIF usage
|
|
15
|
+
echo "Checking for Workload Identity Federation..."
|
|
16
|
+
if grep -r "workload_identity_provider" "$WORKFLOW_DIR" 2>/dev/null; then
|
|
17
|
+
echo "✓ Using Workload Identity Federation"
|
|
18
|
+
else
|
|
19
|
+
echo "✗ No WIF configuration found - use WIF instead of JSON keys"
|
|
20
|
+
((ISSUES++))
|
|
21
|
+
fi
|
|
22
|
+
|
|
23
|
+
# Check for JSON keys (security issue)
|
|
24
|
+
echo "Checking for JSON service account keys..."
|
|
25
|
+
if grep -r "credentials_json\|service-account.*json" "$WORKFLOW_DIR" 2>/dev/null; then
|
|
26
|
+
echo "✗ JSON keys detected - migrate to Workload Identity Federation"
|
|
27
|
+
((ISSUES++))
|
|
28
|
+
else
|
|
29
|
+
echo "✓ No JSON keys found"
|
|
30
|
+
fi
|
|
31
|
+
|
|
32
|
+
# Check for OIDC permissions
|
|
33
|
+
echo "Checking for id-token permissions..."
|
|
34
|
+
if grep -r "id-token.*write" "$WORKFLOW_DIR" 2>/dev/null; then
|
|
35
|
+
echo "✓ OIDC permissions configured"
|
|
36
|
+
else
|
|
37
|
+
echo "⚠ Missing 'id-token: write' permission"
|
|
38
|
+
((ISSUES++))
|
|
39
|
+
fi
|
|
40
|
+
|
|
41
|
+
# Check for security scans
|
|
42
|
+
echo "Checking for security scans..."
|
|
43
|
+
if grep -r "trufflehog\|trivy\|snyk" "$WORKFLOW_DIR" 2>/dev/null; then
|
|
44
|
+
echo "✓ Security scanning configured"
|
|
45
|
+
else
|
|
46
|
+
echo "⚠ No security scanning detected"
|
|
47
|
+
fi
|
|
48
|
+
|
|
49
|
+
echo ""
|
|
50
|
+
if (( ISSUES == 0 )); then
|
|
51
|
+
echo "✓ Workflows are secure"
|
|
52
|
+
exit 0
|
|
53
|
+
else
|
|
54
|
+
echo "✗ Found $ISSUES security issues"
|
|
55
|
+
exit 1
|
|
56
|
+
fi
|