diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..3e262ed --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,6 @@ +repos: + - repo: https://github.com/ibm/detect-secrets + rev: 0.13.1+ibm.62.dss + hooks: + - id: detect-secrets # pragma: whitelist secret + args: [--baseline, .secrets.baseline, --use-all-plugins, --fail-on-unaudited] \ No newline at end of file diff --git a/.secrets.baseline b/.secrets.baseline new file mode 100644 index 0000000..fafda2d --- /dev/null +++ b/.secrets.baseline @@ -0,0 +1,84 @@ +{ + "exclude": { + "files": "^.secrets.baseline$", + "lines": null + }, + "plugins_used": [ + { + "name": "AWSKeyDetector" + }, + { + "name": "ArtifactoryDetector" + }, + { + "name": "AzureStorageKeyDetector" + }, + { + "base64_limit": 4.5, + "name": "Base64HighEntropyString" + }, + { + "name": "BasicAuthDetector" + }, + { + "name": "BoxDetector" + }, + { + "name": "CloudantDetector" + }, + { + "ghe_instance": "github.ibm.com", + "name": "GheDetector" + }, + { + "name": "GitHubTokenDetector" + }, + { + "hex_limit": 3, + "name": "HexHighEntropyString" + }, + { + "name": "IbmCloudIamDetector" + }, + { + "name": "IbmCosHmacDetector" + }, + { + "name": "JwtTokenDetector" + }, + { + "keyword_exclude": null, + "name": "KeywordDetector" + }, + { + "name": "MailchimpDetector" + }, + { + "name": "NpmDetector" + }, + { + "name": "PrivateKeyDetector" + }, + { + "name": "SlackDetector" + }, + { + "name": "SoftlayerDetector" + }, + { + "name": "SquareOAuthDetector" + }, + { + "name": "StripeDetector" + }, + { + "name": "TwilioKeyDetector" + } + ], + "results": {}, + "version": "0.13.1+ibm.62.dss", + "word_list": { + "file": null, + "hash": null + } +} diff --git a/build-locally.sh b/build-locally.sh index 7409a87..cbaaf0c 100755 --- a/build-locally.sh +++ b/build-locally.sh @@ -118,6 +118,39 @@ CONSOLE_FLAG=--console=plain log_file=${LOGS_DIR}/${project}.txt info "Log will be placed at ${log_file}" +function check_exit_code () { + # This function takes 2 parameters in the form: + # $1 an integer value of the returned exit code + # $2 an error message to display if $1 is not equal to 0 + if [[ "$1" != "0" ]]; then + error "$2" + exit 1 + fi +} + +function check_secrets { + h2 "updating secrets baseline" + cd ${BASEDIR} + detect-secrets scan --update .secrets.baseline + rc=$? + check_exit_code $rc "Failed to run detect-secrets. Please check it is installed properly" + success "updated secrets file" + + h2 "running audit for secrets" + detect-secrets audit .secrets.baseline + rc=$? + check_exit_code $rc "Failed to audit detect-secrets." + + #Check all secrets have been audited + secrets=$(grep -c hashed_secret .secrets.baseline) + audits=$(grep -c is_secret .secrets.baseline) + if [[ "$secrets" != "$audits" ]]; then + error "Not all secrets found have been audited" + exit 1 + fi + sed -i '' '/[ ]*"generated_at": ".*",/d' .secrets.baseline + success "secrets audit complete" +} function build_gradle_plugin() { h1 "Building ${project}" @@ -158,4 +191,6 @@ function clean_up_m2 { clean_up_m2 -build_gradle_plugin \ No newline at end of file +build_gradle_plugin + +check_secrets \ No newline at end of file