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

Creating application security checklist #46326

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AnshumanTripathi
Copy link
Contributor

@AnshumanTripathi AnshumanTripathi commented May 12, 2024

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. language/en Issues or PRs related to English language labels May 12, 2024
@k8s-ci-robot k8s-ci-robot added sig/docs Categorizes an issue or PR as relevant to SIG Docs. 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 May 12, 2024
Copy link

netlify bot commented May 12, 2024

Pull request preview available for checking

Built without sensitive environment variables

Name Link
🔨 Latest commit 4f75e48
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-io-main-staging/deploys/66ef3ddc6eb9530008ce648b
😎 Deploy Preview https://deploy-preview-46326--kubernetes-io-main-staging.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@AnshumanTripathi AnshumanTripathi force-pushed the anshuman/app_sec_checklist branch 2 times, most recently from 252c1b0 to 1dae29a Compare May 14, 2024 06:11
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. area/blog Issues or PRs related to the Kubernetes Blog subproject area/localization General issues or PRs related to localization area/release-eng Issues or PRs related to the Release Engineering subproject area/web-development Issues or PRs related to the kubernetes.io's infrastructure, design, or build processes language/bn Issues or PRs related to Bengali language language/de Issues or PRs related to German language language/es Issues or PRs related to Spanish language language/fr Issues or PRs related to French language language/hi Issues or PRs related to Hindi language language/id Issues or PRs related to Indonesian language language/it Issues or PRs related to Italian language language/ja Issues or PRs related to Japanese language language/ko Issues or PRs related to Korean language language/pl Issues or PRs related to Polish language language/pt Issues or PRs related to Portuguese language and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 10, 2024
@sftim
Copy link
Contributor

sftim commented Jun 12, 2024

/remove-sig release
/sig security

@k8s-ci-robot k8s-ci-robot added sig/security Categorizes an issue or PR as relevant to SIG Security. and removed sig/release Categorizes an issue or PR as relevant to SIG Release. labels Jun 12, 2024
@mtardy
Copy link
Member

mtardy commented Jun 14, 2024

This looks good :)! I think it's a very valuable checklist for app developers.

@AnshumanTripathi AnshumanTripathi marked this pull request as ready for review June 19, 2024 19:28
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 19, 2024
Copy link

@NissesSenap NissesSenap left a comment

Choose a reason for hiding this comment

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

First of all, great job, I think this document is a great addition.

But here are my thoughts.
First, my question is, for whom is this document written for? Is it the 85-90% of app developers that run an http API or an event based app in a non-critical environment that just wants a good base layer? Or are we trying to point to all security features that exist from an app developer point of view?

Personally, I think we should aim this document mainly towards the 85-90% of the users.
Especially since there is a tendency to want to be able to complete everything on a checklist, but if it becomes too painful, you end up doing nothing.
See keep it relatively simple and provide some kind of leveling system.

I would add a header called ## base security. In there I would add the most basic stuff.

Then I would add another header, ## advanced security, or something like that.

I would keep everything you have written, but I would move these down to advanced security

  • rbac, if you are using rbac in your http api, you are most likely doing something wrong. I would emphasize that really hard in the document.
  • runtime class, custom runetime classes isn't something that the majority of Kubenetes environment will use.
  • Seccomp profiles, It's more or less impossible to setup unless you have some kind of tooling + since version 1.25 the default profile is enabled by default.
  • SElinux, most developers don't know what it is and just like secomp profile you more or less need tooling to create something decent.
  • AppArmor, even fewer people know what it is, and you need custom tooling to create something more advanced than default.

@AnshumanTripathi
Copy link
Contributor Author

AnshumanTripathi commented Jun 24, 2024

First of all, great job, I think this document is a great addition.

But here are my thoughts. First, my question is, for whom is this document written for? Is it the 85-90% of app developers that run an http API or an event based app in a non-critical environment that just wants a good base layer? Or are we trying to point to all security features that exist from an app developer point of view?

Personally, I think we should aim this document mainly towards the 85-90% of the users. Especially since there is a tendency to want to be able to complete everything on a checklist, but if it becomes too painful, you end up doing nothing. See keep it relatively simple and provide some kind of leveling system.

I would add a header called ## base security. In there I would add the most basic stuff.

Then I would add another header, ## advanced security, or something like that.

I would keep everything you have written, but I would move these down to advanced security

  • rbac, if you are using rbac in your http api, you are most likely doing something wrong. I would emphasize that really hard in the document.
  • runtime class, custom runetime classes isn't something that the majority of Kubenetes environment will use.
  • Seccomp profiles, It's more or less impossible to setup unless you have some kind of tooling + since version 1.25 the default profile is enabled by default.
  • SElinux, most developers don't know what it is and just like secomp profile you more or less need tooling to create something decent.
  • AppArmor, even fewer people know what it is, and you need custom tooling to create something more advanced than default.

Thanks for the detailed response. I like this format and I will try to update the document accordingly.
Regarding the target audience I did add this point

This checklist assumes a developer is a Kubernetes cluster user that interacts with namespaced scope objects.
https://github.com/kubernetes/website/pull/46326/files#diff-5285725b7ae5cc6b415f12dbb2acf91aea311bf5dd5dc71851b29c216afcb9adR20

I did realize that identifying the target audience is key here and then keeping the list generic so that it can be used by everyone. Because app developers can consist of tools that can be running cluster wide like log and metric collectors or policy agents. This is where the line between admins and developers start to blur. I'll try to add more details about the target audience for this list.

@AnshumanTripathi
Copy link
Contributor Author

@NissesSenap I have updated the checklist structure based on your recommendation.

Can you expand on

rbac, if you are using rbac in your http api, you are most likely doing something wrong. I would emphasize that really hard in the document.

I'm not sure what you mean here.

@NissesSenap
Copy link

@NissesSenap I have updated the checklist structure based on your recommendation.

Can you expand on

rbac, if you are using rbac in your http api, you are most likely doing something wrong. I would emphasize that really hard in the document.

I'm not sure what you mean here.

That is great @AnshumanTripathi , I will try to take a deeper look at the update as soon as possible. My point is that the majority of all apps ruining in Kubernetes don't need access to its API. So I would emphasize that custom rbac rules for apps just aren't needed, in the majority of applications. Still good to talk about it, just like you have, but point to that there are limited use cases for it.

@AnshumanTripathi
Copy link
Contributor Author

@NissesSenap I have updated the checklist structure based on your recommendation.
Can you expand on

rbac, if you are using rbac in your http api, you are most likely doing something wrong. I would emphasize that really hard in the document.

I'm not sure what you mean here.

That is great @AnshumanTripathi , I will try to take a deeper look at the update as soon as possible. My point is that the majority of all apps ruining in Kubernetes don't need access to its API. So I would emphasize that custom rbac rules for apps just aren't needed, in the majority of applications. Still good to talk about it, just like you have, but point to that there are limited use cases for it.

Makes sense. I am not covering applications using Kubernetes client as a part of this checklist. I think having a doc about secure practices for applications that use the Kubernetes API (and operator) can be very helpful. I will create an issue for this :)

@AnshumanTripathi
Copy link
Contributor Author

AnshumanTripathi commented Jul 24, 2024

@NissesSenap created kubernetes/sig-security#121 for hardening guide for using Kubernetes API
Cross posted issue on k website - #47405

Signed-off-by: Anshuman Tripathi <anshuman.tripathi305@gmail.com>

Update based on feedback

Signed-off-by: Anshuman Tripathi <anshuman.tripathi305@gmail.com>

Update based on feedback

Signed-off-by: Anshuman Tripathi <anshuman.tripathi305@gmail.com>

Update checklist reading guide

Signed-off-by: Anshuman Tripathi <anshuman.tripathi305@gmail.com>

Update checklist structure based on feedback

Signed-off-by: Anshuman Tripathi <anshuman.tripathi305@gmail.com>
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign sftim for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@tengqm
Copy link
Contributor

tengqm commented Sep 22, 2024

I'd suggest we place this under content/en/docs/reference/security/, a new directory for consolidating security related contents. This page is not suitable for the concepts section.

@AnshumanTripathi
Copy link
Contributor Author

I'd suggest we place this under content/en/docs/reference/security/, a new directory for consolidating security related contents. This page is not suitable for the concepts section.

Actually we can move this checklist and the existing checklist to content/en/docs/reference/issues-security maybe? I dont think I should do that as a part of this change though.

@tengqm
Copy link
Contributor

tengqm commented Sep 22, 2024

I'd suggest we place this under content/en/docs/reference/security/, a new directory for consolidating security related contents. This page is not suitable for the concepts section.

Actually we can move this checklist and the existing checklist to content/en/docs/reference/issues-security maybe? I dont think I should do that as a part of this change though.

The issues-security directory is positioned to be a folder for disclosing the vulnerabilities of kubernetes release. What we are trying to compile is a collection of guidelines, best practices for users.

I don't think we want to kick this in and then follow up with another PR to move it.
We may want to get the page into a suitable folder in the first place.
The migration of other relevant pages could be left as follow-ups, for sure.

@AnshumanTripathi
Copy link
Contributor Author

I'd suggest we place this under content/en/docs/reference/security/, a new directory for consolidating security related contents. This page is not suitable for the concepts section.

Actually we can move this checklist and the existing checklist to content/en/docs/reference/issues-security maybe? I dont think I should do that as a part of this change though.

The issues-security directory is positioned to be a folder for disclosing the vulnerabilities of kubernetes release. What we are trying to compile is a collection of guidelines, best practices for users.

I don't think we want to kick this in and then follow up with another PR to move it. We may want to get the page into a suitable folder in the first place. The migration of other relevant pages could be left as follow-ups, for sure.

Makes sense. I'll try to make that change

@drackpack drackpack mentioned this pull request Sep 22, 2024
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.

Thanks! We could really use this new page.

Here's some advice about how to get this ready to merge.


For sensitive workloads consider using Kernel emulation tools like [gVisor](https://gvisor.dev/docs/) or [kata-containers](https://katacontainers.io/).

In high trust environments, consider using [confidential virutal machines](/blog/2023/07/06/confidential-kubernetes/) to improve cluster security even further.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
In high trust environments, consider using [confidential virutal machines](/blog/2023/07/06/confidential-kubernetes/) to improve cluster security even further.
In high trust environments, consider using [confidential virtual machines](/blog/2023/07/06/confidential-kubernetes/) to improve cluster security even further.

Watch out for linking to non-evergreen blog articles (anything that gets marked as out of date once at least a year old).


Some containers may require a different isolation level from what is provided by the default runtime of the cluster. `runtimeClassname` can be used in a podspec to define a differnt runtime class.

For sensitive workloads consider using Kernel emulation tools like [gVisor](https://gvisor.dev/docs/) or [kata-containers](https://katacontainers.io/).
Copy link
Contributor

Choose a reason for hiding this comment

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

Kata containers is not a kernel emulator:

Suggested change
For sensitive workloads consider using Kernel emulation tools like [gVisor](https://gvisor.dev/docs/) or [kata-containers](https://katacontainers.io/).
For sensitive workloads consider using kernel emulation tools like [gVisor](https://gvisor.dev/docs/), or virtualized isolation using a mechanism such as [kata-containers](https://katacontainers.io/).

Copy link
Contributor

Choose a reason for hiding this comment

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

The following checklist provide a base security hardening recommendations that would apply to most applications deploying to Kubernetes.

### Application design
- [ ] Following the right [design principles for the application.](https://kubernetes.io/blog/2018/03/principles-of-container-app-design/)
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 recommend linking to that article. Find a better source, such as https://www.cncf.io/wp-content/uploads/2022/06/CNCF_cloud-native-security-whitepaper-May2022-v2.pdf

- [ ] CPU limit might be set on sensitive workloads.

### Service account
- [ ] Avoid using `default` service account. Create service accounts for workloads.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- [ ] Avoid using `default` service account. Create service accounts for workloads.
- [ ] Avoid using the `default` ServiceAccount. Create ServiceAccounts for each workload or microservice.

### Container Security Context
- [ ] Disable privilege escalations using `allowPrivilegeEscalation: false`.
- [ ] Configure the root filesystem to be read-only with `readOnlyRootFilesystem: true`.
- [ ] Avoid running privileged containers with `privileged: false`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- [ ] Avoid running privileged containers with `privileged: false`.
- [ ] Avoid running privileged containers (set `privileged: false`).

- [ ] Avoid using `default` service account. Create service accounts for workloads.
- [ ] `automountServiceAccountToken` should be set to `false` unless the pod specifically requires access to the Kubernetes API to operate.

### Pod Security Context
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
### Pod Security Context
### Pod-level `securityContext` recommendations {#security-context-pod}

- [ ] Optionally add a supplimentary group with `fsGroup` to access persistent volumes.
- [ ] Appropriate Pod Security Standard policies are enforced to all pods in the application namespace.

### Container Security Context
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
### Container Security Context
### Container-level `securityContext` recommendations {#security-context-container}

- [ ] Set `runAsNonRoot: true`.
- [ ] Configure User permissions and access controls using `runAsUser` and `runAsGroup`.
- [ ] Optionally add a supplimentary group with `fsGroup` to access persistent volumes.
- [ ] Appropriate Pod Security Standard policies are enforced to all pods in the application namespace.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this:

Suggested change
- [ ] Appropriate Pod Security Standard policies are enforced to all pods in the application namespace.
- [ ] The application deploys into a namespace that enforces an appropriate _Pod security standard_.
If you cannot control this enforcement for the cluster(s) where the application is deployed,
take this into account either through documentation or additional defense in depth.

- [ ] Avoid creating RBAC permissions to create or update roles which can lead to [privilege escalation](/docs/reference/access-authn-authz/rbac/#privilege-escalation-prevention-and-bootstrapping).
- [ ] Review bindings for the `system:unauthenticated` group and remove them where possible, as this gives access to anyone who can contact the API server at a network level.

The `create`, `update` and `delete` should be used judicously. The `patch` permission can [allow users to update labels on the namespace or deployments](/docs/concepts/security/rbac-good-practices/#namespace-modification) which can increase the attack surface.
Copy link
Contributor

Choose a reason for hiding this comment

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

Try this:

Suggested change
The `create`, `update` and `delete` should be used judicously. The `patch` permission can [allow users to update labels on the namespace or deployments](/docs/concepts/security/rbac-good-practices/#namespace-modification) which can increase the attack surface.
The **create**, **update** and **delete** verbs should be permitted judiciously. The **patch** verb if allowed on a Namespace can
[allow users to update labels on the namespace or deployments](/docs/concepts/security/rbac-good-practices/#namespace-modification) which can increase the attack surface.
For sensitive workloads, consider providing a recommended ValidatingAdmissionPolicy that further restricts the permitted write actions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. language/en Issues or PRs related to English language sig/docs Categorizes an issue or PR as relevant to SIG Docs. sig/security Categorizes an issue or PR as relevant to SIG Security. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants