-
Notifications
You must be signed in to change notification settings - Fork 166
Core key vault firewall should not be set to "Allow public access from all networks" #4260
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
Merged
jonnyry
merged 33 commits into
microsoft:main
from
nwsde:jr/upstream-main/93-close-keyvault-firewall
Feb 13, 2025
Merged
Changes from 6 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
e0753da
Core key vault firewall should not be set to "Allow public access fro…
jonnyry e33f235
Linting
jonnyry c9af674
Update core version
jonnyry 9f1ef68
Linting
jonnyry 1fefc9f
Linting
jonnyry 8af920d
Linting
jonnyry 8c24844
Simplified: Remove use of azure tags, make specific to key vault
jonnyry 357891f
Merge branch 'main' into jr/upstream-main/93-close-keyvault-firewall
jonnyry f6ed85a
Update core version
jonnyry dcb0b8f
Linting
jonnyry 135be76
Update to deal with scenario where TRE_ID is not available
jonnyry 4a1b8b8
Remove unused null provisioner from .terraform.lock.hcl
jonnyry d7ce398
Merge branch 'main' into jr/upstream-main/93-close-keyvault-firewall
jonnyry e9833c4
Merge branch 'main' into jr/upstream-main/93-close-keyvault-firewall
jonnyry 2fa2a95
Merge branch 'main' into jr/upstream-main/93-close-keyvault-firewall
jonnyry 56d91d1
Merge branch 'main' into jr/upstream-main/93-close-keyvault-firewall
jonnyry 6251320
Remove unused scripts: key_vault_list.sh & set_contributor_sp_secret…
jonnyry de97183
Refactor as per @marrobi
jonnyry bd786c4
Update letsencrypt.sh
jonnyry cc2551e
Update kv_add_network_exception.sh
jonnyry 417c195
Update kv_add_network_exception.sh
jonnyry dee1c14
Update kv_add_network_exception.sh
jonnyry 67c2b2a
Merge branch 'main' into jr/upstream-main/93-close-keyvault-firewall
jonnyry 73049a1
Merge branch 'main' into jr/upstream-main/93-close-keyvault-firewall
jonnyry 6dc3fe0
Update CHANGELOG.md
jonnyry df52d62
Simplify
jonnyry 3d8e6c1
Update letsencrypt.sh
jonnyry f480b32
Update kv_add_network_exception.sh
jonnyry 1aaffb2
Merge branch 'main' into jr/upstream-main/93-close-keyvault-firewall
jonnyry 97db895
Merge branch 'main' into jr/upstream-main/93-close-keyvault-firewall
jonnyry b94443a
Merge branch 'main' into jr/upstream-main/93-close-keyvault-firewall
jonnyry d65eaf4
Merge branch 'main' into jr/upstream-main/93-close-keyvault-firewall
jonnyry f2c8c96
Update version.txt
jonnyry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
marrobi marked this conversation as resolved.
Show resolved
Hide resolved
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
marrobi marked this conversation as resolved.
Show resolved
Hide resolved
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.11.16" | ||
__version__ = "0.11.17" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#!/bin/bash | ||
|
||
TRE_DEPLOYMENT_NETWORK_EXCEPTION_TAG="tre_deployment_network_exception" | ||
|
||
function main() { | ||
|
||
set -o errexit | ||
set -o pipefail | ||
|
||
|
||
# parse params/set up inputs | ||
# | ||
if [[ -z "$TRE_ID" ]]; then | ||
echo -e "Could not open deployment network exceptions: TRE_ID is not set\nExiting...\n" | ||
exit 1 | ||
fi | ||
|
||
local MY_IP="${PUBLIC_DEPLOYMENT_IP_ADDRESS:-}" | ||
|
||
if [[ -z "$MY_IP" ]]; then | ||
MY_IP=$(curl -s "ipecho.net/plain"; echo) | ||
fi | ||
|
||
local TRE_CORE_RG="rg-${TRE_ID}" | ||
|
||
|
||
# find resources that require network exceptions | ||
# | ||
echo -e "\nQuerying resources that require network exceptions adding for deployment..." | ||
|
||
if [[ -z "$(az group list --query "[?name=='$TRE_CORE_RG']" --output tsv)" ]]; then | ||
echo -e " Core resource group $TRE_CORE_RG not found\n" | ||
return 0 | ||
fi | ||
|
||
local AZ_IDS | ||
AZ_IDS=$(az resource list --resource-group "$TRE_CORE_RG" --query "[?tags.${TRE_DEPLOYMENT_NETWORK_EXCEPTION_TAG}=='true'].id" --output tsv) | ||
|
||
if [ -z "$AZ_IDS" ]; then | ||
echo -e " No resources found\n" | ||
return 0 | ||
fi | ||
|
||
|
||
# add network exceptions | ||
# | ||
local AZ_ID | ||
for AZ_ID in $AZ_IDS; do | ||
|
||
local RESOURCE_TYPE | ||
RESOURCE_TYPE=$(az resource show --ids "${AZ_ID}" --query 'type' --output tsv) | ||
|
||
if [ "$RESOURCE_TYPE" == "Microsoft.KeyVault/vaults" ]; then | ||
add_keyvault_network_exception "$AZ_ID" "$MY_IP" | ||
fi | ||
|
||
done | ||
|
||
echo "" | ||
|
||
} | ||
|
||
function add_keyvault_network_exception() { | ||
local AZ_ID="$1" | ||
local MY_IP="$2" | ||
|
||
local KV_NAME | ||
KV_NAME=$(basename "$AZ_ID") | ||
|
||
echo " Adding keyvault deployment network exception for $KV_NAME" | ||
|
||
az keyvault network-rule add --name "$KV_NAME" --ip-address "$MY_IP" --output none | ||
|
||
local ATTEMPT=1 | ||
local MAX_ATTEMPTS=10 | ||
|
||
while true; do | ||
|
||
if KV_OUTPUT=$(az keyvault secret list --vault-name "$KV_NAME" --query '[].name' --output tsv 2>&1); then | ||
echo " Keyvault $KV_NAME is now accessible" | ||
break | ||
fi | ||
|
||
if [ $ATTEMPT -eq $MAX_ATTEMPTS ]; then | ||
echo -e "Could not add deployment network exception for $KV_NAME" | ||
echo -e "Unable to access keyvault $KV_NAME after $ATTEMPT/$MAX_ATTEMPTS.\n" | ||
echo -e "$KV_OUTPUT\n" | ||
|
||
exit 1 | ||
fi | ||
|
||
echo " Unable to access keyvault $KV_NAME after $ATTEMPT/$MAX_ATTEMPTS. Waiting for network rules to take effect." | ||
sleep 5 | ||
((ATTEMPT++)) | ||
|
||
done | ||
|
||
} | ||
|
||
main "$@" |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/bin/bash | ||
|
||
TRE_DEPLOYMENT_NETWORK_EXCEPTION_TAG="tre_deployment_network_exception" | ||
|
||
function main() { | ||
|
||
set -o errexit | ||
set -o pipefail | ||
|
||
|
||
# parse params/set up inputs | ||
# | ||
if [[ -z "$TRE_ID" ]]; then | ||
echo -e "Could not close deployment network exceptions: TRE_ID is not set\nExiting...\n" | ||
exit 1 | ||
fi | ||
|
||
local MY_IP="${PUBLIC_DEPLOYMENT_IP_ADDRESS:-}" | ||
|
||
if [[ -z "$MY_IP" ]]; then | ||
MY_IP=$(curl -s "ipecho.net/plain"; echo) | ||
fi | ||
|
||
local TRE_CORE_RG="rg-${TRE_ID}" | ||
|
||
|
||
# find resources that require network exceptions | ||
# | ||
echo -e "\nQuerying resources that require network exceptions removing for deployment..." | ||
|
||
if [[ -z "$(az group list --query "[?name=='$TRE_CORE_RG']" --output tsv)" ]]; then | ||
echo -e " Core resource group $TRE_CORE_RG not found\n" | ||
return 0 | ||
fi | ||
|
||
local AZ_IDS | ||
AZ_IDS=$(az resource list --resource-group "$TRE_CORE_RG" --query "[?tags.${TRE_DEPLOYMENT_NETWORK_EXCEPTION_TAG}=='true'].id" --output tsv) | ||
|
||
if [ -z "$AZ_IDS" ]; then | ||
echo -e " No resources found\n" | ||
return 0 | ||
fi | ||
|
||
|
||
# remove network exceptions | ||
# | ||
local AZ_ID | ||
for AZ_ID in $AZ_IDS; do | ||
|
||
local RESOURCE_TYPE | ||
RESOURCE_TYPE=$(az resource show --ids "${AZ_ID}" --query 'type' --output tsv) | ||
|
||
if [ "$RESOURCE_TYPE" == "Microsoft.KeyVault/vaults" ]; then | ||
remove_keyvault_network_exception "$AZ_ID" "$MY_IP" | ||
fi | ||
|
||
done | ||
|
||
echo "" | ||
|
||
} | ||
|
||
function remove_keyvault_network_exception() { | ||
local AZ_ID="$1" | ||
local MY_IP="$2" | ||
|
||
local KV_NAME | ||
KV_NAME=$(basename "$AZ_ID") | ||
|
||
echo " Removing keyvault deployment network exception for $KV_NAME" | ||
|
||
az keyvault network-rule remove --name "$KV_NAME" --ip-address "$MY_IP" --output none | ||
} | ||
|
||
main "$@" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.