Skip to content

Commit 6c89475

Browse files
[CLOUDSTACK-10314] Add Text-Field to each ACL Rule
It is interesting to have a text field (e.g. CHAR-256) added to each ACL rule, which allows to enter a "reason" for each FW Rule created. This is valuable for customer documentation, as well as best practice for an evidence towards auditing the system
1 parent 2037dc9 commit 6c89475

34 files changed

Lines changed: 1403 additions & 282 deletions

File tree

api/src/main/java/com/cloud/network/vpc/NetworkACLItem.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,5 @@ enum Action {
7878
@Override
7979
boolean isDisplay();
8080

81+
String getReason();
8182
}

api/src/main/java/com/cloud/network/vpc/NetworkACLService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.apache.cloudstack.api.command.user.network.CreateNetworkACLCmd;
2222
import org.apache.cloudstack.api.command.user.network.ListNetworkACLListsCmd;
2323
import org.apache.cloudstack.api.command.user.network.ListNetworkACLsCmd;
24+
import org.apache.cloudstack.api.command.user.network.UpdateNetworkACLItemCmd;
2425

2526
import com.cloud.exception.ResourceUnavailableException;
2627
import com.cloud.utils.Pair;
@@ -119,8 +120,7 @@ public interface NetworkACLService {
119120
* @return
120121
* @throws ResourceUnavailableException
121122
*/
122-
NetworkACLItem updateNetworkACLItem(Long id, String protocol, List<String> sourceCidrList, NetworkACLItem.TrafficType trafficType, String action, Integer number,
123-
Integer sourcePortStart, Integer sourcePortEnd, Integer icmpCode, Integer icmpType, String newUUID, Boolean forDisplay) throws ResourceUnavailableException;
123+
NetworkACLItem updateNetworkACLItem(UpdateNetworkACLItemCmd updateNetworkACLItemCmd) throws ResourceUnavailableException;
124124

125125
/**
126126
* Associates ACL with specified Network

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ public class ApiConstants {
452452
public static final String SUPPORTED_SERVICES = "supportedservices";
453453
public static final String NSP_ID = "nspid";
454454
public static final String ACL_TYPE = "acltype";
455+
public static final String ACL_REASON = "reason";
455456
public static final String SUBDOMAIN_ACCESS = "subdomainaccess";
456457
public static final String LOAD_BALANCER_DEVICE_ID = "lbdeviceid";
457458
public static final String LOAD_BALANCER_DEVICE_NAME = "lbdevicename";

api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkACLCmd.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,12 @@ public class CreateNetworkACLCmd extends BaseAsyncCreateCmd {
100100
@Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "an optional field, whether to the display the rule to the end user or not", since = "4.4", authorized = {RoleType.Admin})
101101
private Boolean display;
102102

103+
@Parameter(name = ApiConstants.ACL_REASON, type = CommandType.STRING, description = "A description indicating why the ACL rule is required.")
104+
private String reason;
105+
103106
// ///////////////////////////////////////////////////
104107
// ///////////////// Accessors ///////////////////////
105108
// ///////////////////////////////////////////////////
106-
@Deprecated
107-
public Boolean getDisplay() {
108-
return display;
109-
}
110109

111110
@Override
112111
public boolean isDisplay() {
@@ -227,6 +226,10 @@ public Long getACLId() {
227226
return aclId;
228227
}
229228

229+
public String getReason() {
230+
return reason;
231+
}
232+
230233
@Override
231234
public void create() {
232235
NetworkACLItem result = _networkACLService.createNetworkACLItem(this);

api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLItemCmd.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@
2121
import org.apache.cloudstack.acl.RoleType;
2222
import org.apache.cloudstack.api.APICommand;
2323
import org.apache.cloudstack.api.ApiConstants;
24-
import org.apache.cloudstack.api.ApiErrorCode;
2524
import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
2625
import org.apache.cloudstack.api.Parameter;
27-
import org.apache.cloudstack.api.ServerApiException;
2826
import org.apache.cloudstack.api.response.NetworkACLItemResponse;
2927
import org.apache.cloudstack.context.CallContext;
3028
import org.apache.log4j.Logger;
@@ -85,6 +83,9 @@ public class UpdateNetworkACLItemCmd extends BaseAsyncCustomIdCmd {
8583
@Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "an optional field, whether to the display the rule to the end user or not", since = "4.4", authorized = {RoleType.Admin})
8684
private Boolean display;
8785

86+
@Parameter(name = ApiConstants.ACL_REASON, type = CommandType.STRING, description = "A description indicating why the ACL rule is required.")
87+
private String reason;
88+
8889
// ///////////////////////////////////////////////////
8990
// ///////////////// Accessors ///////////////////////
9091
// ///////////////////////////////////////////////////
@@ -173,15 +174,14 @@ public Integer getIcmpType() {
173174
return icmpType;
174175
}
175176

177+
public String getReason() {
178+
return reason;
179+
}
180+
176181
@Override
177182
public void execute() throws ResourceUnavailableException {
178183
CallContext.current().setEventDetails("Rule Id: " + getId());
179-
NetworkACLItem aclItem =
180-
_networkACLService.updateNetworkACLItem(getId(), getProtocol(), getSourceCidrList(), getTrafficType(), getAction(), getNumber(), getSourcePortStart(),
181-
getSourcePortEnd(), getIcmpCode(), getIcmpType(), this.getCustomId(), this.isDisplay());
182-
if (aclItem == null) {
183-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update network ACL item");
184-
}
184+
NetworkACLItem aclItem = _networkACLService.updateNetworkACLItem(this);
185185
NetworkACLItemResponse aclResponse = _responseGenerator.createNetworkACLItemResponse(aclItem);
186186
setResponseObject(aclResponse);
187187
aclResponse.setResponseName(getCommandName());

api/src/main/java/org/apache/cloudstack/api/response/NetworkACLItemResponse.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ public class NetworkACLItemResponse extends BaseResponse {
8585
@Param(description = "is rule for display to the regular user", since = "4.4", authorized = {RoleType.Admin})
8686
private Boolean forDisplay;
8787

88+
@SerializedName(ApiConstants.ACL_REASON)
89+
@Param(description = "an explanation on why this ACL rule is being applied", since = "4.12")
90+
private String reason;
91+
8892
public void setId(String id) {
8993
this.id = id;
9094
}
@@ -140,4 +144,12 @@ public void setAction(String action) {
140144
public void setForDisplay(Boolean forDisplay) {
141145
this.forDisplay = forDisplay;
142146
}
147+
148+
public void setReason(String reason) {
149+
this.reason = reason;
150+
}
151+
152+
public String getReason() {
153+
return reason;
154+
}
143155
}

engine/components-api/src/main/java/com/cloud/network/vpc/NetworkACLManager.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ public interface NetworkACLManager {
7878
* @param forDisplay TODO
7979
* @return
8080
*/
81-
NetworkACLItem createNetworkACLItem(Integer sourcePortStart, Integer sourcePortEnd, String protocol, List<String> sourceCidrList, Integer icmpCode, Integer icmpType,
82-
NetworkACLItem.TrafficType trafficType, Long aclId, String action, Integer number, Boolean forDisplay);
81+
NetworkACLItem createNetworkACLItem(NetworkACLItemVO networkACLItemVO);
8382

8483
/**
8584
* Returns Network ACL Item with specified Id
@@ -137,8 +136,7 @@ NetworkACLItem createNetworkACLItem(Integer sourcePortStart, Integer sourcePortE
137136
* @return
138137
* @throws ResourceUnavailableException
139138
*/
140-
NetworkACLItem updateNetworkACLItem(Long id, String protocol, List<String> sourceCidrList, NetworkACLItem.TrafficType trafficType, String action, Integer number,
141-
Integer sourcePortStart, Integer sourcePortEnd, Integer icmpCode, Integer icmpType, String customId, Boolean forDisplay) throws ResourceUnavailableException;
139+
NetworkACLItem updateNetworkACLItem(NetworkACLItemVO networkACLItemVO) throws ResourceUnavailableException;
142140

143141
/**
144142
* Associates acl with a network and applies the ACLItems

engine/schema/src/main/java/com/cloud/network/vpc/NetworkACLItemVO.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@
3333
import javax.persistence.Transient;
3434

3535
import com.cloud.utils.db.GenericDao;
36+
import com.cloud.utils.exception.CloudRuntimeException;
3637
import com.cloud.utils.net.NetUtils;
3738

3839
@Entity
3940
@Table(name = "network_acl_item")
40-
public class NetworkACLItemVO implements NetworkACLItem {
41+
public class NetworkACLItemVO implements NetworkACLItem, Cloneable {
4142

4243
/**
4344
*
@@ -97,12 +98,15 @@ public class NetworkACLItemVO implements NetworkACLItem {
9798
@Column(name = "display", updatable = true, nullable = false)
9899
protected boolean display = true;
99100

101+
@Column(name = "reason", length = 2500)
102+
private String reason;
103+
100104
public NetworkACLItemVO() {
101105
uuid = UUID.randomUUID().toString();
102106
}
103107

104108
public NetworkACLItemVO(Integer portStart, Integer portEnd, String protocol, long aclId, List<String> sourceCidrs, Integer icmpCode, Integer icmpType,
105-
TrafficType trafficType, Action action, int number) {
109+
TrafficType trafficType, Action action, int number, String reason) {
106110
sourcePortStart = portStart;
107111
sourcePortEnd = portEnd;
108112
this.protocol = protocol;
@@ -115,6 +119,7 @@ public NetworkACLItemVO(Integer portStart, Integer portEnd, String protocol, lon
115119
this.trafficType = trafficType;
116120
this.action = action;
117121
this.number = number;
122+
this.reason = reason;
118123
}
119124

120125
public void setSourceCidrList(List<String> sourceCidrs) {
@@ -252,4 +257,22 @@ public void setDisplay(boolean display) {
252257
public boolean isDisplay() {
253258
return display;
254259
}
260+
261+
@Override
262+
public String getReason() {
263+
return reason;
264+
}
265+
266+
public void setReason(String reason) {
267+
this.reason = reason;
268+
}
269+
270+
@Override
271+
protected NetworkACLItemVO clone(){
272+
try {
273+
return (NetworkACLItemVO)super.clone();
274+
} catch (CloneNotSupportedException e) {
275+
throw new CloudRuntimeException(e);
276+
}
277+
}
255278
}

engine/schema/src/main/resources/META-INF/db/schema-41100to41200.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717

1818
--;
1919
-- Schema upgrade from 4.11.0.0 to 4.12.0.0
20-
--;
20+
--;
21+
22+
-- [CLOUDSTACK-10314] Add reason column to ACL rule table
23+
ALTER TABLE `cloud`.`network_acl_item` ADD COLUMN `reason` VARCHAR(2500) AFTER `display`;

server/src/main/java/com/cloud/api/ApiResponseHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2363,7 +2363,7 @@ public NetworkACLItemResponse createNetworkACLItemResponse(NetworkACLItem aclIte
23632363
CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
23642364
}
23652365
response.setTags(tagResponses);
2366-
2366+
response.setReason(aclItem.getReason());
23672367
response.setObjectName("networkacl");
23682368
return response;
23692369
}

0 commit comments

Comments
 (0)