Repository navigation
Description
Hi,
I'm facing an issue uploading a SARIF file using upload-sarif@v1 on a self-hosted runner.
Here is my code (in a composite action) :
- name: Scan image
id: scan
uses: sysdiglabs/scan-action@v3
with:
[...]
- uses: github/codeql-action/upload-sarif@v1
with:
sarif_file: ${{ steps.scan.outputs.sarifReport }}
This works great when I push / PR to a branch called develop but an issue is happening when I apply the same composite action to master branch. It looks like for some reason the upload-sarif@v1 action doesn't call the API correctly ?
Here are the logs on develop (omitting env variables) :
Run github/codeql-action/upload-sarif@v1
with:
sarif_file: ./sarif.json
checkout_path: /home/azureuser/actions-runner-2/runner/_work/my-app/my-app
token: ***
matrix: {
"node-version": "16.3.0",
"env": {
"name": "development"
}
}
env:
[...]
Uploading results
Processing sarif files: ["./sarif.json"]
Uploading results
Successfully uploaded results
I can see the uploaded results on the security tab of the github repo.
Here are the logs on master:
Processing sarif files: ["./sarif.json"]
Uploading results
Error: Invalid request.
master does not match /^refs\/(heads|pull|tags)\/.*$/.
RequestError [HttpError]: Invalid request.
master does not match /^refs\/(heads|pull|tags)\/.*$/.
at /home/azureuser/actions-runner-2/runner/_work/_actions/github/codeql-action/v1/node_modules/@octokit/request/dist-node/index.js:66:23
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Job.doExecute (/home/azureuser/actions-runner-2/runner/_work/_actions/github/codeql-action/v1/node_modules/bottleneck/light.js:405:18) {
name: 'HttpError',
status: 422,
headers: {
'access-control-allow-origin': '*',
'access-control-expose-headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset',
connection: 'close',
'content-length': '141',
'content-security-policy': "default-src 'none'",
'content-type': 'application/json; charset=utf-8',
date: 'Thu, 28 Oct 2021 06:12:21 GMT',
'referrer-policy': 'origin-when-cross-origin, strict-origin-when-cross-origin',
server: 'GitHub.com',
'strict-transport-security': 'max-age=31536000; includeSubdomains; preload',
vary: 'Accept-Encoding, Accept, X-Requested-With',
'x-content-type-options': 'nosniff',
'x-frame-options': 'deny',
'x-github-media-type': 'github.v3; format=json',
'x-github-request-id': '0805:5EAA:1CCB18D:34AE888:617A3F44',
'x-ratelimit-limit': '500',
'x-ratelimit-remaining': '490',
'x-ratelimit-reset': '1635404509',
'x-ratelimit-resource': 'code_scanning_upload',
'x-ratelimit-used': '10',
'x-xss-protection': '0'
},
request: {
method: 'PUT',
url: 'https://api.github.com/repos/MYORG/my-app/code-scanning/analysis',
headers: {
accept: 'application/vnd.github.v3+json',
'user-agent': 'CodeQL-Action/1.0.20 octokit-core.js/3.1.2 Node.js/12.13.1 (linux; x64)',
authorization: 'token [REDACTED]',
'content-type': 'application/json; charset=utf-8'
},
...
The API doc mention that ref is Required. The full Git reference, formatted as refs/heads/<branch name>,refs/pull/<number>/merge, or refs/pull/<number>/head. : https://docs.github.com/en/rest/reference/code-scanning#upload-an-analysis-as-sarif-data
Using this action we have no control other what the action sends to the API so it is not possible in our end to enforce the full git reference.
Is this a known issue ? Any reason why I am facing here in a master branch but not on other branches ?
Activity
aeisenberg commentedon Oct 28, 2021
The ref that the upload action passes is grabbed from the
GITHUB_REFenvironment variable (there's some extra checking for edge cases, but it's mostly just that). So, if the action is uploading an invalid ref it's most likely that the environment variable is not pointing to the correct thing.You mentioned that you are using a composite action. It's unlikely, but it's possible that the environment variable is getting mangled there? Something like this would work:
Can you try something for me? Before the
- uses: github/codeql-action/upload-sarif@v1step, can you add a new step that outputs all of your environment variables? And then please add a comment with all the relevant variables.If my guess is right, then we should figure out why the variable is being mangled. But as a quick workaround, you could explicitly set the variable to prepend the
/refs/headsbefore running the upload action.totogtr commentedon Oct 29, 2021
Thanks for your quick reply.
Indeed you are right, it seems that the GITHUB_REF is not populated correctly in some case with the composite action.
I've added the dump environment, here is what I get when I trigger my workflow (that include the composite action)
Workflow triggered manually on master branch :
GITHUB_REFcontains refs/head and the upload-sarif works fine.However when the same workflow is triggered by a PR closed from develop to master, I get :
Here the
GITHUB_REFis onlymasterand then it fails.So do you think "something" in the composite action change the value of the
GITHUB_BASE_REFif the workflow using it hasGITHUB_EVENT_NAMEset aspull_requestinstead ofworkflow_dispatchIn my use-case, this workflow could be either triggered by a PR or manually. I'll add a step to check and explicity set the
/refs/headsif it's missing.lenyfernandez commentedon Jan 21, 2022
Hi @totogtr and @aeisenberg I'm facing the same issue. Were you able to explicitly set the
/refs/heads? I could not seem to explicitly setGITHUB_REFto any value. Thanks!aeisenberg commentedon Jan 21, 2022
I haven't heard back to hear if the solution works, but you could add a step like this in your composite action before uploading:I haven't tried this out directly, but in theory, this should update theGITHUB_REFenv variable if it doesn't already start with/refs/heads/.EDIT: This will not work. GitHub Actions refuses to allow you to edit any env variable prefixed with
GITHUB_. It is a security flaw.adityasharad commentedon Jan 21, 2022
@totogtr would you be able to share the full Actions workflow file, so that we can see the different events your workflow is running on? And also the full contents of your composite action if possible.
totogtr commentedon Mar 29, 2022
@adityasharad Hi, sorry I cannot share the full action, some as client data in it.
I've just hit this issue again today (1st time since my last message !)
Is there anything in #889 that would help us fix it?
aeisenberg commentedon Mar 29, 2022
Yes, the upload-sarif action now supports a
refandshainput. So, you can specify the values you want using thewithproperty:You need to specify both of them together.
Workaround for GitHub / CodeQL bug
Workaround for GitHub / CodeQL bug
Workaround for GitHub / CodeQL bug
Workaround for GitHub / CodeQL bug