Skip to content

Commit cd15f4a

Browse files
committed
Merge branch 'master' into isaiahraya/npm-cilium-migration-script
2 parents 2f7d338 + 150d1c4 commit cd15f4a

File tree

19 files changed

+331
-98
lines changed

19 files changed

+331
-98
lines changed

aitelemetry/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import (
55

66
"github.com/Azure/azure-container-networking/common"
77
"github.com/microsoft/ApplicationInsights-Go/appinsights"
8+
"github.com/microsoft/ApplicationInsights-Go/appinsights/contracts"
89
)
910

1011
// Application trace/log structure
1112
type Report struct {
1213
Message string
14+
Level contracts.SeverityLevel
1315
Context string
1416
AppVersion string
1517
CustomDimensions map[string]string

aitelemetry/telemetrywrapper.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/Azure/azure-container-networking/processlock"
1212
"github.com/Azure/azure-container-networking/store"
1313
"github.com/microsoft/ApplicationInsights-Go/appinsights"
14+
"github.com/microsoft/ApplicationInsights-Go/appinsights/contracts"
1415
)
1516

1617
const (
@@ -35,6 +36,17 @@ const (
3536
defaultRefreshTimeoutInSecs = 10
3637
)
3738

39+
type Level = contracts.SeverityLevel
40+
41+
const (
42+
DebugLevel Level = contracts.Verbose
43+
InfoLevel Level = contracts.Information
44+
WarnLevel Level = contracts.Warning
45+
ErrorLevel Level = contracts.Error
46+
PanicLevel Level = contracts.Critical
47+
FatalLevel Level = contracts.Critical
48+
)
49+
3850
var debugMode bool
3951

4052
func setAIConfigDefaults(config *AIConfig) {
@@ -203,7 +215,7 @@ func NewAITelemetry(
203215
// and for rest it uses custom dimesion
204216
func (th *telemetryHandle) TrackLog(report Report) {
205217
// Initialize new trace message
206-
trace := appinsights.NewTraceTelemetry(report.Message, appinsights.Warning)
218+
trace := appinsights.NewTraceTelemetry(report.Message, report.Level)
207219

208220
// will be empty if cns used as telemetry service for cni
209221
if th.appVersion == "" {

azure-ipam/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ require (
7272
go.uber.org/multierr v1.11.0 // indirect
7373
golang.org/x/crypto v0.31.0 // indirect
7474
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
75-
golang.org/x/net v0.30.0 // indirect
75+
golang.org/x/net v0.33.0 // indirect
7676
golang.org/x/oauth2 v0.22.0 // indirect
7777
golang.org/x/sync v0.10.0 // indirect
7878
golang.org/x/sys v0.28.0 // indirect

azure-ipam/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
237237
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
238238
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
239239
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
240-
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
241-
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
240+
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
241+
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
242242
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
243243
golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA=
244244
golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=

build/tools/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ require (
201201
golang.org/x/exp v0.0.0-20241004190924-225e2abe05e6 // indirect
202202
golang.org/x/exp/typeparams v0.0.0-20241108190413-2d47ceb2692f // indirect
203203
golang.org/x/mod v0.22.0 // indirect
204-
golang.org/x/net v0.32.0 // indirect
204+
golang.org/x/net v0.33.0 // indirect
205205
golang.org/x/sync v0.10.0 // indirect
206206
golang.org/x/sys v0.28.0 // indirect
207207
golang.org/x/text v0.21.0 // indirect

build/tools/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,8 @@ golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
510510
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
511511
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
512512
golang.org/x/net v0.16.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
513-
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI=
514-
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
513+
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
514+
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
515515
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
516516
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
517517
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=

cni/network/invoker_cns.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/Azure/azure-container-networking/iptables"
1616
"github.com/Azure/azure-container-networking/network"
1717
"github.com/Azure/azure-container-networking/network/networkutils"
18+
"github.com/Azure/azure-container-networking/network/policy"
1819
cniSkel "github.com/containernetworking/cni/pkg/skel"
1920
"github.com/pkg/errors"
2021
"go.uber.org/zap"
@@ -55,6 +56,7 @@ type IPResultInfo struct {
5556
skipDefaultRoutes bool
5657
routes []cns.Route
5758
pnpID string
59+
endpointPolicies []policy.Policy
5860
}
5961

6062
func (i IPResultInfo) MarshalLogObject(encoder zapcore.ObjectEncoder) error {
@@ -159,6 +161,7 @@ func (invoker *CNSIPAMInvoker) Add(addConfig IPAMAddConfig) (IPAMAddResult, erro
159161
skipDefaultRoutes: response.PodIPInfo[i].SkipDefaultRoutes,
160162
routes: response.PodIPInfo[i].Routes,
161163
pnpID: response.PodIPInfo[i].PnPID,
164+
endpointPolicies: response.PodIPInfo[i].EndpointPolicies,
162165
}
163166

164167
logger.Info("Received info for pod",
@@ -444,6 +447,7 @@ func configureDefaultAddResult(info *IPResultInfo, addConfig *IPAMAddConfig, add
444447
Gw: ncgw,
445448
})
446449
}
450+
447451
// if we have multiple infra ip result infos, we effectively append routes and ip configs to that same interface info each time
448452
// the host subnet prefix (in ipv4 or ipv6) will always refer to the same interface regardless of which ip result info we look at
449453
addResult.interfaceInfo[key] = network.InterfaceInfo{
@@ -452,6 +456,7 @@ func configureDefaultAddResult(info *IPResultInfo, addConfig *IPAMAddConfig, add
452456
IPConfigs: ipConfigs,
453457
Routes: resRoute,
454458
HostSubnetPrefix: *hostIPNet,
459+
EndpointPolicies: info.endpointPolicies,
455460
}
456461
}
457462

cni/network/invoker_cns_test.go

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/Azure/azure-container-networking/cns"
1313
"github.com/Azure/azure-container-networking/iptables"
1414
"github.com/Azure/azure-container-networking/network"
15+
"github.com/Azure/azure-container-networking/network/policy"
1516
cniSkel "github.com/containernetworking/cni/pkg/skel"
1617
"github.com/stretchr/testify/require"
1718
)
@@ -521,14 +522,38 @@ func TestCNSIPAMInvoker_Add(t *testing.T) {
521522
hostSubnetPrefix *net.IPNet
522523
options map[string]interface{}
523524
}
525+
valueOut := []byte(`{
526+
"Type": "ACL",
527+
"Action": "Block",
528+
"Direction": "Out",
529+
"Priority": 10000
530+
}`)
524531

532+
valueIn := []byte(`{
533+
"Type": "ACL",
534+
"Action": "Block",
535+
"Direction": "In",
536+
"Priority": 10000
537+
}`)
538+
539+
expectedEndpointPolicies := []policy.Policy{
540+
{
541+
Type: policy.EndpointPolicy,
542+
Data: valueOut,
543+
},
544+
{
545+
Type: policy.EndpointPolicy,
546+
Data: valueIn,
547+
},
548+
}
525549
tests := []struct {
526-
name string
527-
fields fields
528-
args args
529-
wantDefaultResult network.InterfaceInfo
530-
wantMultitenantResult network.InterfaceInfo
531-
wantErr bool
550+
name string
551+
fields fields
552+
args args
553+
wantDefaultDenyEndpoints bool
554+
wantDefaultResult network.InterfaceInfo
555+
wantMultitenantResult network.InterfaceInfo
556+
wantErr bool
532557
}{
533558
{
534559
name: "Test happy CNI add",
@@ -559,7 +584,8 @@ func TestCNSIPAMInvoker_Add(t *testing.T) {
559584
PrimaryIP: "10.0.0.1",
560585
Subnet: "10.0.0.0/24",
561586
},
562-
NICType: cns.InfraNIC,
587+
NICType: cns.InfraNIC,
588+
EndpointPolicies: expectedEndpointPolicies,
563589
},
564590
},
565591
Response: cns.Response{
@@ -588,6 +614,7 @@ func TestCNSIPAMInvoker_Add(t *testing.T) {
588614
Gateway: net.ParseIP("10.0.0.1"),
589615
},
590616
},
617+
EndpointPolicies: expectedEndpointPolicies,
591618
Routes: []network.RouteInfo{
592619
{
593620
Dst: network.Ipv4DefaultRouteDstPrefix,
@@ -597,7 +624,8 @@ func TestCNSIPAMInvoker_Add(t *testing.T) {
597624
NICType: cns.InfraNIC,
598625
HostSubnetPrefix: *parseCIDR("10.0.0.0/24"),
599626
},
600-
wantErr: false,
627+
wantDefaultDenyEndpoints: true,
628+
wantErr: false,
601629
},
602630
{
603631
name: "Test CNI add with pod ip info empty nictype",
@@ -665,7 +693,8 @@ func TestCNSIPAMInvoker_Add(t *testing.T) {
665693
NICType: cns.InfraNIC,
666694
HostSubnetPrefix: *parseCIDR("10.0.0.0/24"),
667695
},
668-
wantErr: false,
696+
wantDefaultDenyEndpoints: false,
697+
wantErr: false,
669698
},
670699
{
671700
name: "Test happy CNI add for both ipv4 and ipv6",
@@ -696,7 +725,8 @@ func TestCNSIPAMInvoker_Add(t *testing.T) {
696725
PrimaryIP: "10.0.0.1",
697726
Subnet: "10.0.0.0/24",
698727
},
699-
NICType: cns.InfraNIC,
728+
NICType: cns.InfraNIC,
729+
EndpointPolicies: expectedEndpointPolicies,
700730
},
701731
{
702732
PodIPConfig: cns.IPSubnet{
@@ -716,7 +746,8 @@ func TestCNSIPAMInvoker_Add(t *testing.T) {
716746
PrimaryIP: "fe80::1234:5678:9abc",
717747
Subnet: "fd11:1234::/112",
718748
},
719-
NICType: cns.InfraNIC,
749+
NICType: cns.InfraNIC,
750+
EndpointPolicies: expectedEndpointPolicies,
720751
},
721752
},
722753
Response: cns.Response{
@@ -749,6 +780,7 @@ func TestCNSIPAMInvoker_Add(t *testing.T) {
749780
Gateway: net.ParseIP("fe80::1234:5678:9abc"),
750781
},
751782
},
783+
EndpointPolicies: expectedEndpointPolicies,
752784
Routes: []network.RouteInfo{
753785
{
754786
Dst: network.Ipv4DefaultRouteDstPrefix,
@@ -762,7 +794,8 @@ func TestCNSIPAMInvoker_Add(t *testing.T) {
762794
NICType: cns.InfraNIC,
763795
HostSubnetPrefix: *parseCIDR("fd11:1234::/112"),
764796
},
765-
wantErr: false,
797+
wantDefaultDenyEndpoints: true,
798+
wantErr: false,
766799
},
767800
{
768801
name: "fail to request IP addresses from cns",
@@ -773,12 +806,24 @@ func TestCNSIPAMInvoker_Add(t *testing.T) {
773806
require: require,
774807
requestIPs: requestIPsHandler{
775808
ipconfigArgument: getTestIPConfigsRequest(),
776-
result: nil,
777-
err: errors.New("failed error from CNS"), //nolint "error for ut"
809+
result: &cns.IPConfigsResponse{
810+
PodIPInfo: []cns.PodIpInfo{
811+
{
812+
EndpointPolicies: expectedEndpointPolicies,
813+
},
814+
},
815+
Response: cns.Response{
816+
ReturnCode: 0,
817+
Message: "",
818+
},
819+
},
820+
err: errors.New("failed error from CNS"), //nolint "error for ut"
821+
778822
},
779823
},
780824
},
781-
wantErr: true,
825+
wantDefaultDenyEndpoints: false,
826+
wantErr: true,
782827
},
783828
}
784829
for _, tt := range tests {
@@ -794,6 +839,7 @@ func TestCNSIPAMInvoker_Add(t *testing.T) {
794839
}
795840
ipamAddResult, err := invoker.Add(IPAMAddConfig{nwCfg: tt.args.nwCfg, args: tt.args.args, options: tt.args.options})
796841
if tt.wantErr {
842+
require.Equalf([]policy.Policy(nil), ipamAddResult.interfaceInfo[string(cns.InfraNIC)].EndpointPolicies, "There was an error requesting IP addresses from cns")
797843
require.Error(err)
798844
} else {
799845
require.NoError(err)
@@ -809,6 +855,11 @@ func TestCNSIPAMInvoker_Add(t *testing.T) {
809855
}
810856
if ifInfo.NICType == cns.InfraNIC {
811857
require.Equalf(tt.wantDefaultResult, ifInfo, "incorrect default response")
858+
if tt.wantDefaultDenyEndpoints {
859+
require.Equalf(expectedEndpointPolicies, ifInfo.EndpointPolicies, "Correct default deny ACL")
860+
} else {
861+
require.Equalf([]policy.Policy(nil), ifInfo.EndpointPolicies, "Correct default deny ACL")
862+
}
812863
}
813864
}
814865
})

cni/network/network.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,10 @@ func (plugin *NetPlugin) createEpInfo(opt *createEpInfoOpt) (*network.EndpointIn
833833
// create endpoint policies by appending to network policies
834834
// the value passed into NetworkPolicies should be unaffected since we reassign here
835835
opt.policies = append(opt.policies, endpointPolicies...)
836+
837+
// appends endpoint policies specific to this interface
838+
opt.policies = append(opt.policies, opt.ifInfo.EndpointPolicies...)
839+
836840
endpointInfo.EndpointPolicies = opt.policies
837841
// add even more endpoint policies
838842
epPolicies, err := getPoliciesFromRuntimeCfg(opt.nwCfg, opt.ipamAddResult.ipv6Enabled) // not specific to delegated or infra

cni/network/network_windows_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,12 @@ func GetTestCNSResponseSecondaryWindows(macAddress string) map[string]network.In
878878
SkipDefaultRoutes: true,
879879
NICType: cns.InfraNIC,
880880
HostSubnetPrefix: *getCIDRNotationForAddress("20.224.0.0/16"),
881+
EndpointPolicies: []policy.Policy{
882+
{
883+
Type: policy.EndpointPolicy,
884+
Data: GetRawACLPolicy(),
885+
},
886+
},
881887
},
882888
macAddress: {
883889
MacAddress: parsedMAC,
@@ -895,6 +901,12 @@ func GetTestCNSResponseSecondaryWindows(macAddress string) map[string]network.In
895901
},
896902
},
897903
NICType: cns.NodeNetworkInterfaceFrontendNIC,
904+
EndpointPolicies: []policy.Policy{
905+
{
906+
Type: policy.EndpointPolicy,
907+
Data: GetRawOutBoundNATPolicy(),
908+
},
909+
},
898910
},
899911
}
900912
}
@@ -1226,6 +1238,12 @@ func TestPluginWindowsAdd(t *testing.T) {
12261238
Gateway: net.ParseIP("10.244.2.1"),
12271239
},
12281240
},
1241+
EndpointPolicies: []policy.Policy{
1242+
{
1243+
Type: policy.EndpointPolicy,
1244+
Data: GetRawACLPolicy(),
1245+
},
1246+
},
12291247
},
12301248
epIDRegex: `.*`,
12311249
},
@@ -1269,6 +1287,12 @@ func TestPluginWindowsAdd(t *testing.T) {
12691287
Gateway: net.ParseIP("10.241.0.1"),
12701288
},
12711289
},
1290+
EndpointPolicies: []policy.Policy{
1291+
{
1292+
Type: policy.EndpointPolicy,
1293+
Data: GetRawOutBoundNATPolicy(),
1294+
},
1295+
},
12721296
},
12731297
epIDRegex: `.*`,
12741298
},
@@ -1326,6 +1350,8 @@ func TestPluginWindowsAdd(t *testing.T) {
13261350
epInfo1.EndpointPolicies[0] = policy.Policy{
13271351
Type: policy.ACLPolicy,
13281352
}
1353+
require.Len(t, epInfo1.EndpointPolicies, 1)
1354+
require.Len(t, epInfo2.EndpointPolicies, 1)
13291355
require.NotEqual(t, epInfo1.EndpointPolicies, epInfo2.EndpointPolicies)
13301356
}
13311357
// ensure the network policy slices are separate entities when in separate endpoint infos

0 commit comments

Comments
 (0)