In this section we are going to create an Actions workflow to scan existing workflows for any security weaknesses.
- In your repository,
click
on theActions
tab
NOTE
IfActions
tab is not available (this should not happen since you are looking to scan Actions workflows after all), please contact your organization admin or repository admin to enable it. See enabling Actions section in the documentation for more details.
-
This will take you to the
Actions
page and now click on thenew workflow
button to create a workflow. Alternatively, you can click this link. -
This will put you in the
starter workflows
page. EnterCodeQL Analysis
in theSearch
field and search. You should see one result. Click onConfigure
button on the resulting workflow template. This will take you to the edit window of the the workflow file.
NOTE
IfCodeQl Analysis
search is not returning any results, code scanning might not be enabled for the repo, please contact your organization admin or repository admin to enable it. If you want to learn more about setting up code scanning, you can follow this tutorial.
Now we can edit this workflow to customize it to scan the workflows.
- Give a name to the file (it could be
actions-workflow-codeql.yml
) and also give a name to the workflow (this could beActions WorkFlow CodeQL
)
At this point, you are close to having a CodeQL Workflow that can scan your repository for vulnerabitlities.
- Edit the workflow file as follows:
Look over the first few lines of the workflow. You'd notice that the workflow gets triggered by push
to the default
branch and also by several other events.
Edit the workflow's trigger section as follows:
- Keep the
push
trigger - Add
workflow_dispatch:
trigger. - Remove other trigger that were pre-configured in the workflow.
- In the
strategy
:matrix
:language
section, type'javascript'
as the value for lanuage array. - Remove the
Autobuild
step entirely.
NOTE
Autobuild is only necessary for compiled languages, since we are using thejavascript
extractor, this is not really necessary.
NOTE
workflow_dispatch
will give us the ability to run the scan on demand. As you are typing, Github will indicate if there are any errors in the workflow. You can just add a new line afterpush: branches
section and add the newworkflow_dispatch:
trigger.
- Commit this file into the
default
branch.
When the file is committed, it will generate a push
event and the Actions WorkFlow CodeQL
workflow should be triggered. Now click
on the Actions
tab and you should see the workflow being scheduled to run based on the push
event.
- Monitor the workflow run and ensure that it finishes successfully.
NOTE
For your convenience a sample of this workflow is available in/solutions
directory.
- Now, click on the
Security
tab. And you should see theSecurity Overview
page with two alerts created underCode Scanning
.
- Click on
Code Scanning
in the side menubar of theSecurity Overview
page. And click on the first alert -Expression Injection in Actions
You'll see the details of the alert including the file where this weakness exists.
- Click on
Show more
to see more details including how to resolve this alert.
The Exercise 5 and Exercise 6 will show how to modify the problematic workflow file to resolve this alert.
At the end of those exercises, once the file is committed, it will trigger the Actions Workflow CodeQL
and the alert should be resolved if the recommend fix was implemented.