mirror of
https://github.com/GoogleContainerTools/kaniko
synced 2026-10-19 05:46:49 +02:00
Bump deps (#1885)
``` * use go 1.17 semantics in go.mod * pin tonistiigi/fsutil dep to match docker/docker's dep go get -u ./... go mod vendor ```
This commit is contained in:
+4
-2
@@ -1,8 +1,10 @@
|
||||
# ieproxy
|
||||
|
||||
Go package to detect the proxy settings on Windows platform.
|
||||
Go package to detect the proxy settings on Windows platform, and MacOS.
|
||||
|
||||
The settings are initially attempted to be read from the [`WinHttpGetIEProxyConfigForCurrentUser` DLL call](https://docs.microsoft.com/en-us/windows/desktop/api/winhttp/nf-winhttp-winhttpgetieproxyconfigforcurrentuser), but falls back to the registry (`CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings`) in the event the DLL call fails.
|
||||
On Windows, the settings are initially attempted to be read from the [`WinHttpGetIEProxyConfigForCurrentUser` DLL call](https://docs.microsoft.com/en-us/windows/desktop/api/winhttp/nf-winhttp-winhttpgetieproxyconfigforcurrentuser), but falls back to the registry (`CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings`) in the event the DLL call fails.
|
||||
|
||||
On MacOS, the settings are read from [`CFNetworkCopySystemProxySettings` method of CFNetwork](https://developer.apple.com/documentation/cfnetwork/1426754-cfnetworkcopysystemproxysettings?language=objc).
|
||||
|
||||
For more information, take a look at the [documentation](https://godoc.org/github.com/mattn/go-ieproxy)
|
||||
|
||||
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
module github.com/mattn/go-ieproxy
|
||||
|
||||
go 1.14
|
||||
|
||||
require (
|
||||
golang.org/x/net v0.0.0-20191112182307-2180aed22343
|
||||
golang.org/x/sys v0.0.0-20191112214154-59a1497f0cea
|
||||
golang.org/x/text v0.3.2 // indirect
|
||||
)
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/net v0.0.0-20191112182307-2180aed22343 h1:00ohfJ4K98s3m6BGUoBd8nyfp4Yl0GoIKvw5abItTjI=
|
||||
golang.org/x/net v0.0.0-20191112182307-2180aed22343/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20191112214154-59a1497f0cea h1:Mz1TMnfJDRJLk8S8OPCoJYgrsp/Se/2TBre2+vwX128=
|
||||
golang.org/x/sys v0.0.0-20191112214154-59a1497f0cea/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
+5
@@ -36,6 +36,11 @@ func GetConf() ProxyConf {
|
||||
return getConf()
|
||||
}
|
||||
|
||||
// ReloadConf reloads the proxy configuration
|
||||
func ReloadConf() ProxyConf {
|
||||
return reloadConf()
|
||||
}
|
||||
|
||||
// OverrideEnvWithStaticProxy writes new values to the
|
||||
// `http_proxy`, `https_proxy` and `no_proxy` environment variables.
|
||||
// The values are taken from the Windows Regedit (should be called in `init()` function - see example)
|
||||
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
package ieproxy
|
||||
|
||||
/*
|
||||
#cgo LDFLAGS: -framework CoreFoundation
|
||||
#cgo LDFLAGS: -framework CFNetwork
|
||||
#include <strings.h>
|
||||
#include <CFNetwork/CFProxySupport.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var once sync.Once
|
||||
var darwinProxyConf ProxyConf
|
||||
|
||||
// GetConf retrieves the proxy configuration from the Windows Regedit
|
||||
func getConf() ProxyConf {
|
||||
once.Do(writeConf)
|
||||
return darwinProxyConf
|
||||
}
|
||||
|
||||
func cfStringGetGoString(cfStr C.CFStringRef) string {
|
||||
retCString := (*C.char)(C.calloc(C.ulong(uint(128)), 1))
|
||||
defer C.free(unsafe.Pointer(retCString))
|
||||
|
||||
C.CFStringGetCString(cfStr, retCString, C.long(128), C.kCFStringEncodingUTF8)
|
||||
return C.GoString(retCString)
|
||||
}
|
||||
|
||||
func cfNumberGetGoInt(cfNum C.CFNumberRef) int {
|
||||
ret := 0
|
||||
C.CFNumberGetValue(cfNum, C.kCFNumberIntType, unsafe.Pointer(&ret))
|
||||
return ret
|
||||
}
|
||||
|
||||
func cfArrayGetGoStrings(cfArray C.CFArrayRef) []string {
|
||||
var ret []string
|
||||
for i := 0; i < int(C.CFArrayGetCount(cfArray)); i++ {
|
||||
cfStr := C.CFStringRef(C.CFArrayGetValueAtIndex(cfArray, C.long(i)))
|
||||
if unsafe.Pointer(cfStr) != C.NULL {
|
||||
ret = append(ret, cfStringGetGoString(cfStr))
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func writeConf() {
|
||||
cfDictProxy := C.CFDictionaryRef(C.CFNetworkCopySystemProxySettings())
|
||||
defer C.CFRelease(C.CFTypeRef(cfDictProxy))
|
||||
|
||||
cfNumHttpEnable := C.CFNumberRef(C.CFDictionaryGetValue(cfDictProxy, unsafe.Pointer(C.kCFNetworkProxiesHTTPEnable)))
|
||||
if unsafe.Pointer(cfNumHttpEnable) != C.NULL && cfNumberGetGoInt(cfNumHttpEnable) > 0 {
|
||||
darwinProxyConf.Static.Active = true
|
||||
if darwinProxyConf.Static.Protocols == nil {
|
||||
darwinProxyConf.Static.Protocols = make(map[string]string)
|
||||
}
|
||||
httpHost := C.CFStringRef(C.CFDictionaryGetValue(cfDictProxy, unsafe.Pointer(C.kCFNetworkProxiesHTTPProxy)))
|
||||
httpPort := C.CFNumberRef(C.CFDictionaryGetValue(cfDictProxy, unsafe.Pointer(C.kCFNetworkProxiesHTTPPort)))
|
||||
|
||||
httpProxy := fmt.Sprintf("%s:%d", cfStringGetGoString(httpHost), cfNumberGetGoInt(httpPort))
|
||||
darwinProxyConf.Static.Protocols["http"] = httpProxy
|
||||
}
|
||||
|
||||
cfNumHttpsEnable := C.CFNumberRef(C.CFDictionaryGetValue(cfDictProxy, unsafe.Pointer(C.kCFNetworkProxiesHTTPSEnable)))
|
||||
if unsafe.Pointer(cfNumHttpEnable) != C.NULL && cfNumberGetGoInt(cfNumHttpsEnable) > 0 {
|
||||
darwinProxyConf.Static.Active = true
|
||||
if darwinProxyConf.Static.Protocols == nil {
|
||||
darwinProxyConf.Static.Protocols = make(map[string]string)
|
||||
}
|
||||
httpsHost := C.CFStringRef(C.CFDictionaryGetValue(cfDictProxy, unsafe.Pointer(C.kCFNetworkProxiesHTTPSProxy)))
|
||||
httpsPort := C.CFNumberRef(C.CFDictionaryGetValue(cfDictProxy, unsafe.Pointer(C.kCFNetworkProxiesHTTPSPort)))
|
||||
|
||||
httpProxy := fmt.Sprintf("%s:%d", cfStringGetGoString(httpsHost), cfNumberGetGoInt(httpsPort))
|
||||
darwinProxyConf.Static.Protocols["https"] = httpProxy
|
||||
}
|
||||
|
||||
if darwinProxyConf.Static.Active {
|
||||
cfArrayExceptionList := C.CFArrayRef(C.CFDictionaryGetValue(cfDictProxy, unsafe.Pointer(C.kCFNetworkProxiesExceptionsList)))
|
||||
if unsafe.Pointer(cfArrayExceptionList) != C.NULL {
|
||||
exceptionList := cfArrayGetGoStrings(cfArrayExceptionList)
|
||||
darwinProxyConf.Static.NoProxy = strings.Join(exceptionList, ",")
|
||||
}
|
||||
}
|
||||
|
||||
cfNumPacEnable := C.CFNumberRef(C.CFDictionaryGetValue(cfDictProxy, unsafe.Pointer(C.kCFNetworkProxiesProxyAutoConfigEnable)))
|
||||
if unsafe.Pointer(cfNumPacEnable) != C.NULL && cfNumberGetGoInt(cfNumPacEnable) > 0 {
|
||||
cfStringPac := C.CFStringRef(C.CFDictionaryGetValue(cfDictProxy, unsafe.Pointer(C.kCFNetworkProxiesProxyAutoConfigURLString)))
|
||||
if unsafe.Pointer(cfStringPac) != C.NULL {
|
||||
pac := cfStringGetGoString(cfStringPac)
|
||||
darwinProxyConf.Automatic.PreConfiguredURL = pac
|
||||
darwinProxyConf.Automatic.Active = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// OverrideEnvWithStaticProxy writes new values to the
|
||||
// http_proxy, https_proxy and no_proxy environment variables.
|
||||
// The values are taken from the MacOS System Preferences.
|
||||
func overrideEnvWithStaticProxy(conf ProxyConf, setenv envSetter) {
|
||||
if conf.Static.Active {
|
||||
for _, scheme := range []string{"http", "https"} {
|
||||
url := conf.Static.Protocols[scheme]
|
||||
if url != "" {
|
||||
setenv(scheme+"_proxy", url)
|
||||
}
|
||||
}
|
||||
if conf.Static.NoProxy != "" {
|
||||
setenv("no_proxy", conf.Static.NoProxy)
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-1
@@ -1,4 +1,4 @@
|
||||
// +build !windows
|
||||
// +build !windows,!darwin
|
||||
|
||||
package ieproxy
|
||||
|
||||
@@ -6,5 +6,9 @@ func getConf() ProxyConf {
|
||||
return ProxyConf{}
|
||||
}
|
||||
|
||||
func reloadConf() ProxyConf {
|
||||
return getConf()
|
||||
}
|
||||
|
||||
func overrideEnvWithStaticProxy(pc ProxyConf, setenv envSetter) {
|
||||
}
|
||||
|
||||
+7
-1
@@ -24,6 +24,12 @@ func getConf() ProxyConf {
|
||||
return windowsProxyConf
|
||||
}
|
||||
|
||||
// reloadConf forces a reload of the proxy configuration from the Windows registry
|
||||
func reloadConf() ProxyConf {
|
||||
writeConf()
|
||||
return getConf()
|
||||
}
|
||||
|
||||
func writeConf() {
|
||||
proxy := ""
|
||||
proxyByPass := ""
|
||||
@@ -42,7 +48,7 @@ func writeConf() {
|
||||
autoDetect = ieCfg.fAutoDetect
|
||||
}
|
||||
|
||||
if proxy == "" && !autoDetect{
|
||||
if proxy == "" && !autoDetect {
|
||||
// Try WinHTTP default proxy.
|
||||
if defaultCfg, err := getDefaultProxyConfiguration(); err == nil {
|
||||
defer globalFreeWrapper(defaultCfg.lpszProxy)
|
||||
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
package ieproxy
|
||||
|
||||
/*
|
||||
#cgo LDFLAGS: -framework CoreFoundation
|
||||
#cgo LDFLAGS: -framework CFNetwork
|
||||
#include <strings.h>
|
||||
#include <CFNetwork/CFProxySupport.h>
|
||||
|
||||
#define STR_LEN 128
|
||||
|
||||
void proxyAutoConfCallback(void* client, CFArrayRef proxies, CFErrorRef error) {
|
||||
CFTypeRef* result_ptr = (CFTypeRef*)client;
|
||||
if (error != NULL) {
|
||||
*result_ptr = CFRetain(error);
|
||||
} else {
|
||||
*result_ptr = CFRetain(proxies);
|
||||
}
|
||||
CFRunLoopStop(CFRunLoopGetCurrent());
|
||||
}
|
||||
|
||||
int intCFNumber(CFNumberRef num) {
|
||||
int ret;
|
||||
CFNumberGetValue(num, kCFNumberIntType, &ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
char* _getProxyUrlFromPac(char* pac, char* reqCs) {
|
||||
char* retCString = (char*)calloc(STR_LEN, sizeof(char));
|
||||
|
||||
CFStringRef reqStr = CFStringCreateWithCString(NULL, reqCs, kCFStringEncodingUTF8);
|
||||
CFStringRef pacStr = CFStringCreateWithCString(NULL, pac, kCFStringEncodingUTF8);
|
||||
CFURLRef pacUrl = CFURLCreateWithString(NULL, pacStr, NULL);
|
||||
CFURLRef reqUrl = CFURLCreateWithString(NULL, reqStr, NULL);
|
||||
|
||||
CFTypeRef result = NULL;
|
||||
CFStreamClientContext context = { 0, &result, NULL, NULL, NULL };
|
||||
CFRunLoopSourceRef runloop_src = CFNetworkExecuteProxyAutoConfigurationURL(pacUrl, reqUrl, proxyAutoConfCallback, &context);
|
||||
|
||||
if (runloop_src) {
|
||||
const CFStringRef private_runloop_mode = CFSTR("go-ieproxy");
|
||||
CFRunLoopAddSource(CFRunLoopGetCurrent(), runloop_src, private_runloop_mode);
|
||||
CFRunLoopRunInMode(private_runloop_mode, DBL_MAX, false);
|
||||
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), runloop_src, kCFRunLoopCommonModes);
|
||||
|
||||
if (CFGetTypeID(result) == CFArrayGetTypeID()) {
|
||||
CFArrayRef resultArray = (CFTypeRef)result;
|
||||
if (CFArrayGetCount(resultArray) > 0) {
|
||||
CFDictionaryRef pxy = (CFDictionaryRef)CFArrayGetValueAtIndex(resultArray, 0);
|
||||
CFStringRef pxyType = CFDictionaryGetValue(pxy, kCFProxyTypeKey);
|
||||
|
||||
if (CFEqual(pxyType, kCFProxyTypeNone)) {
|
||||
// noop
|
||||
}
|
||||
|
||||
if (CFEqual(pxyType, kCFProxyTypeHTTP)) {
|
||||
CFStringRef host = (CFStringRef)CFDictionaryGetValue(pxy, kCFProxyHostNameKey);
|
||||
CFNumberRef port = (CFNumberRef)CFDictionaryGetValue(pxy, kCFProxyPortNumberKey);
|
||||
|
||||
char host_str[STR_LEN - 16];
|
||||
CFStringGetCString(host, host_str, STR_LEN - 16, kCFStringEncodingUTF8);
|
||||
|
||||
int port_int = 80;
|
||||
if (port) {
|
||||
CFNumberGetValue(port, kCFNumberIntType, &port_int);
|
||||
}
|
||||
|
||||
sprintf(retCString, "%s:%d", host_str, port_int);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// error
|
||||
}
|
||||
}
|
||||
|
||||
CFRelease(result);
|
||||
CFRelease(reqStr);
|
||||
CFRelease(reqUrl);
|
||||
CFRelease(pacStr);
|
||||
CFRelease(pacUrl);
|
||||
return retCString;
|
||||
}
|
||||
|
||||
char* _getPacUrl() {
|
||||
char* retCString = (char*)calloc(STR_LEN, sizeof(char));
|
||||
CFDictionaryRef proxyDict = CFNetworkCopySystemProxySettings();
|
||||
CFNumberRef pacEnable = (CFNumberRef)CFDictionaryGetValue(proxyDict, kCFNetworkProxiesProxyAutoConfigEnable);
|
||||
|
||||
if (pacEnable && intCFNumber(pacEnable)) {
|
||||
CFStringRef pacUrlStr = (CFStringRef)CFDictionaryGetValue(proxyDict, kCFNetworkProxiesProxyAutoConfigURLString);
|
||||
if (pacUrlStr) {
|
||||
CFStringGetCString(pacUrlStr, retCString, STR_LEN, kCFStringEncodingUTF8);
|
||||
}
|
||||
}
|
||||
|
||||
CFRelease(proxyDict);
|
||||
return retCString;
|
||||
}
|
||||
|
||||
*/
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
func (psc *ProxyScriptConf) findProxyForURL(URL string) string {
|
||||
if !psc.Active {
|
||||
return ""
|
||||
}
|
||||
proxy := getProxyForURL(psc.PreConfiguredURL, URL)
|
||||
return proxy
|
||||
}
|
||||
|
||||
func getProxyForURL(pacFileURL, url string) string {
|
||||
if pacFileURL == "" {
|
||||
pacFileURL = getPacUrl()
|
||||
}
|
||||
if pacFileURL == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
csUrl := C.CString(url)
|
||||
csPac := C.CString(pacFileURL)
|
||||
csRet := C._getProxyUrlFromPac(csPac, csUrl)
|
||||
|
||||
defer C.free(unsafe.Pointer(csUrl))
|
||||
defer C.free(unsafe.Pointer(csPac))
|
||||
defer C.free(unsafe.Pointer(csRet))
|
||||
|
||||
return C.GoString(csRet)
|
||||
}
|
||||
|
||||
func getPacUrl() string {
|
||||
csRet := C._getPacUrl()
|
||||
|
||||
defer C.free(unsafe.Pointer(csRet))
|
||||
return C.GoString(csRet)
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// +build !windows
|
||||
// +build !windows,!darwin
|
||||
|
||||
package ieproxy
|
||||
|
||||
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package ieproxy
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"golang.org/x/net/http/httpproxy"
|
||||
)
|
||||
|
||||
func proxyMiddleman() func(req *http.Request) (i *url.URL, e error) {
|
||||
// Get the proxy configuration
|
||||
conf := GetConf()
|
||||
envCfg := httpproxy.FromEnvironment()
|
||||
|
||||
if envCfg.HTTPProxy != "" || envCfg.HTTPSProxy != "" {
|
||||
// If the user manually specifies environment variables, prefer those over the MacOS config.
|
||||
return http.ProxyFromEnvironment
|
||||
}
|
||||
|
||||
return func(req *http.Request) (i *url.URL, e error) {
|
||||
if conf.Automatic.Active {
|
||||
host := conf.Automatic.FindProxyForURL(req.URL.String())
|
||||
if host != "" {
|
||||
return &url.URL{Host: host}, nil
|
||||
}
|
||||
}
|
||||
if conf.Static.Active {
|
||||
return staticProxy(conf, req)
|
||||
}
|
||||
// Should return no proxy; fallthrough.
|
||||
return http.ProxyFromEnvironment(req)
|
||||
}
|
||||
}
|
||||
|
||||
func staticProxy(conf ProxyConf, req *http.Request) (i *url.URL, e error) {
|
||||
// If static proxy obtaining is specified
|
||||
proxy := httpproxy.Config{
|
||||
HTTPSProxy: conf.Static.Protocols["https"],
|
||||
HTTPProxy: conf.Static.Protocols["http"],
|
||||
NoProxy: conf.Static.NoProxy,
|
||||
}
|
||||
return proxy.ProxyFunc()(req.URL)
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// +build !windows
|
||||
// +build !windows,!darwin
|
||||
|
||||
package ieproxy
|
||||
|
||||
|
||||
Reference in New Issue
Block a user