AWS Builder Center

Beyond CODEOWNERS: Building a Pull Request Gatekeeper with Cedar and Amazon Verified Permissions

How we combined file paths, team membership, PR size and day of the week into a single set of Cedar policies, enforced by a serverless GitHub webhook on AWS. Covers the design choices, what surprised us in the real AWS environment, and what we'd harden next.

GitHub can tell you who owns a path, and it can require reviews from specific teams. As far as we could tell, it can't express rules that combine several facts at once. Examples are "the security team owns  /src/auth/ , unless the PR is over 500 lines," or "no merges on Friday unless it's a hotfix from a senior engineer." Teams usually end up writing a custom CI script for each of these, and every exception becomes a code change.
We built Cedar Merge Gatekeeper, a serverless app that evaluates pull request approvals against Cedar policies stored in Amazon Verified Permissions (AVP).

How a request flows

  1. GitHub sends a webhook to Amazon API Gateway, which invokes AWS Lambda.
  1. Lambda verifies the HMAC-SHA256 signature before any processing.
  1. Lambda fetches the changed files and line count from the GitHub API, handling pagination.
  1. Lambda looks up the reviewer's team memberships in Amazon DynamoDB.
  1. Lambda calls Verified Permissions  IsAuthorized  with all of those facts as request context.
  1. The decision is logged to a second DynamoDB table.
  1. Amazon Bedrock (Nova Lite) writes a plain-English explanation of the result.
  1. Lambda posts a commit status and a PR comment back to GitHub.
  1. A dashboard hosted on AWS Amplify reads the decision log and charts it.
GitHub redelivers webhooks, so each delivery takes a conditional-write lock in DynamoDB keyed on the  X-GitHub-Delivery  header. A redelivery is acknowledged without being processed twice.

Teams as request context

Cedar normally models teams as entities, with  principal in Team::"..." . That needs an entity store kept in sync with GitHub. With a short build window, we passed the facts in the request context instead: the reviewer's teams as a set, the changed path, the line count, the PR author, the day of the week, and a hotfix flag. Policies then read like plain conditions.
The tradeoff is that Verified Permissions trusts whatever Lambda sends, so Lambda has to be the source of truth for those facts.

The policies

Here are the security rule and the Friday rule:
cedar
permit (
principal,
action in [CedarGatekeeper::Action::"approvePR", CedarGatekeeper::Action::"mergePR"],
resource
)
when { context.activeTeams.contains("security-team") && context.changedPath like "/src/auth/*" };

forbid (
principal,
action in [CedarGatekeeper::Action::"approvePR", CedarGatekeeper::Action::"mergePR"],
resource
)
when {
context.dayOfWeek == "Friday" &&
!(context.isHotfix && context.activeTeams.contains("senior-engineers"))
};
The mental shift from  if user.role == ...  is that a single  forbid  beats any  permit , whatever the order. We proved it with a unit test that runs the real policy files through  cedarpy . A security-team member who authored an  /src/auth/  PR matches the permit rule, but the self-approval  forbid  still blocks them.

The LLM explains and never decides

After Cedar decides, Amazon Bedrock writes a short, friendly comment explaining the result. The decision never depends on the model. If Bedrock fails, the handler posts a static fallback message.
If the GitHub API or Verified Permissions is unreachable, the gatekeeper posts a non-passing status with a "check degraded" comment. It never falls back to approving.

What surprised us

  • Real AWS behaved differently from our local emulator. The live response lists determining policies under  policyId , while our local code expected  id . The result was a silent  KeyError  that only showed up in the cloud.
  • AVP returns auto-generated policy IDs. Hashes are useless in a PR comment, so we store each rule's description when uploading policies and look it up with  GetPolicy , cached per Lambda container.
  • Our Python was looser than our Cedar. An early substring check ( "auth/" in file ) would have matched  lib/oauth/helper.py , while Cedar required the prefix  /src/auth/ . The two must match exactly, or one of them fails open.
  • HTTPS mattered for a security demo. An S3 static website only serves HTTP, so we hosted the dashboard on AWS Amplify.

What we would harden next

Building this showed us where the edges are:
  • Post results as check runs from a GitHub App. Commit statuses can be posted by anyone with write access, so a required check should be pinned to our app.
  • Evaluate every reviewer. Today each review event is judged on its own, so the last reviewer's verdict wins.
  • Evaluate every changed file. Verified Permissions has a batch API, so we can check each file and deny if any file is denied. We currently forward a single path.
  • Check at merge time. The merge event fires after the merge, so real gating needs merge-time enforcement such as a merge queue.
  • Use the team's timezone. The day of the week is currently computed in UTC.

Try it

Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article