Skip to content

Commit 5adf782

Browse files
authored
Properly daemonize the csfle servers (#570)
1 parent 35d0592 commit 5adf782

File tree

3 files changed

+35
-34
lines changed

3 files changed

+35
-34
lines changed

.evergreen/config.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,20 @@ functions:
515515
- command: ec2.assume_role
516516
params:
517517
role_arn: ${aws_test_secrets_role}
518+
# Ensure that we can run setup and teardown commands in the foreground without hanging.
519+
- command: subprocess.exec
520+
type: test
521+
params:
522+
binary: bash
523+
include_expansions_in_env: [AWS_SECRET_ACCESS_KEY, AWS_ACCESS_KEY_ID, AWS_SESSION_TOKEN]
524+
args: [src/.evergreen/csfle/setup.sh]
525+
- command: subprocess.exec
526+
type: test
527+
params:
528+
binary: bash
529+
include_expansions_in_env: [AWS_SECRET_ACCESS_KEY, AWS_ACCESS_KEY_ID, AWS_SESSION_TOKEN]
530+
args: [src/.evergreen/csfle/teardown.sh]
531+
# Test setup and teardown for each supported version of Python.
518532
- command: subprocess.exec
519533
type: test
520534
params:

.evergreen/csfle/README.md

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,48 +29,25 @@ The following servers will be started:
2929
- KMS HTTP server with an expired cert on port 9000
3030
- KMS HTTP server with an "wrong host" cert on port 9001
3131
- KMS HTTP server with a correct cert on port 9002
32+
- KMS Failpoint Server on port 9003
3233
- Mock Azure IMDS server on port 8080
3334

3435
When finished, stop the servers by running:
3536

3637
```bash
37-
$DRIVERS_TOOLS/.evergreen/csfle/stop-servers.sh
38+
${DRIVERS_TOOLS}/.evergreen/csfle/teardown.sh
3839
```
3940

40-
If you are starting your CSFLE servers in a separate Evergreen function, it is recommended that you setup secrets
41-
and start the servers in the background, and then have a separate function that uses `await-servers.sh`
42-
in the foreground to wait for the servers to be ready. This will ensure the servers are not torn down
43-
between functions (or the function may stall and not finish because there are processes still running).
44-
If you are starting the servers in a step within the same function as your tests, you
45-
can just start the servers directly in a foreground step.
46-
47-
48-
4941
```yaml
5042
start-csfle-servers:
5143
- command: ec2.assume_role
5244
params:
5345
role_arn: ${aws_test_secrets_role}
5446
- command: subprocess.exec
5547
params:
56-
working_dir: src
57-
binary: bash
58-
include_expansions_in_env: ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN"]
59-
args: |
60-
${DRIVERS_TOOLS}/.evergreen/csfle/setup-secrets.sh
61-
- command: subprocess.exec
62-
params:
63-
working_dir: src
64-
binary: bash
65-
background: true
66-
args:
67-
- ${DRIVERS_TOOLS}/.evergreen/csfle/start-servers.sh
68-
- command: subprocess.exec
69-
params:
70-
working_dir: src
7148
binary: bash
72-
args:
73-
- ${DRIVERS_TOOLS}/.evergreen/csfle/await-servers.sh
49+
include_expansions_in_env: [AWS_SECRET_ACCESS_KEY, AWS_ACCESS_KEY_ID, AWS_SESSION_TOKEN]
50+
args: [${DRIVERS_TOOLS}/.evergreen/csfle/setup.sh]
7451
```
7552
7653
## Legacy Usage

.evergreen/csfle/start-servers.sh

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,50 +30,60 @@ done
3030
. ./activate-kmstlsvenv.sh
3131

3232
# The -u options forces the stdout and stderr streams to be unbuffered.
33-
# TMPDIR is required to avoid "AF_UNIX path too long" errors.
33+
COMMAND="python -u"
34+
if [ "$(uname -s)" != "Darwin" ]; then
35+
# On linux and windows host, we need to use nohup to daemonize the process
36+
# and prevent the task from hanging.
37+
# The macos hosts do not support nohup.
38+
COMMAND="nohup $COMMAND"
39+
fi
40+
41+
3442
echo "Starting KMIP Server..."
35-
TMPDIR="$(dirname "$DRIVERS_TOOLS")" python -u kms_kmip_server.py --ca_file $CSFLE_TLS_CA_FILE --cert_file $CSFLE_TLS_CERT_FILE --port 5698 > kms_kmip_server.log 2>&1 &
43+
# TMPDIR is required to avoid "AF_UNIX path too long" errors.
44+
TMPDIR="$(dirname "$DRIVERS_TOOLS")" $COMMAND kms_kmip_server.py --ca_file $CSFLE_TLS_CA_FILE --cert_file $CSFLE_TLS_CERT_FILE --port 5698 > kms_kmip_server.log 2>&1 &
3645
echo "$!" > kmip_pids.pid
3746
sleep 1
3847
cat kms_kmip_server.log
3948
echo "Starting KMIP Server...done."
4049

4150

4251
echo "Starting HTTP Server 1..."
43-
python -u kms_http_server.py --ca_file $CSFLE_TLS_CA_FILE --cert_file ../x509gen/expired.pem --port 9000 > http1.log 2>&1 &
52+
$COMMAND kms_http_server.py --ca_file $CSFLE_TLS_CA_FILE --cert_file ../x509gen/expired.pem --port 9000 > http1.log 2>&1 &
4453
echo "$!" >> kmip_pids.pid
4554
sleep 1
4655
cat http1.log
4756
echo "Starting HTTP Server 1...done."
4857

4958

5059
echo "Starting HTTP Server 2..."
51-
python -u kms_http_server.py --ca_file $CSFLE_TLS_CA_FILE --cert_file ../x509gen/wrong-host.pem --port 9001 > http2.log 2>&1 &
60+
$COMMAND kms_http_server.py --ca_file $CSFLE_TLS_CA_FILE --cert_file ../x509gen/wrong-host.pem --port 9001 > http2.log 2>&1 &
5261
echo "$!" >> kmip_pids.pid
5362
sleep 1
5463
cat http2.log
5564
echo "Starting HTTP Server 2...done."
5665

5766

5867
echo "Starting HTTP Server 3..."
59-
python -u kms_http_server.py --ca_file $CSFLE_TLS_CA_FILE --cert_file $CSFLE_TLS_CERT_FILE --port 9002 --require_client_cert > http3.log 2>&1 &
68+
$COMMAND kms_http_server.py --ca_file $CSFLE_TLS_CA_FILE --cert_file $CSFLE_TLS_CERT_FILE --port 9002 --require_client_cert > http3.log 2>&1 &
6069
echo "$!" >> kmip_pids.pid
6170
sleep 1
6271
cat http3.log
6372
echo "Starting HTTP Server 3...done."
6473

6574

6675
echo "Starting Failpoint Server..."
67-
python -u kms_failpoint_server.py --port 9003 > failpoint.log 2>&1 &
76+
$COMMAND kms_failpoint_server.py --port 9003 > failpoint.log 2>&1 &
6877
echo "$!" >> kmip_pids.pid
6978
echo "Starting Failpoint Server...done."
7079
sleep 1
7180

7281
echo "Starting Fake Azure IMDS..."
73-
python bottle.py fake_azure:imds > fake_azure.log 2>&1 &
82+
$COMMAND bottle.py fake_azure:imds > fake_azure.log 2>&1 &
7483
echo "$!" >> kmip_pids.pid
7584
sleep 1
7685
cat fake_azure.log
7786
echo "Starting Fake Azure IMDS...done."
7887

88+
# Wait for all of the servers to start.
7989
bash ./await-servers.sh

0 commit comments

Comments
 (0)