Skip to content

Harden migrated App Service samples and migrate archived Entra/RBAC security samples - #49935

Merged
weidongxu-microsoft merged 6 commits into
Azure:mainfrom
weidongxu-microsoft:mgmt-harden-mslearn-samples-security
Jul 28, 2026
Merged

Harden migrated App Service samples and migrate archived Entra/RBAC security samples#49935
weidongxu-microsoft merged 6 commits into
Azure:mainfrom
weidongxu-microsoft:mgmt-harden-mslearn-samples-security

Conversation

@weidongxu-microsoft

Copy link
Copy Markdown
Member

Summary

Follow-up to #49923 (which migrated the archived MS Learn Java sample pages into azure-resourcemanager). This PR:

  1. Hardens the migrated App Service samples with passwordless / secure-by-default patterns.
  2. Migrates the archived security-samples page (Microsoft Entra ID / RBAC) — two new samples.

Archived source page added in this PR:

Mapping: MS Learn sample → file path

Paths are relative to sdk/resourcemanager/azure-resourcemanager/src/samples/java/com/azure/resourcemanager/.

Security (Microsoft Entra ID / RBAC) — new in this PR

MS Learn sample File path
Manage users, groups and roles authorization/samples/ManageUsersGroupsAndRoles.java
Manage service principals authorization/samples/ManageServicePrincipal.java (modernized off the retired Track 1 sample — no auth file / self-signed cert)
Sign in users to a web application Skipped (deleted) — standalone MSAL/OpenID Connect auth sample, unrelated to azure-resourcemanager
Native/headless sign-in sample Skipped (left as redirect) — archived README already redirects to current guidance

Virtual machines (from #49923, for context)

MS Learn sample File path
Create a virtual machine from a custom image compute/samples/CreateVirtualMachineUsingCustomImageFromVM.java
Create a virtual machine using specialized VHD from a snapshot compute/samples/CreateVirtualMachineUsingSpecializedDiskFromSnapshot.java
Create virtual machines in parallel in the same network compute/samples/ManageVirtualMachinesInParallel.java

Web apps

MS Learn sample File path
Create a web app and deploy from FTP or GitHub Skipped — MS Learn link is empty (./)
Create a web app and manage deployment slots appservice/samples/ManageWebAppSlots.java
Create a web app and configure a custom domain appservice/samples/ManageWebAppWithCustomDomain.java
Scale a web app with high availability across multiple regions appservice/samples/ScaleWebAppWithTrafficManager.java
Connect a web app to a storage account appservice/samples/ConnectWebAppToStorageAccount.java (hardened in this PR)
Connect a web app to a SQL database appservice/samples/ConnectWebAppToSqlDatabase.java (hardened in this PR)

SQL Database

MS Learn sample File path
Connect and query data from Azure SQL Database using JDBC Skipped — JDBC how-to tutorial, no management sample
Create and manage SQL databases sql/samples/ManageSqlDatabase.java
Manage SQL databases across multiple regions sql/samples/ManageSqlDatabasesAcrossRegions.java

Containers

MS Learn sample File path
Manage Azure Container Registries containerregistry/samples/ManageContainerRegistry.java
Manage Azure Container Service containerservice/samples/ManageKubernetesCluster.java (ACS retired → AKS)
Deploy an image from Azure Container Registry into a new Linux Web App appservice/samples/DeployImageFromAcrToLinuxWebApp.java

Security hardening (App Service samples)

  • ConnectWebAppToStorageAccount — passwordless: grants the web app's system-assigned managed identity the
    Storage Blob Data Contributor role instead of storing an account key in app settings. Re-recorded on a personal
    subscription (Japan East); the recording deploys a dependency-free Node verifier that confirms managed-identity
    blob access. Recording asset pushed to Azure/azure-sdk-assets.
  • ConnectWebAppToSqlDatabase — Microsoft Entra-only SQL Server with the web app's managed identity as admin
    (already in Migrate archived MS Learn Java samples into azure-resourcemanager #49923; noted here for completeness).
  • HTTPS-only enabled on the web apps; minimum TLS 1.2 and FTPS-only are Azure defaults (commented in the samples).

Security samples (Entra / RBAC): live-only, not recorded

GraphRbacSampleTests (testManageUsersGroupsAndRoles, testManageServicePrincipal) is @LiveOnly — never
recorded — because these create real Entra users/apps/service principals with secrets that must not be persisted, and
service-principal re-authentication cannot replay through the test proxy. Both were validated LIVE on a personal
subscription
; an Entra before/after snapshot confirmed complete cleanup (no leftover identities or dangling role
assignments).

  • Least privilege: ManageServicePrincipal assigns Reader (only lists VMs), not Contributor.
  • Complete cleanup: deletes the created AD application (cascades to the service principal), role assignments, users
    and groups — nothing orphaned.

Verification

  • Module compiles + passes spotless:check / checkstyle:check.
  • Storage sample: RECORD + PLAYBACK pass; asset pushed.
  • GraphRBAC samples: pass LIVE on a personal sub; nothing recorded/pushed.

weidongxu-microsoft and others added 2 commits July 27, 2026 14:15
…TTPS-only)

Security follow-up to Azure#49923:
- ConnectWebAppToStorageAccount: remove storage account-key connection string;
  disable shared-key access, use system-assigned managed identity + Storage Blob
  Data Contributor role, expose only the blob endpoint. Convert the web app to
  Linux Node.js and deploy a small dependency-free managed-identity blob verifier
  via zipDeploy (bounded retry on HTTP 409). Re-recorded on personal sub.
- All web-app samples: set httpsOnly(true) explicitly; note TLS 1.2 / FTPS-only
  are already App Service defaults.
- Wire src/samples/resources onto the test classpath for the verifier assets.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4727c5a4-1b1d-4c1d-af70-7b9e7f83f806
…sourcemanager

Add ManageUsersGroupsAndRoles and ManageServicePrincipal under
authorization/samples, migrated from the archived MS Learn security-samples
page. ManageServicePrincipal is modernized off the retired Track 1 sample
(no auth file / self-signed cert; password credential + ClientSecretCredential).

Tests run live-only (@liveonly, GraphRbacSampleTests): these create Entra
users/apps/service principals with secrets that must not be recorded, and SP
re-auth cannot replay through the test proxy. Validated LIVE on a personal
subscription; cleanup verified against an Entra before/after snapshot.

Security: least-privilege Reader for the SP (only lists VMs); complete cleanup
of the created application (cascades to the SP), role assignment, users and
groups so nothing is orphaned.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4727c5a4-1b1d-4c1d-af70-7b9e7f83f806
@github-actions github-actions Bot added the Mgmt This issue is related to a management-plane library. label Jul 27, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
33 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

… pom

Fixes CI 'Verify versions in POM files' failure requiring a <version> element with x-version-update tag for org.codehaus.mojo:build-helper-maven-plugin.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 7882f7ff-8f5e-41d1-817d-c11ab59a2c14
@weidongxu-microsoft
weidongxu-microsoft marked this pull request as ready for review July 27, 2026 07:32
Copilot AI review requested due to automatic review settings July 27, 2026 07:32
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
33 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

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.

Pull request overview

This PR follows up on the earlier MS Learn sample migration by (1) hardening the App Service samples with secure-by-default patterns (notably HTTPS-only and passwordless managed identity for Storage) and (2) adding new Microsoft Entra ID / RBAC samples plus a live-only test suite for them.

Changes:

  • Harden App Service samples: enforce HTTPS-only across web app creations and update the Storage connection sample to use system-assigned managed identity + RBAC instead of storage keys.
  • Add Microsoft Entra ID / RBAC samples (users/groups/roles and service principals) and add @LiveOnly tests to run them safely without recordings.
  • Update build/test wiring so sample resource files under src/samples/resources are available at test runtime; update assets tag for refreshed recordings.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
sdk/resourcemanager/azure-resourcemanager/src/test/java/com/azure/resourcemanager/samples/GraphRbacSampleTests.java Adds live-only tests for Entra/RBAC samples.
sdk/resourcemanager/azure-resourcemanager/src/samples/resources/appservice/mi-blob-verify/server.js Adds dependency-free Node verifier app for managed-identity Blob access.
sdk/resourcemanager/azure-resourcemanager/src/samples/resources/appservice/mi-blob-verify/package.json Declares start script for the verifier app.
sdk/resourcemanager/azure-resourcemanager/src/samples/java/com/azure/resourcemanager/samples/SampleUtils.java Adds password generator helper used by Entra samples.
sdk/resourcemanager/azure-resourcemanager/src/samples/java/com/azure/resourcemanager/authorization/samples/package-info.java Introduces package docs for Entra/RBAC samples.
sdk/resourcemanager/azure-resourcemanager/src/samples/java/com/azure/resourcemanager/authorization/samples/ManageUsersGroupsAndRoles.java New sample for creating users/groups and managing role assignments.
sdk/resourcemanager/azure-resourcemanager/src/samples/java/com/azure/resourcemanager/authorization/samples/ManageServicePrincipal.java New sample for creating and using a service principal with least-privilege access.
sdk/resourcemanager/azure-resourcemanager/src/samples/java/com/azure/resourcemanager/appservice/samples/ScaleWebAppWithTrafficManager.java Enforces HTTPS-only for created web apps.
sdk/resourcemanager/azure-resourcemanager/src/samples/java/com/azure/resourcemanager/appservice/samples/ManageWebAppWithCustomDomain.java Enforces HTTPS-only and documents defaults.
sdk/resourcemanager/azure-resourcemanager/src/samples/java/com/azure/resourcemanager/appservice/samples/ManageWebAppSlots.java Enforces HTTPS-only and documents defaults.
sdk/resourcemanager/azure-resourcemanager/src/samples/java/com/azure/resourcemanager/appservice/samples/DeployImageFromAcrToLinuxWebApp.java Enforces HTTPS-only and documents defaults.
sdk/resourcemanager/azure-resourcemanager/src/samples/java/com/azure/resourcemanager/appservice/samples/ConnectWebAppToStorageAccount.java Migrates to passwordless MI + RBAC model, deploys verifier app package.
sdk/resourcemanager/azure-resourcemanager/src/samples/java/com/azure/resourcemanager/appservice/samples/ConnectWebAppToSqlDatabase.java Enforces HTTPS-only and documents defaults.
sdk/resourcemanager/azure-resourcemanager/pom.xml Adds src/samples/resources as test resources so samples can load packaged files.
sdk/resourcemanager/azure-resourcemanager/assets.json Updates assets tag to reference refreshed recordings.

weidongxu-microsoft and others added 3 commits July 27, 2026 16:57
Address bot review feedback that does not require re-recording:
- ManageUsersGroupsAndRoles: guard getByName(spName) in the cleanup finally block so a null lookup (eventual consistency / name collision) no longer throws and skips remaining identity cleanup.
- ConnectWebAppToStorageAccount: throw a clear FileNotFoundException when a bundled mi-blob-verify resource is missing instead of a message-less NullPointerException.

These are Java-only logic changes that do not alter recorded HTTP traffic (storage sample stays playback-compatible; GraphRbac sample is @liveonly).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 7882f7ff-8f5e-41d1-817d-c11ab59a2c14
Add a src/samples/README.md following the standard samples layout used by other modules (YAML front-matter + grouped, linked sample list). Lists the runnable management samples migrated from the archived MS Learn pages, grouped by service (App Service, Authorization, Compute, Container Registry, Container Service, SQL), and links to the SDK getting-started, SAMPLE.md snippets, and management SDK docs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 7882f7ff-8f5e-41d1-817d-c11ab59a2c14
Add a pointer from the module README Examples section to the new src/samples/README.md listing the runnable management samples.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 7882f7ff-8f5e-41d1-817d-c11ab59a2c14
@weidongxu-microsoft
weidongxu-microsoft merged commit 768fba0 into Azure:main Jul 28, 2026
19 checks passed
@weidongxu-microsoft
weidongxu-microsoft deleted the mgmt-harden-mslearn-samples-security branch July 28, 2026 02:32
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