---
# System prepended metadata

title: k/k scanning using snyk

---

# k/k scanning using snyk

This is to track what's needed for scanning `kubernetes/kubernetes` repo using one of the available options, snyk <https://snyk.io/> command line interface.




## Why run the scan
Preemptively report any vunerable dependencies.




## Snyk local run

### Step0: Install Synk CLI

Follow these instructions to synk cli installed on your machine: https://support.snyk.io/hc/en-us/articles/360003812538-Install-the-Snyk-CL 


### Step1: Auth
#### option A :
Running command `snyk auth` takes you to snyk.io website, do signup/login/auth
```
snyk auth
```
#### option B:
Get the API token from https://app.snyk.io/account and use it
```
snyk auth XXX-XXX-XXX-XXX-XXX
Your account has been authenticated. Snyk is now ready to be used.
```

### Step 2: Run test
```
# in k/k repo
snyk test
```

## How to run scan for k/k
option A: Run prow periodic CI job which runs snyk CLI


### Requires
1 - API token for authentication with snyk (see snyk local run above)
2 - Periodic CI job

### Caveats
#### 1. dep identification
snyk reports CVEs and CWEs for k/k deps. It's reporting a few deps which shouldnt be there.
For example, take a look at this `snyk test` run for k/k 
```
➜  kubernetes git:(master) git rev-parse HEAD
b0abe89ae259d5e891887414cb0e5f81c969c697
➜  kubernetes git:(master) snyk test

Testing /Users/navids/go/src/k8s.io/kubernetes...

✗ Medium severity vulnerability found in k8s.io/kubernetes
  Description: Man-in-the-Middle (MitM)
  Info: https://snyk.io/vuln/SNYK-GOLANG-K8SIOKUBERNETES-1048855
  Introduced through: k8s.io/kubernetes@0.0.0
  From: k8s.io/kubernetes@0.0.0
  Fixed in: 1.21.0-alpha.1

✗ Medium severity vulnerability found in k8s.io/kubernetes
  Description: Directory Traversal
  Info: https://snyk.io/vuln/SNYK-GOLANG-K8SIOKUBERNETES-50019
  Introduced through: k8s.io/kubernetes@0.0.0
  From: k8s.io/kubernetes@0.0.0
  Fixed in: 1.1.1

✗ High severity vulnerability found in github.com/satori/go.uuid
  Description: Insecure Randomness
  Info: https://snyk.io/vuln/SNYK-GOLANG-GITHUBCOMSATORIGOUUID-72488
  Introduced through: k8s.io/legacy-cloud-providers/azure@unknown
  From: k8s.io/legacy-cloud-providers/azure@unknown > github.com/Azure/azure-sdk-for-go/storage@unknown > github.com/satori/go.uuid@1.2.0

✗ High severity vulnerability found in github.com/dgrijalva/jwt-go
  Description: Access Restriction Bypass
  Info: https://snyk.io/vuln/SNYK-GOLANG-GITHUBCOMDGRIJALVAJWTGO-596515
  Introduced through: github.com/heketi/heketi/client/api/go-client@unknown, k8s.io/apiserver/pkg/storage/etcd3/testing@unknown
  From: github.com/heketi/heketi/client/api/go-client@unknown > github.com/dgrijalva/jwt-go@3.2.0
  From: k8s.io/apiserver/pkg/storage/etcd3/testing@unknown > go.etcd.io/etcd/integration@unknown > go.etcd.io/etcd/etcdserver/api/v3rpc@unknown > go.etcd.io/etcd/mvcc@unknown > go.etcd.io/etcd/auth@unknown > github.com/dgrijalva/jwt-go@3.2.0
  Fixed in: 4.0.0-preview1



Organization:      navidshaikh
Package manager:   gomodules
Target file:       go.mod
Project name:      k8s.io/kubernetes
Open source:       no
Project path:      /Users/navids/go/src/k8s.io/kubernetes
Licenses:          enabled

Tested 1686 dependencies for known issues, found 4 issues, 5 vulnerable paths.

Tip: Detected multiple supported manifests (34), use --all-projects to scan all of them at once.

```

Note these two instances
```
✗ Medium severity vulnerability found in k8s.io/kubernetes
  Description: Man-in-the-Middle (MitM)
  Info: https://snyk.io/vuln/SNYK-GOLANG-K8SIOKUBERNETES-1048855
  Introduced through: k8s.io/kubernetes@0.0.0
  From: k8s.io/kubernetes@0.0.0
  Fixed in: 1.21.0-alpha.1

✗ Medium severity vulnerability found in k8s.io/kubernetes
  Description: Directory Traversal
  Info: https://snyk.io/vuln/SNYK-GOLANG-K8SIOKUBERNETES-50019
  Introduced through: k8s.io/kubernetes@0.0.0
  From: k8s.io/kubernetes@0.0.0
  Fixed in: 1.1.1
```

line `Introduced through: k8s.io/kubernetes@0.0.0` hints `k8s.io/kubernetes@0.0.0` as k8s dep.
This needs to be investigated.

#### 2. json output
Run `snyk test --json` and notice the number of reported instances. I see 5 while in default output (without `--json`) it reported as 4.
OR 
Run `snyk test --json-file-output=licenses-cves.json` to store the json output in a file and let stdout use command line friendly output

#### 3. Licenses

Licenses can be removed from the output using this query:

`cat licenses-cves.json |  jq '.vulnerabilities | .[] | select (.type=="license" | not)' > only_cves.json`
#### 4. Removing False positive CVEs identified with v0.0.0

Since these are really pointing to the code at HEAD in git tracking, we can ignore the vulnerbalities that are generated when snyk detects version of the dependency. Easy way to remove licensing and CVEs like this:

`cat licenses-cves.json |  jq '.vulnerabilities | .[] | select ((.type=="license") or (.version=="0.0.0") | not)' > only_cves_wo000.json`


## Filtered out JSON scan result

```
{
  "CVSSv3": "CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H",
  "alternativeIds": [],
  "creationTime": "2021-02-08T10:27:10.200417Z",
  "credit": [
    "Unknown"
  ],
  "cvssScore": 7.2,
  "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",
  "disclosureTime": "2021-02-05T00:00:00Z",
  "exploit": "Not Defined",
  "fixedIn": [
    "0.8.1"
  ],
  "functions": [],
  "functions_new": [],
  "id": "SNYK-GOLANG-GITHUBCOMCONTAINERNETWORKINGCNIPKGINVOKE-1070549",
  "identifiers": {
    "CVE": [
      "CVE-2021-20206"
    ],
    "CWE": [
      "CWE-22"
    ]
  },
  "language": "golang",
  "modificationTime": "2021-02-08T14:14:51.744734Z",
  "moduleName": "github.com/containernetworking/cni/pkg/invoke",
  "packageManager": "golang",
  "packageName": "github.com/containernetworking/cni/pkg/invoke",
  "patches": [],
  "proprietary": false,
  "publicationTime": "2021-02-08T14:14:51.968123Z",
  "references": [
    {
      "title": "GitHub PR",
      "url": "https://github.com/containernetworking/cni/pull/808"
    },
    {
      "title": "RedHat Bugzilla Bug",
      "url": "https://bugzilla.redhat.com/show_bug.cgi?id=1919391"
    }
  ],
  "semver": {
    "hashesRange": [
      "<v0.8.1"
    ],
    "vulnerable": [
      "<0.8.1"
    ],
    "vulnerableHashes": [<snipped a long list of hashes for brevity>
    ]
  },
  "severity": "high",
  "severityWithCritical": "high",
  "title": "Directory Traversal",
  "from": [
    "k8s.io/kubernetes@0.0.0",
    "github.com/containernetworking/cni/libcni@0.8.0",
    "github.com/containernetworking/cni/pkg/invoke@0.8.0"
  ],
  "upgradePath": [],
  "isUpgradable": false,
  "isPatchable": false,
  "name": "github.com/containernetworking/cni/pkg/invoke",
  "version": "0.8.0"
}
{
  "CVSSv3": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N",
  "alternativeIds": [],
  "creationTime": "2020-07-30T13:33:31.283115Z",
  "credit": [
    "christopher-wong"
  ],
  "cvssScore": 7.5,
  "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",
  "disclosureTime": "2020-07-30T13:22:28Z",
  "exploit": "Not Defined",
  "fixedIn": [
    "4.0.0-preview1"
  ],
  "functions": [],
  "functions_new": [],
  "id": "SNYK-GOLANG-GITHUBCOMDGRIJALVAJWTGO-596515",
  "identifiers": {
    "CVE": [
      "CVE-2020-26160"
    ],
    "CWE": [
      "CWE-287"
    ]
  },
  "language": "golang",
  "modificationTime": "2020-11-30T11:23:07.967004Z",
  "moduleName": "github.com/dgrijalva/jwt-go",
  "packageManager": "golang",
  "packageName": "github.com/dgrijalva/jwt-go",
  "patches": [],
  "proprietary": false,
  "publicationTime": "2020-09-13T15:53:35Z",
  "references": [
    {
      "title": "GitHub Issue",
      "url": "https://github.com/dgrijalva/jwt-go/issues/422"
    },
    {
      "title": "GitHub PR",
      "url": "https://github.com/dgrijalva/jwt-go/pull/426"
    }
  ],
  "semver": {
    "hashesRange": [
      "v4.0.0-preview1"
    ],
    "vulnerable": [
      "<4.0.0-preview1"
    ],
    "vulnerableHashes": null
  },
  "severity": "high",
  "severityWithCritical": "high",
  "title": "Access Restriction Bypass",
  "from": [
    "k8s.io/kubernetes@0.0.0",
    "github.com/heketi/heketi/client/api/go-client@10.2.0",
    "github.com/dgrijalva/jwt-go@3.2.0"
  ],
  "upgradePath": [],
  "isUpgradable": false,
  "isPatchable": false,
  "name": "github.com/dgrijalva/jwt-go",
  "version": "3.2.0"
}
{
  "CVSSv3": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N",
  "alternativeIds": [],
  "creationTime": "2020-07-30T13:33:31.283115Z",
  "credit": [
    "christopher-wong"
  ],
  "cvssScore": 7.5,
  "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",
  "disclosureTime": "2020-07-30T13:22:28Z",
  "exploit": "Not Defined",
  "fixedIn": [
    "4.0.0-preview1"
  ],
  "functions": [],
  "functions_new": [],
  "id": "SNYK-GOLANG-GITHUBCOMDGRIJALVAJWTGO-596515",
  "identifiers": {
    "CVE": [
      "CVE-2020-26160"
    ],
    "CWE": [
      "CWE-287"
    ]
  },
  "language": "golang",
  "modificationTime": "2020-11-30T11:23:07.967004Z",
  "moduleName": "github.com/dgrijalva/jwt-go",
  "packageManager": "golang",
  "packageName": "github.com/dgrijalva/jwt-go",
  "patches": [],
  "proprietary": false,
  "publicationTime": "2020-09-13T15:53:35Z",
  "references": [
    {
      "title": "GitHub Issue",
      "url": "https://github.com/dgrijalva/jwt-go/issues/422"
    },
    {
      "title": "GitHub PR",
      "url": "https://github.com/dgrijalva/jwt-go/pull/426"
    }
  ],
  "semver": {
    "hashesRange": [
      "v4.0.0-preview1"
    ],
    "vulnerable": [
      "<4.0.0-preview1"
    ],
    "vulnerableHashes": null
  },
  "severity": "high",
  "severityWithCritical": "high",
  "title": "Access Restriction Bypass",
  "from": [
    "k8s.io/kubernetes@0.0.0",
    "k8s.io/apiserver/pkg/storage/etcd3/testing@0.0.0",
    "go.etcd.io/etcd/integration@#dd1b699fc489",
    "go.etcd.io/etcd/etcdserver/api/v3rpc@#dd1b699fc489",
    "go.etcd.io/etcd/mvcc@#dd1b699fc489",
    "go.etcd.io/etcd/auth@#dd1b699fc489",
    "github.com/dgrijalva/jwt-go@3.2.0"
  ],
  "upgradePath": [],
  "isUpgradable": false,
  "isPatchable": false,
  "name": "github.com/dgrijalva/jwt-go",
  "version": "3.2.0"
}

```

## Action items:

- [x]  Work with snyk team to see if we can have an API token for k/k repo (and check can be it be kept in the public github repo)

- [x]   Report the dep identification caveats as mentioned above with snyk team and investigate further (Check https://hackmd.io/QfcKDRWwTBmdlazRP9YLAA?view#3-Licenses)

- [ ] Work with k8s sig-testing to create a CI job which installs snyk CLI and run the scan


## References
- Slack thread https://kubernetes.slack.com/archives/CHGFYJVAN/p1595258034095300
- Request snyk service account: https://github.com/kubernetes/steering/issues/206

## Notes:


09 Apr: PJ : Navid

- Authentication:
    - Being taken care by open issue https://github.com/kubernetes/steering/issues/206

- Process:
    - What should be the cadence to run the scans?
        - We can begin with once a day, which runs the scans for all the updates to k8s dependencies
    - How are the results surfaced? / What to do with the output ?1
        - Options:
            - Fail the snyk job and alert on the slack/ML
            - Open the issue against k/k repo with results listing of vulnerable dependencies

    - What to do with the snyk results? and Triaging of vulnerabilities: 
        - Discussion underway here: https://docs.google.com/document/d/1V-IUJVYq4SGizNpZXA9GPBPeCJ-oH9p5V747o51NYvo/edit

- What to scan?
    - k8s master branch
    - k8s released branches
        - Major
        - Patch releases

- Open questions for snyk team?
    - RAM Usage:
        - RAM usage for each scan. Need some analysis on this and figure out if this is deterministic over a period of time
    - Licenses:
        - [x] Need to be able to remove license info or configure safe licenses as per CNCF guidelines. Check https://hackmd.io/QfcKDRWwTBmdlazRP9YLAA?view#3-Licenses
        - [ ] Can we use CNCF snyk scanning here?


First iteration plan:
- Uses the auth token received via the open steering issue
- Runs against master branch
- Figure out simplest reporting mechanism
    - Github issue ?
    - Slack notification ?
    - Fail the CI job ?