-
Notifications
You must be signed in to change notification settings - Fork 629
[CBR-470] Ensure 600 file permission on generated x509 certificates and keys #3773
[CBR-470] Ensure 600 file permission on generated x509 certificates and keys #3773
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do this portably without the unix library:
I stole this function I wrote years ago for the Cabal lib. It also has the advantage of writing the file atomically.
-- | Writes a file atomically, and with private file permissions.
--
-- The file is either written successfully or an IO exception is raised and
-- the original file is left unchanged.
--
-- On unix systems the file permissions are 600, i.e. user read and write,
-- but no others.
--
-- On windows it is not possible to delete a file that is open by a process.
-- This case will give an IO exception but the atomic property is not affected.
--
writeFileAtomicPrivate :: FilePath -> BS.ByteString -> IO ()
writeFileAtomicPrivate targetPath content = do
let (targetDir, targetFile) = splitFileName targetPath
Exception.bracketOnError
(openBinaryTempFile targetDir $ targetFile <.> "tmp")
(\(tmpPath, handle) -> hClose handle >> removeFile tmpPath)
(\(tmpPath, handle) -> do
BS.hPut handle content
hClose handle
renameFile tmpPath targetPath)
…nd keys It is of the utmost importance that those files aren't readable by anyone but the user generating them. Files are generated upon start and used to secure the communication between cardano-sl and its clients (e.g. Daedalus) Note that, we do assume that users are able to secure their own environment from potential adversary services, so this is really about preventing one user to have access to certificates of another user.
9f6fd9c
to
310b94d
Compare
@dcoutts Went for your nice trick :)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The normal way this is done is with umask.
Is the 600 file permission a result of using openBinaryTempFile
?
Yes. I've double-checked in the source code actually: https://hackage.haskell.org/package/base-4.12.0.0/docs/src/System.IO.html#openBinaryTempFile -- | Like 'openTempFile', but opens the file in binary mode. See 'openBinaryFile' for more comments.
openBinaryTempFile :: FilePath -> String -> IO (FilePath, Handle)
openBinaryTempFile tmp_dir template
= openTempFile' "openBinaryTempFile" tmp_dir template True 0o600 A bit ad-hoc, but if it buys us some extra "security" on windows as well, why not. |
This looks like it fixes the permissions to lock them down a bit further. lets merge it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
This was an oversight and should have landed in May I merge that in the release branch now or should I wait a bit? |
Description
It is of the utmost importance that those files aren't readable by anyone but the user generating them.
Files are generated upon start and used to secure the communication between cardano-sl and its clients (e.g. Daedalus)
Note that, we do assume that users are able to secure their own environment from potential adversary services,
so this is really about preventing one user to have access to certificates of another user.
Linked issue
[CBR-470]
Type of change
Developer checklist
Testing checklist
QA Steps
Screenshots (if available)