How to safely store the connection string when using sails.js

I have a database connection string in config \ adapters.js that looks like below. I do not want to leave the connection string in plain text. What is the best way to protect this information, and the service can call and connect to the database?

module.exports.adapters = {

  // If you leave the adapter config unspecified 
  // in a model definition, 'default' will be used.
  'default': 'mssql',

    mssql: {
        connectionString: 'Driver={SQL Server Native Client 10.0};Server=foo.domain.com;Database=RODDY;Uid=jsmith;Pwd=nw0ow21',
        module: 'sails-mssql'
    }

};
+4
source share
3 answers

All the other answers are great answers, here is another approach.

Set an environment variable called SQL_STRING.

It is assumed that you are on ubuntu ..

#edit /etc/profile or ~/.profile
vim /etc/profile;
#add this line to it.
export SQL_STRING=<insert your sql string>

now in your file config/local.jsadd this forconnectionString:

connectionString: process.env.SQL_STRING

this will load the connection string as an environment variable. This will do two things

  • local.js , , , , env. , ..

  • , , , .

sailsjs, sails, ~/.profile MAILGUN, db , . sudo, ssh , .

, , root .

+6

, . - , filesytsem. , .

-, - . , , :

  • . (, root) , db
  • ( , s3)
  • , , ( http, https, ssh)
  • FTP ,
  • , -.

, , , .

+2

, sails.js config/local.js, .gitignore, git [1]. sails.js local.js [2]. , local.js :

// Local configuration
// 
// Included in the .gitignore by default,
// this is where you include configuration overrides for your local system
// or for a production deployment.
//
// For example, to use port 80 on the local machine, override the `port` config
module.exports = {
    port: 80,
    environment: 'production',
    adapters: {
        mssql: {
            connectionString: 'Driver={SQL Server Native Client 10.0};Server=foo.domain.com;Database=RODDY;Uid=jsmith;Pwd=nw0ow21'
        }
    }
}

, , . , , @SamT, .

0
source

Source: https://habr.com/ru/post/1524184/


All Articles