Skip to content

mgmt, sql , fix live test failures#49163

Draft
v-huizhu2 wants to merge 6 commits into
Azure:mainfrom
v-huizhu2:java_mgmt_sql
Draft

mgmt, sql , fix live test failures#49163
v-huizhu2 wants to merge 6 commits into
Azure:mainfrom
v-huizhu2:java_mgmt_sql

Conversation

@v-huizhu2
Copy link
Copy Markdown
Member

Introduces a method to enable Microsoft Entra-only authentication when creating SQL Servers, addressing scenarios where policies require disabling SQL authentication. Updates tests and utilities to use Entra admin exclusively, improving compliance with platform security requirements.

Description

#49070

If an SDK is being regenerated based on a new swagger spec, a link to the pull request containing these swagger spec changes has been included above.

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

Introduces a method to enable Microsoft Entra-only authentication when creating SQL Servers, addressing scenarios where policies require disabling SQL authentication. Updates tests and utilities to use Entra admin exclusively, improving compliance with platform security requirements.
@github-actions github-actions Bot added the Mgmt This issue is related to a management-plane library. label May 13, 2026
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think name this similar to CLI
https://learn.microsoft.com/en-us/cli/azure/sql/server?view=azure-cli-latest#az-sql-server-create

Create a server without SQL Admin, with AD admin and AD Only enabled.

So, here, we can do withAzureActiveDirectoryOnlyAuthentication() at this (impl would set withAzureADOnlyAuthentication(true)`.

And another optional stage and method, e.g. withExternalActiveDirectoryAdministrator(String userLogin, String sid) (similar to WithActiveDirectoryAdministrator).

And test code would be

.withAzureActiveDirectoryOnlyAuthentication()
.withExternalActiveDirectoryAdministrator(.., ..)
.

PS: there is --external-admin-principal-type in CLI. Do we need it?

@XiaofeiCao for opinion

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agree. We should have a dedicated withAzureActiveDirectoryOnlyAuthentication.
Also, I'm seeing we already have withActiveDirectoryAdministrator method, can we reuse that?
e.g.

WithActiveDirectoryAdministrator withAzureActiveDirectoryOnlyAuthentication();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

They appear somehow different. withAzureActiveDirectoryOnlyAuthentication would create a resource.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, then we should have two phases.

interface WithAzureActiveDirectoryOnlyAuthentication {
  WithExternalActiveDirectoryAdministrator withAzureActiveDirectoryOnlyAuthentication();
}

interface WithExternalActiveDirectoryAdministrator {
  WithCreate withExternalActiveDirectoryAdministrator(.., ..);
}

@v-huizhu2 Could you help check what's sqlServer.innerModel().administrators().principalType() after server creation? I assume server will "infer" from the "sid" if not provided, though need confirmation.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

  1. API naming — Done. Renamed to .withAzureActiveDirectoryOnlyAuthentication() + .withExternalActiveDirectoryAdministrator(userLogin, sid) as you suggested, matching the CLI pattern.
  2. Do we need --external-admin-principal-type? — The implementation now hardcodes withPrincipalType(PrincipalType.USER) in withExternalActiveDirectoryAdministrator(). The server can infer the principal type from the SID, but setting it explicitly to USER avoids an extra Graph lookup by the service. If we need to support Group or Application in the future, we can add an overload. For now, all live tests use a user principal, so USER is sufficient.
  3. Two-phase interface design — Done.
  4. What's sqlServer.innerModel().administrators().principalType() after creation? — The implementation now sets withPrincipalType(PrincipalType.USER) explicitly. The service does infer it from the SID if omitted, but setting it explicitly is safer and avoids ambiguity.

Copy link
Copy Markdown
Member

@weidongxu-microsoft weidongxu-microsoft May 18, 2026

Choose a reason for hiding this comment

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

On 2: any code not in test folder is for user to use. not for your test to use. "all live tests use a user principal, so USER is sufficient" is not a explanation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For general region, we could make it a field property and reference it in each test, in case we need to update it again in future recording tests.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Region as field property — Done. Extracted DEFAULT_REGION, SECONDARY_REGION, TERTIARY_REGION as private static final constants at class level.

Comment on lines 895 to 897
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What's the accountKey if SAS is disabled?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

What's the accountKey if SAS is disabled? — That's exactly why the threat detection policy test is now commented out. The AAD-only tenant requires disableSharedKeyAccess(), which makes getKeys() return keys the data plane won't accept. The securityAlertPolicies API has no Managed Identity option (unlike auditingSettings), so there's no working auth path. The import/export test was rewritten to use withManagedIdentity(uamiResourceId) instead.

Comment on lines 67 to 86
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These seems not needed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

These seems not needed?" (adminLogin/adminSid in SqlServerTest) — Correct, removed. Each test now calls azureCliSignedInUser() directly to get the AzureUser, making the adminLogin()/adminSid() helpers and their caching logic unnecessary.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this due to concurrent test running? If so, we could enhance the azureCliSignedInUser method, to cache the AzureUser instance.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

"Is this due to concurrent test running? Cache azureCliSignedInUser?" — The azureCliSignedInUser() method is inherited from ResourceManagerTestProxyTestBase. Each test method calls it independently; tests don't run concurrently within a single class (JUnit 5 default). If caching is desired for performance, it can be done in the base class. Current usage is simple and correct without caching.

v-huizhu2 added 5 commits May 15, 2026 21:32
Enables user-assigned managed identity authentication for SQL database import/export operations, allowing secure access to storage accounts when shared-key authentication is disabled. Updates public APIs, implementation, and tests to support this authentication method. Also refines Entra-only authentication setup, streamlining interface and test usage.

Relates to customer scenarios with storage accounts enforcing identity-based access.
Cleans up formatting by deleting a redundant empty line,
improving code readability and maintaining style consistency.
Removes unnecessary line breaks and indentation in several interface
method and type declarations to improve code readability and
maintain consistency across model definitions.
Allows user-assigned managed identity authentication for SQL database import, export, and creation stages in the fluent API, clarifying that these enhancements impact only SDK-implemented interfaces and do not break user implementations.
Comment on lines +1519 to +1526
{
"code": "java.method.addedToInterface",
"new" : {
"matcher": "regex",
"match": "method .* com\\.azure\\.resourcemanager\\.sql\\.models\\.(SqlDatabase|SqlDatabaseOperations|SqlDatabaseExportRequest|SqlDatabaseImportRequest)\\.DefinitionStages\\.(WithAuthentication|WithAuthenticationAfterElasticPool|WithAuthenticationTypeAndLoginPassword)(<ParentT>)?::withManagedIdentity\\(java\\.lang\\.String\\)"
},
"justification": "Adds user-assigned managed identity authentication option to SQL database import/export and creation fluent stages. These DefinitionStages interfaces are only meant to be implemented by the SDK itself."
},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

withActiveDirectoryLoginAndPassword(String administratorLogin, String administratorPassword);

/**
* Sets the user-assigned managed identity used to authenticate to the SQL database for export.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it restricted to uami? Can sami be used here?

Also, can signed-in user's objectId be used?

//
// The UAMI resource ID is read from the AZURE_SQL_IMPORT_EXPORT_UAMI_ID environment variable.
// If it is not provided the test is skipped instead of failing.
String uamiResourceId = System.getenv("AZURE_SQL_IMPORT_EXPORT_UAMI_ID");
Copy link
Copy Markdown
Contributor

@XiaofeiCao XiaofeiCao May 18, 2026

Choose a reason for hiding this comment

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

Is it possible to programmatically create uami and assign "Storage Blob Data Contributor" to it?

If so, could you also try sami path?

  • get sami ID
  • assign "Storage Blob Data Contributor" to it
  • import/export(without setting withManagedIdentity)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Mgmt This issue is related to a management-plane library.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants