From 9cfb9cc1124ada89dc5898cc7c8a3835fa4462a7 Mon Sep 17 00:00:00 2001 From: Niel Markwick Date: Fri, 13 Sep 2024 18:53:15 +0200 Subject: [PATCH] chore: docs --- terraform/README.md | 131 ++++++++++++++++++++++++++++++-------------- 1 file changed, 90 insertions(+), 41 deletions(-) diff --git a/terraform/README.md b/terraform/README.md index 82f5a2d6..43a75e94 100644 --- a/terraform/README.md +++ b/terraform/README.md @@ -1,19 +1,42 @@ # Terraform deployment -TODO write this up properly +This directory contains the terraform files required to deploy the +malware-scanner service on cloud run. + +The deployment is split into 4 stages: + +1. Set up the google cloud project environment and service configuration. +1. Use Terraform to set up the required service accounts and deploy required + infrastructure. +1. Launch cloud build to build the Docker image for the malware-scanner + service. +1. Use Terraform to deploy the malware-scanner service to cloud run, and + connect the service to the infrastructure created in stage 2. + +Follow the instructions below to use Terraform to deploy the malware scanner +service in a demo project. + +## Create a project and assign billing + +Using the Cloud Console, create a new Cloud project, and assign the billing +account. Take note of the Project ID of your new project. ## Clone repo +In Cloud shell, run the following to pull the malware-scanner source code from +GitHub. + ```bash git clone https://github.com/GoogleCloudPlatform/docker-clamav-malware-scanner.git cd docker-clamav-malware-scanner ``` -## Create a project and assign billing +## Initialize environment with service configuration -console blah blah blah +Run the following commands in Cloud Shell to setup your environment and specify +the parameters of your service for the Terraform deployment. -## Init environment +Replace `MY_PROJECT_ID` with the ID of your newly created Project. ```bash @@ -21,8 +44,6 @@ PROJECT_ID=MY_PROJECT_ID gcloud config set project $PROJECT_ID TF_VAR_project_id=$PROJECT_ID -TF_VAR_region=us-central1 -TF_VAR_bucket_location=us TF_VAR_config_json=$(cat < **Error:** Error creating Trigger: googleapi: Error 400: Invalid resource > state for "": Permission denied while using the Eventarc Service Agent. If you @@ -80,21 +141,11 @@ Note: if you get the error: > necessary permissions are propagated to the Service Agent. Otherwise, verify > that it has Eventarc Service Agent role. -Simply retry running `terraform apply -auto-approve` - -Last line of output should show: - -```text -Outputs: - -cloud_run_uri = "https://malware-scanner-xxxxxxx-xx.a.run.app" -``` - ## Test the service ### Get version info from cloud run -Use that URL in the following command: +You can query the malware-scanner service for the version information: ```bash MALWARE_SCANNER_URL="$(terraform output -raw cloud_run_uri)" @@ -102,8 +153,8 @@ curl -H "Authorization: Bearer $(gcloud auth print-identity-token)" \ "${MALWARE_SCANNER_URL}" ``` -Should output lines showing the versions of the malware scanner, ClamAV and the -current malware definition package database version/date. +This command will output lines showing the versions of the malware scanner, +ClamAV and the current malware definitions version/datem for example: ```text gcs-malware-scanner version 3.0.0 @@ -114,6 +165,10 @@ Service to scan GCS documents for the malware and move the analyzed documents to ### Create and scan a clean file and an simulated infected file +Run the following command to create 2 files in the unscanned bucket, a simple +`clean.txt` file and an `eicar-infected.txt` file containing a +[test string which simulates a virus](https://en.wikipedia.org/wiki/EICAR_test_file) + ```bash echo -e 'HELLO WORLD!' \ | gcloud storage cp - "gs://unscanned-${PROJECT_ID}/clean.txt" @@ -121,35 +176,29 @@ echo -e 'X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*' \ | gcloud storage cp - "gs://unscanned-${PROJECT_ID}/eicar-infected.txt" ``` -Check the unscanned bucket +Check contents of the unscanned bucket ```bash gcloud storage ls gs://unscanned-${PROJECT_ID}/ ``` -Should have no results (if the files still exist, recheck after a couple of -seconds) +This should return no results as the files will have been moved by the +malware-scanner. If the files still exist, re-run the command after a couple of +seconds. -Check the clean files bucket +Check contents of the clean files bucket ```bash gcloud storage ls gs://clean-${PROJECT_ID}/ ``` -should show - -```text -gs://clean-PROJECT_ID/clean.txt -``` +This should show that the clean.txt file has been moved to the clean bucket. -Check the quarantined bucket +Check contents of the quarantined bucket ```bash gcloud storage ls gs://quarantined-${PROJECT_ID}/ ``` -should show the infected file in quarantined bucket - -```text -gs://clean-PROJECT_ID/eicar-infected.txt -``` +This should show that the eicar-infected.txt file has been moved to the +quarantined bucket.