Skip to content

ROX-29500: Use stackrox protobufs instead of types.NetworkInfo #2189

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

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d3c4a64
X-Smart-Branch-Parent: master
JoukoVirtanen Jun 27, 2025
037aa91
Reduced usage of NetworkInfo
JoukoVirtanen Jun 23, 2025
d9cc8be
Entirely removed types.NetworkInfo
JoukoVirtanen Jun 23, 2025
b325c41
Changed NetworkInfoBatch to NetworkConnectionBatch
JoukoVirtanen Jun 23, 2025
7871e22
Fixed TestProcessNetwork
JoukoVirtanen Jun 24, 2025
3c27b20
Fixed repeated_network_flow.go
JoukoVirtanen Jun 25, 2025
67010b6
Fixed listening_ports.go
JoukoVirtanen Jun 25, 2025
4bf0b9c
Fixed udp_networkflow.go
JoukoVirtanen Jun 25, 2025
340510f
Check for equality between connections checks for protocol
JoukoVirtanen Jun 26, 2025
23de1bb
Removed unused import
JoukoVirtanen Jun 26, 2025
b465bf6
Using EqualVT from generated code rather than own function
JoukoVirtanen Jun 28, 2025
b285896
Setting port variables
JoukoVirtanen Jul 2, 2025
f04ed83
Using EqualNetworkConnection for connections_and_endpoints.go
JoukoVirtanen Jul 2, 2025
712c132
adjustNetworkConnectionForComparison passes conn by value instead of …
JoukoVirtanen Jul 2, 2025
56cae48
Using bytes.Compare instead of CompareBytes
JoukoVirtanen Jul 2, 2025
1283ac1
Using proto.Equal instead of EqualVT
JoukoVirtanen Jul 3, 2025
f38392b
Removed NotNilTimestamp
JoukoVirtanen Jul 3, 2025
c0c605b
Fixed LessNetworkConnection
JoukoVirtanen Jul 3, 2025
9952557
Passing conn to adjustNetworkConnectionForComparison by reference rat…
JoukoVirtanen Jul 14, 2025
2fdd62b
Moved some vars to const
JoukoVirtanen Jul 14, 2025
1404d11
Moved adjustNetworkConnectionForComparison inside EqualNetworkConnection
JoukoVirtanen Jul 14, 2025
0e6a2eb
connections_and_endpoints.go doesn't compare close timestamps
JoukoVirtanen Jul 14, 2025
453bfdc
Use CloneVT to avoid mutation. Pass pointers to functions
JoukoVirtanen Jul 15, 2025
66f1706
Renamed NilTimestampStr back to NilTimestamp. Created placeholderIP f…
JoukoVirtanen Jul 15, 2025
2e99de6
Reduced usage of CloneVT()
JoukoVirtanen Jul 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
190 changes: 108 additions & 82 deletions integration-tests/integration_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package integrationtests

import (
"fmt"
"strings"
"testing"

sensorAPI "github.com/stackrox/rox/generated/internalapi/sensor"
"github.com/stackrox/rox/generated/storage"

"github.com/stretchr/testify/suite"

"github.com/stackrox/collector/integration-tests/pkg/collector"
Expand All @@ -13,6 +17,10 @@ import (
"github.com/stackrox/collector/integration-tests/suites"
)

const (
placeholderIP = "0.0.0.0"
)

func TestProcessNetwork(t *testing.T) {
suite.Run(t, new(suites.ProcessNetworkTestSuite))
}
Expand Down Expand Up @@ -162,40 +170,43 @@ func TestDuplicateEndpoints(t *testing.T) {

func TestConnectionsAndEndpointsNormal(t *testing.T) {
// Server uses a normal port. Client is assigned a port in the ephemeral range in the normal way
port := 40
normalPorts := &suites.ConnectionsAndEndpointsTestSuite{
Server: suites.Container{
Name: "socat-server-0",
Cmd: "socat TCP4-LISTEN:40,reuseaddr,fork - &",
ExpectedNetwork: []types.NetworkInfo{
ExpectedNetwork: []*sensorAPI.NetworkConnection{
{
LocalAddress: ":40",
RemoteAddress: "CLIENT_IP",
Role: "ROLE_SERVER",
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
CloseTimestamp: types.NilTimestamp,
LocalAddress: types.CreateNetworkAddress("", "", uint32(port)),
RemoteAddress: types.CreateNetworkAddress("", placeholderIP, 0),
Protocol: storage.L4Protocol_L4_PROTOCOL_TCP,
Role: sensorAPI.ClientServerRole_ROLE_SERVER,
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
CloseTimestamp: types.NotNilTimestamp,
},
},
ExpectedEndpoints: []types.EndpointInfo{
{
Protocol: "L4_PROTOCOL_TCP",
Address: types.ListenAddress{
AddressData: "\x00\x00\x00\x00",
Port: 40,
Port: port,
IpNetwork: "\x00\x00\x00\x00 ",
},
},
},
},
Client: suites.Container{
Name: "socat-client-0",
Cmd: "echo hello | socat - TCP4:SERVER_IP:40",
ExpectedNetwork: []types.NetworkInfo{
Cmd: fmt.Sprintf("echo hello | socat - TCP4:SERVER_IP:%d", port),
ExpectedNetwork: []*sensorAPI.NetworkConnection{
{
LocalAddress: "",
RemoteAddress: "SERVER_IP:40",
Role: "ROLE_CLIENT",
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
CloseTimestamp: types.NilTimestamp,
LocalAddress: nil,
RemoteAddress: types.CreateNetworkAddress("", placeholderIP, uint32(port)),
Protocol: storage.L4Protocol_L4_PROTOCOL_TCP,
Role: sensorAPI.ClientServerRole_ROLE_CLIENT,
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
CloseTimestamp: types.NotNilTimestamp,
},
},
ExpectedEndpoints: nil,
Expand All @@ -207,40 +218,43 @@ func TestConnectionsAndEndpointsNormal(t *testing.T) {
func TestConnectionsAndEndpointsHighLowPorts(t *testing.T) {
// The server is assigned a port in the ephemeral ports range.
// The client is assigned a source port in a non-ephemeral ports range
port := 40000
mixedHighLowPorts := &suites.ConnectionsAndEndpointsTestSuite{
Server: suites.Container{
Name: "socat-server-1",
Cmd: "socat TCP4-LISTEN:40000,reuseaddr,fork - &",
ExpectedNetwork: []types.NetworkInfo{
Cmd: fmt.Sprintf("socat TCP4-LISTEN:%d,reuseaddr,fork - &", port),
ExpectedNetwork: []*sensorAPI.NetworkConnection{
{
LocalAddress: ":40000",
RemoteAddress: "CLIENT_IP",
Role: "ROLE_SERVER",
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
CloseTimestamp: types.NilTimestamp,
LocalAddress: types.CreateNetworkAddress("", "", uint32(port)),
RemoteAddress: types.CreateNetworkAddress("", placeholderIP, 0),
Protocol: storage.L4Protocol_L4_PROTOCOL_TCP,
Role: sensorAPI.ClientServerRole_ROLE_SERVER,
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
CloseTimestamp: types.NotNilTimestamp,
},
},
ExpectedEndpoints: []types.EndpointInfo{
{
Protocol: "L4_PROTOCOL_TCP",
Address: types.ListenAddress{
AddressData: "\x00\x00\x00\x00",
Port: 40000,
Port: port,
IpNetwork: "\x00\x00\x00\x00 ",
},
},
},
},
Client: suites.Container{
Name: "socat-client-1",
Cmd: "echo hello | socat - TCP4:SERVER_IP:40000,sourceport=10000",
ExpectedNetwork: []types.NetworkInfo{
Cmd: fmt.Sprintf("echo hello | socat - TCP4:SERVER_IP:%d,sourceport=10000", port),
ExpectedNetwork: []*sensorAPI.NetworkConnection{
{
LocalAddress: "",
RemoteAddress: "SERVER_IP:40000",
Role: "ROLE_CLIENT",
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
CloseTimestamp: types.NilTimestamp,
LocalAddress: nil,
RemoteAddress: types.CreateNetworkAddress("", placeholderIP, uint32(port)),
Protocol: storage.L4Protocol_L4_PROTOCOL_TCP,
Role: sensorAPI.ClientServerRole_ROLE_CLIENT,
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
CloseTimestamp: types.NotNilTimestamp,
},
},
ExpectedEndpoints: nil,
Expand All @@ -252,25 +266,27 @@ func TestConnectionsAndEndpointsHighLowPorts(t *testing.T) {
func TestConnectionsAndEndpointsServerHigh(t *testing.T) {
// The server is assigned a port in the ephemeral ports range.
// The client is assigned a port in the ephemeral ports range in the normal way.
port := 60999
mixedHighLowPorts := &suites.ConnectionsAndEndpointsTestSuite{
Server: suites.Container{
Name: "socat-server-2",
Cmd: "socat TCP4-LISTEN:60999,reuseaddr,fork - &",
ExpectedNetwork: []types.NetworkInfo{
Cmd: fmt.Sprintf("socat TCP4-LISTEN:%d,reuseaddr,fork - &", port),
ExpectedNetwork: []*sensorAPI.NetworkConnection{
{
LocalAddress: ":60999",
RemoteAddress: "CLIENT_IP",
Role: "ROLE_SERVER",
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
CloseTimestamp: types.NilTimestamp,
LocalAddress: types.CreateNetworkAddress("", "", uint32(port)),
RemoteAddress: types.CreateNetworkAddress("", placeholderIP, 0),
Protocol: storage.L4Protocol_L4_PROTOCOL_TCP,
Role: sensorAPI.ClientServerRole_ROLE_SERVER,
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
CloseTimestamp: types.NotNilTimestamp,
},
},
ExpectedEndpoints: []types.EndpointInfo{
{
Protocol: "L4_PROTOCOL_TCP",
Address: types.ListenAddress{
AddressData: "\x00\x00\x00\x00",
Port: 60999,
Port: port,
IpNetwork: "\x00\x00\x00\x00 ",
},
},
Expand All @@ -279,13 +295,14 @@ func TestConnectionsAndEndpointsServerHigh(t *testing.T) {
Client: suites.Container{
Name: "socat-client-2",
Cmd: "echo hello | socat - TCP4:SERVER_IP:60999",
ExpectedNetwork: []types.NetworkInfo{
ExpectedNetwork: []*sensorAPI.NetworkConnection{
{
LocalAddress: "",
RemoteAddress: "SERVER_IP:60999",
Role: "ROLE_CLIENT",
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
CloseTimestamp: types.NilTimestamp,
LocalAddress: nil,
RemoteAddress: types.CreateNetworkAddress("", placeholderIP, uint32(port)),
Protocol: storage.L4Protocol_L4_PROTOCOL_TCP,
Role: sensorAPI.ClientServerRole_ROLE_CLIENT,
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
CloseTimestamp: types.NotNilTimestamp,
},
},
ExpectedEndpoints: nil,
Expand All @@ -297,40 +314,43 @@ func TestConnectionsAndEndpointsServerHigh(t *testing.T) {
func TestConnectionsAndEndpointsSourcePort(t *testing.T) {
// The server is assigned a port in the ephemeral ports range.
// The client is assigned a source port in a non-ephemeral ports range
port := 10000
mixedHighLowPorts := &suites.ConnectionsAndEndpointsTestSuite{
Server: suites.Container{
Name: "socat-server-1",
Cmd: "socat TCP4-LISTEN:10000,reuseaddr,fork - &",
ExpectedNetwork: []types.NetworkInfo{
Cmd: fmt.Sprintf("socat TCP4-LISTEN:%d,reuseaddr,fork - &", port),
ExpectedNetwork: []*sensorAPI.NetworkConnection{
{
LocalAddress: ":10000",
RemoteAddress: "CLIENT_IP",
Role: "ROLE_SERVER",
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
CloseTimestamp: types.NilTimestamp,
LocalAddress: types.CreateNetworkAddress("", "", uint32(port)),
RemoteAddress: types.CreateNetworkAddress("", placeholderIP, 0),
Protocol: storage.L4Protocol_L4_PROTOCOL_TCP,
Role: sensorAPI.ClientServerRole_ROLE_SERVER,
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
CloseTimestamp: types.NotNilTimestamp,
},
},
ExpectedEndpoints: []types.EndpointInfo{
{
Protocol: "L4_PROTOCOL_TCP",
Address: types.ListenAddress{
AddressData: "\x00\x00\x00\x00",
Port: 10000,
Port: port,
IpNetwork: "\x00\x00\x00\x00 ",
},
},
},
},
Client: suites.Container{
Name: "socat-client-1",
Cmd: "echo hello | socat - TCP4:SERVER_IP:10000,sourceport=40000",
ExpectedNetwork: []types.NetworkInfo{
Cmd: fmt.Sprintf("echo hello | socat - TCP4:SERVER_IP:%d,sourceport=40000", port),
ExpectedNetwork: []*sensorAPI.NetworkConnection{
{
LocalAddress: "",
RemoteAddress: "SERVER_IP:10000",
Role: "ROLE_CLIENT",
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
CloseTimestamp: types.NilTimestamp,
LocalAddress: nil,
RemoteAddress: types.CreateNetworkAddress("", placeholderIP, uint32(port)),
Protocol: storage.L4Protocol_L4_PROTOCOL_TCP,
Role: sensorAPI.ClientServerRole_ROLE_CLIENT,
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
CloseTimestamp: types.NotNilTimestamp,
},
},
ExpectedEndpoints: nil,
Expand All @@ -341,10 +361,11 @@ func TestConnectionsAndEndpointsSourcePort(t *testing.T) {

func TestConnectionsAndEndpointsUDPNormal(t *testing.T) {
// A test for UDP
port := 53
mixedHighLowPorts := &suites.ConnectionsAndEndpointsTestSuite{
Server: suites.Container{
Name: "socat-server-udp",
Cmd: "socat UDP-LISTEN:53,reuseaddr,fork - &",
Cmd: fmt.Sprintf("socat UDP-LISTEN:%d,reuseaddr,fork - &", port),
// TODO UDP connections are not always reported on the server side
ExpectedNetwork: nil,
// ExpectedNetwork: []types.NetworkInfo{
Expand All @@ -361,14 +382,15 @@ func TestConnectionsAndEndpointsUDPNormal(t *testing.T) {
},
Client: suites.Container{
Name: "socat-client-udp",
Cmd: "echo hello | socat - UDP:SERVER_IP:53",
ExpectedNetwork: []types.NetworkInfo{
Cmd: fmt.Sprintf("echo hello | socat - UDP:SERVER_IP:%d", port),
ExpectedNetwork: []*sensorAPI.NetworkConnection{
{
LocalAddress: "",
RemoteAddress: "SERVER_IP:53",
Role: "ROLE_CLIENT",
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
CloseTimestamp: types.NilTimestamp,
LocalAddress: nil,
RemoteAddress: types.CreateNetworkAddress("", placeholderIP, uint32(port)),
Protocol: storage.L4Protocol_L4_PROTOCOL_UDP,
Role: sensorAPI.ClientServerRole_ROLE_CLIENT,
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
CloseTimestamp: types.NotNilTimestamp,
},
},
ExpectedEndpoints: nil,
Expand All @@ -379,10 +401,11 @@ func TestConnectionsAndEndpointsUDPNormal(t *testing.T) {

func TestConnectionsAndEndpointsUDPNoReuseaddr(t *testing.T) {
// A test for UDP without reuseaddr
port := 53
mixedHighLowPorts := &suites.ConnectionsAndEndpointsTestSuite{
Server: suites.Container{
Name: "socat-server-udp",
Cmd: "socat UDP-LISTEN:53,fork - &",
Cmd: fmt.Sprintf("socat UDP-LISTEN:%d,fork - &", port),
// TODO UDP connections are not always reported on the server side
ExpectedNetwork: nil,
// ExpectedNetwork: []types.NetworkInfo{
Expand All @@ -399,14 +422,15 @@ func TestConnectionsAndEndpointsUDPNoReuseaddr(t *testing.T) {
},
Client: suites.Container{
Name: "socat-client-udp",
Cmd: "echo hello | socat - UDP:SERVER_IP:53",
ExpectedNetwork: []types.NetworkInfo{
Cmd: fmt.Sprintf("echo hello | socat - UDP:SERVER_IP:%d", port),
ExpectedNetwork: []*sensorAPI.NetworkConnection{
{
LocalAddress: "",
RemoteAddress: "SERVER_IP:53",
Role: "ROLE_CLIENT",
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
CloseTimestamp: types.NilTimestamp,
LocalAddress: nil,
RemoteAddress: types.CreateNetworkAddress("", placeholderIP, uint32(port)),
Protocol: storage.L4Protocol_L4_PROTOCOL_UDP,
Role: sensorAPI.ClientServerRole_ROLE_CLIENT,
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
CloseTimestamp: types.NotNilTimestamp,
},
},
ExpectedEndpoints: nil,
Expand All @@ -417,10 +441,11 @@ func TestConnectionsAndEndpointsUDPNoReuseaddr(t *testing.T) {

func TestConnectionsAndEndpointsUDPNoFork(t *testing.T) {
// A test for UDP without fork or reuseaddr
port := 53
mixedHighLowPorts := &suites.ConnectionsAndEndpointsTestSuite{
Server: suites.Container{
Name: "socat-server-udp",
Cmd: "socat UDP-LISTEN:53 - &",
Cmd: fmt.Sprintf("socat UDP-LISTEN:%d - &", port),
// TODO UDP connections are not always reported on the server side
ExpectedNetwork: nil,
// ExpectedNetwork: []types.NetworkInfo{
Expand All @@ -437,14 +462,15 @@ func TestConnectionsAndEndpointsUDPNoFork(t *testing.T) {
},
Client: suites.Container{
Name: "socat-client-udp",
Cmd: "echo hello | socat - UDP:SERVER_IP:53",
ExpectedNetwork: []types.NetworkInfo{
Cmd: fmt.Sprintf("echo hello | socat - UDP:SERVER_IP:%d", port),
ExpectedNetwork: []*sensorAPI.NetworkConnection{
{
LocalAddress: "",
RemoteAddress: "SERVER_IP:53",
Role: "ROLE_CLIENT",
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
CloseTimestamp: types.NilTimestamp,
LocalAddress: nil,
RemoteAddress: types.CreateNetworkAddress("", placeholderIP, uint32(port)),
Protocol: storage.L4Protocol_L4_PROTOCOL_UDP,
Role: sensorAPI.ClientServerRole_ROLE_CLIENT,
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
CloseTimestamp: types.NotNilTimestamp,
},
},
ExpectedEndpoints: nil,
Expand Down
Loading
Loading