Skip to content

Commit 0629c08

Browse files
GiteaBotwolfogre
andauthored
Support allowed hosts for migrations to work with proxy (#32025) (#32026)
Backport #32025 by @wolfogre Fix #32024. Follow #27655. After this PR, all usage of "new dial context" needs to provide a proxy, so I dropped the old `NewDialContext` and renamed `NewDialContextWithProxy` to `NewDialContext`. Co-authored-by: Jason Song <[email protected]>
1 parent 54d828f commit 0629c08

File tree

4 files changed

+3
-11
lines changed

4 files changed

+3
-11
lines changed

modules/hostmatcher/http.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ import (
1313
)
1414

1515
// NewDialContext returns a DialContext for Transport, the DialContext will do allow/block list check
16-
func NewDialContext(usage string, allowList, blockList *HostMatchList) func(ctx context.Context, network, addr string) (net.Conn, error) {
17-
return NewDialContextWithProxy(usage, allowList, blockList, nil)
18-
}
19-
20-
func NewDialContextWithProxy(usage string, allowList, blockList *HostMatchList, proxy *url.URL) func(ctx context.Context, network, addr string) (net.Conn, error) {
16+
func NewDialContext(usage string, allowList, blockList *HostMatchList, proxy *url.URL) func(ctx context.Context, network, addr string) (net.Conn, error) {
2117
// How Go HTTP Client works with redirection:
2218
// transport.RoundTrip URL=http://domain.com, Host=domain.com
2319
// transport.DialContext addrOrHost=domain.com:80

services/migrations/http_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ func NewMigrationHTTPTransport() *http.Transport {
2424
return &http.Transport{
2525
TLSClientConfig: &tls.Config{InsecureSkipVerify: setting.Migrations.SkipTLSVerify},
2626
Proxy: proxy.Proxy(),
27-
DialContext: hostmatcher.NewDialContext("migration", allowList, blockList),
27+
DialContext: hostmatcher.NewDialContext("migration", allowList, blockList, setting.Proxy.ProxyURLFixed),
2828
}
2929
}

services/migrations/migrate.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,5 @@ func Init() error {
499499
// TODO: at the moment, if ALLOW_LOCALNETWORKS=false, ALLOWED_DOMAINS=domain.com, and domain.com has IP 127.0.0.1, then it's still allowed.
500500
// if we want to block such case, the private&loopback should be added to the blockList when ALLOW_LOCALNETWORKS=false
501501

502-
if setting.Proxy.Enabled && setting.Proxy.ProxyURLFixed != nil {
503-
allowList.AppendPattern(setting.Proxy.ProxyURLFixed.Host)
504-
}
505-
506502
return nil
507503
}

services/webhook/deliver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ func Init() error {
303303
Transport: &http.Transport{
304304
TLSClientConfig: &tls.Config{InsecureSkipVerify: setting.Webhook.SkipTLSVerify},
305305
Proxy: webhookProxy(allowedHostMatcher),
306-
DialContext: hostmatcher.NewDialContextWithProxy("webhook", allowedHostMatcher, nil, setting.Webhook.ProxyURLFixed),
306+
DialContext: hostmatcher.NewDialContext("webhook", allowedHostMatcher, nil, setting.Webhook.ProxyURLFixed),
307307
},
308308
}
309309

0 commit comments

Comments
 (0)