Page MenuHomePhabricator

Disable agent forwarding for Cloud VPS
Closed, ResolvedPublic

Description

Agent forwarding is considered harmful. In particular, labs hosts are to be considered untrusted, and WMF devs may (inadvertently) have prod keys in their agent when they log in to beta for a canary deploy.

https://wikitech.wikimedia.org/wiki/Production_shell_access uses -a in the ProxyCommand line in the suggested ssh configuration, but in my testing (which could be wrong) that just prevents the agent from being passed to the bastion; the destination host could still request an agent connection from the proxied source.

Even for trusted production hosts, the danger is that devs could ssh *from* production *to* labs or an external untrusted host, and thereby expose their production key.

I recommend using AllowAgentForwarding no in the /etc/ssh/sshd_config of the bastions and the typical deployment targets of WMF devs, to reduce the scope of user agent-forwarding errors. In particular, the deploy* hosts in prod and deployment-tin are the usual destination hosts for deployers, so those hosts should proactively disallow agent forwarding.

Event Timeline

Probably a good idea though I don't think anyone ever really minded for non-privileged users (i.e. people who can't do anything particularly sensitive in labs and certainly can't get into anything in prod). One thing that should be kept in mind is that while wikimedia can lock this down on the wikimedia server side, there's nothing preventing you from forwarding your prod key to random untrusted machines on the internet. Might be better to ensure that all privileged users at least know that they should never use -A to a host they do not fully trust, and that labs machines must be treated as untrustworthy.

Might be better to ensure that all privileged users at least know that they should never use -A to a host they do not fully trust, and that labs machines must be treated as untrustworthy.

Generally, one should set ForwardAgent no in their ~/.ssh/config

Relevant bits of mine:

ForwardAgent no

Host bastion.wmflabs.org tools-login.wmflabs.org
    User demon
    IdentityFile ~/.ssh/priv/wmflabs.org
    ProxyCommand none
    ControlMaster auto

Host *.eqiad.wmflabs *.codfw.wmflabs
    User demon
    IdentityFile ~/.ssh/priv/wmflabs.org
    ProxyCommand ssh -a -W %h:%p bastion.wmflabs.org
    StrictHostKeyChecking no
    UserKnownHostsFile /dev/null

Might be better to ensure that all privileged users at least know that they should never use -A to a host they do not fully trust, and that labs machines must be treated as untrustworthy.

Generally, one should set ForwardAgent no in their ~/.ssh/config

I don't think that actually prevents ssh -A from working.

Teaching to not use -A is good. Setting it in your ~/.ssh/config is useful in case it's not disabled system-wide by default :)

• Vvjjkkii renamed this task from Disable agent forwarding to important hosts to hbaaaaaaaa.Jul 1 2018, 1:03 AM
• Vvjjkkii triaged this task as High priority.
• Vvjjkkii updated the task description. (Show Details)
• Vvjjkkii removed a subscriber: Aklapper.
CommunityTechBot renamed this task from hbaaaaaaaa to Disable agent forwarding to important hosts.Jul 2 2018, 9:59 AM
CommunityTechBot raised the priority of this task from High to Needs Triage.
CommunityTechBot updated the task description. (Show Details)
CommunityTechBot added a subscriber: Aklapper.

Is there a technical reason to only do it selectively for a few WMCS hosts and not in general? Or in other words, is there any known component (like something in Toolforge or so) which is known to depend on agent forwarding being enabled?

Is there a technical reason to only do it selectively for a few WMCS hosts and not in general? Or in other words, is there any known component (like something in Toolforge or so) which is known to depend on agent forwarding being enabled?

Nope, nothing should require this anymore for quite awhile AFAIK. Heartily embrace disabling to surface workflows that do :). It does get trickier if effecting regular tenants but a policy documenting would hopefully suffice

Our guide for Windows users still uses agent forwarding:

https://wikitech.wikimedia.org/wiki/Help:Putty#Setting_up_your_session

So I think disabling this on WMCS bastions would break things for some of our users.

I certainly have no objection to disabling this throughout prod though.

fgiunchedi claimed this task.
fgiunchedi subscribed.

AFAICS we're disabling agent forwarding across the board (production and wmcs), resolving

No, it's still enabled in Cloud VPS.

@MoritzMuehlenhoff to see if I understand your most recent comment correctly, is production done and the remaining work is within WMCS only?

@MoritzMuehlenhoff to see if I understand your most recent comment correctly, is production done and the remaining work is within WMCS only?

That's correct, it has been disabled in production for long time, it's only enabled for cloud-vps at this point. I'll rename the task.

MoritzMuehlenhoff renamed this task from Disable agent forwarding to important hosts to Disable agent forwarding for Cloud VPS.Jan 5 2023, 2:00 PM

Change 875899 had a related patch set uploaded (by Majavah; author: Majavah):

[operations/puppet@production] hieradata: disable agent forwarding in eqiad1

https://gerrit.wikimedia.org/r/875899

Change #1189855 had a related patch set uploaded (by Muehlenhoff; author: Muehlenhoff):

[operations/puppet@production] Remove Hiera option disable agent forwarding

https://gerrit.wikimedia.org/r/1189855

Change #875899 merged by Majavah:

[operations/puppet@production] hieradata: disable agent forwarding in eqiad1

https://gerrit.wikimedia.org/r/875899

It seems to be disabled now. I can no loner clone my github repos (which I could in march).

Thanks, I followed the link, but I still don't understand what would be the best way to clone a git repo from within an potentially unsecure labs instance.

I still don't understand what would be the best way to clone a git repo from within an potentially unsecure labs instance.

make a new key for that instance, add as a deploy key. https://docs.github.com/en/authentication/connecting-to-github-with-ssh/managing-deploy-keys#deploy-keys

I still don't understand what would be the best way to clone a git repo from within an potentially unsecure labs instance.

make a new key for that instance, add as a deploy key. https://docs.github.com/en/authentication/connecting-to-github-with-ssh/managing-deploy-keys#deploy-keys

Thanks. I did that, it works. It still means that everyone with access to that machine can push to that repo (if I wouldn't use a password for the ssh-key). I would guess that having many private keys stored on labs instances makes them a valuable target for attackers. Thus I found the ssh agent forwarding approach more secure (if used correctly).

Thanks. I did that, it works. It still means that everyone with access to that machine can push to that repo (if I wouldn't use a password for the ssh-key). I would guess that having many private keys stored on labs instances makes them a valuable target for attackers. Thus I found the ssh agent forwarding approach more secure (if used correctly).

By forwarding your agent to a VM, you're giving anyone with enough access on that VM full access to the keys loaded to your agent. (Here's an example of how that can go wrong.) Using specifically restricted deploy keys located on the hosts themselves is a major security improvement over forwarding your personal keys in there.

Ok, maybe it's more secure not to write to git repos from the labs hosts.

Mentioned in SAL (#wikimedia-cloud) [2026-02-11T21:49:37Z] <taavi> remove hiera override still allowing ssh agent forwarding onto toolforge bastions T198138

One related question. How can I copy files from one instance to another? I wanted to generate ssh keys and add them to authorized keys on the other instance. However, the ssh config is changed to

AuthorizedKeysFile /etc/ssh/userkeys/%u /etc/ssh/userkeys/%u.d/cumin

Is that a good idea to add another file or change one of files mentioned there?

One related question. How can I copy files from one instance to another?

For automated shifting of files between VMs I recommend setting up an rsync server -- that allows for easy control of what can happen and where, unlike generic ssh keys which might result in priv escalation. There are puppet classes to assist with rsync server but it's also pretty easy to configure by hand.

One related question. How can I copy files from one instance to another?

For automated shifting of files between VMs I recommend setting up an rsync server -- that allows for easy control of what can happen and where, unlike generic ssh keys which might result in priv escalation. There are puppet classes to assist with rsync server but it's also pretty easy to configure by hand.

@Andrew thank you. That sounds doable, but a bit more complicated than a 1 off sync. Now, I am thinking of 3 options.

So unless you would advise against volume multiattach I would try that first as this would save space and reduce unnecessary coping of data

One related question. How can I copy files from one instance to another?

For automated shifting of files between VMs I recommend setting up an rsync server -- that allows for easy control of what can happen and where, unlike generic ssh keys which might result in priv escalation. There are puppet classes to assist with rsync server but it's also pretty easy to configure by hand.

@Andrew thank you. That sounds doable, but a bit more complicated than a 1 off sync. Now, I am thinking of 3 options.

So unless you would advise against volume multiattach I would try that first as this would save space and reduce unnecessary coping of data

multi-attach isn't supported in our cloud, so that's not an option. If it's really one-off you can just scp via your laptop or attach a cinder volume, copy files over, and then move the volume to the new VM.

@Physikerwelt Look up the man page description of scp -3.