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

2429/single clamav #2718

Merged
merged 44 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
99531e7
removed clamav from being deployed unless in production. Pointed AV S…
Aug 14, 2023
43527f5
added network policy to connect to prod clamAV
Aug 23, 2023
58cf0d1
use prod clam av in cloudgov.py too
Aug 25, 2023
4a55e18
Merge branch 'develop' into 2429/single-clamav
Aug 25, 2023
8c98ce2
fixing 'f-string is missing placeholders' now that we are hardcoding …
Aug 25, 2023
dab98ab
removed quotes from add-network-policy command when interpolation not…
Aug 28, 2023
fd2d8a0
removed add-network-policy from deploy-backend.sh and added documenta…
Aug 29, 2023
9131789
add nginx router and manifest
raftmsohani Sep 6, 2023
648e3a5
Merge branch 'develop' into 2429/single-clamav
Sep 6, 2023
f5afac6
Merge branch '2429/single-clamav' of github.com:raft-tech/TANF-app in…
Sep 6, 2023
a32ead7
cleaned up
Sep 6, 2023
b55aa57
Update README for CLAMAV
raftmsohani Sep 11, 2023
d7a9bee
Merge branch '2429/single-clamav' of https://github.com/raft-tech/TAN…
raftmsohani Sep 11, 2023
b005aa0
updated README file with deployment commands
raftmsohani Sep 19, 2023
71d77d4
added network policy for backend to clamav router
raftmsohani Sep 19, 2023
35048bb
updated boundry diagram
raftmsohani Sep 19, 2023
d31f037
updated boundry diagram
raftmsohani Sep 19, 2023
8ea10f1
Removed AV_SCAN url from cloud.gov settings file
raftmsohani Sep 19, 2023
e14fd82
update setting environment variable
raftmsohani Sep 19, 2023
ca4c5f1
refactored circle ci for static clam av vars since only one server no…
Sep 19, 2023
73677dd
Merge branch '2429/single-clamav' of github.com:raft-tech/TANF-app in…
Sep 19, 2023
a2b5089
needs env_var_name, not string for login-cloud-dot-gov
Sep 20, 2023
38d8c0a
revert back to env_var_name type for downstream login_cloud_dot_gov c…
Sep 21, 2023
006d60d
added prod prefix back in
Sep 21, 2023
acf6814
Merge branch 'develop' into 2429/single-clamav
Sep 22, 2023
9b72df8
readd AV_SCAN_URL
Sep 22, 2023
ee6c265
changed the inline comment in common.py settings
raftmsohani Sep 24, 2023
d695c41
Merge branch '2429/single-clamav' of https://github.com/raft-tech/TAN…
raftmsohani Sep 24, 2023
3c6467e
README file rewrite
raftmsohani Sep 25, 2023
19ee517
added note
Sep 25, 2023
79c1f85
Merge branch '2429/single-clamav' of github.com:raft-tech/TANF-app in…
Sep 25, 2023
1f39173
Merge branch 'develop' into 2429/single-clamav
raftmsohani Sep 28, 2023
714bbc8
Merge branch 'develop' into 2429/single-clamav
raftmsohani Sep 28, 2023
16ab89f
readded clam av nginx router url to manifest and setting network poli…
Sep 29, 2023
9e2c437
updated for using backend to set ENV for ClamAV URL.
Sep 29, 2023
cc603c9
Merge branch 'develop' into 2429/single-clamav
raftmsohani Sep 29, 2023
6415c92
getting rid of spaces on empty last line of manifest
Sep 29, 2023
a1fb14d
Merge branch '2429/single-clamav' of github.com:raft-tech/TANF-app in…
Sep 29, 2023
1638950
Remove AV_SCAN_URL from deploy-backend
raftmsohani Oct 2, 2023
6193455
updated README for clarification for clam-av-nginx-router naming
Oct 11, 2023
92727a2
changed https to http for internal routing to clamav-nginx server
Oct 11, 2023
9c401ed
Merge branch 'develop' into 2429/single-clamav
Oct 11, 2023
3526604
moving setting vars for clamav server to above cf push
Oct 11, 2023
799affe
Merge branch 'develop' into 2429/single-clamav
andrew-jameson Oct 12, 2023
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
52 changes: 29 additions & 23 deletions .circleci/deployment/commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,40 @@
backend-appname: <<parameters.backend-appname>>
frontend-appname: <<parameters.frontend-appname>>
cf-space: <<parameters.cf-space>>
- deploy-clamav:
backend-appname: <<parameters.backend-appname>>
cf-org: <<parameters.cf-org>>
cf-space: <<parameters.cf-space>>
- deploy-frontend:
environment: <<parameters.environment>>
backend-appname: <<parameters.backend-appname>>
frontend-appname: <<parameters.frontend-appname>>
cf-space: <<parameters.cf-space>>

clamav-cloud-dot-gov:
parameters:
backend-appname:
default: tdp-backend
type: string
cf-password:
default: CF_PASSWORD_DEV
type: env_var_name
cf-org:
default: CF_ORG
type: env_var_name
cf-space:
default: tanf-dev
type: string
cf-username:
default: CF_USERNAME_DEV
type: env_var_name
steps:
- checkout
- sudo-check
- cf-check
- login-cloud-dot-gov:
cf-password: <<parameters.cf-password>>
cf-org: <<parameters.cf-org>>
cf-space: <<parameters.cf-space>>
cf-username: <<parameters.cf-username>>
- deploy-clamav

deploy-backend:
parameters:
backend-appname:
Expand All @@ -71,30 +95,12 @@
<<parameters.cf-space>>

deploy-clamav:
parameters:
backend-appname:
default: tdp-backend
type: string
cf-org:
default: CF_ORG
type: env_var_name
cf-space:
default: tanf-dev
type: string
steps:
- run:
name: Deploy ClamAV REST application
command: |
cf push clamav-rest -f tdrs-backend/manifest.clamav.yml \
--var cf-space=<<parameters.cf-space>> \
- run:
name: Enable internal route between backend and clamav-rest app
command: |
cf add-network-policy <<parameters.backend-appname>> clamav-rest \
-s <<parameters.cf-space>> \
-o ${<<parameters.cf-org>>} \
--protocol tcp \
--port 9000
--var cf-space=tanf-prod

deploy-frontend:
parameters:
Expand Down
9 changes: 9 additions & 0 deletions .circleci/deployment/jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,12 @@
cf-password: CF_PASSWORD_PROD
cf-space: tanf-prod
cf-username: CF_USERNAME_PROD
prod-deploy-clamav:
executor: docker-executor
working_directory: ~/tdp-deploy
steps:
- clamav-cloud-dot-gov:
backend-appname: tdp-backend-prod
cf-password: CF_PASSWORD_PROD
cf-space: tanf-prod
cf-username: CF_USERNAME_PROD
7 changes: 7 additions & 0 deletions .circleci/deployment/workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@
branches:
only:
- master
- prod-deploy-clamav:
requires:
- deploy-infrastructure-production
filters:
branches:
only:
- master
- make_erd: # from ../util folder
filters:
branches:
Expand Down
242 changes: 241 additions & 1 deletion docs/Security-Compliance/diagram.drawio

Large diffs are not rendered by default.

Binary file modified docs/Security-Compliance/diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/Technical-Documentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This directory contains system and architecture documentation including diagrams
- [buildpack-changelog.md](./buildpack-changelog.md) : A running log of updates to our Cloud.gov buildpacks in use.
- [circle-ci-audit-template.md](./circle-ci-audit-template.md) : This is a checklist document used during audits of our continuous intergration pipeline tool.
- [circle-ci.md](./circle-ci.md) : Overview of our CI/CD platform jobs.
- [clamav.md](./clamav.md) : How to access ClamAV from different apps/spaces.
- [cypress-integration-tests.md](./cypress-integration-tests.md) : Shows how we use Cypress to manage our end to end integration testing.
- [data-file-downloads.md](./data-file-downloads.md) : Provides an architecture-level view of data file storage and downloading.
- [django-admin-logging.md](./django-admin-logging.md) : Outlines sections of the Django Administrator Console and details what should be logged.
Expand Down
48 changes: 48 additions & 0 deletions docs/Technical-Documentation/clamav.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# CLAMAV

In order to have one CLAMAV instance, existing in prod, the Nginx router is created
for CLAMAV to forward the traffic from 'dev' and 'staging' spaces into
prod space, where the CLAMAV service exists.

## Deploy Nginx instance
To route the clamav traffic to clamav in prod, each space needs to have one instance of _Nginx Router_ which routes traffic to clamav.

In order to deploy the nginx router instance, change your directory to `tdrs-backend/clamav-router/` and run the following command while logged into the target space:


>`cf push {nginx_instance_name} -f manifest.yml --no-route`

, where _nginx_instance_name_ can be : _tdp-clamav-nginx_.

The instance name then will be set as an environment variable to redirect each instance traffic. This will deploy the nginx instance to the target environment.

## Further communication configurations

### Setup Individual Instances

First, set the environment variable __AV_SCAN_URL__ as follows:
```
Environment variable name: AV_SCAN_URL
Environment variable value: http://{nginx_instance}.apps.internal:9000/scan
```

### Add network policy from _{tdp-clamav-nginx}_ to clamav in prod
To enable traffic between the "__nginx instance__" and "__clamav instance in production__", we need to add the network policiy and route between the two:

>`cf add-network-policy {nginx_instance} "clamav-rest" -s "tanf-prod" --protocol tcp --port 9000`
e.g: `{nginx_instance_name} = tdp-clamav-nginx-dev`

### Add network policy from _{backend_instance}_ to _tdp-clamav-nginx_

>`cf add-network-policy {backend_instance} {nginx_instance} --protocol tcp --port 9000`

where e.g: `backend_instance = tdp-backend-develop`

### Add route for _tdp-clamav-nginx_

Note: Make sure to delete (if existing) routes that are not being used. In some rare cases, a mal-assigned network policy can interfere with outgoing traffic. As an example, a policy like
>`cf delete-route app.cloud.gov --hostname tdp-frontend-staging`

Add route:

>`cf map-route {nginx_instance} apps.internal --hostname {nginx_instance}`
11 changes: 11 additions & 0 deletions scripts/deploy-backend.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ update_backend()
# Add network policy to allow frontend to access backend
cf add-network-policy "$CGAPPNAME_FRONTEND" "$CGAPPNAME_BACKEND" --protocol tcp --port 8080

if ["$CF_SPACE" = "tanf-prod" ]; then
# Add network policy to allow backend to access tanf-prod services
cf add-network-policy "$CGAPPNAME_BACKEND" clamav-rest --protocol tcp --port 9000
cf set-env "$CGAPPNAME_BACKEND" AV_SCAN_URL "http://tanf-prod-clamav-rest.apps.internal:9000/scan"
else
cf add-network-policy "$CGAPPNAME_BACKEND" tdp-clamav-nginx-$env --protocol tcp --port 9000

# Add environment varilables for clamav
cf set-env "$CGAPPNAME_BACKEND" AV_SCAN_URL "https://tdp-clamav-nginx-$env.apps.internal:9000/scan"
Copy link

Choose a reason for hiding this comment

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

does this require a different nginx proxy in each environment?

Choose a reason for hiding this comment

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

Yes, we basically have two nginx proxy, one for dev and one for staging

Copy link

Choose a reason for hiding this comment

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

are those deployed in ci or manually via the instructions included in the readme?

fi

cd ..
}

Expand Down
9 changes: 9 additions & 0 deletions tdrs-backend/clamav-router/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 1
applications:
- name: tdp-clamav-nginx
buildpacks:
- https://github.com/cloudfoundry/nginx-buildpack.git#v1.2.6
memory: 32M
instances: 1
disk_quota: 64M
timeout: 180
20 changes: 20 additions & 0 deletions tdrs-backend/clamav-router/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
events { worker_connections 1024;
}

# This opens a route to clamav prod
http{
server {
listen {{port}};
location /scan {
proxy_pass http://tanf-prod-clamav-rest.apps.internal:9000/scan;
proxy_pass_request_headers on;
}
}
server {
listen 9000;
location /scan {
proxy_pass http://tanf-prod-clamav-rest.apps.internal:9000/scan;
proxy_pass_request_headers on;
}
}
}
2 changes: 1 addition & 1 deletion tdrs-backend/manifest.clamav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ applications:
env:
MAX_FILE_SIZE: 200M
routes:
- route: ((cf-space))-clamav-rest.apps.internal
- route: tanf-prod-clamav-rest.apps.internal
2 changes: 0 additions & 2 deletions tdrs-backend/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ applications:
disk_quota: 2G
docker:
image: ((docker-backend))
env:
AV_SCAN_URL: http://((cf-space))-clamav-rest.apps.internal:9000/scan
1 change: 0 additions & 1 deletion tdrs-backend/tdpservice/settings/cloudgov.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class CloudGov(Common):

cloudgov_space = cloudgov_app.get('space_name', 'tanf-dev')
cloudgov_space_suffix = cloudgov_space.strip('tanf-')
AV_SCAN_URL = f'http://tanf-{cloudgov_space_suffix}-clamav-rest.apps.internal:9000/scan'
cloudgov_name = cloudgov_app.get('name').split("-")[-1] # converting "tdp-backend-name" to just "name"
services_basename = cloudgov_name if (
cloudgov_name == "develop" and cloudgov_space_suffix == "staging"
Expand Down
2 changes: 1 addition & 1 deletion tdrs-backend/tdpservice/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ class Common(Configuration):
logger.debug("RAW_CLAMAV: " + str(RAW_CLAMAV))
CLAMAV_NEEDED = bool(strtobool(RAW_CLAMAV))

# The URL endpoint to send AV scan requests to (clamav-rest)
# The URL endpoint to send AV scan requests to (clamav-rest/clamav-nginx-proxy)
AV_SCAN_URL = os.getenv('AV_SCAN_URL')

# The factor used to determine how long to wait before retrying failed scans
Expand Down
Loading