-
Notifications
You must be signed in to change notification settings - Fork 2.9k
azrepos: make shared token cache configurable #2415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -920,6 +920,33 @@ export GCM_MSAUTH_USEDEFAULTACCOUNT="false" | |
|
|
||
| --- | ||
|
|
||
| ### GCM_AZREPOS_USE_MSFT_CACHE | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment seems to apply here from https://github.com/git-ecosystem/git-credential-manager/pull/2415/changes#r3870142015 |
||
|
|
||
| Use the token cache shared by Microsoft developer tools when authenticating to | ||
| Azure Repos with Microsoft identity OAuth tokens. This allows GCM to reuse | ||
| authentication performed by tools such as Visual Studio and Azure CLI, and | ||
| allows those tools to reuse authentication performed by GCM. | ||
|
|
||
| Set this value to `false` to use a GCM-specific token cache instead. | ||
|
|
||
| Defaults to `true`. | ||
|
|
||
| #### Windows | ||
|
|
||
| ```batch | ||
| SET GCM_AZREPOS_USE_MSFT_CACHE=false | ||
| ``` | ||
|
|
||
| #### macOS/Linux | ||
|
|
||
| ```bash | ||
| export GCM_AZREPOS_USE_MSFT_CACHE="false" | ||
| ``` | ||
|
|
||
| **Also see: [credential.azreposUseMicrosoftSharedCache][shared-cache]** | ||
|
|
||
| --- | ||
|
|
||
| ### GCM_AZREPOS_CREDENTIALTYPE | ||
|
|
||
| Specify the type of credential the Azure Repos host provider should return. | ||
|
|
@@ -1351,6 +1378,7 @@ Defaults to disabled. | |
| [credential-authority]: configuration.md#credentialauthority-deprecated | ||
| [credential-autodetecttimeout]: configuration.md#credentialautodetecttimeout | ||
| [credential-azrepos-credential-type]: configuration.md#credentialazreposcredentialtype | ||
| [shared-cache]: configuration.md#credentialazreposusemicrosoftsharedcache | ||
| [credential-azrepos-managedidentity]: configuration.md#credentialazreposmanagedidentity | ||
| [credential-azrepos-wif]: configuration.md#credentialazreposworkloadfederation | ||
| [credential-azrepos-wif-clientid]: configuration.md#credentialazreposworkloadfederationclientid | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,48 +15,73 @@ public EntraAuthenticationDiagnostic(ICommandContext context) | |
|
|
||
| protected override async Task<bool> RunInternalAsync(StringBuilder log, IList<string> additionalFiles) | ||
| { | ||
| var entraAuth = new EntraAuthentication(CommandContext, new PublicClientConfig | ||
| { | ||
| UseSharedCache = true, | ||
| }); | ||
| var failures = new List<Exception>(); | ||
|
|
||
| log.Append("Gathering MSAL token cache data..."); | ||
| StorageCreationProperties cacheProps = entraAuth.CreateUserTokenCacheProps(true); | ||
| log.AppendLine(" OK"); | ||
| log.AppendLine($"CacheDirectory: {cacheProps.CacheDirectory}"); | ||
| log.AppendLine($"CacheFileName: {cacheProps.CacheFileName}"); | ||
| log.AppendLine($"CacheFilePath: {cacheProps.CacheFilePath}"); | ||
| await RunCacheDiagnosticAsync("Shared Microsoft developer tools", true, log, failures); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The diagnostic now tests both caches and throws if either fails. Consequently, a user who explicitly selects the GCM-specific cache can still get a failed git-credential-manager diagnose result solely because the unused shared cache is inaccessible, and vice versa. This is especially misleading because DiagnoseCommand reports that failures indicate an installation problem. Consider logging results for both caches but making only the configured cache determine diagnostic success, or registering each cache check as a separate diagnostic so the relevant and optional failures are distinguishable. |
||
| log.AppendLine(); | ||
| await RunCacheDiagnosticAsync("Git Credential Manager", false, log, failures); | ||
|
|
||
| if (PlatformUtils.IsMacOS()) | ||
| if (failures.Count == 1) | ||
| { | ||
| log.AppendLine($"MacKeyChainAccountName: {cacheProps.MacKeyChainAccountName}"); | ||
| log.AppendLine($"MacKeyChainServiceName: {cacheProps.MacKeyChainServiceName}"); | ||
| throw failures[0]; | ||
| } | ||
| else if (PlatformUtils.IsLinux()) | ||
|
|
||
| if (failures.Count > 1) | ||
| { | ||
| log.AppendLine($"KeyringCollection: {cacheProps.KeyringCollection}"); | ||
| log.AppendLine($"KeyringSchemaName: {cacheProps.KeyringSchemaName}"); | ||
| log.AppendLine($"KeyringSecretLabel: {cacheProps.KeyringSecretLabel}"); | ||
| log.AppendLine($"KeyringAttribute1: ({cacheProps.KeyringAttribute1.Key},{cacheProps.KeyringAttribute1.Value})"); | ||
| log.AppendLine($"KeyringAttribute2: ({cacheProps.KeyringAttribute2.Key},{cacheProps.KeyringAttribute2.Value})"); | ||
| throw new AggregateException("Multiple MSAL token cache diagnostics failed.", failures); | ||
| } | ||
|
|
||
| log.Append("Creating cache helper..."); | ||
| var cacheHelper = await MsalCacheHelper.CreateAsync(cacheProps); | ||
| log.AppendLine(" OK"); | ||
| return true; | ||
| } | ||
|
|
||
| private async Task RunCacheDiagnosticAsync( | ||
| string cacheName, | ||
| bool useSharedCache, | ||
| StringBuilder log, | ||
| ICollection<Exception> failures) | ||
| { | ||
| log.AppendLine($"{cacheName} cache"); | ||
|
|
||
| var entraAuth = new EntraAuthentication(CommandContext, new PublicClientConfig | ||
| { | ||
| UseSharedCache = useSharedCache, | ||
| }); | ||
|
|
||
| try | ||
| { | ||
| log.Append("Gathering MSAL token cache data..."); | ||
| StorageCreationProperties cacheProps = entraAuth.CreateUserTokenCacheProps(true); | ||
| log.AppendLine(" OK"); | ||
| log.AppendLine($"CacheDirectory: {cacheProps.CacheDirectory}"); | ||
| log.AppendLine($"CacheFileName: {cacheProps.CacheFileName}"); | ||
| log.AppendLine($"CacheFilePath: {cacheProps.CacheFilePath}"); | ||
|
|
||
| if (PlatformUtils.IsMacOS()) | ||
| { | ||
| log.AppendLine($"MacKeyChainAccountName: {cacheProps.MacKeyChainAccountName}"); | ||
| log.AppendLine($"MacKeyChainServiceName: {cacheProps.MacKeyChainServiceName}"); | ||
| } | ||
| else if (PlatformUtils.IsLinux()) | ||
| { | ||
| log.AppendLine($"KeyringCollection: {cacheProps.KeyringCollection}"); | ||
| log.AppendLine($"KeyringSchemaName: {cacheProps.KeyringSchemaName}"); | ||
| log.AppendLine($"KeyringSecretLabel: {cacheProps.KeyringSecretLabel}"); | ||
| log.AppendLine($"KeyringAttribute1: ({cacheProps.KeyringAttribute1.Key},{cacheProps.KeyringAttribute1.Value})"); | ||
| log.AppendLine($"KeyringAttribute2: ({cacheProps.KeyringAttribute2.Key},{cacheProps.KeyringAttribute2.Value})"); | ||
| } | ||
|
|
||
| log.Append("Creating cache helper..."); | ||
| var cacheHelper = await MsalCacheHelper.CreateAsync(cacheProps); | ||
| log.AppendLine(" OK"); | ||
| log.Append("Verifying MSAL token cache persistence..."); | ||
| cacheHelper.VerifyPersistence(); | ||
| log.AppendLine(" OK"); | ||
| } | ||
| catch (Exception) | ||
| catch (Exception ex) | ||
| { | ||
| log.AppendLine(" Failed"); | ||
| throw; | ||
| failures.Add(new Exception($"{cacheName} cache diagnostic failed.", ex)); | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These additions say the selected cache allows authentication reuse with Azure CLI. Azure CLI maintains its own cache under $AZURE_CONFIG_DIR/msal_token_cache.{bin,json}, rather than the .IdentityService/msal.cache cache configured here. Any broker-based SSO on supported systems is separate from sharing this cache and may still occur when this option is disabled.
Remove Azure CLI from these examples or describe the narrower set of tools that actually consume the Microsoft developer shared cache.