Skip to content

Added a check to "osdctl network verify-egress" for public subnets supplied by user with --subnet-id#508

Merged
openshift-merge-bot[bot] merged 7 commits intoopenshift:masterfrom
aliceh:route
May 22, 2024
Merged

Added a check to "osdctl network verify-egress" for public subnets supplied by user with --subnet-id#508
openshift-merge-bot[bot] merged 7 commits intoopenshift:masterfrom
aliceh:route

Conversation

@aliceh
Copy link
Contributor

@aliceh aliceh commented Feb 6, 2024

In this commit, I added a check when a subnet is supplied by a user with --sibnet-id. In the code, I check whether a subnet is public with isSubnetPublic function that checks if there is an internet gateway attached to the subnet and whether the RouteTable for the subnet has a default route to 0.0.0.0/0.

@aliceh
Copy link
Contributor Author

aliceh commented Feb 6, 2024

/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 6, 2024
@openshift-ci openshift-ci bot requested review from mjlshen and sam-nguyen7 February 6, 2024 04:36
@aliceh aliceh changed the title Added a check for private subnets in non-privatelink clusters Added a check for subnets supplied by user with --subnet-id Feb 7, 2024
@aliceh
Copy link
Contributor Author

aliceh commented Feb 7, 2024

cancel /hold

@aliceh
Copy link
Contributor Author

aliceh commented Feb 7, 2024

/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 7, 2024
@aliceh aliceh changed the title Added a check for subnets supplied by user with --subnet-id Added a check to "osdctl network verify-egress" for public subnets supplied by user with --subnet-id Feb 10, 2024
}

// This function checks the gateway attached to the subnet and returns true if the subnet starts with igw- (for InternetGateway) and has a route to 0.0.0.0/0
func (e *EgressVerification) isSubnetPublic(ctx context.Context, subnetID string) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This code seems to be similar to https://github.com/openshift/osdctl/blob/master/cmd/cluster/cpd.go#L125

Can you pull out the common logic into a separate shared function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you show me an example where this has been done in osdctl or other repo?

Copy link
Contributor

Choose a reason for hiding this comment

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

I linked the other function above and that function and this function have most of the same code. I would recommend creating a third function, something called findRouteTableForSubnet and placing all the shared code there, then calling it within isSubnetPublic and the other fucntion I linked

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Where should I put this shared function? A new file in /pkg/utils ? Just want to make sure I understand what the ask is.

Copy link
Contributor Author

@aliceh aliceh Feb 15, 2024

Choose a reason for hiding this comment

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

I am thinking /pkg/utils/utils.go

Copy link
Contributor

Choose a reason for hiding this comment

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

The aws client used by verifier.go and cpd.go implement two separate, incompatible interfaces and a refactor is non-trivial. It would likely involve having the code in verifier.go create one of our AWS Client wrappers defined here instead of using the raw ec2.Client it does today.

@aliceh I'm happy to pair on this if you'd like, let me know!

Copy link
Contributor

Choose a reason for hiding this comment

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

I spent some time digging into this issue this morning and speaking with @mjlshen in this slack thread- I think the right path forward here is to leave this for now and have a future effort to clean up all of the functions in this interface such that they don't hide the context parameter. Then our wrapper interface will be directly compatible with base AWS clients while still allowing all of the helper functions we provide still.

Curious to hear other thoughts, as I think a refactor here would be a bit large for this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

All the better - I'm also perfectly happy deprecating the wrapper interface as a whole and directly using clients from the aws go sdk :)

@abyrne55
Copy link
Contributor

abyrne55 commented Apr 24, 2024

Ran into this while on-call today. Any chance we can get this merged soon? @aliceh
This would also be a great feature for CAD, as it's currently running the verifier on public subnets and providing incorrect service log suggestions as a result

@aliceh
Copy link
Contributor Author

aliceh commented Apr 24, 2024

I'll look at it today.

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 2, 2024
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 15, 2024
},
},
},
describeRouteTablesResp: &ec2.DescribeRouteTablesOutput{
Copy link
Contributor

Choose a reason for hiding this comment

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

I think a few other tests also need this describeRouteTablesResp property defined now so they can pass.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done✅

@typeid
Copy link
Member

typeid commented May 19, 2024

As an FYI, this is the CAD implementation: https://github.com/openshift/configuration-anomaly-detection/pull/276/files

@clcollins
Copy link
Member

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label May 22, 2024
@openshift-ci
Copy link
Contributor

openshift-ci bot commented May 22, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aliceh, clcollins

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 22, 2024
@openshift-ci
Copy link
Contributor

openshift-ci bot commented May 22, 2024

@aliceh: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@openshift-merge-bot openshift-merge-bot bot merged commit 69f4fb3 into openshift:master May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants