Skip to content

Use env config for the location of the RSA files #2069

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions Guide/file-storage.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,16 @@ ssh-keygen -t rsa -b 4096 -m PEM -f ./Config/jwtRS256.key
openssl rsa -in ./Config/jwtRS256.key -pubout -outform PEM -out ./Config/jwtRS256.key.pub
```

Add in the `.envrc` file the location of the newly generated files


```bash
export JWT_PRIVATE_KEY_PATH="./Config/jwtRS256.key";
export JWT_PUBLIC_KEY_PATH="./Config/jwtRS256.key.pub";
```

**Note:** Upon deploy to AWS, the files and location will be automatically set for you via the `flake.nix` file.

```haskell
-- Config/Config.hs
import Control.Exception (catch)
Expand All @@ -961,8 +971,11 @@ config = do
-- ...

-- Private and public keys to sign and verify image style URLs.
privateKeyContent <- liftIO $ readRsaKeyFromFile "./Config/jwtRS256.key"
publicKeyContent <- liftIO $ readRsaKeyFromFile "./Config/jwtRS256.key.pub"
privateKeyFilePath <- env @FilePath "JWT_PRIVATE_KEY_PATH"
publicKeyFilePath <- env @FilePath "JWT_PUBLIC_KEY_PATH"

privateKeyContent <- liftIO $ readRsaKeyFromFile privateKeyFilePath
publicKeyContent <- liftIO $ readRsaKeyFromFile publicKeyFilePath

case (readRsaSecret privateKeyContent, readRsaPublicKey publicKeyContent) of
(Just privateKey, Just publicKey) -> option $ RsaKeys publicKey privateKey
Expand All @@ -971,7 +984,7 @@ config = do

readRsaKeyFromFile :: FilePath -> IO BS.ByteString
readRsaKeyFromFile path = do
catch (BS.readFile path) handleException
Control.Exception.catch (BS.readFile path) handleException
where
handleException :: IOError -> IO BS.ByteString
handleException _ = return BS.empty
Expand Down