Skip to content

Commit cc2aab5

Browse files
authored
Support for ACL (Hnsv2) (#705)
* initial changes * remove extraneous code * Add ACL and wireserver ACL * add ACLs * default acls * address comments * addressed comment
1 parent eab521d commit cc2aab5

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

cni/azure-windows.conflist

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,46 @@
4040
"DestinationPrefix": "10.0.0.0/8",
4141
"NeedEncap": true
4242
}
43+
},
44+
{
45+
"Name": "EndpointPolicy",
46+
"Value": {
47+
"Type": "ACL",
48+
"Action": "Allow",
49+
"Direction": "Out",
50+
"RemoteAddresses": "168.63.129.16/32",
51+
"Protocols": "17",
52+
"RemotePorts": "53",
53+
"Priority": 200
54+
}
55+
},
56+
{
57+
"Name": "EndpointPolicy",
58+
"Value": {
59+
"Type": "ACL",
60+
"Action": "Block",
61+
"Direction": "Out",
62+
"RemoteAddresses": "168.63.129.16/32",
63+
"Priority": 65000
64+
}
65+
},
66+
{
67+
"Name": "EndpointPolicy",
68+
"Value": {
69+
"Type": "ACL",
70+
"Action": "Allow",
71+
"Direction": "Out",
72+
"Priority": 65500
73+
}
74+
},
75+
{
76+
"Name": "EndpointPolicy",
77+
"Value": {
78+
"Type": "ACL",
79+
"Action": "Allow",
80+
"Direction": "In",
81+
"Priority": 65500
82+
}
4383
}
4484
]
4585
}

network/policy/policy.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const (
1010
OutBoundNatPolicy CNIPolicyType = "OutBoundNAT"
1111
RoutePolicy CNIPolicyType = "ROUTE"
1212
PortMappingPolicy CNIPolicyType = "NAT"
13+
ACLPolicy CNIPolicyType = "ACL"
1314
)
1415

1516
type CNIPolicyType string

network/policy/policy_windows.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ func GetPolicyType(policy Policy) CNIPolicyType {
176176
}
177177
}
178178

179+
// Check if the type is ACLPolicy
180+
if policy.Type == ACLPolicy {
181+
return ACLPolicy
182+
}
183+
179184
// Return empty string if the policy type is invalid
180185
log.Printf("Returning policyType INVALID")
181186
return ""
@@ -343,6 +348,28 @@ func GetHcnPortMappingPolicy(policy Policy) (hcn.EndpointPolicy, error) {
343348
return portMappingPolicy, nil
344349
}
345350

351+
// GetHcnACLPolicy returns ACL policy.
352+
func GetHcnACLPolicy(policy Policy) (hcn.EndpointPolicy, error) {
353+
aclEndpolicySetting := hcn.EndpointPolicy{
354+
Type: hcn.ACL,
355+
}
356+
357+
// Check beforehand, the input meets the expected format
358+
// otherwise, endpoint creation will fail later on.
359+
var aclPolicySetting hcn.AclPolicySetting
360+
if err := json.Unmarshal(policy.Data, &aclPolicySetting); err != nil {
361+
return aclEndpolicySetting, err
362+
}
363+
364+
aclPolicySettingBytes, err := json.Marshal(aclPolicySetting)
365+
if err != nil {
366+
return aclEndpolicySetting, err
367+
}
368+
369+
aclEndpolicySetting.Settings = aclPolicySettingBytes
370+
return aclEndpolicySetting, nil
371+
}
372+
346373
// GetHcnEndpointPolicies returns array of all endpoint policies.
347374
func GetHcnEndpointPolicies(policyType CNIPolicyType, policies []Policy, epInfoData map[string]interface{}, enableSnatForDns, enableMultiTenancy bool) ([]hcn.EndpointPolicy, error) {
348375
var (
@@ -363,6 +390,8 @@ func GetHcnEndpointPolicies(policyType CNIPolicyType, policies []Policy, epInfoD
363390
endpointPolicy, err = GetHcnRoutePolicy(policy)
364391
case PortMappingPolicy:
365392
endpointPolicy, err = GetHcnPortMappingPolicy(policy)
393+
case ACLPolicy:
394+
endpointPolicy, err = GetHcnACLPolicy(policy)
366395
default:
367396
// return error as we should be able to parse all the policies specified
368397
return hcnEndPointPolicies, fmt.Errorf("Failed to set Policy: Type: %s, Data: %s", policy.Type, policy.Data)

0 commit comments

Comments
 (0)