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

Apply more restrictive SecurityContext to components #2433

Merged
merged 1 commit into from
Feb 3, 2023

Conversation

hjiawei
Copy link
Contributor

@hjiawei hjiawei commented Jan 28, 2023

Description

This changeset add more restrictive SecurityContext to Calico opensource
and enterprise components. Least privilege principle is applied to this
change.

Data plane components are mostly running as root user and application
layer compoennts are running as non-root users. Capabilities and
SeccompProfile are also filled with sensible defaults in
SecurityContexts.

For PR author

  • Tests for change.
  • If changing pkg/apis/, run make gen-files
  • If changing versions, run make gen-versions

For PR reviewers

A note for code reviewers - all pull requests must have the following:

  • Milestone set according to targeted release.
  • Appropriate labels:
    • kind/bug if this is a bugfix.
    • kind/enhancement if this is a a new feature.
    • enterprise if this PR applies to Calico Enterprise only.

@@ -169,17 +172,23 @@ func (c *component) egwBuildAnnotations() map[string]string {
}

func (c *component) egwInitContainer() *corev1.Container {
sc := securitycontext.NewRootContext(true)
Copy link
Contributor Author

@hjiawei hjiawei Jan 28, 2023

Choose a reason for hiding this comment

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

Pending validation from @sridhartigera. As the init container is running as root and privileged, can we remove the NET_ADMIN?

@hjiawei hjiawei force-pushed the cis-perm-tune branch 9 times, most recently from 02c0944 to d60302a Compare January 31, 2023 05:04
@hjiawei hjiawei marked this pull request as ready for review January 31, 2023 07:33
@hjiawei hjiawei requested a review from a team as a code owner January 31, 2023 07:33
@hjiawei hjiawei force-pushed the cis-perm-tune branch 5 times, most recently from 0cbf7b7 to c53be0f Compare February 1, 2023 22:28
Copy link
Member

@rene-dekker rene-dekker left a comment

Choose a reason for hiding this comment

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

lgtm

Comment on lines +584 to +588
sc.Capabilities.Add = []corev1.Capability{
"SETGID",
"SETUID",
"SYS_CHROOT",
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the ES entrypoint script work without SETGID and SETUID?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really. I believe chroot needs them.

This changeset add more restrictive SecurityContext to Calico opensource
and enterprise components. Least privilege principle is applied to this
change.

Data plane components are mostly running as root user and application
layer compoennts are running as non-root users. `Capabilities` and
`SeccompProfile` are also filled with sensible defaults in
`SecurityContext`s.
@hjiawei
Copy link
Contributor Author

hjiawei commented Feb 3, 2023

I have tested a standard Calico Enterprise install on the following platforms:

  • gcp-kubeadmin
  • gcp-mke
  • gcp-rancher
  • gcp-rke2 (cis not enabled)
  • aws-eks
  • aws-openshift
  • azr-aks

@rene-dekker rene-dekker merged commit b3e846d into tigera:master Feb 3, 2023
@hjiawei hjiawei deleted the cis-perm-tune branch February 9, 2023 18:52
hjiawei added a commit to hjiawei/operator that referenced this pull request Feb 24, 2023
This changeset add and update PodSecurityPolicy for open source and
enterprise components to match the recent work for SecurityContext in [1].

To summarize the changes:
* Update Elasticsearch and Fluentd capabilities in PodSecurityPolicy to
  match SecurityContext.
* Add missing PSPs for all enterprise components. Enterprise components
  like packetcapture, esgateway, l7-log-collector, etc. are able to be
  deployed without creating PodSecurityPolicy manually.
* Manage Prometheus operator ClusterRole and ClusterRoleBinding in
  operator.
* use `UsePSP` as the only flag to determine whether we need to render
  PSPs or not.

[1] tigera#2433
hjiawei added a commit to hjiawei/operator that referenced this pull request Feb 24, 2023
This changeset add and update PodSecurityPolicy for open source and
enterprise components to match the recent work for SecurityContext in [1].

To summarize the changes:
* Update Elasticsearch and Fluentd capabilities in PodSecurityPolicy to
  match SecurityContext.
* Add missing PSPs for all enterprise components. Enterprise components
  like packetcapture, esgateway, l7-log-collector, etc. are able to be
  deployed without creating PodSecurityPolicy manually.
* Manage Prometheus operator ClusterRole and ClusterRoleBinding in
  operator.
* use `UsePSP` as the only flag to determine whether we need to render
  PodSecurityPolicy or not.

[1] tigera#2433
hjiawei added a commit to hjiawei/operator that referenced this pull request Feb 24, 2023
This changeset add and update `PodSecurityPolicy` for open source and
enterprise components to match the recent work for SecurityContext in [1].
This is also required for all components to work in a CIS hardened RKE2
cluster.

To summarize the changes:
* Update Elasticsearch and Fluentd capabilities in `PodSecurityPolicy` to
  match `SecurityContext`.
* Add missing `PodSecurityPolicy` for all enterprise components. Enterprise
  components like packetcapture, esgateway, l7-log-collector, etc. are able
  to be deployed without creating `PodSecurityPolicy` manually.
* Manage Prometheus operator `ClusterRole` and `ClusterRoleBinding` in
  operator.
* use `UsePSP` as the only flag to determine whether we need to render
  `PodSecurityPolicy` or not.

[1] tigera#2433
hjiawei added a commit to hjiawei/operator that referenced this pull request Feb 24, 2023
This changeset add and update `PodSecurityPolicy` for open source and
enterprise components to match the recent work for SecurityContext in [1].
This is also required for all components to work in a CIS hardened RKE2
cluster.

To summarize the changes:
* Update Elasticsearch and Fluentd capabilities in `PodSecurityPolicy` to
  match `SecurityContext`.
* Add missing `PodSecurityPolicy` for all enterprise components. Enterprise
  components like packetcapture, esgateway, l7-log-collector, etc. are able
  to be deployed without creating `PodSecurityPolicy` manually.
* Manage Prometheus operator `ClusterRole` and `ClusterRoleBinding` in
  operator.
* use `UsePSP` as the only flag to determine whether we need to render
  `PodSecurityPolicy` or not.

[1] tigera#2433
hjiawei added a commit to hjiawei/operator that referenced this pull request Feb 25, 2023
This changeset add and update `PodSecurityPolicy` for open source and
enterprise components to match the recent work for SecurityContext in [1].
This is also required for all components to work in a CIS hardened RKE2
cluster.

To summarize the changes:
* Update Elasticsearch and Fluentd capabilities in `PodSecurityPolicy` to
  match `SecurityContext`.
* Add missing `PodSecurityPolicy` for all enterprise components. Enterprise
  components like packetcapture, esgateway, l7-log-collector, etc. are able
  to be deployed without creating `PodSecurityPolicy` manually.
* Manage Prometheus operator `ClusterRole` and `ClusterRoleBinding` in
  operator.
* use `UsePSP` as the only flag to determine whether we need to render
  `PodSecurityPolicy` or not.

[1] tigera#2433
hjiawei added a commit to hjiawei/operator that referenced this pull request Feb 27, 2023
This changeset add and update `PodSecurityPolicy` for open source and
enterprise components to match the recent work for SecurityContext in [1].
This is also required for all components to work in a CIS hardened RKE2
cluster.

To summarize the changes:
* Update Elasticsearch and Fluentd capabilities in `PodSecurityPolicy` to
  match `SecurityContext`.
* Add missing `PodSecurityPolicy` for all enterprise components. Enterprise
  components like packetcapture, esgateway, l7-log-collector, etc. are able
  to be deployed without creating `PodSecurityPolicy` manually.
* Manage Prometheus operator `ClusterRole` and `ClusterRoleBinding` in
  operator.
* use `UsePSP` as the only flag to determine whether we need to render
  `PodSecurityPolicy` or not.

[1] tigera#2433
hjiawei added a commit to hjiawei/operator that referenced this pull request Feb 27, 2023
This changeset add and update `PodSecurityPolicy` for open source and
enterprise components to match the recent work for SecurityContext in [1].
This is also required for all components to work in a CIS hardened RKE2
cluster.

To summarize the changes:
* Update Elasticsearch and Fluentd capabilities in `PodSecurityPolicy` to
  match `SecurityContext`.
* Add missing `PodSecurityPolicy` for all enterprise components. Enterprise
  components like packetcapture, esgateway, l7-log-collector, etc. are able
  to be deployed without creating `PodSecurityPolicy` manually.
* Manage Prometheus operator `ClusterRole` and `ClusterRoleBinding` in
  operator.
* use `UsePSP` as the only flag to determine whether we need to render
  `PodSecurityPolicy` or not.

[1] tigera#2433
hjiawei added a commit to hjiawei/operator that referenced this pull request Feb 28, 2023
This changeset add and update `PodSecurityPolicy` for open source and
enterprise components to match the recent work for SecurityContext in [1].
This is also required for all components to work in a CIS hardened RKE2
cluster.

To summarize the changes:
* Update Elasticsearch and Fluentd capabilities in `PodSecurityPolicy` to
  match `SecurityContext`.
* Add missing `PodSecurityPolicy` for all enterprise components. Enterprise
  components like packetcapture, esgateway, l7-log-collector, etc. are able
  to be deployed without creating `PodSecurityPolicy` manually.
* Manage Prometheus operator `ClusterRole` and `ClusterRoleBinding` in
  operator.
* use `UsePSP` as the only flag to determine whether we need to render
  `PodSecurityPolicy` or not.

[1] tigera#2433
hjiawei added a commit to hjiawei/operator that referenced this pull request Mar 1, 2023
This changeset add and update `PodSecurityPolicy` for open source and
enterprise components to match the recent work for SecurityContext in [1].
This is also required for all components to work in a CIS hardened RKE2
cluster.

To summarize the changes:
* Update Elasticsearch and Fluentd capabilities in `PodSecurityPolicy` to
  match `SecurityContext`.
* Add missing `PodSecurityPolicy` for all enterprise components. Enterprise
  components like packetcapture, esgateway, l7-log-collector, etc. are able
  to be deployed without creating `PodSecurityPolicy` manually.
* Manage Prometheus operator `ClusterRole` and `ClusterRoleBinding` in
  operator.
* use `UsePSP` as the only flag to determine whether we need to render
  `PodSecurityPolicy` or not.

[1] tigera#2433
hjiawei added a commit to hjiawei/operator that referenced this pull request Mar 2, 2023
This changeset add and update `PodSecurityPolicy` for open source and
enterprise components to match the recent work for SecurityContext in [1].
This is also required for all components to work in a CIS hardened RKE2
cluster.

To summarize the changes:
* Update Elasticsearch and Fluentd capabilities in `PodSecurityPolicy` to
  match `SecurityContext`.
* Add missing `PodSecurityPolicy` for all enterprise components. Enterprise
  components like packetcapture, esgateway, l7-log-collector, etc. are able
  to be deployed without creating `PodSecurityPolicy` manually.
* Manage Prometheus operator `ClusterRole` and `ClusterRoleBinding` in
  operator.
* use `UsePSP` as the only flag to determine whether we need to render
  `PodSecurityPolicy` or not.

[1] tigera#2433
hjiawei added a commit to hjiawei/operator that referenced this pull request Mar 2, 2023
This changeset add and update `PodSecurityPolicy` for open source and
enterprise components to match the recent work for SecurityContext in [1].
This is also required for all components to work in a CIS hardened RKE2
cluster.

To summarize the changes:
* Update Elasticsearch and Fluentd capabilities in `PodSecurityPolicy` to
  match `SecurityContext`.
* Add missing `PodSecurityPolicy` for all enterprise components. Enterprise
  components like packetcapture, esgateway, l7-log-collector, etc. are able
  to be deployed without creating `PodSecurityPolicy` manually.
* Manage Prometheus operator `ClusterRole` and `ClusterRoleBinding` in
  operator.
* use `UsePSP` as the only flag to determine whether we need to render
  `PodSecurityPolicy` or not.

[1] tigera#2433
hjiawei added a commit to hjiawei/operator that referenced this pull request Mar 2, 2023
This changeset add and update `PodSecurityPolicy` for open source and
enterprise components to match the recent work for SecurityContext in [1].
This is also required for all components to work in a CIS hardened RKE2
cluster.

To summarize the changes:
* Update Elasticsearch and Fluentd capabilities in `PodSecurityPolicy` to
  match `SecurityContext`.
* Add missing `PodSecurityPolicy` for all enterprise components. Enterprise
  components like packetcapture, esgateway, l7-log-collector, etc. are able
  to be deployed without creating `PodSecurityPolicy` manually.
* Manage Prometheus operator `ClusterRole` and `ClusterRoleBinding` in
  operator.
* use `UsePSP` as the only flag to determine whether we need to render
  `PodSecurityPolicy` or not.

[1] tigera#2433
rene-dekker pushed a commit that referenced this pull request Mar 3, 2023
This changeset add and update `PodSecurityPolicy` for open source and
enterprise components to match the recent work for SecurityContext in [1].
This is also required for all components to work in a CIS hardened RKE2
cluster.

To summarize the changes:
* Update Elasticsearch and Fluentd capabilities in `PodSecurityPolicy` to
  match `SecurityContext`.
* Add missing `PodSecurityPolicy` for all enterprise components. Enterprise
  components like packetcapture, esgateway, l7-log-collector, etc. are able
  to be deployed without creating `PodSecurityPolicy` manually.
* Manage Prometheus operator `ClusterRole` and `ClusterRoleBinding` in
  operator.
* use `UsePSP` as the only flag to determine whether we need to render
  `PodSecurityPolicy` or not.

[1] #2433
hjiawei added a commit to hjiawei/operator that referenced this pull request Mar 16, 2023
When PSP Pod Admission Controller is enabled in a cluster before v1.25,
add the PSP PolicyRule for anomaly detection detectors. This is missed
in tigera#2433.
hjiawei added a commit to hjiawei/operator that referenced this pull request Mar 16, 2023
When PSP Pod Admission Controller is enabled in a cluster before v1.25,
add the PSP PolicyRule for anomaly detection detectors. This is missed
in tigera#2433.
rene-dekker pushed a commit that referenced this pull request Mar 17, 2023
When PSP Pod Admission Controller is enabled in a cluster before v1.25,
add the PSP PolicyRule for anomaly detection detectors. This is missed
in #2433.
rene-dekker pushed a commit that referenced this pull request Mar 17, 2023
When PSP Pod Admission Controller is enabled in a cluster before v1.25,
add the PSP PolicyRule for anomaly detection detectors. This is missed
in #2433.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants