Skip to content

zedUpload/sftp: accept a scheme-qualified host as well as bare host:port - #90

Merged
eriknordmark merged 1 commit into
lf-edge:mainfrom
milan-zededa:sftp-scheme
Aug 7, 2026
Merged

zedUpload/sftp: accept a scheme-qualified host as well as bare host:port#90
eriknordmark merged 1 commit into
lf-edge:mainfrom
milan-zededa:sftp-scheme

Conversation

@milan-zededa

@milan-zededa milan-zededa commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

getSftpClient assumed host was always a bare host:port and extracted the hostname for its pre-flight DNS check via a naive strings.Split(host, ":"), taking the first element. Since lf-edge/eve#5588, EVE's datastore Fqdn is required to be always scheme-qualified for every datastore type, including SFTP (e.g. sftp://host:port), which broke that assumption: the first element became the literal scheme sftp instead of the real host, causing the SFTP download to fail with:

sftpclient failed for sftp://my-server:22: lookup sftp on 127.0.0.1:53: no such host

(i.e. trying to resolve sftp instead of my-server)

Detect which form was given via url.Parse: a real scheme-qualified authority-form URL parses with a non-empty Host, whereas a bare host:port also "succeeds" but only as an opaque URI (empty Host, with the part before the port's colon landing in Scheme/Opaque instead). Use u.Host when present, and fall back to the original bare host:port otherwise, so existing callers outside EVE are unaffected.

Also replaces the naive colon-split used for the hostname-only DNS pre-check with net.SplitHostPort, which additionally fixes handling of a bracketed IPv6 literal (e.g. [::1]:22) in both forms.

In EVE, this is exercised by newly added TestSFTPDatastore.

@milan-zededa
milan-zededa requested a review from rouming as a code owner August 6, 2026 07:46
@milan-zededa milan-zededa added the bug Something isn't working label Aug 6, 2026
@eriknordmark

Copy link
Copy Markdown
Contributor

Test failure fixed in #91

@eriknordmark eriknordmark left a comment

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.

Please rebase once #91 is merged to we can see CI green.

getSftpClient assumed host was always a bare "host:port" and extracted the
hostname for its pre-flight DNS check via a naive strings.Split(host, ":"),
taking the first element. Since lf-edge/eve#5588,
EVE's datastore Fqdn is always scheme-qualified for every datastore type,
including SFTP (e.g. "sftp://host:port"), which broke that assumption: the
first element became the literal scheme "sftp" instead of the real host,
causing the SFTP download to fail with:

sftpclient failed for sftp://244.244.244.244:22: lookup sftp on 127.0.0.1:53: no such host

(i.e. trying to resolve "sftp")

Detect which form was given via url.Parse: a real scheme-qualified
authority-form URL parses with a non-empty Host, whereas a bare host:port
also "succeeds" but only as an opaque URI (empty Host, with the part
before the port's colon landing in Scheme/Opaque instead). Use u.Host when
present, and fall back to the original bare host:port otherwise, so
existing callers outside EVE are unaffected.

Also replaces the naive colon-split used for the hostname-only DNS
pre-check with net.SplitHostPort, which additionally fixes handling of a
bracketed IPv6 literal (e.g. "[::1]:22") in both forms.

Signed-off-by: Milan Lenco <milan@zededa.com>

@eriknordmark eriknordmark left a comment

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.

Thanks

@eriknordmark
eriknordmark merged commit 882c841 into lf-edge:main Aug 7, 2026
5 checks passed
milan-zededa added a commit to milan-zededa/eve that referenced this pull request Aug 14, 2026
Update eve-libs to include lf-edge/eve-libs#90, which fixes the SFTP
datastore's getSftpClient to accept a scheme-qualified host
(sftp://host:port) as well as the bare host:port form. Since EVE
requires datastore Fqdn to always be scheme-qualified, SFTP downloads
were failing with a DNS lookup on the literal "sftp" scheme instead of
the real hostname.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Signed-off-by: Milan Lenco <milan@zededa.com>
eriknordmark pushed a commit to lf-edge/eve that referenced this pull request Aug 14, 2026
Update eve-libs to include lf-edge/eve-libs#90, which fixes the SFTP
datastore's getSftpClient to accept a scheme-qualified host
(sftp://host:port) as well as the bare host:port form. Since EVE
requires datastore Fqdn to always be scheme-qualified, SFTP downloads
were failing with a DNS lookup on the literal "sftp" scheme instead of
the real hostname.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Signed-off-by: Milan Lenco <milan@zededa.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants