Skip to content

ci: give each Azure SQL service principal job its own app registration - #1849

Open
arthurschreiber wants to merge 4 commits into
masterfrom
claude/azure-sql-per-job-apps
Open

arthurschreiber wants to merge 4 commits into
masterfrom
claude/azure-sql-per-job-apps

Conversation

@arthurschreiber

@arthurschreiber arthurschreiber commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes the next failure on #1844's first end-to-end run (provisioning job):

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

The service principal configs added a short-lived client secret to the shared test app, but Entra allows it at most two passwords and it already has two long-lived ones. Even without them, two such configs per run means a cap on one app limits how many runs can overlap.

It also fixes teardown hanging. On #1844's run for eac4ef7, the first az sql server delete blocked for the teardown job's whole 30-minute timeout (teardown job), so the second server was never deleted.

Changes

  • Per-job app registration for azure-ad-sp-secret and token-credential. provision.sh creates an app registration named after the job's server (tedious-ci-<run>-<attempt>-<config>), plus its service principal and a client secret that expires after 2h.
    • That app is the server's Entra admin, so a leaked secret only reaches its own server. Previously, a leaked secret gave admin on every concurrent CI server.
    • Propagation: server creation is retried (up to 4 attempts, 20s apart) in case the new app isn't visible yet. Before publishing the credentials, the script waits until the secret can get an Azure SQL token (wait_for_app_token, up to 5 min).
    • No new permissions: the provisioner's existing Application.ReadWrite.OwnedBy covers creating these apps and managing them, and only them.
  • Teardown (teardown.sh):
    • deletes the attempt's apps and purges them from deleted items (delete_ci_app; the purge is best effort);
    • starts every server deletion with --no-wait, then polls until the attempt's servers are gone, for up to 15 minutes. A slow deletion no longer blocks the others, and Azure carries out an accepted deletion even if the job ends first;
    • still removes tedious-ci-* secrets on the shared test app, which runs from the previous version created.
  • The hourly cleanup:
    • deletes per-job apps (tedious-ci-<run>-<attempt>-…) more than 2h old and purges deleted ones (best effort, with a warning);
    • never touches the shared test app, even if it has a similar name;
    • deletes servers with --no-wait, and retries any still there on its next run.
  • Unchanged: the other configs keep tedious-ci-sql-admins as Entra admin, and the Entra password tests keep the shared app as their public client. The test side (ci: run Azure SQL tests against per-run servers, including fork PRs #1844) needs no change, because the provisioner already sends the client ID.
  • .github/AZURE_SQL_CI.md: updated. The shared app no longer needs to be in the admin group, needs no secrets, and the provisioner no longer needs to own it.

After merging, tedious_app can be removed from tedious-ci-sql-admins. Its long-lived secrets can be deleted once the old Azure jobs are gone (#1844).

Testing

Mock GitHub API, mock Entra token endpoint and fake az:

  • azure-ad-sp-secret:
    • the app, service principal and secret are created;
    • the server's Entra admin is Application with the new app's ID;
    • the test job gets the new client ID, plus the secret and the server's admin password, both encrypted;
    • the token wait succeeded after 2 failed attempts;
    • the shared test app was never touched.
  • azure-default and azure-ad-password: no app is created, and the group stays the admin. The password tests keep the shared client ID.
  • token-credential with server creation failing once: the retry succeeds.
  • A token that never works: fails with an error and found=true, so the test job fails fast.
  • Teardown:
    • deletes and purges only the attempt's apps;
    • issues every server deletion with --no-wait and waits until they're gone;
    • with one deletion that never finishes, the other server is still deleted, and the job warns and fails after the deadline.
  • Cleanup filters: sample data including tedious-ci-test, tedious-ci-provisioner and a renamed shared app; none of them is selected.
  • Regression: the 11 cases from ci: start Azure SQL provisioning when the test run is created #1846 still pass. shellcheck and zizmor (pedantic) are clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UtKcuYJkSGXdBxqC7KTtqm

The service principal configs added a short-lived client secret to the
shared test app, but Entra allows that app at most two passwords and it
already has two, so provisioning failed with TooManyAppPasswords. With
two such configs per run, a cap on one app would also limit how many
runs can overlap.

For `azure-ad-sp-secret` and `token-credential`, provision.sh now
creates an app registration named after the job's server, with its
service principal and a client secret that expires after two hours. It
makes that app the server's Entra admin, retries server creation while
the new app propagates, and waits until the secret can get an Azure SQL
token before publishing it. A leaked secret now only reaches its own
server.

The teardown deletes the attempt's apps and purges them from deleted
items, and the hourly cleanup removes any older than two hours. Client
secrets on the shared test app are still removed for runs from the
previous version. The other configs keep the admin group, and the Entra
password tests keep the shared app as their public client.

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

claude Bot commented Nov 19, 2026

Copy link
Copy Markdown

Claude review of 7e916ca

.github/workflows/azure-sql-cleanup.yml:95-97: the hourly cleanup can delete the shared test app. The filter deletes every owned app whose name starts with tedious-ci- and that is more than 2h old. AZURE_SQL_CI.md names the shared public client app tedious-ci-test (and the provisioner tedious-ci-provisioner). Existing setups made the provisioner an owner of the test app, which the old docs required and which teardown.sh still needs to remove legacy secrets. In those setups, the first cleanup run after merge deletes tedious-ci-test and purges it from deleted items, so it can't be restored. That breaks the azure-ad-password tests for good. Fix: match only the per-job name format, e.g. test("^tedious-ci-[0-9]+-[0-9]+-"), and/or skip appId == $TEST_APP_CLIENT_ID. The deleted-items purge loop below it needs the same filter.

The hourly cleanup deleted and purged every app it owned whose name
started with `tedious-ci-`. That includes the shared public client app
if it is named `tedious-ci-test` (as the setup guide suggests) and the
provisioner owns it (as earlier setups required), which would break the
Entra password tests for good.

Only match the per-job name format (`tedious-ci-<run>-<attempt>-...`)
and never the app with the shared test app's client ID, in both the
cleanup and the purge of deleted items. The teardown gets the same
client ID guard.

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

Copy link
Copy Markdown
Collaborator Author

Re the review of 7e916ca: confirmed, and fixed in 1ff34e8.

  • Cleanup: both the delete loop and the deleted-items purge now only match the per-job name format (^tedious-ci-[0-9]+-[0-9]+-). They also skip the app whose client ID is AZURE_TEST_APP_CLIENT_ID, so tedious-ci-test and tedious-ci-provisioner are never selected, even if the provisioner owns them.
  • Teardown: it already matched only its own tedious-ci-<run>-<attempt>- prefix, and now has the same client ID guard.

I checked the filters against sample data with those names and a renamed shared app. The teardown mock test still passes.


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 85.24%. Comparing base (61fb184) to head (57d3166).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1849   +/-   ##
=======================================
  Coverage   85.24%   85.24%           
=======================================
  Files          97       97           
  Lines        4778     4778           
  Branches      896      896           
=======================================
  Hits         4073     4073           
  Misses        447      447           
  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.

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