Skip to content
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

adding smoke tests #653

Merged
merged 60 commits into from Mar 7, 2023
Merged

adding smoke tests #653

merged 60 commits into from Mar 7, 2023

Conversation

Prateeknandle
Copy link
Contributor

@Prateeknandle Prateeknandle commented Jan 12, 2023

Signed-off-by: Prateeknandle prateeknandle@gmail.com

opened new pr, old one is closed without merging, i blundered it during rebase.

@Prateeknandle
Copy link
Contributor Author

Prateeknandle commented Jan 12, 2023

didn't understood the problem here, working fine locally. here ig the exec.Command is not working.

@rksharma95
Copy link
Contributor

kubearmor/kubearmor-client#241 (comment) i opened an issue on kubearmor-client, ig it will ease out things here. after handling that we'll no longer required to handle policies from stdout and also the port-forward instruction will not be there to mess the json encoding.
WDYT @seswarrajan @nyrahul

@Prateeknandle
Copy link
Contributor Author

@rksharma95 now i'm getting the same error locally, seems like karmor discover cmd is not working. I tried the cmd in terminal but it does not generate any output

@Prateeknandle
Copy link
Contributor Author

@nyrahul can you run thi pr locally and please confirm, are you getting an error?

@nyrahul
Copy link
Contributor

nyrahul commented Jan 13, 2023

@nyrahul can you run thi pr locally and please confirm, are you getting an error?

@rksharma95 , can you please check this? Thanks

Signed-off-by: Prateeknandle <prateeknandle@gmail.com>
@Prateeknandle
Copy link
Contributor Author

@rksharma95 @nyrahul please review the pr

tests/smoke/smoke_test.go Outdated Show resolved Hide resolved
tests/smoke/smoke_test.go Outdated Show resolved Hide resolved
tests/smoke/smoke_test.go Outdated Show resolved Hide resolved
Signed-off-by: Prateeknandle <prateeknandle@gmail.com>
Signed-off-by: Prateeknandle <prateeknandle@gmail.com>
Signed-off-by: Prateeknandle <prateeknandle@gmail.com>
tests/smoke/smoke_test.go Outdated Show resolved Hide resolved
tests/smoke/smoke_test.go Outdated Show resolved Hide resolved
Signed-off-by: Prateeknandle <prateeknandle@gmail.com>
Signed-off-by: Prateeknandle <prateeknandle@gmail.com>
Signed-off-by: Prateeknandle <prateeknandle@gmail.com>
Signed-off-by: Prateeknandle <prateeknandle@gmail.com>
Signed-off-by: Prateeknandle <prateeknandle@gmail.com>
Signed-off-by: Prateeknandle <prateeknandle@gmail.com>
@Prateeknandle
Copy link
Contributor Author

Prateeknandle commented Jan 18, 2023

@nyrahul I tried to reduce the sleep time to 10 sec and also added the checkpod in BeforeSuite but it was giving error in unmarshalling, when i increase the sleep time to 20 & 25, it works fine.

Also the test case for Network policy also checks for protocol type and port no., should we not check them because sometimes it passes and sometimes not. Basically the policcy keeps changing the protocol and port no.

@nyrahul
Copy link
Contributor

nyrahul commented Jan 19, 2023

@nyrahul I tried to reduce the sleep time to 10 sec and also added the checkpod in BeforeSuite but it was giving error in unmarshalling, when i increase the sleep time to 20 & 25, it works fine.

Also the test case for Network policy also checks for protocol type and port no., should we not check them because sometimes it passes and sometimes not. Basically the policcy keeps changing the protocol and port no.

  • the unmarshalling error needs to be debugged
  • You say the policies keep changing ... Can you paste the policies that are generated in all cases?

@Prateeknandle
Copy link
Contributor Author

Prateeknandle commented Jan 19, 2023

@nyrahul

  1. [{"kind":"NetworkPolicy","apiVersion":"networking.k8s.io/v1","metadata":{"name":"autopol-egress-ffczpxzqoteados","namespace":"wordpress-mysql","creationTimestamp":null,"labels":{"app":"wordpress"}},"spec":{"podSelector":{"matchLabels":{"app":"wordpress"}},"egress":[{"ports":[{"protocol":"UDP"}]},{"ports":[{"protocol":"TCP","port":3306}]}],"policyTypes":["Egress"]}},{"kind":"NetworkPolicy","apiVersion":"networking.k8s.io/v1","metadata":{"name":"autopol-ingress-mxxzuhbjcjqwlyo","namespace":"wordpress-mysql","creationTimestamp":null,"labels":{"app":"wordpress"}},"spec":{"podSelector":{"matchLabels":{"app":"wordpress"}},"ingress":[{"ports":[{"protocol":"TCP","port":3306}],"from":[{"podSelector":{"matchLabels":{"app":"mysql"}}}]}],"policyTypes":["Ingress"]}},{"kind":"NetworkPolicy","apiVersion":"networking.k8s.io/v1","metadata":{"name":"autopol-egress-vqrepkxgmyhoxwn","namespace":"wordpress-mysql","creationTimestamp":null,"labels":{"app":"mysql"}},"spec":{"podSelector":{"matchLabels":{"app":"mysql"}},"egress":[{"ports":[{"protocol":"UDP"}]},{"ports":[{"protocol":"TCP","port":3306}],"to":[{"podSelector":{"matchLabels":{"app":"wordpress"}}}]}],"policyTypes":["Egress"]}}]

  2. [{"kind":"NetworkPolicy","apiVersion":"networking.k8s.io/v1","metadata":{"name":"autopol-ingress-xearahknuzwbstx","namespace":"wordpress-mysql","creationTimestamp":null,"labels":{"app":"mysql"}},"spec":{"podSelector":{"matchLabels":{"app":"mysql"}},"ingress":[{"ports":[{"protocol":"UDP"}]},{"ports":[{"protocol":"UDP","port":3306}]}],"policyTypes":["Ingress"]}},{"kind":"NetworkPolicy","apiVersion":"networking.k8s.io/v1","metadata":{"name":"autopol-egress-ayduueeldqknuak","namespace":"wordpress-mysql","creationTimestamp":null,"labels":{"app":"mysql"}},"spec":{"podSelector":{"matchLabels":{"app":"mysql"}},"egress":[{"ports":[{"protocol":"UDP"}]}],"policyTypes":["Egress"]}},{"kind":"NetworkPolicy","apiVersion":"networking.k8s.io/v1","metadata":{"name":"autopol-egress-hkdgbznulihhvgx","namespace":"wordpress-mysql","creationTimestamp":null,"labels":{"app":"wordpress"}},"spec":{"podSelector":{"matchLabels":{"app":"wordpress"}},"egress":[{"ports":[{"protocol":"UDP"}]},{"ports":[{"protocol":"TCP","port":3306}]}],"policyTypes":["Egress"]}}]

Signed-off-by: Prateeknandle <prateeknandle@gmail.com>
Signed-off-by: Prateeknandle <prateeknandle@gmail.com>
@Prateeknandle
Copy link
Contributor Author

@nyrahul while using sleep time 10 secs karmor discover cmd does not provide any policy as a output, that is why we're getting error while unmarshal, I've also implemented checkpod() to check wether the pod is up and running or not.

@nyrahul
Copy link
Contributor

nyrahul commented Jan 20, 2023

@nyrahul while using sleep time 10 secs karmor discover cmd does not provide any policy as a output, that is why we're getting error while unmarshal, I've also implemented checkpod() to check wether the pod is up and running or not.

Ok i see, in general, the discovery-engine might require to observe at least for 10 seconds before it can discover the policy.

@nyrahul
Copy link
Contributor

nyrahul commented Jan 20, 2023

@nyrahul

  1. [{"kind":"NetworkPolicy","apiVersion":"networking.k8s.io/v1","metadata":{"name":"autopol-egress-ffczpxzqoteados","namespace":"wordpress-mysql","creationTimestamp":null,"labels":{"app":"wordpress"}},"spec":{"podSelector":{"matchLabels":{"app":"wordpress"}},"egress":[{"ports":[{"protocol":"UDP"}]},{"ports":[{"protocol":"TCP","port":3306}]}],"policyTypes":["Egress"]}},{"kind":"NetworkPolicy","apiVersion":"networking.k8s.io/v1","metadata":{"name":"autopol-ingress-mxxzuhbjcjqwlyo","namespace":"wordpress-mysql","creationTimestamp":null,"labels":{"app":"wordpress"}},"spec":{"podSelector":{"matchLabels":{"app":"wordpress"}},"ingress":[{"ports":[{"protocol":"TCP","port":3306}],"from":[{"podSelector":{"matchLabels":{"app":"mysql"}}}]}],"policyTypes":["Ingress"]}},{"kind":"NetworkPolicy","apiVersion":"networking.k8s.io/v1","metadata":{"name":"autopol-egress-vqrepkxgmyhoxwn","namespace":"wordpress-mysql","creationTimestamp":null,"labels":{"app":"mysql"}},"spec":{"podSelector":{"matchLabels":{"app":"mysql"}},"egress":[{"ports":[{"protocol":"UDP"}]},{"ports":[{"protocol":"TCP","port":3306}],"to":[{"podSelector":{"matchLabels":{"app":"wordpress"}}}]}],"policyTypes":["Egress"]}}]
  2. [{"kind":"NetworkPolicy","apiVersion":"networking.k8s.io/v1","metadata":{"name":"autopol-ingress-xearahknuzwbstx","namespace":"wordpress-mysql","creationTimestamp":null,"labels":{"app":"mysql"}},"spec":{"podSelector":{"matchLabels":{"app":"mysql"}},"ingress":[{"ports":[{"protocol":"UDP"}]},{"ports":[{"protocol":"UDP","port":3306}]}],"policyTypes":["Ingress"]}},{"kind":"NetworkPolicy","apiVersion":"networking.k8s.io/v1","metadata":{"name":"autopol-egress-ayduueeldqknuak","namespace":"wordpress-mysql","creationTimestamp":null,"labels":{"app":"mysql"}},"spec":{"podSelector":{"matchLabels":{"app":"mysql"}},"egress":[{"ports":[{"protocol":"UDP"}]}],"policyTypes":["Egress"]}},{"kind":"NetworkPolicy","apiVersion":"networking.k8s.io/v1","metadata":{"name":"autopol-egress-hkdgbznulihhvgx","namespace":"wordpress-mysql","creationTimestamp":null,"labels":{"app":"wordpress"}},"spec":{"podSelector":{"matchLabels":{"app":"wordpress"}},"egress":[{"ports":[{"protocol":"UDP"}]},{"ports":[{"protocol":"TCP","port":3306}]}],"policyTypes":["Egress"]}}]
  3. [{"kind":"NetworkPolicy","apiVersion":"networking.k8s.io/v1","metadata":{"name":"autopol-egress-lrmbvlwhgeqtkhj","namespace":"wordpress-mysql","creationTimestamp":null,"labels":{"app":"wordpress"}},"spec":{"podSelector":{"matchLabels":{"app":"wordpress"}},"egress":[{"ports":[{"protocol":"UDP"}]},{"ports":[{"protocol":"TCP","port":3306}]}],"policyTypes":["Egress"]}},{"kind":"NetworkPolicy","apiVersion":"networking.k8s.io/v1","metadata":{"name":"autopol-ingress-mfiznqrzwlbqexw","namespace":"wordpress-mysql","creationTimestamp":null,"labels":{"app":"mysql"}},"spec":{"podSelector":{"matchLabels":{"app":"mysql"}},"ingress":[{"ports":[{"protocol":"UDP"}]},{"ports":[{"protocol":"UDP","port":3306}]}],"policyTypes":["Ingress"]}},{"kind":"NetworkPolicy","apiVersion":"networking.k8s.io/v1","metadata":{"name":"autopol-egress-qrlmdyysvkwrnyt","namespace":"wordpress-mysql","creationTimestamp":null,"labels":{"app":"mysql"}},"spec":{"podSelector":{"matchLabels":{"app":"mysql"}},"egress":[{"ports":[{"protocol":"UDP"}]}],"policyTypes":["Egress"]}}]

Please point to specifics. What do you see changing?

Signed-off-by: Prateeknandle <prateeknandle@gmail.com>
Signed-off-by: Prateeknandle <prateeknandle@gmail.com>
Signed-off-by: Prateeknandle <prateeknandle@gmail.com>
Signed-off-by: Prateeknandle <prateeknandle@gmail.com>
Signed-off-by: Prateeknandle <prateeknandle@gmail.com>
@Prateeknandle
Copy link
Contributor Author

Prateeknandle commented Feb 7, 2023

@rksharma95 can you please check why go-sec is failing, also @rksharma95 @nyrahul please review the pr

@rksharma95
Copy link
Contributor

@Prateeknandle PTAL https://www.joeshaw.org/dont-defer-close-on-writable-files/ ig it might help with deferring close() issues.

@rksharma95
Copy link
Contributor

@Prateeknandle PTAL kubearmor/KubeArmor#1098 for gosec issues.

Signed-off-by: Prateeknandle <prateeknandle@gmail.com>
@Prateeknandle
Copy link
Contributor Author

@rksharma95 @nyrahul now you can review the pr

Signed-off-by: Prateeknandle <prateeknandle@gmail.com>
Signed-off-by: Prateeknandle <prateeknandle@gmail.com>
Signed-off-by: Prateeknandle <prateeknandle@gmail.com>
Signed-off-by: Prateeknandle <prateeknandle@gmail.com>
Signed-off-by: Prateeknandle <prateeknandle@gmail.com>
@Prateeknandle
Copy link
Contributor Author

Prateeknandle commented Feb 9, 2023

@seswarrajan here is the network policy we are getting after 300 seconds so the policy we are getting should be considered final, do you think this is a valid policy and test cases should be molded acc to this?
policy - https://github.com/accuknox/discovery-engine/actions/runs/4118258190/jobs/7155494607#step:7:1154

policy have no protocal mentioned with port and port is also not 3306.
And if this policy is not a final/ideal network policy then should we consider the test for network policy to be flaky and keep it as it is ?

Signed-off-by: Prateeknandle <prateeknandle@gmail.com>
Signed-off-by: Prateeknandle <prateeknandle@gmail.com>
Signed-off-by: Prateeknandle <prateeknandle@gmail.com>
Signed-off-by: Prateeknandle <prateeknandle@gmail.com>
Signed-off-by: Prateeknandle <prateeknandle@gmail.com>
@Prateeknandle
Copy link
Contributor Author

@PrimalPimmy @rksharma95 can you please review the pr

Copy link
Member

@PrimalPimmy PrimalPimmy left a comment

Choose a reason for hiding this comment

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

LGTM

@PrimalPimmy PrimalPimmy dismissed nyrahul’s stale review March 7, 2023 06:40

resolved, so merging it

@PrimalPimmy PrimalPimmy merged commit 4bb4ca0 into accuknox:dev Mar 7, 2023
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.

None yet

4 participants