0

I am using Linux Web Apps for Azure together with a SQL Azure Database.

I can save my SQL Azure Database password (for argument's sake, let us say it is pass123) in META-INF/context.xml and this works successfully

<Context>
<Resource name="jdbc/myDB" type="javax.sql.DataSource" auth="Container"
       factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
       driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" initialSize="30"
       maxActive="100" validationQuery="SELECT 1"
       validationQueryTimeout="1000"
       testOnBorrow="true"
       url="jdbc:sqlserver://exampleserver.database.windows.net:1433;database=exampledb;encrypt=true;hostNameInCertificate=westeurope1-a.control.database.windows.net;
       loginTimeout=10;user=myuser;
       password=pass123"
            />
</Context>

I however would like the password to be encrypted and not stored in plaintext in the context.xml file. So I did the following - based on https://learn.microsoft.com/en-us/azure/app-service/containers/configure-language-java#data-sources:

I added two Web App/Configuration/Application Settings CATALINA_OPTS and THEDBPASSWORD

I set CATALINA_OPTS to be "$CATALINA_OPTS -Ddbpassword={THEDBPASSWORD}"

I set THEDBPASSWORD to be the password of the user

Picture from Azure Portal of Application Settings

I then changed my context.xml to be password={dbpassword} instead of password=pass123

I then however get the following error in the log (and the application fails to start)

Error: Could not find or load main class "$CATALINA_OPTS -Ddbpassword=pass123" -Ddbpassword=pass123

Any ideas?

gordon613
  • 2,770
  • 12
  • 52
  • 81

1 Answers1

0

I solved it by doing the following:

  1. I had forgotten the $ in context.xml

So context.xml needed to be password=${dbpassword}

  1. I also changed the CATALINA_OPTS to be -Ddbpassword=pass123

  2. I dispensed with the THEDBPASSWORD variable

I am sure this is not the only way or the best way of doing this, but at least it works. I was partly inspired by Tomcat 8 - context.xml use Environment Variable in Datasource

gordon613
  • 2,770
  • 12
  • 52
  • 81