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

CVE-2023-5044: Code injection via nginx.ingress.kubernetes.io/permanent-redirect annotation #126817

Closed
cjcullen opened this issue Oct 25, 2023 · 15 comments
Assignees
Labels
area/security committee/security-response Denotes an issue or PR intended to be handled by the product security committee. kind/bug Categorizes issue or PR as related to a bug. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. official-cve-feed Issues or PRs related to CVEs officially announced by Security Response Committee (SRC) triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@cjcullen
Copy link
Member

cjcullen commented Oct 25, 2023

Issue Details

A security issue was identified in ingress-nginx where the nginx.ingress.kubernetes.io/permanent-redirect annotation on an Ingress object (in the networking.k8s.io or extensions API group) can be used to inject arbitrary commands, and obtain the credentials of the ingress-nginx controller. In the default configuration, that credential has access to all secrets in the cluster.

This issue has been rated High (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:L/A:L), and assigned CVE-2023-5044.

Affected Components and Configurations

This bug affects ingress-nginx. If you do not have ingress-nginx installed on your cluster, you are not affected. You can check this by running kubectl get po -n ingress-nginx.

If you are running the “chrooted” ingress-nginx controller introduced in v1.2.0 (gcr.io/k8s-staging-ingress-nginx/controller-chroot), command execution is possible but credential extraction is not, so the High severity does not apply.

Multi-tenant environments where non-admin users have permissions to create Ingress objects are most affected by this issue.

Affected Versions

  • <v1.9.0

Versions allowing mitigation

  • v1.9.0

Mitigation

Ingress Administrators should set the --enable-annotation-validation flag to enforce restrictions on the contents of ingress-nginx annotation fields.

Detection

If you find evidence that this vulnerability has been exploited, please contact security@kubernetes.io

Additional Details

See ingress-nginx Issue #10572 for more details.

Acknowledgements

This vulnerability was reported by Jan-Otto Kröpke (Cloudeteer GmbH)

Thank You,
CJ Cullen on behalf of the Kubernetes Security Response Committee

@cjcullen cjcullen added the kind/bug Categorizes issue or PR as related to a bug. label Oct 25, 2023
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If Ingress contributors determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Oct 25, 2023
@cjcullen cjcullen changed the title Placeholder CVE-2023-5044: Code injection via nginx.ingress.kubernetes.io/permanent-redirect annotation Oct 25, 2023
@ealasgarov
Copy link

@cjcullen did you mean version 1.19, not 1.9, right?

@joshsleeper
Copy link

@ealasgarov I think 1.9.0 is correct and intended, as it's referring to the controller version not the underlying nginx version.

I'm assuming that since 1.9.0 of the controller is when the --enable-annotation-validation flag + feature was added

https://github.com/kubernetes/ingress-nginx/releases/tag/controller-v1.9.0

@havenotfear
Copy link

Is this only affecting deployments where the nginx.ingress.kubernetes.io/permanent-redirect has been added to the ingress annotations?

@stromvirvel
Copy link

I'd like to set --enable-annotation-validation, but its impact on the existing Ingress objects is unclear to me. I haven't found any documentation on that feature, except this single sentence of the CLI argument.
May somebody be so kind and give us further context?

@cilindrox
Copy link

@stromvirvel each annotation has a risk weight/grade - the annotation validation flag alone won't be of much use, since the default threshold is Critical, so you need to enable both --enable-annotation-validation and add the threshold for risk-level under the configmap, eg annotations-risk-level: High.

As for figuring out the threshold, you'll need to go through the codebase, afaik there's no documentation for each of these - best I could find was this test file: kubernetes/ingress-nginx@c5f348e#diff-1cf51e128ca991f6d8ea012512e57cf68e224e64ff68e2401d9a598e4da98837R70-R74

There you can see nginx.ingress.kubernetes.io/auth-signin (authReqSigninAnnotation) has a Risk of High (AnnotationRiskHigh), so you'd configure annotations-risk-level as High (ie: the highest risk among all of your used annotations). Hope this is somewhat clear

@magustin-telus
Copy link

I'd like to set --enable-annotation-validation, but its impact on the existing Ingress objects is unclear to me. I haven't found any documentation on that feature, except this single sentence of the CLI argument. May somebody be so kind and give us further context?

it is in the values.yaml.

@prashanthkasamsetty
Copy link

If anyone is not sure on how to enable that annotation or where this annotation will be set, check info mentioned below.

This annotation is set as arg in the container level of the nginx
image
this annotation is not set by default and needs to be enabled explicitly.
Highlighted below is the value for the --enable-annotation-validation parameter that should be passed with true while you are installing.
image
Through terraform, you need to put below in your '.tf' file
set {
name = "controller.enableAnnotationValidations"
value = true
}

@rikatz
Copy link
Contributor

rikatz commented Nov 3, 2023

As for figuring out the threshold, you'll need to go through the codebase, afaik there's no documentation for each of these - best I could find was this test file: kubernetes/ingress-nginx@c5f348e#diff-1cf51e128ca991f6d8ea012512e57cf68e224e64ff68e2401d9a598e4da98837R70-R74

@cilindrox you are right! I have plans to automate the documentation generation for this annotations (risk, description and eventually the validation) but didn't had the opportunity to do it yet (tho I've left the majority of code ready for it).

Sorry for that, we had to rush on implementation and missed this

@rikatz
Copy link
Contributor

rikatz commented Nov 3, 2023

/assign @cpanato @rikatz @strongjz @tao12345666333

@rikatz
Copy link
Contributor

rikatz commented Nov 3, 2023

Hey folks,

As this CVE has been opened for 1 week now, I'm closing the issue.

The description of the issue contains all the required mitigations, and we plan in future releases to turn the validation on by default and also implement more safety measures.

Thank you all for using the project, and for your continuous support for us.

/close

@k8s-ci-robot
Copy link
Contributor

@rikatz: Closing this issue.

In response to this:

Hey folks,

As this CVE has been opened for 1 week now, I'm closing the issue.

The description of the issue contains all the required mitigations, and we plan in future releases to turn the validation on by default and also implement more safety measures.

Thank you all for using the project, and for your continuous support for us.

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

starlingx-github referenced this issue in starlingx/nginx-ingress-controller-armada-app Nov 16, 2023
This commit adds the flags and config options recommended by the
community in:

https://github.com/kubernetes/ingress-nginx/issues/10570
https://github.com/kubernetes/ingress-nginx/issues/10572

CVE-2023-5044 is mitigated with enableAnnotationValidations
CVE-2022-4886 is mitigated with strict-validate-path-type

Test cases:

PASS: Full build, system install, bootstrap and unlock.
PASS: system application-update to this new version
PASS: Create Ingress resource with special character in path /apple$,
      Verify it's possible to curl localhost/apple$.
      Apply strict-validate-path-type override and verify creating the
      same Ingress object is not possible anymore, neither curl works.
PASS: Create Ingress resource with special characters and verify that
      it creates successfully.

      annotations:

      nginx.ingress.kubernetes.io/permanent-redirect: |
        https://www.google.com$HOST

      Apply enableAnnotationValidations override and verify creating the
      same Ingress object is not possible anymore and a validation error
      is now returned.
PASS: stx-openstack applies without error.

Closes-Bug: 2042977

Change-Id: I2f2279ebb34094d0a21d4440e48ef890f09a6133
Signed-off-by: Rei Oliveira <Reinildes.JoseMateusOliveira@windriver.com>
@nguyenthai0107
Copy link

nguyenthai0107 commented Jan 2, 2024

Hello @prashanthkasamsetty @rikatz @longwuyuan
depend on CVE-2021-25742 ( This issue has been rated High )
but when I edited annotations-risk-level: High and set --enable-annotation-validation=true , look like this wrong and cannot create ingress object. Im not sure CVE-2021-25742 was rated correctly.
Here are details

  1. Configmap Ingress Nginx Controller
apiVersion: v1
kind: ConfigMap
metadata:
  name: ingress-nginx-controller
  namespace: ingress-nginx
data:
  allow-snippet-annotations: "true"
  annotations-risk-level: High
  1. Deployment Ingress Nginx Controller
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ingress-nginx-controller
  namespace: ingress-nginx
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: ingress-nginx
      app.kubernetes.io/instance: platform
      app.kubernetes.io/component: controller
  replicas: 5
  revisionHistoryLimit: 10
  minReadySeconds: 0
  template:
    spec:
      containers:
      - name: controller
        image: registry.k8s.io-ingress-nginx-controller:v1.9.5
        imagePullPolicy: IfNotPresent
        lifecycle:
          preStop:
            exec:
              command:
              - /wait-shutdown
        args:
        - /nginx-ingress-controller
        - **--enable-annotation-validation=true**
        - --publish-service=$(POD_NAMESPACE)/ingress-nginx-controller
        - --election-id=ingress-nginx-leader
        - --controller-class=k8s.io/ingress-nginx
        - --ingress-class=nginx
        - --configmap=$(POD_NAMESPACE)/ingress-nginx-controller
        - --validating-webhook=:8443
        - --validating-webhook-certificate=/usr/local/certificates/cert
        - --validating-webhook-key=/usr/local/certificates/key
        - --enable-ssl-passthrough=true
  1. Deploy app with Ingress object which got issue.
    Exactly app is deploy Kiali inside namespace Istio
   ingress:
      class_name: "nginx"
      enabled: true
      # default: override_yaml is undefined
      override_yaml:
        metadata:
          annotations:
              nginx.ingress.kubernetes.io/configuration-snippet: |
              proxy_set_header "X-B3-Sampled" "1";
        spec:
          rules:
          - host: kiali.example.com
            http:
              paths:
              - backend:
                  service:
                    name: kiali
                    port:
                      number: 20001
                path: /
                pathType: Prefix
          tls:
          - hosts:
            - kiali.example.com
            secretName: "kiali-tls"`
  • Components Used:
    Nginx Ingress Controller 1.9.5
    Helm version 4.9.0
    Kiali Operator v1.77.0
`/nginx-ingress-controller 
-------------------------------------------------------------------------------
NGINX Ingress controller
  Release:       v1.9.5
  Repository:    https://github.com/kubernetes/ingress-nginx
  nginx version: nginx/1.21.6

Here is the issue which use command line kubectl describe kiali -n istio and ingress of Kiali wasn't created.

Status:
  Conditions:
    Message:               
    Reason:                
    Status:                False
    Type:                  Successful
    Message:               Running reconciliation
    Reason:                Running
    Status:                False
    Type:                  Running
    Ansible Result:
      Changed:             5
      Failures:            1
      Ok:                  64
      Skipped:             51
    Message:               Failed to patch object: b'{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"admission webhook \\"validate.nginx.ingress.kubernetes.io\\" denied the request: annotation group ConfigurationSnippet contains risky annotation based on ingress configuration","reason":"BadRequest","code":400}\n'
    Reason:                Failed
    Status:                True
    Type:                  Failure
  Deployment:
    Instance Name:  kiali
    Namespace:      istio
  Environment:
    Is Kubernetes:       true
    Kubernetes Version:  1.24.17
    Operator Version:    v1.77.0
  Progress:
    Duration:    0:00:26
    Message:     5. Creating core resources
  Spec Version:  default
Events:          <none>

But when set to Critical or delete annotations-risk-level in configmap, the issue was gone and working fine.
Just got stuck when set to High, Medium or Low.
So please kindly for take a look.
Thank you guys.

@cji
Copy link
Member

cji commented Aug 20, 2024

/transfer kubernetes

@k8s-ci-robot k8s-ci-robot added the needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Aug 20, 2024
@k8s-ci-robot k8s-ci-robot transferred this issue from kubernetes/ingress-nginx Aug 20, 2024
@cji
Copy link
Member

cji commented Aug 20, 2024

/area security
/kind bug
/committee security-response
/triage accepted
/lifecycle frozen
/label official-cve-feed

@k8s-ci-robot k8s-ci-robot added lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. area/security committee/security-response Denotes an issue or PR intended to be handled by the product security committee. triage/accepted Indicates an issue or PR is ready to be actively worked on. official-cve-feed Issues or PRs related to CVEs officially announced by Security Response Committee (SRC) and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/security committee/security-response Denotes an issue or PR intended to be handled by the product security committee. kind/bug Categorizes issue or PR as related to a bug. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. official-cve-feed Issues or PRs related to CVEs officially announced by Security Response Committee (SRC) triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Archived in project
Development

No branches or pull requests