kubearmor / KubeArmor

Runtime Security Enforcement System. Workload hardening/sandboxing and implementing least-permissive policies made easy leveraging LSMs (BPF-LSM, AppArmor).
https://kubearmor.io/
Apache License 2.0
1.45k stars 335 forks source link

Deprecate k8s watchers in favor of k8s informers #1057

Open achrefbensaad opened 1 year ago

achrefbensaad commented 1 year ago

Feature Request

Short Description

Currently we are making use of kubernetes watchers to listen for resource events. This has two side effect:

Describe the solution you'd like

We should make use of k8s informers in order to solve the above mentioned problems.

Describe alternatives you've considered

TheRealSibasishBehera commented 1 year ago

Hi @achrefbensaad I would like to look into this issue , if nobody is working on this

achrefbensaad commented 1 year ago

Hi @TheRealSibasishBehera , Sure.

nyrahul commented 1 year ago

Hey @TheRealSibasishBehera , you have other issues assigned to you. Removing this one. Thank you for your active involvement.

eugercek commented 1 year ago

Hi @achrefbensaad I like to work on this issue if it's ok. I would appreciate some starting points, just to speed things up (only file:line), Issue's title is pretty self explanatory though.

achrefbensaad commented 1 year ago

Hi @eugercek, Sure. You can use this PR as a refrence.

eugercek commented 1 year ago

Hi, currently implementing informers on:

I'm not sure what can be done in crioHandler dockerHandler and containerdHandler. I'd appreciate a suggestion.

eugercek commented 1 year ago

Also I want to get pre-confirmation on some deletions:

  1. AFAIU WatchK8sSecurityPolicies is not used anymore, I'll delete it
  2. I believe we won't need some of the fields (resourceFoo and resourceFooLock) in KubeArmorDaemon after informers update:

    • K8sPods
    • SecurityPolicies
    • HostSecurityPolicies
    • DefaultPostures

      If I don't miss an eventual consistency problem, we only use these fields for having local copy of the.
      current state while reacting to watch events, we don't use them in any other place. Informers already solve this problem so deleting these makes sense too. If we wan't a unified resource API, can create new struct like Store and write getters to leverage informers' indexers.