-
Notifications
You must be signed in to change notification settings - Fork 375
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
Support for Managed Identity for Azure resources #875
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
8f9ecde
Merge pull request #787 from Microsoft/dev
yitam 9654020
Dev (#820)
yitam ff3c6a4
Merge branch 'master' into dev
yitam b47cec2
Dev to Master - 5.4.0-preview (#853)
yitam 0fa3a43
Merge branch 'master' of https://github.com/Microsoft/msphpsql
yitam 80442d4
Change readme links to https
BackEndTea 14acf00
Merge pull request #857 from BackEndTea/patch-1
david-puglielli 097c06f
Merge branch 'master' of https://github.com/Microsoft/msphpsql
yitam eb679ea
Update survey image link
2e13851
Merge branch 'master' of https://github.com/Microsoft/msphpsql
yitam f831c9e
Merge branch 'master' into dev
yitam b69c824
Merge branch 'dev' of https://github.com/Microsoft/msphpsql into dev
yitam 3919628
Merge branch 'dev' of https://github.com/Microsoft/msphpsql into dev
yitam 1bdbf86
Merge branch 'dev' of https://github.com/Microsoft/msphpsql into dev
yitam e3d897f
Merge branch 'dev' of https://github.com/Microsoft/msphpsql into dev
yitam 313913a
Merge branch 'dev' of https://github.com/Microsoft/msphpsql into dev
yitam 2b3b7da
Merge branch 'dev' of https://github.com/Microsoft/msphpsql into dev
yitam 7d45079
Merge branch 'dev' of https://github.com/Microsoft/msphpsql into dev
yitam 4d2ebb9
Merge branch 'dev' of https://github.com/Microsoft/msphpsql into dev
yitam 28404e8
Merge branch 'dev' of https://github.com/Microsoft/msphpsql into dev
yitam d65f6a3
Merge branch 'dev' of https://github.com/Microsoft/msphpsql into dev
yitam 7653e96
Merge branch 'dev' of https://github.com/Microsoft/msphpsql into dev
yitam 2281bc2
Merge branch 'dev' of https://github.com/Microsoft/msphpsql into dev
yitam bbc58c5
Support for Managed Identity for Azure resources
yitam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
test/functional/pdo_sqlsrv/pdo_azure_ad_managed_identity.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
--TEST-- | ||
Test some error conditions of Azure AD Managed Identity support | ||
--DESCRIPTION-- | ||
This test expects certain exceptions to be thrown under some conditions. | ||
--SKIPIF-- | ||
<?php require('skipif.inc');?> | ||
--FILE-- | ||
<?php | ||
require_once("MsCommon_mid-refactor.inc"); | ||
|
||
function verifyErrorMessage($exception, $expectedError, $msg) | ||
{ | ||
if (strpos($exception->getMessage(), $expectedError) === false) { | ||
echo "AzureAD Managed Identity test: expected to fail with $msg\n"; | ||
|
||
print_r($exception->getMessage()); | ||
echo "\n"; | ||
} | ||
} | ||
|
||
function connectWithInvalidOptions() | ||
{ | ||
global $server; | ||
|
||
$message = 'AzureAD Managed Identity test: expected to fail with '; | ||
$expectedError = 'When using ActiveDirectoryMsi Authentication, PWD must be NULL. UID can be NULL, but if not, an empty string is not accepted'; | ||
|
||
$uid = ''; | ||
$connectionInfo = "Authentication = ActiveDirectoryMsi;"; | ||
$testCase = 'empty UID provided'; | ||
try { | ||
$conn = new PDO("sqlsrv:server = $server; $connectionInfo", $uid); | ||
echo $message . $testCase . PHP_EOL; | ||
} catch(PDOException $e) { | ||
verifyErrorMessage($e, $expectedError, $testCase); | ||
} | ||
unset($connectionInfo); | ||
|
||
$pwd = ''; | ||
$connectionInfo = "Authentication = ActiveDirectoryMsi;"; | ||
$testCase = 'empty PWD provided'; | ||
try { | ||
$conn = new PDO("sqlsrv:server = $server; $connectionInfo", null, $pwd); | ||
echo $message . $testCase . PHP_EOL; | ||
} catch(PDOException $e) { | ||
verifyErrorMessage($e, $expectedError, $testCase); | ||
} | ||
unset($connectionInfo); | ||
|
||
$pwd = 'dummy'; | ||
$connectionInfo = "Authentication = ActiveDirectoryMsi;"; | ||
$testCase = 'PWD provided'; | ||
try { | ||
$conn = new PDO("sqlsrv:server = $server; $connectionInfo", null, $pwd); | ||
echo $message . $testCase . PHP_EOL; | ||
} catch(PDOException $e) { | ||
verifyErrorMessage($e, $expectedError, $testCase); | ||
} | ||
unset($connectionInfo); | ||
|
||
$expectedError = 'When using Azure AD Access Token, the connection string must not contain UID, PWD, or Authentication keywords.'; | ||
$connectionInfo = "Authentication = ActiveDirectoryMsi; AccessToken = '123';"; | ||
$testCase = 'AccessToken option'; | ||
try { | ||
$conn = new PDO("sqlsrv:server = $server; $connectionInfo"); | ||
echo $message . $testCase . PHP_EOL; | ||
} catch(PDOException $e) { | ||
verifyErrorMessage($e, $expectedError, $testCase); | ||
} | ||
unset($connectionInfo); | ||
} | ||
|
||
function connectInvalidServer() | ||
{ | ||
global $server, $driver, $uid, $pwd; | ||
|
||
try { | ||
$conn = new PDO("sqlsrv:server = $server; driver=$driver;", $uid, $pwd); | ||
|
||
$msodbcsqlVer = $conn->getAttribute(PDO::ATTR_CLIENT_VERSION)["DriverVer"]; | ||
$version = explode(".", $msodbcsqlVer); | ||
|
||
if ($version[0] < 17 || $version[1] < 3) { | ||
//skip the rest of this test, which requires ODBC driver 17.3 or above | ||
return; | ||
} | ||
unset($conn); | ||
|
||
// Try connecting to an invalid server, should get an exception from ODBC | ||
$connectionInfo = "Authentication = ActiveDirectoryMsi;"; | ||
$testCase = 'invalidServer'; | ||
try { | ||
$conn = new PDO("sqlsrv:server = invalidServer; $connectionInfo", null, null); | ||
echo $message . $testCase . PHP_EOL; | ||
} catch(PDOException $e) { | ||
// TODO: check the exception message here | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part is missing? For the sqlsrv test too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this we have to wait for ODBC 17.3 official release |
||
} | ||
} catch(PDOException $e) { | ||
print_r($e->getMessage()); | ||
} | ||
} | ||
|
||
require_once('MsSetup.inc'); | ||
|
||
// Test some error conditions | ||
connectWithInvalidOptions(); | ||
|
||
// Make a connection to an invalid server | ||
connectInvalidServer(); | ||
|
||
echo "Done\n"; | ||
?> | ||
--EXPECT-- | ||
Done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
test/functional/sqlsrv/sqlsrv_azure_ad_managed_identity.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
--TEST-- | ||
Test some error conditions of Azure AD Managed Identity support | ||
--DESCRIPTION-- | ||
This test expects certain exceptions to be thrown under some conditions. | ||
--SKIPIF-- | ||
<?php require('skipif.inc');?> | ||
--FILE-- | ||
<?php | ||
require_once("MsCommon.inc"); | ||
|
||
function verifyErrorMessage($conn, $expectedError, $msg) | ||
{ | ||
if ($conn === false) { | ||
if (strpos(sqlsrv_errors($conn)[0]['message'], $expectedError) === false) { | ||
print_r(sqlsrv_errors()); | ||
} | ||
} else { | ||
fatalError("AzureAD Managed Identity test: expected to fail with $msg\n"); | ||
} | ||
} | ||
|
||
function connectWithInvalidOptions() | ||
{ | ||
global $server; | ||
|
||
$expectedError = 'When using ActiveDirectoryMsi Authentication, PWD must be NULL. UID can be NULL, but if not, an empty string is not accepted'; | ||
|
||
$connectionInfo = array("UID"=>"", "Authentication" => "ActiveDirectoryMsi"); | ||
$conn = sqlsrv_connect($server, $connectionInfo); | ||
verifyErrorMessage($conn, $expectedError, 'empty UID provided'); | ||
unset($connectionInfo); | ||
|
||
$connectionInfo = array("PWD"=>"", "Authentication" => "ActiveDirectoryMsi"); | ||
$conn = sqlsrv_connect($server, $connectionInfo); | ||
verifyErrorMessage($conn, $expectedError, 'empty PWD provided'); | ||
unset($connectionInfo); | ||
|
||
$connectionInfo = array("PWD"=>"pwd", "Authentication" => "ActiveDirectoryMsi"); | ||
$conn = sqlsrv_connect($server, $connectionInfo); | ||
verifyErrorMessage($conn, $expectedError, 'PWD provided'); | ||
unset($connectionInfo); | ||
|
||
$expectedError = 'When using Azure AD Access Token, the connection string must not contain UID, PWD, or Authentication keywords.'; | ||
$connectionInfo = array("Authentication"=>"ActiveDirectoryMsi", "AccessToken" => "123"); | ||
$conn = sqlsrv_connect($server, $connectionInfo); | ||
verifyErrorMessage($conn, $expectedError, 'AccessToken option'); | ||
unset($connectionInfo); | ||
} | ||
|
||
function connectInvalidServer() | ||
{ | ||
global $server, $driver, $userName, $userPassword; | ||
|
||
$connectionInfo = array("UID"=>$userName, "PWD"=>$userPassword, "Driver" => $driver); | ||
$conn = sqlsrv_connect($server, $connectionInfo); | ||
if ($conn === false) { | ||
fatalError("Failed to connect in connectInvalidServer."); | ||
} | ||
|
||
$msodbcsqlVer = sqlsrv_client_info($conn)['DriverVer']; | ||
$version = explode(".", $msodbcsqlVer); | ||
|
||
if ($version[0] < 17 || $version[1] < 3) { | ||
//skip the rest of this test, which requires ODBC driver 17.3 or above | ||
return; | ||
} | ||
sqlsrv_close($conn); | ||
|
||
// Try connecting to an invalid server, should get an exception from ODBC | ||
$connectionInfo = array("Authentication"=>"ActiveDirectoryMsi"); | ||
$conn = sqlsrv_connect('invalidServer', $connectionInfo); | ||
if ($conn) { | ||
fatalError("AzureAD Managed Identity test: expected to fail with invalidServer\n"); | ||
} else { | ||
// TODO: check the exception message here, using verifyErrorMessage() | ||
} | ||
} | ||
|
||
// Test some error conditions | ||
connectWithInvalidOptions($server); | ||
|
||
// Make a connection to an invalid server | ||
connectInvalidServer(); | ||
|
||
echo "Done\n"; | ||
?> | ||
--EXPECT-- | ||
Done |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if the user sets the keyword to something other than ActiveDirectoryMsi? Do we just pass that straight to the ODBC driver?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand the question. In terms of keywords check, please check the shared\core_conn.cpp line 733