Skip to content
This repository was archived by the owner on Nov 6, 2025. It is now read-only.

Commit e2eedd1

Browse files
authored
Merge pull request #1811 from 18F/tock-1792-cleanup-and-docs
Update deployment docs and lower New Relic log level
2 parents b7ed7c5 + 2e2be1e commit e2eedd1

File tree

3 files changed

+109
-17
lines changed

3 files changed

+109
-17
lines changed

docs/deployment-process.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ and production dependencies.
5151

5252
#### Cloud Foundry environment variables
5353

54-
In production, Tock requires a few different environment variables. These are
55-
updated using the [User Provided Service](#user-provided-service-ups) and
56-
configured in the `manifest-*.yaml`.
54+
In production, Tock requires a few different environment variables. These values are
55+
updated using the [User Provided Service](#user-provided-service-ups),
56+
configured in the `manifest-*.yaml`, or set manually during [egress proxy setup](egress.md).
5757

5858
| type | name | description |
5959
| ---- | -----| ----------- |
@@ -67,9 +67,14 @@ configured in the `manifest-*.yaml`.
6767
| **public** | `NEW_RELIC_ENV` | The application environment that appears in the New Relic interface. |
6868
| **public** | `NEW_RELIC_HOST` | The New Relic endpoint used to collect APM data from the Python agent. Per [New Relic documentation](https://docs.newrelic.com/docs/security/security-privacy/compliance/fedramp-compliant-endpoints/#apm-endpoints), the default endpoint will not ensure FedRAMP compliance. |
6969
| **public** | `NEW_RELIC_LOG` | Logging that New Relic should listen to: e.g. `stdout`. |
70+
| **egress** | `egress_proxy` | The URL of the egress proxy used to filter external network traffic. Set manually during egress proxy setup. |
71+
| **egress** | `http_proxy` | Set to the value of `egress_proxy`. Used to filter HTTP traffic. |
72+
| **egress** | `https_proxy` | Set to the value of `egress_proxy`. Used to filter HTTPS traffic. |
73+
| **egress** | `NEW_RELIC_PROXY_HOST` | Set to the value of `egress_proxy`. Specifies the proxy URL for the New Relic Python agent and admin tool. |
7074

7175
Variables with the designation **secret** are stored in the `tock-credentials` User-Provided Service (UPS).
7276
**Public** variables are stored in the environment's `manifest-*.yml` file.
77+
Variables marked **egress** are set based on manual configuration during [egress proxy setup](egress.md).
7378

7479
### Services
7580

docs/egress.md

Lines changed: 100 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,94 @@ Accordingly, we have configured [a Caddy proxy](https://github.com/GSA-TTS/cg-eg
1010

1111
- `uaa.fr.cloud.gov`: The [cloud.gov UAA server](https://cloud.gov/docs/management/leveraging-authentication/) which in turn uses GSA SecureAuth for authentication.
1212
- `google-analytics.com`: [DAP](https://digital.gov/guides/dap/), for web app analytics
13-
- `api.newrelic.com`: [New Relic endpoints](https://docs.newrelic.com/docs/apis/rest-api-v2/get-started/introduction-new-relic-rest-api-v2/) which is used for the `newrelic-admin` tool
13+
- `api.newrelic.com`: The [New Relic REST API endpoint](https://docs.newrelic.com/docs/apis/rest-api-v2/get-started/introduction-new-relic-rest-api-v2/) which is used by the `newrelic-admin` tool to record deployments
14+
- `gov-collector.newrelic.com`: The FedRAMP-compliant [New Relic APM collector endpoint](https://docs.newrelic.com/docs/security/security-privacy/compliance/fedramp-compliant-endpoints/#agents), used by the New Relic Python agent
1415

1516
## A note about cloud.gov egress and spaces
1617

1718
cloud.gov allows configuration of [egress traffic controls](https://cloud.gov/docs/management/space-egress/) on a per-space basis _only_. Also, different network security groups are required for the proxy and application. This is why a separate space is required for the proxy.
1819

1920
## Tock staging setup
2021

21-
### Create the egress proxy
22+
Updating Tock's egress proxy settings is a rarely performed, highly manual process that requires rebuilding the proxy configuration in a local development environment. If possible, seek an administrator of this repo to pair with you as you make changes.
2223

23-
To create a new proxy, we largely follow the [cf-egress-proxy README](https://github.com/GSA-TTS/cg-egress-proxy).
24+
The following instructions use the staging egress proxy as an example.
2425

25-
As an example, to set up egress for Tock staging:
26+
### Clone the proxy application repo
27+
28+
Pull the current version of the Caddy proxy application from [GSA-TTS/cf-egress-proxy](https://github.com/GSA-TTS/cg-egress-proxy). Refer to its documentation for more information about local development.
29+
30+
#### First-time setup
31+
32+
If you have not previously cloned the repo, do so:
33+
```bash
34+
git clone git@github.com:GSA-TTS/cg-egress-proxy.git
35+
```
36+
37+
#### Updating an existing repo
38+
39+
If you have previously cloned the repo, ensure you are working from the current version with git:
40+
41+
1. Stash or delete any local changes
42+
2. Check out the `main` branch
43+
3. Pull the `main` branch from upstream
44+
45+
### Log in with the Cloud Foundry CLI tool
2646

27-
Create a new cloud.gov space
2847
```bash
2948
cf login -a api.fr.cloud.gov --sso
49+
```
50+
51+
### Create a new egress proxy (if needed)
52+
53+
If you are setting up a new egress proxy from scratch, create a new cloud.gov space:
54+
```bash
3055
cf create-space staging-egress -o gsa-18f-tock
3156
```
3257

33-
Clone the egress proxy from [GSA-TTS/cf-egress-proxy](https://github.com/GSA-TTS/cg-egress-proxy). Refer to its documentation for more information about local development.
58+
### Target the staging-egress CF space
59+
3460
```bash
35-
git clone git@github.com:GSA-TTS/cg-egress-proxy.git
61+
cf target -s staging-egress
62+
```
63+
64+
### Configure the `tock.vars.yml` file for the proxy
65+
66+
Copy these files from from your local `tock` repo into your `cf-egress-proxy` repo:
67+
68+
1. [tock.vars.yml](../egress_proxy/tock.vars.yml)
69+
2. [manifest.yml](../egress_proxy/manifest.yml)
70+
71+
#### Set username and password
72+
73+
In your `cf-egress-proxy` repo, manually set the `username` and `password` values in `tock.vars.yml`.
74+
75+
##### When creating a new proxy
76+
77+
Use the `uuidgen` command to create a new, random username and password. Paste each into the vars file for the appropriate key.
78+
79+
##### When updating an existing proxy
80+
81+
Retrieve the existing proxy username and password from the deployed egress proxy application:
82+
83+
```bash
84+
cf env staging-egress | grep PROXY_USERNAME
3685
```
3786

38-
Copy over [vars.tock.yml](../egress_proxy/tock.vars.yml) and configure it for your application. Use `uuidgen` for the username and password. Also copy over the [manifest.yml](../egress_proxy/manifest.yml). Finally, push the egress application to your space.
87+
Paste each value into the vars file for the appropriate key.
88+
89+
#### Deploy the egress proxy application
90+
91+
Push the egress proxy application to your space.
3992

4093
```bash
4194
cf target -s staging-egress
4295
cf push --vars-file tock.vars.yml
4396
```
4497

45-
SSH into the proxy to make sure that it is running and restricting URLs as advertised.
98+
### Validate the proxy
99+
100+
SSH into the proxy application's container to make sure that it is running and restricting URLs as advertised.
46101

47102
```bash
48103
cf ssh staging-egress -t -c "/tmp/lifecycle/launcher /home/vcap/app /bin/bash 0"
@@ -58,31 +113,63 @@ $ curl https://google-analytics.com
58113
> (html response)
59114
```
60115

61-
Once that looks good, you will need to set the proxy environment variable on Tock staging. Use the proxy path from the egress space.
116+
### Configure Tock application to use the egress proxy
117+
118+
Once the egress proxy looks good, you will need to set the proxy environment variable on Tock staging.
119+
Use the proxy path from the egress space.
62120

63121
```bash
64122
cf target -s tock-staging
65123

66124
# enable tock staging to talk to the egress server
67125
cf add-network-policy tock-staging staging-egress -s staging-egress --protocol tcp --port 61443
68126

69-
# provide an environment variable with the egress_proxy path
127+
# set an environment variable with the egress_proxy path
70128
cf set-env tock-staging egress_proxy https://<username>:<password>@<egress-host>.apps.internal:61443
71129

72130
# restage the application so it can use the variable
73131
cf restage tock-staging
74132
```
75133

134+
### Validate Tock configuration
135+
76136
SSH into the Tock staging space and confirm with `curl` that traffic out is being vetted by staging-egress.
77137

78-
__Note:__ The [../.profile](.profile file) (see the [relevant documentation](https://docs.cloudfoundry.org/devguide/deploy-apps/deploy-app.html#profile)) is configured to export the environmental variables `http_proxy` and `https_proxy` to whatever `egress_proxy` is set to. This allows us to update cloud.gov buildpacks and build the application itself without the proxy active. In other words, the proxy is only active once the application has booted up.
138+
```bash
139+
cf ssh tock-staging -t -c "/tmp/lifecycle/launcher /home/vcap/app /bin/bash 0"
140+
141+
# from the tock-staging terminal
142+
143+
# test that it is blocking egress appropriately
144+
$ curl https://18f.gsa.gov
145+
> curl: (56) Received HTTP code 403 from proxy after CONNECT
146+
147+
# test that it is allowing egress appropriately
148+
$ curl https://google-analytics.com
149+
> (html response)
150+
```
151+
152+
### Troubleshooting
79153

80-
If you need to troubleshoot, you may want to start with the logs:
154+
To troubleshoot end-to-end traffic, you may want to start with the egress proxy logs:
81155

82156
```bash
83157
cf logs staging-egress --recent
84158
```
85159

160+
If network calls from the Tock application are reaching the egress proxy, you should see log lines from the proxy indicating whether the calls were allowed or denied.
161+
162+
If a call from the Tock application is behaving unexpectedly (i.e. failing when it should be allowed, or succeeding when it should be denied):
163+
164+
* If the proxy logs show that the proxy is processing the call, double-check the `proxyallow` and `proxydeny` settings in [tock.vars.yml](../egress_proxy/tock.vars.yml).
165+
* If the proxy log doesn't contain any record of the call, double-check the URL in the `egress_proxy` environment variable and the network policy for the Tock application.
166+
167+
## A note on proxy URL environment variables
168+
169+
The [.profile file](../.profile) (see the [relevant documentation](https://docs.cloudfoundry.org/devguide/deploy-apps/deploy-app.html#profile)) is configured to export the environmental variables `http_proxy` and `https_proxy` to whatever `egress_proxy` is set to. This allows us to update cloud.gov buildpacks and build the application itself without the proxy active. In other words, the proxy is only active once the application has booted up.
170+
171+
It additionally exports a `NEW_RELIC_PROXY_HOST` variable set to the value of `egress_proxy`. This variable is required by the New Relic Python agent and `newrelic-admin` tool.
172+
86173
## A note on SSL certificates
87174

88175
The Python [certifi](https://pypi.org/project/certifi/) library does _not_ pick up on system-wide certificate authority files automatically. Instead, we have configured manifest files to explicitly set the environment variable `REQUESTS_CA_BUNDLE` so that Python libraries, including `certifi`, will use these certificates. If we do not, then all connections to the proxy are considered untrusted (cloud.gov specific certificates are in `/etc/cf-system-certificates` and replicated to `/etc/ssl/certs/ca-certificates.crt`).

newrelic.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ log_file = /tmp/newrelic-python-agent.log
6161
# of information very quickly, so it is best not to keep the
6262
# agent at this level for longer than it takes to reproduce the
6363
# problem you are experiencing.
64-
log_level = debug
64+
log_level = info
6565

6666
# The Python Agent communicates with the New Relic service using
6767
# SSL by default. Note that this does result in an increase in

0 commit comments

Comments
 (0)