Added separate database credentials for each stack #1152

Merged
a24julot merged 9 commits from issue-988-db-passwords-week7 into both_teams_week_8 2026-05-28 10:48:14 +00:00
Collaborator

What has been done

  • Added separate database usernames and passwords for each stack service

  • Updated compose files for:

    • user
    • parking
    • temperature
    • energy
    • roomBooking
  • Updated healthchecks to use stack-specific database users

  • Added stack-specific environment variables

Notes

This PR re-applies the changes on top of team_1_week_7 after PR #985 was merged.

Conflicts from the previous closed PR were resolved against the latest week_7 branch.

## What has been done * Added separate database usernames and passwords for each stack service * Updated compose files for: * user * parking * temperature * energy * roomBooking * Updated healthchecks to use stack-specific database users * Added stack-specific environment variables ## Notes This PR re-applies the changes on top of `team_1_week_7` after PR #985 was merged. Conflicts from the previous closed PR were resolved against the latest week_7 branch.
c24danli 2026-05-26 06:31:56 +00:00
b23albst left a comment
Collaborator

Review on #1152

Whats done

Tested building a fresh install of the project to see if it works

Tested on ubuntu

  • App does not star starts
    • This is because the new database credentials are not generated in the installation script
    • Since the services with new credentials still use DATABASE_USER and DATABASE_PASSWORD in their connection strings, some of them do not work, even when the variables have been added to the env file.

Inspected following files

  • Indentation/code styling ok
  • Naming convention ok
  • Comments
    • There are no comments, but as this is the case across all yaml files, this is no problem
  • General code quality
    + On line 71 in DockerCompose/stacks/parking/compose.yaml there is some code left from a merge. This should be removed

What needs to be done

  • Add new env variables to installation script

  • Update the database connection strings in the affected services to use new env variables

  • Fix code on line 71 in DockerCompose/stacks/parking/compose.yaml that is left from merge.

  • Another thing is that the file database does not get new credentials, however this is fine with me, as long as DATABASE_USER and DATABASE_PASSWORD are not removed from the installation scripts

Conclusion

  • This is not ready to merge yet
# Review on #1152 ## Whats done Tested building a fresh install of the project to see if it works ### Tested on ubuntu + App does not star starts + This is because the new database credentials are not generated in the installation script + Since the services with new credentials still use DATABASE_USER and DATABASE_PASSWORD in their connection strings, some of them do not work, even when the variables have been added to the env file. ### Inspected following files + Indentation/code styling ok + Naming convention ok + Comments + There are no comments, but as this is the case across all yaml files, this is no problem + General code quality + On line 71 in DockerCompose/stacks/parking/compose.yaml there is some code left from a merge. This should be removed ## What needs to be done + Add new env variables to installation script + Update the database connection strings in the affected services to use new env variables + Fix code on line 71 in DockerCompose/stacks/parking/compose.yaml that is left from merge. + Another thing is that the file database does not get new credentials, however this is fine with me, as long as DATABASE_USER and DATABASE_PASSWORD are not removed from the installation scripts ## Conclusion + This is not ready to merge yet
Collaborator

This is still not ready to merge. It builds, but cannot connect to the databases. When checking the logs, the it is still DATABASE_USER trying to connect, presumably with the incorrect password. I do not know if this is because it still uses the old images, or if I missed updating some env-variable

This is still not ready to merge. It builds, but cannot connect to the databases. When checking the logs, the it is still DATABASE_USER trying to connect, presumably with the incorrect password. I do not know if this is because it still uses the old images, or if I missed updating some env-variable
Collaborator

When trying to connect to the databases, the "old" variables are still used (strings DATABASE_USER and DATABASE_PASSWORD in env file). I have no idea why.

When trying to connect to the databases, the "old" variables are still used (strings DATABASE_USER and DATABASE_PASSWORD in env file). I have no idea why.
Collaborator

I think the problem is in middleware. The connection string used to connect to all databases there is

var connectionString = $"Host={service}-db;Port=5432;Username={dbUser};Password={dbPassword};Database={dataBase}";

dbUser and Password are still the old DATABASE_USER and DATABASE_PASSWORD.
This needs to be updated so that the correct username and password are used when trying to connect to a specific database

I think the problem is in middleware. The connection string used to connect to **all** databases there is ``` var connectionString = $"Host={service}-db;Port=5432;Username={dbUser};Password={dbPassword};Database={dataBase}"; ``` dbUser and Password are still the old DATABASE_USER and DATABASE_PASSWORD. This needs to be updated so that the correct username and password are used when trying to connect to a specific database
Collaborator

@b23albst wrote in #1152 (comment):

I think the problem is in middleware. The connection string used to connect to all databases there is

var connectionString = $"Host={service}-db;Port=5432;Username={dbUser};Password={dbPassword};Database={dataBase}";

dbUser and Password are still the old DATABASE_USER and DATABASE_PASSWORD. This needs to be updated so that the correct username and password are used when trying to connect to a specific database

Was just about to comment this. This issue basically covers 4 areas: compose files, installation scripts, middleware and all the service DataQueries.
As you just said, middleware connects to all databases with the same user and password. This needs to be changed so that middleware tries to access ENERGY_DATABASE_USER if the service provided is energy, for example. Middleware right now does receive the service name so this should be possible.

@b23albst wrote in https://git.webug.se/Andras/BoundlessFlowCampus2K/pulls/1152#issuecomment-14111: > I think the problem is in middleware. The connection string used to connect to **all** databases there is > > ```text > var connectionString = $"Host={service}-db;Port=5432;Username={dbUser};Password={dbPassword};Database={dataBase}"; > ``` > > dbUser and Password are still the old DATABASE_USER and DATABASE_PASSWORD. This needs to be updated so that the correct username and password are used when trying to connect to a specific database Was just about to comment this. This issue basically covers 4 areas: compose files, installation scripts, middleware and all the service DataQueries. As you just said, middleware connects to all databases with the same user and password. This needs to be changed so that middleware tries to access ENERGY_DATABASE_USER if the service provided is energy, for example. Middleware right now does receive the service name so this should be possible.
a22erigr changed target branch from team_1_week_7 to both_teams_week_8 2026-05-27 08:57:59 +00:00
a24timsv left a comment
Collaborator

Several issues was found:

  • Middleware could not insert into certain databases since the method for retrieving the username and password is not in that method.
  • All service's compose files was not modified, causing errors.
  • The WindowsInstallation script didn't generate all needed variables.
  • The general Database user and password should not exist, there shouldn't be a fallback system for usernames and passwords.
  • MENU_ICS_URL should not exist anymore.

The issues above has already been solved since to be able to review this, I needed to fix them. The commit below involves these fixes.

Several issues was found: - Middleware could not insert into certain databases since the method for retrieving the username and password is not in that method. - All service's compose files was not modified, causing errors. - The WindowsInstallation script didn't generate all needed variables. - The general Database user and password should not exist, there shouldn't be a fallback system for usernames and passwords. - MENU_ICS_URL should not exist anymore. The issues above has already been solved since to be able to review this, I needed to fix them. The commit below involves these fixes.
Fixed the following issues:
- Middleware could not insert into certain databases since the method for retrieving the username and password is not in that method.
- All service's compose files was not modified, causing errors.
- The WindowsInstallation script didn't generate all needed variables.
- The general Database user and password should not exist, there shouldn't be a fallback system for usernames and passwords.
- MENU_ICS_URL should not exist anymore.
Collaborator

Theses fixes don't fix the solar service. It has wrongly typed database queries.

Theses fixes don't fix the solar service. It has wrongly typed database queries.
a24sakma approved these changes 2026-05-28 10:10:26 +00:00
a24sakma left a comment
Collaborator

what has been reviewed

  1. the code seems follow the logic for creation of different users and databases for each service
  2. it has been test on both on linux and windows

Important notes

remove .env file
run installation script
run rebuild

OBG: you need to remove your old .env as it uses only one user and one password for all services

# what has been reviewed 1. the code seems follow the logic for creation of different users and databases for each service 2. it has been test on both on linux and windows # Important notes remove .env file run installation script run rebuild OBG: you need to remove your old .env as it uses only one user and one password for all services
a24julot merged commit 637c98fc70 into both_teams_week_8 2026-05-28 10:48:14 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Andras/BoundlessFlowCampus2K!1152
No description provided.