diff --git a/Makefile b/Makefile index 0733b7dc..ba9e7d57 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ all: info docker test ## Run all targets. .PHONY: test -test: info validate-container-image-labels test-lib inspec lint-codebase test-default-config-files test-find lint-subset-files test-non-default-workdir test-git-flags test-linters ## Run the test suite +test: info validate-container-image-labels test-lib inspec lint-codebase test-default-config-files test-find lint-subset-files test-custom-ssl-cert test-non-default-workdir test-git-flags test-linters ## Run the test suite # if this session isn't interactive, then we don't want to allocate a # TTY, which would fail, but if it is interactive, we do want to attach @@ -259,6 +259,18 @@ test-default-config-files: ## Test default configuration files loading -v "$(CURDIR)/docs":/tmp/lint \ $(SUPER_LINTER_TEST_CONTAINER_URL) +.phony: test-custom-ssl-cert +test-custom-ssl-cert: ## Test the configuration of a custom SSL/TLS certificate + docker run \ + -e RUN_LOCAL=true \ + -e ACTIONS_RUNNER_DEBUG=true \ + -e ENABLE_GITHUB_ACTIONS_GROUP_TITLE=true \ + -e DEFAULT_BRANCH=main \ + -e USE_FIND_ALGORITHM=true \ + -e SSL_CERT_SECRET="$(shell cat test/data/ssl-certificate/rootCA-test.crt)" \ + -v "$(CURDIR)/docs":/tmp/lint \ + $(SUPER_LINTER_TEST_CONTAINER_URL) + .phony: test-linters test-linters: ## Run the linters test suite docker run \ diff --git a/lib/functions/setupSSH.sh b/lib/functions/setupSSH.sh index 28f7f69c..81e9609d 100755 --- a/lib/functions/setupSSH.sh +++ b/lib/functions/setupSSH.sh @@ -1,14 +1,5 @@ #!/usr/bin/env bash -################################################################################ -################################################################################ -########### Super-Linter linting Functions ##################################### -################################################################################ -################################################################################ -########################## FUNCTION CALLS BELOW ################################ -################################################################################ -################################################################################ -#### Function SetupSshAgent #################################################### function SetupSshAgent() { # Check to see if a SSH_KEY_SECRET was passed if [ -n "${SSH_KEY}" ]; then @@ -19,8 +10,7 @@ function SetupSshAgent() { ssh-add - <<<"${SSH_KEY}" 2>/dev/null fi } -################################################################################ -#### Function SetupGithubComSshKeys ############################################ + function SetupGithubComSshKeys() { if [[ -n "${SSH_KEY}" || "${SSH_SETUP_GITHUB}" == "true" ]]; then info "Adding github.com SSH keys" @@ -41,4 +31,3 @@ function SetupGithubComSshKeys() { fi fi } -################################################################################ diff --git a/lib/functions/updateSSL.sh b/lib/functions/updateSSL.sh index e43ef3be..b4d58272 100755 --- a/lib/functions/updateSSL.sh +++ b/lib/functions/updateSSL.sh @@ -1,79 +1,39 @@ #!/usr/bin/env bash -################################################################################ -################################################################################ -########### Super-Linter linting Functions @admiralawkbar ###################### -################################################################################ -################################################################################ -########################## FUNCTION CALLS BELOW ################################ -################################################################################ -################################################################################ -#### Function CheckSSLCert ##################################################### function CheckSSLCert() { if [ -z "${SSL_CERT_SECRET}" ]; then # No cert was passed - debug "User did not provide a SSL secret, moving on..." + debug "User did not provide a SSL_CERT_SECRET" else # User has provided a cert file to upload - debug "User passed SSL secret:[${SSL_CERT_SECRET}]" + debug "User configured a SSL_CERT_SECRET" InstallSSLCert fi } -################################################################################ -#### Function InstallSSLCert ################################################### + function InstallSSLCert() { - ############# - # Base Vars # - ############# + local CERT_FILE CERT_FILE='/tmp/cert.crt' + local CERT_ROOT CERT_ROOT='/usr/local/share/ca-certificates' + local FILE_NAME FILE_NAME=$(basename "${CERT_FILE}" 2>&1) - ######################### - # Echo secret into file # - ######################### echo "${SSL_CERT_SECRET}" >>"${CERT_FILE}" - ######################################## - # Put the cert in the correct location # - ######################################## - COPY_CMD=$(mv "${CERT_FILE}" "${CERT_ROOT}/${FILE_NAME}" 2>&1) - - ####################### - # Load the error code # - ####################### - ERROR_CODE=$? - - ############################## - # Check the shell for errors # - ############################## - if [ "${ERROR_CODE}" -ne 0 ]; then - error "ERROR! Failed to move cert into location!" - fatal "ERROR:[${COPY_CMD}]" - else - info "Moved cert into location, adding to trust store..." + local CERT_DESTINATION + CERT_DESTINATION="${CERT_ROOT}/${FILE_NAME}" + info "Moving certificate to ${CERT_DESTINATION}" + local COPY_CMD + if ! COPY_CMD=$(mv -v "${CERT_FILE}" "${CERT_DESTINATION}" 2>&1); then + fatal "Failed to move cert to ${CERT_DESTINATION}. Output: ${COPY_CMD}" fi + debug "Move certificate output: ${COPY_CMD}" - ############################################## - # Update ca-certificates to pull in the cert # - ############################################## - UPDATE_CMD=$(update-ca-certificates 2>&1) - - ####################### - # Load the error code # - ####################### - ERROR_CODE=$? - - ############################## - # Check the shell for errors # - ############################## - if [ "${ERROR_CODE}" -ne 0 ]; then - # ERROR - error "ERROR! Failed to add cert to trust store!" - fatal "ERROR:[${UPDATE_CMD}]" - else - # Success - info "Successfully added cert to trust store" + info "Update cert store to consider the new certificate" + local UPDATE_CMD + if ! UPDATE_CMD=$(update-ca-certificates 2>&1); then + fatal "Failed to add the certificate to the trust store. Output: ${UPDATE_CMD}" fi + debug "Cert store update output: ${UPDATE_CMD}" } -################################################################################ diff --git a/test/data/ssl-certificate/rootCA-test.crt b/test/data/ssl-certificate/rootCA-test.crt new file mode 100644 index 00000000..bcde9ba9 --- /dev/null +++ b/test/data/ssl-certificate/rootCA-test.crt @@ -0,0 +1,31 @@ +-----BEGIN CERTIFICATE----- +MIIFWTCCA0GgAwIBAgIUOC6jhUoFsZnjjBW2PprtWU42pSUwDQYJKoZIhvcNAQEL +BQAwOzEUMBIGA1UEAwwLZXhhbXBsZS5jb20xCzAJBgNVBAYTAlVTMRYwFAYDVQQH +DA1TYW4gRnJhbnNpc2NvMCAXDTI0MDExMjEzMzc0OFoYDzIxMjEwNzAyMTMzNzQ4 +WjA7MRQwEgYDVQQDDAtleGFtcGxlLmNvbTELMAkGA1UEBhMCVVMxFjAUBgNVBAcM +DVNhbiBGcmFuc2lzY28wggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDO +dOCh1uuHtwmrdfyhn+nZo+znIOVqMc6WTEfiSMjEzyu2aoRs6g33Ri+hA3eb7FJO +yMheG6m9b/kLawoEVrww0686+nr7d383jYRbuk56odh2B3oQ0w7m2s+YmQd6zY9Q +NV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