Skip to content

Provide a way to specify target server hostname or specify username when authenticating with Azure AD CLI #576

Open
@mmalecki

Description

@mmalecki

Wow, that was a mouthful to put in the title. Sadly I don't think there's a shorter way to go about this than providing a use-case, so here goes:

I'm looking for a way to connect to a Azure SQL server instance in a private network using sqlcmd, a proxy inside that network and Azure AD authentication. I am, however, unable to use that method without hard-coding a DNS alias for the server hostname pointing to 127.0.0.1 in /etc/hosts due to how SQL Server login works (?).

So, if I set up the proxy on port 11433, the following fails to log in:

SQLCMDSERVER="127.0.0.1,11433" sqlcmd -N -C --authentication-method=ActiveDirectoryAzCli

But the following works if I add an entry to /etc/hosts pointing my actual server hostname at 127.0.0.1 (still going through the same proxy, note the port):

SQLCMDSERVER="<server-name>.database.windows.net,11433" sqlcmd -N -C --authentication-method=ActiveDirectoryAzCli

In #484 the poster was able to solve this issue by specifying the hostname as part of the passed in username, like:

sqlcmd -N -C -U 'mail#<email>@<server-name>.database.windows.net' --authentication-method=ActiveDirectoryAzCli

But the -U switch doesn't seem to do anything in case of CLI authentication.

So, I'm looking for a way to specify the server name, preferably by an entirely different command line switch altogether, or to tack on that server hostname to the username. I tried taking a dive into this client, as well as the MSSQL library, and found a promising lead in form of HostDialer, but nothing that could work out of the box with the current state of things. I'd love to be corrected and just close this issue though ;).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions