OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Allow locking of the seeded admin user (#17273)
Oliver Günthera13edc8a2576
diff --git a/app/seeders/root_seeder.rb b/app/seeders/root_seeder.rbindex f1a150e4723..0958652ca40 100644--- a/app/seeders/root_seeder.rb+++ b/app/seeders/root_seeder.rb@@ -75,6 +75,11 @@ class RootSeeder < Seederseed_development_data if seed_development_data?seed_plugins_dataseed_env_data+ cleanup_seed_data+ end++ def cleanup_seed_data+ admin_user.lock! if Setting.seed_admin_user_locked?enddef seed_development_data?diff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rbindex 16fe9e0705f..8c7c30a1bd6 100644--- a/config/constants/settings/definition.rb+++ b/config/constants/settings/definition.rb@@ -923,6 +923,12 @@ module Settingsdefault: "https://releases.openproject.com/v1/check.svg",writable: false},+ seed_admin_user_locked: {+ description: "Lock the created admin user after seeding, so it can not be used for logging in. " \+ "If set to true, an admin user has to be created manually or through an SSO provider.",+ default: false,+ writable: false+ },seed_admin_user_password: {description: 'Password to set for the initially created admin user (Login remains "admin").',default: "admin",diff --git a/docs/installation-and-operations/configuration/README.md b/docs/installation-and-operations/configuration/README.mdindex 839ec412458..8ff6d3f5867 100644--- a/docs/installation-and-operations/configuration/README.md+++ b/docs/installation-and-operations/configuration/README.md@@ -173,6 +173,18 @@ OPENPROJECT_SEED_ADMIN_USER_NAME="OpenProject Admin" # Name to assign to that usOPENPROJECT_SEED_ADMIN_USER_MAIL="[email protected]" # Email attribute to assign to that user. Note that in packaged installations, a wizard step will assign this variable as well.```+Optionally, you can also lock the admin user that gets created right away. This is useful when you have an LDAP or SSO integration set up and you want to prevent the admin user from logging in.++```shell++> [!WARNING]+> With the admin user seeding disabled, you need to have an LDAP or SSO integration set up through environment variables.+> Otherwise, you will not be able to retain access to the system.++```shell+OPENPROJECT_SEED_ADMIN_USER_LOCKED="true"+```+### Seeding LDAP connectionsOpenProject allows you to create and maintain an LDAP connection with optional synchronized group filters. This is relevant for e.g., automated deployments, where you want to trigger the synchronization right at the start.diff --git a/modules/bim/spec/seeders/root_seeder_bim_edition_spec.rb b/modules/bim/spec/seeders/root_seeder_bim_edition_spec.rbindex 1e4870b4a90..892c1ce4ebc 100644--- a/modules/bim/spec/seeders/root_seeder_bim_edition_spec.rb+++ b/modules/bim/spec/seeders/root_seeder_bim_edition_spec.rb@@ -249,4 +249,27 @@ RSpec.describe RootSeeder,include_examples "no email deliveries"end++ context "when admin user creation is locked with OPENPROJECT_SEED_ADMIN_USER_LOCKED=true",+ :settings_reset do+ shared_let(:root_seeder) { described_class.new }++ before_all do+ with_env("OPENPROJECT_SEED_ADMIN_USER_LOCKED" => "true") do+ with_edition("bim") do+ reset(:seed_admin_user_locked)+ root_seeder.seed_data!+ end+ end+ ensure+ reset(:seed_admin_user_locked)+ RequestStore.clear! # resets `User.current` cached result+ end++ it "seeds without any errors, but locks the admin user", :aggregate_failures do+ expect(Project.count).to eq 4+ expect(WorkPackage.count).to eq 76+ expect(root_seeder.admin_user).to be_locked+ end+ endenddiff --git a/spec/seeders/admin_user_seeder_spec.rb b/spec/seeders/admin_user_seeder_spec.rbindex 0dcb7960810..db1f4d1de5e 100644--- a/spec/seeders/admin_user_seeder_spec.rb+++ b/spec/seeders/admin_user_seeder_spec.rb@@ -56,6 +56,7 @@ RSpec.describe AdminUserSeeder doseeder.seed!admin = User.admin.last+ expect(admin).to be_activeexpect(admin.firstname).to eq "foo"expect(admin.lastname).to eq "bar"expect(admin.mail).to eq "[email protected]"diff --git a/spec/seeders/root_seeder_standard_edition_spec.rb b/spec/seeders/root_seeder_standard_edition_spec.rbindex af0561b82d9..9f416a03afe 100644--- a/spec/seeders/root_seeder_standard_edition_spec.rb+++ b/spec/seeders/root_seeder_standard_edition_spec.rb@@ -286,4 +286,27 @@ RSpec.describe RootSeeder,include_examples "no email deliveries"end++ context "when admin user creation is locked with OPENPROJECT_SEED_ADMIN_USER_LOCKED=true",+ :settings_reset do+ shared_let(:root_seeder) { described_class.new }++ before_all do+ with_env("OPENPROJECT_SEED_ADMIN_USER_LOCKED" => "true") do+ with_edition("standard") do+ reset(:seed_admin_user_locked)+ root_seeder.seed_data!+ end+ end+ ensure+ reset(:seed_admin_user_locked)+ RequestStore.clear! # resets `User.current` cached result+ end++ it "seeds without any errors, but locks the admin user", :aggregate_failures do+ expect(Project.count).to eq 2+ expect(WorkPackage.count).to eq 36+ expect(root_seeder.admin_user).to be_locked+ end+ endend