First off, I’m a Chef n00b, so any patience with Chef n00bery is much appreciated. Trying to get Chef Server and some Server 2012R2 machines going, and struggling mightily with our authenticated proxy.
I see the wget.ps1 file that’s created on-the-fly via knife-windows on our target VM, which is using System.Net.WebClient to make the web request to download the Chef agent. It looks like this is being generated from ~/.chefdk/gem/ruby/2.1.0/gems/knife-windows-1.4.1/lib/chef/knife/core/windows_bootstrap_context.rb. The Ruby code appears to be looking for the bootstrap_proxy command line parameter, and if set it’s passing that information along to the wget.ps1 script.
In our environment, however, we need more than that - I need to set some authenticated user settings. What’s the best way to do that?
What I’ve done, which appears to work fairly well, is modify the windows_bootstrap_context.rb file to add the proxy settings (hardcoded for now, but I could abstract them as well):
win_wget_ps = <<-WGET_PS
param(
[String] $remoteUrl,
[String] $localPath
)
$ProxyUrl = $env:http_proxy;
$webClient = new-object System.Net.WebClient;
if ($ProxyUrl -ne '') {
$WebProxy = New-Object System.Net.WebProxy($ProxyUrl,$true)
$WebClient.Proxy = $WebProxy
}
$WebClient.Proxy.Credentials = New-Object System.Net.NetworkCredential("username","password","domain")
$webClient.DownloadFile($remoteUrl, $localPath);
WGET_PS
Same thing goes for the knife client file, which also is created by the same windows_bootstrap_context.rb script - I’ve added some additional code to set the auth user proxy settings there too:
if knife_config[:bootstrap_proxy]
client_rb << "\n"
client_rb << %Q{http_proxy "#{knife_config[:bootstrap_proxy]}"\n}
client_rb << %Q{http_proxy_user 'username'\n}
client_rb << %Q{http_proxy_pass 'password'\n}
client_rb << %Q{https_proxy "#{knife_config[:bootstrap_proxy]}"\n}
client_rb << %Q{https_proxy_user 'username'\n}
client_rb << %Q{https_proxy_pass 'password'\n}
client_rb << %Q{no_proxy "#{knife_config[:bootstrap_no_proxy]}"\n} if knife_config[:bootstrap_no_proxy]
end
Any help would be very much appreciated.