Re: Connection-local login programs

Eshel Yaron <[email protected]> Wed, 25 Mar 2026 19:34:16 +0100
Newsgroups gmane.emacs.tramp
Message-ID <[email protected]>
Hi,

Michael Albinus <[email protected]> writes:

>> I have a use case that I couldn't find a clean solution for, and I'm
>> wondering if Tramp could provide a nicer way to handle it.
>>
>> In Kubed[0], we define a Tramp method called "kubedv2", which uses
>> kubectl to interact with Kubernetes workloads, somewhat similarly to the
>> "kubernetes" method from tramp-container.el.  Following a feature
>> request from a user, we want the "kubedv2" method to work in multi-hop
>> settings, in which the user uses Tramp to connect to some remote host,
>> say via ssh, and then from that remote host they invoke a Kubed command
>> that starts a two-hop Tramp connection using ssh for the first hop and
>> kubedv2 for the second.
>>
>> The difficulty is that on the remote host (the target of the ssh
>> connection), the user may need to specify a different kubectl executable
>> to use as the tramp-login-program.  Kubed lets you specify which kubectl
>> to use through a user option kubed-kubectl-program, and we always use
>> the connection-local value of that variable so users can configure
>> different kubectl to use on different hosts, but that doesn't naturally
>> extend to our Tramp method, because the tramp-login-program is always
>> taken from the specific value we put in tramp-methods when "defining"
>> the method.
>>
>> Is there a better (or just more officially supported) approach that you
>> would recommend?
>
> All parameters specified by tramp-methods can be overwritten by
> connection properties, see (info "(tramp) Predefined connection information")
>
> In your case, you could do (untested)
>
> (add-to-list 'tramp-connection-properties
>               (list "^/kubedv2:user@example\\.com:")
>                     "login-program" "/another/kubectl"))

Thanks.  I'm not sure it applies to my use case, but perhaps I'm missing
something:

IIUC, tramp-connection-properties lets users override the login-program
used for the first hop, whereas we need to allow the login-program of
the second hop to depend on the first.  Namely, considering a file name
such as "/ssh:[email protected]|kubedv2:...:/some/file", we want Tramp to
use the connection-local value of kubed-kubectl-program in
"/ssh:[email protected]:" as the login-program for the second hop.

So far I couldn't find a way to do that with
tramp-connection-properties, did I miss anything?

FWIW I tried:

  (add-to-list 'tramp-connection-properties
               (list "example.com.*kubedv2" "login-program" "/another/kubectl"))

This would be more cumbersome than reusing the connection-local value of
kubed-kubectl-program, but it would be a step in the right direction.
Unfortunately, that didn't seem to work, I think because the previous
hop isn't included in the string that is matched against the regexp.


Best,

Eshel