summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Ssh.hs
diff options
context:
space:
mode:
authorDaniel Brooks2015-08-02 00:59:28 -0400
committerDaniel Brooks2015-08-02 00:59:28 -0400
commiteb15f06896aeb208d19f6f322905c7782125356e (patch)
tree6f28ac50e476e83b212e2827a10d4b6dee0730c9 /src/Propellor/Property/Ssh.hs
parent65b511e2d4f4ec9864167e414e76b967eda32dba (diff)
parentb7a9655a695103b3ca2e4e6edfe305f9b44d9250 (diff)
Merge branch 'joeyconfig' of git://git.kitenet.net/propellor into joeyconfig
Conflicts: src/Propellor/Property/SiteSpecific/IABak.hs
Diffstat (limited to 'src/Propellor/Property/Ssh.hs')
-rw-r--r--src/Propellor/Property/Ssh.hs41
1 files changed, 30 insertions, 11 deletions
diff --git a/src/Propellor/Property/Ssh.hs b/src/Propellor/Property/Ssh.hs
index 37e65728..fca7d037 100644
--- a/src/Propellor/Property/Ssh.hs
+++ b/src/Propellor/Property/Ssh.hs
@@ -1,7 +1,10 @@
module Propellor.Property.Ssh (
PubKeyText,
sshdConfig,
+ ConfigKeyword,
+ setSshdConfigBool,
setSshdConfig,
+ RootLogin(..),
permitRootLogin,
passwordAuthentication,
noPasswords,
@@ -24,11 +27,11 @@ import Propellor
import qualified Propellor.Property.File as File
import qualified Propellor.Property.Service as Service
import Propellor.Property.User
-import Utility.SafeCommand
import Utility.FileMode
import System.PosixCompat
import qualified Data.Map as M
+import Data.List
type PubKeyText = String
@@ -39,21 +42,37 @@ sshBool False = "no"
sshdConfig :: FilePath
sshdConfig = "/etc/ssh/sshd_config"
-setSshdConfig :: String -> Bool -> Property NoInfo
-setSshdConfig setting allowed = combineProperties "sshd config"
- [ sshdConfig `File.lacksLine` (sshline $ not allowed)
- , sshdConfig `File.containsLine` (sshline allowed)
- ]
+type ConfigKeyword = String
+
+setSshdConfigBool :: ConfigKeyword -> Bool -> Property NoInfo
+setSshdConfigBool setting allowed = setSshdConfig setting (sshBool allowed)
+
+setSshdConfig :: ConfigKeyword -> String -> Property NoInfo
+setSshdConfig setting val = File.fileProperty desc f sshdConfig
`onChange` restarted
- `describe` unwords [ "ssh config:", setting, sshBool allowed ]
where
- sshline v = setting ++ " " ++ sshBool v
+ desc = unwords [ "ssh config:", setting, val ]
+ cfgline = setting ++ " " ++ val
+ wantedline s
+ | s == cfgline = True
+ | (setting ++ " ") `isPrefixOf` s = False
+ | otherwise = True
+ f ls
+ | cfgline `elem` ls = filter wantedline ls
+ | otherwise = filter wantedline ls ++ [cfgline]
+
+data RootLogin
+ = RootLogin Bool -- ^ allow or prevent root login
+ | WithoutPassword -- ^ disable password authentication for root, while allowing other authentication methods
+ | ForcedCommandsOnly -- ^ allow root login with public-key authentication, but only if a forced command has been specified for the public key
-permitRootLogin :: Bool -> Property NoInfo
-permitRootLogin = setSshdConfig "PermitRootLogin"
+permitRootLogin :: RootLogin -> Property NoInfo
+permitRootLogin (RootLogin b) = setSshdConfigBool "PermitRootLogin" b
+permitRootLogin WithoutPassword = setSshdConfig "PermitRootLogin" "without-password"
+permitRootLogin ForcedCommandsOnly = setSshdConfig "PermitRootLogin" "forced-commands-only"
passwordAuthentication :: Bool -> Property NoInfo
-passwordAuthentication = setSshdConfig "PasswordAuthentication"
+passwordAuthentication = setSshdConfigBool "PasswordAuthentication"
-- | Configure ssh to not allow password logins.
--