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

⭐ Allow enabling pod discovery with an env var #473

Merged
merged 3 commits into from
Jul 28, 2022
Merged

Conversation

imilchev
Copy link
Member

@imilchev imilchev commented Jul 27, 2022

Allow enabling pod discovery by setting FEATURE_DISCOVER_PODS env var. If you'd like to test this you need to do the following:

  1. Make sure minikube is running minikube start
  2. In the mondoo-operator root directory run the following:
make generate-manifests
make load-minikube
kubectl apply -f mondoo-operator-manifests.yaml
  1. Edit the mondoo-operator deployment to add the env var
kubectl edit -n mondoo-operator deployment mondoo-operator-controller-manager

It should look like this:

....
containers:
  - args:
    - operator
    - --health-probe-bind-address=:8081
    - --metrics-bind-address=:8080
    - --leader-elect
    command:
    - /mondoo-operator
    env: # <-- this is the important bit
    - name: FEATURE_DISCOVER_PODS
      value: "1"
....
  1. Apply the following MondooOperatorConfig config:
apiVersion: k8s.mondoo.com/v1alpha2
kind: MondooOperatorConfig
metadata:
  name: mondoo-operator-config
spec:
  skipContainerResolution: true
  1. Create a Mondoo space and upload policies that are targeting k8s.pod assets
  2. Create a k8s integration in the Mondoo space and copy ONLY the command that creates the token
  3. Apply the following MondooAuditConfig:
apiVersion: k8s.mondoo.com/v1alpha2
kind: MondooAuditConfig
metadata:
  name: mondoo-client
  namespace: mondoo-operator
spec:
  mondooCredsSecretRef:
    name: mondoo-client
  mondooTokenSecretRef:
    name: mondoo-token
  scanner:
    image:
      name: docker.io/mondoo/client
      tag: edge-6.9.0-7
  kubernetesResources:
    enable: true

Within a minute the pods should show up in your Mondoo space

var enablePodDiscovery bool

func init() {
_, ok := os.LookupEnv("SCAN_DISCOVER_PODS")
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need some way to pass down this environment variable from the mondoo-operator Deployment to the generated CronJob definitions that will instantiate their own MondooClient?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we do. I just added the var to the client but forgot that it's called from the CronJob and not from the operator. Will update that once we can actually test it

imilchev added 2 commits July 28, 2022 13:00
Signed-off-by: Ivan Milchev <[email protected]>
Signed-off-by: Ivan Milchev <[email protected]>
@imilchev imilchev marked this pull request as ready for review July 28, 2022 11:40
Copy link
Contributor

@czunker czunker left a comment

Choose a reason for hiding this comment

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

Works! Nice! 🎉

@chris-rock
Copy link
Member

created #474 to track the discussion around the MondooOperatorConfig flag

@imilchev imilchev merged commit 858616e into main Jul 28, 2022
@imilchev imilchev deleted the ivan/discover-pods branch July 28, 2022 13:12
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.

4 participants