Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Steps for connecting to SQL database #4619

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ To see what is releasing in the FHIR Server, please refer to the [releases](http
- [SMART on FHIR Proxy tutorial](docs/SMARTonFHIR.md): Describes how to use the proxy to enable SMART on FHIR applications with the FHIR Server.
- [FHIR Postman tutorial](https://docs.microsoft.com/azure/healthcare-apis/access-fhir-postman-tutorial): Describes how to access a FHIR API using Postman.
- [Debugging](docs/HowToDebug.md): Describes how to debug FHIR Server for Azure using Visual Studio.
- [Connect to SQL Database](docs/HowToConnectSQLDatabase.md): Describes how to connect to SQL Database.

## Blog Posts
* Blog: [FHIR Server for Azure, an open source project for modern healthcare](https://cloudblogs.microsoft.com/industry-blog/health/2018/11/12/fhir-server-for-azure-an-open-source-project-for-cloud-based-health-solutions/).
Expand Down
43 changes: 43 additions & 0 deletions docs/HowToConnectSQLDatabase.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Connecting to a SQL Database
The procedures for connecting to a SQL database are outlined in this article.

## Active Directory Administrator for SQL Server

The user must set themselves as SQL Server Active Directory Admin when they connect to the database for the first time.

The actions to do are listed below for it.
* Access the SQL Server
* Click on Settings -> Microsoft Entra ID -> Set Admin
![alt text](images/HowToConnectSQLDatabase/entraid-admin.png "Entra Admin")
* Choose the User Account
![alt text](images/HowToConnectSQLDatabase/choose-user-account.png "Entra Admin")
* Press the "Save" button.
![alt text](images/HowToConnectSQLDatabase/save-user-admin-account.png "Entra Admin")

At this point, the user can connect to the database using `Active Directory authentication`.

Create a new user in the database and give them the role `db_owner` after connecting to the database.

The script for the same can be found below:
```
CREATE USER [user-name] FROM EXTERNAL PROVIDER;
ALTER ROLE db_owner ADD MEMBER [user-name];
```

Example query
```
CREATE USER [[email protected]] FROM EXTERNAL PROVIDER;
ALTER ROLE db_owner ADD MEMBER [[email protected]];
```

Revert the SQL Server Active directory admin user changes once the user has been created, that is, set the `OSS FHIR Server(App service)` user assigned identity back to SQL Server admin.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SergeyGaluzo is this the recommended approach?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brendankowitz What problem are we trying to solve? Is something not working with managed identities?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SergeyGaluzo We have worked on creating the documentation on the below mentioned details:

"Currently in OSS, we only have a single login enabled for the SQL Server - the User Assigned Managed Identity that the FHIR Service uses to access the server.

This is a problem because customers may need to access the database directly to check data or they may have other applications that need to access the database. This also could be problematic for FHIR Team devs that need to check the database directly like the JobQueue table.

We need to provide instructions or a script to update the SQL Admin of the user's choosing (maybe the current user??) but also create the SQL Login for the User Assigned Managed Identity.

We cannot do this in pipeline because the identity we you add a SQL user via a service principal, the SQL Server needs a managed identity that has graph read all access."

@brendankowitz FYI

Copy link
Contributor

@SergeyGaluzo SergeyGaluzo Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brendankowitz I would suggest different approach. FHIR SQL server does not need FHIR Server UAMI as admin for FHIR server to work, it is just hard to setup by the pipeline. Therefore, I usually "downgrade" UAMI to db owner after FHIR server is setup. This contains similar steps to create login for UAMI and corresponding database user. Setting up user access becomes a separate issue. In certain cases, it could remain admin...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brendankowitz: Please let us know if you suggest us to update the pipeline and documentation with an alternative approach, and if you'd like us to include instructions on providing user access to the database which will be the separate issue as mentioned.


This is a `one-time only` activity. The user can utilize an active directory login to connect directly to the database the next time.

## Important Information


During that time, when the `user-assigned identity` assigned to the `OSS FHIR Server(App service)` is removed as the SQL Server admin,
the App service would degrade since it won't be able to access to the database.

However, the `OSS FHIR Server(App service)` will return to normal once the user-assigned identity is changed back to admin when the user is created in the database.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading