-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #404 from mjcheetham/os-config
Add ability to specify default settings values from the registry on Windows
- Loading branch information
Showing
12 changed files
with
203 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Enterprise configuration defaults | ||
|
||
Git Credential Manager Core (GCM Core) can be configured using multiple | ||
different mechanisms. In order of preference, those mechanisms are: | ||
|
||
1. [Environment variables](environment.md) | ||
2. [Standard Git configuration files](configuration.md) | ||
1. Repository/local configuration (`.git/config`) | ||
2. User/global configuration (`$HOME/.gitconfig` or `%HOME%\.gitconfig`) | ||
3. Installation/system configuration (`etc/gitconfig`) | ||
3. Enterprise system administrator defaults | ||
4. Compiled default values | ||
|
||
This model largely matches what Git itself supports, namely environment | ||
variables that take precedence over Git configuration files. | ||
|
||
The addition of the enterprise system administrator defaults enables those | ||
administrators to configure many GCM settings using familiar MDM tooling, rather | ||
than having to modify the Git installation configuration files. | ||
|
||
### User Freedom | ||
|
||
We believe the user should _always_ be at liberty to configure | ||
Git and GCM exactly as they wish. By prefering environment variables and Git | ||
configuration files over system admin values, these only act as _default values_ | ||
that can always be overriden by the user in the usual ways. | ||
|
||
## Windows | ||
|
||
Default setting values come from the Windows Registry, specifically the | ||
following keys: | ||
|
||
**32-bit Windows** | ||
|
||
```text | ||
HKEY_LOCAL_MACHINE\SOFTWARE\GitCredentialManager\Configuration | ||
``` | ||
|
||
**64-bit Windows** | ||
|
||
```text | ||
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\GitCredentialManager\Configuration | ||
``` | ||
|
||
> GCM Core is a 32-bit executable on Windows. When running on a 64-bit | ||
installation of Windows registry access is transparently redirected to the | ||
`WOW6432Node` node. | ||
|
||
By using the Windows Registry, system administrators can use Group Policy to | ||
easily set defaults for GCM Core's settings. | ||
|
||
The names and possible values of all settings under this key are the same as | ||
those of the [Git configuration](configuration.md) settings. | ||
|
||
The type of each registry key can be either `REG_SZ` (string) or `REG_DWORD` | ||
(integer). | ||
|
||
|
||
## macOS/Linux | ||
|
||
Default configuration setting stores has not been implemented. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/shared/Microsoft.Git.CredentialManager/Interop/Windows/WindowsSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
namespace Microsoft.Git.CredentialManager.Interop.Windows | ||
{ | ||
/// <summary> | ||
/// Reads settings from Git configuration, environment variables, and defaults from the Windows Registry. | ||
/// </summary> | ||
public class WindowsSettings : Settings | ||
{ | ||
private readonly ITrace _trace; | ||
|
||
public WindowsSettings(IEnvironment environment, IGit git, ITrace trace) | ||
: base(environment, git) | ||
{ | ||
EnsureArgument.NotNull(trace, nameof(trace)); | ||
_trace = trace; | ||
|
||
PlatformUtils.EnsureWindows(); | ||
} | ||
|
||
protected override bool TryGetExternalDefault(string section, string property, out string value) | ||
{ | ||
value = null; | ||
|
||
#if NETFRAMEWORK | ||
// Check for machine (HKLM) registry keys that match the Git configuration name. | ||
// These can be set by system administrators via Group Policy, so make useful defaults. | ||
using (Win32.RegistryKey configKey = Win32.Registry.LocalMachine.OpenSubKey(Constants.WindowsRegistry.HKConfigurationPath)) | ||
{ | ||
if (configKey is null) | ||
{ | ||
// No configuration key exists | ||
return false; | ||
} | ||
|
||
string name = $"{section}.{property}"; | ||
object registryValue = configKey.GetValue(name); | ||
if (registryValue is null) | ||
{ | ||
// No property exists | ||
return false; | ||
} | ||
|
||
value = registryValue.ToString(); | ||
_trace.WriteLine($"Default setting found in registry: {name}={value}"); | ||
|
||
return true; | ||
} | ||
#else | ||
return base.TryGetExternalDefault(section, property, out value); | ||
#endif | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Xunit; | ||
|
||
namespace Microsoft.Git.CredentialManager.Tests | ||
{ | ||
public static class AssertEx | ||
{ | ||
/// <summary> | ||
/// Requires the fact or theory be marked with the <see cref="SkippableFactAttribute"/> | ||
/// or <see cref="SkippableTheoryAttribute"/>. | ||
/// </summary> | ||
/// <param name="reason">Reason the test has been skipped.</param> | ||
public static void Skip(string reason) | ||
{ | ||
Xunit.Skip.If(true, reason); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters