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

Add --audit and --audit-destination flags #40

Merged
merged 1 commit into from
Apr 3, 2019
Merged

Conversation

rbren
Copy link
Contributor

@rbren rbren commented Mar 29, 2019

  • Created validator.AuditData, a struct meant to contain a full Fairwinds report
  • Created validator.RunAudit to populate AuditData
  • Created --audit flag in main.go to trigger RunAudit, prints to stdout by default
  • Created --audit-destination flag to submit the audit as a JSON POST request

@rbren
Copy link
Contributor Author

rbren commented Mar 29, 2019

Here's a quick look at CLI output:

image

Copy link
Contributor

@robscott robscott left a comment

Choose a reason for hiding this comment

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

Hey @bobby-brennan, thanks for this PR! It looks really promising, with some great changes. Just added some questions below. It looks like a rebase would be good here, and it may even be worth squashing a couple commits.


// RunAudit runs a full Fairwinds audit and returns an AuditData object
func RunAudit(config conf.Configuration, kubeAPI *kube.API) (AuditData, error) {
// TODO: Validate pods and containers
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment seems strange, we're already validating pods and containers that are part of deployments

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah you're right, that's a bit confusing.

In the comment below (copied from elsewhere) it says Once we are validating more than deployments - I was trying to make this a more explicit TODO. Maybe Validate pods and containers that are not part of deployments? Or is there something else we should be validating?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the next goal would be to add other parent resources of pods to this. That includes stateful sets, daemonsets, and cron jobs. I think it would be good to eventually capture pods that did not have a parent resource, but that could potentially be quite challenging. As far as containers specifically, they are always contained inside pods and can't exist outside of that context in Kubernetes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, thanks, that makes sense. Updated the comment accordingly.

Errors: uint(1),
}

acutalAudit, _ := RunAudit(c, k8s)
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like it would be good to also set the second variable here as err and verify that it's nil as one of the tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

main.go Outdated
body, _ := ioutil.ReadAll(resp.Body)
glog.Println(string(body))
} else {
printSummary := func(summary validator.ResultSummary, indent string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of all the logic to manage indentation below this, could we get by with something like yaml output?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, that's probably easier to maintain and more useful in the long run. Done.

@@ -43,8 +46,10 @@ var log = logf.Log.WithName("fairwinds")
func main() {
dashboard := flag.Bool("dashboard", false, "Runs the webserver for Fairwinds dashboard.")
webhook := flag.Bool("webhook", false, "Runs the webhook webserver.")
audit := flag.Bool("audit", false, "Runs a one-time audit.")
Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand this correctly, audit, webhook, and dashboard are all separate modes Fairwinds can run in, but it can never run in more than one of them. Is that accurate? If so, it might make more sense to have a single mode/service/whatever argument with a default value, maybe dashboard?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was under the impression that you could run webhook and dashboard simultaneously. Is that wrong?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't believe that's currently possible due to them both requiring a server to run, and those servers being different implementations (one of which is specific to controller-runtime's webhook implementation). I think it could be possible to run them together at some point in the future, but it may be simplest to keep them separate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If that's the case, it might make sense to split these operations into different binaries. I can take a crack at that in another PR if you agree.

For now, I set audit as the default, since that's the simplest operation. It'll also exit immediately, so if you intended a different operation you won't be sitting there waiting for it to finish.

@rbren rbren force-pushed the bb/remote-audit branch 2 times, most recently from 3432f4b to 41c247e Compare April 3, 2019 17:40
@rbren
Copy link
Contributor Author

rbren commented Apr 3, 2019

Thanks for the review! Rebased && squashed - let me know if I missed anything

Add option to send audit results to a remote host

add audit flag to print results to stdout

add comments

make comments more consistent

move audit test

fix fullaudit_test

add test instructions to README

update audit test

simplify stdout output

update comment

fix import

run audit by default
Copy link
Contributor

@robscott robscott left a comment

Choose a reason for hiding this comment

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

looks good to me, thanks!

@rbren rbren merged commit beb7791 into master Apr 3, 2019
@rbren rbren deleted the bb/remote-audit branch April 4, 2019 18:41
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.

2 participants