Skip to content

Commit 7cea3d9

Browse files
florelisyao-msft
andauthored
Add support for proxies #190 (#4203)
For #190 See spec on #4152 See #1776 for a related PR for the feature with the core implementation for proxies in wininet This PR adds basic support for using proxies. Most of the changes are for enabling the configuration and blocking of the feature. This feature will be gated behind an experimental feature setting * Added Group Policy and Admin settings for enabling/disabling the use of proxy CLI arguments and for setting a default proxy. + Pending: Internal review for new Group Policy + Extended `AdminSettings` to support settings with string values, instead of only bool flags. The implementation is mostly a copy of the bool case. In the future we should look back at it to reduce duplication of code. + Added a `set` subcommand to `settings` that can set the admin settings * Added CLI arguments to select a proxy on each different invocation of winget, or to disable the use of a default one. * Updated calls to wininet and cpprestsdk to use the provided proxy, and added plumbing to get the arguments from the command line to the point of use. * Changed the flow around downloads to force winget to use proxies if available. Manually tested on a VM using mitmproxy Pending: Adding automated tests tests. Co-authored-by: yao-msft <[email protected]>
1 parent 8a00654 commit 7cea3d9

File tree

79 files changed

+999
-220
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+999
-220
lines changed

doc/Settings.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,3 +312,14 @@ You can enable the feature as shown below.
312312
"configuration03": true
313313
},
314314
```
315+
316+
### proxy
317+
318+
This feature enables the use of web proxies.
319+
You can enable the feature as shown below.
320+
321+
```json
322+
"experimentalFeatures": {
323+
"proxy": true
324+
},
325+
```

doc/admx/DesktopAppInstaller.admx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,22 @@
166166
<decimal value="0" />
167167
</disabledValue>
168168
</policy>
169+
<policy name="EnableWindowsPackageManagerProxyCommandLineOptions" class="Machine" displayName="$(string.EnableWindowsPackageManagerProxyCommandLineOptions)" explainText="$(string.EnableWindowsPackageManagerProxyCommandLineOptionsExplanation)" key="Software\Policies\Microsoft\Windows\AppInstaller" valueName="EnableWindowsPackageManagerProxyCommandLineOptions">
170+
<parentCategory ref="AppInstaller" />
171+
<supportedOn ref="windows:SUPPORTED_Windows_10_0_RS5" />
172+
<enabledValue>
173+
<decimal value="1" />
174+
</enabledValue>
175+
<disabledValue>
176+
<decimal value="0" />
177+
</disabledValue>
178+
</policy>
179+
<policy name="WindowsPackageManagerDefaultProxy" class="Machine" displayName="$(string.WindowsPackageManagerDefaultProxy)" explainText="$(string.WindowsPackageManagerDefaultProxyExplanation)" presentation="$(presentation.WindowsPackageManagerDefaultProxy)" key="Software\Policies\Microsoft\Windows\AppInstaller">
180+
<parentCategory ref="AppInstaller" />
181+
<supportedOn ref="windows:SUPPORTED_Windows_10_0_RS5" />
182+
<elements>
183+
<text id="WindowsPackageManagerDefaultProxy" valueName="DefaultProxy" />
184+
</elements>
185+
</policy>
169186
</policies>
170187
</policyDefinitions>

doc/admx/en-US/DesktopAppInstaller.adml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ If you disable or do not configure this setting, users will not be able to insta
100100

101101
If you disable this policy, users will not be able execute the Windows Package Manager CLI, and PowerShell cmdlets.
102102

103-
If you enable, or do not configuring this policy, users will be able to execute the Windows Package Manager CLI commands, and PowerShell cmdlets. (Provided “Enable App Installer” policy is not disabled).
103+
If you enable, or do not configure this policy, users will be able to execute the Windows Package Manager CLI commands, and PowerShell cmdlets. (Provided “Enable App Installer” policy is not disabled).
104104

105105
This policy does not override the “Enable App Installer” policy.</string>
106106
<string id="EnableWindowsPackageManagerConfiguration">Enable Windows Package Manager Configuration</string>
@@ -109,6 +109,19 @@ If you disable or do not configure this setting, users will not be able to insta
109109
If you enable or do not configure this setting, users will be able to use the Windows Package Manager configuration feature.
110110

111111
If you disable this setting, users will not be able to use the Windows Package Manager configuration feature.</string>
112+
<string id="EnableWindowsPackageManagerProxyCommandLineOptions">Enable Windows Package Manager Proxy command line options</string>
113+
<string id="EnableWindowsPackageManagerProxyCommandLineOptionsExplanation">
114+
This policy controls whether the Windows Package Manager usage of proxy can be configured by users through the command line.
115+
116+
If you enable this setting, users will be able to configure the Windows Package Manager's use of proxy through the command line.
117+
118+
If you disable or do not configure this setting, users will not be able to to configure the Windows Package Manager's use of proxy through the command line.</string>
119+
<string id="WindowsPackageManagerDefaultProxy">Set Windows Package Manager Default Proxy</string>
120+
<string id="WindowsPackageManagerDefaultProxyExplanation">This policy controls the default proxy used by the Windows Package Manager.
121+
122+
If you disable or do not configure this setting, no proxy will be used by default.
123+
124+
If you enable this setting, the specified proxy will be used by default.</string>
112125
</stringTable>
113126
<presentationTable>
114127
<presentation id="SourceAutoUpdateInterval">
@@ -120,6 +133,11 @@ If you disable this setting, users will not be able to use the Windows Package M
120133
<presentation id="AllowedSources">
121134
<listBox refId="AllowedSources" required="false">Allowed Sources: </listBox>
122135
</presentation>
136+
<presentation id="WindowsPackageManagerDefaultProxy">
137+
<textBox refId="WindowsPackageManagerDefaultProxy">
138+
<label>Default Proxy</label>
139+
</textBox>
140+
</presentation>
123141
</presentationTable>
124142
</resources>
125143
</policyDefinitionResources>

schemas/JSON/settings/settings.export.schema.0.1.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,26 @@
1616
"description": "Enable installing local manifests.",
1717
"type": "boolean",
1818
"default": false
19+
},
20+
"InstallerHashOverride": {
21+
"description": "Enable overriding installer hash validation.",
22+
"type": "boolean",
23+
"default": false
24+
},
25+
"LocalArchiveMalwareScanOverride": {
26+
"description": "Enable overriding malware scan for local archives.",
27+
"type": "boolean",
28+
"default": false
29+
},
30+
"ProxyCommandLineOptions": {
31+
"description": "Enable using command line options for proxy.",
32+
"type": "boolean",
33+
"default": false
34+
},
35+
"DefaultProxy": {
36+
"description": "Default proxy.",
37+
"type": "string"
1938
}
20-
}
2139
},
2240
"UserSettingsFile": {
2341
"description": "Path for the winget's user settings file.",

schemas/JSON/settings/settings.schema.0.2.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,13 @@
266266
"type": "boolean",
267267
"default": false
268268
},
269-
"configuration": {
270-
"description": "Enable support for configuration",
269+
"configuration03": {
270+
"description": "Enable support for configuration schema 0.3",
271+
"type": "boolean",
272+
"default": false
273+
},
274+
"proxy": {
275+
"description": "Enable support for proxies",
271276
"type": "boolean",
272277
"default": false
273278
}

src/AppInstallerCLICore/Argument.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ namespace AppInstaller::CLI
151151
return { type, "enable"_liv, ArgTypeCategory::None, ArgTypeExclusiveSet::EnableDisable };
152152
case Execution::Args::Type::AdminSettingDisable:
153153
return { type, "disable"_liv, ArgTypeCategory::None, ArgTypeExclusiveSet::EnableDisable };
154+
case Execution::Args::Type::SettingName:
155+
return { type, "setting"_liv };
156+
case Execution::Args::Type::SettingValue:
157+
return { type, "value"_liv };
154158

155159
// Upgrade command
156160
case Execution::Args::Type::All:
@@ -233,6 +237,11 @@ namespace AppInstaller::CLI
233237
case Execution::Args::Type::AcceptSourceAgreements:
234238
return { type, "accept-source-agreements"_liv, ArgTypeCategory::ExtendedSource };
235239

240+
case Execution::Args::Type::Proxy:
241+
return { type, "proxy"_liv, ArgTypeCategory::CopyValueToSubContext, ArgTypeExclusiveSet::Proxy };
242+
case Execution::Args::Type::NoProxy:
243+
return { type, "no-proxy"_liv, ArgTypeCategory::CopyFlagToSubContext, ArgTypeExclusiveSet::Proxy };
244+
236245
case Execution::Args::Type::ToolVersion:
237246
return { type, "version"_liv, 'v' };
238247

@@ -268,7 +277,7 @@ namespace AppInstaller::CLI
268277
case Args::Type::MultiQuery:
269278
return Argument{ type, Resource::String::MultiQueryArgumentDescription, ArgumentType::Positional }.SetCountLimit(128);
270279
case Args::Type::Manifest:
271-
return Argument{ type, Resource::String::ManifestArgumentDescription, ArgumentType::Standard, Argument::Visibility::Help, Settings::TogglePolicy::Policy::LocalManifestFiles, Settings::AdminSetting::LocalManifestFiles };
280+
return Argument{ type, Resource::String::ManifestArgumentDescription, ArgumentType::Standard, Argument::Visibility::Help, Settings::TogglePolicy::Policy::LocalManifestFiles, Settings::BoolAdminSetting::LocalManifestFiles };
272281
case Args::Type::Id:
273282
return Argument{ type, Resource::String::IdArgumentDescription, ArgumentType::Standard, Argument::Visibility::Help };
274283
case Args::Type::Name:
@@ -308,7 +317,7 @@ namespace AppInstaller::CLI
308317
case Args::Type::InstallLocation:
309318
return Argument{ type, Resource::String::LocationArgumentDescription, ArgumentType::Standard };
310319
case Args::Type::HashOverride:
311-
return Argument{ type, Resource::String::HashOverrideArgumentDescription, ArgumentType::Flag, Settings::TogglePolicy::Policy::HashOverride, Settings::AdminSetting::InstallerHashOverride };
320+
return Argument{ type, Resource::String::HashOverrideArgumentDescription, ArgumentType::Flag, Settings::TogglePolicy::Policy::HashOverride, Settings::BoolAdminSetting::InstallerHashOverride };
312321
case Args::Type::AcceptPackageAgreements:
313322
return Argument{ type, Resource::String::AcceptPackageAgreementsArgumentDescription, ArgumentType::Flag };
314323
case Args::Type::NoUpgrade:
@@ -324,7 +333,7 @@ namespace AppInstaller::CLI
324333
case Args::Type::SkipDependencies:
325334
return Argument{ type, Resource::String::SkipDependenciesArgumentDescription, ArgumentType::Flag, false };
326335
case Args::Type::IgnoreLocalArchiveMalwareScan:
327-
return Argument{ type, Resource::String::IgnoreLocalArchiveMalwareScanArgumentDescription, ArgumentType::Flag, Settings::TogglePolicy::Policy::LocalArchiveMalwareScanOverride, Settings::AdminSetting::LocalArchiveMalwareScanOverride };
336+
return Argument{ type, Resource::String::IgnoreLocalArchiveMalwareScanArgumentDescription, ArgumentType::Flag, Settings::TogglePolicy::Policy::LocalArchiveMalwareScanOverride, Settings::BoolAdminSetting::LocalArchiveMalwareScanOverride };
328337
case Args::Type::SourceName:
329338
return Argument{ type, Resource::String::SourceNameArgumentDescription, ArgumentType::Positional, false };
330339
case Args::Type::SourceArg:
@@ -379,6 +388,10 @@ namespace AppInstaller::CLI
379388
return Argument{ type, Resource::String::AllowRebootArgumentDescription, ArgumentType::Flag };
380389
case Args::Type::IgnoreResumeLimit:
381390
return Argument{ type, Resource::String::IgnoreResumeLimitArgumentDescription, ArgumentType::Flag, ExperimentalFeature::Feature::Resume };
391+
case Args::Type::Proxy:
392+
return Argument{ type, Resource::String::ProxyArgumentDescription, ArgumentType::Standard, ExperimentalFeature::Feature::Proxy, TogglePolicy::Policy::ProxyCommandLineOptions, BoolAdminSetting::ProxyCommandLineOptions };
393+
case Args::Type::NoProxy:
394+
return Argument{ type, Resource::String::NoProxyArgumentDescription, ArgumentType::Flag, ExperimentalFeature::Feature::Proxy, TogglePolicy::Policy::ProxyCommandLineOptions, BoolAdminSetting::ProxyCommandLineOptions };
382395
default:
383396
THROW_HR(E_UNEXPECTED);
384397
}
@@ -394,6 +407,8 @@ namespace AppInstaller::CLI
394407
args.push_back(ForType(Args::Type::RetroStyle));
395408
args.push_back(ForType(Args::Type::VerboseLogs));
396409
args.emplace_back(Args::Type::DisableInteractivity, Resource::String::DisableInteractivityArgumentDescription, ArgumentType::Flag, false);
410+
args.push_back(ForType(Args::Type::Proxy));
411+
args.push_back(ForType(Args::Type::NoProxy));
397412
}
398413

399414
std::string Argument::GetUsageString() const

src/AppInstallerCLICore/Argument.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ namespace AppInstaller::CLI
8585
PurgePreserve = 0x4,
8686
PinType = 0x8,
8787
StubType = 0x10,
88+
Proxy = 0x20,
8889

8990
// This must always be at the end
9091
Max
@@ -211,7 +212,7 @@ namespace AppInstaller::CLI
211212
Argument::Visibility GetVisibility() const;
212213
Settings::ExperimentalFeature::Feature Feature() const { return m_feature; }
213214
Settings::TogglePolicy::Policy GroupPolicy() const { return m_groupPolicy; }
214-
Settings::AdminSetting AdminSetting() const { return m_adminSetting; }
215+
Settings::BoolAdminSetting AdminSetting() const { return m_adminSetting; }
215216

216217
Argument& SetRequired(bool required) { m_required = required; return *this; }
217218
Argument& SetCountLimit(size_t countLimit) { m_countLimit = countLimit; return *this; }
@@ -237,12 +238,15 @@ namespace AppInstaller::CLI
237238
Argument(Execution::Args::Type execArgType, Resource::StringId desc, ArgumentType type, Argument::Visibility visibility, bool required, Settings::ExperimentalFeature::Feature feature) :
238239
m_argCommon(ArgumentCommon::ForType(execArgType)), m_desc(std::move(desc)), m_type(type), m_visibility(visibility), m_required(required), m_feature(feature) {}
239240

240-
Argument(Execution::Args::Type execArgType, Resource::StringId desc, ArgumentType type, Settings::TogglePolicy::Policy groupPolicy, Settings::AdminSetting adminSetting) :
241+
Argument(Execution::Args::Type execArgType, Resource::StringId desc, ArgumentType type, Settings::TogglePolicy::Policy groupPolicy, Settings::BoolAdminSetting adminSetting) :
241242
m_argCommon(ArgumentCommon::ForType(execArgType)), m_desc(std::move(desc)), m_type(type), m_groupPolicy(groupPolicy), m_adminSetting(adminSetting) {}
242243

243-
Argument(Execution::Args::Type execArgType, Resource::StringId desc, ArgumentType type, Argument::Visibility visibility, Settings::TogglePolicy::Policy groupPolicy, Settings::AdminSetting adminSetting) :
244+
Argument(Execution::Args::Type execArgType, Resource::StringId desc, ArgumentType type, Argument::Visibility visibility, Settings::TogglePolicy::Policy groupPolicy, Settings::BoolAdminSetting adminSetting) :
244245
m_argCommon(ArgumentCommon::ForType(execArgType)), m_desc(std::move(desc)), m_type(type), m_visibility(visibility), m_groupPolicy(groupPolicy), m_adminSetting(adminSetting) {}
245246

247+
Argument(Execution::Args::Type execArgType, Resource::StringId desc, ArgumentType type, Settings::ExperimentalFeature::Feature feature, Settings::TogglePolicy::Policy groupPolicy, Settings::BoolAdminSetting adminSetting) :
248+
m_argCommon(ArgumentCommon::ForType(execArgType)), m_desc(std::move(desc)), m_type(type), m_feature(feature), m_groupPolicy(groupPolicy), m_adminSetting(adminSetting) {}
249+
246250
ArgumentCommon m_argCommon;
247251
Resource::StringId m_desc;
248252
bool m_required = false;
@@ -251,6 +255,6 @@ namespace AppInstaller::CLI
251255
size_t m_countLimit = 1;
252256
Settings::ExperimentalFeature::Feature m_feature = Settings::ExperimentalFeature::Feature::None;
253257
Settings::TogglePolicy::Policy m_groupPolicy = Settings::TogglePolicy::Policy::None;
254-
Settings::AdminSetting m_adminSetting = Settings::AdminSetting::Unknown;
258+
Settings::BoolAdminSetting m_adminSetting = Settings::BoolAdminSetting::Unknown;
255259
};
256260
}

src/AppInstallerCLICore/Command.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ namespace AppInstaller::CLI
637637
throw GroupPolicyException(arg.GroupPolicy());
638638
}
639639

640-
if (arg.AdminSetting() != AdminSetting::Unknown && !Settings::IsAdminSettingEnabled(arg.AdminSetting()) && execArgs.Contains(arg.ExecArgType()))
640+
if (arg.AdminSetting() != BoolAdminSetting::Unknown && !Settings::IsAdminSettingEnabled(arg.AdminSetting()) && execArgs.Contains(arg.ExecArgType()))
641641
{
642642
auto setting = Settings::AdminSettingToString(arg.AdminSetting());
643643
AICLI_LOG(CLI, Error, << "Trying to use argument: " << arg.Name() << " disabled by admin setting " << setting);

src/AppInstallerCLICore/Commands/DownloadCommand.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ namespace AppInstaller::CLI
3636
Argument::ForType(Args::Type::CustomHeader),
3737
Argument::ForType(Args::Type::AuthenticationMode),
3838
Argument::ForType(Args::Type::AuthenticationAccount),
39-
Argument::ForType(Execution::Args::Type::AcceptPackageAgreements),
40-
Argument::ForType(Execution::Args::Type::AcceptSourceAgreements),
39+
Argument::ForType(Args::Type::AcceptPackageAgreements),
40+
Argument::ForType(Args::Type::AcceptSourceAgreements),
4141
};
4242
}
4343

src/AppInstallerCLICore/Commands/RootCommand.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,21 @@ namespace AppInstaller::CLI
124124
Execution::TableOutput<2> adminSettingsTable{ context.Reporter, { Resource::String::AdminSettingHeader, Resource::String::StateHeader } };
125125

126126
// Output the admin settings.
127-
for (const auto& setting : Settings::GetAllAdminSettings())
127+
for (const auto& setting : Settings::GetAllBoolAdminSettings())
128128
{
129129
adminSettingsTable.OutputLine({
130130
std::string{ AdminSettingToString(setting)},
131131
Resource::LocString{ IsAdminSettingEnabled(setting) ? Resource::String::StateEnabled : Resource::String::StateDisabled }
132132
});
133133
}
134+
for (const auto& setting : Settings::GetAllStringAdminSettings())
135+
{
136+
auto settingValue = GetAdminSetting(setting);
137+
adminSettingsTable.OutputLine({
138+
std::string{ AdminSettingToString(setting)},
139+
settingValue ? Utility::LocIndString{ settingValue.value() } : Resource::LocString{ Resource::String::StateDisabled }
140+
});
141+
}
134142
adminSettingsTable.Complete();
135143
}
136144

0 commit comments

Comments
 (0)