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

chore: correct port validation #7077

Merged
merged 2 commits into from May 14, 2024
Merged

chore: correct port validation #7077

merged 2 commits into from May 14, 2024

Conversation

vzhukovs
Copy link
Contributor

@vzhukovs vzhukovs commented May 3, 2024

What does this PR do?

The following changes request provides better port validation process for Run Images dialog.

Screenshot / video of UI

What issues does this PR fix or reference?

#6390

How to test this PR?

Try to create two different containers with same exposed port to check that new port is proposed in Run Image dialog and validation of input works proper.

  • Tests are covering the bug fix or the new feature

@vzhukovs vzhukovs self-assigned this May 3, 2024
@vzhukovs vzhukovs requested review from benoitf and a team as code owners May 3, 2024 12:44
@vzhukovs vzhukovs requested review from dgolovin, lstocchi and odockal and removed request for a team May 3, 2024 12:44
@vzhukovs vzhukovs force-pushed the pd#6390 branch 3 times, most recently from 68754d2 to 1cfcb44 Compare May 6, 2024 11:30
package.json Outdated
@@ -183,6 +183,7 @@
"getos": "^3.2.1",
"got": "^14.2.1",
"hpagent": "^1.2.0",
"is-elevated": "^4.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not a big fan of this library as it has no support, not been updated since Aug 11, 2021, it fetched two other library the is-admin and is-root which have the same problem.

The is-admin is running the following on windows fsutil dirty query C: and the is-root is simply checking the user uid..

I don't know what is our policy for adding packages cc @benoitf

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would not proceed with this library

Copy link
Collaborator

@benoitf benoitf May 6, 2024

Choose a reason for hiding this comment

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

I mean, the library is OK from maintenance POV as they're managed by sindresorhus so there is support

but I'm not sure why we would need that library, I mean, in which case people run Podman Desktop with admin privileges ?

I would not allow ports < 1024 in all cases (Windows, macOS or Linux)

also Podman Desktop could be run in admin mode but the gvproxy in user mode so it would fail anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would not allow ports < 1024 in all cases (Windows, macOS or Linux)

This simplifies the whole checks, will going to update the PR by removing this check.

I just rely on that scenario, that all ports, that are below 1024 by default requires administrative permissions to expose.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@vzhukovs yes but I think it's simpler/easier/more robust to not allow that anyway using Podman Desktop

thanks for updating the PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@benoitf new changes are in place

Copy link
Collaborator

@benoitf benoitf left a comment

Choose a reason for hiding this comment

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

I'm wondering why we need to have an object being returned that provides the value and an optional error message vs the method returning the value or throw an error ?

I mean, why we can't rely on catching an error vs returning an object ?

@vzhukovs
Copy link
Contributor Author

vzhukovs commented May 7, 2024

I'm wondering why we need to have an object being returned that provides the value and an optional error message vs the method returning the value or throw an error ?

I mean, why we can't rely on catching an error vs returning an object ?

Because, we will have situation, when the method will return true when port is available and false when some check was not passed and not caused by any exception, but here we have to know what was the reason for that. Also, then we can catch some system exception (like EACCESS or EADDRINUSE or some else) and we will have the situation, when this scenario will be the same as return false but on the client side we have to catch this exception.

It's just to simplify the processing the final checking result. Because when the port is not available, there should be a reason why. WDYT?

@deboer-tim
Copy link
Collaborator

I'd say the same thing as @benoitf: there doesn't seem to be a need for a new type to return both a boolean and a message: either the port is free and we need no message or it's not and we need a message. We don't need to expose any underlying errors directly - we can catch them and throw new Error('Port must be...') to give our own more useful messages where the code currently does.

@vzhukovs
Copy link
Contributor Author

vzhukovs commented May 9, 2024

@deboer-tim @axel7083 new changes are in place

Signed-off-by: Vladyslav Zhukovskyi <[email protected]>
Signed-off-by: Vladyslav Zhukovskyi <[email protected]>
if (isNaN(port) || port > 65535) {
throw new Error('The port must have an integer value within the range from 1025 to 65535.');
} else if (port < 1024) {
throw new Error('The port must be greater than 1024.');
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice having custom message 👍

Copy link
Contributor

@axel7083 axel7083 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@deboer-tim deboer-tim left a comment

Choose a reason for hiding this comment

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

Approved.

Side note: I wonder if we should use NumberInput here (in another PR), would block non-numerical entry and provide +/- for small changes.

@vzhukovs vzhukovs merged commit d1b138b into main May 14, 2024
8 checks passed
@vzhukovs vzhukovs deleted the pd#6390 branch May 14, 2024 08:43
@vzhukovs
Copy link
Contributor Author

Approved.

Side note: I wonder if we should use NumberInput here (in another PR), would block non-numerical entry and provide +/- for small changes.

Submitted an issue for this proposal: #7198

@podman-desktop-bot podman-desktop-bot added this to the 1.11.0 milestone May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Port validation in the Run Image Page is not properly validating the port value until port number has 4 digits
5 participants