forked from mongodb-labs/drivers-evergreen-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DRIVERS-2987 Restrict access to Azure VMs (mongodb-labs#514)
* Remove default network security group rule. Default opens SSH and RDP to internet. * Create NSG rule with current IP * Add set-ssh-ip.sh to add current IP. Needed since Azure KMS task group may run scripts across multiple Evergreen hosts. * Add `-n` to ssh commands. Prevents reading from stdin. Fixes interaction when script is run with Evergreen `shell.exec`. `shell.exec` reads commands from stdin by default.
- Loading branch information
1 parent
0b9b05f
commit 000faf3
Showing
5 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env bash | ||
|
||
# set-ssh-ip.sh adds the current IP to an already-created VM. | ||
|
||
set -o errexit | ||
set -o pipefail | ||
set -o nounset | ||
|
||
# Get DRIVERS_TOOLS path. | ||
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}") | ||
. "$SCRIPT_DIR"/../../handle-paths.sh | ||
|
||
VARLIST=( | ||
AZUREKMS_RESOURCEGROUP | ||
AZUREKMS_VMNAME | ||
AZUREKMS_PRIVATEKEYPATH | ||
) | ||
|
||
# Ensure that all variables required to run the test are set, otherwise throw | ||
# an error. | ||
for VARNAME in "${VARLIST[@]}"; do | ||
[[ -z "${!VARNAME:-}" ]] && echo "ERROR: $VARNAME not set" && exit 1; | ||
done | ||
|
||
EXTERNAL_IP=$(curl -s http://whatismyip.akamai.com/) | ||
|
||
echo "Adding current IP ($EXTERNAL_IP) to Azure Virtual Machine ... begin" | ||
az network nsg rule update \ | ||
--name "$AZUREKMS_VMNAME-nsg-rule" \ | ||
--nsg-name "$AZUREKMS_VMNAME-nsg" \ | ||
--resource-group "$AZUREKMS_RESOURCEGROUP" \ | ||
--source-address-prefixes "$EXTERNAL_IP" > /dev/null | ||
|
||
IP=$(az vm show --show-details --resource-group "$AZUREKMS_RESOURCEGROUP" --name "$AZUREKMS_VMNAME" --query publicIps -o tsv) | ||
|
||
"$DRIVERS_TOOLS/.evergreen/retry-with-backoff.sh" ssh -n -o ConnectTimeout=10 -o StrictHostKeyChecking=no azureuser@"$IP" -i "$AZUREKMS_PRIVATEKEYPATH" "echo 'hi' > /dev/null" | ||
|
||
echo "Adding current IP ($EXTERNAL_IP) to Azure Virtual Machine ... end" |