Skip to content

Commit f34a463

Browse files
committed
placeholder for src/dest IP's + validation
1 parent 404eb16 commit f34a463

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

cns/NetworkContainerContract.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,22 @@ func (networkContainerRequestPolicy *NetworkContainerRequestPolicies) Validate()
253253
if err := json.Unmarshal(networkContainerRequestPolicy.Settings, &requestedAclPolicy); err != nil {
254254
return fmt.Errorf("ACL policy failed to pass validation with error: %+v ", err)
255255
}
256+
//Deny request if ACL Action is empty
256257
if len(strings.TrimSpace(string(requestedAclPolicy.Action))) == 0 {
257258
return fmt.Errorf("Action field cannot be empty in ACL Policy")
258259
}
260+
//Deny request if ACL Action is not Allow or Deny
261+
if !strings.EqualFold(requestedAclPolicy.Action, "Allow") && !strings.EqualFold(requestedAclPolicy.Action, "Deny") {
262+
return fmt.Errorf("Only Allow or Deny is supported in Action field")
263+
}
264+
//Deny request if ACL Direction is empty
265+
if len(strings.TrimSpace(string(requestedAclPolicy.Direction))) == 0 {
266+
return fmt.Errorf("Direction field cannot be empty in ACL Policy")
267+
}
268+
//Deny request if ACL direction is not In or Out
269+
if !strings.EqualFold(requestedAclPolicy.Direction, "In") && !strings.EqualFold(requestedAclPolicy.Direction, "Out") {
270+
return fmt.Errorf("Only Allow or Deny is supported in Action field")
271+
}
259272
if requestedAclPolicy.Priority == 0 {
260273
return fmt.Errorf("Priority field cannot be empty in ACL Policy")
261274
}

cns/hnsclient/hnsclient_windows.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,14 @@ func configureAclSettingHostNCApipaEndpoint(
445445
if err = json.Unmarshal(requestedPolicy.Settings, &requestedAclPolicy); err != nil {
446446
return nil, fmt.Errorf("Failed to Unmarshal requested ACL policy: %+v with error: %S", requestedPolicy.Settings, err)
447447
}
448+
//Using {NetworkContainerIP} as a placeholder to signal using Network Container IP
449+
if strings.EqualFold(requestedAclPolicy.LocalAddresses, "{NetworkContainerIP}") {
450+
requestedAclPolicy.LocalAddresses = networkContainerApipaIP
451+
}
452+
//Using {HostApipaIP} as a placeholder to signal using Host Apipa IP
453+
if strings.EqualFold(requestedAclPolicy.RemoteAddresses, "{HostApipaIP}") {
454+
requestedAclPolicy.RemoteAddresses = hostApipaIP
455+
}
448456
logger.Printf("ACL Policy requested in NcGoalState %+v", requestedAclPolicy)
449457
if err = addAclToEndpointPolicy(requestedAclPolicy, &endpointPolicies); err != nil {
450458
return nil, err

0 commit comments

Comments
 (0)