Drift detection
Drift detection helps teams monitor alignment between their lockfile and approved rule sources. It identifies when rules have changed upstream, when vendored packs differ from their sources, or when severity remapping policies have been modified.
Overview
Drift detection compares your lockfile’s rule hashes against:
- Allowed sources - Approved versions in
.aligntrue/allow.yaml - Vendored packs - Integrity of git submodule/subtree vendored rules
- Severity remapping - Policy changes in
.aligntrue.team.yaml
Key benefits:
- Catch upstream rule changes before they cause issues
- Verify vendored pack integrity
- Monitor policy compliance
- CI/CD integration with
--gatesflag
Drift categories
Upstream drift
What it detects: Rule content in lockfile differs from the approved version in allow list.
Common causes:
- Upstream pack updated to new version
- Local modifications to rules
- Allow list not updated after rule changes
How to fix:
# Review the changes
aligntrue drift
# Approve new version
aligntrue team approve <source>@<new-version>
# Or accept current state
aligntrue sync --forceVendorized drift
What it detects: Vendored pack (git submodule/subtree) differs from source or is missing.
Common causes:
- Vendored pack deleted or moved
- Pack updated without re-linking
- Missing
.aligntrue.yamlin vendored path
How to fix:
# Update vendored pack
cd vendor/pack-name
git pull
cd ../..
# Re-sync
aligntrue syncSeverity remap drift
What it will detect: Changes to .aligntrue.team.yaml severity remapping rules.
Common causes:
- Policy downgrade without rationale
- Remapping rules modified
Usage
Basic drift check
# Show drift (human-readable)
aligntrue drift
# Output:
# Drift detection report
# ======================
#
# Upstream drift (1 items):
# • base-global: Lockfile hash differs from allowed version
# Suggestion: Run: aligntrue team approve git:...CI integration
# Exit non-zero if drift detected
aligntrue drift --gates
# Exit codes:
# 0 = No drift detected
# 2 = Drift detected (only with --gates)JSON output
# Machine-readable output
aligntrue drift --json
# Output:
# {
# "driftDetected": true,
# "mode": "team",
# "lockfilePath": ".aligntrue.lock.json",
# "summary": "2 drift findings across 2 categories",
# "driftByCategory": {
# "upstream": [...],
# "vendorized": [...]
# }
# }SARIF output
# For GitHub/GitLab CI integration
aligntrue drift --sarif > drift-report.sarif
# Upload to GitHub code scanning
# (GitHub Actions example in CI workflows section)CI workflows
GitHub Actions
GitHub Actions
name: Drift Detection
on:
schedule:
- cron: "0 0 * * *" # Daily at midnight
workflow_dispatch:
jobs:
drift:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
- name: Install dependencies
run: npm install -g @aligntrue/cli
- name: Check for drift
run: aligntrue drift --sarif > drift.sarif
- name: Upload SARIF
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: drift.sarifPre-commit hook
#!/bin/sh
# .git/hooks/pre-commit
# Check for drift before committing lockfile changes
if git diff --cached --name-only | grep -q ".aligntrue.lock.json"; then
echo "Lockfile changed, checking for drift..."
aligntrue drift --gates
fiTroubleshooting
”Drift detection requires team mode”
Cause: Running aligntrue drift in solo mode.
Solution:
# Enable team mode
aligntrue team enable
# Or set in config
echo "mode: team" >> .aligntrue/config.yaml“Lockfile not found”
Cause: No lockfile generated yet.
Solution:
# Generate lockfile
aligntrue sync“Allow list not found”
Cause: No sources approved yet.
Solution:
# Approve sources
aligntrue team approve <source>
# Or create allow list manually
# .aligntrue/allow.yamlFalse positives
Scenario: Drift reported but you know rules haven’t changed.
Debugging:
- Check lockfile generation date
- Verify allow list hashes
- Re-sync to update lockfile
- Check for local modifications
Solution:
# Regenerate lockfile
aligntrue sync --force
# Update allow list
aligntrue team approve <source>@latestConfiguration
Drift detection uses your existing AlignTrue configuration:
# .aligntrue/config.yaml
mode: team # Required for drift detection
# Lockfile settings
modules:
lockfile: true # Required
lockfile:
mode: soft # or strict
# Performance settings (optional)
performance:
max_file_size_kb: 1024
respect_gitignore: trueBest practices
Regular monitoring
- Run
aligntrue driftin CI daily or on schedule - Use
--gatesflag in PR checks to block on drift - Review drift reports during team sync meetings
When to use —gates
Use --gates flag when:
- Enforcing strict version control
- Blocking PRs with unauthorized changes
- Maintaining compliance requirements
Don’t use --gates when:
- Exploring drift informally
- Learning about upstream changes
- Testing new rule versions
Handling drift findings
Upstream drift:
- Review changelog for upstream pack
- Test changes in dev environment
- Approve new version or pin current
- Update documentation
Vendorized drift:
- Check git submodule/subtree status
- Update vendored pack if appropriate
- Re-link and re-sync
- Commit vendored changes
Related documentation
- Team mode - Team collaboration features
- Git workflows - Pull and link commands
- Commands - All CLI commands reference
See also
- Allow list:
.aligntrue/allow.yamlformat and approval workflow - Lockfile:
.aligntrue.lock.jsongeneration and validation - Team mode: Enabling and configuring team collaboration