Repository navigation
feat(azure-devops): connect through the customer's own Entra app - #494
Evgeniy-DB wants to merge 5 commits into
Conversation
artempartos
left a comment
There was a problem hiding this comment.
Reviewed the whole diff. The design matches what we agreed: Flow as the issuer, a per-company subject from an immutable public_id, a PEM signing key, Contributors plus a reduced set, and a permission check that evaluates effective permissions by action name instead of inferring them from group membership. The description is unusually candid about what was not verified, which made this much easier to review. Thanks.
Blocking
- CI has never run on this PR. Only
clahas reported. The branch is 89 commits behinddevelop, and the conflicts are trivial (CHANGELOG.md,db/schema.rb,docs/index.md). Please rebase so the suite runs. - Shared-app onboarding can overwrite a federated installation. See the inline comment on
azure_devops_installation.rb; the line itself isonboarding.rb:190. - No live run yet. We are configuring staging for one. Before merge, it should cover Contributors, the reduced set, and revocation (delete the credential and watch the failure).
Should fix
4. A signing key with literal \n escapes silently turns the feature off. See federation_config.rb.
5. FederatedOnboarding#complete! keeps a DB transaction open across every Azure call. See inline.
To check in the live run
6. The reduced set adds the service principal with no project entitlement and only direct ACEs. See setup_script.rb.
7. PermissionCheck fails open on required Repos checks. See inline.
Operator note: when enabling this on a deployment, set AZURE_DEVOPS_FEDERATION_ISSUER_URL explicitly instead of relying on the DOMAIN default. Once customers have pinned the issuer, the default would silently follow any later change of DOMAIN. Worth a line in the runbook.
| def azure_identity_is_immutable | ||
| %w[company_id tenant_id client_id organization_slug].each do |attr| | ||
| immutable = %w[company_id tenant_id organization_slug credential_kind] | ||
| immutable << "client_id" unless federated? |
There was a problem hiding this comment.
Bug (blocking), through this exception. It is triggered from Onboarding#build_installation (onboarding.rb:190, which this PR does not change, so I can't comment there).
If this company's installation for the organization is already federated, that line reassigns client_id to the shared app and sets app_config_key, while credential_kind stays federated.
This exception allows a client_id change on a federated row, so save! succeeds. Every later token request then runs the federated exchange with Aixle's multi-tenant app as the client, and that app has no federated credential for our issuer. The result:
- every connection the company has on that organization breaks;
entitle!also adds the shared app's service principal to the organization.
Repro: connect an organization through Your own Entra app. Then, from another project, choose Aixle's Microsoft app, sign in as an administrator and add a project that is not approved yet. That goes complete! → build_installation.
FederatedOnboarding#bind already refuses the opposite direction. This needs the mirror check before OwnershipProof runs, for example raise ValidationFailed, ... if existing_installation(tenant)&.federated?, plus a test like the one for the opposite case.
| def parse_signing_key(pem) | ||
| key = OpenSSL::PKey::RSA.new(pem) | ||
| key.private? && key.n.num_bits >= MIN_KEY_BITS ? key : nil | ||
| rescue OpenSSL::PKey::RSAError |
There was a problem hiding this comment.
A key that is set but does not parse looks exactly like no key at all:
enabled?returns false;- both
.well-knownendpoints return 404; - the option disappears from the dialog;
- nothing is logged.
The likeliest way to get there is pasting the PEM with literal \n escapes, which is common for single-line env values and secret stores. .to_json in settings.yml keeps the backslashes, and OpenSSL::PKey::RSA.new then fails.
Suggest both:
- normalize a literal
\nto a newline before parsing; - log a warning once when
signing_keyis present but unusable (not RSA, under 2048 bits, or unparseable), so an operator can see why the feature is off.
|
|
||
| tenant = TenantDiscovery.call(organization) | ||
|
|
||
| AzureDevopsInstallation.transaction do |
There was a problem hiding this comment.
This transaction stays open across the token exchange, the project listing and the whole PermissionCheck. That is about nine GETs per chosen project plus the namespace lookups, each with a 30 s read timeout. When Azure is slow, the DB connection and the lock on the installation row are held for all of it.
inspect! already shows the read-only part can run on a static client. Suggest this order instead:
- Exchange the token.
- List the visible projects and run the permission check.
- Open a short transaction only for bind, assign and
save!.
The guarantee stays the same, since nothing is written until every check has passed.
| CUSTOM_BODY = <<~"BASH" | ||
| #{COMMON} | ||
| # Basic access only; everything else is granted below, project by project, and nothing more. | ||
| add_to_organization '[]' |
There was a problem hiding this comment.
For the live run: with projectEntitlements: [], the service principal is not a member of any project, and everything else is direct ACEs, including GENERIC_READ on the project.
Whether an identity that is not a project member can list the project, clone and open pull requests with ACEs alone is exactly the unverified part. Please run the reduced set as its own case, separate from Contributors.
|
|
||
| answer = @client.get("_apis", "permissions", check.namespace, bit, params: { tokens: token }) | ||
| value = Array(answer["value"]) | ||
| return :unknown unless value.size == 1 && [ true, false ].include?(value.first) |
There was a problem hiding this comment.
Failing open is a reasonable call while the response shapes are unverified, and the dialog does show "could not be checked".
Once the live run confirms the _apis/permissions and _apis/securitynamespaces shapes, consider treating unknown on a required Repos check as blocking, or at least as a warning. Today a connection that will fail on its first push can go through looking almost clean.
Add a third way to connect Azure DevOps, next to Sign in with Microsoft and the administrator PAT. The customer registers a single-tenant app in their own Entra directory and adds a federated credential that trusts this deployment as an OIDC issuer. Flow signs a short-lived JWT, Entra exchanges it for a token of the customer's app, and the existing service-principal path takes over. No secret, certificate or PAT is stored, and no administrator credential reaches Aixle. - publish /.well-known/openid-configuration and jwks.json, enabled when AZURE_DEVOPS_FEDERATION_SIGNING_KEY is set - subject is aixle:company:<companies.public_id>, a new immutable uuid - installations gain credential_kind; a federated one may move to a recreated app only together with re-verification - FederatedOnboarding binds in one transaction; the token exchange is the proof of ownership - PermissionCheck asks Azure what the identity can do; a missing Repos permission blocks, anything it cannot determine does not - generated setup script for the Project Collection Administrator - "Your own Entra app" option in the connect dialog Not run against a live Azure DevOps or Entra: every request is covered by WebMock stubs written from Microsoft's documentation. The known compromises are recorded in docs/design/azure-devops-integration.md, section 15.4. Signed-off-by: Evgeniy Yagnenkov <[email protected]>
…ions Binding the shared app onto a federated row passed validation, because a federated row may change its client id, and left it federated with the shared app's client id. Every later token exchange then failed for every connection on that organization. Signed-off-by: Evgeniy Yagnenkov <[email protected]> Co-authored-by: Cursor <[email protected]>
…log why it is ignored A key that is set but unusable looked the same as no key: the option disappeared with nothing in the log. Signed-off-by: Evgeniy Yagnenkov <[email protected]> Co-authored-by: Cursor <[email protected]>
…g transaction The transaction used to stay open across the token exchange and every permission request, holding a connection and the installation row for as long as Azure took to answer. Signed-off-by: Evgeniy Yagnenkov <[email protected]> Co-authored-by: Cursor <[email protected]>
…bling it Signed-off-by: Evgeniy Yagnenkov <[email protected]> Co-authored-by: Cursor <[email protected]>
274db27 to
901bea1
Compare
) The previous staging merge resolved develop against the stale copies of branches already squashed into develop, and lost Azure Entra's schema column and its unsaved-changes wiring in the process. This commit's tree is develop with the Azure Entra branch and feat/billing-page-redesign merged on top, conflicts resolved by hand, nothing else. Signed-off-by: Alex Astafyev <[email protected]>
Conflicts were between staging's feature-branch merges of #677, #684 and an earlier head of #689 and develop's squash-merges of #677/#684 (plus #700, #704). Each hunk takes develop's side (the final, reviewed version), except config/settings.yml, which keeps the runners.release block of #689, and CHANGELOG.md, which keeps both sides' entries. Staging-only content (#494) merged without conflict and is kept.
Summary
Adds a third way to connect Azure DevOps, next to "Sign in with Microsoft" and the administrator PAT.
The customer registers a single-tenant app in their own Entra directory and adds a federated credential ("Other issuer") that trusts this deployment as an OIDC issuer. Flow signs
a short-lived JWT, Entra exchanges it for an access token of the customer's app, and from there on the existing service-principal path is used unchanged.
This does not remove the Azure DevOps administrator. Azure DevOps lets only a Project Collection Administrator add any identity to an organization. The PCA does that once, with a
generated script. What is removed is the third-party-app consent and handing a vendor an admin token.
How it works
Ownership proof comes from the exchange itself. It succeeds only if someone who controls an app in that organization's directory trusted exactly this company's subject. Company B
cannot reuse company A's app: B's assertion carries B's subject.
What changed
Issuer
OidcIssuerController: anonymousGET /.well-known/openid-configurationand/.well-known/jwks.json, 404 unless configured,Cache-Control: public, max-age=300. Only publickeys.
AzureDevops::FederationConfig: issuer URL (defaultprotocol://domain), signing key, audience, previous public keys for rotation.kidis the RFC 7638 thumbprint (checkedagainst the RFC's worked example). The feature is on exactly when a ≥2048-bit RSA private key is configured and the issuer is a public HTTPS origin with no path. No separate
enable flag, same rule as the rest of the integration.
Entra::FederatedAssertion: the JWT. Nox5t,audis the token-exchange audience (not the token URL like the certificate assertion).Data model (
20261015140000_add_federation_to_azure_devops)companies.public_id uuid(defaultgen_random_uuid(), unique,attr_readonly). Backfills existing rows.azure_devops_installations.credential_kind(shared_appdefault /federated).app_config_keyis now nullable (a federated installation uses no operator app config).client_idandservice_principal_object_idtogether (the customer recreated the app). Everything else stays immutable.Token path
FederatedTokenExchange: sends the assertion, maps Entra errors, newFederationRejectederror ("fix it on the customer's side", as opposed toCredentialActionRequired, whichis the operator's).
AppTokenServicebranches onfederated?. Cache generation isfederated:<client_id>, so a recreated app is never served the old app's token.CredentialProvider,Clientand every agent tool are unchanged.Connect flow
FederatedOnboarding#inspect!(writes nothing) and#complete!(one transaction: bind/rebind, exchange, require chosen projects visible, require Repos permissions, record the SPoid, activate). A failure at any step leaves nothing behind.azure_devops_federated_inspect|connect|script), policy entries, routes, regeneratedroutes.ts.PermissionCheck: asks Azure what the identity can actually do (permission evaluation), not which group it is in.SetupScript: shell script for the PCA, two permission sets.IntegrationService#testre-runs the permission check for a federated connection and reports removed permissions as a warning.UI
AzureDevopsConnectModalgets a mode switch ("Aixle's Microsoft app" / "Your own Entra app"), shown only when the deployment can be an issuer. NewAzureDevopsFederatedForm:copyable issuer/subject/audience, script generator, "Verify access", project picker, permission report.
CapabilityPicker,azureDevopsShared.tsextracted from the modal (no behaviour change for the existing modes).Shared code touched
AppConfig.enabled?now also true when federation is configured (a deployment may have federation and no shared app).azure_devops_props:client_idisnilwhen there is no shared app; newsharedAppEnabledandfederationprops.Onboardingreads theoidclaim through the newTokenClaims(behaviour-preserving extraction).Docs / config: user guide (both copies), design doc §15, operator runbook,
.env.example, configuration reference (+ synced portal copy), CHANGELOG.Decisions and the alternatives considered
aixle:company:<uuid>)companies.public_idcompanies.id(bigint),slug,nameidis guessable and sequential; slug and name are editable. Nothing a useroidc.<domain>); static hostaws-sdk-kmsand IAM, and open-source deployments need a PEM fallback anyway. Left as ajwks.jsonfor deployments behind a VPNissuer_urlis still a setting, so adding it later needs no reworkFederationRejectedCredentialActionRequiredclient_idchange for federated, only with successful re-verification, in a transactionclient_idimmutable (needs a newrestrictFK blocks it while integrations exist)_apis/securitynamespacesat runtimeunknown, never blocks (fail-open)az restonlyaz devopsas the task text saysaz resthits the same REST endpoints the code already uses (and that production has exercised:serviceprincipalentitlements,accesscontrolentries).az devopsalso needs an extension and cannot add a service principal to a group without a Graph descriptorTest connectionchecks all selectedKnown compromises
Also recorded in
docs/design/azure-devops-integration.md§15.4._apis/permissionsand_apis/securitynamespacesresponse shapes, the namespace ids andaction names (
GenericRead,GenericContribute,CreateBranch,PullRequestContribute,WORK_ITEM_READ/WRITE,ViewBuilds,ViewSubscriptions/EditSubscriptions), the area-pathroot lookup,
serviceprincipalentitlementsfor an app with no project entitlement, and the generated script end to end. This is exactly the failure mode design §13 warns about:contract tests that match payloads we wrote.
AADSTS700213(subject),AADSTS700016(app not found) andAADSTS7000112(app disabled) carry a specific hint. Any otherinvalid_clientshows Entra's code and a checklist. Codes come from documentation, not observation.
unknownnever blocks and only a missing Repos permission does. A wrong action name or a changed response shape degrades to "could not bechecked", at the price of letting a broken connection through.
az restinstead ofaz devops; "custom group" is direct grants to the identity (no group). The project-visibility ACE and theidentity descriptor shape are assumptions (the descriptor is the fallback
ServiceHookGrantalready uses). Verified: valid bash for both flavors (bash -n), no injection throughany interpolated value.
and Flow cannot recall it. The connection turns red on the next rejected call or test. The acceptance criterion "deleting the credential stops access" is met with this qualification.
AZURE_DEVOPS_FEDERATION_ISSUER_URLexists to pin it.
shared app's certificate. Rotation is via
AZURE_DEVOPS_FEDERATION_PREVIOUS_PUBLIC_KEYS; how long Entra caches the key set is not measured (the runbook says "allow a day").only for the projects chosen.
Test connectionshows removed permissions asa warning, not an error.
Security notes
attr_readonly.jti; tenant and client ids are validated as GUIDs before any request.half-working option).
complete!is transactional: a failed exchange, a missing project or a missing permission leaves no installation behind.Operator notes
companies.public_idwith a volatile default (rewritescompanies; small table) and a unique index; additive and reversible.AZURE_DEVOPS_FEDERATION_SIGNING_KEY(RSA PEM). Verify from outside:AZURE_DEVOPS_FEDERATION_SIGNING_KEY,_ISSUER_URL,_PREVIOUS_PUBLIC_KEYS,_AUDIENCE(documented in the configuration reference).What was verified
this change.
error mapping,
AppTokenServicefederated branch and cache keying,FederatedOnboarding(incl. rollback, rebinding, cross-company isolation),PermissionCheck(granted / missing /unknown cases),
SetupScript(shell syntax, injection refusal), controller endpoints, authorization matrix,IntegrationService#test.eslint,tsc,steiger(FSD),rubocop,brakemanare clean.What was not verified
Everything listed in compromise 1, plus a real end-to-end push, pull request and work-item edit with the granted permissions. Recommended before relying on this in production: one
run on a real tenant covering Contributors, the reduced set, and revoking (delete the credential, observe the failure).
Review pointers
db/schema.rbwas edited by hand to the three intended changes (a dev-database dump reordered unrelated columns).app/frontend/shared/routes.tswas regenerated and trimmed of dev-onlyletter_openerroutes.FederatedOnboarding,AppTokenServiceandPermissionCheck; the rest is mostly plumbing.Follow-ups
Checklist
Integrations)rubocop,brakeman,eslint,tsc,steiger, Rails suite, Vitest