Skip to content
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

Added check for egress rule to allow traffic on all ports in MS NSG. #300

Open
wants to merge 2 commits into
base: development
Choose a base branch
from

Conversation

ManviGupta-prog
Copy link

No description provided.

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Jan 7, 2025
@ManviGupta-prog ManviGupta-prog changed the base branch from main to development January 9, 2025 07:18
Copy link

Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA).
The following contributors of this PR have not signed the OCA:

To sign the OCA, please create an Oracle account and sign the OCA in Oracle's Contributor Agreement Application.

When signing the OCA, please provide your GitHub username. After signing the OCA and getting an OCA approval from Oracle, this PR will be automatically updated.

If you are an Oracle employee, please make sure that you are a member of the main Oracle GitHub organization, and your membership in this organization is public.

@oracle-contributor-agreement oracle-contributor-agreement bot added OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. and removed OCA Verified All contributors have signed the Oracle Contributor Agreement. labels Jan 9, 2025
@ManviGupta-prog ManviGupta-prog force-pushed the topic_manvigup-JCS-14691 branch from 1c0ae26 to 6f73111 Compare January 9, 2025 09:09
@oracle-contributor-agreement oracle-contributor-agreement bot added OCA Verified All contributors have signed the Oracle Contributor Agreement. and removed OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. labels Jan 9, 2025
@telake
Copy link
Member

telake commented Jan 10, 2025

Can you explain how you tested check_egress_all_traffic_in_seclist_or_nsg() function? The reason I find this important is that if I look at this code submission only the "nsg" option would ever be passed to this function.

continue
fi

if [[ $egress_destination == "0.0.0.0/0" && ( $egress_protocol == "all" || $egress_protocol == "1" ) ]]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if the "1" was assigned to a descriptive variable. In other parts of the code a variable is defined for tcp_protocol="6". This tells a reader of the code that TCP is being looked for when $tcp_protocol is referenced. I am reading this and I have no clue what "1" protocol is.

Copy link
Member

@telake telake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You addressed my comments so I am approving.

@@ -347,6 +347,52 @@ function check_udp_port_open_in_seclist_or_nsg() {
echo 1
fi
}

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.

@@ -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:

Choose a reason for hiding this comment

The 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.
In addition to that, looks like this line does not begin with comment sign (#) . Doesn't this cause an error when the script is run?

@@ -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:
# nsg_ocid: OCID for the nsg.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the code expects two parameters:

  • seclist_or_nsg_ocid
  • ocid_type
    and here I see only one listed

local seclist_or_nsg_ocid=$1
local ocid_type=$2
local icmp_protocol="1"
local egress_is_open=false

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, variable in line 359:
local egress_is_open=false

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}."

Choose a reason for hiding this comment

The 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

Copy link
Member

@roberto-sanchez-herrera roberto-sanchez-herrera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes because I see one thing that makes me think the script might fail when run, the lack of comment in the header of the function

# nsg_ocid: OCID for the nsg.
# Returns:
# 0|1
function check_egress_all_traffic_in_nsg() {

Choose a reason for hiding this comment

The 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,
But I see the code still supports sect lists.
Why was this done? is this intended?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants