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

Enable audit logging for all of our test environments #348

Closed
ankeesler opened this issue Jan 21, 2021 · 2 comments
Closed

Enable audit logging for all of our test environments #348

ankeesler opened this issue Jan 21, 2021 · 2 comments
Assignees
Labels
chore Not a bug or an enhancement, but still a work item state/accepted All done!

Comments

@ankeesler
Copy link
Contributor

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

  • @enj and I were debugging a mysteriously deleted Secret, and we had a really hard time figuring out why it was getting deleted.
  • We enabled audit logging, and immediately discovered what entity was deleting the Secret and we were able to figure out our bug.
  • More generally: it would be helpful when debugging test environments to have an audit log to help us understand what is going on.

Describe the solution you'd like
A clear and concise description of what you want to happen.

  • Enable kube-apiserver audit logs in our test environments (i.e., our test kind clusters).
  • We can write this audit log to a file inside of the kind docker container.

Describe alternatives you've considered

  • None.

Are you considering submitting a PR for this feature?

  • How will this project improvement be tested?
  • Manually checking that audit logs are being populated after this fix goes in.
  • How does this change the current architecture?
  • It doesn't change our source code architecture, as it is a test change.
  • It will fill up our kind cluster disks more quickly, but these disks are ephemeral as they are inside of the kind container.
  • How will this change be backwards compatible?
  • Yes - this is a purely additive test change.
  • How will this feature be documented?
  • Perhaps we should have some sort of "how to debug test PR test failures" section in our CONTRIBUTING.md?

Additional context
Here is what @enj and I did to enable audit logs in one of our kind clusters.

  1. SSH into the VM on which our test kind cluster was running.
  2. Exec into the kind container.
  3. cd /etc/kubernetes
  4. Create an audit-policy.yaml file, something like the below.
apiVersion: audit.k8s.io/v1beta1
kind: Policy
metadata:
  name: Default
# Don't generate audit events for all requests in RequestReceived stage.
omitStages:
- "RequestReceived"
rules:
# Don't log requests for events
- level: None
  resources:
  - group: ""
    resources: ["events"]
# Don't log authenticated requests to certain non-resource URL paths.
- level: None
  userGroups: ["system:authenticated", "system:unauthenticated"]
  nonResourceURLs:
  - "/api*" # Wildcard matching.
  - "/version"
  - "/healthz"
  - "/readyz"
# A catch-all rule to log all other requests at the Metadata level.
- level: Metadata
  # Long-running requests like watches that fall under this rule will not
  # generate an audit event in RequestReceived.
  omitStages:
  - "RequestReceived"
  1. Add the --audit-policy-file=/etc/kubernetes/audit-policy.yaml flag to the manifests/kube-apiserver.yaml command array (surely there is a way in kind to do this).
  2. Add the --audit-log-path=/var/log/kube-audit.log flag to the manifests/kube-apiserver.yaml command array (surely there is a way in kind to do this).
  3. Add volumeMounts and volumes for those files (surely there is a way in kind to do this).
   volumeMounts:
    - mountPath: /var/log
      name: log
    - mountPath: /etc/kubernetes/audit-policy.yaml
      name: audit
      readOnly: true
...

  volumes:
  - hostPath:
      path: /var/log
      type: DirectoryOrCreate
    name: log
  - hostPath:
      path: /etc/kubernetes/audit-policy.yaml
      type: File
    name: audit
@mattmoyer mattmoyer added this to To do in Development via automation Jan 21, 2021
@mattmoyer mattmoyer removed this from To do in Development Jan 21, 2021
@pinniped-ci-bot pinniped-ci-bot added enhancement New feature or request priority/undecided Not yet prioritized chore Not a bug or an enhancement, but still a work item and removed enhancement New feature or request labels Feb 5, 2021
@enj
Copy link
Contributor

enj commented Jun 11, 2021

This is implemented now in all Kind clusters used in CI (the KAS pod logs collected via export-cluster-diagnostics contain the audit logs as well). Leaving this issue open to track future enhancements to Kind clusters running on developer machines as well as non-Kind based CI environments such as EKS.

@mattmoyer
Copy link
Contributor

I think we can consider this issue closed now that we have coverage on Kind clusters. I don't think we'll ever get to 100% coverage with this capability, and this meets most of our needs.

@pinniped-ci-bot pinniped-ci-bot added priority/backlog Prioritized for an upcoming iteration and removed priority/undecided Not yet prioritized labels Jun 15, 2021
@pinniped-ci-bot pinniped-ci-bot added state/accepted All done! and removed priority/backlog Prioritized for an upcoming iteration labels Jun 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Not a bug or an enhancement, but still a work item state/accepted All done!
Projects
None yet
Development

No branches or pull requests

4 participants