19513: Add Users.CreateRoleGroups config option.
authorTom Clegg <tom@curii.com>
Wed, 23 Nov 2022 19:42:23 +0000 (14:42 -0500)
committerTom Clegg <tom@curii.com>
Wed, 23 Nov 2022 19:42:23 +0000 (14:42 -0500)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

doc/user/topics/arvados-sync-external-sources.html.textile.liquid
lib/config/config.default.yml
lib/config/export.go
sdk/go/arvados/config.go
services/api/app/models/group.rb
services/api/config/arvados_config.rb
services/api/test/unit/group_test.rb

index 0ec0098f053aa0b4d53c5a133bc00c1ed2325f58..d84995d5bd3a34b46aa3700d580ffd7579c61586 100644 (file)
@@ -65,6 +65,8 @@ Users can be identified by their email address or username: the tool will check
 
 Permission level can be one of the following: @can_read@, @can_write@ or @can_manage@, giving the group member read, read/write or managing privileges on the group. For backwards compatibility purposes, if any record omits the third (permission) field, it will default to @can_write@ permission. You can read more about permissions on the "group management admin guide":{{ site.baseurl }}/admin/group-management.html.
 
+When using @arvados-sync-groups@, consider setting @Users.CreateRoleGroups: false@ in your "cluster configuration":{{site.baseurl}}/admin/config.html to prevent users from creating additional groups.
+
 h2. Options
 
 The following command line options are supported:
index 0246cb88d5736e158bb1f502d91423b7b7072832..1a0191797ad925b95b228b8211a703476bc8cc02 100644 (file)
@@ -373,6 +373,12 @@ Clusters:
       # cluster.
       RoleGroupsVisibleToAll: true
 
+      # If CreateRoleGroups is true, regular (non-admin) users can
+      # create new role groups.
+      #
+      # If false, only admins can create new role groups.
+      CreateRoleGroups: true
+
       # During each period, a log entry with event_type="activity"
       # will be recorded for each user who is active during that
       # period. The object_uuid attribute will indicate the user's
index 6352406e90e95dc255d9eb43ff1ca13f0e721fd1..14139e85044fb354884004906b0e3b674762e00d 100644 (file)
@@ -236,6 +236,7 @@ var whitelist = map[string]bool{
        "Users.AutoSetupNewUsersWithRepository":               false,
        "Users.AutoSetupNewUsersWithVmUUID":                   false,
        "Users.AutoSetupUsernameBlacklist":                    false,
+       "Users.CreateRoleGroups":                              true,
        "Users.EmailSubjectPrefix":                            false,
        "Users.NewInactiveUserNotificationRecipients":         false,
        "Users.NewUserNotificationRecipients":                 false,
index 2871356e9827059352026432082c5fcdee2f3fce..1257d7a838d9b5774d50dcd72dd8df3a1c4b5035 100644 (file)
@@ -249,6 +249,7 @@ type Cluster struct {
                PreferDomainForUsername               string
                UserSetupMailText                     string
                RoleGroupsVisibleToAll                bool
+               CreateRoleGroups                      bool
                ActivityLoggingPeriod                 Duration
        }
        StorageClasses map[string]StorageClassConfig
index e44e605b16b842e1bd5c4fbe61d7820ef62b8cff..81161e24dab7bfc9f6525afd6d94dbe56c391281 100644 (file)
@@ -268,6 +268,18 @@ class Group < ArvadosModel
     end
   end
 
+  def permission_to_create
+    if !super
+      return false
+    elsif group_class == "role" &&
+       !Rails.configuration.Users.CreateRoleGroups &&
+       !current_user.andand.is_admin
+      raise PermissionDeniedError.new("this cluster does not allow users to create role groups")
+    else
+      return true
+    end
+  end
+
   def permission_to_update
     if !super
       return false
index c0f7ee174fb65f8ef34d8502cc78d26e104f50ef..a7abf819cbed666f425e39584bcfc7900656c42d 100644 (file)
@@ -106,6 +106,7 @@ arvcfg.declare_config "Users.UserNotifierEmailFrom", String, :user_notifier_emai
 arvcfg.declare_config "Users.UserNotifierEmailBcc", Hash
 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 "Users.CreateRoleGroups", Boolean
 arvcfg.declare_config "Users.RoleGroupsVisibleToAll", Boolean
 arvcfg.declare_config "Login.LoginCluster", String
 arvcfg.declare_config "Login.TrustedClients", Hash
index a3bcd4e3568acea466bc52a743cd108b59a8bcc0..33ad0ecdf62cc5c1e4b60dfde3ceed27777334bb 100644 (file)
@@ -532,4 +532,24 @@ update links set tail_uuid='#{g5}' where uuid='#{l1.uuid}'
       assert proj.update_attributes(frozen_by_uuid: users(:active).uuid)
     end
   end
+
+  [
+    [false, :admin, true],
+    [false, :active, false],
+    [true, :admin, true],
+    [true, :active, true],
+  ].each do |conf, user, allowed|
+    test "config.Users.CreateRoleGroups conf=#{conf}, user=#{user}" do
+      Rails.configuration.Users.CreateRoleGroups = conf
+      act_as_user users(user) do
+        if allowed
+          Group.create!(name: 'admin-created', group_class: 'role')
+        else
+          assert_raises(ArvadosModel::PermissionDeniedError) do
+            Group.create!(name: 'user-created', group_class: 'role')
+          end
+        end
+      end
+    end
+  end
 end