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

[Policy Assistant] explain command: support setting (B)ANPs via CLI arg #201

Open
huntergregory opened this issue Feb 26, 2024 · 6 comments
Assignees

Comments

@huntergregory
Copy link
Contributor

huntergregory commented Feb 26, 2024

Successor to #153. Child issue of #150.

Right now we have AdminNetworkPolicies hard-coded (referenced in analyze.go). A user should be able to specify NetworkPolicy, AdminNetworkPolicy, and the BaselineAdminNetworkPolicy by:

  • grabbing these from their Kubernetes cluster
  • specifying the filepath for all policy yamls
  • or both

Code in question:

if args.AllNamespaces || len(args.Namespaces) > 0 {
kubeClient, err := kube.NewKubernetesForContext(args.Context)
utils.DoOrDie(err)
namespaces := args.Namespaces
if args.AllNamespaces {
nsList, err := kubeClient.GetAllNamespaces()
utils.DoOrDie(err)
kubeNamespaces = nsList.Items
namespaces = []string{v1.NamespaceAll}
}
kubePolicies, err = kube.ReadNetworkPoliciesFromKube(kubeClient, namespaces)
if err != nil {
logrus.Errorf("unable to read network policies from kube, ns '%s': %+v", namespaces, err)
}
kubePods, err = kube.GetPodsInNamespaces(kubeClient, namespaces)
if err != nil {
logrus.Errorf("unable to read pods from kube, ns '%s': %+v", namespaces, err)
}
}
// 2. read policies from file
if args.PolicyPath != "" {
policiesFromPath, err := kube.ReadNetworkPoliciesFromPath(args.PolicyPath)
utils.DoOrDie(err)
kubePolicies = append(kubePolicies, policiesFromPath...)
}
// 3. read example policies
if args.UseExamplePolicies {
kubePolicies = append(kubePolicies, netpol.AllExamples...)
kubeANPs = examples.CoreGressRulesCombinedANB
kubeBANPs = examples.CoreGressRulesCombinedBANB
}

@Peac36
Copy link
Contributor

Peac36 commented Apr 13, 2024

/assign

@Peac36
Copy link
Contributor

Peac36 commented Apr 15, 2024

Hey, @huntergregory can you share more details about the task? Is it about reading (B)ANPs from a cluster or file path?
Since I'm new to the project any information would be helpful.


Is there a weekly meeting about this project where I can join and ask these kinds of questions?

@huntergregory
Copy link
Contributor Author

Hey Nikola, thanks for looking to pick this up. Just fixed this issue's description, let me know if you have any questions.

Is there a weekly meeting about this project where I can join and ask these kinds of questions?

Yes! Would be great to have you. We meet every other Tuesday (some more details at this link)

@huntergregory
Copy link
Contributor Author

huntergregory commented Apr 22, 2024

I think the CLI already has the arguments we need (code is in analyze.go). I think they are like --policy-path, --namespace, --all-namespaces.

To create the CLI binary:

  • change into the cmd/policy-assistant/ directory
  • make cyclonus
  • binary at ‘cmd/cyclonus/cyclonus’ I believe

@Peac36
Copy link
Contributor

Peac36 commented Apr 22, 2024

Thanks for the info Hunter.I already started working on this, but more questions arose.

Should cyclonus always work with the (B)ANPs or they should be enabled/disabled via an arguments?

What is the expected behavior if one of the request fail while trying to get info from the api-server?

@huntergregory
Copy link
Contributor Author

Should cyclonus always work with the (B)ANPs or they should be enabled/disabled via an arguments?
Let's always include every policy type.

What is the expected behavior if one of the request fail while trying to get info from the api-server?
I would just log errors with logrus.Errorf() and continue. But if API Server returns this:

error: the server doesn't have a resource type "adminnetworkpolicy"

ideally, we would just log a warning message that ANP isn't defined instead of saying there's an error.

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

No branches or pull requests

2 participants