Handling passwords in connection strings in kubernetes deplyoment.yaml for net core applications

4/13/2021

I am at a loss when I try to figure out how should I handle connection strings in deployment.yaml for Net core application. Lets say I have Sql connection string in my environment variables like:

  env:
    - name: "ASPNETCORE_ENVIRONMENT_ConnectionString"
      value: "Data Source=somedb;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;"

and using this configuration myPassword is visible e.g. in kubedash. So I'm moving password to secret section, creating new variable for it and in my c# code I'm creating connection string with this password. Is this is a good approach? Or perhaps it can be done better?

For rabbit conneection string like :

host=myremoteserver;username=myusername;password=mypassword

I'm doing something like

host=myremoteserver;username=myusername;password=PASSWORD_PLACEHOLDER

and replacing this placeholder in code.

-- Mate
.net-core
c#
kubernetes

0 Answers