-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add ssc-scan action, supporting both SC-SAST & Debricked
- Loading branch information
Showing
20 changed files
with
140 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# fortify/github-action/internal/run-script | ||
|
||
This action can run any of the scripts located in the `scripts` directory of this action, including the ability to run post-job scripts, for example to handle session logout. | ||
|
||
```yaml | ||
- uses: fortify/github-action/internal/run-script@v1 | ||
with: | ||
script: <script name> | ||
post: <post-job script name> | ||
``` | ||
Originally, the idea was to have these scripts located in each individual action directory, for example having `ssc-login.sh` and `ssc-logout.sh` scripts located in the `internal/ssc-login` directory. However, this proved to be difficult/impossible: | ||
|
||
- As scripts need to be run using `bash` (also on Windows), we need to convert `${{github.action_path}}` (which may include drive letter and backslashes on Windows) to `bash` format; an example of how this can be done is shown in `action.yml`. | ||
- GitHub lazily evaluates action inputs when running the post-job actions, but doesn't re-run any steps used to generate those inputs. | ||
|
||
So, suppose we'd generate a `BASH_ACTION_PATH` environment variable that contains `${{github.action_path}}` in `bash` format, we'd expect to be able to use something like: | ||
|
||
```yaml | ||
- uses: fortify/github-action/internal/run-script/[email protected] | ||
with: | ||
script: ${{ env.BASH_ACTION_PATH }}/ssc-login.sh | ||
post: ${{ env.BASH_ACTION_PATH }}/ssc-logout.sh | ||
``` | ||
|
||
This works fine for `script:`, but the `post:` script would use whatever the value of `BASH_ACTION_PATH` is during post-job execution. So, if we'd run both `ssc-login` and `sc-sast-login` actions, the post-job action would try to run `../internal/sc-sast-login/ssc-logout.sh`, which would fail because of the incorrect directory name. | ||
|
||
Several work-arounds were tried, but failed. Only way that this would likely work is to have the calling action pass something like a static action id, which would then be used by this action to set a `POST_<id>_SCRIPT=${{inputs.POST}}` environment variable. During post-job execution, we wouldn't look at any actual inputs, but instead just execute the script identified in the `POST_<id>_SCRIPT` environment variable. | ||
|
||
Apart from hosting the scripts together with the action that executes them, another advantage of such an id is that we can also provide out-of-the-box support for run-once actions, like the various `login` actions; this is currently handled by setting an environment variable in the `*-login.sh` and `*-logout.sh` scripts. As we may also have scripts that may need to be run multiple times, we should control this through a `run-once: true|false` input. | ||
|
||
Disadvantage, apart from slightly more complex implementation, is that each caller of this `run-script` action would also need to provide the value of `${{ github.action_path }}` as an input to this action, in order to have this action determine appropriate script location. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,21 +15,14 @@ inputs: | |
runs: | ||
using: composite | ||
steps: | ||
# github.action_path uses platform-specific path format, like D:\... for Windows. | ||
# The run-script-js action requires the path to be in bash format, so we convert | ||
# the paths to bash format before invoking the run-script-js action. | ||
- run: echo "BASH_SCRIPT_DIR=$(pwd)" >> $GITHUB_ENV | ||
shell: bash | ||
working-directory: ${{ inputs.dir }} | ||
- run: echo "BASH_UTIL_DIR=$(pwd)/util" >> $GITHUB_ENV | ||
- run: echo "_RUN_SCRIPTS_DIR=$(pwd)/scripts" >> $GITHUB_ENV | ||
shell: bash | ||
working-directory: ${{ github.action_path }} | ||
- uses: fortify/github-action/internal/run-script-[email protected] | ||
- uses: fortify/github-action/internal/run-script/[email protected] | ||
with: | ||
util: ${{ env.BASH_UTIL_DIR }} | ||
dir: ${{ env.BASH_SCRIPT_DIR }} | ||
dir: ${{ env._RUN_SCRIPTS_DIR }} | ||
script: ${{ inputs.script }} | ||
post: ${{ inputs.post }} | ||
post: ${{ inputs.post }} | ||
|
||
branding: | ||
icon: 'shield' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const util = require("./util"); | ||
|
||
util.run(process.env.INPUT_SCRIPT); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const util = require("./util"); | ||
|
||
util.run(process.env.INPUT_POST); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const { spawn } = require("child_process"); | ||
|
||
exports.run = function(script) { | ||
if ( script ) { | ||
const scriptDir = process.env.INPUT_DIR; | ||
const subprocess = spawn(`bash -c -o pipefail -v 'export UTIL_DIR=${scriptDir}; ${scriptDir}/${script}'`, | ||
{ stdio: "inherit", shell: true }); | ||
subprocess.on("exit", (exitCode) => { | ||
process.exitCode = exitCode; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash | ||
. ${UTIL_DIR}/common.sh | ||
|
||
# This script assumes that fcli and Debricked CLI have already been installed, | ||
# and that any necessary fcli sessions have been created. | ||
# TODO Check prerequisites like SSC_APPVERSION, DEBRICKED_TOKEN, ... | ||
|
||
if [ "${DO_SC_SAST_SCAN}" == "true" ]; then | ||
run ${FCLI_CMD} sc-sast scan start --publish-to "${SSC_APPVERSION}" -p package.zip -v "${SC_SAST_SENSOR_VERSION}" --store sc_sast_scan ${EXTRA_SC_SAST_SCAN_OPTS} \ | ||
|| exit 1 | ||
fi | ||
if [ "${DO_DEBRICKED_SCAN}" == "true" ]; then | ||
# Debricked may return non-zero exit code on automation rule failures, in which case | ||
# we still want to run subsequent steps, hence we temporarily ignore the exit code, | ||
run ${DEBRICKED_CLI_CMD} scan -t "${DEBRICKED_TOKEN}" -i "Fortify GitHub Action" \ | ||
|| FAIL_ON_EXIT=true | ||
run ${FCLI_CMD} ssc artifact import-debricked --av "${SSC_APPVERSION}" --repository "${GITHUB_REPOSITORY}" --branch "${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}" -t "${DEBRICKED_TOKEN}" --store debricked_scan \ | ||
|| exit 1 | ||
fi | ||
if [ "${DO_WAIT}" == "true" ] || [ "${DO_EXPORT}" == "true" ]; then | ||
if [ "${DO_SC_SAST_SCAN}" == "true" ]; then | ||
run ${FCLI_CMD} sc-sast scan wait-for ::sc_sast_scan:: \ | ||
|| exit 1 | ||
fi | ||
if [ "${DO_DEBRICKED_SCAN}" == "true" ]; then | ||
run ${FCLI_CMD} ssc artifact wait-for ::debricked_scan:: \ | ||
|| exit 1 | ||
fi | ||
fi | ||
if [ "${FAIL_ON_EXIT}" == "true" ]; then | ||
echo "Earlier failures detected" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: 'Perform SAST scan' | ||
description: 'Perform a SAST scan on ScanCentral SAST' | ||
author: 'Fortify' | ||
runs: | ||
using: composite | ||
steps: | ||
- uses: fortify/github-action/[email protected] | ||
with: | ||
export-path: false | ||
fcli: action-default | ||
debricked-cli: ${{ env.DO_DEBRICKED_SCAN=='true' && 'action-default' || 'skip' }} | ||
- uses: fortify/github-action/internal/[email protected] | ||
- uses: fortify/github-action/internal/[email protected] | ||
- uses: fortify/github-action/[email protected] | ||
- uses: fortify/github-action/internal/[email protected] | ||
with: | ||
dir: ${{ github.action_path }} | ||
script: ssc-scan.sh | ||
- if: env.DO_EXPORT == 'true' | ||
uses: fortify/github-action/[email protected] | ||
|
||
branding: | ||
icon: 'shield' | ||
color: 'blue' | ||
|