How to authenticate Azure SQL server with Access Token through SSH Tunnel with SqlServerDataSource JDBC?

Link 5 Reputation points
2023-05-31T16:45:10.8066667+00:00

I have a JAVA cloud application that is using Microsoft JDBC driver (9.4 or 12.2) to make a database connection to Azure SQL Server through a SSH tunnel (Bastion Server/Jump Server). I know my SSH tunnel is working because when I authenticate with SQL username/password through the SSH server, I have no issue. My application is able to login and make query. The issue is when I switch over to Azure Active Directory access token authentication through the same SSH server, I kept getting the login failed at 127.0.0.1. Also, I know my access token is valid because I can authenticate fine without going through the SSH Tunnel. The issue arise when I try to authenticate with access token through the SSH tunnel.

User's image

I'm using the SqlServerDataSource class from MS JDBC driver. The only difference I see between username/password versus accessToken is these 3 setter methods:

SqlServerDataSource#setUser

SqlServerDataSource#setPassword
SqlServerDataSource$#setAccessToken

What am I missing here in the SqlServerDataSource configuration for Access Token beside setAccessToken? It failed the login when going through the SSH server 127.0.0.1. I tried setting the host certificate with SqlServerDataSource#setHostNameInCertificate but that didn't make a difference.

Anyone know if we can use Azure Active Directory access token through SSH tunnel? What am I missing in my setting?

Azure SQL Database
Microsoft Security Microsoft Entra Microsoft Entra ID
{count} votes

3 answers

Sort by: Most helpful
  1. Sedat SALMAN 14,180 Reputation points MVP
    2023-05-31T17:34:02.4933333+00:00

    I want to an example document for Access token usage

    https://towardsdatascience.com/how-to-use-azure-sql-access-token-authentication-from-azure-devops-pipelines-344fa7dafa49

    as you can understand from the document to get an access token you need to authenticate your used from the active directory first.

    I think your problem is related with your SSH tunnel

    by using that tunnel you can connect toi SQL Server but not Azure AD

    so you need to reconfigure your tunnel and routing at first to create connection to the Azure AD also

    in such cases it is better to use VPN instead of SSH tunneling to reduce the complexity also


  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. اسماء امين عبده ابوزيد 0 Reputation points
    2023-07-11T09:29:27.91+00:00

    Hi ,, all thanx for answering my question 🙋🏼‍♀️

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.