Prompt
How do I add approval workflows to GitLab CI/CD with audit logs?
Latest observation
You can add approval workflows to GitLab CI/CD by combining:
- Protected branches/tags
- Merge request approvals
- Manual jobs in CI/CD
- Audit events / audit logs
- Optionally, compliance pipelines and external approvals
Here’s the practical way to do it.
1) Use merge request approvals for code changes
This is the most common approval gate before CI/CD runs deploy or release steps.
Setup
In your GitLab project:
- Go to Settings → Merge requests
- Configure:
- Approval rules
- Required number of approvals
- Optional approvers/groups
- Code owner approvals
Use CODEOWNERS
Add a CODEOWNERS file so certain files require approval from specific teams.
Example:
/docs/ @docs-team
/infra/ @platform-team
*.tf @devops-team
Then enable Code owner approval in project settings.
Benefits
- Enforces peer review
- Tracks who approved what
- Works well with auditability through GitLab events
2) Add manual approval gates in .gitlab-ci.yml
If you want approval before a deployment, use a manual job.
Example:
stages:
- test
- build
- approve
- deploy
test:
stage: test
script:
- echo "Running tests"
build:
stage: build
script:
- echo "Building app"
approve_deploy:
stage: approve
when: manual
allow_failure: false
script:
- echo "Deployment approved"
deploy_prod:
stage: deploy
script:
- echo "Deploying to production"
needs: ["approve_deploy"]
environment:
name: production
How it works
- Pipeline pauses at
approve_deploy - A permitted user clicks Play
- Only then does
deploy_prodrun
Notes
- Manual jobs are useful, but they are not the same as a formal approval system unless you restrict who can trigger them via project permissions.
- For stronger control, combine this with protected environments.
3) Protect environments for deployment approvals
GitLab lets you restrict who can deploy to environments like production.
Setup
Go to:
- Settings → CI/CD → Protected environments
Add production and allow only specific users or roles to deploy.
In .gitlab-ci.yml
deploy_prod:
stage: deploy
script:
- ./deploy.sh
environment:
name: production
Result
Only authorized users can trigger or approve deploys to production.
4) Use protected branches/tags to control release flow
Protect your main or release branches so only approved merges happen.
Setup
Go to:
- Settings → Repository → Protected branches
Protect:
mainrelease/*
You can require:
- Maintainers only to push
- Merge requests only
- No direct pushes
This ensures approvals happen through the MR process, not direct commits.
5) Add audit logs for approval actions
GitLab provides auditability through Audit Events.
Where to find them
Depending on your GitLab edition and setup:
- Group → Audit Events
- Admin Area → Audit Events
- Sometimes project-level event history is available too
What gets logged
Typical audit events can include:
- User added/removed from groups
- Changes to protected branches/environments
- Changes to approval rules
- Role changes
- Some security/compliance actions
CI/CD approval logging
For manual jobs and deployment approvals:
- GitLab records job execution and user who triggered the job
- Deployment history shows who deployed what and when
- If using protected environments, authorization is tied to the user account
Best practice
To make approval actions easier to audit:
- Use protected environments
- Require MRs for production changes
- Use approval rules and CODEOWNERS
- Keep deploy jobs manual
- Centralize logs to your SIEM if needed
6) Optional: use an approval job with a separate approver group
If you want a visible “approval” step in the pipeline:
approve_release:
stage: approve
when: manual
allow_failure: false
script:
- echo "Approved by release manager"
deploy_release:
stage: deploy
script:
- ./deploy.sh
needs: ["approve_release"]
Then combine with:
- Protected environment
production - Allowed deployers group
- Approvals in the MR before pipeline runs
7) Make approvals more formal with policy-as-code
If you need stricter governance, consider:
- Code Owners
- Compliance pipelines
- Security approvals
- External policy engines like:
- OPA/Gatekeeper
- Custom validation jobs
- ChatOps approval workflows
A common pattern is:
- Merge request needs 2 approvals
- Pipeline runs tests
- Release job is manual
- Only release managers can approve deploy to production
- Audit trail records approver, timestamp, and environment
Example end-to-end workflow
1. Developer opens MR
- Branch change is reviewed
- Required approvers sign off
2. Pipeline runs automatically
- Tests, lint, build, security scans
3. Deploy job is manual
deploy_prodwaits for approval
4. Protected environment enforces access
- Only deployment approvers can trigger it
5. Audit trail captured
- MR approvals
- Manual job trigger
- Deployment event
- All timestamps and users visible in GitLab logs
Recommended configuration for production
If your goal is “strong approval workflow with auditability,” use all three:
- MR approvals + CODEOWNERS
- Protected branch
- Protected production environment with manual deploy job
That gives you:
- Review before merge
- Approval before deploy
- Audit record of who approved and deployed
If you want, I can help with either of these next:
- A sample
.gitlab-ci.ymlwith approval gates and production deployment - A step-by-step GitLab UI setup guide
- A compliance/audit logging design for regulated environments
Brands