PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, July 14, 2022

[FIXED] How to handle configuration values in production applications

 July 14, 2022     environment-variables, mean-stack, web-deployment     No comments   

Issue

I am new to and have recently been learning how to build/deploy a MEAN stack application and now wish to deploy to AWS (Using EC2). Currently my node.js API utilises environment variables (process.env) for values such as:

  1. MongoDB URL (for process running on port 27017)
  2. JWT authentication secret
  3. Email and passwords for emailing service
  4. Port to run node

What is the best way to handle these dynamic values when deploying this app to production? I have read that environment variables, whilst more secure than plaintext values, are still insecure in some regard. I am aware of services such as the AWS parameter store for secure storage of these values but wanted to know if there is some general best practice advice to follow for storing such configuration variables when deploying an app into production for any given deployment option.

Thanks


Solution

AWS Parameter Store is indeed advantageous when compared to storing credentials in config files or environment variables. To know more about potential issues with those 2 you may want to check answers to this question https://stackoverflow.com/a/28329996/2579733

AWS Parameter Store would require little configuration since it's a tool within the AWS ecosystem.

Secrets stored in PS are encrypted in transit and at rest.

Basically you'd need an IAM role with ssm:GetParameter and kms:Decrypt permissions which you can assign to your EC2 instance.

Then basic node.js implementation can be something like this:

const aws = require('aws-sdk')

async function getSecureValue(path) {
    const ssm = new aws.SSM()
    const ssmParams = {
        Name: path,
        WithDecryption: true,
    }

    const storeResponse = await ssm.getParameter(ssmParams).promise()

    return storeResponse.Parameter.Value
}

const password = await ssm.getSecureValue(PASSWORD_SSM_PATH)



Answered By - Max Ivanov
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing