Skip to content

Conversation

Copy link

Copilot AI commented Sep 10, 2025

This PR fixes critical configuration issues in the Azure Managed Identity SQL authentication demo that were preventing proper environment variable resolution and managed identity setup.

Issues Fixed

1. Broken Environment Variable Configuration

The AZURE_CLIENT_ID property was hardcoded as a placeholder instead of referencing the actual environment variable:

Before:

AZURE_CLIENT_ID=<your managed identity client id>

After:

AZURE_CLIENT_ID=${AZURE_CLIENT_ID}

2. Missing Environment Variable Resolution

The Java application was loading properties but not resolving Spring-style ${VAR_NAME} placeholders, causing connection strings to contain literal placeholder text instead of actual values.

Added environment variable resolution method:

private static String resolveEnvironmentVariables(String input) {
    // Resolves ${VAR_NAME} patterns with actual environment variable values
    Pattern pattern = Pattern.compile("\\$\\{([^}]+)\\}");
    // ... implementation details
}

Verification

The connection string is now properly constructed with managed identity parameters:

jdbc:sqlserver://[server].database.windows.net:1433;database=demo;encrypt=true;
trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;
loginTimeout=30;;msiClientId=[resolved-client-id];authentication=ActiveDirectoryMSI

Testing

  • ✅ Application builds successfully with mvn clean package
  • ✅ Environment variables are properly resolved (tested with multiple variable combinations)
  • ✅ Managed identity authentication parameters are correctly applied to connection string
  • ✅ Build artifacts cleaned up and added to .gitignore

This ensures the demo application properly demonstrates Azure Managed Identity authentication with Azure SQL Database using the Spring Cloud Azure dependencies that were already configured.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • myserver.database.windows.net
    • Triggering command: java -cp target/demo-1.0-SNAPSHOT.jar com.example.MainSQL (dns block)
  • prod-server.database.windows.net
    • Triggering command: java -jar target/demo-1.0-SNAPSHOT.jar (dns block)
    • Triggering command: java -cp target/demo-1.0-SNAPSHOT.jar com.example.MainSQL (dns block)
  • testserver.database.windows.net
    • Triggering command: java -jar target/demo-1.0-SNAPSHOT.jar (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Created from VS Code via the GitHub Pull Request extension.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits September 10, 2025 20:40
…olution

Co-authored-by: richposada <454664+richposada@users.noreply.github.com>
Co-authored-by: richposada <454664+richposada@users.noreply.github.com>
Copilot AI changed the title [WIP] Migrate to Azure Managed Identity for Azure SQL (mi-azuresql-spring) Fix Azure Managed Identity configuration for SQL authentication in mi-azuresql-spring demo Sep 10, 2025
Copilot AI requested a review from richposada September 10, 2025 20:44
Copilot finished work on behalf of richposada September 10, 2025 20:44
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