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