Skip to content

ci: add Query Shield (DB query checks) - #100

Closed
banking-devops-app[bot] wants to merge 1 commit into
masterfrom
queryshield/onboard
Closed

banking-devops-app[bot] wants to merge 1 commit into
masterfrom
queryshield/onboard

Conversation

@banking-devops-app

Copy link
Copy Markdown

Adds Query Shield, the DBA team's check for database queries: one workflow file, no secrets.

What it does

  • On every PR (drafts too): the SQL the PR adds or changes is EXPLAINed live on the production read replica and scored 1–10. You get a commit status query-shield (red only on BLOCKED), a PR comment with the report, and a Slack alert to the owning team on BLOCKED/WARNING. A PR that touches no query-bearing file costs nothing.
  • On merge: the queries that landed are recorded.
  • Baseline: the repo's full baseline is running now, alongside this PR, on the DBA team's runners (about 30–60 min) — onboarding run. It is stored as the score PR checks compare against; if it finds a Tier 1 (critical) query, DDL/DML tickets for this repo's cluster are held in Gandalf until it is fixed and re-baselined. If it does not get stored, merging this PR runs it again.

On a PR later

  • Skip one PR: a DBA superAdmin asks the Datastores Agent (skip query shield for <repo> PR <n>, with a reason).
  • Fixed it on the DB side (e.g. added an index)? Re-run the job — the EXPLAIN is live, no new commit needed.
  • The check is advisory until you make query-shield a required status.

Requested by kartik.verma@razorpay.com via the Datastores Agent · onboarding run. Questions: #dba-internal.

issues: write
pull-requests: write
uses: razorpay/query-shield/.github/workflows/query-shield.yml@master
secrets: inherit # the runner App's ID and key (org secrets)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High severity issue identified in your code:

The reusable Query Shield workflow inherits all repository and organization secrets, including the runner App ID and key. A compromised or malicious change to the external workflow could exfiltrate those credentials and use them outside the intended job.

More details about this

query-shield calls razorpay/query-shield/.github/workflows/query-shield.yml@master and passes it every secret available to this repository through secrets: inherit, including the organization-level runner App ID and key mentioned in the comment—not only secrets required by Query Shield.

A plausible attack is:

  1. An attacker compromises the razorpay/query-shield repository, or a change merged into its master branch introduces a malicious step.
  2. This workflow runs for a pull request or a push to master/main.
  3. The called query-shield workflow can read inherited values such as the runner App ID and key, then send them to an attacker-controlled endpoint (for example, with curl from a workflow step).
  4. The attacker uses those credentials to impersonate the runner App or access other organization resources, even though this job only declares contents: read, statuses: write, issues: write, and pull-requests: write permissions. Because the workflow is pinned to the mutable master branch, a compromised upstream workflow can receive these secrets on its next run.

To resolve this comment:

✨ Commit fix suggestion

Suggested change
secrets: inherit # the runner App's ID and key (org secrets)
secrets:
RUNNER_APP_ID: ${{ secrets.RUNNER_APP_ID }}
RUNNER_APP_PRIVATE_KEY: ${{ secrets.RUNNER_APP_PRIVATE_KEY }}
View step-by-step instructions
  1. Remove secrets: inherit from .github/workflows/query-shield.yml; do not pass every repository secret to the reusable workflow.
  2. Check razorpay/query-shield/.github/workflows/query-shield.yml@master for the declared secret names and identify the runner App ID and private key it requires.
  3. Pass only those two secrets explicitly, using the names declared by the reusable workflow. For example:
    secrets:
      RUNNER_APP_ID: ${{ secrets.RUNNER_APP_ID }}
      RUNNER_APP_PRIVATE_KEY: ${{ secrets.RUNNER_APP_PRIVATE_KEY }}
    Replace RUNNER_APP_ID and RUNNER_APP_PRIVATE_KEY with the exact secret names used by the reusable workflow and configured as organization or repository secrets.
  4. Update the reusable workflow's on.workflow_call.secrets declaration if those secrets are not already defined there. A called workflow can only receive explicitly declared secrets, so the names in the caller and reusable workflow must match.
💬 Ignore this finding

Leave a nosemgrep comment directly above or at the end of line 18 like so // nosemgrep: yaml.github-actions.security.secrets-inherit.secrets-inherit

Take care to validate that this is not a true positive finding before ignoring it.
Learn more about ignoring code, files and folders here.

You can view more details about this finding in the Semgrep AppSec Platform.

@sanjiv-kannaa-j

Copy link
Copy Markdown

Closing: this Query Shield onboarding PR was opened while testing the flow. The repo will be onboarded again through the Datastores Agent when it is ready (onboard queryshield for ).

@sanjiv-kannaa-j
sanjiv-kannaa-j deleted the queryshield/onboard branch November 4, 2026 04:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant