Skip to content

Add basic network policy for Ingress to Workers#488

Open
haiyanmeng wants to merge 2 commits into
agent-substrate:mainfrom
haiyanmeng:pr-340
Open

Add basic network policy for Ingress to Workers#488
haiyanmeng wants to merge 2 commits into
agent-substrate:mainfrom
haiyanmeng:pr-340

Conversation

@haiyanmeng

@haiyanmeng haiyanmeng commented Jul 22, 2026

Copy link
Copy Markdown

This PR includes #340 and several tiny enhancements:

- Add ate.dev/worker-pool label to NetworkPolicy metadata and remove Egress management to allow default egress behavior
- Define ateSystemNamespace and atenetRouterAppName constants for Ingress peer selectors
- Centralize deterministic NetworkPolicy naming logic (resources.NetworkPolicyName) and prevent trailing hyphens
- Add comprehensive E2E test suite for networkpolicy covering control plane reconciliation, positive data plane verification (authorized ingress via atenet-router), and negative data plane verification (unauthorized ingress blocking)

Here is the e2e test result:

$ ./hack/run-e2e.sh ./internal/e2e/suites/networkpolicy/...
=== RUN   TestNetworkPolicyLifecycleAndReconciliation
    networkpolicy_test.go:45: Creating namespace: pown-891
    networkpolicy_test.go:61: Creating WorkerPool pown-891/test-wp-netpol...
    networkpolicy_test.go:67: Waiting for NetworkPolicy substrate-test-wp-netpol-4d332 to be created...
    networkpolicy_test.go:83: Successfully retrieved NetworkPolicy substrate-test-wp-netpol-4d332
    networkpolicy_test.go:120: Deleting WorkerPool pown-891/test-wp-netpol and verifying NetworkPolicy GC...
    networkpolicy_test.go:139: NetworkPolicy substrate-test-wp-netpol-4d332 was successfully garbage collected
--- PASS: TestNetworkPolicyLifecycleAndReconciliation (2.48s)
=== RUN   TestNetworkPolicyDataPlaneEnforcement
    networkpolicy_test.go:143: Creating namespace: rulb-250
    networkpolicy_test.go:148: Waiting for ActorTemplate rulb-250/counter to be Ready...
    networkpolicy_test.go:148: ActorTemplate rulb-250/counter is Ready with golden snapshot "gs://snapshot-substrate-test-haiyanmeng-gke-dev/ate-demo-counter/7f7a56f7-a3c9-44ba-9486-c98e763282e7/2026-07-22T18:37:38Z-WVWHPIIGHK5MMVFYITI7ACPTG3"
    networkpolicy_test.go:159: Creating Actor "netpol-dataplane-rulb-250" in Atespace "rulb-250"...
    networkpolicy_test.go:176: Resuming Actor "netpol-dataplane-rulb-250"...
    networkpolicy_test.go:182: Actor "netpol-dataplane-rulb-250" reached RUNNING status
    networkpolicy_test.go:185: === Verifying authorized ingress via atenet-router ===
    networkpolicy_test.go:214: Positive Data Plane Verification PASSED: Successfully accessed actor "netpol-dataplane-rulb-250" via authorized atenet-router (HTTP 200): hello from: 169.254.17.2 | preserved memory count: 1 | preserved file counter: 1
    networkpolicy_test.go:217: === Verifying unauthorized ingress blocking ===
    networkpolicy_test.go:218: Creating namespace: jwnm-278
    networkpolicy_test.go:231: Target worker pod rulb-250/counter-856d7c896c-j9zcp has IP 10.24.0.31
    networkpolicy_test.go:256: Creating unauthorized probe pod jwnm-278/unauthorized-probe...
    networkpolicy_test.go:260: Pod jwnm-278/unauthorized-probe is RUNNING
    networkpolicy_test.go:272: Executing unauthorized connection attempt from jwnm-278/unauthorized-probe to 10.24.0.31:8080...
    networkpolicy_test.go:278: Negative Data Plane Verification PASSED: Unauthorized connection attempt from jwnm-278/unauthorized-probe to 10.24.0.31:8080 was blocked as expected (err: exit status 1)
--- PASS: TestNetworkPolicyDataPlaneEnforcement (13.01s)
PASS
Cleaning up 3 namespaces...
Deleting namespace pown-891...
Deleting namespace rulb-250...
Deleting namespace jwnm-278...
ok  	github.com/agent-substrate/substrate/internal/e2e/suites/networkpolicy	16.954s

Restrict Ingress to Workers and hence Actors to be only
from the Router component.

This makes the atecontroller responsible for K8s level network policy

Note: this is a belts-and-suspenders model as this applies on the Worker
level. This will be refined further with Actor-specific policies.
@haiyanmeng
haiyanmeng force-pushed the pr-340 branch 2 times, most recently from 3415f90 to 0af3ac5 Compare July 22, 2026 18:43
- Add ate.dev/worker-pool label to NetworkPolicy metadata and remove Egress management to allow default egress behavior
- Define ateSystemNamespace and atenetRouterAppName constants for Ingress peer selectors
- Centralize deterministic NetworkPolicy naming logic (resources.NetworkPolicyName) and prevent trailing hyphens
- Add comprehensive E2E test suite for networkpolicy covering control plane reconciliation, positive data plane verification (authorized ingress via atenet-router), and negative data plane verification (unauthorized ingress blocking)
@EItanya

Copy link
Copy Markdown
Collaborator

This PR includes #340 and several tiny enhancements:

Should we close #340 then?

Comment thread cmd/atecontroller/main.go
os.Exit(1)
}

if err = (&controllers.NetworkPolicyReconciler{

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be optional? seems like a net positive, but not sure if specific networking needs might want this togglable

@haiyanmeng

Copy link
Copy Markdown
Author

This PR includes #340 and several tiny enhancements:

Should we close #340 then?

I asked Bowei Du (@bowei) to close #340

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants