summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Propellor/Property/Ssh.hs17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/Propellor/Property/Ssh.hs b/src/Propellor/Property/Ssh.hs
index 59698ec0..ca20e68c 100644
--- a/src/Propellor/Property/Ssh.hs
+++ b/src/Propellor/Property/Ssh.hs
@@ -279,9 +279,12 @@ userKeys user@(User name) context ks = combineProperties desc $ toProps $
-- | Sets up a user with the specified pubic key, and a private
-- key from the privdata.
--
--- A file can be specified to write the key to somewhere other than
+-- A FilePath can be specified to write the key to somewhere other than
-- the default locations. Allows a user to have multiple keys for
-- different roles.
+--
+-- When the FilePath is relative, is put inside the User's
+-- ~/.ssh/ directory.
userKeyAt :: IsContext c => Maybe FilePath -> User -> c -> (SshKeyType, PubKeyText) -> Property (HasInfo + UnixLike)
userKeyAt dest user@(User u) context (keytype, pubkeytext) =
combineProperties desc $ props
@@ -306,14 +309,18 @@ userKeyAt dest user@(User u) context (keytype, pubkeytext) =
installprop writer ext key = do
f <- liftIO $ keyfile ext
return $ combineProperties desc $ props
+ & File.dirExists (takeDirectory f)
& writer f (keyFileContent key)
& File.ownerGroup f user (userGroup user)
& File.ownerGroup (takeDirectory f) user (userGroup user)
keyfile ext = case dest of
- Nothing -> do
- home <- homeDirectory <$> getUserEntryForName u
- return $ home </> ".ssh" </> "id_" ++ fromKeyType keytype ++ ext
- Just f -> return $ f ++ ext
+ Nothing -> relhomessh $ "id_" ++ fromKeyType keytype ++ ext
+ Just f
+ | isRelative f -> relhomessh (f ++ ext)
+ | otherwise -> return (f ++ ext)
+ relhomessh f = do
+ home <- homeDirectory <$> getUserEntryForName u
+ return $ home </> ".ssh" </> f
fromKeyType :: SshKeyType -> String
fromKeyType SshRsa = "rsa"