-
Notifications
You must be signed in to change notification settings - Fork 7
Added check for egress rule to allow traffic on all ports in MS NSG. #300
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
Changes from 2 commits
6f73111
01b7864
f306213
0a0664e
3553e25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -347,6 +347,52 @@ function check_udp_port_open_in_seclist_or_nsg() { | |
echo 1 | ||
fi | ||
} | ||
# Checks if there is an egress rule to ensure that the network can establish outbound communication to any destination, utilizing all available protocols and ports. | ||
Args: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest to use the same format for function comments used in other functions. |
||
# nsg_ocid: OCID for the nsg. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see the code expects two parameters:
|
||
# Returns: | ||
# 0|1 | ||
function check_egress_all_traffic_in_nsg() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see you renamed the function in your second commit, to remove the seclist part from the function, and leave nsg only, |
||
local seclist_or_nsg_ocid=$1 | ||
local ocid_type=$2 | ||
local icmp_protocol="1" | ||
local egress_is_open=false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this variable really needed? I see is declared here, and is set to true in line 383, and then the code returns in line 385. Si, this variable is never read. Unless I am missing something There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean, variable in line 359: |
||
local egress_rules_count=0 | ||
declare -A nsg_sec_list_array | ||
|
||
if [[ $ocid_type == "nsg" ]]; then | ||
egress_rules=$(oci network nsg rules list --nsg-id $seclist_or_nsg_ocid --direction EGRESS | jq -r '.data') | ||
else | ||
egress_rules=$(oci network security-list get --security-list-id $seclist_or_nsg_ocid | jq -r '.data["egress-security-rules"]') | ||
fi | ||
|
||
egress_rules_count=$(echo $egress_rules | jq '. | length') | ||
|
||
if [[ $egress_rules_count -gt 0 ]]; then | ||
for ((j = 0; j < egress_rules_count; j++)); do | ||
egress_protocol=$(echo $egress_rules | jq -r --arg i "$j" '.[$i|tonumber].protocol') | ||
egress_destination=$(echo $egress_rules | jq -r --arg i "$j" '.[$i|tonumber].destination') | ||
egress_destination_type=$(echo $egress_rules | jq -r --arg i "$j" '.[$i|tonumber]."destination-type"') | ||
|
||
if [[ $egress_destination_type != "CIDR_BLOCK" ]]; then | ||
nsg_sec_list_array[$j]="WARNING: Source type is either NSG or Service. Skipping the validation check for ${egress_destination}." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be destination type or target type (I do not know the correct names) instead of source type? we are checking they type of egress destination type |
||
continue | ||
fi | ||
|
||
if [[ $egress_destination == "0.0.0.0/0" && ( $egress_protocol == "all" || $egress_protocol == $icmp_protocol ) ]]; then | ||
egress_is_open=true | ||
echo 0 | ||
return | ||
fi | ||
done | ||
fi | ||
|
||
if [[ ${#nsg_sec_list_array[@]} != 0 ]]; then | ||
echo "${nsg_sec_list_array[@]}" | ||
else | ||
echo 1 | ||
fi | ||
} | ||
|
||
|
||
#################################################### | ||
|
@@ -852,7 +898,16 @@ fi | |
if [[ -n ${WLS_SUBNET_OCID} && -n ${ADMIN_SRV_NSG_OCID} && -n ${MANAGED_SRV_NSG_OCID} ]] | ||
then | ||
wls_subnet_cidr_block=$(oci network subnet get --subnet-id ${WLS_SUBNET_OCID} | jq -r '.data["cidr-block"]') | ||
|
||
# Check if egress rule to allow traffic on all ports in Managed Server NSG. | ||
res=$(check_egress_all_traffic_in_nsg ${MANAGED_SRV_NSG_OCID} "nsg") | ||
if [[ $res == *"WARNING"* ]]; then | ||
for warning in "${res[@]}"; do | ||
echo "$warning" | ||
done | ||
elif [[ $res -ne 0 ]]; then | ||
echo "ERROR: Missing egress rule to allow traffic on all ports in Managed Server NSG [$MANAGED_SRV_NSG_OCID]. ${NETWORK_VALIDATION_MSG}" | ||
validation_return_code=2 | ||
fi | ||
# Check if SSH port is open for access by WLS subnet CIDR in Admin Server NSG | ||
res=$(check_tcp_port_open_in_seclist_or_nsg $MANAGED_SRV_NSG_OCID "${SSH_PORT}" "$wls_subnet_cidr_block" "nsg") | ||
if [[ $res == *"WARNING"* ]] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The copyright header needs to change to
Copyright (c) 2023, 2025, Oracle and/or its affiliates.