Skip to content

Commit d97b550

Browse files
authored
Condition out DefaultAzureCredential in release builds (#1775)
1 parent b2c3d77 commit d97b550

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/Microsoft.DotNet.ImageBuilder/src/AzureTokenCredentialProvider.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,20 @@ Attempted to get Service Connection credential but SYSTEM_ACCESSTOKEN environmen
6363
_systemAccessToken);
6464
}
6565

66+
#if DEBUG
6667
// Fall back to DefaultAzureCredential if no service connection is provided.
68+
// This can still be used for local development against non-production resources.
6769
credential ??= new DefaultAzureCredential();
70+
#endif
71+
72+
if (credential is null)
73+
{
74+
// Using DefaultAzureCredential is not allowed in production environments.
75+
throw new InvalidOperationException(
76+
"Attempted to get an Azure Pipelines Credential but no service connection was provided."
77+
);
78+
}
79+
6880
var accessToken = credential.GetToken(new TokenRequestContext([scope]), CancellationToken.None);
6981
return new StaticTokenCredential(accessToken);
7082
});

0 commit comments

Comments
 (0)