1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
15 "git.arvados.org/arvados.git/sdk/go/arvados"
16 "github.com/ghodss/yaml"
19 type deprRequestLimits struct {
20 MaxItemsPerResponse *int
21 MultiClusterRequestConcurrency *int
24 type deprCluster struct {
25 RequestLimits deprRequestLimits
26 NodeProfiles map[string]nodeProfile
28 GoogleClientID *string
29 GoogleClientSecret *string
30 GoogleAlternateEmailAddresses *bool
32 ProviderAppSecret *string
36 type deprecatedConfig struct {
37 Clusters map[string]deprCluster
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"`
53 type systemServiceInstance struct {
59 func (ldr *Loader) applyDeprecatedConfig(cfg *arvados.Config) error {
60 var dc deprecatedConfig
61 err := yaml.Unmarshal(ldr.configdata, &dc)
65 hostname, err := os.Hostname()
69 for id, dcluster := range dc.Clusters {
70 cluster, ok := cfg.Clusters[id]
72 return fmt.Errorf("can't load legacy config %q that is not present in current config", id)
74 for name, np := range dcluster.NodeProfiles {
75 if name == "*" || name == os.Getenv("ARVADOS_NODE_PROFILE") || name == hostname {
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)
80 applyDeprecatedNodeProfile(name, np.RailsAPI, &cluster.Services.RailsAPI)
81 applyDeprecatedNodeProfile(name, np.Controller, &cluster.Services.Controller)
82 applyDeprecatedNodeProfile(name, np.DispatchCloud, &cluster.Services.DispatchCloud)
84 if dst, n := &cluster.API.MaxItemsPerResponse, dcluster.RequestLimits.MaxItemsPerResponse; n != nil && *n != *dst {
87 if dst, n := &cluster.API.MaxRequestAmplification, dcluster.RequestLimits.MultiClusterRequestConcurrency; n != nil && *n != *dst {
91 // Google* moved to Google.*
92 if dst, n := &cluster.Login.Google.ClientID, dcluster.Login.GoogleClientID; n != nil && *n != *dst {
95 // In old config, non-empty ClientID meant enable
96 cluster.Login.Google.Enable = true
99 if dst, n := &cluster.Login.Google.ClientSecret, dcluster.Login.GoogleClientSecret; n != nil && *n != *dst {
102 if dst, n := &cluster.Login.Google.AlternateEmailAddresses, dcluster.Login.GoogleAlternateEmailAddresses; n != nil && *n != *dst {
106 cfg.Clusters[id] = cluster
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" {
116 AccessKey string `json:",omitempty"`
117 SecretKey string `json:",omitempty"`
119 SecretAccessKey string
121 err := json.Unmarshal(vol.DriverParameters, ¶ms)
123 return fmt.Errorf("error loading %s.Volumes.%s.DriverParameters: %w", clusterID, volID, err)
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)
129 var allparams map[string]interface{}
130 err = json.Unmarshal(vol.DriverParameters, &allparams)
132 return fmt.Errorf("error loading %s.Volumes.%s.DriverParameters: %w", clusterID, volID, err)
134 for k := range allparams {
135 if lk := strings.ToLower(k); lk == "accesskey" || lk == "secretkey" {
139 ldr.Logger.Warnf("using your old config keys %s.Volumes.%s.DriverParameters.AccessKey/SecretKey -- but you should rename them to AccessKeyID/SecretAccessKey", clusterID, volID)
140 allparams["AccessKeyID"] = params.AccessKey
141 allparams["SecretAccessKey"] = params.SecretKey
142 vol.DriverParameters, err = json.Marshal(allparams)
146 cluster.Volumes[volID] = vol
154 func applyDeprecatedNodeProfile(hostname string, ssi systemServiceInstance, svc *arvados.Service) {
159 if svc.InternalURLs == nil {
160 svc.InternalURLs = map[arvados.URL]arvados.ServiceInstance{}
166 if strings.HasPrefix(host, ":") {
167 host = hostname + host
169 svc.InternalURLs[arvados.URL{Scheme: scheme, Host: host, Path: "/"}] = arvados.ServiceInstance{}
172 func (ldr *Loader) loadOldConfigHelper(component, path string, target interface{}) error {
176 buf, err := ioutil.ReadFile(path)
181 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 err = yaml.Unmarshal(buf, target)
185 return fmt.Errorf("%s: %s", path, err)
190 type oldCrunchDispatchSlurmConfig struct {
191 Client *arvados.Client
193 SbatchArguments *[]string
194 PollPeriod *arvados.Duration
195 PrioritySpread *int64
197 // crunch-run command to invoke. The container UUID will be
198 // appended. If nil, []string{"crunch-run"} will be used.
200 // Example: []string{"crunch-run", "--cgroup-parent-subsystem=memory"}
201 CrunchRunCommand *[]string
203 // Extra RAM to reserve (in Bytes) for SLURM job, in addition
204 // to the amount specified in the container's RuntimeConstraints
205 ReserveExtraRAM *int64
207 // Minimum time between two attempts to run the same container
208 MinRetryPeriod *arvados.Duration
210 // Batch size for container queries
214 const defaultCrunchDispatchSlurmConfigPath = "/etc/arvados/crunch-dispatch-slurm/crunch-dispatch-slurm.yml"
216 func loadOldClientConfig(cluster *arvados.Cluster, client *arvados.Client) {
220 if client.APIHost != "" {
221 cluster.Services.Controller.ExternalURL.Host = client.APIHost
222 cluster.Services.Controller.ExternalURL.Path = "/"
224 if client.Scheme != "" {
225 cluster.Services.Controller.ExternalURL.Scheme = client.Scheme
227 cluster.Services.Controller.ExternalURL.Scheme = "https"
229 if client.AuthToken != "" {
230 cluster.SystemRootToken = client.AuthToken
232 cluster.TLS.Insecure = client.Insecure
234 for i, u := range client.KeepServiceURIs {
240 cluster.Containers.SLURM.SbatchEnvironmentVariables = map[string]string{"ARVADOS_KEEP_SERVICES": ks}
243 // update config using values from an crunch-dispatch-slurm config file.
244 func (ldr *Loader) loadOldCrunchDispatchSlurmConfig(cfg *arvados.Config) error {
245 if ldr.CrunchDispatchSlurmPath == "" {
248 var oc oldCrunchDispatchSlurmConfig
249 err := ldr.loadOldConfigHelper("crunch-dispatch-slurm", ldr.CrunchDispatchSlurmPath, &oc)
250 if os.IsNotExist(err) && (ldr.CrunchDispatchSlurmPath == defaultCrunchDispatchSlurmConfigPath) {
252 } else if err != nil {
256 cluster, err := cfg.GetCluster("")
261 loadOldClientConfig(cluster, oc.Client)
263 if oc.SbatchArguments != nil {
264 cluster.Containers.SLURM.SbatchArgumentsList = *oc.SbatchArguments
266 if oc.PollPeriod != nil {
267 cluster.Containers.CloudVMs.PollInterval = *oc.PollPeriod
269 if oc.PrioritySpread != nil {
270 cluster.Containers.SLURM.PrioritySpread = *oc.PrioritySpread
272 if oc.CrunchRunCommand != nil {
273 if len(*oc.CrunchRunCommand) >= 1 {
274 cluster.Containers.CrunchRunCommand = (*oc.CrunchRunCommand)[0]
276 if len(*oc.CrunchRunCommand) >= 2 {
277 cluster.Containers.CrunchRunArgumentsList = (*oc.CrunchRunCommand)[1:]
280 if oc.ReserveExtraRAM != nil {
281 cluster.Containers.ReserveExtraRAM = arvados.ByteSize(*oc.ReserveExtraRAM)
283 if oc.MinRetryPeriod != nil {
284 cluster.Containers.MinRetryPeriod = *oc.MinRetryPeriod
286 if oc.BatchSize != nil {
287 cluster.API.MaxItemsPerResponse = int(*oc.BatchSize)
290 cfg.Clusters[cluster.ClusterID] = *cluster
294 type oldWsConfig struct {
295 Client *arvados.Client
296 Postgres *arvados.PostgreSQLConnection
302 PingTimeout *arvados.Duration
303 ClientEventQueue *int
304 ServerEventQueue *int
306 ManagementToken *string
309 const defaultWebsocketConfigPath = "/etc/arvados/ws/ws.yml"
311 // update config using values from an crunch-dispatch-slurm config file.
312 func (ldr *Loader) loadOldWebsocketConfig(cfg *arvados.Config) error {
313 if ldr.WebsocketPath == "" {
317 err := ldr.loadOldConfigHelper("arvados-ws", ldr.WebsocketPath, &oc)
318 if os.IsNotExist(err) && ldr.WebsocketPath == defaultWebsocketConfigPath {
320 } else if err != nil {
324 cluster, err := cfg.GetCluster("")
329 loadOldClientConfig(cluster, oc.Client)
331 if oc.Postgres != nil {
332 cluster.PostgreSQL.Connection = *oc.Postgres
334 if oc.PostgresPool != nil {
335 cluster.PostgreSQL.ConnectionPool = *oc.PostgresPool
337 if oc.Listen != nil {
338 cluster.Services.Websocket.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
340 if oc.LogLevel != nil {
341 cluster.SystemLogs.LogLevel = *oc.LogLevel
343 if oc.LogFormat != nil {
344 cluster.SystemLogs.Format = *oc.LogFormat
346 if oc.PingTimeout != nil {
347 cluster.API.SendTimeout = *oc.PingTimeout
349 if oc.ClientEventQueue != nil {
350 cluster.API.WebsocketClientEventQueue = *oc.ClientEventQueue
352 if oc.ServerEventQueue != nil {
353 cluster.API.WebsocketServerEventQueue = *oc.ServerEventQueue
355 if oc.ManagementToken != nil {
356 cluster.ManagementToken = *oc.ManagementToken
359 cfg.Clusters[cluster.ClusterID] = *cluster
363 type oldKeepProxyConfig struct {
364 Client *arvados.Client
369 Timeout *arvados.Duration
372 ManagementToken *string
375 const defaultKeepproxyConfigPath = "/etc/arvados/keepproxy/keepproxy.yml"
377 func (ldr *Loader) loadOldKeepproxyConfig(cfg *arvados.Config) error {
378 if ldr.KeepproxyPath == "" {
381 var oc oldKeepProxyConfig
382 err := ldr.loadOldConfigHelper("keepproxy", ldr.KeepproxyPath, &oc)
383 if os.IsNotExist(err) && ldr.KeepproxyPath == defaultKeepproxyConfigPath {
385 } else if err != nil {
389 cluster, err := cfg.GetCluster("")
394 loadOldClientConfig(cluster, oc.Client)
396 if oc.Listen != nil {
397 cluster.Services.Keepproxy.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
399 if oc.DefaultReplicas != nil {
400 cluster.Collections.DefaultReplication = *oc.DefaultReplicas
402 if oc.Timeout != nil {
403 cluster.API.KeepServiceRequestTimeout = *oc.Timeout
406 if *oc.Debug && cluster.SystemLogs.LogLevel != "debug" {
407 cluster.SystemLogs.LogLevel = "debug"
408 } else if !*oc.Debug && cluster.SystemLogs.LogLevel != "info" {
409 cluster.SystemLogs.LogLevel = "info"
412 if oc.ManagementToken != nil {
413 cluster.ManagementToken = *oc.ManagementToken
416 // The following legacy options are no longer supported. If they are set to
417 // true or PIDFile has a value, error out and notify the user
418 unsupportedEntry := func(cfgEntry string) error {
419 return fmt.Errorf("the keepproxy %s configuration option is no longer supported, please remove it from your configuration file", cfgEntry)
421 if oc.DisableGet != nil && *oc.DisableGet {
422 return unsupportedEntry("DisableGet")
424 if oc.DisablePut != nil && *oc.DisablePut {
425 return unsupportedEntry("DisablePut")
427 if oc.PIDFile != nil && *oc.PIDFile != "" {
428 return unsupportedEntry("PIDFile")
431 cfg.Clusters[cluster.ClusterID] = *cluster
435 const defaultKeepWebConfigPath = "/etc/arvados/keep-web/keep-web.yml"
437 type oldKeepWebConfig struct {
438 Client *arvados.Client
442 AnonymousTokens *[]string
443 AttachmentOnlyHost *string
444 TrustAllContent *bool
447 TTL *arvados.Duration
448 UUIDTTL *arvados.Duration
449 MaxCollectionEntries *int
450 MaxCollectionBytes *int64
454 // Hack to support old command line flag, which is a bool
455 // meaning "get actual token from environment".
456 deprecatedAllowAnonymous *bool
458 // Authorization token to be included in all health check requests.
459 ManagementToken *string
462 func (ldr *Loader) loadOldKeepWebConfig(cfg *arvados.Config) error {
463 if ldr.KeepWebPath == "" {
466 var oc oldKeepWebConfig
467 err := ldr.loadOldConfigHelper("keep-web", ldr.KeepWebPath, &oc)
468 if os.IsNotExist(err) && ldr.KeepWebPath == defaultKeepWebConfigPath {
470 } else if err != nil {
474 cluster, err := cfg.GetCluster("")
479 loadOldClientConfig(cluster, oc.Client)
481 if oc.Listen != nil {
482 cluster.Services.WebDAV.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
483 cluster.Services.WebDAVDownload.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
485 if oc.AttachmentOnlyHost != nil {
486 cluster.Services.WebDAVDownload.ExternalURL = arvados.URL{Host: *oc.AttachmentOnlyHost, Path: "/"}
488 if oc.ManagementToken != nil {
489 cluster.ManagementToken = *oc.ManagementToken
491 if oc.TrustAllContent != nil {
492 cluster.Collections.TrustAllContent = *oc.TrustAllContent
494 if oc.Cache.TTL != nil {
495 cluster.Collections.WebDAVCache.TTL = *oc.Cache.TTL
497 if oc.Cache.UUIDTTL != nil {
498 cluster.Collections.WebDAVCache.UUIDTTL = *oc.Cache.UUIDTTL
500 if oc.Cache.MaxCollectionEntries != nil {
501 cluster.Collections.WebDAVCache.MaxCollectionEntries = *oc.Cache.MaxCollectionEntries
503 if oc.Cache.MaxCollectionBytes != nil {
504 cluster.Collections.WebDAVCache.MaxCollectionBytes = *oc.Cache.MaxCollectionBytes
506 if oc.Cache.MaxUUIDEntries != nil {
507 cluster.Collections.WebDAVCache.MaxUUIDEntries = *oc.Cache.MaxUUIDEntries
509 if oc.AnonymousTokens != nil {
510 if len(*oc.AnonymousTokens) > 0 {
511 cluster.Users.AnonymousUserToken = (*oc.AnonymousTokens)[0]
512 if len(*oc.AnonymousTokens) > 1 {
513 ldr.Logger.Warn("More than 1 anonymous tokens configured, using only the first and discarding the rest.")
518 cfg.Clusters[cluster.ClusterID] = *cluster
522 const defaultGitHttpdConfigPath = "/etc/arvados/git-httpd/git-httpd.yml"
524 type oldGitHttpdConfig struct {
525 Client *arvados.Client
530 ManagementToken *string
533 func (ldr *Loader) loadOldGitHttpdConfig(cfg *arvados.Config) error {
534 if ldr.GitHttpdPath == "" {
537 var oc oldGitHttpdConfig
538 err := ldr.loadOldConfigHelper("arv-git-httpd", ldr.GitHttpdPath, &oc)
539 if os.IsNotExist(err) && ldr.GitHttpdPath == defaultGitHttpdConfigPath {
541 } else if err != nil {
545 cluster, err := cfg.GetCluster("")
550 loadOldClientConfig(cluster, oc.Client)
552 if oc.Listen != nil {
553 cluster.Services.GitHTTP.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
555 if oc.ManagementToken != nil {
556 cluster.ManagementToken = *oc.ManagementToken
558 if oc.GitCommand != nil {
559 cluster.Git.GitCommand = *oc.GitCommand
561 if oc.GitoliteHome != nil {
562 cluster.Git.GitoliteHome = *oc.GitoliteHome
564 if oc.RepoRoot != nil {
565 cluster.Git.Repositories = *oc.RepoRoot
568 cfg.Clusters[cluster.ClusterID] = *cluster
572 const defaultKeepBalanceConfigPath = "/etc/arvados/keep-balance/keep-balance.yml"
574 type oldKeepBalanceConfig struct {
575 Client *arvados.Client
577 KeepServiceTypes *[]string
578 KeepServiceList *arvados.KeepServiceList
579 RunPeriod *arvados.Duration
580 CollectionBatchSize *int
581 CollectionBuffers *int
582 RequestTimeout *arvados.Duration
583 LostBlocksFile *string
584 ManagementToken *string
587 func (ldr *Loader) loadOldKeepBalanceConfig(cfg *arvados.Config) error {
588 if ldr.KeepBalancePath == "" {
591 var oc oldKeepBalanceConfig
592 err := ldr.loadOldConfigHelper("keep-balance", ldr.KeepBalancePath, &oc)
593 if os.IsNotExist(err) && ldr.KeepBalancePath == defaultKeepBalanceConfigPath {
595 } else if err != nil {
599 cluster, err := cfg.GetCluster("")
604 loadOldClientConfig(cluster, oc.Client)
606 if oc.Listen != nil {
607 cluster.Services.Keepbalance.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
609 if oc.ManagementToken != nil {
610 cluster.ManagementToken = *oc.ManagementToken
612 if oc.RunPeriod != nil {
613 cluster.Collections.BalancePeriod = *oc.RunPeriod
615 if oc.LostBlocksFile != nil {
616 cluster.Collections.BlobMissingReport = *oc.LostBlocksFile
618 if oc.CollectionBatchSize != nil {
619 cluster.Collections.BalanceCollectionBatch = *oc.CollectionBatchSize
621 if oc.CollectionBuffers != nil {
622 cluster.Collections.BalanceCollectionBuffers = *oc.CollectionBuffers
624 if oc.RequestTimeout != nil {
625 cluster.API.KeepServiceRequestTimeout = *oc.RequestTimeout
628 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."
630 // If the keep service type provided is "disk" silently ignore it, since
631 // this is what ends up being done anyway.
632 if oc.KeepServiceTypes != nil {
633 numTypes := len(*oc.KeepServiceTypes)
634 if numTypes != 0 && !(numTypes == 1 && (*oc.KeepServiceTypes)[0] == "disk") {
635 return fmt.Errorf(msg, "KeepServiceTypes")
639 if oc.KeepServiceList != nil {
640 return fmt.Errorf(msg, "KeepServiceList")
643 cfg.Clusters[cluster.ClusterID] = *cluster
647 func (ldr *Loader) loadOldEnvironmentVariables(cfg *arvados.Config) error {
648 if os.Getenv("ARVADOS_API_TOKEN") == "" && os.Getenv("ARVADOS_API_HOST") == "" {
651 cluster, err := cfg.GetCluster("")
655 if tok := os.Getenv("ARVADOS_API_TOKEN"); tok != "" && cluster.SystemRootToken == "" {
656 ldr.Logger.Warn("SystemRootToken missing from cluster config, falling back to ARVADOS_API_TOKEN environment variable")
657 cluster.SystemRootToken = tok
659 if apihost := os.Getenv("ARVADOS_API_HOST"); apihost != "" && cluster.Services.Controller.ExternalURL.Host == "" {
660 ldr.Logger.Warn("Services.Controller.ExternalURL missing from cluster config, falling back to ARVADOS_API_HOST(_INSECURE) environment variables")
661 u, err := url.Parse("https://" + apihost)
663 return fmt.Errorf("cannot parse ARVADOS_API_HOST: %s", err)
665 cluster.Services.Controller.ExternalURL = arvados.URL(*u)
666 if i := os.Getenv("ARVADOS_API_HOST_INSECURE"); i != "" && i != "0" {
667 cluster.TLS.Insecure = true
670 cfg.Clusters[cluster.ClusterID] = *cluster