JSReport Studio User Different Password per Environment



  • I was hoping to get some advice on how to best configure different passwords for a particular JSReport studio user per environment in docker.

    The scenario:
    There are two docker servers, test and production. The admin user has different passwords configured via environment variable. This works well.

    There is also a user named: 'jsreport' that we are using with the .net sdk and basic auth to run reports against the studio. Ideally I would like this user the have different passwords per environment similar to how the admin user environmental variable works.

    It looks like I can do an HTTP post to change the password of the 'jsreport' user but I have to wait for the service to startup after a redeploy. So is there a better / easier way to change the password per environment?

    Alternatively should I be doing something other than basic auth and would this make security per environment easier? I am using SSL and not using javascript to talk to the server so I don't think security of basic auth is a big concern. Additionally, I really only care about the password of this particular user and am not interested in doing this at scale / for other users.

    JSReport is a great product. Thanks for all the help.



  • You can make the following change to your server.js file which boots jsreport.
    This will update the jsreport user password during the startup to an env variable value,

    const jsreport = require('jsreport')()
    
    if (process.env.JSREPORT_CLI) {
      // export jsreport instance to make it possible to use jsreport-cli
      module.exports = jsreport
    } else {
      jsreport.init().then(() => {
        // *** here is the change
        return jsreport.documentStore.collection('users').update({
          username: 'jsreport'
        }, {
          $set: {
            password: require('password-hash').generate(process.env.YOUR_VARIABLE)
          }
        })
        // *** change end
        // running
      }).catch((e) => {
        // error during startup
        console.error(e.stack)
        process.exit(1)
      })
    }
    

Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.