Skip to content

fix: Improve confusing tunnel security messaging#246

Merged
muchzill4 merged 3 commits intoarm:mainfrom
muchzill4:chore/confusing-curl-messaging
Apr 29, 2026
Merged

fix: Improve confusing tunnel security messaging#246
muchzill4 merged 3 commits intoarm:mainfrom
muchzill4:chore/confusing-curl-messaging

Conversation

@muchzill4
Copy link
Copy Markdown
Contributor

Changes

  • Stop displaying curl failures in the logs, because failing curl is actually good in this case
  • Explain the purpose of the check
  • Make error/success messages more meaningful and potentially actionable

Signed-off-by: Bartek Mucha <bartosz.mucha@arm.com>
Signed-off-by: Bartek Mucha <bartosz.mucha@arm.com>
@muchzill4 muchzill4 requested a review from a team as a code owner April 27, 2026 16:15
Comment thread internal/ssh/ssh_tunnel.go Outdated
Comment on lines +124 to +128
cmd := exec.Command("curl", fmt.Sprintf("%s:%s", hostName, ct.Port), "--max-time", "1")
// curl failing is the success path here; suppress its output so a
// "Failed to connect" line doesn't appear in the deployment log.
cmd.Stdout = io.Discard
cmd.Stderr = io.Discard
Copy link
Copy Markdown
Contributor

@th3james th3james Apr 28, 2026

Choose a reason for hiding this comment

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

I think this is actually a regression because we're suppressing diagnostic information, but we're not validating that the error is the one we're expecting. According to the curl man page, we can actually use the status codes to be more targeted and only expect status code 7 - "Failed to connect to host". This means host resolution or malformed URLs would be errors.
https://linux.die.net/man/1/curl

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've suppressed the output, that is correct, however I'd refrain from calling it diagnostic information. For the end user this is meaningless. We could debug log what curl says instead.

But to clarify, I've not introduced a regression, this code was already broken, which is something I'm realising now. Curl will error when trying to poke a protocol it doesn't understand. In case of ssh forwarding it is simply TCP, and trying to curl the port I'm getting curl: (56) Recv failure: Connection reset by peer.

Now, I'm not sure if we can rely on status codes, because curl on windows is not what you think. Perhaps curl.exe behaves like curl with status codes. Will check when I get my hands on a windows box.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

so do you think we need to check the port security without using curl?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, I see your point. The registry uses HTTP, so I believe the curl test should work correctly if the registry is running (@yejseo01 should be able to confirm, she tested it). The next question becomes whether we should be testing pure TCP or coupling the check the registry running (probably just TCP?).

The thing I can't remember is why we're doing a curl test rather than using Go's networking libs - feels like it would be easier to guarantee the portability of that approach.

Let's integrate this PR with just the UX fixes and address the robustness separately.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes. As long as the registry is running the curl check should be fine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The thing I can't remember is why we're doing a curl test rather than using Go's networking libs - feels like it would be easier to guarantee the portability of that approach.

Depending on CGO_ENABLED it may or may not be able to lookup the host using the hostname. I learned that yesterday after trying to do a simple tcp dial in golang.

Yes. As long as the registry is running the curl check should be fine.

As far as I can tell, there's nothing in the code that guarantees registry running before this curl executes. The operations are ordered correctly, but we run registry in the background, so who knows if it's listening or not.
I've tried setting GatewayPorts yes on remote and was not able to make this check fail. 🤷

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm surprised that happened. I thought the ordered operations would be good enough for most of the check to be fine. did you make some sort of artificial delay to hit it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Can you share how you've been testing this? Perhaps I'm doing something wrong.

Co-authored-by: James Cox-Morton <Th3james@fastmail.fm>
Signed-off-by: Bartek Mucha <muchzill4@gmail.com>
@muchzill4 muchzill4 merged commit 7ef59f0 into arm:main Apr 29, 2026
5 checks passed
@muchzill4 muchzill4 deleted the chore/confusing-curl-messaging branch April 29, 2026 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants