docker-mendix-buildpack icon indicating copy to clipboard operation
docker-mendix-buildpack copied to clipboard

Allow CERTIFICATE_AUTHORITIES to point to a file

Open JamesRamm opened this issue 4 years ago • 0 comments

It would be useful if the CERTIFICATE_AUTHORITIES variable could also be a file

At the moment we have added a hack to startup (.py) in order to copy the contents of a certificate file to the CERTIFICATE_AUTHORITIES var:

def import_cacertificates():
    logging.debug("Checking for HTTPS certificate...")
    if "--secure" in sys.argv:
        try:
            with open('/opt/mendix/server.crt', 'r') as fin:
                contents = fin.read()
            if not contents:
                raise Exception('Certificate file /opt/mendix/server.crt is empty')
            os.environ['CERTIFICATE_AUTHORITIES'] = contents
            logging.debug('Loaded certificate from /opt/mendix/server.crt')
        except Exception as e:
            logging.error('Unable to import certificate. Full error:\n{}'.format(e))
            sys.exit(1)

When running an API (which our mendix app is talking to), pretty much all other components requiring the cert (such as Nginx) just accept a file path. So we mount the cert file(s) as volumes where needed. It is only Mendix which presents a problem since it must be specified as an env var. This is a pain when using docker-compose/kubernetes etc as it either means we write some kind of wrapper script to read the certificate and set the relevant env. var before running docker-compose or we need to edit the mendix startup script as above.

JamesRamm avatar Aug 26 '19 07:08 JamesRamm