|
| 1 | +# Periodic scanning for vulnerabilities in build time dependencies |
| 2 | + |
| 3 | +Report vulnerabilities in build time dependencies |
| 4 | +of [kubernetes](https://github.com/kubernetes/kubernetes) repository |
| 5 | + |
| 6 | +Tracker: [Issue #101528](https://github.com/kubernetes/kubernetes/issues/101528) |
| 7 | + |
| 8 | +## Background and Prior work |
| 9 | + |
| 10 | +The process described here is tooling agnostic i.e. the process can be |
| 11 | +implemented using any scanner with minimal or no changes. This is also _not_ an |
| 12 | +endorsement of any specific tool or scanner. In order to get a working solution |
| 13 | +in place, [snyk](https://snyk.io/) was chosen for following reasons: |
| 14 | + |
| 15 | +1. Existing partnership between CNCF and Synk helped procure an account that |
| 16 | + allowed us to scan `kubernetes/kubernetes` |
| 17 | + repo: https://github.com/kubernetes/steering/issues/206 |
| 18 | +2. Snyk has detected vulnerabilities in transient dependencies of |
| 19 | + `kubernetes/kubernetes`: https://kubernetes.slack.com/archives/CHGFYJVAN/p1595258034095300 |
| 20 | +3. Snyk has a programmable interface which made it easier to filter out |
| 21 | + licensing issues and known false positive vulnerabilities |
| 22 | + |
| 23 | +## Implementation with Snyk |
| 24 | + |
| 25 | +There are two ways to scan the kubernetes repo for vulnerabilities in |
| 26 | +dependencies at build time |
| 27 | + |
| 28 | +### Running the scan locally |
| 29 | + |
| 30 | +#### Step 0: Install Synk CLI |
| 31 | + |
| 32 | +Follow these instructions to synk cli installed on your |
| 33 | +machine: https://support.snyk.io/hc/en-us/articles/360003812538-Install-the-Snyk-CL |
| 34 | + |
| 35 | +#### Step 1: Authenticate |
| 36 | + |
| 37 | +##### Option A : |
| 38 | + |
| 39 | +Running command `snyk auth` takes you to snyk.io website, do signup/login/auth |
| 40 | + |
| 41 | +``` |
| 42 | +snyk auth |
| 43 | +``` |
| 44 | + |
| 45 | +##### Option B: |
| 46 | + |
| 47 | +Get the API token from https://app.snyk.io/account and use it |
| 48 | + |
| 49 | +``` |
| 50 | +snyk auth XXX-XXX-XXX-XXX-XXX |
| 51 | +Your account has been authenticated. Snyk is now ready to be used. |
| 52 | +``` |
| 53 | + |
| 54 | +#### Step 2: Run test |
| 55 | + |
| 56 | +``` |
| 57 | +# in k/k repo |
| 58 | +snyk test |
| 59 | +``` |
| 60 | + |
| 61 | +### Running the scan as part of k/k testgrid |
| 62 | + |
| 63 | +Prow job that runs every 6 hours is located |
| 64 | +here: https://testgrid.k8s.io/sig-security-snyk-scan#ci-kubernetes-snyk-master |
| 65 | + |
| 66 | +#### Improvements to the raw scan results |
| 67 | + |
| 68 | +Raw scan results were useful, but needed some kubernetes specific work |
| 69 | + |
| 70 | +##### JSON output |
| 71 | + |
| 72 | +To store the json output in a file and let stdout use command line friendly |
| 73 | +output: |
| 74 | + |
| 75 | +``` |
| 76 | +snyk test --json-file-output=licenses-cves.json |
| 77 | +``` |
| 78 | + |
| 79 | +##### Licenses |
| 80 | + |
| 81 | +Since detecting licensing violations is a non-goal, licenses related results, |
| 82 | +can be removed from the output using this query: |
| 83 | + |
| 84 | +``` |
| 85 | +cat licenses-cves.json | jq '.vulnerabilities | .[] | select (.type=="license" | not)' > only_cves.json |
| 86 | +``` |
| 87 | + |
| 88 | +##### Removing False Positive CVEs identified with v0.0.0 |
| 89 | + |
| 90 | +Since these are really pointing to the code at HEAD in git tracking, we can |
| 91 | +ignore the vulnerabilities that are generated when snyk detects v0.0.0 as |
| 92 | +kubernetes version because of the way |
| 93 | +[replace](https://github.com/golang/go/wiki/Modules#when-should-i-use-the-replace-directive) |
| 94 | +directives are used. |
| 95 | + |
| 96 | +Easy way to remove licensing *and* CVEs like this: |
| 97 | + |
| 98 | +``` |
| 99 | +cat licenses-cves.json | jq '.vulnerabilities | .[] | select ((.type=="license") or (.version=="0.0.0") | not)' > only_cves_wo000.json |
| 100 | +``` |
| 101 | + |
| 102 | +### Example of filtered JSON scan result |
| 103 | + |
| 104 | +<!-- markdownlint-disable MD033 --> |
| 105 | +<details><summary>Click to view result</summary> |
| 106 | +<!-- markdownlint-enable MD033 --> |
| 107 | + |
| 108 | +``` |
| 109 | +{ |
| 110 | + "CVSSv3": "CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H", |
| 111 | + "alternativeIds": [], |
| 112 | + "creationTime": "2021-02-08T10:27:10.200417Z", |
| 113 | + "credit": [ |
| 114 | + "Unknown" |
| 115 | + ], |
| 116 | + "cvssScore": 7.2, |
| 117 | + "description": "## Overview\n\nAffected versions of this package are vulnerable to Directory Traversal. When specifying the plugin to load in the `type` field in the network configuration, it is possible to use special elements such as \"../\" separators to reference binaries elsewhere on the system. An attacker can use this to execute other existing binaries other than the cni plugins/types such as `reboot`.\n\n## Details\n\nA Directory Traversal attack (also known as path traversal) aims to access files and directories that are stored outside the intended folder. By manipulating files with \"dot-dot-slash (../)\" sequences and its variations, or by using absolute file paths, it may be possible to access arbitrary files and directories stored on file system, including application source code, configuration, and other critical system files.\n\nDirectory Traversal vulnerabilities can be generally divided into two types:\n\n- **Information Disclosure**: Allows the attacker to gain information about the folder structure or read the contents of sensitive files on the system.\n\n`st` is a module for serving static files on web pages, and contains a [vulnerability of this type](https://snyk.io/vuln/npm:st:20140206). In our example, we will serve files from the `public` route.\n\nIf an attacker requests the following URL from our server, it will in turn leak the sensitive private key of the root user.\n\n```\ncurl http://localhost:8080/public/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/root/.ssh/id_rsa\n```\n**Note** `%2e` is the URL encoded version of `.` (dot).\n\n- **Writing arbitrary files**: Allows the attacker to create or replace existing files. This type of vulnerability is also known as `Zip-Slip`. \n\nOne way to achieve this is by using a malicious `zip` archive that holds path traversal filenames. When each filename in the zip archive gets concatenated to the target extraction folder, without validation, the final path ends up outside of the target folder. If an executable or a configuration file is overwritten with a file containing malicious code, the problem can turn into an arbitrary code execution issue quite easily.\n\nThe following is an example of a `zip` archive with one benign file and one malicious file. Extracting the malicious file will result in traversing out of the target folder, ending up in `/root/.ssh/` overwriting the `authorized_keys` file:\n\n```\n2018-04-15 22:04:29 ..... 19 19 good.txt\n2018-04-15 22:04:42 ..... 20 20 ../../../../../../root/.ssh/authorized_keys\n```\n\n## Remediation\nUpgrade `github.com/containernetworking/cni/pkg/invoke` to version 0.8.1 or higher.\n## References\n- [GitHub PR](https://github.com/containernetworking/cni/pull/808)\n- [RedHat Bugzilla Bug](https://bugzilla.redhat.com/show_bug.cgi?id=1919391)\n", |
| 118 | + "disclosureTime": "2021-02-05T00:00:00Z", |
| 119 | + "exploit": "Not Defined", |
| 120 | + "fixedIn": [ |
| 121 | + "0.8.1" |
| 122 | + ], |
| 123 | + "functions": [], |
| 124 | + "functions_new": [], |
| 125 | + "id": "SNYK-GOLANG-GITHUBCOMCONTAINERNETWORKINGCNIPKGINVOKE-1070549", |
| 126 | + "identifiers": { |
| 127 | + "CVE": [ |
| 128 | + "CVE-2021-20206" |
| 129 | + ], |
| 130 | + "CWE": [ |
| 131 | + "CWE-22" |
| 132 | + ] |
| 133 | + }, |
| 134 | + "language": "golang", |
| 135 | + "modificationTime": "2021-02-08T14:14:51.744734Z", |
| 136 | + "moduleName": "github.com/containernetworking/cni/pkg/invoke", |
| 137 | + "packageManager": "golang", |
| 138 | + "packageName": "github.com/containernetworking/cni/pkg/invoke", |
| 139 | + "patches": [], |
| 140 | + "proprietary": false, |
| 141 | + "publicationTime": "2021-02-08T14:14:51.968123Z", |
| 142 | + "references": [ |
| 143 | + { |
| 144 | + "title": "GitHub PR", |
| 145 | + "url": "https://github.com/containernetworking/cni/pull/808" |
| 146 | + }, |
| 147 | + { |
| 148 | + "title": "RedHat Bugzilla Bug", |
| 149 | + "url": "https://bugzilla.redhat.com/show_bug.cgi?id=1919391" |
| 150 | + } |
| 151 | + ], |
| 152 | + "semver": { |
| 153 | + "hashesRange": [ |
| 154 | + "<v0.8.1" |
| 155 | + ], |
| 156 | + "vulnerable": [ |
| 157 | + "<0.8.1" |
| 158 | + ], |
| 159 | + "vulnerableHashes": [<snipped a long list of hashes for brevity> |
| 160 | + ] |
| 161 | + }, |
| 162 | + "severity": "high", |
| 163 | + "severityWithCritical": "high", |
| 164 | + "title": "Directory Traversal", |
| 165 | + "from": [ |
| 166 | + |
| 167 | + "github.com/containernetworking/cni/[email protected]", |
| 168 | + "github.com/containernetworking/cni/pkg/[email protected]" |
| 169 | + ], |
| 170 | + "upgradePath": [], |
| 171 | + "isUpgradable": false, |
| 172 | + "isPatchable": false, |
| 173 | + "name": "github.com/containernetworking/cni/pkg/invoke", |
| 174 | + "version": "0.8.0" |
| 175 | +} |
| 176 | +{ |
| 177 | + "CVSSv3": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N", |
| 178 | + "alternativeIds": [], |
| 179 | + "creationTime": "2020-07-30T13:33:31.283115Z", |
| 180 | + "credit": [ |
| 181 | + "christopher-wong" |
| 182 | + ], |
| 183 | + "cvssScore": 7.5, |
| 184 | + "description": "## Overview\n[github.com/dgrijalva/jwt-go](https://github.com/dgrijalva/jwt-go) is a go implementation of JSON Web Tokens.\n\nAffected versions of this package are vulnerable to Access Restriction Bypass if `m[\"aud\"]` happens to be `[]string{}`, as allowed by the spec, the type assertion fails and the value of `aud` is `\"\"`. This can cause audience verification to succeed even if the audiences being passed are incorrect if `required` is set to `false`.\n## Remediation\nUpgrade `github.com/dgrijalva/jwt-go` to version 4.0.0-preview1 or higher.\n## References\n- [GitHub Issue](https://github.com/dgrijalva/jwt-go/issues/422)\n- [GitHub PR](https://github.com/dgrijalva/jwt-go/pull/426)\n", |
| 185 | + "disclosureTime": "2020-07-30T13:22:28Z", |
| 186 | + "exploit": "Not Defined", |
| 187 | + "fixedIn": [ |
| 188 | + "4.0.0-preview1" |
| 189 | + ], |
| 190 | + "functions": [], |
| 191 | + "functions_new": [], |
| 192 | + "id": "SNYK-GOLANG-GITHUBCOMDGRIJALVAJWTGO-596515", |
| 193 | + "identifiers": { |
| 194 | + "CVE": [ |
| 195 | + "CVE-2020-26160" |
| 196 | + ], |
| 197 | + "CWE": [ |
| 198 | + "CWE-287" |
| 199 | + ] |
| 200 | + }, |
| 201 | + "language": "golang", |
| 202 | + "modificationTime": "2020-11-30T11:23:07.967004Z", |
| 203 | + "moduleName": "github.com/dgrijalva/jwt-go", |
| 204 | + "packageManager": "golang", |
| 205 | + "packageName": "github.com/dgrijalva/jwt-go", |
| 206 | + "patches": [], |
| 207 | + "proprietary": false, |
| 208 | + "publicationTime": "2020-09-13T15:53:35Z", |
| 209 | + "references": [ |
| 210 | + { |
| 211 | + "title": "GitHub Issue", |
| 212 | + "url": "https://github.com/dgrijalva/jwt-go/issues/422" |
| 213 | + }, |
| 214 | + { |
| 215 | + "title": "GitHub PR", |
| 216 | + "url": "https://github.com/dgrijalva/jwt-go/pull/426" |
| 217 | + } |
| 218 | + ], |
| 219 | + "semver": { |
| 220 | + "hashesRange": [ |
| 221 | + "v4.0.0-preview1" |
| 222 | + ], |
| 223 | + "vulnerable": [ |
| 224 | + "<4.0.0-preview1" |
| 225 | + ], |
| 226 | + "vulnerableHashes": null |
| 227 | + }, |
| 228 | + "severity": "high", |
| 229 | + "severityWithCritical": "high", |
| 230 | + "title": "Access Restriction Bypass", |
| 231 | + "from": [ |
| 232 | + |
| 233 | + "github.com/heketi/heketi/client/api/[email protected]", |
| 234 | + "github.com/dgrijalva/[email protected]" |
| 235 | + ], |
| 236 | + "upgradePath": [], |
| 237 | + "isUpgradable": false, |
| 238 | + "isPatchable": false, |
| 239 | + "name": "github.com/dgrijalva/jwt-go", |
| 240 | + "version": "3.2.0" |
| 241 | +} |
| 242 | +{ |
| 243 | + "CVSSv3": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N", |
| 244 | + "alternativeIds": [], |
| 245 | + "creationTime": "2020-07-30T13:33:31.283115Z", |
| 246 | + "credit": [ |
| 247 | + "christopher-wong" |
| 248 | + ], |
| 249 | + "cvssScore": 7.5, |
| 250 | + "description": "## Overview\n[github.com/dgrijalva/jwt-go](https://github.com/dgrijalva/jwt-go) is a go implementation of JSON Web Tokens.\n\nAffected versions of this package are vulnerable to Access Restriction Bypass if `m[\"aud\"]` happens to be `[]string{}`, as allowed by the spec, the type assertion fails and the value of `aud` is `\"\"`. This can cause audience verification to succeed even if the audiences being passed are incorrect if `required` is set to `false`.\n## Remediation\nUpgrade `github.com/dgrijalva/jwt-go` to version 4.0.0-preview1 or higher.\n## References\n- [GitHub Issue](https://github.com/dgrijalva/jwt-go/issues/422)\n- [GitHub PR](https://github.com/dgrijalva/jwt-go/pull/426)\n", |
| 251 | + "disclosureTime": "2020-07-30T13:22:28Z", |
| 252 | + "exploit": "Not Defined", |
| 253 | + "fixedIn": [ |
| 254 | + "4.0.0-preview1" |
| 255 | + ], |
| 256 | + "functions": [], |
| 257 | + "functions_new": [], |
| 258 | + "id": "SNYK-GOLANG-GITHUBCOMDGRIJALVAJWTGO-596515", |
| 259 | + "identifiers": { |
| 260 | + "CVE": [ |
| 261 | + "CVE-2020-26160" |
| 262 | + ], |
| 263 | + "CWE": [ |
| 264 | + "CWE-287" |
| 265 | + ] |
| 266 | + }, |
| 267 | + "language": "golang", |
| 268 | + "modificationTime": "2020-11-30T11:23:07.967004Z", |
| 269 | + "moduleName": "github.com/dgrijalva/jwt-go", |
| 270 | + "packageManager": "golang", |
| 271 | + "packageName": "github.com/dgrijalva/jwt-go", |
| 272 | + "patches": [], |
| 273 | + "proprietary": false, |
| 274 | + "publicationTime": "2020-09-13T15:53:35Z", |
| 275 | + "references": [ |
| 276 | + { |
| 277 | + "title": "GitHub Issue", |
| 278 | + "url": "https://github.com/dgrijalva/jwt-go/issues/422" |
| 279 | + }, |
| 280 | + { |
| 281 | + "title": "GitHub PR", |
| 282 | + "url": "https://github.com/dgrijalva/jwt-go/pull/426" |
| 283 | + } |
| 284 | + ], |
| 285 | + "semver": { |
| 286 | + "hashesRange": [ |
| 287 | + "v4.0.0-preview1" |
| 288 | + ], |
| 289 | + "vulnerable": [ |
| 290 | + "<4.0.0-preview1" |
| 291 | + ], |
| 292 | + "vulnerableHashes": null |
| 293 | + }, |
| 294 | + "severity": "high", |
| 295 | + "severityWithCritical": "high", |
| 296 | + "title": "Access Restriction Bypass", |
| 297 | + "from": [ |
| 298 | + |
| 299 | + "k8s.io/apiserver/pkg/storage/etcd3/[email protected]", |
| 300 | + "go.etcd.io/etcd/integration@#dd1b699fc489", |
| 301 | + "go.etcd.io/etcd/etcdserver/api/v3rpc@#dd1b699fc489", |
| 302 | + "go.etcd.io/etcd/mvcc@#dd1b699fc489", |
| 303 | + "go.etcd.io/etcd/auth@#dd1b699fc489", |
| 304 | + "github.com/dgrijalva/[email protected]" |
| 305 | + ], |
| 306 | + "upgradePath": [], |
| 307 | + "isUpgradable": false, |
| 308 | + "isPatchable": false, |
| 309 | + "name": "github.com/dgrijalva/jwt-go", |
| 310 | + "version": "3.2.0" |
| 311 | +} |
| 312 | +
|
| 313 | +``` |
| 314 | + |
| 315 | +</details> |
0 commit comments