np-guard / netpol-analyzer

A Golang library for analyzing k8s connectivity-configuration resources (a.k.a. network policies)
Apache License 2.0
9 stars 2 forks source link

connlist implementing exposure analysis #296

Closed shireenf-ibm closed 9 months ago

shireenf-ibm commented 9 months ago

issue #236

task + sub-task :

- [on base branch ] initial computing of exposure analysis - (basic exposure cases - entire class + rules with `namespaceSelector`)
   *  - [ this branch] code implementations in connlist: compute (separate) exposure-analysis results in `getConnectionsBetweenPeers` into the new returned value

the focus in this PR is to store the exposure analysis conns separately from the p2pconns; i.e implementations in connlist pkg

main file changes in connlist:

main changes under eval pkg which are relevant to review are related to the new pod flags : IngressProtected and EgressProtected (adding + handling them), + removed unused code

shireenf-ibm commented 9 months ago

tested changes locally by printing the []ExposedPeer result for debug , got expected results

adisos commented 9 months ago

tested changes locally by printing the []ExposedPeer result for debug , got expected results

can you add here few examples for those printed results?

shireenf-ibm commented 9 months ago

tested changes locally by printing the []ExposedPeer result for debug , got expected results

can you add here few examples for those printed results? 1. allow-all-test : we have one workload and an ingress + egress netpol that allowe all : Screenshot 2024-01-17 101831

(the &{true map[]} is for all connections , i simply printed %v for the variable containing AllowedConnectivity interface value)

  1. test : minimal_test_with_unmatched_ns : two peers:

    • one is not protected by netpols at all
    • and one peer is protected on ingress only, with potential namespaces having a selector "foo"

Screenshot 2024-01-17 101928

  1. same test as in (2.), but added to the ingress netpol following rule

    - from:
    - namespaceSelector: {}
    ports:
    - port: 8050
      protocol: TCP

so we have the any-namespace and the namespace with foo selector enabled on same TCP connection we should only see that it is exposed to entire ns on that connection (since the ns with selector included in it)

Screenshot 2024-01-17 102133