-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add cve-query step #5455
Open
jason1028kr
wants to merge
4
commits into
ccoa/2024-2025
Choose a base branch
from
jasonjung/test-query-0
base: ccoa/2024-2025
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: add cve-query step #5455
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,59 @@ | ||
#!/usr/bin/env bash | ||
set -uo pipefail | ||
|
||
CVE_REPORT_DIRNAME=/opt/azure/containers | ||
CVE_REPORT_PATH=${CVE_REPORT_DIRNAME}/cve-report.out | ||
|
||
UMSI_PRINCIPAL_ID=${1} | ||
UMSI_CLIENT_ID=${2} | ||
ACCOUNT_NAME=${3} | ||
KUSTO_ENDPOINT=${4} | ||
KUSTO_DATABASE=${5} | ||
KUSTO_TABLE=${6} | ||
COMMIT_HASH=${7} | ||
STORAGE_ACCOUNT_NAME=${8} | ||
CVE_REPORT_OUTPUT_NAME=${9} | ||
CVE_REPORT_CONTAINER_NAME=${10} | ||
AZURE_MSI_RESOURCE_STRING=${11} | ||
|
||
|
||
MODULE_NAME="vuln-to-kusto-vhd" | ||
GO_ARCH="amd64" | ||
|
||
# hardcoded for now | ||
LOOKBACK_HOURS=12h | ||
SEVERITY="HIGH" | ||
|
||
# redirect stderr for correct script failure detection | ||
{ | ||
sudo apt-get install -y ca-certificates curl apt-transport-https lsb-release gnupg | ||
curl -sL https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - | ||
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/azure-cli.list | ||
sudo apt-get update -y && sudo apt-get upgrade -y | ||
sudo apt-get install -y azure-cli | ||
} 2>&1 | ||
|
||
az login --identity --username $UMSI_PRINCIPAL_ID | ||
|
||
# pull vuln-to-kusto binary | ||
az storage blob download --auth-mode login --account-name ${ACCOUNT_NAME} -c vuln-to-kusto \ | ||
--name ${MODULE_VERSION}/${MODULE_NAME}_linux_${GO_ARCH} \ | ||
--file ./${MODULE_NAME} 2>&1 | ||
chmod a+x ${MODULE_NAME} | ||
|
||
./vuln-to-kusto-vhd query-report ${LOOKBACK_HOURS} ${COMMIT_HASH} \ | ||
--severity ${SEVERITY} \ | ||
--kusto-endpoint ${KUSTO_ENDPOINT} \ | ||
--kusto-database ${KUSTO_DATABASE} \ | ||
--kusto-table ${KUSTO_TABLE} \ | ||
--kusto-managed-identity-client-id=${UMSI_CLIENT_ID} > ${CVE_REPORT_PATH} | ||
|
||
if [[ $? -ne 0 ]] && [[ -f ${CVE_REPORT_PATH} ]]; then | ||
echo "vuln-to-kusto-vhd query-report cmd found CVEs" | ||
az login --identity --username $AZURE_MSI_RESOURCE_STRING | ||
az storage blob upload --file ${CVE_REPORT_PATH} \ | ||
--container-name ${CVE_REPORT_CONTAINER_NAME} \ | ||
--name ${CVE_REPORT_OUTPUT_NAME} \ | ||
--account-name ${STORAGE_ACCOUNT_NAME} \ | ||
--auth-mode login | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/bin/bash | ||
set -euxo pipefail | ||
|
||
QUERY_RESOURCE_PREFIX="cve-query" | ||
QUERY_VM_NAME="$QUERY_RESOURCE_PREFIX-vm-$(date +%s)-$RANDOM" | ||
RESOURCE_GROUP_NAME="$QUERY_RESOURCE_PREFIX-$(date +%s)-$RANDOM" | ||
|
||
QUERY_VM_USERNAME="azureuser" | ||
|
||
QUERY_SCRIPT_PATH="query-cve-vm.sh" | ||
|
||
set +x | ||
QUERY_VM_PASSWORD="QueryVM@$(date +%s)" | ||
set -x | ||
|
||
function cleanup() { | ||
echo "Deleting resource group ${RESOURCE_GROUP_NAME}" | ||
az group delete --name $RESOURCE_GROUP_NAME --yes --no-wait | ||
} | ||
trap cleanup EXIT | ||
|
||
az group create --name $RESOURCE_GROUP_NAME --location ${QUERY_VM_LOCATION} | ||
|
||
az vm create --resource-group $RESOURCE_GROUP_NAME \ | ||
--name $QUERY_VM_NAME \ | ||
--image $QUERY_VHD_IMAGE \ | ||
--admin-username $QUERY_VM_USERNAME \ | ||
--admin-password $QUERY_VM_PASSWORD \ | ||
--assign-identity "${UMSI_RESOURCE_ID}" | ||
|
||
FULL_PATH=$(realpath $0) | ||
CDIR=$(dirname $FULL_PATH) | ||
QUERY_SCRIPT_PATH="$CDIR/$QUERY_SCRIPT_PATH" | ||
|
||
# storage account specific variables | ||
|
||
# Use the domain name from the classic blob URL to get the storage account name. | ||
# If the CLASSIC_BLOB var is not set create a new var called BLOB_STORAGE_NAME in the pipeline. | ||
BLOB_URL_REGEX="^https:\/\/.+\.blob\.core\.windows\.net\/vhd(s)?$" | ||
if [[ $CLASSIC_BLOB =~ $BLOB_URL_REGEX ]]; then | ||
STORAGE_ACCOUNT_NAME=$(echo $CLASSIC_BLOB | sed -E 's|https://(.*)\.blob\.core\.windows\.net(:443)?/(.*)?|\1|') | ||
else | ||
# Used in the 'AKS Linux VHD Build - PR check-in gate' pipeline. | ||
if [ -z "$BLOB_STORAGE_NAME" ]; then | ||
echo "BLOB_STORAGE_NAME is not set, please either set the CLASSIC_BLOB var or create a new var BLOB_STORAGE_NAME in the pipeline." | ||
exit 1 | ||
fi | ||
STORAGE_ACCOUNT_NAME=${BLOB_STORAGE_NAME} | ||
fi | ||
|
||
# for scanning storage account/container upload access | ||
az vm identity assign -g $RESOURCE_GROUP_NAME --name $QUERY_VM_NAME --identities $AZURE_MSI_RESOURCE_STRING | ||
|
||
TIMESTAMP=$(date +%s%3N) | ||
CVE_REPORT_OUTPUT_NAME="cve-report-${BUILD_SOURCEVERSION}-${TIMESTAMP}.out" | ||
CVE_REPORT_CONTAINER_NAME="vhd-scans" | ||
|
||
ret=$(az vm run-command invoke \ | ||
--command-id RunShellScript \ | ||
--name $QUERY_VM_NAME \ | ||
--resource-group $RESOURCE_GROUP_NAME \ | ||
--scripts @$QUERY_SCRIPT_PATH\ | ||
--parameters "UMSI_PRINCIPAL_ID"=${UMSI_PRINCIPAL_ID} \ | ||
"UMSI_CLIENT_ID"=${UMSI_CLIENT_ID} \ | ||
"ACCOUNT_NAME"=${ACCOUNT_NAME} \ | ||
"KUSTO_ENDPOINT"=${KUSTO_ENDPOINT} \ | ||
"KUSTO_DATABASE"=${KUSTO_DATABASE} \ | ||
"KUSTO_TABLE"=${KUSTO_TABLE} \ | ||
"COMMIT_HASH"=${BUILD_SOURCEVERSION} \ | ||
"STORAGE_ACCOUNT_NAME"=${STORAGE_ACCOUNT_NAME} \ | ||
"CVE_REPORT_OUTPUT_NAME"=${CVE_REPORT_OUTPUT_NAME} \ | ||
"CVE_REPORT_CONTAINER_NAME"=${CVE_REPORT_CONTAINER_NAME} \ | ||
"AZURE_MSI_RESOURCE_STRING"=${AZURE_MSI_RESOURCE_STRING}) | ||
|
||
# check stderr for script errors | ||
errMsg=$(echo -e $(echo $ret | jq ".value[] | .message" | grep -oP '(?<=stderr]).*(?=\\n")')) | ||
if [[ $errMsg != '' ]]; then | ||
az storage blob download --account-name $STORAGE_ACCOUNT_NAME --container-name $CVE_REPORT_CONTAINER_NAME --name $CVE_REPORT_OUTPUT_NAME --file cve-report.out --auth-mode login | ||
az storage blob delete --account-name $STORAGE_ACCOUNT_NAME --container-name $CVE_REPORT_CONTAINER_NAME --name $CVE_REPORT_OUTPUT_NAME --auth-mode login | ||
exit 1 | ||
fi |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is coming from a variable group can you explicitly declare the group at the top of the yaml to minimize confusion?