Last active
October 7, 2021 22:30
-
-
Save jeremyje/df65eee6cff02419cd1552ae9a03f85d to your computer and use it in GitHub Desktop.
rdp
This file contains hidden or 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
| #!/bin/bash | |
| # curl -s -L -H 'Cache-Control: no-cache' https://gist.githubusercontent.com/jeremyje/df65eee6cff02419cd1552ae9a03f85d/raw/rdp.sh | bash -s PROJECT_ID_OPTIONAL NETWORK_NAME_OPTIONAL | |
| # Creates an allow firewall rule for your machine to access a Windows via RDP. | |
| # This firewall rule will only apply to VMs with the "rdp" network tag. | |
| # This script creates a firewall rule in the target project that accepts | |
| # port 3389 traffic. You may need to change this every so often as your IP | |
| # address changes. | |
| # | |
| # ./rdp.sh <PROJECT_ID> <NETWORK> | |
| PROJECT_ID=${1:-$(gcloud config get-value project)} | |
| NETWORK=${2:-default} | |
| # https://whatismyipaddress.com/api | |
| MY_IP_ADDRESS=$(curl ipv4bot.whatismyipaddress.com) | |
| MY_IP_UNDERSCORED=$(echo "${MY_IP_ADDRESS}" | tr . -) | |
| RDP_RULE_NAME="rdp-${NETWORK}-${MY_IP_UNDERSCORED}-all" | |
| NODEPORT_RULE_NAME="k8snp-${NETWORK}-${MY_IP_UNDERSCORED}-all" | |
| echo "Enabling RDP to ${MY_IP_ADDRESS} for ${PROJECT_ID} via ${RDP_RULE_NAME}" | |
| gcloud --project "${PROJECT_ID}" compute firewall-rules create \ | |
| "${RDP_RULE_NAME}" \ | |
| --allow=tcp:3389 \ | |
| --description="Allow RDP access from ${MY_IP_ADDRESS}" \ | |
| --direction=INGRESS \ | |
| --network="${NETWORK}" \ | |
| --source-ranges="${MY_IP_ADDRESS}/32" | |
| echo "Enabling NodePort access to ${MY_IP_ADDRESS} for ${PROJECT_ID} via ${NODEPORT_RULE_NAME}" | |
| gcloud --project "${PROJECT_ID}" compute firewall-rules create \ | |
| "${NODEPORT_RULE_NAME}" \ | |
| --allow=tcp:3000-32767 \ | |
| --description="Allow NodePort access to ${MY_IP_ADDRESS}" \ | |
| --direction=INGRESS \ | |
| --network="${NETWORK}" \ | |
| --source-ranges="${MY_IP_ADDRESS}/32" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment