Skip to content
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

US51939: Added malware scan workflow #67

Merged
merged 5 commits into from
Jun 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/malware-scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# (C) Copyright 2023 Hewlett Packard Enterprise Development LP

name: Malware Scan
on:
pull_request:
push:
branches:
- main
- master

jobs:
scan_repository:
name: "Scan Virus on Repository"
runs-on: "ubuntu-latest"
permissions:
id-token: write
contents: read
steps:
- name: "Checkout Repository"
uses: "actions/[email protected]"
with:
fetch-depth: 0
- name: "Scan Source for Viruses"
id: scan
run: |
SHA_SHORT=$(git rev-parse --short HEAD)
SCAN_OUTPUT=/tmp/clamav-repository-results-${{ github.event.repository.name }}-${SHA_SHORT}-$(date +%s).txt
echo "scan_output=${SCAN_OUTPUT}" >> $GITHUB_OUTPUT
docker run --rm -v ${{ github.workspace }}:/scandir -v /tmp:/tmp -e SCAN_OUTPUT=${SCAN_OUTPUT} clamav/clamav:stable clamscan --infected --recursive --max-files=0 --max-filesize=0 --max-scansize=0 --max-recursion=1000 --max-dir-recursion=1000 /scandir | tee -a $SCAN_OUTPUT
INFECTED_FILES=$(grep ^Infected $SCAN_OUTPUT | awk '{print $NF}')
echo "infected_files=${INFECTED_FILES}" >> $GITHUB_OUTPUT
exit $INFECTED_FILES
- name: "Configure AWS Credentials"
if: always()
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: arn:aws:iam::522637239241:role/s3-avscan-upload
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these HPE AWS roles ? if yes, are we fine to put them in public repos.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes its HPE's AWS roles, I asked the same to the security guy who suggested. But not reply back. So, if they come back saying we shouldn't then we can keep in secrets. Or what do you suggest?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These repos are open to public and can be accessed by anyone. I do not recommend to expose any users to public repos. We are ideally exposing our AWS Account ID and then the roles. @reubenur-rahman do you have any suggestions here ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from Security team : This should be ok because our OIDC role and policy only allows to post the results to the bucket and even though public, a peer reviewed pull request would still be required; being public is all the mor reason to run the scan; I have approved the PR.

role-session-name: malware-scan-upload
aws-region: us-west-2
- name: "Upload Source Scan Results"
if: always()
run: aws s3 cp ${{ steps.scan.outputs.scan_output }} s3://glcs-cloud-security-dev-avscan.hpe-hcss.hpe.com/
- name: "Tag Scan Upload"
if: always()
run: |
GH_OWNER=${{ github.repository_owner }}
GH_REPO=${{ github.event.repository.name }}
INFECTED_FILES=${{ steps.scan.outputs.infected_files }}
OBJECT_KEY=`basename ${{ steps.scan.outputs.scan_output }}`
aws s3api put-object-tagging \
--bucket glcs-cloud-security-dev-avscan.hpe-hcss.hpe.com \
--key $OBJECT_KEY \
--tagging "{\"TagSet\": [{ \"Key\": \"github_owner\", \"Value\": \"$GH_OWNER\" },{ \"Key\": \"github_repository\", \"Value\": \"$GH_REPO\"},{\"Key\": \"infected_files\", \"Value\": \"$INFECTED_FILES\"}]}"