FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

CKS: allow the APIs of the Kubernetes provider in the project role by adestis-mf · Pull Request #14690 · apache/cloudstack · GitHub

Repository navigation

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import org.apache.cloudstack.api.command.user.address.AssociateIPAddrCmd;
import org.apache.cloudstack.api.command.user.address.DisassociateIPAddrCmd;
import org.apache.cloudstack.api.command.user.address.ListPublicIpAddressesCmd;
import org.apache.cloudstack.api.command.user.config.ListCapabilitiesCmd;
import org.apache.cloudstack.api.command.user.firewall.CreateFirewallRuleCmd;
import org.apache.cloudstack.api.command.user.firewall.DeleteFirewallRuleCmd;
import org.apache.cloudstack.api.command.user.firewall.ListFirewallRulesCmd;
Expand All @@ -92,16 +93,21 @@
import org.apache.cloudstack.api.command.user.kubernetes.cluster.UpdateKubernetesClusterAffinityGroupCmd;
import org.apache.cloudstack.api.command.user.kubernetes.cluster.UpgradeKubernetesClusterCmd;
import org.apache.cloudstack.api.command.user.loadbalancer.AssignToLoadBalancerRuleCmd;
import org.apache.cloudstack.api.command.user.loadbalancer.CreateLBStickinessPolicyCmd;
import org.apache.cloudstack.api.command.user.loadbalancer.CreateLoadBalancerRuleCmd;
import org.apache.cloudstack.api.command.user.loadbalancer.DeleteLBStickinessPolicyCmd;
import org.apache.cloudstack.api.command.user.loadbalancer.DeleteLoadBalancerRuleCmd;
import org.apache.cloudstack.api.command.user.loadbalancer.ListLBStickinessPoliciesCmd;
import org.apache.cloudstack.api.command.user.loadbalancer.ListLoadBalancerRuleInstancesCmd;
import org.apache.cloudstack.api.command.user.loadbalancer.ListLoadBalancerRulesCmd;
import org.apache.cloudstack.api.command.user.loadbalancer.RemoveFromLoadBalancerRuleCmd;
import org.apache.cloudstack.api.command.user.loadbalancer.UpdateLoadBalancerRuleCmd;
import org.apache.cloudstack.api.command.user.network.CreateNetworkACLCmd;
import org.apache.cloudstack.api.command.user.network.DeleteNetworkACLCmd;
import org.apache.cloudstack.api.command.user.network.ListNetworkACLListsCmd;
import org.apache.cloudstack.api.command.user.network.ListNetworkACLsCmd;
import org.apache.cloudstack.api.command.user.network.ListNetworksCmd;
import org.apache.cloudstack.api.command.user.network.UpdateNetworkACLItemCmd;
import org.apache.cloudstack.api.command.user.snapshot.CreateSnapshotCmd;
import org.apache.cloudstack.api.command.user.snapshot.DeleteSnapshotCmd;
import org.apache.cloudstack.api.command.user.snapshot.ListSnapshotsCmd;
Expand All @@ -112,6 +118,7 @@
import org.apache.cloudstack.api.command.user.volume.DetachVolumeCmd;
import org.apache.cloudstack.api.command.user.volume.ListVolumesCmd;
import org.apache.cloudstack.api.command.user.volume.ResizeVolumeCmd;
import org.apache.cloudstack.api.command.user.vpc.ListVPCsCmd;
import org.apache.cloudstack.api.response.KubernetesClusterConfigResponse;
import org.apache.cloudstack.api.response.KubernetesClusterResponse;
import org.apache.cloudstack.api.response.KubernetesUserVmResponse;
Expand Down Expand Up @@ -267,6 +274,7 @@ public class KubernetesClusterManagerImpl extends ManagerBase implements Kuberne
private static final String DEFAULT_NETWORK_OFFERING_FOR_KUBERNETES_SERVICE_NAME = "DefaultNetworkOfferingforKubernetesService";
private static final List<Class<?>> PROJECT_KUBERNETES_ACCOUNT_ROLE_ALLOWED_APIS = Arrays.asList(
QueryAsyncJobResultCmd.class,
ListCapabilitiesCmd.class,
ListVMsCmd.class,
ListVolumesCmd.class,
CreateVolumeCmd.class,
Expand All @@ -275,6 +283,7 @@ public class KubernetesClusterManagerImpl extends ManagerBase implements Kuberne
DetachVolumeCmd.class,
ResizeVolumeCmd.class,
ListNetworksCmd.class,
ListVPCsCmd.class,
CreateSnapshotCmd.class,
ListSnapshotsCmd.class,
DeleteSnapshotCmd.class,
Expand All @@ -288,13 +297,18 @@ public class KubernetesClusterManagerImpl extends ManagerBase implements Kuberne
AssignToLoadBalancerRuleCmd.class,
RemoveFromLoadBalancerRuleCmd.class,
ListLoadBalancerRuleInstancesCmd.class,
ListLBStickinessPoliciesCmd.class,
CreateLBStickinessPolicyCmd.class,
DeleteLBStickinessPolicyCmd.class,
ListFirewallRulesCmd.class,
CreateFirewallRuleCmd.class,
UpdateFirewallRuleCmd.class,
DeleteFirewallRuleCmd.class,
ListNetworkACLsCmd.class,
CreateNetworkACLCmd.class,
DeleteNetworkACLCmd.class,
ListNetworkACLListsCmd.class,
UpdateNetworkACLItemCmd.class,
ListKubernetesClustersCmd.class,
ScaleKubernetesClusterCmd.class
);
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
import com.cloud.vm.dao.VMInstanceDao;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import org.apache.cloudstack.acl.Role;
import org.apache.cloudstack.acl.RolePermissionEntity;
import org.apache.cloudstack.acl.RoleService;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.acl.Rule;
import org.apache.cloudstack.affinity.AffinityGroupVO;
import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
import org.apache.cloudstack.api.BaseCmd;
Expand All @@ -63,6 +68,7 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
Expand Down Expand Up @@ -118,6 +124,9 @@ public class KubernetesClusterManagerImplTest {
@Mock
private HostDao hostDao;

@Mock
private RoleService roleService;

@Spy
@InjectMocks
KubernetesClusterManagerImpl kubernetesClusterManager;
Expand Down Expand Up @@ -914,4 +923,30 @@ public void testValidateNodeAffinityGroupsAffinityNoExistingWorkers() {
Mockito.verify(kubernetesClusterAffinityGroupMapDao).listAffinityGroupIdsByClusterIdAndNodeType(1L, WORKER.name());
}

@Test
public void testProjectKubernetesAccountRoleAllowsTheProviderApis() {
Role role = Mockito.mock(Role.class);
Mockito.when(roleService.createRole(Mockito.anyString(), Mockito.any(RoleType.class), Mockito.anyString(), Mockito.anyBoolean())).thenReturn(role);

kubernetesClusterManager.createProjectKubernetesAccountRole();

ArgumentCaptor<Rule> rules = ArgumentCaptor.forClass(Rule.class);
ArgumentCaptor<RolePermissionEntity.Permission> permissions = ArgumentCaptor.forClass(RolePermissionEntity.Permission.class);
Mockito.verify(roleService, Mockito.atLeastOnce()).createRolePermission(Mockito.eq(role), rules.capture(), permissions.capture(), Mockito.anyString());
List<String> ruleStrings = new ArrayList<>();
for (Rule rule : rules.getAllValues()) {
ruleStrings.add(rule.getRuleString());
}

for (String api : Arrays.asList("listCapabilities", "listVPCs", "listNetworkACLLists", "updateNetworkACLItem",
"listLBStickinessPolicies", "createLBStickinessPolicy", "deleteLBStickinessPolicy")) {
int index = ruleStrings.indexOf(api);
Assert.assertTrue(api + " is not in the role: " + ruleStrings, index >= 0);
Assert.assertEquals(api, RolePermissionEntity.Permission.ALLOW, permissions.getAllValues().get(index));
}
int last = ruleStrings.size() - 1;
Assert.assertEquals("*", ruleStrings.get(last));
Assert.assertEquals(RolePermissionEntity.Permission.DENY, permissions.getAllValues().get(last));
Comment on lines +936 to +949

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Both captors are filled by the same verify, so their lists are paired call by call and the indices can't diverge. Each API in the list gets exactly one ALLOW and * comes last with DENY, so a duplicate would be an ALLOW as well. I'd keep the test as it is.

}

}

Back | FazBrowse Home | New Git URL