Merge branch '16312-s3-signature-v4'
[arvados.git] / lib / config / deprecated.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package config
6
7 import (
8         "fmt"
9         "io/ioutil"
10         "net/url"
11         "os"
12         "strings"
13
14         "git.arvados.org/arvados.git/sdk/go/arvados"
15         "github.com/ghodss/yaml"
16 )
17
18 type deprRequestLimits struct {
19         MaxItemsPerResponse            *int
20         MultiClusterRequestConcurrency *int
21 }
22
23 type deprCluster struct {
24         RequestLimits deprRequestLimits
25         NodeProfiles  map[string]nodeProfile
26         Login         struct {
27                 GoogleClientID                *string
28                 GoogleClientSecret            *string
29                 GoogleAlternateEmailAddresses *bool
30                 ProviderAppID                 *string
31                 ProviderAppSecret             *string
32         }
33 }
34
35 type deprecatedConfig struct {
36         Clusters map[string]deprCluster
37 }
38
39 type nodeProfile struct {
40         Controller    systemServiceInstance `json:"arvados-controller"`
41         Health        systemServiceInstance `json:"arvados-health"`
42         Keepbalance   systemServiceInstance `json:"keep-balance"`
43         Keepproxy     systemServiceInstance `json:"keepproxy"`
44         Keepstore     systemServiceInstance `json:"keepstore"`
45         Keepweb       systemServiceInstance `json:"keep-web"`
46         Nodemanager   systemServiceInstance `json:"arvados-node-manager"`
47         DispatchCloud systemServiceInstance `json:"arvados-dispatch-cloud"`
48         RailsAPI      systemServiceInstance `json:"arvados-api-server"`
49         Websocket     systemServiceInstance `json:"arvados-ws"`
50         Workbench1    systemServiceInstance `json:"arvados-workbench"`
51 }
52
53 type systemServiceInstance struct {
54         Listen   string
55         TLS      bool
56         Insecure bool
57 }
58
59 func (ldr *Loader) applyDeprecatedConfig(cfg *arvados.Config) error {
60         var dc deprecatedConfig
61         err := yaml.Unmarshal(ldr.configdata, &dc)
62         if err != nil {
63                 return err
64         }
65         hostname, err := os.Hostname()
66         if err != nil {
67                 return err
68         }
69         for id, dcluster := range dc.Clusters {
70                 cluster, ok := cfg.Clusters[id]
71                 if !ok {
72                         return fmt.Errorf("can't load legacy config %q that is not present in current config", id)
73                 }
74                 for name, np := range dcluster.NodeProfiles {
75                         if name == "*" || name == os.Getenv("ARVADOS_NODE_PROFILE") || name == hostname {
76                                 name = "localhost"
77                         } else if ldr.Logger != nil {
78                                 ldr.Logger.Warnf("overriding Clusters.%s.Services using Clusters.%s.NodeProfiles.%s (guessing %q is a hostname)", id, id, name, name)
79                         }
80                         applyDeprecatedNodeProfile(name, np.RailsAPI, &cluster.Services.RailsAPI)
81                         applyDeprecatedNodeProfile(name, np.Controller, &cluster.Services.Controller)
82                         applyDeprecatedNodeProfile(name, np.DispatchCloud, &cluster.Services.DispatchCloud)
83                 }
84                 if dst, n := &cluster.API.MaxItemsPerResponse, dcluster.RequestLimits.MaxItemsPerResponse; n != nil && *n != *dst {
85                         *dst = *n
86                 }
87                 if dst, n := &cluster.API.MaxRequestAmplification, dcluster.RequestLimits.MultiClusterRequestConcurrency; n != nil && *n != *dst {
88                         *dst = *n
89                 }
90
91                 // Google* moved to Google.*
92                 if dst, n := &cluster.Login.Google.ClientID, dcluster.Login.GoogleClientID; n != nil && *n != *dst {
93                         *dst = *n
94                         if *n != "" {
95                                 // In old config, non-empty ClientID meant enable
96                                 cluster.Login.Google.Enable = true
97                         }
98                 }
99                 if dst, n := &cluster.Login.Google.ClientSecret, dcluster.Login.GoogleClientSecret; n != nil && *n != *dst {
100                         *dst = *n
101                 }
102                 if dst, n := &cluster.Login.Google.AlternateEmailAddresses, dcluster.Login.GoogleAlternateEmailAddresses; n != nil && *n != *dst {
103                         *dst = *n
104                 }
105
106                 // Provider* moved to SSO.Provider*
107                 if dst, n := &cluster.Login.SSO.ProviderAppID, dcluster.Login.ProviderAppID; n != nil && *n != *dst {
108                         *dst = *n
109                         if *n != "" {
110                                 // In old config, non-empty ID meant enable
111                                 cluster.Login.SSO.Enable = true
112                         }
113                 }
114                 if dst, n := &cluster.Login.SSO.ProviderAppSecret, dcluster.Login.ProviderAppSecret; n != nil && *n != *dst {
115                         *dst = *n
116                 }
117
118                 cfg.Clusters[id] = cluster
119         }
120         return nil
121 }
122
123 func applyDeprecatedNodeProfile(hostname string, ssi systemServiceInstance, svc *arvados.Service) {
124         scheme := "https"
125         if !ssi.TLS {
126                 scheme = "http"
127         }
128         if svc.InternalURLs == nil {
129                 svc.InternalURLs = map[arvados.URL]arvados.ServiceInstance{}
130         }
131         host := ssi.Listen
132         if host == "" {
133                 return
134         }
135         if strings.HasPrefix(host, ":") {
136                 host = hostname + host
137         }
138         svc.InternalURLs[arvados.URL{Scheme: scheme, Host: host, Path: "/"}] = arvados.ServiceInstance{}
139 }
140
141 func (ldr *Loader) loadOldConfigHelper(component, path string, target interface{}) error {
142         if path == "" {
143                 return nil
144         }
145         buf, err := ioutil.ReadFile(path)
146         if err != nil {
147                 return err
148         }
149
150         ldr.Logger.Warnf("you should remove the legacy %v config file (%s) after migrating all config keys to the cluster configuration file (%s)", component, path, ldr.Path)
151
152         err = yaml.Unmarshal(buf, target)
153         if err != nil {
154                 return fmt.Errorf("%s: %s", path, err)
155         }
156         return nil
157 }
158
159 type oldCrunchDispatchSlurmConfig struct {
160         Client *arvados.Client
161
162         SbatchArguments *[]string
163         PollPeriod      *arvados.Duration
164         PrioritySpread  *int64
165
166         // crunch-run command to invoke. The container UUID will be
167         // appended. If nil, []string{"crunch-run"} will be used.
168         //
169         // Example: []string{"crunch-run", "--cgroup-parent-subsystem=memory"}
170         CrunchRunCommand *[]string
171
172         // Extra RAM to reserve (in Bytes) for SLURM job, in addition
173         // to the amount specified in the container's RuntimeConstraints
174         ReserveExtraRAM *int64
175
176         // Minimum time between two attempts to run the same container
177         MinRetryPeriod *arvados.Duration
178
179         // Batch size for container queries
180         BatchSize *int64
181 }
182
183 const defaultCrunchDispatchSlurmConfigPath = "/etc/arvados/crunch-dispatch-slurm/crunch-dispatch-slurm.yml"
184
185 func loadOldClientConfig(cluster *arvados.Cluster, client *arvados.Client) {
186         if client == nil {
187                 return
188         }
189         if client.APIHost != "" {
190                 cluster.Services.Controller.ExternalURL.Host = client.APIHost
191                 cluster.Services.Controller.ExternalURL.Path = "/"
192         }
193         if client.Scheme != "" {
194                 cluster.Services.Controller.ExternalURL.Scheme = client.Scheme
195         } else {
196                 cluster.Services.Controller.ExternalURL.Scheme = "https"
197         }
198         if client.AuthToken != "" {
199                 cluster.SystemRootToken = client.AuthToken
200         }
201         cluster.TLS.Insecure = client.Insecure
202         ks := ""
203         for i, u := range client.KeepServiceURIs {
204                 if i > 0 {
205                         ks += " "
206                 }
207                 ks += u
208         }
209         cluster.Containers.SLURM.SbatchEnvironmentVariables = map[string]string{"ARVADOS_KEEP_SERVICES": ks}
210 }
211
212 // update config using values from an crunch-dispatch-slurm config file.
213 func (ldr *Loader) loadOldCrunchDispatchSlurmConfig(cfg *arvados.Config) error {
214         if ldr.CrunchDispatchSlurmPath == "" {
215                 return nil
216         }
217         var oc oldCrunchDispatchSlurmConfig
218         err := ldr.loadOldConfigHelper("crunch-dispatch-slurm", ldr.CrunchDispatchSlurmPath, &oc)
219         if os.IsNotExist(err) && (ldr.CrunchDispatchSlurmPath == defaultCrunchDispatchSlurmConfigPath) {
220                 return nil
221         } else if err != nil {
222                 return err
223         }
224
225         cluster, err := cfg.GetCluster("")
226         if err != nil {
227                 return err
228         }
229
230         loadOldClientConfig(cluster, oc.Client)
231
232         if oc.SbatchArguments != nil {
233                 cluster.Containers.SLURM.SbatchArgumentsList = *oc.SbatchArguments
234         }
235         if oc.PollPeriod != nil {
236                 cluster.Containers.CloudVMs.PollInterval = *oc.PollPeriod
237         }
238         if oc.PrioritySpread != nil {
239                 cluster.Containers.SLURM.PrioritySpread = *oc.PrioritySpread
240         }
241         if oc.CrunchRunCommand != nil {
242                 if len(*oc.CrunchRunCommand) >= 1 {
243                         cluster.Containers.CrunchRunCommand = (*oc.CrunchRunCommand)[0]
244                 }
245                 if len(*oc.CrunchRunCommand) >= 2 {
246                         cluster.Containers.CrunchRunArgumentsList = (*oc.CrunchRunCommand)[1:]
247                 }
248         }
249         if oc.ReserveExtraRAM != nil {
250                 cluster.Containers.ReserveExtraRAM = arvados.ByteSize(*oc.ReserveExtraRAM)
251         }
252         if oc.MinRetryPeriod != nil {
253                 cluster.Containers.MinRetryPeriod = *oc.MinRetryPeriod
254         }
255         if oc.BatchSize != nil {
256                 cluster.API.MaxItemsPerResponse = int(*oc.BatchSize)
257         }
258
259         cfg.Clusters[cluster.ClusterID] = *cluster
260         return nil
261 }
262
263 type oldWsConfig struct {
264         Client       *arvados.Client
265         Postgres     *arvados.PostgreSQLConnection
266         PostgresPool *int
267         Listen       *string
268         LogLevel     *string
269         LogFormat    *string
270
271         PingTimeout      *arvados.Duration
272         ClientEventQueue *int
273         ServerEventQueue *int
274
275         ManagementToken *string
276 }
277
278 const defaultWebsocketConfigPath = "/etc/arvados/ws/ws.yml"
279
280 // update config using values from an crunch-dispatch-slurm config file.
281 func (ldr *Loader) loadOldWebsocketConfig(cfg *arvados.Config) error {
282         if ldr.WebsocketPath == "" {
283                 return nil
284         }
285         var oc oldWsConfig
286         err := ldr.loadOldConfigHelper("arvados-ws", ldr.WebsocketPath, &oc)
287         if os.IsNotExist(err) && ldr.WebsocketPath == defaultWebsocketConfigPath {
288                 return nil
289         } else if err != nil {
290                 return err
291         }
292
293         cluster, err := cfg.GetCluster("")
294         if err != nil {
295                 return err
296         }
297
298         loadOldClientConfig(cluster, oc.Client)
299
300         if oc.Postgres != nil {
301                 cluster.PostgreSQL.Connection = *oc.Postgres
302         }
303         if oc.PostgresPool != nil {
304                 cluster.PostgreSQL.ConnectionPool = *oc.PostgresPool
305         }
306         if oc.Listen != nil {
307                 cluster.Services.Websocket.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
308         }
309         if oc.LogLevel != nil {
310                 cluster.SystemLogs.LogLevel = *oc.LogLevel
311         }
312         if oc.LogFormat != nil {
313                 cluster.SystemLogs.Format = *oc.LogFormat
314         }
315         if oc.PingTimeout != nil {
316                 cluster.API.SendTimeout = *oc.PingTimeout
317         }
318         if oc.ClientEventQueue != nil {
319                 cluster.API.WebsocketClientEventQueue = *oc.ClientEventQueue
320         }
321         if oc.ServerEventQueue != nil {
322                 cluster.API.WebsocketServerEventQueue = *oc.ServerEventQueue
323         }
324         if oc.ManagementToken != nil {
325                 cluster.ManagementToken = *oc.ManagementToken
326         }
327
328         cfg.Clusters[cluster.ClusterID] = *cluster
329         return nil
330 }
331
332 type oldKeepProxyConfig struct {
333         Client          *arvados.Client
334         Listen          *string
335         DisableGet      *bool
336         DisablePut      *bool
337         DefaultReplicas *int
338         Timeout         *arvados.Duration
339         PIDFile         *string
340         Debug           *bool
341         ManagementToken *string
342 }
343
344 const defaultKeepproxyConfigPath = "/etc/arvados/keepproxy/keepproxy.yml"
345
346 func (ldr *Loader) loadOldKeepproxyConfig(cfg *arvados.Config) error {
347         if ldr.KeepproxyPath == "" {
348                 return nil
349         }
350         var oc oldKeepProxyConfig
351         err := ldr.loadOldConfigHelper("keepproxy", ldr.KeepproxyPath, &oc)
352         if os.IsNotExist(err) && ldr.KeepproxyPath == defaultKeepproxyConfigPath {
353                 return nil
354         } else if err != nil {
355                 return err
356         }
357
358         cluster, err := cfg.GetCluster("")
359         if err != nil {
360                 return err
361         }
362
363         loadOldClientConfig(cluster, oc.Client)
364
365         if oc.Listen != nil {
366                 cluster.Services.Keepproxy.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
367         }
368         if oc.DefaultReplicas != nil {
369                 cluster.Collections.DefaultReplication = *oc.DefaultReplicas
370         }
371         if oc.Timeout != nil {
372                 cluster.API.KeepServiceRequestTimeout = *oc.Timeout
373         }
374         if oc.Debug != nil {
375                 if *oc.Debug && cluster.SystemLogs.LogLevel != "debug" {
376                         cluster.SystemLogs.LogLevel = "debug"
377                 } else if !*oc.Debug && cluster.SystemLogs.LogLevel != "info" {
378                         cluster.SystemLogs.LogLevel = "info"
379                 }
380         }
381         if oc.ManagementToken != nil {
382                 cluster.ManagementToken = *oc.ManagementToken
383         }
384
385         // The following legacy options are no longer supported. If they are set to
386         // true or PIDFile has a value, error out and notify the user
387         unsupportedEntry := func(cfgEntry string) error {
388                 return fmt.Errorf("the keepproxy %s configuration option is no longer supported, please remove it from your configuration file", cfgEntry)
389         }
390         if oc.DisableGet != nil && *oc.DisableGet {
391                 return unsupportedEntry("DisableGet")
392         }
393         if oc.DisablePut != nil && *oc.DisablePut {
394                 return unsupportedEntry("DisablePut")
395         }
396         if oc.PIDFile != nil && *oc.PIDFile != "" {
397                 return unsupportedEntry("PIDFile")
398         }
399
400         cfg.Clusters[cluster.ClusterID] = *cluster
401         return nil
402 }
403
404 const defaultKeepWebConfigPath = "/etc/arvados/keep-web/keep-web.yml"
405
406 type oldKeepWebConfig struct {
407         Client *arvados.Client
408
409         Listen *string
410
411         AnonymousTokens    *[]string
412         AttachmentOnlyHost *string
413         TrustAllContent    *bool
414
415         Cache struct {
416                 TTL                  *arvados.Duration
417                 UUIDTTL              *arvados.Duration
418                 MaxCollectionEntries *int
419                 MaxCollectionBytes   *int64
420                 MaxPermissionEntries *int
421                 MaxUUIDEntries       *int
422         }
423
424         // Hack to support old command line flag, which is a bool
425         // meaning "get actual token from environment".
426         deprecatedAllowAnonymous *bool
427
428         // Authorization token to be included in all health check requests.
429         ManagementToken *string
430 }
431
432 func (ldr *Loader) loadOldKeepWebConfig(cfg *arvados.Config) error {
433         if ldr.KeepWebPath == "" {
434                 return nil
435         }
436         var oc oldKeepWebConfig
437         err := ldr.loadOldConfigHelper("keep-web", ldr.KeepWebPath, &oc)
438         if os.IsNotExist(err) && ldr.KeepWebPath == defaultKeepWebConfigPath {
439                 return nil
440         } else if err != nil {
441                 return err
442         }
443
444         cluster, err := cfg.GetCluster("")
445         if err != nil {
446                 return err
447         }
448
449         loadOldClientConfig(cluster, oc.Client)
450
451         if oc.Listen != nil {
452                 cluster.Services.WebDAV.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
453                 cluster.Services.WebDAVDownload.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
454         }
455         if oc.AttachmentOnlyHost != nil {
456                 cluster.Services.WebDAVDownload.ExternalURL = arvados.URL{Host: *oc.AttachmentOnlyHost, Path: "/"}
457         }
458         if oc.ManagementToken != nil {
459                 cluster.ManagementToken = *oc.ManagementToken
460         }
461         if oc.TrustAllContent != nil {
462                 cluster.Collections.TrustAllContent = *oc.TrustAllContent
463         }
464         if oc.Cache.TTL != nil {
465                 cluster.Collections.WebDAVCache.TTL = *oc.Cache.TTL
466         }
467         if oc.Cache.UUIDTTL != nil {
468                 cluster.Collections.WebDAVCache.UUIDTTL = *oc.Cache.UUIDTTL
469         }
470         if oc.Cache.MaxCollectionEntries != nil {
471                 cluster.Collections.WebDAVCache.MaxCollectionEntries = *oc.Cache.MaxCollectionEntries
472         }
473         if oc.Cache.MaxCollectionBytes != nil {
474                 cluster.Collections.WebDAVCache.MaxCollectionBytes = *oc.Cache.MaxCollectionBytes
475         }
476         if oc.Cache.MaxPermissionEntries != nil {
477                 cluster.Collections.WebDAVCache.MaxPermissionEntries = *oc.Cache.MaxPermissionEntries
478         }
479         if oc.Cache.MaxUUIDEntries != nil {
480                 cluster.Collections.WebDAVCache.MaxUUIDEntries = *oc.Cache.MaxUUIDEntries
481         }
482         if oc.AnonymousTokens != nil {
483                 if len(*oc.AnonymousTokens) > 0 {
484                         cluster.Users.AnonymousUserToken = (*oc.AnonymousTokens)[0]
485                         if len(*oc.AnonymousTokens) > 1 {
486                                 ldr.Logger.Warn("More than 1 anonymous tokens configured, using only the first and discarding the rest.")
487                         }
488                 }
489         }
490
491         cfg.Clusters[cluster.ClusterID] = *cluster
492         return nil
493 }
494
495 const defaultGitHttpdConfigPath = "/etc/arvados/git-httpd/git-httpd.yml"
496
497 type oldGitHttpdConfig struct {
498         Client          *arvados.Client
499         Listen          *string
500         GitCommand      *string
501         GitoliteHome    *string
502         RepoRoot        *string
503         ManagementToken *string
504 }
505
506 func (ldr *Loader) loadOldGitHttpdConfig(cfg *arvados.Config) error {
507         if ldr.GitHttpdPath == "" {
508                 return nil
509         }
510         var oc oldGitHttpdConfig
511         err := ldr.loadOldConfigHelper("arv-git-httpd", ldr.GitHttpdPath, &oc)
512         if os.IsNotExist(err) && ldr.GitHttpdPath == defaultGitHttpdConfigPath {
513                 return nil
514         } else if err != nil {
515                 return err
516         }
517
518         cluster, err := cfg.GetCluster("")
519         if err != nil {
520                 return err
521         }
522
523         loadOldClientConfig(cluster, oc.Client)
524
525         if oc.Listen != nil {
526                 cluster.Services.GitHTTP.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
527         }
528         if oc.ManagementToken != nil {
529                 cluster.ManagementToken = *oc.ManagementToken
530         }
531         if oc.GitCommand != nil {
532                 cluster.Git.GitCommand = *oc.GitCommand
533         }
534         if oc.GitoliteHome != nil {
535                 cluster.Git.GitoliteHome = *oc.GitoliteHome
536         }
537         if oc.RepoRoot != nil {
538                 cluster.Git.Repositories = *oc.RepoRoot
539         }
540
541         cfg.Clusters[cluster.ClusterID] = *cluster
542         return nil
543 }
544
545 const defaultKeepBalanceConfigPath = "/etc/arvados/keep-balance/keep-balance.yml"
546
547 type oldKeepBalanceConfig struct {
548         Client              *arvados.Client
549         Listen              *string
550         KeepServiceTypes    *[]string
551         KeepServiceList     *arvados.KeepServiceList
552         RunPeriod           *arvados.Duration
553         CollectionBatchSize *int
554         CollectionBuffers   *int
555         RequestTimeout      *arvados.Duration
556         LostBlocksFile      *string
557         ManagementToken     *string
558 }
559
560 func (ldr *Loader) loadOldKeepBalanceConfig(cfg *arvados.Config) error {
561         if ldr.KeepBalancePath == "" {
562                 return nil
563         }
564         var oc oldKeepBalanceConfig
565         err := ldr.loadOldConfigHelper("keep-balance", ldr.KeepBalancePath, &oc)
566         if os.IsNotExist(err) && ldr.KeepBalancePath == defaultKeepBalanceConfigPath {
567                 return nil
568         } else if err != nil {
569                 return err
570         }
571
572         cluster, err := cfg.GetCluster("")
573         if err != nil {
574                 return err
575         }
576
577         loadOldClientConfig(cluster, oc.Client)
578
579         if oc.Listen != nil {
580                 cluster.Services.Keepbalance.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
581         }
582         if oc.ManagementToken != nil {
583                 cluster.ManagementToken = *oc.ManagementToken
584         }
585         if oc.RunPeriod != nil {
586                 cluster.Collections.BalancePeriod = *oc.RunPeriod
587         }
588         if oc.LostBlocksFile != nil {
589                 cluster.Collections.BlobMissingReport = *oc.LostBlocksFile
590         }
591         if oc.CollectionBatchSize != nil {
592                 cluster.Collections.BalanceCollectionBatch = *oc.CollectionBatchSize
593         }
594         if oc.CollectionBuffers != nil {
595                 cluster.Collections.BalanceCollectionBuffers = *oc.CollectionBuffers
596         }
597         if oc.RequestTimeout != nil {
598                 cluster.API.KeepServiceRequestTimeout = *oc.RequestTimeout
599         }
600
601         msg := "The %s configuration option is no longer supported. Please remove it from your configuration file. See the keep-balance upgrade notes at https://doc.arvados.org/admin/upgrading.html for more details."
602
603         // If the keep service type provided is "disk" silently ignore it, since
604         // this is what ends up being done anyway.
605         if oc.KeepServiceTypes != nil {
606                 numTypes := len(*oc.KeepServiceTypes)
607                 if numTypes != 0 && !(numTypes == 1 && (*oc.KeepServiceTypes)[0] == "disk") {
608                         return fmt.Errorf(msg, "KeepServiceTypes")
609                 }
610         }
611
612         if oc.KeepServiceList != nil {
613                 return fmt.Errorf(msg, "KeepServiceList")
614         }
615
616         cfg.Clusters[cluster.ClusterID] = *cluster
617         return nil
618 }
619
620 func (ldr *Loader) loadOldEnvironmentVariables(cfg *arvados.Config) error {
621         if os.Getenv("ARVADOS_API_TOKEN") == "" && os.Getenv("ARVADOS_API_HOST") == "" {
622                 return nil
623         }
624         cluster, err := cfg.GetCluster("")
625         if err != nil {
626                 return err
627         }
628         if tok := os.Getenv("ARVADOS_API_TOKEN"); tok != "" && cluster.SystemRootToken == "" {
629                 ldr.Logger.Warn("SystemRootToken missing from cluster config, falling back to ARVADOS_API_TOKEN environment variable")
630                 cluster.SystemRootToken = tok
631         }
632         if apihost := os.Getenv("ARVADOS_API_HOST"); apihost != "" && cluster.Services.Controller.ExternalURL.Host == "" {
633                 ldr.Logger.Warn("Services.Controller.ExternalURL missing from cluster config, falling back to ARVADOS_API_HOST(_INSECURE) environment variables")
634                 u, err := url.Parse("https://" + apihost)
635                 if err != nil {
636                         return fmt.Errorf("cannot parse ARVADOS_API_HOST: %s", err)
637                 }
638                 cluster.Services.Controller.ExternalURL = arvados.URL(*u)
639                 if i := os.Getenv("ARVADOS_API_HOST_INSECURE"); i != "" && i != "0" {
640                         cluster.TLS.Insecure = true
641                 }
642         }
643         cfg.Clusters[cluster.ClusterID] = *cluster
644         return nil
645 }