You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2020/06/09 15:55:06 UTC

[GitHub] [cloudstack] sureshanaparti opened a new pull request #4071: Dynamic roles improvements

sureshanaparti opened a new pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti commented on a change in pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#discussion_r448845603



##########
File path: api/src/main/java/org/apache/cloudstack/api/command/admin/acl/UpdateRoleCmd.java
##########
@@ -67,13 +63,6 @@ public String getRoleName() {
         return roleName;
     }
 
-    public RoleType getRoleType() {
-        if (!Strings.isNullOrEmpty(roleType)) {
-            return RoleType.fromString(roleType);
-        }
-        return null;
-    }
-
     public String getRoleDescription() {

Review comment:
       > Since roleType and roleDescription have been moved to RoleCmd class, can we not remove getRoleDescription() from this class?
   
   thanks @Pearl1594, missed this one. updated.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti commented on a change in pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#discussion_r433411189



##########
File path: engine/schema/src/main/resources/META-INF/db/schema-41310to41400.sql
##########
@@ -379,3 +379,81 @@ CREATE TABLE IF NOT EXISTS `cloud`.`kubernetes_cluster_details` (
     PRIMARY KEY(`id`),
     CONSTRAINT `fk_kubernetes_cluster_details__cluster_id` FOREIGN KEY `fk_kubernetes_cluster_details__cluster_id`(`cluster_id`) REFERENCES `kubernetes_cluster`(`id`) ON DELETE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+ALTER TABLE `cloud`.`roles` ADD COLUMN `is_default` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'is this a default role';
+UPDATE `cloud`.`roles` SET `is_default` = 1 WHERE id IN (1, 2, 3, 4);
+
+-- Updated Default CloudStack roles with read-only and support admin and user roles
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'Read-Only Admin', 'Admin', 'Default read-only admin role', 1) ON DUPLICATE KEY UPDATE name=name;

Review comment:
       this is in sync with existing default roles with id (1,2,3,4). Shall I prepend all these role names with "Default" ? 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti commented on a change in pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#discussion_r433405275



##########
File path: api/src/main/java/org/apache/cloudstack/api/command/admin/acl/ImportRoleCmd.java
##########
@@ -0,0 +1,139 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.cloudstack.api.command.admin.acl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cloudstack.acl.Role;
+import org.apache.cloudstack.acl.RoleType;
+import org.apache.cloudstack.acl.Rule;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiArgValidator;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.RoleResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.commons.collections.MapUtils;
+
+import com.cloud.user.Account;
+import com.google.common.base.Strings;
+
+@APICommand(name = ImportRoleCmd.APINAME, description = "Imports a role", responseObject = RoleResponse.class,

Review comment:
       > nit - Make description more verbose, something like 'Imports a role based on provided map of rule permissions...'
   
   Updated




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] borisstoyanov commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
borisstoyanov commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-652874308


   @blueorangutan package


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-653370522


   @borisstoyanov a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] rhtyd commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
rhtyd commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-644578371


   @blueorangutan test


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti commented on a change in pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#discussion_r433404787



##########
File path: server/src/main/java/org/apache/cloudstack/acl/RoleManagerImpl.java
##########
@@ -159,9 +242,6 @@ public Role updateRole(final Role role, final String name, final RoleType roleTy
             roleVO.setName(name);
         }
         if (roleType != null) {
-            if (role.getId() <= RoleType.User.getId()) {

Review comment:
       @rhtyd agree that the role ids are compared against the role type enum earlier. now these roles, with ids (1,2,3,4) are marked as default roles, which is considered while updating or deleting the role. The `role` is already populated with db details.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] rhtyd commented on a change in pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
rhtyd commented on a change in pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#discussion_r439288648



##########
File path: api/src/main/java/org/apache/cloudstack/api/command/admin/acl/ImportRoleCmd.java
##########
@@ -0,0 +1,139 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.cloudstack.api.command.admin.acl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cloudstack.acl.Role;
+import org.apache.cloudstack.acl.RoleType;
+import org.apache.cloudstack.acl.Rule;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiArgValidator;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.RoleResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.commons.collections.MapUtils;
+
+import com.cloud.user.Account;
+import com.google.common.base.Strings;
+
+@APICommand(name = ImportRoleCmd.APINAME, description = "Imports a role based on provided map of rule permissions", responseObject = RoleResponse.class,
+        requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
+        since = "4.15.0",
+        authorized = {RoleType.Admin})
+public class ImportRoleCmd extends RoleCmd {
+    public static final String APINAME = "importRole";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true,
+            description = "Creates a role with this unique name", validations = {ApiArgValidator.NotNullOrEmpty})
+    private String roleName;
+
+    @Parameter(name = ApiConstants.RULES, type = CommandType.MAP, required = true,
+            description = "Rules param list, rule and permission is must. Example: rules[0].rule=create*&rules[0].permission=allow&rules[0].description=create%20rule&rules[1].rule=list*&rules[1].permission=allow&rules[1].description=listing")
+    private Map rules;
+
+    @Parameter(name = ApiConstants.FORCED, type = CommandType.BOOLEAN,
+            description = "Force create a role with the same name. This overrides the role type, description and rule permissions for the existing role. Default is false.")
+    private Boolean forced;
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+    public String getRoleName() {
+        return roleName;
+    }
+
+    public List<Map<String, Object>> getRules() {
+        if (MapUtils.isEmpty(rules)) {
+            return null;
+        }
+

Review comment:
       @sureshanaparti why not process rules and convert into a list of TOs/VOs, or something simpler that service layer can easily consume? Can you make the iteration logic simpler? Thanks.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti commented on a change in pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#discussion_r433406006



##########
File path: engine/schema/src/main/resources/META-INF/db/schema-41310to41400-cleanup.sql
##########
@@ -26,3 +26,6 @@ UPDATE `cloud`.`storage_pool` SET path="/var/lib/libvirt/images" WHERE path="/va
 
 -- remove (one of) duplicate unique indexes from Region table
 ALTER TABLE `region` DROP INDEX `id_3`;
+
+-- remove the old NetApp storage APIs (unsupported since 4.12) from role_permissions
+DELETE from `cloud`.`role_permissions` WHERE rule IN ('createPool', 'modifyPool', 'deletePool', 'listPools', 'associateLun', 'dissociateLun', 'createLunOnFiler', 'destroyLunOnFiler', 'listLunsOnFiler', 'createVolumeOnFiler', 'destroyVolumeOnFiler', 'listVolumesOnFiler');

Review comment:
       > We want the DB changes in the 4.14 -> 4.15 upgrade path.
   
   Moved to 4.15 upgrade path




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] rhtyd commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
rhtyd commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-644551264


   @sureshanaparti I've converted the PR to draft, until testing concludes so we don't accidently merge this cc @borisstoyanov @vladimirpetrov
   @blueorangutan package


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-641077045






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-644578750


   @rhtyd a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] rhtyd commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
rhtyd commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-643061308


   Thanks @sureshanaparti I'll do another review pass and ping you.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti commented on a change in pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#discussion_r433405404



##########
File path: api/src/main/java/org/apache/cloudstack/api/command/admin/acl/ImportRoleCmd.java
##########
@@ -0,0 +1,139 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.cloudstack.api.command.admin.acl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cloudstack.acl.Role;
+import org.apache.cloudstack.acl.RoleType;
+import org.apache.cloudstack.acl.Rule;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiArgValidator;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.RoleResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.commons.collections.MapUtils;
+
+import com.cloud.user.Account;
+import com.google.common.base.Strings;
+
+@APICommand(name = ImportRoleCmd.APINAME, description = "Imports a role", responseObject = RoleResponse.class,
+        requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
+        since = "4.15.0",
+        authorized = {RoleType.Admin})
+public class ImportRoleCmd extends RoleCmd {
+    public static final String APINAME = "importRole";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true,
+            description = "Creates a role with this unique name", validations = {ApiArgValidator.NotNullOrEmpty})
+    private String roleName;
+
+    @Parameter(name = ApiConstants.RULES, type = CommandType.MAP, required = true,
+            description = "Rules param list, rule and permission is must. Example: rules[0].rule=create*&rules[0].permission=allow&rules[0].description=create%20rule&rules[1].rule=list*&rules[1].permission=allow&rules[1].description=listing")
+    private Map rules;
+
+    @Parameter(name = ApiConstants.FORCED, type = CommandType.BOOLEAN,
+            description = "Force create a role")

Review comment:
       > nit - fix description to say what happens in case of a role name matches (i.e. explain for the users that it will override/replace the previosly created role with the provided parameters).
   
   Updated




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti commented on a change in pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#discussion_r433400535



##########
File path: api/src/main/java/org/apache/cloudstack/api/response/RoleResponse.java
##########
@@ -43,6 +43,10 @@
     @Param(description = "the description of the role")
     private String roleDescription;
 
+    @SerializedName(ApiConstants.IS_DEFAULT)
+    @Param(description = "true if role is default, false otherwise")

Review comment:
       default meaning this role(s) comes by default with cloudstack installation / upgrade. "default" used, in sync with similar usage at the offerings, accounts in CS.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti commented on a change in pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#discussion_r439926852



##########
File path: server/src/main/java/org/apache/cloudstack/acl/RoleManagerImpl.java
##########
@@ -146,10 +150,89 @@ public RoleVO doInTransaction(TransactionStatus status) {
         });
     }
 
+    @Override
+    @ActionEvent(eventType = EventTypes.EVENT_ROLE_CREATE, eventDescription = "creating Role")

Review comment:
       > Should the description say we're creating a role by cloning another role ?
   
   Updated event description




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-652896068


   Packaging result: ✔centos7 ✔debian. JID-1504


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-642456966


   @blueorangutan package


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] rhtyd commented on a change in pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
rhtyd commented on a change in pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#discussion_r439285205



##########
File path: engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41400to41500.java
##########
@@ -235,6 +238,267 @@ private void updateSystemVmTemplates(final Connection conn) {
         LOG.debug("Updating System Vm Template IDs Complete");
     }
 
+    private void addRolePermissionsForNewReadOnlyAndSupportRoles(final Connection conn) {
+        addRolePermissionsForReadOnlyAdmin(conn);
+        addRolePermissionsForReadOnlyUser(conn);
+        addRolePermissionsForAdminSupport(conn);
+        addRolePermissionsForUserSupport(conn);

Review comment:
       Minor nit - can we call the role 'SupportAdmin' and 'SupportUser'? 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti commented on a change in pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#discussion_r439926785



##########
File path: engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41400to41500.java
##########
@@ -235,6 +238,267 @@ private void updateSystemVmTemplates(final Connection conn) {
         LOG.debug("Updating System Vm Template IDs Complete");
     }
 
+    private void addRolePermissionsForNewReadOnlyAndSupportRoles(final Connection conn) {
+        addRolePermissionsForReadOnlyAdmin(conn);
+        addRolePermissionsForReadOnlyUser(conn);
+        addRolePermissionsForAdminSupport(conn);
+        addRolePermissionsForUserSupport(conn);
+    }
+
+    private void addRolePermissionsForReadOnlyAdmin(final Connection conn) {
+        LOG.debug("Adding role permissions for new read-only admin role");
+        try {
+            PreparedStatement pstmt = conn.prepareStatement("SELECT id FROM `cloud`.`roles` WHERE name = 'Read-Only Admin (Default)' AND is_default = 1");
+            ResultSet rs = pstmt.executeQuery();
+            if (rs.next()) {
+                long readOnlyAdminRoleId = rs.getLong(1);
+                int readOnlyAdminSortOrder = 0;
+                List<String> insertSqlForReadOnlyAdminRolePermissions = new ArrayList<String>();
+                insertSqlForReadOnlyAdminRolePermissions.add("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, 'list*', 'ALLOW', ?) ON DUPLICATE KEY UPDATE rule=rule");
+                insertSqlForReadOnlyAdminRolePermissions.add("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, 'getUploadParamsFor*', 'DENY', ?) ON DUPLICATE KEY UPDATE rule=rule");
+                insertSqlForReadOnlyAdminRolePermissions.add("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, 'get*', 'ALLOW', ?) ON DUPLICATE KEY UPDATE rule=rule");
+                insertSqlForReadOnlyAdminRolePermissions.add("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, 'cloudianIsEnabled', 'ALLOW', ?) ON DUPLICATE KEY UPDATE rule=rule");
+                insertSqlForReadOnlyAdminRolePermissions.add("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, 'quotaIsEnabled', 'ALLOW', ?) ON DUPLICATE KEY UPDATE rule=rule");
+                insertSqlForReadOnlyAdminRolePermissions.add("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, 'quotaTariffList', 'ALLOW', ?) ON DUPLICATE KEY UPDATE rule=rule");
+                insertSqlForReadOnlyAdminRolePermissions.add("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, 'quotaSummary', 'ALLOW', ?) ON DUPLICATE KEY UPDATE rule=rule");
+                insertSqlForReadOnlyAdminRolePermissions.add("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, '*', 'DENY', ?) ON DUPLICATE KEY UPDATE rule=rule");
+
+                for(String insertSqlForReadOnlyAdmin : insertSqlForReadOnlyAdminRolePermissions) {
+                    pstmt = conn.prepareStatement(insertSqlForReadOnlyAdmin);
+                    pstmt.setLong(1, readOnlyAdminRoleId);
+                    pstmt.setLong(2, readOnlyAdminSortOrder++);
+                    pstmt.executeUpdate();
+                }
+            }
+
+            if (rs != null && !rs.isClosed())  {
+                rs.close();
+            }
+            if (pstmt != null && !pstmt.isClosed())  {
+                pstmt.close();
+            }
+            LOG.debug("Successfully added role permissions for new read-only admin role");
+        } catch (final SQLException e) {
+            LOG.error("Exception while adding role permissions for read-only admin role: " + e.getMessage());
+            throw new CloudRuntimeException("Exception while adding role permissions for read-only admin role: " + e.getMessage(), e);
+        }
+    }
+
+    private void addRolePermissionsForReadOnlyUser(final Connection conn) {
+        LOG.debug("Adding role permissions for new read-only user role");
+        try {
+            PreparedStatement pstmt = conn.prepareStatement("SELECT id FROM `cloud`.`roles` WHERE name = 'Read-Only User (Default)' AND is_default = 1");
+            ResultSet rs = pstmt.executeQuery();
+            if (rs.next()) {
+                long readOnlyUserRoleId = rs.getLong(1);
+                int readOnlyUserSortOrder = 0;
+
+                pstmt = conn.prepareStatement("SELECT rule FROM `cloud`.`role_permissions` WHERE role_id = 4 AND permission = 'ALLOW' AND rule LIKE 'list%' ORDER BY sort_order");
+                ResultSet rsRolePermissions = pstmt.executeQuery();
+
+                while (rsRolePermissions.next()) {
+                    String rule = rsRolePermissions.getString(1);
+                    pstmt = conn.prepareStatement("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, ?, 'ALLOW', ?) ON DUPLICATE KEY UPDATE rule=rule");
+                    pstmt.setLong(1, readOnlyUserRoleId);
+                    pstmt.setString(2, rule);
+                    pstmt.setLong(3, readOnlyUserSortOrder++);
+                    pstmt.executeUpdate();
+                }
+
+                pstmt = conn.prepareStatement("SELECT rule FROM `cloud`.`role_permissions` WHERE role_id = 4 AND permission = 'ALLOW' AND rule LIKE 'get%' AND rule NOT LIKE 'getUploadParamsFor%' ORDER BY sort_order");
+                rsRolePermissions = pstmt.executeQuery();
+
+                while (rsRolePermissions.next()) {
+                    String rule = rsRolePermissions.getString(1);
+                    pstmt = conn.prepareStatement("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, ?, 'ALLOW', ?) ON DUPLICATE KEY UPDATE rule=rule");
+                    pstmt.setLong(1, readOnlyUserRoleId);
+                    pstmt.setString(2, rule);
+                    pstmt.setLong(3, readOnlyUserSortOrder++);
+                    pstmt.executeUpdate();
+                }
+
+                List<String> insertSqlForReadOnlyUserRolePermissions = new ArrayList<String>();
+                insertSqlForReadOnlyUserRolePermissions.add("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, 'cloudianIsEnabled', 'ALLOW', ?) ON DUPLICATE KEY UPDATE rule=rule");
+                insertSqlForReadOnlyUserRolePermissions.add("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, 'quotaIsEnabled', 'ALLOW', ?) ON DUPLICATE KEY UPDATE rule=rule");
+                insertSqlForReadOnlyUserRolePermissions.add("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, 'quotaTariffList', 'ALLOW', ?) ON DUPLICATE KEY UPDATE rule=rule");
+                insertSqlForReadOnlyUserRolePermissions.add("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, 'quotaSummary', 'ALLOW', ?) ON DUPLICATE KEY UPDATE rule=rule");
+                insertSqlForReadOnlyUserRolePermissions.add("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, '*', 'DENY', ?) ON DUPLICATE KEY UPDATE rule=rule");
+
+                for(String insertSqlForReadOnlyUser : insertSqlForReadOnlyUserRolePermissions) {
+                    pstmt = conn.prepareStatement(insertSqlForReadOnlyUser);
+                    pstmt.setLong(1, readOnlyUserRoleId);
+                    pstmt.setLong(2, readOnlyUserSortOrder++);
+                    pstmt.executeUpdate();
+                }
+
+                if (rsRolePermissions != null && !rsRolePermissions.isClosed())  {
+                    rsRolePermissions.close();
+                }
+            }
+
+            if (rs != null && !rs.isClosed())  {
+                rs.close();
+            }
+            if (pstmt != null && !pstmt.isClosed())  {
+                pstmt.close();
+            }
+            LOG.debug("Successfully added role permissions for new read-only user role");
+        } catch (final SQLException e) {
+            LOG.error("Exception while adding role permissions for read-only user role: " + e.getMessage());
+            throw new CloudRuntimeException("Exception while adding role permissions for read-only user role: " + e.getMessage(), e);
+        }
+    }
+
+    private void addRolePermissionsForAdminSupport(final Connection conn) {
+        LOG.debug("Adding role permissions for new admin support role");
+        try {
+            PreparedStatement pstmt = conn.prepareStatement("SELECT id FROM `cloud`.`roles` WHERE name = 'Admin-Support (Default)' AND is_default = 1");
+            ResultSet rs = pstmt.executeQuery();
+            if (rs.next()) {
+                long adminSupportRoleId = rs.getLong(1);
+                int adminSupportSortOrder = 0;
+
+                pstmt = conn.prepareStatement("SELECT id FROM `cloud`.`roles` WHERE name = 'Read-Only Admin (Default)' AND is_default = 1");
+                ResultSet rsReadOnlyAdmin = pstmt.executeQuery();
+                if (rsReadOnlyAdmin.next()) {
+                    long readOnlyAdminRoleId = rsReadOnlyAdmin.getLong(1);
+                    pstmt = conn.prepareStatement("SELECT rule FROM `cloud`.`role_permissions` WHERE role_id = ? AND permission = 'ALLOW' ORDER BY sort_order");
+                    pstmt.setLong(1, readOnlyAdminRoleId);
+                    ResultSet rsRolePermissions = pstmt.executeQuery();
+
+                    while (rsRolePermissions.next()) {
+                        String rule = rsRolePermissions.getString(1);
+                        pstmt = conn.prepareStatement("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, ?, 'ALLOW', ?) ON DUPLICATE KEY UPDATE rule=rule");
+                        pstmt.setLong(1, adminSupportRoleId);
+                        pstmt.setString(2, rule);
+                        pstmt.setLong(3, adminSupportSortOrder++);
+                        pstmt.executeUpdate();
+                    }
+
+                    List<String> insertSqlForAdminSupportRolePermissions = new ArrayList<String>();
+                    insertSqlForAdminSupportRolePermissions.add("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, 'prepareHostForMaintenance', 'ALLOW', ?) ON DUPLICATE KEY UPDATE rule=rule");

Review comment:
       > nit - Could be made less verbose by doing a loop on the API strings and add the string to the collection/list. Same for other parts of code.
   
   Updated with API rules




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-642469454


   Packaging result: ✔centos7 ✔debian. JID-1337


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti commented on a change in pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#discussion_r433407021



##########
File path: engine/schema/src/main/resources/META-INF/db/schema-41310to41400.sql
##########
@@ -379,3 +379,81 @@ CREATE TABLE IF NOT EXISTS `cloud`.`kubernetes_cluster_details` (
     PRIMARY KEY(`id`),
     CONSTRAINT `fk_kubernetes_cluster_details__cluster_id` FOREIGN KEY `fk_kubernetes_cluster_details__cluster_id`(`cluster_id`) REFERENCES `kubernetes_cluster`(`id`) ON DELETE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+ALTER TABLE `cloud`.`roles` ADD COLUMN `is_default` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'is this a default role';
+UPDATE `cloud`.`roles` SET `is_default` = 1 WHERE id IN (1, 2, 3, 4);
+
+-- Updated Default CloudStack roles with read-only and support admin and user roles
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'Read-Only Admin', 'Admin', 'Default read-only admin role', 1) ON DUPLICATE KEY UPDATE name=name;
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'Read-Only User', 'User', 'Default read-only user role', 1) ON DUPLICATE KEY UPDATE name=name;
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'Admin-Support', 'Admin', 'Default admin support role', 1) ON DUPLICATE KEY UPDATE name=name;
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'User-Support', 'User', 'Default user support role', 1) ON DUPLICATE KEY UPDATE name=name;
+
+-- Role permissions for Read-Only Admin
+SELECT id INTO @ReadOnlyAdminRoleId FROM `cloud`.`roles` WHERE name = 'Read-Only Admin' AND is_default = 1;
+SELECT @ReadOnlyAdminSortOrder:=-1;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'list*', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'getUploadParamsFor*', 'DENY', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'get*', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'cloudianIsEnabled', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'quotaIsEnabled', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'quotaTariffList', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'quotaSummary', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, '*', 'DENY', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+
+-- Role permissions for Read-Only User
+SELECT id INTO @ReadOnlyUserRoleId FROM `cloud`.`roles` WHERE name = 'Read-Only User' AND is_default = 1;
+SELECT @ReadOnlyUserSortOrder:=-1;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) SELECT UUID(), @ReadOnlyUserRoleId, rule, 'ALLOW', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1 FROM `cloud`.`role_permissions` WHERE role_id = 4 AND permission = 'ALLOW' AND rule LIKE 'list%';

Review comment:
       > Should the `rule` here be `list*` or `get*` etc.? Or was `rule` declared somewhere I missed ?
   
   the 'list*' and 'get*' rules for the User role are added for read-only user




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti commented on a change in pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#discussion_r433398348



##########
File path: api/src/main/java/org/apache/cloudstack/api/command/admin/acl/RoleCmd.java
##########
@@ -18,11 +18,41 @@
 package org.apache.cloudstack.api.command.admin.acl;
 
 import org.apache.cloudstack.acl.Role;
+import org.apache.cloudstack.acl.RoleType;
+import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.response.RoleResponse;
 
+import com.google.common.base.Strings;
+
 public abstract class RoleCmd extends BaseCmd {
 
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @Parameter(name = ApiConstants.TYPE, type = CommandType.STRING, description = "The type of the role, valid options are: Admin, ResourceAdmin, DomainAdmin, User")
+    private String roleType;

Review comment:
       > I get the reuse with the createRole API, but do we want these parameters for the updateRole API?
   
   yep, UpdateRoleCmd also inherits the same RoleCmd.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] Pearl1594 commented on a change in pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
Pearl1594 commented on a change in pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#discussion_r448112372



##########
File path: api/src/main/java/org/apache/cloudstack/api/command/admin/acl/UpdateRoleCmd.java
##########
@@ -67,13 +63,6 @@ public String getRoleName() {
         return roleName;
     }
 
-    public RoleType getRoleType() {
-        if (!Strings.isNullOrEmpty(roleType)) {
-            return RoleType.fromString(roleType);
-        }
-        return null;
-    }
-
     public String getRoleDescription() {

Review comment:
       Since roleType and roleDescription have been moved to RoleCmd class, can we not remove getRoleDescription() from this class?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-637032225


   > First pass review, no major issues; mostly logistics/cosmetics/nits.
   > Please ping after addressing @sureshanaparti Thanks.
   
   @rhyd addressed the comments, please take a look. thanks.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti commented on a change in pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#discussion_r433412427



##########
File path: engine/schema/src/main/resources/META-INF/db/schema-41310to41400.sql
##########
@@ -379,3 +379,81 @@ CREATE TABLE IF NOT EXISTS `cloud`.`kubernetes_cluster_details` (
     PRIMARY KEY(`id`),
     CONSTRAINT `fk_kubernetes_cluster_details__cluster_id` FOREIGN KEY `fk_kubernetes_cluster_details__cluster_id`(`cluster_id`) REFERENCES `kubernetes_cluster`(`id`) ON DELETE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+ALTER TABLE `cloud`.`roles` ADD COLUMN `is_default` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'is this a default role';
+UPDATE `cloud`.`roles` SET `is_default` = 1 WHERE id IN (1, 2, 3, 4);
+
+-- Updated Default CloudStack roles with read-only and support admin and user roles
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'Read-Only Admin', 'Admin', 'Default read-only admin role', 1) ON DUPLICATE KEY UPDATE name=name;
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'Read-Only User', 'User', 'Default read-only user role', 1) ON DUPLICATE KEY UPDATE name=name;
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'Admin-Support', 'Admin', 'Default admin support role', 1) ON DUPLICATE KEY UPDATE name=name;
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'User-Support', 'User', 'Default user support role', 1) ON DUPLICATE KEY UPDATE name=name;
+
+-- Role permissions for Read-Only Admin
+SELECT id INTO @ReadOnlyAdminRoleId FROM `cloud`.`roles` WHERE name = 'Read-Only Admin' AND is_default = 1;
+SELECT @ReadOnlyAdminSortOrder:=-1;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'list*', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'getUploadParamsFor*', 'DENY', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'get*', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'cloudianIsEnabled', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'quotaIsEnabled', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'quotaTariffList', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'quotaSummary', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, '*', 'DENY', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+
+-- Role permissions for Read-Only User
+SELECT id INTO @ReadOnlyUserRoleId FROM `cloud`.`roles` WHERE name = 'Read-Only User' AND is_default = 1;
+SELECT @ReadOnlyUserSortOrder:=-1;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) SELECT UUID(), @ReadOnlyUserRoleId, rule, 'ALLOW', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1 FROM `cloud`.`role_permissions` WHERE role_id = 4 AND permission = 'ALLOW' AND rule LIKE 'list%';
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) SELECT UUID(), @ReadOnlyUserRoleId, rule, 'ALLOW', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1 FROM `cloud`.`role_permissions` WHERE role_id = 4 AND permission = 'ALLOW' AND rule LIKE 'get%' AND rule NOT LIKE 'getUploadParamsFor%';
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyUserRoleId, 'cloudianIsEnabled', 'ALLOW', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyUserRoleId, 'quotaIsEnabled', 'ALLOW', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyUserRoleId, 'quotaTariffList', 'ALLOW', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyUserRoleId, 'quotaSummary', 'ALLOW', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyUserRoleId, '*', 'DENY', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+
+-- Role permissions for Admin-Support
+SELECT id INTO @AdminSupportRoleId FROM `cloud`.`roles` WHERE name = 'Admin-Support' AND is_default = 1;
+SELECT @AdminSupportSortOrder:=-1;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) SELECT UUID(), @AdminSupportRoleId, rule, 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1 FROM `cloud`.`role_permissions` WHERE role_id = @ReadOnlyAdminRoleId AND permission = 'ALLOW';
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'prepareHostForMaintenance', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'cancelHostMaintenance', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'enableStorageMaintenance', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'cancelStorageMaintenance', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'createServiceOffering', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'createDiskOffering', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'createNetworkOffering', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'createVPCOffering', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'startVirtualMachine', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'stopVirtualMachine', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'rebootVirtualMachine', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'startKubernetesCluster', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'stopKubernetesCluster', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'attachVolume', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'detachVolume', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'uploadVolume', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'attachIso', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'detachIso', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'registerTemplate', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'registerIso', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'getUploadParamsFor*', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, '*', 'DENY', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+
+-- Role permissions for User-Support
+SELECT id INTO @UserSupportRoleId FROM `cloud`.`roles` WHERE name = 'User-Support' AND is_default = 1;
+SELECT @UserSupportSortOrder:=-1;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) SELECT UUID(), @UserSupportRoleId, rule, 'ALLOW', @UserSupportSortOrder:=@UserSupportSortOrder+1 FROM `cloud`.`role_permissions` WHERE role_id = @ReadOnlyUserRoleId AND permission = 'ALLOW';

Review comment:
       > Same as above about the `rule` use?
   
   rules for the User support role are added from read-only user with additional api rules




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-652874637


   @borisstoyanov a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] rhtyd commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
rhtyd commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-654608839


   Test LGTM, failures not related to the PR


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-651731964


   @borisstoyanov a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] rhtyd merged pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
rhtyd merged pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti commented on a change in pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#discussion_r439927791



##########
File path: api/src/main/java/org/apache/cloudstack/api/command/admin/acl/ImportRoleCmd.java
##########
@@ -0,0 +1,139 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.cloudstack.api.command.admin.acl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cloudstack.acl.Role;
+import org.apache.cloudstack.acl.RoleType;
+import org.apache.cloudstack.acl.Rule;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiArgValidator;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.RoleResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.commons.collections.MapUtils;
+
+import com.cloud.user.Account;
+import com.google.common.base.Strings;
+
+@APICommand(name = ImportRoleCmd.APINAME, description = "Imports a role based on provided map of rule permissions", responseObject = RoleResponse.class,
+        requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
+        since = "4.15.0",
+        authorized = {RoleType.Admin})
+public class ImportRoleCmd extends RoleCmd {
+    public static final String APINAME = "importRole";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true,
+            description = "Creates a role with this unique name", validations = {ApiArgValidator.NotNullOrEmpty})
+    private String roleName;
+
+    @Parameter(name = ApiConstants.RULES, type = CommandType.MAP, required = true,
+            description = "Rules param list, rule and permission is must. Example: rules[0].rule=create*&rules[0].permission=allow&rules[0].description=create%20rule&rules[1].rule=list*&rules[1].permission=allow&rules[1].description=listing")
+    private Map rules;
+
+    @Parameter(name = ApiConstants.FORCED, type = CommandType.BOOLEAN,
+            description = "Force create a role with the same name. This overrides the role type, description and rule permissions for the existing role. Default is false.")
+    private Boolean forced;
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+    public String getRoleName() {
+        return roleName;
+    }
+
+    public List<Map<String, Object>> getRules() {
+        if (MapUtils.isEmpty(rules)) {
+            return null;
+        }
+

Review comment:
       > @sureshanaparti why not process rules and convert into a list of TOs/VOs, or something simpler that service layer can easily consume? Can you make the iteration logic simpler? Thanks.
   
   The Map here corresponds to a rule, with the permission details maintained in the keys: rule, permission & description, after validating them. The cmd object hold list of such maps, which are the role permissions for the role being imported.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] borisstoyanov commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
borisstoyanov commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-651731703


   @blueorangutan package


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-644575289


   Packaging result: ✔centos7 ✔debian. JID-1393


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti commented on a change in pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#discussion_r433407328



##########
File path: engine/schema/src/main/resources/META-INF/db/schema-41310to41400.sql
##########
@@ -379,3 +379,81 @@ CREATE TABLE IF NOT EXISTS `cloud`.`kubernetes_cluster_details` (
     PRIMARY KEY(`id`),
     CONSTRAINT `fk_kubernetes_cluster_details__cluster_id` FOREIGN KEY `fk_kubernetes_cluster_details__cluster_id`(`cluster_id`) REFERENCES `kubernetes_cluster`(`id`) ON DELETE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+

Review comment:
       > We want the DB changes in the 4.14 -> 4.15 upgrade path.
   
   Moved to 4.15 upgrade path




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] rhtyd commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
rhtyd commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-640998000






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] rhtyd closed pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
rhtyd closed pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-628414918


   Packaging result: ✔centos7 ✔debian. JID-1223


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] rhtyd commented on a change in pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
rhtyd commented on a change in pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#discussion_r439286361



##########
File path: server/src/main/java/org/apache/cloudstack/acl/RoleManagerImpl.java
##########
@@ -146,10 +150,89 @@ public RoleVO doInTransaction(TransactionStatus status) {
         });
     }
 
+    @Override
+    @ActionEvent(eventType = EventTypes.EVENT_ROLE_CREATE, eventDescription = "creating Role")

Review comment:
       Should the description say we're creating a role by cloning another role ?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-644551870


   @rhtyd a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-644528207


   @rhtyd a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti commented on a change in pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#discussion_r433412175



##########
File path: engine/schema/src/main/resources/META-INF/db/schema-41310to41400.sql
##########
@@ -379,3 +379,81 @@ CREATE TABLE IF NOT EXISTS `cloud`.`kubernetes_cluster_details` (
     PRIMARY KEY(`id`),
     CONSTRAINT `fk_kubernetes_cluster_details__cluster_id` FOREIGN KEY `fk_kubernetes_cluster_details__cluster_id`(`cluster_id`) REFERENCES `kubernetes_cluster`(`id`) ON DELETE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+ALTER TABLE `cloud`.`roles` ADD COLUMN `is_default` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'is this a default role';
+UPDATE `cloud`.`roles` SET `is_default` = 1 WHERE id IN (1, 2, 3, 4);
+
+-- Updated Default CloudStack roles with read-only and support admin and user roles
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'Read-Only Admin', 'Admin', 'Default read-only admin role', 1) ON DUPLICATE KEY UPDATE name=name;
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'Read-Only User', 'User', 'Default read-only user role', 1) ON DUPLICATE KEY UPDATE name=name;
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'Admin-Support', 'Admin', 'Default admin support role', 1) ON DUPLICATE KEY UPDATE name=name;
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'User-Support', 'User', 'Default user support role', 1) ON DUPLICATE KEY UPDATE name=name;
+
+-- Role permissions for Read-Only Admin
+SELECT id INTO @ReadOnlyAdminRoleId FROM `cloud`.`roles` WHERE name = 'Read-Only Admin' AND is_default = 1;
+SELECT @ReadOnlyAdminSortOrder:=-1;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'list*', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'getUploadParamsFor*', 'DENY', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'get*', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'cloudianIsEnabled', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'quotaIsEnabled', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'quotaTariffList', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'quotaSummary', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, '*', 'DENY', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+
+-- Role permissions for Read-Only User
+SELECT id INTO @ReadOnlyUserRoleId FROM `cloud`.`roles` WHERE name = 'Read-Only User' AND is_default = 1;
+SELECT @ReadOnlyUserSortOrder:=-1;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) SELECT UUID(), @ReadOnlyUserRoleId, rule, 'ALLOW', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1 FROM `cloud`.`role_permissions` WHERE role_id = 4 AND permission = 'ALLOW' AND rule LIKE 'list%';
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) SELECT UUID(), @ReadOnlyUserRoleId, rule, 'ALLOW', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1 FROM `cloud`.`role_permissions` WHERE role_id = 4 AND permission = 'ALLOW' AND rule LIKE 'get%' AND rule NOT LIKE 'getUploadParamsFor%';
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyUserRoleId, 'cloudianIsEnabled', 'ALLOW', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyUserRoleId, 'quotaIsEnabled', 'ALLOW', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyUserRoleId, 'quotaTariffList', 'ALLOW', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyUserRoleId, 'quotaSummary', 'ALLOW', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyUserRoleId, '*', 'DENY', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+
+-- Role permissions for Admin-Support
+SELECT id INTO @AdminSupportRoleId FROM `cloud`.`roles` WHERE name = 'Admin-Support' AND is_default = 1;
+SELECT @AdminSupportSortOrder:=-1;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) SELECT UUID(), @AdminSupportRoleId, rule, 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1 FROM `cloud`.`role_permissions` WHERE role_id = @ReadOnlyAdminRoleId AND permission = 'ALLOW';

Review comment:
       > Same as above about the `rule` use?
   
   rules for the Admin support role are added from read-only admin with additional api rules




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] rhtyd commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
rhtyd commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-643152653


   @sureshanaparti I've completed another pass, please see the comments. Next, I'll test/review the Primate PR against this branch.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti commented on a change in pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#discussion_r433412531



##########
File path: server/src/main/java/org/apache/cloudstack/acl/RoleManagerImpl.java
##########
@@ -146,10 +150,89 @@ public RoleVO doInTransaction(TransactionStatus status) {
         });
     }
 
+    @Override
+    @ActionEvent(eventType = EventTypes.EVENT_ROLE_CREATE, eventDescription = "creating Role")
+    public Role createRole(String name, Role role, String description) {
+        checkCallerAccess();
+        return Transaction.execute(new TransactionCallback<RoleVO>() {
+            @Override
+            public RoleVO doInTransaction(TransactionStatus status) {
+                RoleVO newRoleVO = roleDao.persist(new RoleVO(name, role.getRoleType(), description));
+                if (newRoleVO == null) {
+                    throw new CloudRuntimeException("Unable to add role into DB, is DB full?");

Review comment:
       > nit - Can you improve the exception message?
   
   Updated




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] borisstoyanov removed a comment on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
borisstoyanov removed a comment on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-653370045


   @blueorangutan test


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-653257193


   <b>Trillian test result (tid-1939)</b>
   Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
   Total time taken: 47854 seconds
   Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr4071-t1939-kvm-centos7.zip
   Intermittent failure detected: /marvin/tests/smoke/test_password_server.py
   Intermittent failure detected: /marvin/tests/smoke/test_router_dhcphosts.py
   Intermittent failure detected: /marvin/tests/smoke/test_vpc_redundant.py
   Intermittent failure detected: /marvin/tests/smoke/test_vpc_vpn.py
   Smoke tests completed. 80 look OK, 3 have error(s)
   Only failed tests results shown below:
   
   
   Test | Result | Time (s) | Test File
   --- | --- | --- | ---
   test_isolate_network_password_server | `Failure` | 13.23 | test_password_server.py
   test_router_dhcphosts | `Failure` | 13.45 | test_router_dhcphosts.py
   ContextSuite context=TestRouterDHCPHosts>:teardown | `Error` | 25.83 | test_router_dhcphosts.py
   test_03_create_redundant_VPC_1tier_2VMs_2IPs_2PF_ACL_reboot_routers | `Error` | 321.61 | test_vpc_redundant.py
   test_04_rvpc_network_garbage_collector_nics | `Error` | 3870.10 | test_vpc_redundant.py
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-642472475


   @blueorangutan test


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] rhtyd commented on a change in pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
rhtyd commented on a change in pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#discussion_r439285700



##########
File path: engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41400to41500.java
##########
@@ -235,6 +238,267 @@ private void updateSystemVmTemplates(final Connection conn) {
         LOG.debug("Updating System Vm Template IDs Complete");
     }
 
+    private void addRolePermissionsForNewReadOnlyAndSupportRoles(final Connection conn) {
+        addRolePermissionsForReadOnlyAdmin(conn);
+        addRolePermissionsForReadOnlyUser(conn);
+        addRolePermissionsForAdminSupport(conn);
+        addRolePermissionsForUserSupport(conn);
+    }
+
+    private void addRolePermissionsForReadOnlyAdmin(final Connection conn) {
+        LOG.debug("Adding role permissions for new read-only admin role");
+        try {
+            PreparedStatement pstmt = conn.prepareStatement("SELECT id FROM `cloud`.`roles` WHERE name = 'Read-Only Admin (Default)' AND is_default = 1");
+            ResultSet rs = pstmt.executeQuery();
+            if (rs.next()) {
+                long readOnlyAdminRoleId = rs.getLong(1);
+                int readOnlyAdminSortOrder = 0;
+                List<String> insertSqlForReadOnlyAdminRolePermissions = new ArrayList<String>();
+                insertSqlForReadOnlyAdminRolePermissions.add("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, 'list*', 'ALLOW', ?) ON DUPLICATE KEY UPDATE rule=rule");
+                insertSqlForReadOnlyAdminRolePermissions.add("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, 'getUploadParamsFor*', 'DENY', ?) ON DUPLICATE KEY UPDATE rule=rule");
+                insertSqlForReadOnlyAdminRolePermissions.add("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, 'get*', 'ALLOW', ?) ON DUPLICATE KEY UPDATE rule=rule");
+                insertSqlForReadOnlyAdminRolePermissions.add("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, 'cloudianIsEnabled', 'ALLOW', ?) ON DUPLICATE KEY UPDATE rule=rule");
+                insertSqlForReadOnlyAdminRolePermissions.add("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, 'quotaIsEnabled', 'ALLOW', ?) ON DUPLICATE KEY UPDATE rule=rule");
+                insertSqlForReadOnlyAdminRolePermissions.add("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, 'quotaTariffList', 'ALLOW', ?) ON DUPLICATE KEY UPDATE rule=rule");
+                insertSqlForReadOnlyAdminRolePermissions.add("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, 'quotaSummary', 'ALLOW', ?) ON DUPLICATE KEY UPDATE rule=rule");
+                insertSqlForReadOnlyAdminRolePermissions.add("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, '*', 'DENY', ?) ON DUPLICATE KEY UPDATE rule=rule");
+
+                for(String insertSqlForReadOnlyAdmin : insertSqlForReadOnlyAdminRolePermissions) {
+                    pstmt = conn.prepareStatement(insertSqlForReadOnlyAdmin);
+                    pstmt.setLong(1, readOnlyAdminRoleId);
+                    pstmt.setLong(2, readOnlyAdminSortOrder++);
+                    pstmt.executeUpdate();
+                }
+            }
+
+            if (rs != null && !rs.isClosed())  {
+                rs.close();
+            }
+            if (pstmt != null && !pstmt.isClosed())  {
+                pstmt.close();
+            }
+            LOG.debug("Successfully added role permissions for new read-only admin role");
+        } catch (final SQLException e) {
+            LOG.error("Exception while adding role permissions for read-only admin role: " + e.getMessage());
+            throw new CloudRuntimeException("Exception while adding role permissions for read-only admin role: " + e.getMessage(), e);
+        }
+    }
+
+    private void addRolePermissionsForReadOnlyUser(final Connection conn) {
+        LOG.debug("Adding role permissions for new read-only user role");
+        try {
+            PreparedStatement pstmt = conn.prepareStatement("SELECT id FROM `cloud`.`roles` WHERE name = 'Read-Only User (Default)' AND is_default = 1");
+            ResultSet rs = pstmt.executeQuery();
+            if (rs.next()) {
+                long readOnlyUserRoleId = rs.getLong(1);
+                int readOnlyUserSortOrder = 0;
+
+                pstmt = conn.prepareStatement("SELECT rule FROM `cloud`.`role_permissions` WHERE role_id = 4 AND permission = 'ALLOW' AND rule LIKE 'list%' ORDER BY sort_order");
+                ResultSet rsRolePermissions = pstmt.executeQuery();
+
+                while (rsRolePermissions.next()) {
+                    String rule = rsRolePermissions.getString(1);
+                    pstmt = conn.prepareStatement("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, ?, 'ALLOW', ?) ON DUPLICATE KEY UPDATE rule=rule");
+                    pstmt.setLong(1, readOnlyUserRoleId);
+                    pstmt.setString(2, rule);
+                    pstmt.setLong(3, readOnlyUserSortOrder++);
+                    pstmt.executeUpdate();
+                }
+
+                pstmt = conn.prepareStatement("SELECT rule FROM `cloud`.`role_permissions` WHERE role_id = 4 AND permission = 'ALLOW' AND rule LIKE 'get%' AND rule NOT LIKE 'getUploadParamsFor%' ORDER BY sort_order");
+                rsRolePermissions = pstmt.executeQuery();
+
+                while (rsRolePermissions.next()) {
+                    String rule = rsRolePermissions.getString(1);
+                    pstmt = conn.prepareStatement("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, ?, 'ALLOW', ?) ON DUPLICATE KEY UPDATE rule=rule");
+                    pstmt.setLong(1, readOnlyUserRoleId);
+                    pstmt.setString(2, rule);
+                    pstmt.setLong(3, readOnlyUserSortOrder++);
+                    pstmt.executeUpdate();
+                }
+
+                List<String> insertSqlForReadOnlyUserRolePermissions = new ArrayList<String>();
+                insertSqlForReadOnlyUserRolePermissions.add("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, 'cloudianIsEnabled', 'ALLOW', ?) ON DUPLICATE KEY UPDATE rule=rule");
+                insertSqlForReadOnlyUserRolePermissions.add("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, 'quotaIsEnabled', 'ALLOW', ?) ON DUPLICATE KEY UPDATE rule=rule");
+                insertSqlForReadOnlyUserRolePermissions.add("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, 'quotaTariffList', 'ALLOW', ?) ON DUPLICATE KEY UPDATE rule=rule");
+                insertSqlForReadOnlyUserRolePermissions.add("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, 'quotaSummary', 'ALLOW', ?) ON DUPLICATE KEY UPDATE rule=rule");
+                insertSqlForReadOnlyUserRolePermissions.add("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, '*', 'DENY', ?) ON DUPLICATE KEY UPDATE rule=rule");
+
+                for(String insertSqlForReadOnlyUser : insertSqlForReadOnlyUserRolePermissions) {
+                    pstmt = conn.prepareStatement(insertSqlForReadOnlyUser);
+                    pstmt.setLong(1, readOnlyUserRoleId);
+                    pstmt.setLong(2, readOnlyUserSortOrder++);
+                    pstmt.executeUpdate();
+                }
+
+                if (rsRolePermissions != null && !rsRolePermissions.isClosed())  {
+                    rsRolePermissions.close();
+                }
+            }
+
+            if (rs != null && !rs.isClosed())  {
+                rs.close();
+            }
+            if (pstmt != null && !pstmt.isClosed())  {
+                pstmt.close();
+            }
+            LOG.debug("Successfully added role permissions for new read-only user role");
+        } catch (final SQLException e) {
+            LOG.error("Exception while adding role permissions for read-only user role: " + e.getMessage());
+            throw new CloudRuntimeException("Exception while adding role permissions for read-only user role: " + e.getMessage(), e);
+        }
+    }
+
+    private void addRolePermissionsForAdminSupport(final Connection conn) {
+        LOG.debug("Adding role permissions for new admin support role");
+        try {
+            PreparedStatement pstmt = conn.prepareStatement("SELECT id FROM `cloud`.`roles` WHERE name = 'Admin-Support (Default)' AND is_default = 1");
+            ResultSet rs = pstmt.executeQuery();
+            if (rs.next()) {
+                long adminSupportRoleId = rs.getLong(1);
+                int adminSupportSortOrder = 0;
+
+                pstmt = conn.prepareStatement("SELECT id FROM `cloud`.`roles` WHERE name = 'Read-Only Admin (Default)' AND is_default = 1");
+                ResultSet rsReadOnlyAdmin = pstmt.executeQuery();
+                if (rsReadOnlyAdmin.next()) {
+                    long readOnlyAdminRoleId = rsReadOnlyAdmin.getLong(1);
+                    pstmt = conn.prepareStatement("SELECT rule FROM `cloud`.`role_permissions` WHERE role_id = ? AND permission = 'ALLOW' ORDER BY sort_order");
+                    pstmt.setLong(1, readOnlyAdminRoleId);
+                    ResultSet rsRolePermissions = pstmt.executeQuery();
+
+                    while (rsRolePermissions.next()) {
+                        String rule = rsRolePermissions.getString(1);
+                        pstmt = conn.prepareStatement("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, ?, 'ALLOW', ?) ON DUPLICATE KEY UPDATE rule=rule");
+                        pstmt.setLong(1, adminSupportRoleId);
+                        pstmt.setString(2, rule);
+                        pstmt.setLong(3, adminSupportSortOrder++);
+                        pstmt.executeUpdate();
+                    }
+
+                    List<String> insertSqlForAdminSupportRolePermissions = new ArrayList<String>();
+                    insertSqlForAdminSupportRolePermissions.add("INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), ?, 'prepareHostForMaintenance', 'ALLOW', ?) ON DUPLICATE KEY UPDATE rule=rule");

Review comment:
       nit - Could be made less verbose by doing a loop on the API strings and add the string to the collection/list. Same for other parts of code.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-652204115


   @borisstoyanov a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-642473145


   @sureshanaparti a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-645005027


   <b>Trillian test result (tid-1741)</b>
   Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
   Total time taken: 46789 seconds
   Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr4071-t1741-kvm-centos7.zip
   Intermittent failure detected: /marvin/tests/smoke/test_kubernetes_supported_versions.py
   Intermittent failure detected: /marvin/tests/smoke/test_router_dhcphosts.py
   Intermittent failure detected: /marvin/tests/smoke/test_vpc_redundant.py
   Smoke tests completed. 82 look OK, 1 have error(s)
   Only failed tests results shown below:
   
   
   Test | Result | Time (s) | Test File
   --- | --- | --- | ---
   test_01_add_delete_kubernetes_supported_version | `Error` | 1807.94 | test_kubernetes_supported_versions.py
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-651746500


   Packaging result: ✔centos7 ✔debian. JID-1491


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] rhtyd commented on a change in pull request #4071: [WIP] Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
rhtyd commented on a change in pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#discussion_r426535314



##########
File path: api/src/main/java/org/apache/cloudstack/api/command/admin/acl/ImportRoleCmd.java
##########
@@ -0,0 +1,139 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.cloudstack.api.command.admin.acl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cloudstack.acl.Role;
+import org.apache.cloudstack.acl.RoleType;
+import org.apache.cloudstack.acl.Rule;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiArgValidator;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.RoleResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.commons.collections.MapUtils;
+
+import com.cloud.user.Account;
+import com.google.common.base.Strings;
+
+@APICommand(name = ImportRoleCmd.APINAME, description = "Imports a role", responseObject = RoleResponse.class,

Review comment:
       nit - Make description more verbose, something like 'Imports a role based on provided map of rule permissions...'

##########
File path: api/src/main/java/org/apache/cloudstack/api/command/admin/acl/ImportRoleCmd.java
##########
@@ -0,0 +1,139 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.cloudstack.api.command.admin.acl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cloudstack.acl.Role;
+import org.apache.cloudstack.acl.RoleType;
+import org.apache.cloudstack.acl.Rule;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiArgValidator;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.RoleResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.commons.collections.MapUtils;
+
+import com.cloud.user.Account;
+import com.google.common.base.Strings;
+
+@APICommand(name = ImportRoleCmd.APINAME, description = "Imports a role", responseObject = RoleResponse.class,
+        requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
+        since = "4.15.0",
+        authorized = {RoleType.Admin})
+public class ImportRoleCmd extends RoleCmd {
+    public static final String APINAME = "importRole";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true,
+            description = "Creates a role with this unique name", validations = {ApiArgValidator.NotNullOrEmpty})
+    private String roleName;
+
+    @Parameter(name = ApiConstants.RULES, type = CommandType.MAP, required = true,
+            description = "Rules param list, rule and permission is must. Example: rules[0].rule=create*&rules[0].permission=allow&rules[0].description=create%20rule&rules[1].rule=list*&rules[1].permission=allow&rules[1].description=listing")
+    private Map rules;
+
+    @Parameter(name = ApiConstants.FORCED, type = CommandType.BOOLEAN,
+            description = "Force create a role")

Review comment:
       nit - fix description to say what happens in case of a role name matches (i.e. explain for the users that it will override/replace the previosly created role with the provided parameters).

##########
File path: engine/schema/src/main/resources/META-INF/db/schema-41310to41400.sql
##########
@@ -379,3 +379,81 @@ CREATE TABLE IF NOT EXISTS `cloud`.`kubernetes_cluster_details` (
     PRIMARY KEY(`id`),
     CONSTRAINT `fk_kubernetes_cluster_details__cluster_id` FOREIGN KEY `fk_kubernetes_cluster_details__cluster_id`(`cluster_id`) REFERENCES `kubernetes_cluster`(`id`) ON DELETE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+ALTER TABLE `cloud`.`roles` ADD COLUMN `is_default` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'is this a default role';
+UPDATE `cloud`.`roles` SET `is_default` = 1 WHERE id IN (1, 2, 3, 4);

Review comment:
       Please check in code if there exists any restriction on ID for default/built-in roles.

##########
File path: engine/schema/src/main/resources/META-INF/db/schema-41310to41400.sql
##########
@@ -379,3 +379,81 @@ CREATE TABLE IF NOT EXISTS `cloud`.`kubernetes_cluster_details` (
     PRIMARY KEY(`id`),
     CONSTRAINT `fk_kubernetes_cluster_details__cluster_id` FOREIGN KEY `fk_kubernetes_cluster_details__cluster_id`(`cluster_id`) REFERENCES `kubernetes_cluster`(`id`) ON DELETE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+ALTER TABLE `cloud`.`roles` ADD COLUMN `is_default` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'is this a default role';
+UPDATE `cloud`.`roles` SET `is_default` = 1 WHERE id IN (1, 2, 3, 4);
+
+-- Updated Default CloudStack roles with read-only and support admin and user roles
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'Read-Only Admin', 'Admin', 'Default read-only admin role', 1) ON DUPLICATE KEY UPDATE name=name;
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'Read-Only User', 'User', 'Default read-only user role', 1) ON DUPLICATE KEY UPDATE name=name;
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'Admin-Support', 'Admin', 'Default admin support role', 1) ON DUPLICATE KEY UPDATE name=name;
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'User-Support', 'User', 'Default user support role', 1) ON DUPLICATE KEY UPDATE name=name;
+
+-- Role permissions for Read-Only Admin
+SELECT id INTO @ReadOnlyAdminRoleId FROM `cloud`.`roles` WHERE name = 'Read-Only Admin' AND is_default = 1;
+SELECT @ReadOnlyAdminSortOrder:=-1;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'list*', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'getUploadParamsFor*', 'DENY', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'get*', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'cloudianIsEnabled', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'quotaIsEnabled', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'quotaTariffList', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'quotaSummary', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, '*', 'DENY', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+
+-- Role permissions for Read-Only User
+SELECT id INTO @ReadOnlyUserRoleId FROM `cloud`.`roles` WHERE name = 'Read-Only User' AND is_default = 1;
+SELECT @ReadOnlyUserSortOrder:=-1;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) SELECT UUID(), @ReadOnlyUserRoleId, rule, 'ALLOW', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1 FROM `cloud`.`role_permissions` WHERE role_id = 4 AND permission = 'ALLOW' AND rule LIKE 'list%';

Review comment:
       Should the `rule` here be `list*` or `get*` etc.? Or was `rule` declared somewhere I missed ?

##########
File path: engine/schema/src/main/resources/META-INF/db/schema-41310to41400.sql
##########
@@ -379,3 +379,81 @@ CREATE TABLE IF NOT EXISTS `cloud`.`kubernetes_cluster_details` (
     PRIMARY KEY(`id`),
     CONSTRAINT `fk_kubernetes_cluster_details__cluster_id` FOREIGN KEY `fk_kubernetes_cluster_details__cluster_id`(`cluster_id`) REFERENCES `kubernetes_cluster`(`id`) ON DELETE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+ALTER TABLE `cloud`.`roles` ADD COLUMN `is_default` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'is this a default role';
+UPDATE `cloud`.`roles` SET `is_default` = 1 WHERE id IN (1, 2, 3, 4);
+
+-- Updated Default CloudStack roles with read-only and support admin and user roles
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'Read-Only Admin', 'Admin', 'Default read-only admin role', 1) ON DUPLICATE KEY UPDATE name=name;
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'Read-Only User', 'User', 'Default read-only user role', 1) ON DUPLICATE KEY UPDATE name=name;
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'Admin-Support', 'Admin', 'Default admin support role', 1) ON DUPLICATE KEY UPDATE name=name;
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'User-Support', 'User', 'Default user support role', 1) ON DUPLICATE KEY UPDATE name=name;
+
+-- Role permissions for Read-Only Admin
+SELECT id INTO @ReadOnlyAdminRoleId FROM `cloud`.`roles` WHERE name = 'Read-Only Admin' AND is_default = 1;
+SELECT @ReadOnlyAdminSortOrder:=-1;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'list*', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'getUploadParamsFor*', 'DENY', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'get*', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'cloudianIsEnabled', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'quotaIsEnabled', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'quotaTariffList', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'quotaSummary', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, '*', 'DENY', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+
+-- Role permissions for Read-Only User
+SELECT id INTO @ReadOnlyUserRoleId FROM `cloud`.`roles` WHERE name = 'Read-Only User' AND is_default = 1;
+SELECT @ReadOnlyUserSortOrder:=-1;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) SELECT UUID(), @ReadOnlyUserRoleId, rule, 'ALLOW', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1 FROM `cloud`.`role_permissions` WHERE role_id = 4 AND permission = 'ALLOW' AND rule LIKE 'list%';
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) SELECT UUID(), @ReadOnlyUserRoleId, rule, 'ALLOW', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1 FROM `cloud`.`role_permissions` WHERE role_id = 4 AND permission = 'ALLOW' AND rule LIKE 'get%' AND rule NOT LIKE 'getUploadParamsFor%';
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyUserRoleId, 'cloudianIsEnabled', 'ALLOW', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyUserRoleId, 'quotaIsEnabled', 'ALLOW', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyUserRoleId, 'quotaTariffList', 'ALLOW', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyUserRoleId, 'quotaSummary', 'ALLOW', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyUserRoleId, '*', 'DENY', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+
+-- Role permissions for Admin-Support
+SELECT id INTO @AdminSupportRoleId FROM `cloud`.`roles` WHERE name = 'Admin-Support' AND is_default = 1;
+SELECT @AdminSupportSortOrder:=-1;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) SELECT UUID(), @AdminSupportRoleId, rule, 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1 FROM `cloud`.`role_permissions` WHERE role_id = @ReadOnlyAdminRoleId AND permission = 'ALLOW';
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'prepareHostForMaintenance', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'cancelHostMaintenance', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'enableStorageMaintenance', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'cancelStorageMaintenance', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'createServiceOffering', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'createDiskOffering', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'createNetworkOffering', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'createVPCOffering', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'startVirtualMachine', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'stopVirtualMachine', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'rebootVirtualMachine', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'startKubernetesCluster', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'stopKubernetesCluster', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'attachVolume', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'detachVolume', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'uploadVolume', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'attachIso', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'detachIso', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'registerTemplate', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'registerIso', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, 'getUploadParamsFor*', 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @AdminSupportRoleId, '*', 'DENY', @AdminSupportSortOrder:=@AdminSupportSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+
+-- Role permissions for User-Support
+SELECT id INTO @UserSupportRoleId FROM `cloud`.`roles` WHERE name = 'User-Support' AND is_default = 1;
+SELECT @UserSupportSortOrder:=-1;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) SELECT UUID(), @UserSupportRoleId, rule, 'ALLOW', @UserSupportSortOrder:=@UserSupportSortOrder+1 FROM `cloud`.`role_permissions` WHERE role_id = @ReadOnlyUserRoleId AND permission = 'ALLOW';

Review comment:
       Same as above about the `rule` use?

##########
File path: engine/schema/src/main/resources/META-INF/db/schema-41310to41400-cleanup.sql
##########
@@ -26,3 +26,6 @@ UPDATE `cloud`.`storage_pool` SET path="/var/lib/libvirt/images" WHERE path="/va
 
 -- remove (one of) duplicate unique indexes from Region table
 ALTER TABLE `region` DROP INDEX `id_3`;
+
+-- remove the old NetApp storage APIs (unsupported since 4.12) from role_permissions
+DELETE from `cloud`.`role_permissions` WHERE rule IN ('createPool', 'modifyPool', 'deletePool', 'listPools', 'associateLun', 'dissociateLun', 'createLunOnFiler', 'destroyLunOnFiler', 'listLunsOnFiler', 'createVolumeOnFiler', 'destroyVolumeOnFiler', 'listVolumesOnFiler');

Review comment:
       We want the DB changes in the 4.14 -> 4.15 upgrade path.

##########
File path: engine/schema/src/main/resources/META-INF/db/schema-41310to41400.sql
##########
@@ -379,3 +379,81 @@ CREATE TABLE IF NOT EXISTS `cloud`.`kubernetes_cluster_details` (
     PRIMARY KEY(`id`),
     CONSTRAINT `fk_kubernetes_cluster_details__cluster_id` FOREIGN KEY `fk_kubernetes_cluster_details__cluster_id`(`cluster_id`) REFERENCES `kubernetes_cluster`(`id`) ON DELETE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+ALTER TABLE `cloud`.`roles` ADD COLUMN `is_default` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'is this a default role';
+UPDATE `cloud`.`roles` SET `is_default` = 1 WHERE id IN (1, 2, 3, 4);
+
+-- Updated Default CloudStack roles with read-only and support admin and user roles
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'Read-Only Admin', 'Admin', 'Default read-only admin role', 1) ON DUPLICATE KEY UPDATE name=name;
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'Read-Only User', 'User', 'Default read-only user role', 1) ON DUPLICATE KEY UPDATE name=name;
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'Admin-Support', 'Admin', 'Default admin support role', 1) ON DUPLICATE KEY UPDATE name=name;
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'User-Support', 'User', 'Default user support role', 1) ON DUPLICATE KEY UPDATE name=name;
+
+-- Role permissions for Read-Only Admin
+SELECT id INTO @ReadOnlyAdminRoleId FROM `cloud`.`roles` WHERE name = 'Read-Only Admin' AND is_default = 1;
+SELECT @ReadOnlyAdminSortOrder:=-1;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'list*', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'getUploadParamsFor*', 'DENY', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'get*', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'cloudianIsEnabled', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'quotaIsEnabled', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'quotaTariffList', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, 'quotaSummary', 'ALLOW', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyAdminRoleId, '*', 'DENY', @ReadOnlyAdminSortOrder:=@ReadOnlyAdminSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+
+-- Role permissions for Read-Only User
+SELECT id INTO @ReadOnlyUserRoleId FROM `cloud`.`roles` WHERE name = 'Read-Only User' AND is_default = 1;
+SELECT @ReadOnlyUserSortOrder:=-1;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) SELECT UUID(), @ReadOnlyUserRoleId, rule, 'ALLOW', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1 FROM `cloud`.`role_permissions` WHERE role_id = 4 AND permission = 'ALLOW' AND rule LIKE 'list%';
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) SELECT UUID(), @ReadOnlyUserRoleId, rule, 'ALLOW', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1 FROM `cloud`.`role_permissions` WHERE role_id = 4 AND permission = 'ALLOW' AND rule LIKE 'get%' AND rule NOT LIKE 'getUploadParamsFor%';
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyUserRoleId, 'cloudianIsEnabled', 'ALLOW', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyUserRoleId, 'quotaIsEnabled', 'ALLOW', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyUserRoleId, 'quotaTariffList', 'ALLOW', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyUserRoleId, 'quotaSummary', 'ALLOW', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) VALUES (UUID(), @ReadOnlyUserRoleId, '*', 'DENY', @ReadOnlyUserSortOrder:=@ReadOnlyUserSortOrder+1) ON DUPLICATE KEY UPDATE rule=rule;
+
+-- Role permissions for Admin-Support
+SELECT id INTO @AdminSupportRoleId FROM `cloud`.`roles` WHERE name = 'Admin-Support' AND is_default = 1;
+SELECT @AdminSupportSortOrder:=-1;
+INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) SELECT UUID(), @AdminSupportRoleId, rule, 'ALLOW', @AdminSupportSortOrder:=@AdminSupportSortOrder+1 FROM `cloud`.`role_permissions` WHERE role_id = @ReadOnlyAdminRoleId AND permission = 'ALLOW';

Review comment:
       Same as above about the `rule` use?

##########
File path: api/src/main/java/org/apache/cloudstack/api/response/RoleResponse.java
##########
@@ -43,6 +43,10 @@
     @Param(description = "the description of the role")
     private String roleDescription;
 
+    @SerializedName(ApiConstants.IS_DEFAULT)
+    @Param(description = "true if role is default, false otherwise")

Review comment:
       nit - can you also explain what it means for a role to be default (default could be misleading, perhaps what you mean is if the role is built-in).

##########
File path: engine/schema/src/main/resources/META-INF/db/schema-41310to41400.sql
##########
@@ -379,3 +379,81 @@ CREATE TABLE IF NOT EXISTS `cloud`.`kubernetes_cluster_details` (
     PRIMARY KEY(`id`),
     CONSTRAINT `fk_kubernetes_cluster_details__cluster_id` FOREIGN KEY `fk_kubernetes_cluster_details__cluster_id`(`cluster_id`) REFERENCES `kubernetes_cluster`(`id`) ON DELETE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+

Review comment:
       We want the DB changes in the 4.14 -> 4.15 upgrade path.

##########
File path: api/src/main/java/org/apache/cloudstack/api/command/admin/acl/RoleCmd.java
##########
@@ -18,11 +18,41 @@
 package org.apache.cloudstack.api.command.admin.acl;
 
 import org.apache.cloudstack.acl.Role;
+import org.apache.cloudstack.acl.RoleType;
+import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.response.RoleResponse;
 
+import com.google.common.base.Strings;
+
 public abstract class RoleCmd extends BaseCmd {
 
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @Parameter(name = ApiConstants.TYPE, type = CommandType.STRING, description = "The type of the role, valid options are: Admin, ResourceAdmin, DomainAdmin, User")
+    private String roleType;

Review comment:
       I get the reuse with the createRole API, but do we want these parameters for the updateRole API?

##########
File path: engine/schema/src/main/resources/META-INF/db/schema-41310to41400.sql
##########
@@ -379,3 +379,81 @@ CREATE TABLE IF NOT EXISTS `cloud`.`kubernetes_cluster_details` (
     PRIMARY KEY(`id`),
     CONSTRAINT `fk_kubernetes_cluster_details__cluster_id` FOREIGN KEY `fk_kubernetes_cluster_details__cluster_id`(`cluster_id`) REFERENCES `kubernetes_cluster`(`id`) ON DELETE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+ALTER TABLE `cloud`.`roles` ADD COLUMN `is_default` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'is this a default role';
+UPDATE `cloud`.`roles` SET `is_default` = 1 WHERE id IN (1, 2, 3, 4);
+
+-- Updated Default CloudStack roles with read-only and support admin and user roles
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'Read-Only Admin', 'Admin', 'Default read-only admin role', 1) ON DUPLICATE KEY UPDATE name=name;

Review comment:
       Why not change the name to reflect these are default or `built-in` roles, should we be renaming any existing roles matching this? It could lead to side-effects, I would've preferred failing an upgrade instead of silent override.

##########
File path: server/src/main/java/org/apache/cloudstack/acl/RoleManagerImpl.java
##########
@@ -159,9 +242,6 @@ public Role updateRole(final Role role, final String name, final RoleType roleTy
             roleVO.setName(name);
         }
         if (roleType != null) {
-            if (role.getId() <= RoleType.User.getId()) {

Review comment:
       Here was a check which determined that the role was built-in, i.e. the first 4 roles treated as built-in and no changes to these 4 roles were allowed by using enum idx without requiring a db column for that.

##########
File path: server/src/main/java/org/apache/cloudstack/acl/RoleManagerImpl.java
##########
@@ -146,10 +150,89 @@ public RoleVO doInTransaction(TransactionStatus status) {
         });
     }
 
+    @Override
+    @ActionEvent(eventType = EventTypes.EVENT_ROLE_CREATE, eventDescription = "creating Role")
+    public Role createRole(String name, Role role, String description) {
+        checkCallerAccess();
+        return Transaction.execute(new TransactionCallback<RoleVO>() {
+            @Override
+            public RoleVO doInTransaction(TransactionStatus status) {
+                RoleVO newRoleVO = roleDao.persist(new RoleVO(name, role.getRoleType(), description));
+                if (newRoleVO == null) {
+                    throw new CloudRuntimeException("Unable to add role into DB, is DB full?");

Review comment:
       nit - Can you improve the exception message?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti commented on a change in pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#discussion_r439926674



##########
File path: engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41400to41500.java
##########
@@ -235,6 +238,267 @@ private void updateSystemVmTemplates(final Connection conn) {
         LOG.debug("Updating System Vm Template IDs Complete");
     }
 
+    private void addRolePermissionsForNewReadOnlyAndSupportRoles(final Connection conn) {
+        addRolePermissionsForReadOnlyAdmin(conn);
+        addRolePermissionsForReadOnlyUser(conn);
+        addRolePermissionsForAdminSupport(conn);
+        addRolePermissionsForUserSupport(conn);

Review comment:
       > Minor nit - can we call the role 'SupportAdmin' and 'SupportUser'?
   
   Updated




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] rhtyd closed pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
rhtyd closed pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] rhtyd commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
rhtyd commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-653017853


   Cheers @borisstoyanov I'll merge this tomorrow if tests pass.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti commented on a change in pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#discussion_r433408963



##########
File path: engine/schema/src/main/resources/META-INF/db/schema-41310to41400.sql
##########
@@ -379,3 +379,81 @@ CREATE TABLE IF NOT EXISTS `cloud`.`kubernetes_cluster_details` (
     PRIMARY KEY(`id`),
     CONSTRAINT `fk_kubernetes_cluster_details__cluster_id` FOREIGN KEY `fk_kubernetes_cluster_details__cluster_id`(`cluster_id`) REFERENCES `kubernetes_cluster`(`id`) ON DELETE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+ALTER TABLE `cloud`.`roles` ADD COLUMN `is_default` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'is this a default role';
+UPDATE `cloud`.`roles` SET `is_default` = 1 WHERE id IN (1, 2, 3, 4);

Review comment:
       > Please check in code if there exists any restriction on ID for default/built-in roles.
   
   The role ids (1,2,3,4) are hard-coded when upgraded to dynamic roles access checker. The same roles are now marked as default roles in cloudstack.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] borisstoyanov commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
borisstoyanov commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-653370045


   @blueorangutan test


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-628522273


   @rhtyd a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] borisstoyanov commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
borisstoyanov commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-652897190


   @blueorangutan test


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] rhtyd commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
rhtyd commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-628521853


   @blueorangutan test 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-644544332


   Packaging result: ✔centos7 ✖debian. JID-1383


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] rhtyd commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
rhtyd commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-644528040


   @blueorangutan package


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] borisstoyanov commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
borisstoyanov commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-652203905


   @blueorangutan package


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] rhtyd commented on a change in pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
rhtyd commented on a change in pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#discussion_r437203881



##########
File path: engine/schema/src/main/resources/META-INF/db/schema-41400to41500.sql
##########
@@ -18,3 +18,81 @@
 --;
 -- Schema upgrade from 4.14.0.0 to 4.15.0.0
 --;
+
+ALTER TABLE `cloud`.`roles` ADD COLUMN `is_default` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'is this a default role';
+UPDATE `cloud`.`roles` SET `is_default` = 1 WHERE id IN (1, 2, 3, 4);
+
+-- Updated Default CloudStack roles with read-only and support admin and user roles
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'Read-Only Admin', 'Admin', 'Default read-only admin role', 1) ON DUPLICATE KEY UPDATE name=name;
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'Read-Only User', 'User', 'Default read-only user role', 1) ON DUPLICATE KEY UPDATE name=name;
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'Admin-Support', 'Admin', 'Default admin support role', 1) ON DUPLICATE KEY UPDATE name=name;
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'User-Support', 'User', 'Default user support role', 1) ON DUPLICATE KEY UPDATE name=name;
+
+-- Role permissions for Read-Only Admin
+SELECT id INTO @ReadOnlyAdminRoleId FROM `cloud`.`roles` WHERE name = 'Read-Only Admin' AND is_default = 1;
+SELECT @ReadOnlyAdminSortOrder:=-1;

Review comment:
       With a debugger I found that execution fails for mvn deploydb with:
   ```
   ========> Processing upgrade: com.cloud.upgrade.DatabaseUpgradeChecker
   [WARNING] 
   java.lang.reflect.InvocationTargetException
       at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
       at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
       at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
       at java.lang.reflect.Method.invoke (Method.java:566)
       at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:297)
       at java.lang.Thread.run (Thread.java:834)
   Caused by: com.cloud.utils.exception.CloudRuntimeException: Unable to upgrade the database
       at com.cloud.upgrade.DatabaseUpgradeChecker.upgrade (DatabaseUpgradeChecker.java:271)
       at com.cloud.upgrade.DatabaseUpgradeChecker.check (DatabaseUpgradeChecker.java:342)
       at com.cloud.upgrade.DatabaseCreator.main (DatabaseCreator.java:217)
       at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
       at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
       at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
       at java.lang.reflect.Method.invoke (Method.java:566)
       at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:297)
       at java.lang.Thread.run (Thread.java:834)
   Caused by: com.cloud.utils.exception.CloudRuntimeException: Unable to execute upgrade script
       at com.cloud.upgrade.DatabaseUpgradeChecker.runScript (DatabaseUpgradeChecker.java:209)
       at com.cloud.upgrade.DatabaseUpgradeChecker.upgrade (DatabaseUpgradeChecker.java:258)
       at com.cloud.upgrade.DatabaseUpgradeChecker.check (DatabaseUpgradeChecker.java:342)
       at com.cloud.upgrade.DatabaseCreator.main (DatabaseCreator.java:217)
       at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
       at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
       at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
       at java.lang.reflect.Method.invoke (Method.java:566)
       at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:297)
       at java.lang.Thread.run (Thread.java:834)
   Caused by: java.sql.SQLException: Column index out of range.
       at com.cloud.utils.db.ScriptRunner.runScript (ScriptRunner.java:185)
       at com.cloud.utils.db.ScriptRunner.runScript (ScriptRunner.java:87)
       at com.cloud.upgrade.DatabaseUpgradeChecker.runScript (DatabaseUpgradeChecker.java:203)
       at com.cloud.upgrade.DatabaseUpgradeChecker.upgrade (DatabaseUpgradeChecker.java:258)
       at com.cloud.upgrade.DatabaseUpgradeChecker.check (DatabaseUpgradeChecker.java:342)
       at com.cloud.upgrade.DatabaseCreator.main (DatabaseCreator.java:217)
       at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
       at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
       at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
       at java.lang.reflect.Method.invoke (Method.java:566)
       at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:297)
       at java.lang.Thread.run (Thread.java:834)
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-652212600


   Packaging result: ✔centos7 ✔debian. JID-1496


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-642457450


   @sureshanaparti a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-642941492


   <b>Trillian test result (tid-1674)</b>
   Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
   Total time taken: 48018 seconds
   Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr4071-t1674-kvm-centos7.zip
   Intermittent failure detected: /marvin/tests/smoke/test_kubernetes_clusters.py
   Intermittent failure detected: /marvin/tests/smoke/test_vpc_redundant.py
   Intermittent failure detected: /marvin/tests/smoke/test_vpc_vpn.py
   Smoke tests completed. 82 look OK, 1 have error(s)
   Only failed tests results shown below:
   
   
   Test | Result | Time (s) | Test File
   --- | --- | --- | ---
   test_01_create_redundant_VPC_2tiers_4VMs_4IPs_4PF_ACL | `Failure` | 347.44 | test_vpc_redundant.py
   test_03_create_redundant_VPC_1tier_2VMs_2IPs_2PF_ACL_reboot_routers | `Failure` | 342.00 | test_vpc_redundant.py
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti commented on a change in pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#discussion_r439191916



##########
File path: engine/schema/src/main/resources/META-INF/db/schema-41400to41500.sql
##########
@@ -18,3 +18,81 @@
 --;
 -- Schema upgrade from 4.14.0.0 to 4.15.0.0
 --;
+
+ALTER TABLE `cloud`.`roles` ADD COLUMN `is_default` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'is this a default role';
+UPDATE `cloud`.`roles` SET `is_default` = 1 WHERE id IN (1, 2, 3, 4);
+
+-- Updated Default CloudStack roles with read-only and support admin and user roles
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'Read-Only Admin', 'Admin', 'Default read-only admin role', 1) ON DUPLICATE KEY UPDATE name=name;
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'Read-Only User', 'User', 'Default read-only user role', 1) ON DUPLICATE KEY UPDATE name=name;
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'Admin-Support', 'Admin', 'Default admin support role', 1) ON DUPLICATE KEY UPDATE name=name;
+INSERT INTO `cloud`.`roles` (`uuid`, `name`, `role_type`, `description`, `is_default`) VALUES (UUID(), 'User-Support', 'User', 'Default user support role', 1) ON DUPLICATE KEY UPDATE name=name;
+
+-- Role permissions for Read-Only Admin
+SELECT id INTO @ReadOnlyAdminRoleId FROM `cloud`.`roles` WHERE name = 'Read-Only Admin' AND is_default = 1;
+SELECT @ReadOnlyAdminSortOrder:=-1;

Review comment:
       @rhtyd Moved permissions update to the Upgrade* class. Please check. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan removed a comment on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan removed a comment on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-653370522


   @borisstoyanov a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #4071: Dynamic roles improvements

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #4071:
URL: https://github.com/apache/cloudstack/pull/4071#issuecomment-652897586


   @borisstoyanov a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org