Lab: CI/CD Guardrails in Practice
Goal
Validate each guardrail layer by triggering it:
- pre-commit hooks block unsafe local operations
- CI pipeline structure enforces plan-approve-apply
- CodeRabbit configuration provides automated review coverage
Prerequisites
pre-commitinstalled (pip install pre-commitorbrew install pre-commit)- Access to the
sre/platform repository - Familiarity with GitHub Actions workflow syntax
Step 1: Install Pre-commit Hooks
cd sre/
pre-commit install --install-hooks
Verify installation:
ls -la .git/hooks/pre-commit
pre-commit --version
Expected:
- hook symlink present
- pre-commit version output
Step 2: Trigger Branch Protection Hook
Attempt to commit directly on main:
git checkout main
echo "# test" >> README.md
git add README.md
git commit -m "test direct commit to main"
Expected:
- commit is blocked by
master-branch-check.sh - error message indicates direct commits to main/master are not allowed
Clean up:
git checkout -- README.md
git checkout - # return to previous branch
Step 3: Trigger Secret Blocking Hook
Create a test file that matches secret patterns:
git checkout -b test-hooks
echo "KUBECONFIG=/home/user/.kube/config" > test.env
git add test.env
git commit -m "test secret detection"
Expected:
- commit is blocked by
block-secrets.sh - error identifies the
.envfile as a potential secret
Clean up:
rm test.env
git reset HEAD test.env
Step 4: Trigger Flux Manifest Validation
Introduce a deliberate YAML error in a Flux manifest:
cp flux/apps/backend/base/deployment.yaml flux/apps/backend/base/deployment.yaml.bak
# Add invalid YAML (wrong indentation)
echo " invalid_field: [unclosed" >> flux/apps/backend/base/deployment.yaml
git add flux/apps/backend/base/deployment.yaml
git commit -m "test flux validation"
Expected:
- commit is blocked by
flux-kustomize-validate.sh - error shows YAML syntax or kustomize build failure
Clean up:
mv flux/apps/backend/base/deployment.yaml.bak flux/apps/backend/base/deployment.yaml
git restore --staged flux/apps/backend/base/deployment.yaml 2>/dev/null || true
git checkout -- flux/apps/backend/base/deployment.yaml
git checkout - 2>/dev/null || true
git branch -D test-hooks 2>/dev/null || true
Step 5: Review GitHub Actions Pipeline Structure
Open .github/workflows/terraform-hcloud.yml and identify:
- Concurrency block: What does
cancel-in-progress: falseprotect against? - Plan job: What artifact is uploaded and with what retention?
- Approval gate: Which manual approval action is used? What is the timeout?
- Apply job: How does it retrieve the exact plan that was reviewed?
- Secret handling: How are credentials passed to Terraform?
Record answers for each question.
Step 6: Analyze the Destroy Workflow
Open .github/workflows/terraform-hcloud-destroy.yml and identify:
- What confirmation string is required to trigger destroy?
- How many approvers are required?
- What cleanup steps run before
terraform destroy?
Step 7: Review CodeRabbit Configuration
Open .coderabbit.yml and identify:
- What review profile is used and what does it mean?
- Which security scanning tools are enabled?
- Are there path-specific review rules?
Step 8: Evidence Collection
For lab completion, document:
- Screenshot or terminal output of a blocked commit (branch protection, secret detection, or manifest validation)
- Written answers to the pipeline analysis questions from Steps 5-7
- Guardrails layer diagram — draw or describe the 4-layer model:
- What each layer catches
- What happens if that layer is bypassed
Failure Scenarios
Pre-commit hooks not installed
pre-commit run --all-filesreports no hooks configured- solution:
pre-commit install --install-hooks
Hook passes when it should block
- verify hook script is executable
- verify
.pre-commit-config.yamlreferences correct script path
CI pipeline applies without approval
- verify manual approval step is present in workflow
- verify approvers and
timeout-minutesare configured
Done When
- Learner has triggered at least two different pre-commit hooks and seen them block
- Learner can explain the Plan-Approve-Apply pipeline flow
- Learner can describe what CodeRabbit adds beyond human review
- Learner can draw the 4-layer guardrails model with examples of what each catches