Skip to content

Commit 93e9581

Browse files
committed
fix: integrate Allow and Deny flags with NetworkPolicy validation
- Add missing flag integration in createNetworkpolicyInstance() - Fixes broken IP filtering where -allow and -deny flags were ignored - Add test coverage for Allow/Deny flag validation The NetworkPolicy instance was created without the Allow/Deny flag values, causing all IP filtering to be bypassed regardless of command-line flags
1 parent faac44c commit 93e9581

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

runner/runner.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,11 @@ func (runner *Runner) createNetworkpolicyInstance(options *Options) (*networkpol
412412
npOptions.DenyList = append(npOptions.DenyList, exclude)
413413
}
414414
}
415+
416+
// Add Allow and Deny flag integration
417+
npOptions.AllowList = append(npOptions.AllowList, options.Allow...)
418+
npOptions.DenyList = append(npOptions.DenyList, options.Deny...)
419+
415420
np, err := networkpolicy.New(npOptions)
416421
return np, err
417422
}

runner/runner_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,37 @@ func TestRunner_CSVRow(t *testing.T) {
222222
t.Error("CSV sanitization incorrectly modified non-vulnerable field")
223223
}
224224
}
225+
226+
func TestCreateNetworkpolicyInstance_AllowDenyFlags(t *testing.T) {
227+
// Test Allow flag blocks IPs outside allowed range
228+
options := &Options{}
229+
options.Allow = []string{"192.168.1.0/24"}
230+
231+
runner := &Runner{}
232+
np, err := runner.createNetworkpolicyInstance(options)
233+
require.Nil(t, err, "could not create networkpolicy instance")
234+
require.NotNil(t, np, "networkpolicy instance should not be nil")
235+
236+
// Should block IP outside allowed range
237+
allowed := np.Validate("8.8.8.8")
238+
require.False(t, allowed, "IP outside allowed range should be blocked")
239+
240+
// Should allow IP inside allowed range
241+
allowed = np.Validate("192.168.1.10")
242+
require.True(t, allowed, "IP inside allowed range should be allowed")
243+
244+
// Test Deny flag blocks IPs in denied range
245+
options = &Options{}
246+
options.Deny = []string{"127.0.0.0/8"}
247+
248+
np, err = runner.createNetworkpolicyInstance(options)
249+
require.Nil(t, err, "could not create networkpolicy instance")
250+
251+
// Should block IP in denied range
252+
allowed = np.Validate("127.0.0.1")
253+
require.False(t, allowed, "IP in denied range should be blocked")
254+
255+
// Should allow IP outside denied range
256+
allowed = np.Validate("8.8.8.8")
257+
require.True(t, allowed, "IP outside denied range should be allowed")
258+
}

0 commit comments

Comments
 (0)