Repository: bridgecrewio/checkov

Issue:
Azure Devops Pipeline - Container Crash - "Context for Kubernetes runner was not set"
Sorry if this is not the correct issue type, but it didn't really fit in to any of the boxes.

**Describe the issue**
At some point between 11:34 and 14:39 on Monday December 12th our Terraform pipelines started failing with the error "Context for Kubernetes runner was not set". I have pinned the container to 2.2.131 and the issue has stopped.

I found 3 references to this error in the code, and confusingly none of them look like they've been updated in that window, but it's being raised as an error, so it's the one in runner.py that's being triggered.
```
checkov/kubernetes/runner.py
189:                logging.error("Context for Kubernetes runner was not set")
246:            logging.error("Context for Kubernetes runner was not set")

checkov/kustomize/runner.py
560:            logging.warning("Failed to run Kubernetes runner", exc_info=True)

checkov/helm/runner.py
82:            logging.warning(f"Failed to run Kubernetes runner on charts {self.chart_dir_and_meta}", exc_info=True)
```

**Examples**
Not an IaC issue.

**Exception Trace**

The version from the Pipeline output is here, I also have 37,000 lines of 'real' logs from running the container with `-e LOG_LEVEL=debug` if you need them.

```2022-12-21T16:26:07.5139046Z ##[debug]Evaluating condition for step: 'Checkov'
2022-12-21T16:26:07.5140610Z ##[debug]Evaluating: SucceededNode()
2022-12-21T16:26:07.5141112Z ##[debug]Evaluating SucceededNode:
2022-12-21T16:26:07.5142072Z ##[debug]=> True
2022-12-21T16:26:07.5142555Z ##[debug]Result: True
2022-12-21T16:26:07.5143009Z ##[section]Starting: Checkov
2022-12-21T16:26:07.5150093Z ==============================================================================
2022-12-21T16:26:07.5150381Z Task         : Bash
2022-12-21T16:26:07.5150614Z Description  : Run a Bash script on macOS, Linux, or Windows
2022-12-21T16:26:07.5150872Z Version      : 3.214.0
2022-12-21T16:26:07.5151074Z Author       : Microsoft Corporation
2022-12-21T16:26:07.5151387Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/bash
2022-12-21T16:26:07.5151739Z ==============================================================================
2022-12-21T16:26:07.5625001Z ##[debug]Using node path: /home/vsts/agents/2.213.2/externals/node16/bin/node
2022-12-21T16:26:07.6454674Z ##[debug]agent.TempDirectory=/home/vsts/work/_temp
2022-12-21T16:26:08.0329046Z ##[debug]loading inputs and endpoints
2022-12-21T16:26:08.0339588Z ##[debug]loading INPUT_TARGETTYPE
2022-12-21T16:26:08.0360107Z ##[debug]loading INPUT_FILEPATH
2022-12-21T16:26:08.0365289Z ##[debug]loading INPUT_SCRIPT
2022-12-21T16:26:08.0370316Z ##[debug]loading INPUT_WORKINGDIRECTORY
2022-12-21T16:26:08.0374935Z ##[debug]loading INPUT_FAILONSTDERR
2022-12-21T16:26:08.0379873Z ##[debug]loading ENDPOINT_AUTH_SYSTEMVSSCONNECTION
2022-12-21T16:26:08.0384771Z ##[debug]loading ENDPOINT_AUTH_SCHEME_SYSTEMVSSCONNECTION
2022-12-21T16:26:08.0390935Z ##[debug]loading ENDPOINT_AUTH_PARAMETER_SYSTEMVSSCONNECTION_ACCESSTOKEN
2022-12-21T16:26:08.0398046Z ##[debug]loading SECRET_SYSTEM_ACCESSTOKEN
2022-12-21T16:26:08.0403361Z ##[debug]loaded 9
2022-12-21T16:26:08.0409860Z ##[debug]Agent.ProxyUrl=undefined
2022-12-21T16:26:08.0413615Z ##[debug]Agent.CAInfo=undefined
2022-12-21T16:26:08.0417387Z ##[debug]Agent.ClientCert=undefined
2022-12-21T16:26:08.0420132Z ##[debug]Agent.SkipCertValidation=undefined
2022-12-21T16:26:08.0428192Z ##[debug]check path : /home/vsts/work/_tasks/Bash_6c731c3c-3c68-459a-a5c9-bde6e6595b5b/3.214.0/task.json
2022-12-21T16:26:08.0434139Z ##[debug]adding resource file: /home/vsts/work/_tasks/Bash_6c731c3c-3c68-459a-a5c9-bde6e6595b5b/3.214.0/task.json
2022-12-21T16:26:08.0437444Z ##[debug]system.culture=en-US
2022-12-21T16:26:08.0451686Z ##[debug]failOnStderr=true
2022-12-21T16:26:08.0455768Z ##[debug]workingDirectory=/home/vsts/work/1/s
2022-12-21T16:26:08.0456555Z ##[debug]check path : /home/vsts/work/1/s
2022-12-21T16:26:08.0461564Z ##[debug]targetType=inline
2022-12-21T16:26:08.0463523Z ##[debug]bashEnvValue=undefined
2022-12-21T16:26:08.0468525Z ##[debug]script=docker pull bridgecrew/checkov
docker run --rm --volume /home/vsts/work/1/s:/tf --volume /home/vsts/work/1/s/.ssh:/root/.ssh bridgecrew/checkov --directory /tf/ --download-external-modules True --soft-fail-on medium --hard-fail-on high -o junitxml > /home/vsts/work/1/s/output/20221221.4-checkov.xml
2022-12-21T16:26:08.0482350Z Generating script.
2022-12-21T16:26:08.0486139Z ##[debug]which 'bash'
2022-12-21T16:26:08.0496885Z ##[debug]found: '/usr/bin/bash'
2022-12-21T16:26:08.0498418Z ##[debug]Agent.Version=2.213.2
2022-12-21T16:26:08.0499326Z ##[debug]agent.tempDirectory=/home/vsts/work/_temp
2022-12-21T16:26:08.0499981Z ##[debug]check path : /home/vsts/work/_temp
2022-12-21T16:26:08.0508264Z ========================== Starting Command Output ===========================
2022-12-21T16:26:08.0510819Z ##[debug]which '/usr/bin/bash'
2022-12-21T16:26:08.0512779Z ##[debug]found: '/usr/bin/bash'
2022-12-21T16:26:08.0514731Z ##[debug]/usr/bin/bash arg: /home/vsts/work/_temp/641541e8-c7dc-44d7-bd18-8a8f6b60471e.sh
2022-12-21T16:26:08.0518432Z ##[debug]exec tool: /usr/bin/bash
2022-12-21T16:26:08.0520400Z ##[debug]arguments:
2022-12-21T16:26:08.0521904Z ##[debug]   /home/vsts/work/_temp/641541e8-c7dc-44d7-bd18-8a8f6b60471e.sh
2022-12-21T16:26:08.0525186Z [command]/usr/bin/bash /home/vsts/work/_temp/641541e8-c7dc-44d7-bd18-8a8f6b60471e.sh
2022-12-21T16:26:08.6002233Z Using default tag: latest
2022-12-21T16:26:09.7318107Z latest: Pulling from bridgecrew/checkov
2022-12-21T16:26:09.7326138Z 3f4ca61aafcd: Pulling fs layer
2022-12-21T16:26:09.7333411Z 3f487a3359db: Pulling fs layer
2022-12-21T16:26:09.7334035Z 4ea2d1d8495e: Pulling fs layer
2022-12-21T16:26:09.7334380Z 0e9cf1618b4f: Pulling fs layer
2022-12-21T16:26:09.7334734Z b474c35f0abd: Pulling fs layer
2022-12-21T16:26:09.7335092Z 284952fd7973: Pulling fs layer
2022-12-21T16:26:09.7335430Z 6b166825e46f: Pulling fs layer
2022-12-21T16:26:09.7335780Z d2e65564a00a: Pulling fs layer
2022-12-21T16:26:09.7336249Z 92e2ce2669d5: Pulling fs layer
2022-12-21T16:26:09.7336542Z cf8b633247c1: Pulling fs layer
2022-12-21T16:26:09.7336837Z 0e9cf1618b4f: Waiting
2022-12-21T16:26:09.7337121Z b474c35f0abd: Waiting
2022-12-21T16:26:09.7337385Z 284952fd7973: Waiting
2022-12-21T16:26:09.7337664Z 6b166825e46f: Waiting
2022-12-21T16:26:09.7337971Z d2e65564a00a: Waiting
2022-12-21T16:26:09.7338479Z 92e2ce2669d5: Waiting
2022-12-21T16:26:09.7338745Z cf8b633247c1: Waiting
2022-12-21T16:26:10.0462016Z 3f487a3359db: Verifying Checksum
2022-12-21T16:26:10.0462421Z 3f487a3359db: Download complete
2022-12-21T16:26:10.1578871Z 4ea2d1d8495e: Verifying Checksum
2022-12-21T16:26:10.1579355Z 4ea2d1d8495e: Download complete
2022-12-21T16:26:10.2030639Z 3f4ca61aafcd: Verifying Checksum
2022-12-21T16:26:10.2031029Z 3f4ca61aafcd: Download complete
2022-12-21T16:26:10.3164421Z 0e9cf1618b4f: Verifying Checksum
2022-12-21T16:26:10.3170532Z 0e9cf1618b4f: Download complete
2022-12-21T16:26:10.4659860Z b474c35f0abd: Verifying Checksum
2022-12-21T16:26:10.4660342Z b474c35f0abd: Download complete
2022-12-21T16:26:10.7935623Z d2e65564a00a: Verifying Checksum
2022-12-21T16:26:10.7936033Z d2e65564a00a: Download complete
2022-12-21T16:26:10.8761747Z 6b166825e46f: Verifying Checksum
2022-12-21T16:26:10.8765899Z 6b166825e46f: Download complete
2022-12-21T16:26:11.0106839Z 284952fd7973: Verifying Checksum
2022-12-21T16:26:11.0110925Z 284952fd7973: Download complete
2022-12-21T16:26:11.0712130Z 92e2ce2669d5: Verifying Checksum
2022-12-21T16:26:11.0718360Z 92e2ce2669d5: Download complete
2022-12-21T16:26:11.1513446Z cf8b633247c1: Verifying Checksum
2022-12-21T16:26:11.1517622Z cf8b633247c1: Download complete
2022-12-21T16:26:11.5368719Z 3f4ca61aafcd: Pull complete
2022-12-21T16:26:12.4799193Z 3f487a3359db: Pull complete
2022-12-21T16:26:13.2303342Z 4ea2d1d8495e: Pull complete
2022-12-21T16:26:13.2908355Z 0e9cf1618b4f: Pull complete
2022-12-21T16:26:13.6812578Z b474c35f0abd: Pull complete
2022-12-21T16:26:15.5469911Z 284952fd7973: Pull complete
2022-12-21T16:26:20.2683367Z 6b166825e46f: Pull complete
2022-12-21T16:26:20.3268760Z d2e65564a00a: Pull complete
2022-12-21T16:26:20.3815220Z 92e2ce2669d5: Pull complete
2022-12-21T16:26:20.4304012Z cf8b633247c1: Pull complete
2022-12-21T16:26:20.4348508Z Digest: sha256:18ce7c7a3e8982ed7611b3e5c93df9036d7a41ce88737deeb009df9e3f732484
2022-12-21T16:26:20.4364732Z Status: Downloaded newer image for bridgecrew/checkov:latest
2022-12-21T16:26:20.4391652Z docker.io/bridgecrew/checkov:latest
2022-12-21T16:26:23.7703122Z 2022-12-21 16:26:23,769 [MainThread  ] [ERROR]  Context for Kubernetes runner was not set
2022-12-21T16:26:54.5952668Z ##[debug]Exit code 1 received from tool '/usr/bin/bash'
2022-12-21T16:26:54.5954224Z ##[debug]STDIO streams have closed for tool '/usr/bin/bash'
2022-12-21T16:26:54.5988691Z ##[error]Bash exited with code '1'.
2022-12-21T16:26:54.5997366Z ##[debug]Processed: ##vso[task.issue type=error;]Bash exited with code '1'.
2022-12-21T16:26:54.5998695Z ##[error]Bash wrote one or more lines to the standard error stream.
2022-12-21T16:26:54.5999388Z ##[debug]Processed: ##vso[task.issue type=error;]Bash wrote one or more lines to the standard error stream.
2022-12-21T16:26:54.6001156Z ##[error]2022-12-21 16:26:23,769 [MainThread  ] [ERROR]  Context for Kubernetes runner was not set

2022-12-21T16:26:54.6001966Z ##[debug]Processed: ##vso[task.issue type=error;]2022-12-21 16:26:23,769 [MainThread  ] [ERROR]  Context for Kubernetes runner was not set%0A
2022-12-21T16:26:54.6003055Z ##[debug]task result: Failed
2022-12-21T16:26:54.6005120Z ##[debug]Processed: ##vso[task.complete result=Failed;done=true;]
2022-12-21T16:26:54.6007815Z ##[section]Finishing: Checkov
```

**Desktop (please complete the following information):**
 - OS: Docker container running on Ubuntu
 - Checkov Version >2.2.131

**Additional context**
We're just using a bash step to pull the container and run it, at the moment. We are not running any Kubernetes through this, so these files shouldn't 
`docker run --rm --volume /home/vsts/work/1/s:/tf --volume /home/vsts/work/1/s/.ssh:/root/.ssh bridgecrew/checkov --directory /tf/ --download-external-modules True --soft-fail-on medium --hard-fail-on high -o junitxml > /home/vsts/work/1/s/output`



Discussion:
hey @jbstans thanks for reaching out. What do you mean exactly with failing? This specific error log messages was already moved to a proper location, but it doesn't influence the run in  any way. So, you can give one of the newer version a try, but I'm not sure it will solve your actual problem.
Using `bridgecrewio/checkov-action@master` in a github action and I'm getting the same error. This worked on December 21st.

`Error: -27 17:13:29,212 [MainThread  ] [ERROR]  Context for Kubernetes runner was not set`
@gruebel I saw the PR for moving the error message as I was creating the issue, because I was going to try and hunt down potential commits so I was looking at changes to those files, and immediately thought 'ah ha, it's already been solved'. 

Unfortunately when I tried again with the latest container but unfortunately the error message returned. 

And when I say it's causing the build to f ail I mean that whatever is causing this error message to fire is causing the step in which we run our Checkov steps to return a non-zero exit code and therefore the step is considered unsuccessful and as such the pipeline is halted.

I believe Azure Pipelines and Github actions are basically the same thing under the hood so @AliOatley thank you - that's quite reassuring. I was beginning to think I was going mad as I was sure there would be more people than just me running into this!
Yeah, second this. We've had to switch to an old checkov version since the latest change has broken our pipeline. Would love this looked at!

Resolving patch:
diff --git a/checkov/kubernetes/runner.py b/checkov/kubernetes/runner.py
--- a/checkov/kubernetes/runner.py
+++ b/checkov/kubernetes/runner.py
@@ -242,11 +242,6 @@ def mutate_kubernetes_graph_results(
         if not checks_results:
             return report
 
-        if not self.context:
-            # this shouldn't happen
-            logging.error("Context for Kubernetes runner was not set")
-            return report
-
         for check, check_results in checks_results.items():
             for check_result in check_results:
                 entity = check_result["entity"]


Test patch: