Skip to content

New cookbook: fb_ssh#58

Open
jaymzh wants to merge 1 commit intofacebook:mainfrom
jaymzh:fb_ssh
Open

New cookbook: fb_ssh#58
jaymzh wants to merge 1 commit intofacebook:mainfrom
jaymzh:fb_ssh

Conversation

@jaymzh
Copy link
Copy Markdown
Collaborator

@jaymzh jaymzh commented Aug 16, 2019

This is a cookbook to manage SSH using the FB attribute-driven model.

It handles daemon and client configs as well as authorized_keys and
authorized_principals.

There is something worth noting here: the API for public keys uses a data_bag.
Grocery delivery and taste-tester have long supported data_bags even though
FB doesn't use them in prod... but it doesn't matter since FB uses principals in prod
and not keys, so this shouldn't be an issue no matter what.

Here are all the steps to do, internally, to be able to import this.

  1. Copy all node.default['fb_ssh']... to also have a node.default['fb_ssh_old']...
  2. Add code handle reads, and code-replace it
  3. Copy fb_ssh to fb_ssh_old
  4. Fix roles and include_recipes to reference fb_ssh_old
  5. Delete references to fb_ssh
  6. Delete fb_ssh
  7. Import new fb_ssh

Comment thread cookbooks/fb_ssh/recipes/default.rb Outdated

module FB
class SSH
DESTDIR = {
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 think these should probably be configurable (not everybody will have/want the same paths).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I disagree... one of the things we've almost never done in fb cookbooks is make configuration paths configurable....

@jaymzh
Copy link
Copy Markdown
Collaborator Author

jaymzh commented Oct 3, 2019

rebased and addressed review comments

@jaymzh jaymzh force-pushed the fb_ssh branch 2 times, most recently from bb22af9 to 0356777 Compare October 4, 2019 17:43
@jaymzh jaymzh force-pushed the fb_ssh branch 2 times, most recently from 6402389 to eea046d Compare July 2, 2020 18:51
@jaymzh
Copy link
Copy Markdown
Collaborator Author

jaymzh commented Sep 19, 2020

Added windows support

@ericnorris
Copy link
Copy Markdown
Contributor

ericnorris commented Mar 2, 2022

Hey there @jaymzh (and @davide125)! Apologies for resurrecting this PR, but I wanted to a) point out what I think is a bug I found, and b) ask if there was any chance this could get merged, as we'd like to use it!

Regarding the bug, I believe that the current default of joining arrays by spaces does not work for the HostKey directive. Here is a snippet of my fb_ssh attributes:

node.default['fb_ssh']['sshd_config'] = {
  'HostKey' => [
    '/etc/ssh/ssh_host_rsa_key',
    '/etc/ssh/ssh_host_ecdsa_key',
    '/etc/ssh/ssh_host_ed25519_key',
  ],
  # ...
}

Using this results in the following error:

FATAL: Chef::Exceptions::ValidationFailed: template[/etc/ssh/sshd_config] (fb_ssh::default line 92) had an error: Chef::Exceptions::ValidationFailed: Proposed content for /etc/ssh/sshd_config failed verification /usr/sbin/sshd -t -f %{path}
STDOUT:
STDERR: /etc/ssh/.chef-sshd_config20220302-2453-dz99m0 line 6: garbage at end of line; "/etc/ssh/ssh_host_ecdsa_key".

I'm not familiar with openssh's codebase, but I believe this is because the HostKey option does not support whitespace-separated arguments. At the time of writing, here is an example of how openssh parses the AcceptEnvoption, which does allow whitespace-separated arguments:

https://github.com/openssh/openssh-portable/blob/379b30120da53d7c84aa8299c26b18c51c2a0dac/servconf.c#L2016

...and here is how it parses HostKey:

https://github.com/openssh/openssh-portable/blob/379b30120da53d7c84aa8299c26b18c51c2a0dac/servconf.c#L1431

If I understand correctly, it's only taking one argument at a time from the HostKey option, vs. parsing them all in the AcceptEnv option. I think that we currently want the default HostKey option, so we can remove the attribute for now, but it'd be nice if this worked.

Finally, regarding merging, at Etsy we've been exploring using Facebook-style cookbooks for freshening up our Chef configuration, and found it really pleasant so far! We'd like to be able to customize our sshd config this way as well, so merging this would allow us to rely on the upstream repo.

Thanks both!

@jaymzh
Copy link
Copy Markdown
Collaborator Author

jaymzh commented Mar 2, 2022

Hi @ericnorris - thanks for commenting.

The delay on merging this is because FB has an internal fb_ssh cookbook, so it's a migration for them, and resources on that team are currently a bit limited.

I'm happy to continue keeping this up-to-date in the PR though, and the Vicarious folks are already using it (I just left there, but I wrote it while I was there). FB will get to it, but it'll take some time. I'm hoping to update a bunch of my PRs that submit new cookbooks in the coming weeks now that I have a bit more time.

The HostKey is an interesting one. I think there are only two config keys that require multi-define - HostKey is one, ListenAddress is the other. Perhaps the best solution is to just hard-code those two cases... I can see no way to handle both cases the same and have them be parsed correctly by sshd.

@ericnorris
Copy link
Copy Markdown
Contributor

ericnorris commented Mar 2, 2022

Appreciate the fast response @jaymzh! Understood, we have a mechanism for pulling in your fork for a given cookbook (e.g. this and fb_sssd) at a specific commit, so we can keep using that for the time being.

Also appreciate you offering to keep it up to date! I agree, HostKey is interesting. I think your solution makes sense, and I'll add that I think another approach could be to always multi-define (e.g. even for AcceptEnv)? The config would be more verbose, though. I'm fine with either option.

Finally, I'd be curious to see if there's an fb_pamd cookbook that could make its way to this repository, but now I fear I'm asking too much :)

@davide125
Copy link
Copy Markdown
Member

If you'd like to contribute a cookbook to manage PAM, we should be able to merge it without issues. As @jaymzh mentioned, the main blocker to merging this one is refactoring our internal one and migrating off it.

@jaymzh
Copy link
Copy Markdown
Collaborator Author

jaymzh commented Mar 2, 2022

I don't think multi-defining works for anything else. For example AuthorizedKeysFile needs space-delimited options. Or consider AuthenticationMethods where you do space-delimited array of comma-delimited options! ;)

So I don't think there's a format that works for everything, unfortunately.

ericnorris added a commit to etsy/chef-cookbooks that referenced this pull request Jan 9, 2024
adsr pushed a commit to etsy/chef-cookbooks that referenced this pull request Jul 11, 2024
@jaymzh
Copy link
Copy Markdown
Collaborator Author

jaymzh commented Feb 6, 2025

I'm gonna get this updated here. I have a solution for the non-space-delimited things, but there's some systemd new stuff that's required to get in here... should have an update today or tomorrow.

@jaymzh jaymzh force-pushed the fb_ssh branch 2 times, most recently from 858bb6c to 2b91160 Compare February 6, 2025 02:58
@jaymzh
Copy link
Copy Markdown
Collaborator Author

jaymzh commented Feb 6, 2025

OK this update properly handles special non-space-delimited keys as well as handles config files that are included from packages.

@ericnorris - would love any feedback or testing.

This is a cookbook to manage SSH using the FB attribute-driven model.

It handles daemon and client configs as well as authorized_keys and
authorized_principals.

There are few things worth noting here: The API for public keys uses a
`data_bag`. Grocery delivery and taste-tester have long supported
data_bags even though FB doesn't use them in prod... but it doesn't
matter since FB uses principals in prod and not keys, so this shouldn't
be an issue no matter what.
kcronin added a commit to etsy/chef-cookbooks that referenced this pull request Mar 16, 2026
On Ubuntu 24.04, openssh 9.6p1 checks for the privilege separation
directory /run/sshd even in config-test (-t) mode. When the openssh
packages are upgraded during a Chef run, dpkg post-install scripts
restart sshd asynchronously via deb-systemd-invoke (bypassing
policy-rc.d), causing systemd to briefly remove /run/sshd (a
RuntimeDirectory) during the stop phase.

By the time Chef has run through the preceding resources (ruby_block,
confdir directory, key file resources), the stop phase has already
completed. Adding a directory resource here recreates /run/sshd so the
sshd_config template verify succeeds.

See: facebook#58

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants