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.MaxCollectionBytes != nil {
498 cluster.Collections.WebDAVCache.MaxCollectionBytes = arvados.ByteSize(*oc.Cache.MaxCollectionBytes)
500 if oc.AnonymousTokens != nil {
501 if len(*oc.AnonymousTokens) > 0 {
502 cluster.Users.AnonymousUserToken = (*oc.AnonymousTokens)[0]
503 if len(*oc.AnonymousTokens) > 1 {
504 ldr.Logger.Warn("More than 1 anonymous tokens configured, using only the first and discarding the rest.")
509 cfg.Clusters[cluster.ClusterID] = *cluster
513 const defaultGitHttpdConfigPath = "/etc/arvados/git-httpd/git-httpd.yml"
515 type oldGitHttpdConfig struct {
516 Client *arvados.Client
521 ManagementToken *string
524 func (ldr *Loader) loadOldGitHttpdConfig(cfg *arvados.Config) error {
525 if ldr.GitHttpdPath == "" {
528 var oc oldGitHttpdConfig
529 err := ldr.loadOldConfigHelper("arvados-git-httpd", ldr.GitHttpdPath, &oc)
530 if os.IsNotExist(err) && ldr.GitHttpdPath == defaultGitHttpdConfigPath {
532 } else if err != nil {
536 cluster, err := cfg.GetCluster("")
541 loadOldClientConfig(cluster, oc.Client)
543 if oc.Listen != nil {
544 cluster.Services.GitHTTP.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
546 if oc.ManagementToken != nil {
547 cluster.ManagementToken = *oc.ManagementToken
549 if oc.GitCommand != nil {
550 cluster.Git.GitCommand = *oc.GitCommand
552 if oc.GitoliteHome != nil {
553 cluster.Git.GitoliteHome = *oc.GitoliteHome
555 if oc.RepoRoot != nil {
556 cluster.Git.Repositories = *oc.RepoRoot
559 cfg.Clusters[cluster.ClusterID] = *cluster
563 const defaultKeepBalanceConfigPath = "/etc/arvados/keep-balance/keep-balance.yml"
565 type oldKeepBalanceConfig struct {
566 Client *arvados.Client
568 KeepServiceTypes *[]string
569 KeepServiceList *arvados.KeepServiceList
570 RunPeriod *arvados.Duration
571 CollectionBatchSize *int
572 CollectionBuffers *int
573 RequestTimeout *arvados.Duration
574 LostBlocksFile *string
575 ManagementToken *string
578 func (ldr *Loader) loadOldKeepBalanceConfig(cfg *arvados.Config) error {
579 if ldr.KeepBalancePath == "" {
582 var oc oldKeepBalanceConfig
583 err := ldr.loadOldConfigHelper("keep-balance", ldr.KeepBalancePath, &oc)
584 if os.IsNotExist(err) && ldr.KeepBalancePath == defaultKeepBalanceConfigPath {
586 } else if err != nil {
590 cluster, err := cfg.GetCluster("")
595 loadOldClientConfig(cluster, oc.Client)
597 if oc.Listen != nil {
598 cluster.Services.Keepbalance.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
600 if oc.ManagementToken != nil {
601 cluster.ManagementToken = *oc.ManagementToken
603 if oc.RunPeriod != nil {
604 cluster.Collections.BalancePeriod = *oc.RunPeriod
606 if oc.LostBlocksFile != nil {
607 cluster.Collections.BlobMissingReport = *oc.LostBlocksFile
609 if oc.CollectionBatchSize != nil {
610 cluster.Collections.BalanceCollectionBatch = *oc.CollectionBatchSize
612 if oc.CollectionBuffers != nil {
613 cluster.Collections.BalanceCollectionBuffers = *oc.CollectionBuffers
615 if oc.RequestTimeout != nil {
616 cluster.API.KeepServiceRequestTimeout = *oc.RequestTimeout
619 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."
621 // If the keep service type provided is "disk" silently ignore it, since
622 // this is what ends up being done anyway.
623 if oc.KeepServiceTypes != nil {
624 numTypes := len(*oc.KeepServiceTypes)
625 if numTypes != 0 && !(numTypes == 1 && (*oc.KeepServiceTypes)[0] == "disk") {
626 return fmt.Errorf(msg, "KeepServiceTypes")
630 if oc.KeepServiceList != nil {
631 return fmt.Errorf(msg, "KeepServiceList")
634 cfg.Clusters[cluster.ClusterID] = *cluster
638 func (ldr *Loader) loadOldEnvironmentVariables(cfg *arvados.Config) error {
639 if os.Getenv("ARVADOS_API_TOKEN") == "" && os.Getenv("ARVADOS_API_HOST") == "" {
642 cluster, err := cfg.GetCluster("")
646 if tok := os.Getenv("ARVADOS_API_TOKEN"); tok != "" && cluster.SystemRootToken == "" {
647 ldr.Logger.Warn("SystemRootToken missing from cluster config, falling back to ARVADOS_API_TOKEN environment variable")
648 cluster.SystemRootToken = tok
650 if apihost := os.Getenv("ARVADOS_API_HOST"); apihost != "" && cluster.Services.Controller.ExternalURL.Host == "" {
651 ldr.Logger.Warn("Services.Controller.ExternalURL missing from cluster config, falling back to ARVADOS_API_HOST(_INSECURE) environment variables")
652 u, err := url.Parse("https://" + apihost)
654 return fmt.Errorf("cannot parse ARVADOS_API_HOST: %s", err)
656 cluster.Services.Controller.ExternalURL = arvados.URL(*u)
657 if i := os.Getenv("ARVADOS_API_HOST_INSECURE"); i != "" && i != "0" {
658 cluster.TLS.Insecure = true
661 cfg.Clusters[cluster.ClusterID] = *cluster