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 documentation on pod-security.kubernetes.io annotations #31602

Merged
merged 5 commits into from
Mar 7, 2022

Conversation

mtardy
Copy link
Member

@mtardy mtardy commented Feb 2, 2022

Addresses issue #30809 and more 😄 !

This PR adds documentation for the following audit log annotations in the Well-Known Labels, Annotations and Taints page:

  • pod-security.kubernetes.io/exempt
  • pod-security.kubernetes.io/audit-violations
  • pod-security.kubernetes.io/enforce-policy

These annotations were added by PR [PodSecurity] Add annotations denoting the exemption reason and the enforcement policy used #105908 in the Kubernetes repository.

It's maybe a bit special because they are the first notes on audit logs Event kind on the page. I also took the liberty to use an abbreviated example for audit-violations.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 2, 2022
@k8s-ci-robot k8s-ci-robot added language/en Issues or PRs related to English language sig/docs Categorizes an issue or PR as relevant to SIG Docs. labels Feb 2, 2022
@netlify
Copy link

netlify bot commented Feb 2, 2022

✔️ Deploy Preview for kubernetes-io-main-staging ready!

🔨 Explore the source changes: cc64e7c

🔍 Inspect the deploy log: https://app.netlify.com/sites/kubernetes-io-main-staging/deploys/621fc2116376d00008505901

😎 Browse the preview: https://deploy-preview-31602--kubernetes-io-main-staging.netlify.app

@sftim
Copy link
Contributor

sftim commented Feb 3, 2022

/sig auth

@k8s-ci-robot k8s-ci-robot added the sig/auth Categorizes an issue or PR as relevant to SIG Auth. label Feb 3, 2022
Copy link
Contributor

@sftim sftim left a comment

Choose a reason for hiding this comment

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

As written, I think this would mislead readers into thinking that audit annotations apply to the Event objects - they don't.

I suggested a clarification.

PS. https://kubernetes.io/docs/reference/glossary/?fundamental=true&core-object=true#term-event might be useful too?


Example: `pod-security.kubernetes.io/exempt: namespace`

Used on: Event
Copy link
Contributor

@sftim sftim Feb 3, 2022

Choose a reason for hiding this comment

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

This isn't used on resources of kind Event; in fact, this annotation is not used on resources.

Suggested change
Used on: Event
This annotation is not used within the Kubernetes API. When you
[enable auditing](/docs/tasks/debug-application-cluster/audit/) in your cluster,
audit event data is written using `Event` from API group `audit.k8s.io`.
The annotation applies to audit events. Audit events are different from objects in the
[Event API](/docs/reference/kubernetes-api/cluster-resources/event-v1/) (API group
`events.k8s.io`).

Copy link
Member Author

Choose a reason for hiding this comment

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

But audit logs aren't composed of kind Event? Like this entry of the logs for example?

{
  "kind": "Event",
  "apiVersion": "audit.k8s.io/v1",
  "level": "Metadata",
  "auditID": "c981b4a5-e51a-4c14-b9c1-dabe06fd605a",
  "stage": "ResponseComplete",
  "requestURI": "/api/v1/namespaces/verify-pod-security/pods?fieldManager=kubectl-client-side-apply",
  "verb": "create",
  "user": {
    "username": "minikube-user",
    "groups": [
      "system:masters",
      "system:authenticated"
    ]
  },
  "sourceIPs": [
    "192.168.49.1"
  ],
  "userAgent": "kubectl/v1.23.3 (darwin/amd64) kubernetes/816c97a",
  "objectRef": {
    "resource": "pods",
    "namespace": "verify-pod-security",
    "name": "busybox-privileged",
    "apiVersion": "v1"
  },
  "responseStatus": {
    "metadata": {},
    "status": "Failure",
    "reason": "Forbidden",
    "code": 403
  },
  "requestReceivedTimestamp": "2022-02-02T18:32:40.833098Z",
  "stageTimestamp": "2022-02-02T18:32:40.841531Z",
  "annotations": {
    "authorization.k8s.io/decision": "allow",
    "authorization.k8s.io/reason": "",
    "pod-security.kubernetes.io/audit-violations": "would violate PodSecurity \"restricted:latest\": allowPrivilegeEscalation != false (container \"busybox\" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container \"busybox\" must set securityContext.capabilities.drop=[\"ALL\"]), runAsNonRoot != true (pod or container \"busybox\" must set securityContext.runAsNonRoot=true), seccompProfile (pod or container \"busybox\" must set securityContext.seccompProfile.type to \"RuntimeDefault\" or \"Localhost\")",
    "pod-security.kubernetes.io/enforce-policy": "restricted:latest"
  }
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Event from audit.k8s.io/v1 != Event from events.k8s.io/v1.

Unless we're clear about it, some readers will assume that Event means the kind used in the API.

Copy link
Contributor

Choose a reason for hiding this comment

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

There's no HTTP API that lets you create, read, update or delete the audit.k8s.io/v1 sort of Event.

Copy link
Member Author

Choose a reason for hiding this comment

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

oh 😲 ! All right I see, thanks a lot! It's confusing I admit, I was not very familiar with audits logs and didn't notice they were completely different objects. So what do you think, we should put a disclaimer in front of the three annotations "This annotation is not used within the Kubernetes API" or put them in a separate category then?

Copy link
Contributor

Choose a reason for hiding this comment

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

We discussed the subject a little bit with sig security docs folks and thought that maybe a good idea would be to publish the missing content first (with the disclaimer you proposed) and open an issue to reorganize this reference section.

👍

Copy link
Member Author

@mtardy mtardy Feb 4, 2022

Choose a reason for hiding this comment

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

I made the choice to repeat the disclaimer to avoid dependencies between references like on this one that adds:

The taints listed below are always used on Nodes

Which can be skipped if you are only looking for a specific label, annotation or taint without reading the whole document.

I also noticed that the API objects should be in inline code format according to the style guide.

Would it be preferable to create multiple issues for the possible independent contributions or create one asking for the whole reorganization/reformatting?

Copy link
Member

Choose a reason for hiding this comment

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

As written, I think this would mislead readers into thinking that audit annotations apply to the Event objects - they don't.

I had the same reaction before seeing this comment. This info is good to document, but I don't think it belongs on this page. Putting it on an audit-specific or PodSecurity-specific page seems less misleading

Copy link
Contributor

Choose a reason for hiding this comment

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

We could create a separate page for audit annotations and have the main Well-Known Labels, Annotations and Taints refer to the other page. Maybe that, then?

It'd be nice to put the audit annotation keys somewhere in the main Well-Known Labels, Annotations and Taints page, I think, so that if people search for any of those, they do find a match.

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! Originally, the idea would have been to add it "as is", but I admit that it might be confusing... And then to reorganize the whole reference page to have categories.

Tell me if you think we could organize this differently so I change that PR! :)

Comment on lines 477 to 478
See [Pod Security Standards](/docs/concepts/security/pod-security-standards/)
for more information.
Copy link
Contributor

Choose a reason for hiding this comment

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

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 why not, I admit I prefered the beginning of the page because of the table with the privilege, baseline, restricted descriptions and these specific part on instantiation was not that helpful!

sftim
sftim previously requested changes Feb 4, 2022
Copy link
Contributor

@sftim sftim left a comment

Choose a reason for hiding this comment

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

A bit more feedback

content/en/docs/reference/labels-annotations-taints.md Outdated Show resolved Hide resolved
content/en/docs/reference/labels-annotations-taints.md Outdated Show resolved Hide resolved
@mtardy
Copy link
Member Author

mtardy commented Feb 8, 2022

Are the new changes ok @sftim? 😸

@sftim sftim dismissed their stale review February 8, 2022 18:16

Review was stale

@sftim
Copy link
Contributor

sftim commented Feb 8, 2022

I'd like to have SIG Auth provide a technical review here. The Markdown changes LGTM.

@tengqm
Copy link
Contributor

tengqm commented Feb 21, 2022

/approve

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 21, 2022
@kbhawkey
Copy link
Contributor

kbhawkey commented Mar 1, 2022

Ping
/sig auth

@liggitt
Copy link
Member

liggitt commented Mar 1, 2022

The blurbs on each annotation look correct, but my comment at #31602 (comment) stands... I don't think this is the right page for audit annotations that are not set on REST API objects.

This This document serves both as a reference to the values and as a coordination point for assigning values. statement this page starts with isn't accurate for audit annotations, and needing to put a note beside each audit annotation calling out that it is not actually an annotation you can set seems like confirmation this is a confusing place to put these.

@mtardy
Copy link
Member Author

mtardy commented Mar 1, 2022

The blurbs on each annotation look correct, but my comment at #31602 (comment) stands... I don't think this is the right page for audit annotations that are not set on REST API objects.

This This document serves both as a reference to the values and as a coordination point for assigning values. statement this page starts with isn't accurate for audit annotations, and needing to put a note beside each audit annotation calling out that it is not actually an annotation you can set seems like confirmation this is a confusing place to put these.

ok @liggitt, so I'm not sure what I must do then. We also agreed that it was a problem and created this issue Reorganize the "Well-Known Labels, Annotations and Taints" reference page #31648. And Tim Bannister already noted that some others audit annotations were missing from the doc in Document built-in audit annotations #31576.

So you think we should not merge this PR before it has been reorganized? Or that it is even better we split the reference page about annotations in two, having two subpages for "Well-Known Labels, Annotations and Taints"?

And can I really work on this (reorganizing pages and creating a new one) or is it too big a change that needs to be discussed and approved first?

@liggitt
Copy link
Member

liggitt commented Mar 1, 2022

I think a separate page for audit annotations would be clearer. Including them on the existing page seems more confusing than helpful to me.

@sftim
Copy link
Contributor

sftim commented Mar 1, 2022

I'm fine with having a separate page for audit annotations, provided that a “search in page” for those annotation keys, in the main annotations/labels/taints page, yields something (perhaps a hyperlink).

If we skip that, people looking at the official list may well think we've missed them out, and might think that even if the page does include text that mentions checking other lists.

@sftim
Copy link
Contributor

sftim commented Mar 1, 2022

@mtardy based on the discussion so far, what course of action would you recommend? (if you're flummoxed enough that you don't feel you can recommend anything, I'd understand!)

@mtardy
Copy link
Member Author

mtardy commented Mar 2, 2022

I'm fine with having a separate page for audit annotations, provided that a “search in page” for those annotation keys, in the main annotations/labels/taints page, yields something (perhaps a hyperlink).

If we skip that, people looking at the official list may well think we've missed them out, and might think that even if the page does include text that mentions checking other lists.

Ahah I'm a bit flummoxed (btw thanks I didn't know this word 😄 ), I admit!

But nevertheless, what would you think that we do something like this:

.
├── [...]
├── API Access Control
│   └── ...
├── Well-Known Labels, Annotations and Taints  <-- Reference two categories page with simple lists and links
│   ├── API*                                   <-- Page with all the current details from the existing page
│   └── Audits*                                <-- Page with the new documentation for audits stuff
├── Kubernetes API
│   └── ...
└── [...]

* not the final name

The idea is to have a complete reference page, one in which you can CTRL+F, a kind of table of content for the two sub-pages. And the details in the two sub-pages, separated into the existing stuff, which is about the Kubernetes API, and the new documentation provided by this PR and the future PR for the issue #31576 for example.

What do you think? If you agree, what do you think is the next step? Do I need to explicit all that in a separate issue or can I directly create a PR from this discussion to try to fix that?

@sftim
Copy link
Contributor

sftim commented Mar 2, 2022

That suggestion might be more complicated than it needs to be @mtardy

I was thinking of including a simple unordered list near the end of https://kubernetes.io/docs/reference/labels-annotations-taints/, headed “Annotations used for audit”, where each entry is a hyperlink to the relevant heading in that separate Audit annotations page.

No need to create a new page that lists API annotations / labels / taints; those can stay in https://kubernetes.io/docs/reference/labels-annotations-taints/

Would that work? I think it'd be less effort.

@mtardy
Copy link
Member Author

mtardy commented Mar 2, 2022

.
├── [...]
├── API Access Control
│   └── ...
├── Well-Known Labels, Annotations and Taints  <-- Current page "as-is" + list of audit annotations in new category
│   └── Audits*                                <-- Page with the new documentation for audit annotations
├── Kubernetes API
│   └── ...
└── [...]

* not the final name

Ok so something like this? You are right, it will be much simpler!

@sftim
Copy link
Contributor

sftim commented Mar 2, 2022

LGTM

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 2, 2022
@mtardy
Copy link
Member Author

mtardy commented Mar 2, 2022

I'm not really sure about the level 2 headers:

  • Labels, annotations and taints used on API objects
  • Annotations used for audit

We can remake it flat with only level 2 headers, but the "Annotations used for audit" looks a bit weird with all the others headers named from a label, an annotation, or a taint.

It feels a bit messy in the end but this page was not already super neat! What do you think?

@mtardy
Copy link
Member Author

mtardy commented Mar 7, 2022

Here are the previsualizations for the Well-Known Labels, Annotations and Taints page and the Audit Annotations new page.

Do you think it's better this way @liggitt and @sftim?

@liggitt
Copy link
Member

liggitt commented Mar 7, 2022

Do you think it's better this way @liggitt and @sftim?

I think so.

I'm not really sure why we need to double-maintain the list of annotations as links from the API labels/annotations page, if search results would take people directly to the audit annotations page anyway (and including them in the current page seems likely to actually confuse search results and maybe make people do two hops), but this is definitely clearer.

@mtardy
Copy link
Member Author

mtardy commented Mar 7, 2022

I'm not really sure why we need to double-maintain the list of annotations as links from the API labels/annotations page, if search results would take people directly to the audit annotations page anyway (and including them in the current page seems likely to actually confuse search results and maybe make people do two hops), but this is definitely clearer.

I agree, Tim suggested a searchable reference page, that's why. But it results in a "double-maintain" list, as you said, which is not very handy, maybe we should keep the current "Well know annotations" page as-is and create the new one without creating a single searchable page (and use the search engines as the searchable page).

@liggitt
Copy link
Member

liggitt commented Mar 7, 2022

I don't feel that strongly, so I'll defer the searchability / double-maintenance burden question to docs folks

content lgtm

@sftim
Copy link
Contributor

sftim commented Mar 7, 2022

Let's do it with the extra toil for now. If we find we're documenting lots of audit annotations, we can look at adding automation to make that easier.

I also actually like the side-effect that non-audit annotations now use a 3rd-level heading, which makes the page body more compact.
/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 7, 2022
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 4b21127e8dca72ae881782ed206d8bb243571347

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sftim, tengqm

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sftim
Copy link
Contributor

sftim commented Mar 7, 2022

Aside: we might in future allow filtering the annotations / labels / taints, the way you can filter glossary entries.

@mtardy
Copy link
Member Author

mtardy commented Mar 7, 2022

Aside: we might in future allow filtering the annotations / labels / taints, the way you can filter glossary entries.

It would be cool, maybe I can mention that in the reorganization #31648 issue!

Thanks for the feedback and the help! 🤗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. language/en Issues or PRs related to English language lgtm "Looks good to me", indicates that a PR is ready to be merged. sig/auth Categorizes an issue or PR as relevant to SIG Auth. sig/docs Categorizes an issue or PR as relevant to SIG Docs. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants