@@ -66,6 +66,12 @@ const (
6666
6767 // aclPriority200 indicates the ACL priority of 200
6868 aclPriority200 = 200
69+
70+ // aclPolicyType indicates a ACL policy
71+ aclPolicyType = "ACLPolicy"
72+
73+ //signals a APIPA endpoint type
74+ apipaEndpointType = "APIPA"
6975)
7076
7177var (
@@ -347,7 +353,8 @@ func configureAclSettingHostNCApipaEndpoint(
347353 networkContainerApipaIP string ,
348354 hostApipaIP string ,
349355 allowNCToHostCommunication bool ,
350- allowHostToNCCommunication bool ) ([]hcn.EndpointPolicy , error ) {
356+ allowHostToNCCommunication bool ,
357+ ncRequestedPolicies []cns.NetworkContainerRequestPolicies ) ([]hcn.EndpointPolicy , error ) {
351358 var (
352359 err error
353360 endpointPolicies []hcn.EndpointPolicy
@@ -426,8 +433,33 @@ func configureAclSettingHostNCApipaEndpoint(
426433 return nil , err
427434 }
428435 }
436+
429437 }
430438
439+ if ncRequestedPolicies != nil {
440+ // Iterate thru the requested endpoint policies where policy type is ACL, endpoint type is APIPA
441+ // include the raw json message in the endpoint policies
442+ for _ , requestedPolicy := range ncRequestedPolicies {
443+ if strings .EqualFold (requestedPolicy .Type , aclPolicyType ) && strings .EqualFold (requestedPolicy .EndpointType , apipaEndpointType ) {
444+ var requestedAclPolicy hcn.AclPolicySetting
445+ if err = json .Unmarshal (requestedPolicy .Settings , & requestedAclPolicy ); err != nil {
446+ return nil , fmt .Errorf ("Failed to Unmarshal requested ACL policy: %+v with error: %S" , requestedPolicy .Settings , err )
447+ }
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+ }
456+ logger .Printf ("ACL Policy requested in NcGoalState %+v" , requestedAclPolicy )
457+ if err = addAclToEndpointPolicy (requestedAclPolicy , & endpointPolicies ); err != nil {
458+ return nil , err
459+ }
460+ }
461+ }
462+ }
431463 return endpointPolicies , nil
432464}
433465
@@ -436,7 +468,8 @@ func configureHostNCApipaEndpoint(
436468 networkID string ,
437469 localIPConfiguration cns.IPConfiguration ,
438470 allowNCToHostCommunication bool ,
439- allowHostToNCCommunication bool ) (* hcn.HostComputeEndpoint , error ) {
471+ allowHostToNCCommunication bool ,
472+ ncPolicies []cns.NetworkContainerRequestPolicies ) (* hcn.HostComputeEndpoint , error ) {
440473 endpoint := & hcn.HostComputeEndpoint {
441474 Name : endpointName ,
442475 HostComputeNetwork : networkID ,
@@ -455,7 +488,8 @@ func configureHostNCApipaEndpoint(
455488 networkContainerApipaIP ,
456489 hostApipaIP ,
457490 allowNCToHostCommunication ,
458- allowHostToNCCommunication )
491+ allowHostToNCCommunication ,
492+ ncPolicies )
459493
460494 if err != nil {
461495 logger .Errorf ("[Azure CNS] Failed to configure ACL for HostNCApipaEndpoint. Error: %v" , err )
@@ -490,7 +524,8 @@ func CreateHostNCApipaEndpoint(
490524 networkContainerID string ,
491525 localIPConfiguration cns.IPConfiguration ,
492526 allowNCToHostCommunication bool ,
493- allowHostToNCCommunication bool ) (string , error ) {
527+ allowHostToNCCommunication bool ,
528+ ncPolicies []cns.NetworkContainerRequestPolicies ) (string , error ) {
494529 var (
495530 network * hcn.HostComputeNetwork
496531 endpoint * hcn.HostComputeEndpoint
@@ -528,7 +563,8 @@ func CreateHostNCApipaEndpoint(
528563 network .Id ,
529564 localIPConfiguration ,
530565 allowNCToHostCommunication ,
531- allowHostToNCCommunication ); err != nil {
566+ allowHostToNCCommunication ,
567+ ncPolicies ); err != nil {
532568 logger .Errorf ("[Azure CNS] Failed to configure HostNCApipaEndpoint: %s. Error: %v" , endpointName , err )
533569 return "" , err
534570 }
0 commit comments