Skip to content

ci: run Azure SQL tests against per-run servers, including fork PRs - #1844

Open
arthurschreiber wants to merge 11 commits into
masterfrom
claude/beautiful-johnson-se1sc6
Open

arthurschreiber wants to merge 11 commits into
masterfrom
claude/beautiful-johnson-se1sc6

Conversation

@arthurschreiber

@arthurschreiber arthurschreiber commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Replaces the four Azure jobs in nodejs.yml, which share one long-lived Azure SQL server and are skipped for fork PRs. Each test job now gets its own Azure SQL server, which is deleted when the run finishes. Fork PRs can run these tests too, and their code never runs where Azure credentials are available.

This is the untrusted half. The trusted half, the provisioning and cleanup workflows, landed in #1845, and this branch has master merged in. Setup and the security model are documented in .github/AZURE_SQL_CI.md.

How it works

Workflow Trigger Azure access Runs PR code
azure-sql.yml (this PR) push, pull_request None Yes
azure-sql-provision.yml (#1845) workflow_run (start and end of each test run) Yes, via OIDC Never
azure-sql-cleanup.yml (#1845) Hourly Yes, via OIDC Never
  1. Each test job (request-server.sh) creates a one-time RSA key pair and uploads a request artifact with its runner IP and public key.
  2. When the test run starts, the provisioning workflow validates each request and creates a server reachable only from that IP. It uploads the credentials encrypted to the job's key.
  3. The test job (wait-for-server.sh) accepts the credentials only if they were uploaded by the provisioning workflow from the default branch, so an artifact planted by another run is ignored. It decrypts them and runs the integration tests.
  4. When the test run completes, the provisioning workflow deletes that run attempt's servers and client secrets. The hourly cleanup deletes anything older than 2h.

What PR code can get: its own server's admin password, and for the SP configs, a client secret that is valid for at most 2h on CI servers only. What it never gets: Azure credentials, write tokens, or the Entra test user's password (a repository secret, which GitHub doesn't pass to fork or Dependabot runs).

Changes in this PR

  • .github/workflows/azure-sql.yml, plus .github/scripts/azure-sql/request-server.sh and wait-for-server.sh.
  • The four old Azure jobs removed from nodejs.yml.
  • test/config.token-credential.ts uses ClientSecretCredential instead of UsernamePasswordCredential, so it can run with the short-lived secret. Tedious's token-credential path is tested the same way.
  • actions.lock entry for azure-sql.yml.

Testing

  • Full handshake, run locally against a mock GitHub API and a fake az: request → validation → provisioning → encryption → provenance check → decryption → teardown, including a forged credentials artifact being ignored.
  • Linting: shellcheck, zizmor and npm run lint are clean.
  • Real runs: this PR's Azure SQL (…) jobs are the first end-to-end test against real GitHub and Azure.
  • Open question: runner capacity. Each test job holds a runner while it waits for the provisioning jobs, which only queue after the test run starts. When the Windows matrix fills the queue, the test jobs can time out before provisioning gets a runner. Possible mitigations:
    • one test job running the four configs as separate steps;
    • one provisioning job instead of four;
    • a longer wait.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UtKcuYJkSGXdBxqC7KTtqm

claude and others added 7 commits November 18, 2026 10:56
Replace the four Azure jobs in nodejs.yml, which shared one long-lived
server and were skipped for forks, with azure-sql.yml:

- Each job logs in via GitHub OIDC, creates its own Azure SQL server
  (random admin password, Entra group admin, firewall limited to the
  runner IP) and deletes it in an `always()` teardown step.
- azure-sql-cleanup.yml runs hourly and deletes tagged servers and test
  app client secrets older than two hours.
- Pull requests run via pull_request_target. The PR code is exported
  without .git and run in a locked-down container that only receives
  the throwaway server's credentials. Fork and bot PRs use an
  environment that requires approval, never get the Entra test user's
  password, and skip the Codecov upload.
- The token-credential tests use a ClientSecretCredential, so they can
  run with a short-lived client secret.

Setup and the security model are documented in .github/AZURE_SQL_CI.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UtKcuYJkSGXdBxqC7KTtqm
They were left out of the previous commit because .gitignore ignores
new files under .github.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UtKcuYJkSGXdBxqC7KTtqm
Register Microsoft.Sql up front, grant the Graph permission via an app
role assignment, add the ROPC test user's requirements, note what the
provisioner must not own, and add a manual dry run for before the
workflows are merged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UtKcuYJkSGXdBxqC7KTtqm
Rework the Azure SQL CI so that pull request code never runs where
Azure credentials are available, instead of running fork code under
pull_request_target in a container:

- azure-sql.yml runs on pull_request and push with no Azure access.
  Each job uploads a request artifact (runner IP and a one-time RSA
  public key), waits for its credentials and runs the tests.
- azure-sql-provision.yml runs on workflow_run from the default branch
  and never checks out pull request code. When a test run starts, it
  validates each request, creates a server reachable only from the
  requesting runner, and uploads the credentials encrypted to the
  job's key. When the run completes, it deletes that run's servers
  and client secrets.
- The test job only accepts credentials uploaded by the provisioning
  workflow, so an artifact planted by another run is ignored.

This avoids pull_request_target, which GitHub blocks by default in
public repositories from December 2, 2026, and the
allow-unsafe-pr-checkout opt-out that actions/checkout now requires
for fork code.

The scripts live in .github/scripts/azure-sql/. The setup guide is
updated: one environment, ROPC secrets as repository secrets, and
fork run approval through the repository's Actions settings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UtKcuYJkSGXdBxqC7KTtqm
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UtKcuYJkSGXdBxqC7KTtqm

Copy link
Copy Markdown
Collaborator Author

The Azure SQL (…) jobs on this PR fail with "Timed out waiting for the Azure SQL server". That's expected for now: they wait for credentials from azure-sql-provision.yml, which runs on workflow_run and only triggers once that workflow file exists on the default branch. Until then, nothing provisions servers for these runs.

The steps before the wait passed on a real runner: request key generation, the runner IP lookup, and the request artifact upload. All other checks are green so far.

To test end to end before this merges, the provisioning workflow, the cleanup workflow and .github/scripts/azure-sql/ can be landed on master first in a separate PR. This PR's Azure SQL jobs would then provision real servers.


Generated by Claude Code

…hnson-se1sc6

# Conflicts:
#	.github/workflows/actions.lock
The provisioning jobs can still be queued for a runner when the test
jobs start waiting, so allow for more than server creation itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UtKcuYJkSGXdBxqC7KTtqm

Copy link
Copy Markdown
Collaborator Author

The Azure SQL (azure-default) failure on c37d480 is a real provisioning run, and it failed for a reason outside this PR's code. Azure rejected the server in the default region (provisioning job):

(RegionDoesNotAllowProvisioning) Location 'East US 2' is not accepting creation of new Windows Azure SQL Database servers at this time.

The fix is configuration: set the AZURE_SQL_LOCATION repository variable to a region that accepts new servers for this subscription. The other configs on this run will fail the same way until then.

The rest of the path worked on real GitHub and Azure:

  • the OIDC login;
  • reading the test run's artifacts while it was still in progress;
  • the provenance check;
  • the error artifact, which failed the test job within seconds instead of after the 40-minute wait.

Generated by Claude Code

@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.97%. Comparing base (61fb184) to head (eac4ef7).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1844      +/-   ##
==========================================
- Coverage   85.24%   84.97%   -0.28%     
==========================================
  Files          97       97              
  Lines        4778     4778              
  Branches      896      896              
==========================================
- Hits         4073     4060      -13     
- Misses        447      460      +13     
  Partials      258      258              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Collaborator Author

codecov/project (-0.91%) follows from the region failure above. This PR removes the old Azure jobs from nodejs.yml, and they're the only ones that cover the Azure-only code paths, mainly the Entra ID authentication. The new Azure SQL (…) jobs failed before running any tests, so they uploaded no coverage. Once a provisioning region is set and those jobs run, coverage should be back at master's level.


Generated by Claude Code

Copy link
Copy Markdown
Collaborator Author

On eac4ef7, Azure SQL (token-credential) and Azure SQL (azure-ad-sp-secret) fail at provisioning, not in this PR's code (provisioning run):

TooManyAppPasswords: Not allowed to add 3 passwords. You can only add a maximum of 2 passwords.

The provisioner on master still adds a short-lived secret to the shared test app, which is already at Entra's two-password limit. #1849 fixes this by giving each service principal job its own app registration. These two configs will pass once that's merged and master is merged in here.

On the same run, azure-default and azure-ad-password provisioned their servers in westus3 and received their credentials.


Generated by Claude Code

arthurschreiber pushed a commit that referenced this pull request Nov 24, 2026
On #1844's first end-to-end run, teardown hung in the first
`az sql server delete` for its whole 30-minute timeout, so the run's
second server was never deleted at all.

teardown.sh now starts every deletion with --no-wait, then polls the
resource group until the attempt's servers are gone, for up to 15
minutes. A slow deletion can no longer stop the others, and Azure
carries out an accepted deletion even if the job ends first. The hourly
cleanup also deletes with --no-wait and retries anything still there on
its next run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UtKcuYJkSGXdBxqC7KTtqm

This branch has not been deployed

No deployments
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.

2 participants