Skip to content

Commit df302bd

Browse files
Prachi Damleminchen07
authored andcommitted
Split the Root Admin policy to allow 'ListEntry' access for listing resources for scope 'all', but 'UseEntry' access only within Account scope
Same with Domain Admin policy
1 parent a509f94 commit df302bd

1 file changed

Lines changed: 32 additions & 17 deletions

File tree

services/iam/plugin/src/org/apache/cloudstack/iam/RoleBasedAPIAccessChecker.java

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -218,23 +218,6 @@ public void setServices(List<PluggableService> services) {
218218
private void addDefaultAclPolicyPermission(String apiName, Class<?> cmdClass, RoleType role) {
219219
AccessType accessType = null;
220220
Class<?>[] entityTypes = null;
221-
if (cmdClass != null) {
222-
BaseCmd cmdObj;
223-
try {
224-
cmdObj = (BaseCmd) cmdClass.newInstance();
225-
if (cmdObj instanceof BaseListCmd) {
226-
accessType = AccessType.UseEntry;
227-
} else if (!(cmdObj instanceof BaseAsyncCreateCmd)) {
228-
accessType = AccessType.OperateEntry;
229-
}
230-
} catch (Exception e) {
231-
throw new CloudRuntimeException(String.format(
232-
"%s is claimed as an API command, but it cannot be instantiated", cmdClass.getName()));
233-
}
234-
235-
APICommand at = cmdClass.getAnnotation(APICommand.class);
236-
entityTypes = at.entityType();
237-
}
238221

239222
PermissionScope permissionScope = PermissionScope.ACCOUNT;
240223
Long policyId = getDefaultPolicyId(role);
@@ -256,15 +239,47 @@ private void addDefaultAclPolicyPermission(String apiName, Class<?> cmdClass, Ro
256239
break;
257240
}
258241

242+
boolean addAccountScopedUseEntry = false;
243+
244+
if (cmdClass != null) {
245+
BaseCmd cmdObj;
246+
try {
247+
cmdObj = (BaseCmd) cmdClass.newInstance();
248+
if (cmdObj instanceof BaseListCmd) {
249+
if (permissionScope == PermissionScope.ACCOUNT) {
250+
accessType = AccessType.UseEntry;
251+
} else {
252+
accessType = AccessType.ListEntry;
253+
addAccountScopedUseEntry = true;
254+
}
255+
} else if (!(cmdObj instanceof BaseAsyncCreateCmd)) {
256+
accessType = AccessType.OperateEntry;
257+
}
258+
} catch (Exception e) {
259+
throw new CloudRuntimeException(String.format(
260+
"%s is claimed as an API command, but it cannot be instantiated", cmdClass.getName()));
261+
}
262+
263+
APICommand at = cmdClass.getAnnotation(APICommand.class);
264+
entityTypes = at.entityType();
265+
}
259266

260267
if (entityTypes == null || entityTypes.length == 0) {
261268
_iamSrv.addIAMPermissionToIAMPolicy(policyId, null, permissionScope.toString(), new Long(IAMPolicyPermission.PERMISSION_SCOPE_ID_CURRENT_CALLER),
262269
apiName, (accessType == null) ? null : accessType.toString(), Permission.Allow, false);
270+
if (addAccountScopedUseEntry) {
271+
_iamSrv.addIAMPermissionToIAMPolicy(policyId, null, PermissionScope.ACCOUNT.toString(), new Long(
272+
IAMPolicyPermission.PERMISSION_SCOPE_ID_CURRENT_CALLER), apiName, AccessType.UseEntry.toString(), Permission.Allow, false);
273+
}
263274
} else {
264275
for (Class<?> entityType : entityTypes) {
265276
_iamSrv.addIAMPermissionToIAMPolicy(policyId, entityType.getSimpleName(), permissionScope.toString(), new Long(
266277
IAMPolicyPermission.PERMISSION_SCOPE_ID_CURRENT_CALLER),
267278
apiName, (accessType == null) ? null : accessType.toString(), Permission.Allow, false);
279+
if (addAccountScopedUseEntry) {
280+
_iamSrv.addIAMPermissionToIAMPolicy(policyId, entityType.getSimpleName(), PermissionScope.ACCOUNT.toString(), new Long(
281+
IAMPolicyPermission.PERMISSION_SCOPE_ID_CURRENT_CALLER), apiName, AccessType.UseEntry.toString(), Permission.Allow, false);
282+
}
268283
}
269284
}
270285

0 commit comments

Comments
 (0)