@@ -106,7 +106,7 @@ func DeleteLoopbackAdapter(adapterName string) error {
106106}
107107
108108// This function gets the flattened network configuration (compliant with azure cni) in byte array format
109- func getNetworkConfig (configFilePath string ) ([]byte , error ) {
109+ func getNetworkConfig (configFilePath string , defaultDenyACL bool ) ([]byte , error ) {
110110 content , err := os .ReadFile (configFilePath )
111111 if err != nil {
112112 return nil , err
@@ -134,34 +134,35 @@ func getNetworkConfig(configFilePath string) ([]byte, error) {
134134 flatNetConfigMap [versionStr ] = configMap [versionStr ].(string )
135135 flatNetConfigMap [nameStr ] = configMap [nameStr ].(string )
136136
137- // TODO Check if default deny bool is enabled to true
138- // insert default dent policy here
139- defaultDenyOutACL := map [string ]interface {}{
140- "Name" : "EndpointPolicy" ,
141- "Value" : map [string ]interface {}{
142- "Type" : "ACL" ,
143- "Action" : "Block" ,
144- "Direction" : "Out" ,
145- "Priority" : 300 ,
146- },
147- }
137+ if defaultDenyACL {
138+ // insert default dent policy here
139+ defaultDenyOutACL := map [string ]interface {}{
140+ "Name" : "EndpointPolicy" ,
141+ "Value" : map [string ]interface {}{
142+ "Type" : "ACL" ,
143+ "Action" : "Block" ,
144+ "Direction" : "Out" ,
145+ "Priority" : 300 ,
146+ },
147+ }
148148
149- defaultDenyInACL := map [string ]interface {}{
150- "Name" : "EndpointPolicy" ,
151- "Value" : map [string ]interface {}{
152- "Type" : "ACL" ,
153- "Action" : "Block" ,
154- "Direction" : "In" ,
155- "Priority" : 300 ,
156- },
157- }
158- additionalArgsKey := "AdditionalArgs"
159- if _ , exists := flatNetConfigMap [additionalArgsKey ]; ! exists {
160- flatNetConfigMap [additionalArgsKey ] = []interface {}{}
161- }
149+ defaultDenyInACL := map [string ]interface {}{
150+ "Name" : "EndpointPolicy" ,
151+ "Value" : map [string ]interface {}{
152+ "Type" : "ACL" ,
153+ "Action" : "Block" ,
154+ "Direction" : "In" ,
155+ "Priority" : 300 ,
156+ },
157+ }
158+ additionalArgsKey := "AdditionalArgs"
159+ if _ , exists := flatNetConfigMap [additionalArgsKey ]; ! exists {
160+ flatNetConfigMap [additionalArgsKey ] = []interface {}{}
161+ }
162162
163- flatNetConfigMap [additionalArgsKey ] = append (flatNetConfigMap [additionalArgsKey ].([]interface {}), defaultDenyOutACL )
164- flatNetConfigMap [additionalArgsKey ] = append (flatNetConfigMap [additionalArgsKey ].([]interface {}), defaultDenyInACL )
163+ flatNetConfigMap [additionalArgsKey ] = append (flatNetConfigMap [additionalArgsKey ].([]interface {}), defaultDenyOutACL )
164+ flatNetConfigMap [additionalArgsKey ] = append (flatNetConfigMap [additionalArgsKey ].([]interface {}), defaultDenyInACL )
165+ }
165166
166167 // convert into bytes format
167168 netConfig , err := json .Marshal (flatNetConfigMap )
@@ -227,17 +228,17 @@ func execPlugin(rt *libcni.RuntimeConf, netconf []byte, operation, path string)
227228}
228229
229230// Attach - attaches network container to network.
230- func (cn * NetworkContainers ) Attach (podInfo cns.PodInfo , dockerContainerid string , netPluginConfig * NetPluginConfiguration ) error {
231+ func (cn * NetworkContainers ) Attach (podInfo cns.PodInfo , dockerContainerid string , netPluginConfig * NetPluginConfiguration , defaultDenyACL bool ) error {
231232 logger .Printf ("[Azure CNS] NetworkContainers.Attach called" )
232- err := configureNetworkContainerNetworking (cniAdd , podInfo .Name (), podInfo .Namespace (), dockerContainerid , netPluginConfig )
233+ err := configureNetworkContainerNetworking (cniAdd , podInfo .Name (), podInfo .Namespace (), dockerContainerid , netPluginConfig , defaultDenyACL )
233234 logger .Printf ("[Azure CNS] NetworkContainers.Attach finished" )
234235 return err
235236}
236237
237238// Detach - detaches network container from network.
238- func (cn * NetworkContainers ) Detach (podInfo cns.PodInfo , dockerContainerid string , netPluginConfig * NetPluginConfiguration ) error {
239+ func (cn * NetworkContainers ) Detach (podInfo cns.PodInfo , dockerContainerid string , netPluginConfig * NetPluginConfiguration , defaultDenyACL bool ) error {
239240 logger .Printf ("[Azure CNS] NetworkContainers.Detach called" )
240- err := configureNetworkContainerNetworking (cniDelete , podInfo .Name (), podInfo .Namespace (), dockerContainerid , netPluginConfig )
241+ err := configureNetworkContainerNetworking (cniDelete , podInfo .Name (), podInfo .Namespace (), dockerContainerid , netPluginConfig , defaultDenyACL )
241242 logger .Printf ("[Azure CNS] NetworkContainers.Detach finished" )
242243 return err
243244}
0 commit comments