2014-04-03 06:27:17 +00:00
|
|
|
module Propellor.Property.Ssh (
|
|
|
|
setSshdConfig,
|
|
|
|
permitRootLogin,
|
|
|
|
passwordAuthentication,
|
|
|
|
hasAuthorizedKeys,
|
|
|
|
restartSshd,
|
|
|
|
uniqueHostKeys
|
|
|
|
) where
|
2014-03-30 03:10:52 +00:00
|
|
|
|
2014-03-31 03:55:59 +00:00
|
|
|
import Propellor
|
2014-03-31 03:37:54 +00:00
|
|
|
import qualified Propellor.Property.File as File
|
|
|
|
import Propellor.Property.User
|
2014-03-31 03:55:59 +00:00
|
|
|
import Utility.SafeCommand
|
2014-03-30 03:10:52 +00:00
|
|
|
|
|
|
|
sshBool :: Bool -> String
|
|
|
|
sshBool True = "yes"
|
|
|
|
sshBool False = "no"
|
|
|
|
|
|
|
|
sshdConfig :: FilePath
|
|
|
|
sshdConfig = "/etc/ssh/sshd_config"
|
|
|
|
|
|
|
|
setSshdConfig :: String -> Bool -> Property
|
2014-04-01 21:32:37 +00:00
|
|
|
setSshdConfig setting allowed = combineProperties "sshd config"
|
2014-03-30 17:12:33 +00:00
|
|
|
[ sshdConfig `File.lacksLine` (sshline $ not allowed)
|
|
|
|
, sshdConfig `File.containsLine` (sshline allowed)
|
2014-03-30 20:11:00 +00:00
|
|
|
]
|
|
|
|
`onChange` restartSshd
|
|
|
|
`describe` unwords [ "ssh config:", setting, sshBool allowed ]
|
2014-03-30 03:10:52 +00:00
|
|
|
where
|
2014-03-30 05:49:11 +00:00
|
|
|
sshline v = setting ++ " " ++ sshBool v
|
2014-03-30 03:10:52 +00:00
|
|
|
|
|
|
|
permitRootLogin :: Bool -> Property
|
|
|
|
permitRootLogin = setSshdConfig "PermitRootLogin"
|
|
|
|
|
|
|
|
passwordAuthentication :: Bool -> Property
|
|
|
|
passwordAuthentication = setSshdConfig "PasswordAuthentication"
|
|
|
|
|
|
|
|
hasAuthorizedKeys :: UserName -> IO Bool
|
|
|
|
hasAuthorizedKeys = go <=< homedir
|
|
|
|
where
|
|
|
|
go Nothing = return False
|
|
|
|
go (Just home) = not . null <$> catchDefaultIO ""
|
|
|
|
(readFile $ home </> ".ssh" </> "authorized_keys")
|
|
|
|
|
|
|
|
restartSshd :: Property
|
2014-03-31 03:55:59 +00:00
|
|
|
restartSshd = cmdProperty "service" ["ssh", "restart"]
|
2014-03-30 03:45:48 +00:00
|
|
|
|
2014-04-03 06:27:17 +00:00
|
|
|
-- | Blows away existing host keys and make new ones.
|
|
|
|
-- Useful for systems installed from an image that might reuse host keys.
|
|
|
|
-- A flag file is used to only ever do this once.
|
2014-03-30 03:45:48 +00:00
|
|
|
uniqueHostKeys :: Property
|
|
|
|
uniqueHostKeys = flagFile prop "/etc/ssh/.unique_host_keys"
|
|
|
|
`onChange` restartSshd
|
|
|
|
where
|
2014-03-30 19:31:57 +00:00
|
|
|
prop = Property "ssh unique host keys" $ do
|
2014-03-30 03:45:48 +00:00
|
|
|
void $ boolSystem "sh"
|
|
|
|
[ Param "-c"
|
|
|
|
, Param "rm -f /etc/ssh/ssh_host_*"
|
|
|
|
]
|
|
|
|
ensureProperty $
|
|
|
|
cmdProperty "/var/lib/dpkg/info/openssh-server.postinst"
|
2014-03-31 03:55:59 +00:00
|
|
|
["configure"]
|