From a2bb647827ee7eea0c038fdd40d1bd65c0d7a2c8 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 4 Jan 2015 16:10:24 -0400 Subject: Ssh.hostKey and Ssh.hostKeys no longer install public keys from the privdata. Instead, the public keys of a host should be set using Ssh.pubKey. --- src/Propellor/Property/Ssh.hs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/Propellor/Property/Ssh.hs b/src/Propellor/Property/Ssh.hs index 301c628b..8642d990 100644 --- a/src/Propellor/Property/Ssh.hs +++ b/src/Propellor/Property/Ssh.hs @@ -95,21 +95,25 @@ hostKeys :: IsContext c => c -> Property hostKeys ctx = propertyList "known ssh host keys" $ map (flip hostKey ctx) [minBound..maxBound] --- | Installs a single ssh host key. +-- | Installs a single ssh host key of a particular type. -- --- The private key comes from the privdata. --- --- The public key is set using 'pubKey'. +-- The private key comes from the privdata; +-- the public key is set using 'pubKey'. hostKey :: IsContext c => SshKeyType -> c -> Property hostKey keytype context = combineProperties desc - [ installkey (keysrc ".pub" (SshPubKey keytype "")) (install writeFile ".pub") - , installkey (keysrc "" (SshPrivKey keytype "")) (install writeFileProtected "") + [ property desc $ do + v <- M.lookup keytype <$> getPubKey + case v of + Just k -> install writeFile ".pub" k + Nothing -> do + warningMessage $ "Missing ssh pubKey " ++ show keytype + return FailedChange + , withPrivData (keysrc "" (SshPrivKey keytype "")) context $ \getkey -> + property desc $ getkey $ install writeFileProtected "" ] `onChange` restarted where desc = "known ssh host key (" ++ fromKeyType keytype ++ ")" - installkey p a = withPrivData p context $ \getkey -> - property desc $ getkey a install writer ext key = do let f = "/etc/ssh/ssh_host_" ++ fromKeyType keytype ++ "_key" ++ ext s <- liftIO $ readFileStrict f -- cgit v1.3-2-g0d8e