Skip to content

Commit 65e6b71

Browse files
committed
devbox: enable msauth default account and broker in devbox
Detect when we are in a Microsoft Dev Box environment, and if we are, then default to enabling the default OS account setting and enabling WAM.
1 parent d2e0b39 commit 65e6b71

File tree

7 files changed

+69
-11
lines changed

7 files changed

+69
-11
lines changed

docs/configuration.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,10 @@ git config --global credential.msauthFlow devicecode
543543

544544
Use the operating system account manager where available.
545545

546-
Defaults to `false`. This default is subject to change in the future.
546+
Defaults to `false`. In certain cloud hosted environments when using a work or
547+
school account, such as [Microsoft DevBox][devbox], the default is `true`.
548+
549+
These defaults are subject to change in the future.
547550

548551
_**Note:** before you enable this option on Windows, please review the
549552
[Windows Broker][wam] details for what this means to your local Windows user
@@ -568,7 +571,10 @@ git config --global credential.msauthUseBroker true
568571

569572
Use the current operating system account by default when the broker is enabled.
570573

571-
Defaults to `false`. This default is subject to change in the future.
574+
Defaults to `false`. In certain cloud hosted environments when using a work or
575+
school account, such as [Microsoft DevBox][devbox], the default is `true`.
576+
577+
These defaults are subject to change in the future.
572578

573579
Value|Description
574580
-|-
@@ -692,6 +698,7 @@ git config --global credential.azreposCredentialType oauth
692698
[credential-plaintextstorepath]: #credentialplaintextstorepath
693699
[credential-cache]: https://git-scm.com/docs/git-credential-cache
694700
[cred-stores]: credstores.md
701+
[devbox]: https://azure.microsoft.com/en-us/products/dev-box
695702
[enterprise-config]: enterprise-config.md
696703
[envars]: environment.md
697704
[freedesktop-ss]: https://specifications.freedesktop.org/secret-service/

docs/environment.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,10 @@ export GCM_MSAUTH_FLOW="devicecode"
776776

777777
Use the operating system account manager where available.
778778

779-
Defaults to `false`. This default is subject to change in the future.
779+
Defaults to `false`. In certain cloud hosted environments when using a work or
780+
school account, such as [Microsoft DevBox][devbox], the default is `true`.
781+
782+
These defaults are subject to change in the future.
780783

781784
_**Note:** before you enable this option on Windows, please
782785
[review the details][windows-broker] about what this means to your local Windows
@@ -807,7 +810,10 @@ export GCM_MSAUTH_USEBROKER="false"
807810

808811
Use the current operating system account by default when the broker is enabled.
809812

810-
Defaults to `false`. This default is subject to change in the future.
813+
Defaults to `false`. In certain cloud hosted environments when using a work or
814+
school account, such as [Microsoft DevBox][devbox], the default is `true`.
815+
816+
These defaults are subject to change in the future.
811817

812818
Value|Description
813819
-|-
@@ -881,6 +887,7 @@ export GCM_AZREPOS_CREDENTIALTYPE="oauth"
881887
[credential-provider]: configuration.md#credentialprovider
882888
[credential-stores]: credstores.md
883889
[default-values]: enterprise-config.md
890+
[devbox]: https://azure.microsoft.com/en-us/products/dev-box
884891
[freedesktop-ss]: https://specifications.freedesktop.org/secret-service/
885892
[gcm]: usage.md
886893
[gcm-interactive]: #gcm_interactive

docs/windows-broker.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ variable or set the
4343
[`credential.msauthUseDefaultAccount`][credential.msauthUseDefaultAccount] Git
4444
configuration value to `true`.
4545

46+
In certain cloud hosted environments when using a work or school account, such
47+
as [Microsoft Dev Box][devbox], this setting is **_automatically enabled_**.
48+
49+
To disable this behavior, set the environment variable
50+
[`GCM_MSAUTH_USEDEFAULTACCOUNT`][GCM_MSAUTH_USEDEFAULTACCOUNT] or the
51+
[`credential.msauthUseDefaultAccount`][credential.msauthUseDefaultAccount] Git
52+
configuration value explicitly to `false`.
53+
4654
## Surprising behaviors
4755

4856
The WAM and Windows identity systems are complex, addressing a very broad range
@@ -183,10 +191,10 @@ In order to fix the problem, there are a few options:
183191
[azure-refresh-token-terms]: https://docs.microsoft.com/azure/active-directory/devices/concept-primary-refresh-token#key-terminology-and-components
184192
[azure-conditional-access]: https://docs.microsoft.com/azure/active-directory/conditional-access/overview
185193
[azure-devops]: https://dev.azure.com
186-
[GCM_MSAUTH_USEBROKER]: environment.md#GCM_MSAUTH_USEBROKER
187-
[GCM_MSAUTH_USEDEFAULTACCOUNTR]: environment.md#GCM_MSAUTH_USEDEFAULTACCOUNTR
188-
[credential.msauthUseBroker]: configuration.md#credentialmsauthusebroker
189-
[credential.msauthUseDefaultAccount]: configuration.md#credentialmsauthusedefaultaccount
194+
[GCM_MSAUTH_USEBROKER]: environment.md#GCM_MSAUTH_USEBROKER-experimental
195+
[GCM_MSAUTH_USEDEFAULTACCOUNT]: environment.md#GCM_MSAUTH_USEDEFAULTACCOUNT-experimental
196+
[credential.msauthUseBroker]: configuration.md#credentialmsauthusebroker-experimental
197+
[credential.msauthUseDefaultAccount]: configuration.md#credentialmsauthusedefaultaccount-experimental
190198
[aad-questions]: img/aad-questions.png
191199
[aad-questions-21h1]: img/aad-questions-21H1.png
192200
[aad-bitlocker]: img/aad-bitlocker.png
@@ -197,3 +205,4 @@ In order to fix the problem, there are a few options:
197205
[apps-must-ask]: img/apps-must-ask.png
198206
[ms-com]: https://docs.microsoft.com/en-us/windows/win32/com/the-component-object-model
199207
[msal-dotnet]: https://aka.ms/msal-net
208+
[devbox]: https://azure.microsoft.com/en-us/products/dev-box

src/shared/Core/Authentication/MicrosoftAuthentication.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,8 @@ public bool CanUseBroker()
557557
return false;
558558
}
559559

560-
// Default to not using the OS broker
561-
const bool defaultValue = false;
560+
// Default to using the OS broker only on DevBox for the time being
561+
bool defaultValue = PlatformUtils.IsDevBox();
562562

563563
if (Context.Settings.TryGetSetting(Constants.EnvironmentVariables.MsAuthUseBroker,
564564
Constants.GitConfiguration.Credential.SectionName,

src/shared/Core/Constants.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public static class Constants
1616

1717
public const string GcmDataDirectoryName = ".gcm";
1818

19+
public static readonly Guid DevBoxPartnerId = new("e3171dd9-9a5f-e5be-b36c-cc7c4f3f3bcf");
20+
1921
public static class CredentialStoreNames
2022
{
2123
public const string WindowsCredentialManager = "wincredman";
@@ -187,6 +189,10 @@ public static class WindowsRegistry
187189
{
188190
public const string HKAppBasePath = @"SOFTWARE\GitCredentialManager";
189191
public const string HKConfigurationPath = HKAppBasePath + @"\Configuration";
192+
193+
public const string HKWindows365Path = @"SOFTWARE\Microsoft\Windows365";
194+
public const string IsW365EnvironmentKeyName = "IsW365Environment";
195+
public const string W365PartnerIdKeyName = "PartnerId";
190196
}
191197

192198
public static class HelpUrls

src/shared/Core/PlatformUtils.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,35 @@ public static PlatformInformation GetPlatformInformation(ITrace2 trace2)
2222
return new PlatformInformation(osType, osVersion, cpuArch, clrVersion);
2323
}
2424

25+
public static bool IsDevBox()
26+
{
27+
if (!IsWindows())
28+
{
29+
return false;
30+
}
31+
32+
#if NETFRAMEWORK
33+
// Check for machine (HKLM) registry keys for Cloud PC indicators
34+
// Note that the keys are only found in the 64-bit registry view
35+
using (Microsoft.Win32.RegistryKey hklm64 = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry64))
36+
using (Microsoft.Win32.RegistryKey w365Key = hklm64.OpenSubKey(Constants.WindowsRegistry.HKWindows365Path))
37+
{
38+
if (w365Key is null)
39+
{
40+
// No Windows365 key exists
41+
return false;
42+
}
43+
44+
object w365Value = w365Key.GetValue(Constants.WindowsRegistry.IsW365EnvironmentKeyName);
45+
string partnerValue = w365Key.GetValue(Constants.WindowsRegistry.W365PartnerIdKeyName)?.ToString();
46+
47+
return w365Value is not null && Guid.TryParse(partnerValue, out Guid partnerId) && partnerId == Constants.DevBoxPartnerId;
48+
}
49+
#else
50+
return false;
51+
#endif
52+
}
53+
2554
public static bool IsWindowsBrokerSupported()
2655
{
2756
if (!IsWindows())

src/shared/Core/Settings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ ProxyConfiguration CreateConfiguration(Uri uri, bool isLegacy = false)
781781
KnownGitCfg.Credential.MsAuthUseDefaultAccount,
782782
out string str)
783783
? str.IsTruthy()
784-
: false;
784+
: PlatformUtils.IsDevBox(); // default to true in DevBox environment
785785

786786
#region IDisposable
787787

0 commit comments

Comments
 (0)