-
Notifications
You must be signed in to change notification settings - Fork 259
Consume ACL for APIPA Endpoint from CreateNC Req #535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f452123
eaafe09
ff14067
42ff442
8bc949b
143cb49
7db604d
73ebf2d
4feb4ae
a6ddef1
7758c58
404eb16
f34a463
e44eca0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ package cns | |
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "strings" | ||
| ) | ||
|
|
||
| // Container Network Service DNC Contract | ||
|
|
@@ -63,6 +65,14 @@ type CreateNetworkContainerRequest struct { | |
| Routes []Route | ||
| AllowHostToNCCommunication bool | ||
| AllowNCToHostCommunication bool | ||
| EndpointPolicies []NetworkContainerRequestPolicies | ||
| } | ||
|
|
||
| // NetworkContainerRequestPolicies - specifies policies associated with create network request | ||
| type NetworkContainerRequestPolicies struct { | ||
| Type string | ||
| EndpointType string | ||
| Settings json.RawMessage | ||
| } | ||
|
|
||
| // ConfigureContainerNetworkingRequest - specifies request to attach/detach container to network. | ||
ashvindeodhar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
@@ -220,3 +230,51 @@ type UnpublishNetworkContainerResponse struct { | |
| UnpublishStatusCode int | ||
| UnpublishResponseBody []byte | ||
| } | ||
|
|
||
| // ValidAclPolicySetting - Used to validate ACL policy | ||
| type ValidAclPolicySetting struct { | ||
| Protocols string `json:","` | ||
| Action string `json:","` | ||
| Direction string `json:","` | ||
| LocalAddresses string `json:","` | ||
| RemoteAddresses string `json:","` | ||
| LocalPorts string `json:","` | ||
| RemotePorts string `json:","` | ||
| RuleType string `json:","` | ||
| Priority uint16 `json:","` | ||
| } | ||
|
|
||
| // Validate - Validates network container request policies | ||
| func (networkContainerRequestPolicy *NetworkContainerRequestPolicies) Validate() error { | ||
| // validate ACL policy | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As one of my comments said can we enforce the validation on apipa endpoint? Check if the provided acl is on apipa endpoint type, if not fail the validation because we don;t have support for acls on cust subnet endpoint. When we add that we should remove the enforced apipa endpoint validation you'll add here. Let me know if it makes sense / you want to discuss this further.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, restricted this API only to APIPA in latest commit. |
||
| if networkContainerRequestPolicy != nil { | ||
| if strings.EqualFold(networkContainerRequestPolicy.Type, "ACLPolicy") && strings.EqualFold(networkContainerRequestPolicy.EndpointType, "APIPA") { | ||
| var requestedAclPolicy ValidAclPolicySetting | ||
| if err := json.Unmarshal(networkContainerRequestPolicy.Settings, &requestedAclPolicy); err != nil { | ||
| return fmt.Errorf("ACL policy failed to pass validation with error: %+v ", err) | ||
| } | ||
| //Deny request if ACL Action is empty | ||
| if len(strings.TrimSpace(string(requestedAclPolicy.Action))) == 0 { | ||
| return fmt.Errorf("Action field cannot be empty in ACL Policy") | ||
| } | ||
| //Deny request if ACL Action is not Allow or Deny | ||
| if !strings.EqualFold(requestedAclPolicy.Action, "Allow") && !strings.EqualFold(requestedAclPolicy.Action, "Deny") { | ||
| return fmt.Errorf("Only Allow or Deny is supported in Action field") | ||
| } | ||
| //Deny request if ACL Direction is empty | ||
| if len(strings.TrimSpace(string(requestedAclPolicy.Direction))) == 0 { | ||
| return fmt.Errorf("Direction field cannot be empty in ACL Policy") | ||
| } | ||
| //Deny request if ACL direction is not In or Out | ||
| if !strings.EqualFold(requestedAclPolicy.Direction, "In") && !strings.EqualFold(requestedAclPolicy.Direction, "Out") { | ||
| return fmt.Errorf("Only In or Out is supported in Direction field") | ||
| } | ||
| if requestedAclPolicy.Priority == 0 { | ||
| return fmt.Errorf("Priority field cannot be empty in ACL Policy") | ||
| } | ||
| } else { | ||
| return fmt.Errorf("Only ACL Policies on APIPA endpoint supported") | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.