summaryrefslogtreecommitdiff
path: root/src/Propellor
diff options
context:
space:
mode:
authorJoey Hess2019-04-16 11:19:43 -0400
committerJoey Hess2019-04-16 11:19:43 -0400
commite77deb1ef29201ec2a957e17b613958823cca8bb (patch)
treefd45c8fd879cc28fdbbf497682e6dbac56b25e2f /src/Propellor
parent7b4a1e6149f1a04b2b66c22cca65514fe824782d (diff)
Ssh.userKeys, Ssh.userKeyAt: Create .ssh directory when it does not yet exist.
* Ssh.userKeys, Ssh.userKeyAt: Create .ssh directory when it does not yet exist. * Ssh.userKeyAt: When a relative filepath is provided, it's put inside the user's .ssh directory.
Diffstat (limited to 'src/Propellor')
-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"