dbatools icon indicating copy to clipboard operation
dbatools copied to clipboard

[Bug] Connect-DbaInstance - Connection to Azure DB via Port 443 and not Port 1433

Open schupat opened this issue 6 years ago • 23 comments

Environmental information

#### PowerShell version:
Name                           Value                                                                                   
----                           -----                                                                                   
PSVersion                      5.1.14393.3053                                                                          
PSEdition                      Desktop                                                                                 
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                 
BuildVersion                   10.0.14393.3053                                                                         
CLRVersion                     4.0.30319.42000                                                                         
WSManStackVersion              3.0                                                                                     
PSRemotingProtocolVersion      2.3                                                                                     
SerializationVersion           1.1.0.1                                                                                 

#### dbatools Module version:
Name    : dbatools
Path    : C:\Windows\system32\WindowsPowerShell\v1.0\Modules\dbatools\1.0.75\dbatools.psd1
Version : 1.0.75
LCID             Name             DisplayName                                                                                                                                                                                                                                                                                  
----             ----             -----------                                                                                                                                                                                                                                                                                  
1031             de-DE            Deutsch (Deutschland)  

SQL Server:

Azure SQL Server

N/A

Report

Host used

  • [X] powershell.exe
  • [X] ISE
  • [ ] VS Code
  • [ ] Other (please specify)

If anything other than powershell.exe was used, please confirm that you can duplicate the issue with powershell.exe

  • [ ] Still buggy in powershell.exe

Errors Received

Ein Verbindungsversuch ist fehlgeschlagen, da die Gegenstelle nach einer bestimmten Zeitspanne nicht richtig reagiert
hat, oder die hergestellte Verbindung war fehlerhaft, da der verbundene Host nicht reagiert hat 40.126.1.130:443
In C:\Windows\system32\WindowsPowerShell\v1.0\Modules\dbatools\1.0.75\allcommands.ps1:81878 Zeichen:9
+         throw $records[0]
+         ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], Exception
    + FullyQualifiedErrorId : dbatools_Connect-DbaInstance

Steps to Reproduce

Connect-DbaInstance -SqlInstance "servername.database.windows.net:1433" -SqlCredential $cred -Database DatabaseName -Tenant TenantID

also tried

Connect-DbaInstance -SqlInstance "servername.database.windows.net" -SqlCredential $cred -Database DatabaseName -Tenant TenantID

Expected Behavior

  • Connection via Port 1433 and not port 443
  • invoke-sqlcmd works like a charm, just with the DBATools not

Actual Behavior

Connection is timed out as it is trying to connect with 443 and not SQL port 1433. Port 443 is blocked on our server, so I cannot connect to the azure database. As a test we opened port 443 on the firewall and the connection was established right after.

schupat avatar Dec 11 '19 16:12 schupat

Additional Info: Account used to connect is a Azure Service Principle

schupat avatar Dec 11 '19 16:12 schupat

@wsmelton I got this message send from Github but cannot see it anymore: "We do not control the port requirements or what port is used. Azure does and Azure SQL requires port 443, you don't have any other option for it."

Strange thing is that invoke-sqlcmd works on the same server and is only using Port 1433.

schupat avatar Dec 12 '19 11:12 schupat

the way we authorize the TenantID is via their web services (port 443). I have no idea how invoke-sqlcmd is doing it without talking to web services first 🤔

potatoqualitee avatar Dec 12 '19 12:12 potatoqualitee

are you using a tenantid with invoke-sqlcmd?

potatoqualitee avatar Dec 12 '19 12:12 potatoqualitee

no, without the tenantid

schupat avatar Dec 12 '19 12:12 schupat

Yeah thats the difference. We will require port 443 when using tenantid. To use solely 1433, please use another auth method.

potatoqualitee avatar Dec 12 '19 12:12 potatoqualitee

so it will not work with the this commandlet or can I change the auth method?

schupat avatar Dec 12 '19 12:12 schupat

yes, use the auth method you are using with invoke-sqlcmd. let me know if that gives problems

potatoqualitee avatar Dec 12 '19 12:12 potatoqualitee

$AzureDBConnection = @{ ServerInstance = "servername.database.windows.net" Database = "databaseName" credential = New-Object System.Management.Automation.PSCredential ("useraccount", $securePass) EncryptConnection = $True ErrorAction = "Stop" } invoke-sqlcmd @AzureDBConnection -Query "Select * from table"

I'm not specifiying any auth method or did I misunderstood you

schupat avatar Dec 12 '19 12:12 schupat

I am referrring to Connect-DbaInstance as listed above: Connect-DbaInstance -SqlInstance "servername.database.windows.net:1433" -SqlCredential $cred -Database DatabaseName -Tenant TenantID

Can You do

$AzureDBConnection = @{
SqlInstance = "servername.database.windows.net"
Database = "databaseName"
SqlCredential = New-Object System.Management.Automation.PSCredential ("useraccount", $securePass)
EncryptConnection = $True
ErrorAction = "Stop"
}
Connect-DbaInstance @AzureDBConnection

potatoqualitee avatar Dec 12 '19 12:12 potatoqualitee

I get a "Login failed for user 'AppID'"

schupat avatar Dec 12 '19 15:12 schupat

also the same error message if I execute the command without " -Tenant 'TenantID' "

schupat avatar Dec 12 '19 16:12 schupat

🤔 seems like logic failure on my part, but @jaykul is all up in this command. can you take a look, Joel?

potatoqualitee avatar Dec 12 '19 16:12 potatoqualitee

This issue has been automatically marked as stale because it has not had recent activity. If you would like this issue to remain open:

  • Verify that you can still reproduce the issue in the latest version of dbatools
  • Comment that the issue is still reproducible and include:
    • What version of dbatools you reproduced the issue on
    • What OS and version you reproduced the issue on
    • What steps you followed to reproduce the issue

stale[bot] avatar Feb 10 '20 16:02 stale[bot]

This issue has been automatically closed because it has not had activity in the last three months. If this issue is still valid, please add a comment

stale[bot] avatar Jun 09 '20 17:06 stale[bot]

🚧🚨 This issue is being marked as stale due to 90 days of inactivity. If you would like this issue to remain open:

  • Verify the issue/bug is reproduced in the latest version of the module
  • Verify the environmental info provided is still accurate
  • Add any additional steps you followed to reproduce if necessary 🚨🚧 ⌛️ This issue will be closed in 30 days ⌛️

github-actions[bot] avatar Sep 08 '20 06:09 github-actions[bot]

I will close this for now, but you can reopen it if this is still an issue with the current version.

andreasjordan avatar May 19 '21 07:05 andreasjordan

Hi Shawn, what do we want to do with this issue?

andreasjordan avatar Jun 05 '21 12:06 andreasjordan

I had another look at this, and in the future we will not support the use of -Tenant any more. We introduced -AccessToken as a new way to use advaned authentication methods with azure, see the last example at https://docs.dbatools.io/Connect-DbaInstance.

andreasjordan avatar Jun 14 '21 08:06 andreasjordan

We will continue to support that because there is no valid reason not to.

The parameter you speak of that was introduced requires more effort on the users part when dealing with Azure. Why? What purpose is served when the method of getting a token with New command we have can be done? @andreasjordan

wsmelton avatar Jun 14 '21 11:06 wsmelton