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 // Provider* moved to SSO.Provider*
107 if dst, n := &cluster.Login.SSO.ProviderAppID, dcluster.Login.ProviderAppID; n != nil && *n != *dst {
110 // In old config, non-empty ID meant enable
111 cluster.Login.SSO.Enable = true
114 if dst, n := &cluster.Login.SSO.ProviderAppSecret, dcluster.Login.ProviderAppSecret; n != nil && *n != *dst {
118 cfg.Clusters[id] = cluster
123 func (ldr *Loader) applyDeprecatedVolumeDriverParameters(cfg *arvados.Config) error {
124 for clusterID, cluster := range cfg.Clusters {
125 for volID, vol := range cluster.Volumes {
126 if vol.Driver == "S3" {
128 AccessKey string `json:",omitempty"`
129 SecretKey string `json:",omitempty"`
131 SecretAccessKey string
133 err := json.Unmarshal(vol.DriverParameters, ¶ms)
135 return fmt.Errorf("error loading %s.Volumes.%s.DriverParameters: %w", clusterID, volID, err)
137 if params.AccessKey != "" || params.SecretKey != "" {
138 if params.AccessKeyID != "" || params.SecretAccessKey != "" {
139 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)
142 var allparams map[string]interface{}
143 err = json.Unmarshal(vol.DriverParameters, &allparams)
145 return fmt.Errorf("error loading %s.Volumes.%s.DriverParameters: %w", clusterID, volID, err)
147 for k := range allparams {
148 if lk := strings.ToLower(k); lk == "accesskey" || lk == "secretkey" {
152 ldr.Logger.Warnf("using your old config keys %s.Volumes.%s.DriverParameters.AccessKey/SecretKey -- but you should rename them to AccessKeyID/SecretAccessKey", clusterID, volID)
153 allparams["AccessKeyID"] = params.AccessKey
154 allparams["SecretAccessKey"] = params.SecretKey
155 vol.DriverParameters, err = json.Marshal(allparams)
159 cluster.Volumes[volID] = vol
167 func applyDeprecatedNodeProfile(hostname string, ssi systemServiceInstance, svc *arvados.Service) {
172 if svc.InternalURLs == nil {
173 svc.InternalURLs = map[arvados.URL]arvados.ServiceInstance{}
179 if strings.HasPrefix(host, ":") {
180 host = hostname + host
182 svc.InternalURLs[arvados.URL{Scheme: scheme, Host: host, Path: "/"}] = arvados.ServiceInstance{}
185 func (ldr *Loader) loadOldConfigHelper(component, path string, target interface{}) error {
189 buf, err := ioutil.ReadFile(path)
194 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)
196 err = yaml.Unmarshal(buf, target)
198 return fmt.Errorf("%s: %s", path, err)
203 type oldCrunchDispatchSlurmConfig struct {
204 Client *arvados.Client
206 SbatchArguments *[]string
207 PollPeriod *arvados.Duration
208 PrioritySpread *int64
210 // crunch-run command to invoke. The container UUID will be
211 // appended. If nil, []string{"crunch-run"} will be used.
213 // Example: []string{"crunch-run", "--cgroup-parent-subsystem=memory"}
214 CrunchRunCommand *[]string
216 // Extra RAM to reserve (in Bytes) for SLURM job, in addition
217 // to the amount specified in the container's RuntimeConstraints
218 ReserveExtraRAM *int64
220 // Minimum time between two attempts to run the same container
221 MinRetryPeriod *arvados.Duration
223 // Batch size for container queries
227 const defaultCrunchDispatchSlurmConfigPath = "/etc/arvados/crunch-dispatch-slurm/crunch-dispatch-slurm.yml"
229 func loadOldClientConfig(cluster *arvados.Cluster, client *arvados.Client) {
233 if client.APIHost != "" {
234 cluster.Services.Controller.ExternalURL.Host = client.APIHost
235 cluster.Services.Controller.ExternalURL.Path = "/"
237 if client.Scheme != "" {
238 cluster.Services.Controller.ExternalURL.Scheme = client.Scheme
240 cluster.Services.Controller.ExternalURL.Scheme = "https"
242 if client.AuthToken != "" {
243 cluster.SystemRootToken = client.AuthToken
245 cluster.TLS.Insecure = client.Insecure
247 for i, u := range client.KeepServiceURIs {
253 cluster.Containers.SLURM.SbatchEnvironmentVariables = map[string]string{"ARVADOS_KEEP_SERVICES": ks}
256 // update config using values from an crunch-dispatch-slurm config file.
257 func (ldr *Loader) loadOldCrunchDispatchSlurmConfig(cfg *arvados.Config) error {
258 if ldr.CrunchDispatchSlurmPath == "" {
261 var oc oldCrunchDispatchSlurmConfig
262 err := ldr.loadOldConfigHelper("crunch-dispatch-slurm", ldr.CrunchDispatchSlurmPath, &oc)
263 if os.IsNotExist(err) && (ldr.CrunchDispatchSlurmPath == defaultCrunchDispatchSlurmConfigPath) {
265 } else if err != nil {
269 cluster, err := cfg.GetCluster("")
274 loadOldClientConfig(cluster, oc.Client)
276 if oc.SbatchArguments != nil {
277 cluster.Containers.SLURM.SbatchArgumentsList = *oc.SbatchArguments
279 if oc.PollPeriod != nil {
280 cluster.Containers.CloudVMs.PollInterval = *oc.PollPeriod
282 if oc.PrioritySpread != nil {
283 cluster.Containers.SLURM.PrioritySpread = *oc.PrioritySpread
285 if oc.CrunchRunCommand != nil {
286 if len(*oc.CrunchRunCommand) >= 1 {
287 cluster.Containers.CrunchRunCommand = (*oc.CrunchRunCommand)[0]
289 if len(*oc.CrunchRunCommand) >= 2 {
290 cluster.Containers.CrunchRunArgumentsList = (*oc.CrunchRunCommand)[1:]
293 if oc.ReserveExtraRAM != nil {
294 cluster.Containers.ReserveExtraRAM = arvados.ByteSize(*oc.ReserveExtraRAM)
296 if oc.MinRetryPeriod != nil {
297 cluster.Containers.MinRetryPeriod = *oc.MinRetryPeriod
299 if oc.BatchSize != nil {
300 cluster.API.MaxItemsPerResponse = int(*oc.BatchSize)
303 cfg.Clusters[cluster.ClusterID] = *cluster
307 type oldWsConfig struct {
308 Client *arvados.Client
309 Postgres *arvados.PostgreSQLConnection
315 PingTimeout *arvados.Duration
316 ClientEventQueue *int
317 ServerEventQueue *int
319 ManagementToken *string
322 const defaultWebsocketConfigPath = "/etc/arvados/ws/ws.yml"
324 // update config using values from an crunch-dispatch-slurm config file.
325 func (ldr *Loader) loadOldWebsocketConfig(cfg *arvados.Config) error {
326 if ldr.WebsocketPath == "" {
330 err := ldr.loadOldConfigHelper("arvados-ws", ldr.WebsocketPath, &oc)
331 if os.IsNotExist(err) && ldr.WebsocketPath == defaultWebsocketConfigPath {
333 } else if err != nil {
337 cluster, err := cfg.GetCluster("")
342 loadOldClientConfig(cluster, oc.Client)
344 if oc.Postgres != nil {
345 cluster.PostgreSQL.Connection = *oc.Postgres
347 if oc.PostgresPool != nil {
348 cluster.PostgreSQL.ConnectionPool = *oc.PostgresPool
350 if oc.Listen != nil {
351 cluster.Services.Websocket.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
353 if oc.LogLevel != nil {
354 cluster.SystemLogs.LogLevel = *oc.LogLevel
356 if oc.LogFormat != nil {
357 cluster.SystemLogs.Format = *oc.LogFormat
359 if oc.PingTimeout != nil {
360 cluster.API.SendTimeout = *oc.PingTimeout
362 if oc.ClientEventQueue != nil {
363 cluster.API.WebsocketClientEventQueue = *oc.ClientEventQueue
365 if oc.ServerEventQueue != nil {
366 cluster.API.WebsocketServerEventQueue = *oc.ServerEventQueue
368 if oc.ManagementToken != nil {
369 cluster.ManagementToken = *oc.ManagementToken
372 cfg.Clusters[cluster.ClusterID] = *cluster
376 type oldKeepProxyConfig struct {
377 Client *arvados.Client
382 Timeout *arvados.Duration
385 ManagementToken *string
388 const defaultKeepproxyConfigPath = "/etc/arvados/keepproxy/keepproxy.yml"
390 func (ldr *Loader) loadOldKeepproxyConfig(cfg *arvados.Config) error {
391 if ldr.KeepproxyPath == "" {
394 var oc oldKeepProxyConfig
395 err := ldr.loadOldConfigHelper("keepproxy", ldr.KeepproxyPath, &oc)
396 if os.IsNotExist(err) && ldr.KeepproxyPath == defaultKeepproxyConfigPath {
398 } else if err != nil {
402 cluster, err := cfg.GetCluster("")
407 loadOldClientConfig(cluster, oc.Client)
409 if oc.Listen != nil {
410 cluster.Services.Keepproxy.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
412 if oc.DefaultReplicas != nil {
413 cluster.Collections.DefaultReplication = *oc.DefaultReplicas
415 if oc.Timeout != nil {
416 cluster.API.KeepServiceRequestTimeout = *oc.Timeout
419 if *oc.Debug && cluster.SystemLogs.LogLevel != "debug" {
420 cluster.SystemLogs.LogLevel = "debug"
421 } else if !*oc.Debug && cluster.SystemLogs.LogLevel != "info" {
422 cluster.SystemLogs.LogLevel = "info"
425 if oc.ManagementToken != nil {
426 cluster.ManagementToken = *oc.ManagementToken
429 // The following legacy options are no longer supported. If they are set to
430 // true or PIDFile has a value, error out and notify the user
431 unsupportedEntry := func(cfgEntry string) error {
432 return fmt.Errorf("the keepproxy %s configuration option is no longer supported, please remove it from your configuration file", cfgEntry)
434 if oc.DisableGet != nil && *oc.DisableGet {
435 return unsupportedEntry("DisableGet")
437 if oc.DisablePut != nil && *oc.DisablePut {
438 return unsupportedEntry("DisablePut")
440 if oc.PIDFile != nil && *oc.PIDFile != "" {
441 return unsupportedEntry("PIDFile")
444 cfg.Clusters[cluster.ClusterID] = *cluster
448 const defaultKeepWebConfigPath = "/etc/arvados/keep-web/keep-web.yml"
450 type oldKeepWebConfig struct {
451 Client *arvados.Client
455 AnonymousTokens *[]string
456 AttachmentOnlyHost *string
457 TrustAllContent *bool
460 TTL *arvados.Duration
461 UUIDTTL *arvados.Duration
462 MaxCollectionEntries *int
463 MaxCollectionBytes *int64
464 MaxPermissionEntries *int
468 // Hack to support old command line flag, which is a bool
469 // meaning "get actual token from environment".
470 deprecatedAllowAnonymous *bool
472 // Authorization token to be included in all health check requests.
473 ManagementToken *string
476 func (ldr *Loader) loadOldKeepWebConfig(cfg *arvados.Config) error {
477 if ldr.KeepWebPath == "" {
480 var oc oldKeepWebConfig
481 err := ldr.loadOldConfigHelper("keep-web", ldr.KeepWebPath, &oc)
482 if os.IsNotExist(err) && ldr.KeepWebPath == defaultKeepWebConfigPath {
484 } else if err != nil {
488 cluster, err := cfg.GetCluster("")
493 loadOldClientConfig(cluster, oc.Client)
495 if oc.Listen != nil {
496 cluster.Services.WebDAV.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
497 cluster.Services.WebDAVDownload.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
499 if oc.AttachmentOnlyHost != nil {
500 cluster.Services.WebDAVDownload.ExternalURL = arvados.URL{Host: *oc.AttachmentOnlyHost, Path: "/"}
502 if oc.ManagementToken != nil {
503 cluster.ManagementToken = *oc.ManagementToken
505 if oc.TrustAllContent != nil {
506 cluster.Collections.TrustAllContent = *oc.TrustAllContent
508 if oc.Cache.TTL != nil {
509 cluster.Collections.WebDAVCache.TTL = *oc.Cache.TTL
511 if oc.Cache.UUIDTTL != nil {
512 cluster.Collections.WebDAVCache.UUIDTTL = *oc.Cache.UUIDTTL
514 if oc.Cache.MaxCollectionEntries != nil {
515 cluster.Collections.WebDAVCache.MaxCollectionEntries = *oc.Cache.MaxCollectionEntries
517 if oc.Cache.MaxCollectionBytes != nil {
518 cluster.Collections.WebDAVCache.MaxCollectionBytes = *oc.Cache.MaxCollectionBytes
520 if oc.Cache.MaxPermissionEntries != nil {
521 cluster.Collections.WebDAVCache.MaxPermissionEntries = *oc.Cache.MaxPermissionEntries
523 if oc.Cache.MaxUUIDEntries != nil {
524 cluster.Collections.WebDAVCache.MaxUUIDEntries = *oc.Cache.MaxUUIDEntries
526 if oc.AnonymousTokens != nil {
527 if len(*oc.AnonymousTokens) > 0 {
528 cluster.Users.AnonymousUserToken = (*oc.AnonymousTokens)[0]
529 if len(*oc.AnonymousTokens) > 1 {
530 ldr.Logger.Warn("More than 1 anonymous tokens configured, using only the first and discarding the rest.")
535 cfg.Clusters[cluster.ClusterID] = *cluster
539 const defaultGitHttpdConfigPath = "/etc/arvados/git-httpd/git-httpd.yml"
541 type oldGitHttpdConfig struct {
542 Client *arvados.Client
547 ManagementToken *string
550 func (ldr *Loader) loadOldGitHttpdConfig(cfg *arvados.Config) error {
551 if ldr.GitHttpdPath == "" {
554 var oc oldGitHttpdConfig
555 err := ldr.loadOldConfigHelper("arv-git-httpd", ldr.GitHttpdPath, &oc)
556 if os.IsNotExist(err) && ldr.GitHttpdPath == defaultGitHttpdConfigPath {
558 } else if err != nil {
562 cluster, err := cfg.GetCluster("")
567 loadOldClientConfig(cluster, oc.Client)
569 if oc.Listen != nil {
570 cluster.Services.GitHTTP.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
572 if oc.ManagementToken != nil {
573 cluster.ManagementToken = *oc.ManagementToken
575 if oc.GitCommand != nil {
576 cluster.Git.GitCommand = *oc.GitCommand
578 if oc.GitoliteHome != nil {
579 cluster.Git.GitoliteHome = *oc.GitoliteHome
581 if oc.RepoRoot != nil {
582 cluster.Git.Repositories = *oc.RepoRoot
585 cfg.Clusters[cluster.ClusterID] = *cluster
589 const defaultKeepBalanceConfigPath = "/etc/arvados/keep-balance/keep-balance.yml"
591 type oldKeepBalanceConfig struct {
592 Client *arvados.Client
594 KeepServiceTypes *[]string
595 KeepServiceList *arvados.KeepServiceList
596 RunPeriod *arvados.Duration
597 CollectionBatchSize *int
598 CollectionBuffers *int
599 RequestTimeout *arvados.Duration
600 LostBlocksFile *string
601 ManagementToken *string
604 func (ldr *Loader) loadOldKeepBalanceConfig(cfg *arvados.Config) error {
605 if ldr.KeepBalancePath == "" {
608 var oc oldKeepBalanceConfig
609 err := ldr.loadOldConfigHelper("keep-balance", ldr.KeepBalancePath, &oc)
610 if os.IsNotExist(err) && ldr.KeepBalancePath == defaultKeepBalanceConfigPath {
612 } else if err != nil {
616 cluster, err := cfg.GetCluster("")
621 loadOldClientConfig(cluster, oc.Client)
623 if oc.Listen != nil {
624 cluster.Services.Keepbalance.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
626 if oc.ManagementToken != nil {
627 cluster.ManagementToken = *oc.ManagementToken
629 if oc.RunPeriod != nil {
630 cluster.Collections.BalancePeriod = *oc.RunPeriod
632 if oc.LostBlocksFile != nil {
633 cluster.Collections.BlobMissingReport = *oc.LostBlocksFile
635 if oc.CollectionBatchSize != nil {
636 cluster.Collections.BalanceCollectionBatch = *oc.CollectionBatchSize
638 if oc.CollectionBuffers != nil {
639 cluster.Collections.BalanceCollectionBuffers = *oc.CollectionBuffers
641 if oc.RequestTimeout != nil {
642 cluster.API.KeepServiceRequestTimeout = *oc.RequestTimeout
645 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."
647 // If the keep service type provided is "disk" silently ignore it, since
648 // this is what ends up being done anyway.
649 if oc.KeepServiceTypes != nil {
650 numTypes := len(*oc.KeepServiceTypes)
651 if numTypes != 0 && !(numTypes == 1 && (*oc.KeepServiceTypes)[0] == "disk") {
652 return fmt.Errorf(msg, "KeepServiceTypes")
656 if oc.KeepServiceList != nil {
657 return fmt.Errorf(msg, "KeepServiceList")
660 cfg.Clusters[cluster.ClusterID] = *cluster
664 func (ldr *Loader) loadOldEnvironmentVariables(cfg *arvados.Config) error {
665 if os.Getenv("ARVADOS_API_TOKEN") == "" && os.Getenv("ARVADOS_API_HOST") == "" {
668 cluster, err := cfg.GetCluster("")
672 if tok := os.Getenv("ARVADOS_API_TOKEN"); tok != "" && cluster.SystemRootToken == "" {
673 ldr.Logger.Warn("SystemRootToken missing from cluster config, falling back to ARVADOS_API_TOKEN environment variable")
674 cluster.SystemRootToken = tok
676 if apihost := os.Getenv("ARVADOS_API_HOST"); apihost != "" && cluster.Services.Controller.ExternalURL.Host == "" {
677 ldr.Logger.Warn("Services.Controller.ExternalURL missing from cluster config, falling back to ARVADOS_API_HOST(_INSECURE) environment variables")
678 u, err := url.Parse("https://" + apihost)
680 return fmt.Errorf("cannot parse ARVADOS_API_HOST: %s", err)
682 cluster.Services.Controller.ExternalURL = arvados.URL(*u)
683 if i := os.Getenv("ARVADOS_API_HOST_INSECURE"); i != "" && i != "0" {
684 cluster.TLS.Insecure = true
687 cfg.Clusters[cluster.ClusterID] = *cluster