-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #462 from GitGuardian/agateau/test-github-actions
Test our GitHub actions
- Loading branch information
Showing
14 changed files
with
360 additions
and
8 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 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,8 @@ | ||
This directory contains GitHub actions used internally by our CI to simulate the "real" GitHub actions (the ones defined in the `actions` directory) using the latest versions of GGShield. | ||
|
||
They differ from the real GitHub actions by: | ||
|
||
- Using the `gitguardian/ggshield:unstable` Docker image instead of `gitguardian/ggshield:latest`. | ||
- Having the possibility to override the installed GGShield version. | ||
|
||
These actions are not meant to be used outside of GGShield CI. |
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,5 @@ | ||
FROM gitguardian/ggshield:unstable | ||
|
||
COPY entrypoint.sh /entrypoint.sh | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] |
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,26 @@ | ||
name: 'ggshield iac scan' | ||
description: 'Scan commits for iac vulnerabilities' | ||
author: GitGuardian <[email protected]> | ||
|
||
inputs: | ||
args: | ||
description: | | ||
Arguments to be passed to ggshield iac scan | ||
Options: | ||
--exit-zero Always return a 0 (non-error) status code, even if issues | ||
are found. The env var GITGUARDIAN_EXIT_ZERO can also be used | ||
to set this option. | ||
--minimum-severity [LOW|MEDIUM|HIGH|CRITICAL] | ||
Minimum severity of the policies | ||
--ignore-policy, --ipo TEXT Policies to exclude from the results. | ||
--ignore-path, --ipa PATH Do not scan the specified paths. | ||
--json JSON output. | ||
required: false | ||
branding: | ||
icon: 'shield' | ||
color: 'blue' | ||
runs: | ||
using: 'docker' | ||
image: 'Dockerfile' | ||
args: | ||
- ${{ inputs.args }} |
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,51 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
# AUTOGENERATED FILE, DO NOT EDIT! | ||
# This file has been generated by the `action-entrypoint-generator` script | ||
# defined in `scripts/action-entrypoint-generator`. To make changes to this | ||
# file, modify the script and rerun it. | ||
|
||
# GitHub overrides $HOME. Set it back to the home directory of our `app` user, | ||
# otherwise the call to `git config` fails. | ||
export HOME=/home/app | ||
|
||
# Mark the current directory as safe. If we don't do this, git commands fail | ||
# because the source in $PWD is owned by a different user than our `app` user. | ||
git config --global --add safe.directory "$PWD" | ||
|
||
progress() { | ||
echo -e "\033[34m$*\033[0m" | ||
} | ||
|
||
update_ggshield() { | ||
local old_pwd="$PWD" | ||
|
||
cd "$HOME" | ||
local venv_dir=$HOME/venv | ||
|
||
progress "Cloning ggshield $GITGUARDIAN_GGSHIELD_REF" | ||
git clone --depth 1 https://github.com/gitguardian/ggshield | ||
cd ggshield | ||
git fetch origin "$GITGUARDIAN_GGSHIELD_REF" | ||
git checkout FETCH_HEAD | ||
|
||
progress "Creating venv in $venv_dir" | ||
python -m venv "$venv_dir" | ||
. "$venv_dir/bin/activate" | ||
|
||
progress "Installing in venv" | ||
pip install . | ||
|
||
cd "$old_pwd" | ||
|
||
progress "ggshield=$(which ggshield)" | ||
} | ||
|
||
if [ -n "${GITGUARDIAN_GGSHIELD_REF:-}" ] ; then | ||
update_ggshield | ||
else | ||
progress "Using ggshield from image" | ||
fi | ||
|
||
args=("$@") | ||
ggshield iac scan -v ${args[@]} |
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,5 @@ | ||
FROM gitguardian/ggshield:unstable | ||
|
||
COPY entrypoint.sh /entrypoint.sh | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] |
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,26 @@ | ||
name: 'ggshield scan' | ||
description: 'Scan commits for hardcoded secrets and security policy breaks.' | ||
author: GitGuardian <[email protected]> | ||
|
||
branding: | ||
icon: 'shield' | ||
color: 'blue' | ||
|
||
inputs: | ||
args: | ||
description: | | ||
Arguments to be passed to ggshield secret scan | ||
Options: | ||
--json Output results in JSON format [default: False] | ||
--show-secrets Show secrets in plaintext instead of hiding them. | ||
--all-policies Present fails of all policies (Filenames, FileExtensions, | ||
Secret Detection). By default, only Secret Detection is shown. | ||
--exit-zero Always return a 0 (non-error) status code, even if incidents are found. | ||
-b, --banlist-detector TEXT Exclude results from a detector. | ||
required: false | ||
|
||
runs: | ||
using: 'docker' | ||
image: 'Dockerfile' | ||
args: | ||
- ${{ inputs.args }} |
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,51 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
# AUTOGENERATED FILE, DO NOT EDIT! | ||
# This file has been generated by the `action-entrypoint-generator` script | ||
# defined in `scripts/action-entrypoint-generator`. To make changes to this | ||
# file, modify the script and rerun it. | ||
|
||
# GitHub overrides $HOME. Set it back to the home directory of our `app` user, | ||
# otherwise the call to `git config` fails. | ||
export HOME=/home/app | ||
|
||
# Mark the current directory as safe. If we don't do this, git commands fail | ||
# because the source in $PWD is owned by a different user than our `app` user. | ||
git config --global --add safe.directory "$PWD" | ||
|
||
progress() { | ||
echo -e "\033[34m$*\033[0m" | ||
} | ||
|
||
update_ggshield() { | ||
local old_pwd="$PWD" | ||
|
||
cd "$HOME" | ||
local venv_dir=$HOME/venv | ||
|
||
progress "Cloning ggshield $GITGUARDIAN_GGSHIELD_REF" | ||
git clone --depth 1 https://github.com/gitguardian/ggshield | ||
cd ggshield | ||
git fetch origin "$GITGUARDIAN_GGSHIELD_REF" | ||
git checkout FETCH_HEAD | ||
|
||
progress "Creating venv in $venv_dir" | ||
python -m venv "$venv_dir" | ||
. "$venv_dir/bin/activate" | ||
|
||
progress "Installing in venv" | ||
pip install . | ||
|
||
cd "$old_pwd" | ||
|
||
progress "ggshield=$(which ggshield)" | ||
} | ||
|
||
if [ -n "${GITGUARDIAN_GGSHIELD_REF:-}" ] ; then | ||
update_ggshield | ||
else | ||
progress "Using ggshield from image" | ||
fi | ||
|
||
args=("$@") | ||
ggshield secret scan -v ${args[@]} ci |
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 |
---|---|---|
@@ -1,4 +1,18 @@ | ||
#! /usr/bin/env bash | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
# AUTOGENERATED FILE, DO NOT EDIT! | ||
# This file has been generated by the `action-entrypoint-generator` script | ||
# defined in `scripts/action-entrypoint-generator`. To make changes to this | ||
# file, modify the script and rerun it. | ||
|
||
# GitHub overrides $HOME. Set it back to the home directory of our `app` user, | ||
# otherwise the call to `git config` fails. | ||
export HOME=/home/app | ||
|
||
# Mark the current directory as safe. If we don't do this, git commands fail | ||
# because the source in $PWD is owned by a different user than our `app` user. | ||
git config --global --add safe.directory "$PWD" | ||
|
||
|
||
args=("$@") | ||
ggshield iac scan -v ${args[@]} |
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 |
---|---|---|
@@ -1,4 +1,18 @@ | ||
#! /usr/bin/env bash | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
# AUTOGENERATED FILE, DO NOT EDIT! | ||
# This file has been generated by the `action-entrypoint-generator` script | ||
# defined in `scripts/action-entrypoint-generator`. To make changes to this | ||
# file, modify the script and rerun it. | ||
|
||
# GitHub overrides $HOME. Set it back to the home directory of our `app` user, | ||
# otherwise the call to `git config` fails. | ||
export HOME=/home/app | ||
|
||
# Mark the current directory as safe. If we don't do this, git commands fail | ||
# because the source in $PWD is owned by a different user than our `app` user. | ||
git config --global --add safe.directory "$PWD" | ||
|
||
|
||
args=("$@") | ||
ggshield secret scan -v ${args[@]} ci |
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
86 changes: 86 additions & 0 deletions
86
scripts/action-entrypoint-generator/action-entrypoint-generator
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,86 @@ | ||
#!/usr/bin/env python | ||
""" | ||
Generate the entrypoint.sh files for our GitHub actions. | ||
""" | ||
import argparse | ||
import sys | ||
from pathlib import Path | ||
|
||
|
||
TEMPLATE = """#!/usr/bin/env bash | ||
set -euo pipefail | ||
# AUTOGENERATED FILE, DO NOT EDIT! | ||
# This file has been generated by the `action-entrypoint-generator` script | ||
# defined in `scripts/action-entrypoint-generator`. To make changes to this | ||
# file, modify the script and rerun it. | ||
# GitHub overrides $HOME. Set it back to the home directory of our `app` user, | ||
# otherwise the call to `git config` fails. | ||
export HOME=/home/app | ||
# Mark the current directory as safe. If we don't do this, git commands fail | ||
# because the source in $PWD is owned by a different user than our `app` user. | ||
git config --global --add safe.directory "$PWD" | ||
@UPDATE_GGSHIELD@ | ||
args=("$@") | ||
@COMMAND@ | ||
""" | ||
|
||
# This script contains the code used by the unstable actions to update ggshield | ||
UPDATE_GGSHIELD_CODE = (Path(__file__).parent / "update-ggshield.sh").read_text() | ||
|
||
COMMAND_FOR_VERTICAL = { | ||
"secret": "ggshield secret scan -v ${args[@]} ci", | ||
"iac": "ggshield iac scan -v ${args[@]}", | ||
} | ||
|
||
DEFAULT_OUTPUT_DIR = Path(__file__).parent.parent.parent | ||
|
||
|
||
def generate(base_output_dir: Path, stable: bool, vertical: str): | ||
dct = { | ||
"UPDATE_GGSHIELD": "" if stable else UPDATE_GGSHIELD_CODE, | ||
"COMMAND": COMMAND_FOR_VERTICAL[vertical], | ||
} | ||
content = TEMPLATE | ||
for key, value in dct.items(): | ||
content = content.replace(f"@{key}@", value) | ||
|
||
output_dir = ( | ||
base_output_dir / ("actions" if stable else "actions-unstable") / vertical | ||
) | ||
output_dir.mkdir(exist_ok=True, parents=True) | ||
output_file = output_dir / "entrypoint.sh" | ||
print(f"Creating {output_file}") | ||
output_file.write_text(content) | ||
|
||
|
||
def main(): | ||
assert (DEFAULT_OUTPUT_DIR / "actions").exists() | ||
|
||
parser = argparse.ArgumentParser( | ||
formatter_class=argparse.RawDescriptionHelpFormatter, description=__doc__ | ||
) | ||
|
||
parser.add_argument( | ||
"-o", | ||
"--output", | ||
default=DEFAULT_OUTPUT_DIR, | ||
help="write actions to OUTPUT_DIR", | ||
metavar="OUTPUT_DIR", | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
output_dir = Path(args.output) | ||
assert output_dir.is_dir() | ||
for stable in False, True: | ||
for vertical in COMMAND_FOR_VERTICAL.keys(): | ||
generate(output_dir, stable=stable, vertical=vertical) | ||
|
||
return 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) |
Oops, something went wrong.