[arvados] created: 2.1.0-2863-g19c5342a7

git repository hosting git at public.arvados.org
Thu Aug 25 15:01:00 UTC 2022


        at  19c5342a76ab9474c3c8eb5c0e7903c58203a055 (commit)


commit 19c5342a76ab9474c3c8eb5c0e7903c58203a055
Author: Tom Clegg <tom at curii.com>
Date:   Mon Aug 22 09:40:28 2022 -0400

    17344: Recognize ipv6 local addresses as internal.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at curii.com>

diff --git a/sdk/python/tests/nginx.conf b/sdk/python/tests/nginx.conf
index a1a75bbcc..1716291fe 100644
--- a/sdk/python/tests/nginx.conf
+++ b/sdk/python/tests/nginx.conf
@@ -18,6 +18,8 @@ http {
   geo $external_client {
     default 1;
     127.0.0.0/8 0;
+    ::1 0;
+    fd00::/8 0;
     {{INTERNALSUBNETS}}
   }
   upstream controller {

commit 7991a5685dccec15e7d159a8e1bc53a4f89e33a2
Author: Tom Clegg <tom at curii.com>
Date:   Fri Aug 12 16:02:09 2022 -0400

    17344: Fix temp config file.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at curii.com>

diff --git a/lib/boot/supervisor.go b/lib/boot/supervisor.go
index ebe1eb6f6..ca88653fa 100644
--- a/lib/boot/supervisor.go
+++ b/lib/boot/supervisor.go
@@ -282,7 +282,7 @@ func (super *Supervisor) runCluster() error {
 	if err != nil {
 		return err
 	}
-	conffile, err := os.OpenFile(filepath.Join(super.wwwtempdir, "config.yml"), os.O_CREATE|os.O_WRONLY, 0644)
+	conffile, err := os.OpenFile(filepath.Join(super.wwwtempdir, "config.yml"), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
 	if err != nil {
 		return err
 	}

commit c04458c7a14669a739a39ecc332bfa19ee310058
Author: Tom Clegg <tom at curii.com>
Date:   Fri Aug 12 16:02:07 2022 -0400

    17344: Ensure server-to-controller traffic stays local.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at curii.com>

diff --git a/lib/boot/supervisor.go b/lib/boot/supervisor.go
index ddc17953d..ebe1eb6f6 100644
--- a/lib/boot/supervisor.go
+++ b/lib/boot/supervisor.go
@@ -308,6 +308,7 @@ func (super *Supervisor) runCluster() error {
 	if super.ClusterType != "production" {
 		super.prependEnv("PATH", super.tempdir+"/bin:")
 	}
+	super.setEnv("ARVADOS_SERVER_ADDRESS", super.ListenHost)
 
 	// Now that we have the config, replace the bootstrap logger
 	// with a new one according to the logging config.
diff --git a/sdk/go/arvados/client.go b/sdk/go/arvados/client.go
index 24d5ac3e3..cdc07bb0a 100644
--- a/sdk/go/arvados/client.go
+++ b/sdk/go/arvados/client.go
@@ -15,6 +15,7 @@ import (
 	"io/fs"
 	"io/ioutil"
 	"log"
+	"net"
 	"net/http"
 	"net/url"
 	"os"
@@ -94,7 +95,40 @@ func NewClientFromConfig(cluster *Cluster) (*Client, error) {
 	if ctrlURL.Host == "" {
 		return nil, fmt.Errorf("no host in config Services.Controller.ExternalURL: %v", ctrlURL)
 	}
+	var hc *http.Client
+	if srvaddr := os.Getenv("ARVADOS_SERVER_ADDRESS"); srvaddr != "" {
+		// When this client is used to make a request to
+		// https://{ctrlhost}:port/ (any port), it dials the
+		// indicated port on ARVADOS_SERVER_ADDRESS instead.
+		//
+		// This is invoked by arvados-server boot to ensure
+		// that server->server traffic (e.g.,
+		// keepproxy->controller) only hits local interfaces,
+		// even if the Controller.ExternalURL host is a load
+		// balancer / gateway and not a local interface
+		// address (e.g., when running on a cloud VM).
+		//
+		// This avoids unnecessary delay/cost of routing
+		// external traffic, and also allows controller to
+		// recognize other services as internal clients based
+		// on the connection source address.
+		divertedHost := (*url.URL)(&cluster.Services.Controller.ExternalURL).Hostname()
+		var dialer net.Dialer
+		hc = &http.Client{
+			Transport: &http.Transport{
+				TLSClientConfig: &tls.Config{InsecureSkipVerify: cluster.TLS.Insecure},
+				DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
+					host, port, err := net.SplitHostPort(addr)
+					if err == nil && network == "tcp" && host == divertedHost {
+						addr = net.JoinHostPort(srvaddr, port)
+					}
+					return dialer.DialContext(ctx, network, addr)
+				},
+			},
+		}
+	}
 	return &Client{
+		Client:   hc,
 		Scheme:   ctrlURL.Scheme,
 		APIHost:  ctrlURL.Host,
 		Insecure: cluster.TLS.Insecure,
diff --git a/sdk/go/arvadosclient/arvadosclient.go b/sdk/go/arvadosclient/arvadosclient.go
index 24070c5b0..2044df633 100644
--- a/sdk/go/arvadosclient/arvadosclient.go
+++ b/sdk/go/arvadosclient/arvadosclient.go
@@ -166,16 +166,20 @@ func MakeTLSConfig(insecure bool) *tls.Config {
 // fields from configuration files but still need to use the
 // arvadosclient.ArvadosClient package.
 func New(c *arvados.Client) (*ArvadosClient, error) {
-	ac := &ArvadosClient{
-		Scheme:      "https",
-		ApiServer:   c.APIHost,
-		ApiToken:    c.AuthToken,
-		ApiInsecure: c.Insecure,
-		Client: &http.Client{
+	hc := c.Client
+	if hc == nil {
+		hc = &http.Client{
 			Timeout: 5 * time.Minute,
 			Transport: &http.Transport{
 				TLSClientConfig: MakeTLSConfig(c.Insecure)},
-		},
+		}
+	}
+	ac := &ArvadosClient{
+		Scheme:            "https",
+		ApiServer:         c.APIHost,
+		ApiToken:          c.AuthToken,
+		ApiInsecure:       c.Insecure,
+		Client:            hc,
 		External:          false,
 		Retries:           2,
 		KeepServiceURIs:   c.KeepServiceURIs,

commit ca48c72ce0d2c5901234cd7232cc026ca97a22b8
Author: Tom Clegg <tom at curii.com>
Date:   Tue Aug 2 10:12:51 2022 -0400

    17344: arvados-server boot: set X-External-Client header.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at curii.com>

diff --git a/lib/boot/nginx.go b/lib/boot/nginx.go
index b391c4dc8..9f1091eac 100644
--- a/lib/boot/nginx.go
+++ b/lib/boot/nginx.go
@@ -5,6 +5,7 @@
 package boot
 
 import (
+	"bytes"
 	"context"
 	"fmt"
 	"io/ioutil"
@@ -17,6 +18,7 @@ import (
 	"strings"
 
 	"git.arvados.org/arvados.git/sdk/go/arvados"
+	"github.com/sirupsen/logrus"
 )
 
 // Run an Nginx process that proxies the supervisor's configured
@@ -46,6 +48,7 @@ func (runNginx) Run(ctx context.Context, fail func(error), super *Supervisor) er
 	vars := map[string]string{
 		"LISTENHOST":       extListenHost,
 		"UPSTREAMHOST":     super.ListenHost,
+		"INTERNALSUBNETS":  internalSubnets(super.logger),
 		"SSLCERT":          filepath.Join(super.tempdir, "server.crt"),
 		"SSLKEY":           filepath.Join(super.tempdir, "server.key"),
 		"ACCESSLOG":        filepath.Join(super.tempdir, "nginx_access.log"),
@@ -150,3 +153,27 @@ func (runNginx) Run(ctx context.Context, fail func(error), super *Supervisor) er
 	}
 	return waitForConnect(ctx, testurl.Host)
 }
+
+// Return 0 or more local subnets as "geo" fragments for Nginx config,
+// e.g., "1.2.3.0/24 0; 10.1.0.0/16 0;".
+func internalSubnets(logger logrus.FieldLogger) string {
+	iproutes, err := exec.Command("ip", "route").CombinedOutput()
+	if err != nil {
+		logger.Warnf("treating all clients as external because `ip route` failed: %s (%q)", err, iproutes)
+		return ""
+	}
+	subnets := ""
+	for _, line := range bytes.Split(iproutes, []byte("\n")) {
+		fields := strings.Fields(string(line))
+		if len(fields) > 2 && fields[1] == "dev" {
+			// lan example:
+			// 192.168.86.0/24 dev ens3 proto kernel scope link src 192.168.86.196
+			// gcp example (private subnet):
+			// 10.47.0.0/24 dev eth0 proto kernel scope link src 10.47.0.5
+			// gcp example (no private subnet):
+			// 10.128.0.1 dev ens4 scope link
+			subnets += fields[0] + " 0; "
+		}
+	}
+	return subnets
+}
diff --git a/sdk/python/tests/nginx.conf b/sdk/python/tests/nginx.conf
index 4ad3eda42..a1a75bbcc 100644
--- a/sdk/python/tests/nginx.conf
+++ b/sdk/python/tests/nginx.conf
@@ -15,6 +15,11 @@ http {
   fastcgi_temp_path "{{TMPDIR}}";
   uwsgi_temp_path "{{TMPDIR}}";
   scgi_temp_path "{{TMPDIR}}";
+  geo $external_client {
+    default 1;
+    127.0.0.0/8 0;
+    {{INTERNALSUBNETS}}
+  }
   upstream controller {
     server {{UPSTREAMHOST}}:{{CONTROLLERPORT}};
   }
@@ -26,7 +31,10 @@ http {
     client_max_body_size 0;
     location  / {
       proxy_pass http://controller;
+      proxy_set_header Upgrade $http_upgrade;
+      proxy_set_header Connection "upgrade";
       proxy_set_header Host $http_host;
+      proxy_set_header X-External-Client $external_client;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto https;
       proxy_redirect off;
diff --git a/sdk/python/tests/run_test_server.py b/sdk/python/tests/run_test_server.py
index e32d385f7..7147c7aa8 100644
--- a/sdk/python/tests/run_test_server.py
+++ b/sdk/python/tests/run_test_server.py
@@ -660,6 +660,7 @@ def run_nginx():
     nginxconf['ACCESSLOG'] = _logfilename('nginx_access')
     nginxconf['ERRORLOG'] = _logfilename('nginx_error')
     nginxconf['TMPDIR'] = TEST_TMPDIR + '/nginx'
+    nginxconf['INTERNALSUBNETS'] = '169.254.0.0/16 0;'
 
     conftemplatefile = os.path.join(MY_DIRNAME, 'nginx.conf')
     conffile = os.path.join(TEST_TMPDIR, 'nginx.conf')

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list