-
-
Notifications
You must be signed in to change notification settings - Fork 483
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
openssh: init module #1172
Merged
Merged
openssh: init module #1172
Changes from all commits
Commits
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
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,33 @@ | ||
{ config, lib, ... }: | ||
|
||
let | ||
cfg = config.services.openssh; | ||
in | ||
{ | ||
options = { | ||
services.openssh.enable = lib.mkOption { | ||
type = lib.types.nullOr lib.types.bool; | ||
default = null; | ||
description = '' | ||
Whether to enable Apple's built-in OpenSSH server. | ||
The default is null which means let macOS manage the OpenSSH server. | ||
''; | ||
}; | ||
}; | ||
|
||
config = { | ||
# We don't use `systemsetup -setremotelogin` as it requires Full Disk Access | ||
system.activationScripts.launchd.text = lib.mkIf (cfg.enable != null) (if cfg.enable then '' | ||
if [[ "$(systemsetup -getremotelogin | sed 's/Remote Login: //')" == "Off" ]]; then | ||
launchctl enable system/com.openssh.sshd | ||
launchctl bootstrap system /System/Library/LaunchDaemons/ssh.plist | ||
fi | ||
'' else '' | ||
if [[ "$(systemsetup -getremotelogin | sed 's/Remote Login: //')" == "On" ]]; then | ||
launchctl bootout system/com.openssh.sshd | ||
launchctl disable system/com.openssh.sshd | ||
fi | ||
''); | ||
}; | ||
} |
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.
The logic for when
cfg.enable
is false worries me a little, because it seems like you might think your SSH server is off and you’re totally protected, but there’s actually a race condition between boot and the activation scripts running where the server can be accessed?Do we know if there are any meaningful differences between what this does and what
systemsetup -setremotelogin
does? It may be better to just require FDA for this module, as it would certainly solve the race condition.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.
Currently we're adding the text to the
launchd
activation script, which is not one of the activation scripts that runs on boot (etcChecks
,etc
andkeyboard
) (Unrelated tangent: we'll probably wantusers.users.launchd.agents
to allow us to do user activation when they log in as it might have interactive prompts)When you
bootout
anddisable
the SSH server, it won't get reenabled on reboot, I've tested this on a VM by manually going into the Sharing menu, enabling Remote Login, doing adarwin-rebuild switch
withservices.openssh.enable = false;
, rebooting and checking that Remote Login is still disabledThere 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.
Ah, so it actually toggles the visible preference in System Settings when you do this? That’s good enough for me then. Strange that they have a back door like this, though; I wouldn’t be surprised if we have to move to the proper command in future.