X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/42bc78f2f1e9017fff31799e521b61730d53976f..a7631a1ccb6e2a6925d00a06562e171c4ce4ea2f:/services/api/config/arvados_config.rb diff --git a/services/api/config/arvados_config.rb b/services/api/config/arvados_config.rb index 841ec4cca3..4f831160e9 100644 --- a/services/api/config/arvados_config.rb +++ b/services/api/config/arvados_config.rb @@ -16,7 +16,9 @@ # config:migrate to /etc/arvados/config.yml, you will be able to # delete application.yml and database.yml. +require "cgi" require 'config_loader' +require 'open3' begin # If secret_token.rb exists here, we need to load it first. @@ -36,44 +38,57 @@ EOS # Real values will be copied from globals by omniauth_init.rb. For # now, assign some strings so the generic *.yml config loader # doesn't overwrite them or complain that they're missing. - Rails.configuration.Login["ProviderAppID"] = 'xxx' - Rails.configuration.Login["ProviderAppSecret"] = 'xxx' + Rails.configuration.Login["SSO"]["ProviderAppID"] = 'xxx' + Rails.configuration.Login["SSO"]["ProviderAppSecret"] = 'xxx' Rails.configuration.Services["SSO"]["ExternalURL"] = '//xxx' WARNED_OMNIAUTH_CONFIG = true end -# Load the defaults -$arvados_config_defaults = ConfigLoader.load "#{::Rails.root.to_s}/config/config.default.yml" -if $arvados_config_defaults.empty? - raise "Missing #{::Rails.root.to_s}/config/config.default.yml" +# Load the defaults, used by config:migrate and fallback loading +# legacy application.yml +Open3.popen2("arvados-server", "config-dump", "-config=-", "-skip-legacy") do |stdin, stdout, status_thread| + stdin.write("Clusters: {xxxxx: {}}") + stdin.close + confs = YAML.load(stdout, deserialize_symbols: false) + clusterID, clusterConfig = confs["Clusters"].first + $arvados_config_defaults = clusterConfig + $arvados_config_defaults["ClusterID"] = clusterID end -clusterID, clusterConfig = $arvados_config_defaults["Clusters"].first -$arvados_config_defaults = clusterConfig -$arvados_config_defaults["ClusterID"] = clusterID - -# Initialize the global config with the defaults -$arvados_config_global = $arvados_config_defaults.deep_dup - # Load the global config file -confs = ConfigLoader.load "/etc/arvados/config.yml" -if !confs.empty? - clusterID, clusterConfig = confs["Clusters"].first - $arvados_config_global["ClusterID"] = clusterID - - # Copy the cluster config over the defaults - $arvados_config_global.deep_merge!(clusterConfig) +Open3.popen2("arvados-server", "config-dump", "-skip-legacy") do |stdin, stdout, status_thread| + confs = YAML.load(stdout, deserialize_symbols: false) + if confs && !confs.empty? + # config-dump merges defaults with user configuration, so every + # key should be set. + clusterID, clusterConfig = confs["Clusters"].first + $arvados_config_global = clusterConfig + $arvados_config_global["ClusterID"] = clusterID + else + # config-dump failed, assume we will be loading from legacy + # application.yml, initialize with defaults. + $arvados_config_global = $arvados_config_defaults.deep_dup + end end # Now make a copy $arvados_config = $arvados_config_global.deep_dup +def arrayToHash cfg, k, v + val = {} + v.each do |entry| + val[entry.to_s] = {} + end + ConfigLoader.set_cfg cfg, k, val +end + # Declare all our configuration items. arvcfg = ConfigLoader.new arvcfg.declare_config "ClusterID", NonemptyString, :uuid_prefix arvcfg.declare_config "ManagementToken", String, :ManagementToken +arvcfg.declare_config "SystemRootToken", String arvcfg.declare_config "Git.Repositories", String, :git_repositories_dir -arvcfg.declare_config "API.DisabledAPIs", Array, :disable_api_methods +arvcfg.declare_config "API.DisabledAPIs", Hash, :disable_api_methods, ->(cfg, k, v) { arrayToHash cfg, "API.DisabledAPIs", v } arvcfg.declare_config "API.MaxRequestSize", Integer, :max_request_size arvcfg.declare_config "API.MaxIndexDatabaseRead", Integer, :max_index_database_read arvcfg.declare_config "API.MaxItemsPerResponse", Integer, :max_items_per_response @@ -82,7 +97,7 @@ arvcfg.declare_config "API.RailsSessionSecretToken", NonemptyString, :secret_tok arvcfg.declare_config "Users.AutoSetupNewUsers", Boolean, :auto_setup_new_users arvcfg.declare_config "Users.AutoSetupNewUsersWithVmUUID", String, :auto_setup_new_users_with_vm_uuid arvcfg.declare_config "Users.AutoSetupNewUsersWithRepository", Boolean, :auto_setup_new_users_with_repository -arvcfg.declare_config "Users.AutoSetupUsernameBlacklist", Array, :auto_setup_name_blacklist +arvcfg.declare_config "Users.AutoSetupUsernameBlacklist", Hash, :auto_setup_name_blacklist, ->(cfg, k, v) { arrayToHash cfg, "Users.AutoSetupUsernameBlacklist", v } arvcfg.declare_config "Users.NewUsersAreActive", Boolean, :new_users_are_active arvcfg.declare_config "Users.AutoAdminUserWithEmail", String, :auto_admin_user arvcfg.declare_config "Users.AutoAdminFirstUser", Boolean, :auto_admin_first_user @@ -90,15 +105,18 @@ arvcfg.declare_config "Users.UserProfileNotificationAddress", String, :user_prof arvcfg.declare_config "Users.AdminNotifierEmailFrom", String, :admin_notifier_email_from arvcfg.declare_config "Users.EmailSubjectPrefix", String, :email_subject_prefix arvcfg.declare_config "Users.UserNotifierEmailFrom", String, :user_notifier_email_from -arvcfg.declare_config "Users.NewUserNotificationRecipients", Array, :new_user_notification_recipients -arvcfg.declare_config "Users.NewInactiveUserNotificationRecipients", Array, :new_inactive_user_notification_recipients -arvcfg.declare_config "Login.ProviderAppSecret", NonemptyString, :sso_app_secret -arvcfg.declare_config "Login.ProviderAppID", NonemptyString, :sso_app_id +arvcfg.declare_config "Users.NewUserNotificationRecipients", Hash, :new_user_notification_recipients, ->(cfg, k, v) { arrayToHash cfg, "Users.NewUserNotificationRecipients", v } +arvcfg.declare_config "Users.NewInactiveUserNotificationRecipients", Hash, :new_inactive_user_notification_recipients, method(:arrayToHash) +arvcfg.declare_config "Login.SSO.ProviderAppSecret", String, :sso_app_secret +arvcfg.declare_config "Login.SSO.ProviderAppID", String, :sso_app_id +arvcfg.declare_config "Login.LoginCluster", String +arvcfg.declare_config "Login.RemoteTokenRefresh", ActiveSupport::Duration +arvcfg.declare_config "Login.TokenLifetime", ActiveSupport::Duration arvcfg.declare_config "TLS.Insecure", Boolean, :sso_insecure -arvcfg.declare_config "Services.SSO.ExternalURL", NonemptyString, :sso_provider_url +arvcfg.declare_config "Services.SSO.ExternalURL", String, :sso_provider_url arvcfg.declare_config "AuditLogs.MaxAge", ActiveSupport::Duration, :max_audit_log_age arvcfg.declare_config "AuditLogs.MaxDeleteBatch", Integer, :max_audit_log_delete_batch -arvcfg.declare_config "AuditLogs.UnloggedAttributes", Array, :unlogged_attributes +arvcfg.declare_config "AuditLogs.UnloggedAttributes", Hash, :unlogged_attributes, ->(cfg, k, v) { arrayToHash cfg, "AuditLogs.UnloggedAttributes", v } arvcfg.declare_config "SystemLogs.MaxRequestLogParamsSize", Integer, :max_request_log_params_size arvcfg.declare_config "Collections.DefaultReplication", Integer, :default_collection_replication arvcfg.declare_config "Collections.DefaultTrashLifetime", ActiveSupport::Duration, :default_trash_lifetime @@ -106,9 +124,10 @@ arvcfg.declare_config "Collections.CollectionVersioning", Boolean, :collection_v arvcfg.declare_config "Collections.PreserveVersionIfIdle", ActiveSupport::Duration, :preserve_version_if_idle arvcfg.declare_config "Collections.TrashSweepInterval", ActiveSupport::Duration, :trash_sweep_interval arvcfg.declare_config "Collections.BlobSigningKey", NonemptyString, :blob_signing_key -arvcfg.declare_config "Collections.BlobSigningTTL", Integer, :blob_signature_ttl +arvcfg.declare_config "Collections.BlobSigningTTL", ActiveSupport::Duration, :blob_signature_ttl arvcfg.declare_config "Collections.BlobSigning", Boolean, :permit_create_collection_with_unsigned_manifest, ->(cfg, k, v) { ConfigLoader.set_cfg cfg, "Collections.BlobSigning", !v } -arvcfg.declare_config "Containers.SupportedDockerImageFormats", Array, :docker_image_formats +arvcfg.declare_config "Collections.ForwardSlashNameSubstitution", String +arvcfg.declare_config "Containers.SupportedDockerImageFormats", Hash, :docker_image_formats, ->(cfg, k, v) { arrayToHash cfg, "Containers.SupportedDockerImageFormats", v } arvcfg.declare_config "Containers.LogReuseDecisions", Boolean, :log_reuse_decisions arvcfg.declare_config "Containers.DefaultKeepCacheRAM", Integer, :container_default_keep_cache_ram arvcfg.declare_config "Containers.MaxDispatchAttempts", Integer, :max_container_dispatch_attempts @@ -130,15 +149,10 @@ arvcfg.declare_config "Containers.SLURM.Managed.DNSServerConfTemplate", Pathname arvcfg.declare_config "Containers.SLURM.Managed.DNSServerReloadCommand", String, :dns_server_reload_command arvcfg.declare_config "Containers.SLURM.Managed.DNSServerUpdateCommand", String, :dns_server_update_command arvcfg.declare_config "Containers.SLURM.Managed.ComputeNodeDomain", String, :compute_node_domain -arvcfg.declare_config "Containers.SLURM.Managed.ComputeNodeNameservers", Array, :compute_node_nameservers +arvcfg.declare_config "Containers.SLURM.Managed.ComputeNodeNameservers", Hash, :compute_node_nameservers, ->(cfg, k, v) { arrayToHash cfg, "Containers.SLURM.Managed.ComputeNodeNameservers", v } arvcfg.declare_config "Containers.SLURM.Managed.AssignNodeHostname", String, :assign_node_hostname arvcfg.declare_config "Containers.JobsAPI.Enable", String, :enable_legacy_jobs_api, ->(cfg, k, v) { ConfigLoader.set_cfg cfg, "Containers.JobsAPI.Enable", v.to_s } -arvcfg.declare_config "Containers.JobsAPI.CrunchJobWrapper", String, :crunch_job_wrapper -arvcfg.declare_config "Containers.JobsAPI.CrunchJobUser", String, :crunch_job_user -arvcfg.declare_config "Containers.JobsAPI.CrunchRefreshTrigger", String, :crunch_refresh_trigger arvcfg.declare_config "Containers.JobsAPI.GitInternalDir", String, :git_internal_dir -arvcfg.declare_config "Containers.JobsAPI.ReuseJobIfOutputsDiffer", Boolean, :reuse_job_if_outputs_differ -arvcfg.declare_config "Containers.JobsAPI.DefaultDockerImage", String, :default_docker_image_for_jobs arvcfg.declare_config "Mail.MailchimpAPIKey", String, :mailchimp_api_key arvcfg.declare_config "Mail.MailchimpListID", String, :mailchimp_list_id arvcfg.declare_config "Services.Controller.ExternalURL", URI @@ -171,13 +185,14 @@ arvcfg.declare_config "RemoteClusters.*.Proxy", Boolean, :remote_hosts_via_dns dbcfg = ConfigLoader.new dbcfg.declare_config "PostgreSQL.ConnectionPool", Integer, :pool -dbcfg.declare_config "PostgreSQL.Connection.Host", String, :host -dbcfg.declare_config "PostgreSQL.Connection.Port", Integer, :port -dbcfg.declare_config "PostgreSQL.Connection.User", String, :username -dbcfg.declare_config "PostgreSQL.Connection.Password", String, :password -dbcfg.declare_config "PostgreSQL.Connection.DBName", String, :database -dbcfg.declare_config "PostgreSQL.Connection.Template", String, :template -dbcfg.declare_config "PostgreSQL.Connection.Encoding", String, :encoding +dbcfg.declare_config "PostgreSQL.Connection.host", String, :host +dbcfg.declare_config "PostgreSQL.Connection.port", String, :port +dbcfg.declare_config "PostgreSQL.Connection.user", String, :username +dbcfg.declare_config "PostgreSQL.Connection.password", String, :password +dbcfg.declare_config "PostgreSQL.Connection.dbname", String, :database +dbcfg.declare_config "PostgreSQL.Connection.template", String, :template +dbcfg.declare_config "PostgreSQL.Connection.encoding", String, :encoding +dbcfg.declare_config "PostgreSQL.Connection.collation", String, :collation application_config = {} %w(application.default application).each do |cfgfile| @@ -191,7 +206,7 @@ end db_config = {} path = "#{::Rails.root.to_s}/config/database.yml" -if File.exist? path +if !ENV['ARVADOS_CONFIG_NOLEGACY'] && File.exist?(path) db_config = ConfigLoader.load(path, erb: true) end @@ -239,16 +254,23 @@ end # rails environments. # if ::Rails.env.to_s == "test" && db_config["test"].nil? - $arvados_config["PostgreSQL"]["Connection"]["DBName"] = "arvados_test" + $arvados_config["PostgreSQL"]["Connection"]["dbname"] = "arvados_test" +end +if ::Rails.env.to_s == "test" + # Use template0 when creating a new database. Avoids + # character-encoding/collation problems. + $arvados_config["PostgreSQL"]["Connection"]["template"] = "template0" + # Some test cases depend on en_US.UTF-8 collation. + $arvados_config["PostgreSQL"]["Connection"]["collation"] = "en_US.UTF-8" end -if $arvados_config["PostgreSQL"]["Connection"]["Password"].empty? +if $arvados_config["PostgreSQL"]["Connection"]["password"].empty? raise "Database password is empty, PostgreSQL section is: #{$arvados_config["PostgreSQL"]}" end -dbhost = $arvados_config["PostgreSQL"]["Connection"]["Host"] -if $arvados_config["PostgreSQL"]["Connection"]["Post"] != 0 - dbhost += ":#{$arvados_config["PostgreSQL"]["Connection"]["Post"]}" +dbhost = $arvados_config["PostgreSQL"]["Connection"]["host"] +if $arvados_config["PostgreSQL"]["Connection"]["port"] != 0 + dbhost += ":#{$arvados_config["PostgreSQL"]["Connection"]["port"]}" end # @@ -257,13 +279,16 @@ end # For config migration, we've previously populated the PostgreSQL # section of the config from database.yml # -ENV["DATABASE_URL"] = "postgresql://#{$arvados_config["PostgreSQL"]["Connection"]["User"]}:"+ - "#{$arvados_config["PostgreSQL"]["Connection"]["Password"]}@"+ - "#{dbhost}/#{$arvados_config["PostgreSQL"]["Connection"]["DBName"]}?"+ - "template=#{$arvados_config["PostgreSQL"]["Connection"]["Template"]}&"+ +database_url = "postgresql://#{CGI.escape $arvados_config["PostgreSQL"]["Connection"]["user"]}:"+ + "#{CGI.escape $arvados_config["PostgreSQL"]["Connection"]["password"]}@"+ + "#{dbhost}/#{CGI.escape $arvados_config["PostgreSQL"]["Connection"]["dbname"]}?"+ + "template=#{$arvados_config["PostgreSQL"]["Connection"]["template"]}&"+ "encoding=#{$arvados_config["PostgreSQL"]["Connection"]["client_encoding"]}&"+ + "collation=#{$arvados_config["PostgreSQL"]["Connection"]["collation"]}&"+ "pool=#{$arvados_config["PostgreSQL"]["ConnectionPool"]}" +ENV["DATABASE_URL"] = database_url + Server::Application.configure do # Copy into the Rails config object. This also turns Hash into # OrderedOptions so that application code can use