Skip to content

Commit 290a8bc

Browse files
khos2owyadvr
authored andcommitted
CLOUDSTACK-10166: Get accountId and domainId from VPC when tagging a NetworkACL as a user (#2347)
This fixes the issue that a non-root user cannot tag a network ACL item and after the fix a non-root user still cannot tag a globally defined ACL item and only the ACLs they have access to.
1 parent e0d5364 commit 290a8bc

1 file changed

Lines changed: 27 additions & 16 deletions

File tree

server/src/com/cloud/tags/TaggedResourceManagerImpl.java

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@
2424
import javax.inject.Inject;
2525
import javax.naming.ConfigurationException;
2626

27-
import com.cloud.network.vpc.VpcOfferingVO;
28-
import com.cloud.offerings.NetworkOfferingVO;
29-
import com.cloud.storage.SnapshotPolicyVO;
30-
import com.cloud.user.dao.AccountDao;
31-
import com.cloud.utils.exception.CloudRuntimeException;
3227
import org.apache.cloudstack.api.Identity;
3328
import org.apache.cloudstack.api.InternalIdentity;
3429
import org.apache.cloudstack.context.CallContext;
@@ -56,18 +51,21 @@
5651
import com.cloud.network.dao.Site2SiteVpnGatewayVO;
5752
import com.cloud.network.rules.FirewallRuleVO;
5853
import com.cloud.network.rules.PortForwardingRuleVO;
59-
import com.cloud.network.security.SecurityGroupVO;
6054
import com.cloud.network.security.SecurityGroupRuleVO;
55+
import com.cloud.network.security.SecurityGroupVO;
6156
import com.cloud.network.vpc.NetworkACLItemVO;
6257
import com.cloud.network.vpc.NetworkACLVO;
6358
import com.cloud.network.vpc.StaticRouteVO;
59+
import com.cloud.network.vpc.VpcOfferingVO;
6460
import com.cloud.network.vpc.VpcVO;
61+
import com.cloud.offerings.NetworkOfferingVO;
6562
import com.cloud.projects.ProjectVO;
6663
import com.cloud.server.ResourceTag;
6764
import com.cloud.server.ResourceTag.ResourceObjectType;
6865
import com.cloud.server.TaggedResourceService;
6966
import com.cloud.service.ServiceOfferingVO;
7067
import com.cloud.storage.DiskOfferingVO;
68+
import com.cloud.storage.SnapshotPolicyVO;
7169
import com.cloud.storage.SnapshotVO;
7270
import com.cloud.storage.VMTemplateVO;
7371
import com.cloud.storage.VolumeVO;
@@ -77,6 +75,7 @@
7775
import com.cloud.user.DomainManager;
7876
import com.cloud.user.OwnedBy;
7977
import com.cloud.user.UserVO;
78+
import com.cloud.user.dao.AccountDao;
8079
import com.cloud.utils.Pair;
8180
import com.cloud.utils.component.ManagerBase;
8281
import com.cloud.utils.db.DB;
@@ -86,6 +85,7 @@
8685
import com.cloud.utils.db.Transaction;
8786
import com.cloud.utils.db.TransactionCallbackNoReturn;
8887
import com.cloud.utils.db.TransactionStatus;
88+
import com.cloud.utils.exception.CloudRuntimeException;
8989
import com.cloud.vm.NicVO;
9090
import com.cloud.vm.UserVmVO;
9191
import com.cloud.vm.snapshot.VMSnapshotVO;
@@ -146,7 +146,6 @@ public class TaggedResourceManagerImpl extends ManagerBase implements TaggedReso
146146
@Inject
147147
AccountDao _accountDao;
148148

149-
150149
@Override
151150
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
152151
return true;
@@ -195,6 +194,20 @@ private Pair<Long, Long> getAccountDomain(long resourceId, ResourceObjectType re
195194
domainId = ((SecurityGroupVO)SecurityGroup).getDomainId();
196195
}
197196

197+
// if the resource type is network acl, get the accountId and domainId from VPC following: NetworkACLItem -> NetworkACL -> VPC
198+
if (resourceType == ResourceObjectType.NetworkACL) {
199+
NetworkACLItemVO aclItem = (NetworkACLItemVO)entity;
200+
Object networkACL = _entityMgr.findById(s_typeMap.get(ResourceObjectType.NetworkACLList), aclItem.getAclId());
201+
Long vpcId = ((NetworkACLVO)networkACL).getVpcId();
202+
203+
if (vpcId != null && vpcId != 0) {
204+
Object vpc = _entityMgr.findById(s_typeMap.get(ResourceObjectType.Vpc), vpcId);
205+
206+
accountId = ((VpcVO)vpc).getAccountId();
207+
domainId = ((VpcVO)vpc).getDomainId();
208+
}
209+
}
210+
198211
if (entity instanceof OwnedBy) {
199212
accountId = ((OwnedBy)entity).getAccountId();
200213
}
@@ -207,8 +220,7 @@ private Pair<Long, Long> getAccountDomain(long resourceId, ResourceObjectType re
207220
accountId = Account.ACCOUNT_ID_SYSTEM;
208221
}
209222

210-
if ((domainId == null) || ((accountId != null) && (domainId.longValue() == -1)))
211-
{
223+
if ((domainId == null) || ((accountId != null) && (domainId.longValue() == -1))) {
212224
domainId = _accountDao.getDomainIdForGivenAccountId(accountId);
213225
}
214226
return new Pair<Long, Long>(accountId, domainId);
@@ -238,7 +250,7 @@ public List<ResourceTag> createTags(final List<String> resourceIds, final Resour
238250
public void doInTransactionWithoutResult(TransactionStatus status) {
239251
for (String key : tags.keySet()) {
240252
for (String resourceId : resourceIds) {
241-
if (!resourceType.resourceTagsSupport()) {
253+
if (!resourceType.resourceTagsSupport()) {
242254
throw new InvalidParameterValueException("The resource type " + resourceType + " doesn't support resource tags");
243255
}
244256

@@ -249,9 +261,8 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
249261
Long domainId = accountDomainPair.second();
250262
Long accountId = accountDomainPair.first();
251263

252-
if ((domainId != null) && (domainId == -1))
253-
{
254-
throw new CloudRuntimeException("Invalid DomainId : -1");
264+
if ((domainId != null) && (domainId == -1)) {
265+
throw new CloudRuntimeException("Invalid DomainId : -1");
255266
}
256267
if (accountId != null) {
257268
_accountMgr.checkAccess(caller, null, false, _accountMgr.getAccount(accountId));
@@ -290,10 +301,10 @@ public String getUuid(String resourceId, ResourceObjectType resourceType) {
290301
Object entity = _entityMgr.findById(clazz, resourceId);
291302
if (entity != null && entity instanceof Identity) {
292303
return ((Identity)entity).getUuid();
293-
}
304+
}
294305

295-
return resourceId;
296-
}
306+
return resourceId;
307+
}
297308

298309
@Override
299310
@DB

0 commit comments

Comments
 (0)