cbs CDS Guard
Nobody changes a protected CDS entity, annotation or code block by accident, on any Git platform.
npm License Node.js SAP CAP Platforms
cds-guard protects the parts of a CAP or UI5 project that must not change without the right
people noticing: a CDS entity or a single element, a Fiori annotation, a block of code, a file or
a value in manifest.json. You list them in .guard/protected.yml, together with who may approve
a change.
cds-guard lock stores a fingerprint of each protected item in a lock file. cds-guard check
runs in the pull request pipeline and fails when a protected item no longer matches. A deliberate
change updates the lock file, and the lock file can only be merged with approval from the rule's
approvers, through your Git platform's own code owners. No API tokens, no platform-specific code:
the same setup works on GitHub, Azure DevOps, Bitbucket and GitLab.
$ npx cds-guard check
cds-guard: protected items changed.
✗ rule "pricing-model" (Prices and order amounts)
changed cds:my.app.Orders.netAmount content changed
changed annotation:my.app.Orders:@UI.LineItem content changed
If this change is intended: run "npx cds-guard lock --rule pricing-model", commit the lock file and get approval from @my-org/team-pricing.
✨ What works where
What can be protected
| What | Example in protected.yml | Counts as a change | Doesn't count |
|---|---|---|---|
| CDS entity, type, service, aspect | cds: [ my.app.Prices ] | elements, types, keys, associations, annotations on it (from any file) | comments, formatting, file moves |
| CDS element | cds: [ my.app.Orders.netAmount ] | its type, length, default, annotations | other elements of the entity |
| CDS structure only | ignoreAnnotations: true | types and elements | annotations and doc comments |
| CDS annotation | annotations: [ "my.app.Orders:@UI.LineItem" ] | the annotation, its qualified variants (#Compact) and sub-terms, also when added in another .cds file | everything else on the entity |
| Code block | markers: [ tax-calc ] | anything between @protected-begin tax-calc and @protected-end, a removed or extra block | trailing spaces, line endings, code around the block |
| File | paths: [ "app/*/webapp/annotations/*.xml" ] | content, a new file matching the pattern, a deleted file | line endings, trailing spaces |
| JSON value | json: [{ file: …/manifest.json, pointers: [ /sap.app/id ] }] | the value at the pointer | formatting, other values |
CDS items are compared on the compiled model (CSN) that @sap/cds builds, so an annotate in
another file is caught and a reformat is not. Markers work in any language that has comments:
//, #, /* */, <!-- -->.
Platforms
| Platform | Pipeline | Approval of lock files | Generated by cds-guard codeowners |
|---|---|---|---|
| GitHub | action.yml | CODEOWNERS + "Require review from Code Owners" | .github/CODEOWNERS block |
| Azure DevOps | ci/azure-pipelines/cds-guard.yml | Branch policy "Automatically included reviewers", required, with path filter | az repos policy required-reviewer script |
| Bitbucket | ci/bitbucket/bitbucket-pipelines.yml | CODEOWNERS (enforced with a merge check; check your plan) | .bitbucket/CODEOWNERS block |
| GitLab | ci/gitlab/cds-guard.gitlab-ci.yml | CODEOWNERS + "Code owner approval" (Premium) | CODEOWNERS block with a [cds-guard] section |
| Anything else (Jenkins, …) | npx @cbs-consulting/cds-guard check | whatever path-based reviewers the platform has | – |
🚀 Quick start
npm install --save-dev @cbs-consulting/cds-guard # your project already has @sap/cds
npx cds-guard init # creates .guard/protected.yml
# add rules to .guard/protected.yml
npx cds-guard lock # writes .guard/locks/*.lock
npx cds-guard codeowners --write # or --platform azure|gitlab|bitbucket
npx cds-guard skill --write # optional: teaches AI coding agents the guard
git add .guard .github/CODEOWNERS && git commit -m "Protect the pricing model"
Then add the check to your pipeline and make it required (see Set up your platform).
📝 Configuration
.guard/protected.yml:
version: 1
cds:
root: . # where the CAP project is (default: the repository root)
# model: [ db, srv, app ] # load these folders or files instead of the CAP defaults
# Who must approve changes to the guard itself: .guard/protected.yml and the lock files of
# rules without approvers.
guardOwners: [ "@my-org/leads" ]
# Further files only the guard owners may change, such as the pipeline that runs cds-guard.
guardPaths: [ .github/workflows/cds-guard.yml ]
# Extra glob patterns to skip when looking for files and markers.
ignore: [ "test/**" ]
rules:
- id: pricing-model
description: Prices and order amounts
cds: [ my.app.Prices, my.app.Orders.netAmount ]
annotations: [ "my.app.Orders:@UI.LineItem", "my.app.Orders:@UI.HeaderInfo" ]
approvers: [ "@my-org/team-pricing", alice ]
- id: tax-formula
markers: [ tax-calc ]
markerFiles: [ "srv/**/*.js" ] # where to look (default: all text files)
approvers: [ bob@example.com ]
- id: frozen-ui
paths: [ "app/orders/webapp/annotations/*.xml" ]
json:
- file: app/orders/webapp/manifest.json
pointers: [ /sap.app/id, /sap.ui5/routing ]
| Key | Meaning |
|---|---|
id | Name of the rule and its lock file .guard/locks/<id>.lock. Letters, digits, ., _, -. |
cds | Fully qualified definitions (ns.Entity) or elements (ns.Entity.element, also nested ns.Entity.struct.field). |
ignoreAnnotations | Compare cds items without their annotations and doc comments. |
annotations | target:@Term, where target is a definition or element. @UI.HeaderInfo covers @UI.HeaderInfo.TypeName and @UI.HeaderInfo#Q. |
markers, markerFiles | Marker ids and the glob patterns of files to search. |
paths | Glob patterns of whole files. |
json | Files and JSON pointers inside them. |
approvers | Who approves changes, in the format of your platform: @user, @org/team, e-mail address, or for Azure DevOps e-mail addresses and group names. Without approvers, guardOwners approve. |
examples/ has a complete configuration for each platform, with different kinds of
rules and the ways each platform names users, groups and teams.
Changing which items a rule protects needs a new lock (cds-guard check reports
scope-changed). Changing only approvers or description does not; run
cds-guard codeowners --write instead.
Marker example:
module.exports = function tax (net) {
// @protected-begin tax-calc
const rate = 0.19
return Math.round(net * rate * 100) / 100
// @protected-end
}
🔧 Commands
| Command | What it does |
|---|---|
cds-guard init | Creates .guard/protected.yml with examples. |
cds-guard lock [--rule ID]... | Writes the lock files of all rules, or of the given ones, and lists the items that changed. Refuses items that can't be found. |
cds-guard check [--format F] [--junit FILE] [--codequality FILE] [--base REF] | Compares with the lock files. Exit code 1 when something changed, or when a generated CODEOWNERS block or Azure script no longer matches protected.yml. See Check output. |
cds-guard codeowners [--platform P] [--write [FILE]] [--branch B] [--check] | Prints or writes the approver entries. Only the block between # BEGIN cds-guard and # END cds-guard is replaced, the rest of CODEOWNERS stays. --check only reports whether the written blocks are up to date. |
cds-guard list | Shows every protected item per rule, and which ones can't be found. |
cds-guard skill [--write [DIR]] | Prints or writes the agent skill to DIR/cds-guard/SKILL.md (default .claude/skills). |
All commands take --root DIR. Exit codes: 0 ok, 1 protected items changed, 2 usage or
configuration error.
Check output
| Option | What it adds |
|---|---|
--base REF | For each changed item, a short diff of how it looked at the git ref REF (a branch, tag or commit). A shallow clone fetches the commit from origin first. If git can't find it, check warns and carries on. |
--format github | GitHub Actions annotations: each finding is marked on its file and line in the pull request. |
--format azure | The same for Azure Pipelines (logging commands). |
--format json, --format junit | The whole result as JSON or as a JUnit report on standard output. |
--junit FILE, --codequality FILE | Also write a JUnit report, or a GitLab Code Quality report for the merge request widget, to FILE. |
The GitHub Action and the CI templates in ci/ already pass the target branch as --base
and use the matching format.
✗ rule "tax-formula"
changed marker:tax-calc@srv/tax.js block starting at line 2 changed
- const rate = 0.19
+ const rate = 0.2
return Math.round(net * rate * 100) / 100
🏗️ Set up your platform
Three things make the guard binding. Without them it is only a warning.
- Main only accepts pull requests. Nobody pushes directly.
- The
cds-guardjob is a required check for merging. - The lock files need approval from the rule's approvers, through
cds-guard codeowners.
GitHub
# .github/workflows/cds-guard.yml
name: cds-guard
on: [pull_request, merge_group]
jobs:
cds-guard:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: 22 }
- uses: cbs-consulting/cds-guard@v0
In a branch ruleset (or branch protection) for main: "Require a pull request before merging",
"Require review from Code Owners", and "Require status checks to pass" with cds-guard. Then
npx @cbs-consulting/cds-guard codeowners --write. List the workflow file in guardPaths so
nobody can switch the check off unnoticed.
The action marks each finding on its line in the pull request and shows how changed items looked
on the base branch. Set diff: false to leave the diffs out.
Azure DevOps
Copy ci/azure-pipelines/cds-guard.yml into the repository
and reference it from a pipeline (the comment at the top shows how). In the branch policies of
main: add the pipeline as a required Build validation. Then create the reviewer policies once:
npx cds-guard codeowners --platform azure --write # writes .guard/azure-policies.sh
REPO_ID=$(az repos show --repository my-repo --query id -o tsv) sh .guard/azure-policies.sh
Run both commands again after approvers change. The script creates the new policies and then
removes the ones an earlier run created. check fails while .guard/azure-policies.sh doesn't
match protected.yml.
The pipeline fetches the target branch to show what changed. If your checkout step doesn't keep
its credentials, add persistCredentials: true or fetchDepth: 0 to it; without either, check
still works and only leaves out the diffs.
Bitbucket
Merge ci/bitbucket/bitbucket-pipelines.yml into your
pipeline. In the branch restrictions of main: prevent changes without a pull request, and add the
merge checks for successful builds and code owner approval (enforcing merge checks needs Bitbucket
Cloud Premium, or Data Center). Then npx @cbs-consulting/cds-guard codeowners --platform bitbucket --write,
which writes .bitbucket/CODEOWNERS.
GitLab
Include ci/gitlab/cds-guard.gitlab-ci.yml. Turn on
"Pipelines must succeed", protect main with "Allowed to push and merge: No one" and "Code owner
approval" (Premium), then npx cds-guard codeowners --platform gitlab --write.
Other CI systems
Run npx @cbs-consulting/cds-guard check after npm ci, so the project's own @sap/cds
compiles the model. On an agent without Node.js, run both in a node:22 container:
docker run --rm -v "$PWD:/repo" -w /repo node:22 sh -c "npm ci && npx --yes @cbs-consulting/cds-guard check"
🤖 AI coding agents
The package ships an agent skill that teaches coding agents to work
with the guard: set it up when asked, check whether a file is protected before editing it, run
check afterwards, and lock only changes the user asked for, never to silence a failing check.
npx @cbs-consulting/cds-guard skill --write # .claude/skills/cds-guard/SKILL.md
npx @cbs-consulting/cds-guard skill --write .agents/skills # another agent's skills folder
The repository is also a plugin in the cbs Agentic Marketplace, so you can install the skill once for all your projects:
/plugin marketplace add cbs-consulting/agentic-marketplace # Claude Code
/plugin install cds-guard@cbs-consulting
copilot plugin marketplace add cbs-consulting/agentic-marketplace # GitHub Copilot CLI
copilot plugin install cds-guard@cbs-consulting
codex plugin marketplace add cbs-consulting/agentic-marketplace # Codex, then /plugins
The plugin follows the default branch of this repository. skill --write gives you the copy that
matches your installed version instead.
Claude Code picks it up from .claude/skills/. Other agents that read the
Agent Skills format take the folder they look in. Commit the file so the
whole team gets it. The skill belongs to the installed version: run the command again after an
upgrade, which replaces the file. To use the skill without installing the package, copy
skills/cds-guard/SKILL.md.
❓ How it works and its limits
- Fingerprints, not diffs. Each item is hashed: CDS items as canonical JSON of the compiled
model without
$locationand other$metadata, text as normalised lines.checkcompares the working tree with the lock files, so it needs no base branch and works with shallow clones. - The project's own
@sap/cdscompiles the model, so the hashes match what the app builds. The lock file records the@sap/cdsversion; after an upgrade,checkwarns if the version differs. If the upgrade changes how the model compiles, runcds-guard lockand approve it like any other change. - It is a merge gate, not access control. Anyone can edit protected code locally. What stops the merge is the required check plus the required reviewers on the lock files. People who may bypass branch rules can still merge.
- Approver files stay in sync.
checkcompares the generated CODEOWNERS block (in any place a platform reads it from) and.guard/azure-policies.shwithprotected.yml, and fails when they differ. The block also makes the guard owners the owners of the CODEOWNERS file itself, so removing it needs their approval. - Renames look like deletions. A renamed entity is reported as
missing; update the rule and lock again.
🤝 Contributing
See CONTRIBUTING.md. Security problems go through the Security Policy, not public issues.
📄 License
Apache License 2.0, © 2026 cbs Corporate Business Solutions Unternehmensberatung GmbH.