-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New cookbook: fb_ssh #58
Open
jaymzh
wants to merge
10
commits into
facebook:main
Choose a base branch
from
jaymzh:fb_ssh
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+572
−1
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
36302bd
New cookbook: fb_ssh
jaymzh 989a89f
fb_ssh: add verifier, fix principals bug
jaymzh 6d3c96e
add to init for testing
jaymzh b5fdd66
lint
jaymzh 135f24f
lint
jaymzh 28bf8a3
debug
jaymzh 6d2620f
fix centos6
jaymzh b28333f
fix sftp
jaymzh 43232bc
fixes
jaymzh 0fcfa34
add windows support
jaymzh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,7 @@ | |
'fb_screen', | ||
'fb_sdparm', | ||
'fb_securetty', | ||
'fb_ssh', | ||
'fb_storage', | ||
'fb_stunnel', | ||
'fb_sudo', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
fb_ssh Cookbook | ||
=============== | ||
Installs and configures openssh | ||
|
||
Requirements | ||
------------ | ||
|
||
Attributes | ||
---------- | ||
* node['fb_ssh']['manage_packages'] | ||
* node['fb_ssh']['sshd_config'][$CONFIG] | ||
* node['fb_ssh']['ssh_config'][$CONFIG] | ||
* node['fb_ssh']['enable_central_authorized_keys'] | ||
* node['fb_ssh']['authorized_keys_users'] | ||
* node['fb_ssh']['enable_central_authorized_principals'] | ||
* node['fb_ssh']['authorized_principals'][$USER][$KEYNAME] | ||
* node['fb_ssh']['authorized_principals_users'] | ||
|
||
Usage | ||
----- | ||
### Packages | ||
By default `fb_ssh` will install and keep updated both client and server | ||
packages for ssh. | ||
|
||
You can skip package management if you have local packages or otherwise need to | ||
do your own management by setting `manage_packages` to false. | ||
|
||
Given the many ways to manage packages on Windows, especially for SSH, | ||
we default `manage_packages` to false on Windows. | ||
|
||
### Server configuration (sshd_config) | ||
The `sshd_config` hash holds configs that go into `/etc/ssh/sshd_config`. In | ||
general each key can have one of three types, bool, string/ints, or array. | ||
|
||
Bools are translated into `yes`/`no` when emitted into the config file. These | ||
are straight-forward: | ||
|
||
```ruby | ||
node.default['fb_ssh']['sshd_config']['PubkeyAuthentication'] = true | ||
``` | ||
|
||
Becomes: | ||
|
||
```text | ||
PubkeyAuthentication yes | ||
``` | ||
|
||
Strings and ints are always treated like normal strings: | ||
|
||
```ruby | ||
node.default['fb_ssh']['sshd_config']['ClientAliveInterval'] = 0 | ||
node.default['fb_ssh']['sshd_config']['ForceCommand'] = '/bin/false' | ||
``` | ||
|
||
Becomes: | ||
|
||
```text | ||
ClientAliveInterval 0 | ||
ForceCommand /bin/false | ||
``` | ||
|
||
Arrays will be joined by spaces. It's worth noting that while this feature is | ||
here to make management easy, one could clearly take a multi-value value key | ||
and make it a string and it would work, but we support arrays to make modifying | ||
the value later in the runlist easier. For example: | ||
|
||
```ruby | ||
node.default['fb_ssh']['sshd_config']['AuthorizedKeysFile'] = [ | ||
'.ssh/authorized_keys', | ||
'.ssh/authorized_keys2', | ||
] | ||
``` | ||
|
||
Means later it's easy for someone to do: | ||
|
||
```ruby | ||
node.default['fb_ssh']['sshd_config']['AuthorizedKeysFile']. | ||
delete('.ssh/authorized_keys2') | ||
``` | ||
|
||
or: | ||
|
||
```ruby | ||
node.default['fb_ssh']['sshd_config']['AuthorizedKeysFile'] << | ||
'/etc/ssh/authorized_keys/%u' | ||
``` | ||
|
||
So be careful to be consistent about this. | ||
|
||
### Match Values | ||
All match rules in sshd must come at the end, because Match blocks take effect | ||
until the next match block, or the end of the file - indentation is irrelevant. | ||
|
||
You can use Match rules as normal. This cookbook will automatically move them | ||
to the end of the file and keep them in the order that the users specified | ||
them. | ||
|
||
This means that unlike the other keys which are sorted for easier diffing, | ||
these are not sorted. As such, changing the order of your cookbooks could | ||
change the order of your match statements, so be careful. | ||
|
||
Match statements are the exception to the datatype rule above - their value is | ||
a hash, and that hash is treated the same as the top-level sshd_config hash: | ||
|
||
```ruby | ||
node.default['fb_ssh']['sshd_config']['Match Address 1.2.3.4'] => { | ||
'PasswordAuthentication' => true, | ||
} | ||
``` | ||
|
||
#### Authorized Principals | ||
|
||
If you set `enable_central_authorized_principals` to true, then two things will | ||
happen: | ||
1. Your AuthorizedPrincipalsFile will be set to `/etc/ssh/authorized_princs/%u`, | ||
regardless of what you set it to | ||
2. The contents of `node['fb_ssh']['authorized_principals']` will be used | ||
to populate `/etc/ssh/authorized_princs/` with one file for each | ||
user. To limit which users are populated, simply populate the list | ||
`node['fb_ssh']['authorized_principals_users']`. The format of the | ||
`authorized_principals` attribute is: | ||
|
||
```ruby | ||
node.default['fb_ssh']['authorized_principals'][$USER] = ['one', 'two'] | ||
``` | ||
|
||
#### Authorized Keys | ||
|
||
These work similarly to Authorized Principals. If you set | ||
`enable_central_authorized_keys` to true, then two things will happen: | ||
1. Your AuthorizedKeysFile will be set to `/etc/ssh/authorized_keys/%u`, | ||
regardless of what you set it to | ||
2. The contents of the databag `fb_ssh_authorized_keys` | ||
will be used to populate `/etc/ssh/authorized_keys/` with key files for each | ||
user. To limit which keys go on a user, simply populate the list | ||
`node['fb_ssh']['authorized_keys_users']`. The format of the items | ||
in databag is: | ||
|
||
```ruby | ||
{ | ||
'id': $USER, | ||
'keyname1': $KEY1, | ||
'keyname2': $KEY2, | ||
... | ||
} | ||
``` | ||
|
||
There should be one item for each user, as many keys as you'd like may | ||
be in that item. | ||
|
||
Alternatively you can populate `node['fb_ssh']['authorized_keys'][$USER]`. | ||
Doing so should be done similarly to the databags and each key given a name: | ||
|
||
```ruby | ||
node.default['fb_ssh']['authorized_keys']['john']['key1'] = '...' | ||
``` | ||
|
||
Anything in the node overrides databags. | ||
|
||
*NOTE FOR WINDOWS USERS*: On Windows the keys are managed in the homedirectory, | ||
not in a central location. This is because usernames are often in the format of | ||
`domain\user`, which means that `%u` causes sshd to expand the path to | ||
`C:\ProgramData\ssh\authorized_keys\domain\\user`, which is an illegal filename | ||
you can never make. | ||
|
||
### Client config (ssh_config) | ||
The client config works the same as the server config, except the special-case | ||
is `Host` keys instead of `Match` keys. As an example: | ||
|
||
```ruby | ||
node.default['fb_ssh']['ssh_config']['ForwardAgent'] = true | ||
node.default['fb_ssh']['ssh_config']['Host *.cool.com'] = { | ||
'ForwardX11' => true, | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# | ||
# Copyright (c) 2019-present, Vicarious, Inc. | ||
# All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
sftp_path = value_for_platform_family( | ||
['rhel', 'fedora'] => '/usr/libexec/openssh/sftp-server', | ||
['debian'] => '/usr/lib/openssh/sftp-server', | ||
) | ||
|
||
# centos6 only supports 1... | ||
if node.centos6? | ||
auth_keys = '.ssh/authorized_keys' | ||
else | ||
auth_keys = [ | ||
'.ssh/authorized_keys', | ||
'.ssh/authorized_keys2', | ||
] | ||
end | ||
|
||
default['fb_ssh'] = { | ||
'enable_central_authorized_keys' => false, | ||
'manage_packages' => !node.windows?, | ||
'sshd_config' => { | ||
'PermitRootLogin' => false, | ||
'UsePAM' => true, | ||
'Subsystem sftp' => sftp_path, | ||
'AuthorizedKeysFile' => auth_keys, | ||
}, | ||
'authorized_keys' => {}, | ||
'authorized_keys_users' => [], | ||
'authorized_principals' => {}, | ||
'authorized_principals_users' => [], | ||
'ssh_config' => {}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# | ||
# Copyright (c) 2019-present, Vicarious, Inc. | ||
# All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
module FB | ||
class SSH | ||
def self.confdir(node) | ||
node.windows? ? 'C:/ProgramData/ssh' : '/etc/ssh' | ||
end | ||
|
||
DESTDIR = { | ||
'keys' => 'authorized_keys', | ||
'principals' => 'authorized_princs', | ||
}.freeze | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# | ||
# Copyright (c) 2019-present, Vicarious, Inc. | ||
# All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
name 'fb_ssh' | ||
maintainer 'Facebook' | ||
maintainer_email '[email protected]' | ||
license 'Apache-2.0' | ||
description 'Configures ssh and sshd including keys and principals' | ||
source_url 'https://github.com/facebook/chef-cookbooks/' | ||
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) | ||
# never EVER change this number, ever. | ||
version '0.1.0' | ||
supports 'centos' | ||
supports 'debian' | ||
supports 'ubuntu' | ||
supports 'windows' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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....