Skip to content

allow proxy during SSH host key scan in FluxCD CLI#827

Open
adone wants to merge 3 commits into
fluxcd:mainfrom
adone:proxy-for-host-check
Open

allow proxy during SSH host key scan in FluxCD CLI#827
adone wants to merge 3 commits into
fluxcd:mainfrom
adone:proxy-for-host-check

Conversation

@adone

@adone adone commented Nov 27, 2024

Copy link
Copy Markdown

ssh.Dial uses net.DialTimeout under the hood src
and there is no possibility to use a proxy when running command like flux create source git --url ssh://git@example.com/repository.git (unlike for the source controller with ALL_PROXY)

so I replaced ssh.Dial with its almost full internal implementation
except net.DialTimeout replaced with proxy.Dial
like it is done in go-git

@adone
adone requested a review from a team as a code owner November 27, 2024 13:52
@adone
adone force-pushed the proxy-for-host-check branch from d0fe81e to 63c6588 Compare November 27, 2024 14:00

@makkes makkes left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm generally in favor of this change. What I can't judge right now is which Flux CLI commands are affected by this. I couldn't find any controller code affected by this.

It will be very important to document this change with respect to the affected commands.

Comment thread ssh/host_key.go Outdated
defer client.Close()
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
// support for ALL_PROXY ENV varaible

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// support for ALL_PROXY ENV varaible
// this reads the ALL_PROXY environment variable

@adone

adone commented Nov 27, 2024

Copy link
Copy Markdown
Author

I've tried to improve flux create source git, but flux bootstrap git with SSH protocol is affected too

as I understand another PR should be made to document ALL_PROXY variable support in CLI (with pkg version update also)

P.S. and tests for go-git's clone are broken, I'm trying to understand why

@adone

adone commented Nov 27, 2024

Copy link
Copy Markdown
Author

ah! ScanHostKey ignores any SSH/network errors if it manages to get host keys

@adone
adone force-pushed the proxy-for-host-check branch 2 times, most recently from 8c10c5e to ddb3fd8 Compare November 27, 2024 16:39
@gecube

gecube commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

I triaged fluxcd/flux2#4353 (full write-up here) and it leads straight to this PR, so a few data points that may help revive it.

What I can't judge right now is which Flux CLI commands are affected by this.

@makkes the enumeration (as of flux2 v2.9.2 — all of them funnel into sourcesecret.GenerateGitssh.ScanHostKey):

  • flux create source git with an ssh:// URL, unless --secret-ref/--export is given;
  • flux create secret git with an ssh:// URL — including with --export (generation happens before the export branch);
  • flux bootstrap github|gitlab|git|gitea|bitbucket-server over SSH; flux bootstrap git --private-key-file also hits a second call site in bootstrap_git.go when building the CLI's own clone auth.

Related issue reports of the same root cause: fluxcd/flux2#4353, fluxcd/flux2#2509, fluxcd/flux2#3430 (closed), discussion fluxcd/flux2#4414.

Validation: the branch no longer builds against the current modules (its ssh/go.mod pins pre-2025 deps), so I applied the host_key.go change onto ssh/v0.25.0 and built flux v2.9.2 with it. Behind a SOCKS5-only network path (sshd resolvable/reachable only through the proxy): scan with ALL_PROXY=socks5://… succeeds and pins the correct host key; without ALL_PROXY direct connections behave exactly as before. Since go-git already honors ALL_PROXY for the SSH transport, this makes flux bootstrap git over SSH work end-to-end behind a SOCKS5 proxy.

@adone are you still interested in finishing this? If not, I'm happy to submit a rebased version with a regression test, plus the flux2 docs PR documenting ALL_PROXY support for the affected commands.

@adone

adone commented Jul 17, 2026

Copy link
Copy Markdown
Author

hi @gecube
my own original issue was resolved in a different way

honestly I would like to have a contribution to the project
so I will try to revive this PR on this weekend
if I fail you can take the opportunity

@gecube

gecube commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Hi @adone,

Great, go for it — I'd much rather see you land it. Ping me if you need a review (at least I would be able to invest some efforts in testing stage)

One thing though: I'm still curious how your original issue got resolved. Even a short write-up would be useful for anyone else hitting the same thing.

@adone
adone force-pushed the proxy-for-host-check branch from 2be5563 to 2b6f6e8 Compare July 19, 2026 17:43
@adone

adone commented Jul 19, 2026

Copy link
Copy Markdown
Author

I've added a test but it uses a little dirty trick to update cached ENV variables in x/net/proxy package
if you have any better ideas please point to right direction

adone added 3 commits July 22, 2026 17:36
ssh.Dial uses net.DialTimeout under the hood
and there is no possibility to use a proxy
when running command like `flux create source git`

so we use almost all internal implementation of ssh.Dial
except net.DialTimeout is replaced with proxy.Dial
like it is done in go-git

Signed-off-by: Artem Nistratov <nistratov.artem@gmail.com>
previously ScanHostKey ignored any SSH/network errors
in case it managed to get host keys

to make it more obvious we imitate `ssh.Dial` with `sshDial` func

Signed-off-by: Artem Nistratov <nistratov.artem@gmail.com>
Signed-off-by: Artem Nistratov <nistratov.artem@gmail.com>
@adone
adone force-pushed the proxy-for-host-check branch from 2b6f6e8 to c912c45 Compare July 22, 2026 14:36
Comment thread ssh/go.mod
go 1.26.0

require (
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can not take on this dependency which is abandoned for 10+ years.

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.

4 participants