Skip to content

Commit 5d4f942

Browse files
committed
- Added some new pipeline variables to handle the Workload Identity Federation test.
1 parent 006a2d4 commit 5d4f942

File tree

5 files changed

+50
-6
lines changed

5 files changed

+50
-6
lines changed

eng/pipelines/common/templates/steps/update-config-file-step.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ parameters:
124124
type: boolean
125125
default: true
126126

127+
- name: WorkloadIdentityFederationServiceConnectionId
128+
type: string
129+
default: ''
130+
127131
steps:
128132
# All properties should be added here, and this template should be used for any manipulation of the config.json file.
129133
- pwsh: |
@@ -180,6 +184,7 @@ steps:
180184
$p.IsDNSCachingSupportedCR=[System.Convert]::ToBoolean("${{parameters.IsDNSCachingSupportedCR }}")
181185
$p.TracingEnabled=[System.Convert]::ToBoolean("${{parameters.TracingEnabled }}")
182186
$p.EnclaveEnabled=[System.Convert]::ToBoolean("${{parameters.EnclaveEnabled }}")
187+
$p.WorkloadIdentityFederationServiceConnectionId="${{parameters.WorkloadIdentityFederationServiceConnectionId }}"
183188
}
184189
$jdata | ConvertTo-Json | Set-Content "config.json"
185190
workingDirectory: src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities

eng/pipelines/jobs/test-azure-package-ci-job.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,13 @@ jobs:
220220
# necessary here.
221221

222222
AADServicePrincipalId: $(AADServicePrincipalId)
223+
AzureKeyVaultTenantId: $(AzureKeyVaultTenantId)
223224
# macOS doesn't support managed identities.
224225
ManagedIdentitySupported: ${{ not(eq(parameters.vmImage, 'macos-latest')) }}
225226
SupportsIntegratedSecurity: ${{ eq(variables['SupportsIntegratedSecurity'], 'true') }}
226227
TCPConnectionString: $(AZURE_DB_TCP_CONN_STRING)
227228
UserManagedIdentityClientId: $(UserManagedIdentityClientId)
229+
WorkloadIdentityFederationServiceConnectionId: $(WorkloadIdentityFederationServiceConnectionId)
228230
# Note: Using the isFork variable to determine if secrets are
229231
# available is not ideal since it's an indirect association. But
230232
# everything else (referencing secret variables various ways to detect

src/Microsoft.Data.SqlClient.Extensions/Azure/test/Config.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ internal static class Config
4545
internal static string SystemAccessToken { get; } = string.Empty;
4646
internal static bool SystemAssignedManagedIdentitySupported { get; } = false;
4747
internal static string TcpConnectionString { get; } = string.Empty;
48+
internal static string TenantId { get; } = string.Empty;
4849
internal static bool UseManagedSniOnWindows { get; } = false;
4950
internal static string UserManagedIdentityClientId { get; } = string.Empty;
51+
internal static string WorkloadIdentityFederationServiceConnectionId { get; } = string.Empty;
5052

5153
#endregion
5254

@@ -58,7 +60,9 @@ internal static bool HasIntegratedSecurityConnectionString() =>
5860
internal static bool HasServicePrincipal() => !ServicePrincipalId.Empty() && !ServicePrincipalSecret.Empty();
5961
internal static bool HasSystemAccessToken() => !SystemAccessToken.Empty();
6062
internal static bool HasTcpConnectionString() => !TcpConnectionString.Empty();
63+
internal static bool HasTenantId() => !TenantId.Empty();
6164
internal static bool HasUserManagedIdentityClientId() => !UserManagedIdentityClientId.Empty();
65+
internal static bool HasWorkloadIdentityFederationServiceConnectionId() => !WorkloadIdentityFederationServiceConnectionId.Empty();
6266

6367
internal static bool SupportsIntegratedSecurity() => IntegratedSecuritySupported;
6468
internal static bool SupportsManagedIdentity() => ManagedIdentitySupported;
@@ -110,10 +114,14 @@ static Config()
110114
PasswordConnectionString = GetString(root, "AADPasswordConnectionString");
111115
ServicePrincipalId = GetString(root, "AADServicePrincipalId");
112116
ServicePrincipalSecret = GetString(root, "AADServicePrincipalSecret");
113-
SystemAssignedManagedIdentitySupported = GetBool(root, "SupportsSystemAssignedManagedIdentity");
117+
SystemAssignedManagedIdentitySupported =
118+
GetBool(root, "SupportsSystemAssignedManagedIdentity");
114119
TcpConnectionString = GetString(root, "TCPConnectionString");
120+
TenantId = GetString(root, "AzureKeyVaultTenantId");
115121
UseManagedSniOnWindows = GetBool(root, "UseManagedSNIOnWindows");
116122
UserManagedIdentityClientId = GetString(root, "UserManagedIdentityClientId");
123+
WorkloadIdentityFederationServiceConnectionId =
124+
GetString(root, "WorkloadIdentityFederationServiceConnectionId");
117125
}
118126
catch (Exception ex)
119127
{
@@ -151,10 +159,15 @@ static Config()
151159
$" SystemAssignedManagedIdentitySupported: {SystemAssignedManagedIdentitySupported}");
152160
Console.WriteLine(
153161
$" TcpConnectionString: {TcpConnectionString}");
162+
Console.WriteLine(
163+
$" TenantId: {TenantId}");
154164
Console.WriteLine(
155165
$" UseManagedSniOnWindows: {UseManagedSniOnWindows}");
156166
Console.WriteLine(
157167
$" UserManagedIdentityClientId: {UserManagedIdentityClientId}");
168+
Console.WriteLine(
169+
" WorkloadIdentityFederationServiceConnectionId: " +
170+
WorkloadIdentityFederationServiceConnectionId);
158171
}
159172

160173
// Apply the SNI flag, if necessary. This must occur before any MDS

src/Microsoft.Data.SqlClient.Extensions/Azure/test/WorkloadIdentityFederationTests.cs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,49 @@ namespace Microsoft.Data.SqlClient.Extensions.Azure.Test;
1010
// Workload Identity Federation authentication.
1111
public class WorkloadIdentityFederationTests
1212
{
13-
[ConditionalFact(typeof(Config), nameof(Config.HasSystemAccessToken))]
13+
[ConditionalFact(
14+
typeof(Config),
15+
nameof(Config.HasSystemAccessToken),
16+
nameof(Config.HasTenantId),
17+
nameof(Config.HasUserManagedIdentityClientId),
18+
nameof(Config.HasWorkloadIdentityFederationServiceConnectionId))]
1419
public async void GetCredential()
1520
{
1621
AzurePipelinesCredential credential = new(
1722
// The tenant ID if the managed identity associated to our workload
1823
// identity federation service connection. See:
1924
//
2025
// https://ms.portal.azure.com/#@microsoft.onmicrosoft.com/resource/subscriptions/654fffd0-d02d-4894-b1b7-e2dfbc44a665/resourceGroups/aad-testlab-dl797892652000/providers/Microsoft.ManagedIdentity/userAssignedIdentities/dotnetMSI/properties
21-
"72f988bf-86f1-41af-91ab-2d7cd011db47",
26+
//
27+
// Note that we need a service connection configured in each Azure DevOps project
28+
// (Public and ADO.Net) that uses this tenant ID.
29+
//
30+
Config.TenantId,
31+
2232
// The client ID of the managed identity associated to our workload
2333
// identity federation service connection. See:
2434
//
2535
// https://ms.portal.azure.com/#@microsoft.onmicrosoft.com/resource/subscriptions/654fffd0-d02d-4894-b1b7-e2dfbc44a665/resourceGroups/aad-testlab-dl797892652000/providers/Microsoft.ManagedIdentity/userAssignedIdentities/dotnetMSI/overview
26-
"92a44a21-5265-4fdd-9537-45b1cf54aa2d",
36+
//
37+
Config.UserManagedIdentityClientId,
2738

2839
// The Azure Dev Ops service connection ID (resourceId found in the
2940
// URL) of our workload identity federation setup. See:
3041
//
42+
// Note that we need a service connection configured in each Azure
43+
// DevOps project (Public and ADO.Net).
44+
//
45+
// Public project:
46+
//
3147
// https://sqlclientdrivers.visualstudio.com/public/_settings/adminservices?resourceId=ec9623b2-829c-497f-ae1f-7461766f9a9c
32-
"ec9623b2-829c-497f-ae1f-7461766f9a9c",
48+
//
49+
// ADO.Net project:
50+
//
51+
// https://sqlclientdrivers.visualstudio.com/ADO.Net/_settings/adminservices?resourceId=c29947a8-df6a-4ceb-b2d4-1676c57c37b9
52+
//
53+
Config.WorkloadIdentityFederationServiceConnectionId,
54+
55+
// The system access token provided by Azure Pipelines.
3356
Config.SystemAccessToken);
3457

3558
// Acquire a token suitable for accessing Azure SQL databases.

src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@
3535
"ManagedIdentitySupported": true,
3636
"UserManagedIdentityClientId": "",
3737
"PowerShellPath": "",
38-
"AliasName": ""
38+
"AliasName": "",
39+
"WorkloadIdentityFederationServiceConnectionId": ""
3940
}

0 commit comments

Comments
 (0)