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

Feature | Added support for authentication to Azure Key Vault using Managed Identity #1286

Merged
merged 63 commits into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
c97b863
Fix AEv2 tests exclude for reqExternalSetup and cleanup (#1247)
lilgreenbird Feb 5, 2020
54b5a19
Fix | Add null check for getObject() with LocalTime and LocalDate (#1…
peterbae Feb 8, 2020
672b7d6
added all AKV tests to use reqExternalSetup tag so they will be skipp…
lilgreenbird Feb 10, 2020
32c21f5
msi for akv
lilgreenbird Mar 4, 2020
b706fb3
Merge remote-tracking branch 'upstream/dev' into msi
lilgreenbird Mar 6, 2020
9e368a5
msi tests
lilgreenbird Mar 9, 2020
28bb1ee
added new props for AKV with MSI
lilgreenbird Mar 12, 2020
b75ebab
fixed formatting
lilgreenbird Mar 12, 2020
3ce5ad8
fixed formatting
lilgreenbird Mar 12, 2020
3a9db37
fixed formatting
lilgreenbird Mar 12, 2020
5ba6881
fixed formatting
lilgreenbird Mar 12, 2020
95948c1
test fixes
lilgreenbird Mar 12, 2020
beac701
update connection property names
lilgreenbird Mar 13, 2020
86b14ee
updated tests
lilgreenbird Mar 16, 2020
48801af
removed unused
lilgreenbird Mar 17, 2020
7cf8a68
ks registration
lilgreenbird Mar 17, 2020
a64c995
debug
lilgreenbird Mar 17, 2020
7b013e9
debug
lilgreenbird Mar 17, 2020
395790f
debug
lilgreenbird Mar 17, 2020
5bb4313
debug
lilgreenbird Mar 17, 2020
065a0f0
remove debug
lilgreenbird Mar 17, 2020
9ed54ef
remove debug
lilgreenbird Mar 17, 2020
48369bc
AE connectionstring
lilgreenbird Mar 17, 2020
7a43bfd
more tests
lilgreenbird Mar 17, 2020
c2120a3
more tests
lilgreenbird Mar 17, 2020
6dad2e4
more tests
lilgreenbird Mar 17, 2020
564350d
fixed typo
lilgreenbird Mar 17, 2020
855b71b
updated tests
lilgreenbird Mar 18, 2020
355729e
null check
lilgreenbird Mar 18, 2020
6ee6aa2
javadoc
lilgreenbird Mar 18, 2020
ee800b0
exclude MSI tests by default
lilgreenbird Mar 18, 2020
ca1d9d5
formatting
lilgreenbird Mar 18, 2020
14b6efc
merged conflicts
lilgreenbird Mar 19, 2020
604fcc3
renamed
lilgreenbird Mar 23, 2020
7e69b35
unreg all providers
lilgreenbird Mar 23, 2020
ab43dd7
fixed prop names
lilgreenbird Mar 24, 2020
7e662fe
Merge remote-tracking branch 'upstream/dev' into msi
lilgreenbird Mar 25, 2020
54832b8
review updates
lilgreenbird Mar 26, 2020
34784c7
review update
lilgreenbird Mar 27, 2020
a578f1e
migrate to azure-identity
lilgreenbird Mar 28, 2020
5392cc3
remove debug lines
lilgreenbird Mar 28, 2020
942adcc
removed unused
lilgreenbird Mar 28, 2020
d14f398
merged with client auth
lilgreenbird Mar 28, 2020
70b6a3c
removed azure-identities dependency
lilgreenbird Mar 31, 2020
8b7e3a9
missed 1 file
lilgreenbird Mar 31, 2020
8c56ba6
merged conflicts
lilgreenbird Mar 31, 2020
ff179c1
updated
lilgreenbird Mar 31, 2020
49224f5
comment changes
lilgreenbird Mar 31, 2020
2a55d5b
remove unused
lilgreenbird Mar 31, 2020
795e653
review updates
lilgreenbird Mar 31, 2020
88d5d70
more review updates
lilgreenbird Mar 31, 2020
91639a5
javadoc update
lilgreenbird Mar 31, 2020
7ddd561
updated SQLServerConnection loggingClassName
lilgreenbird Mar 31, 2020
ee0a1fb
added tests for MSI and principal id only
lilgreenbird Mar 31, 2020
906a111
review updates
lilgreenbird Mar 31, 2020
19e28a7
added more MSI auth tests
lilgreenbird Mar 31, 2020
0b0d70d
tag for testing MSI auth
lilgreenbird Mar 31, 2020
8b9e633
msi auth servers tags
lilgreenbird Mar 31, 2020
19a582e
added MSI auth w msiClientId tests
lilgreenbird Mar 31, 2020
9497069
Merge remote-tracking branch 'upstream/dev' into msi
lilgreenbird Mar 31, 2020
a1b7f14
fixed connectstr issue
lilgreenbird Apr 1, 2020
33edae9
removed unused imports
lilgreenbird Apr 1, 2020
b5f35ee
fixed resource strings
lilgreenbird Apr 1, 2020
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
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
matrix:
SQL-2019:
Target_SQL: 'HGS-2k19-01'
Ex_Groups: 'xSQLv15,clientCertAuth'
Ex_Groups: 'xSQLv15,MSI,clientCertAuth'
SQL-2012:
Target_SQL: 'SQL-2K12-SP3-1'
Ex_Groups: 'xSQLv12'
Ex_Groups: 'xSQLv12,MSI'
maxParallel: 2
steps:
- powershell: |
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
clientCertAuth - - For tests requiring client certificate authentication setup (excluded by default)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Default testing enabled with SQL Server 2019 (SQLv15) -->
<excludedGroups>xSQLv15, NTLM, reqExternalSetup, clientCertAuth</excludedGroups>
<excludedGroups>xSQLv15,NTLM,MSI,reqExternalSetup,clientCertAuth</excludedGroups>

<!-- Use -preview for preview release, leave empty for official release.-->
<releaseExt>-preview</releaseExt>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,25 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
*/
String getMSIClientId();

/**
lilgreenbird marked this conversation as resolved.
Show resolved Hide resolved
* Sets the value for the connection property 'keyStorePrincipalId'.
*
* @param keyStorePrincipalId
*
* <pre>
* When keyStoreAuthentication = keyVaultClientSecret, set this value to a valid Azure Active Directory Application Client ID.
* When keyStoreAuthentication = keyVaultManagedIdentity, set this value to a valid Azure Active Directory Application Object ID (optional, for user-assigned only).
* </pre>
*/
void setKeyStorePrincipalId(String keyStorePrincipalId);

/**
* Returns the value for the connection property 'keyStorePrincipalId'.
*
* @return keyStorePrincipalId
*/
String getKeyStorePrincipalId();

/**
* Sets the Azure Key Vault (AKV) Provider Client Id to provided value to be used for column encryption.
*
Expand Down
23 changes: 19 additions & 4 deletions src/main/java/com/microsoft/sqlserver/jdbc/KeyVaultCredential.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ class KeyVaultCredential extends KeyVaultCredentials {
String clientKey = null;
String accessToken = null;

KeyVaultCredential(String clientId) throws SQLServerException {
this.clientId = clientId;
}

KeyVaultCredential() {}

KeyVaultCredential(String clientId, String clientKey) {
this.clientId = clientId;
this.clientKey = clientKey;
Expand All @@ -37,11 +43,20 @@ class KeyVaultCredential extends KeyVaultCredentials {
}

public String doAuthenticate(String authorization, String resource, String scope) {
String accessToken;
String accessToken = null;
if (null == authenticationCallback) {
AuthenticationResult token = getAccessTokenFromClientCredentials(authorization, resource, clientId,
clientKey);
accessToken = token.getAccessToken();
if (null == clientKey) {
try {
SqlFedAuthToken token = SQLServerSecurityUtility.getMSIAuthToken(resource, clientId);
accessToken = (null != token) ? token.accessToken : null;
} catch (Exception e) {
throw new RuntimeException(e);
peterbae marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
AuthenticationResult token = getAccessTokenFromClientCredentials(authorization, resource, clientId,
clientKey);
accessToken = token.getAccessToken();
}
} else {
accessToken = authenticationCallback.getAccessToken(authorization, resource, scope);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@ public String getName() {
return this.name;
}

/**
* Constructs a SQLServerColumnEncryptionAzureKeyVaultProvider with a client id and client key to authenticate to
* AAD. This is used by KeyVaultClient at runtime to authenticate to Azure Key Vault.
*
* @param clientId
* Identifier of the client requesting the token.
* @param clientKey
* Key of the client requesting the token.
* @throws SQLServerException
* when an error occurs
*/
public SQLServerColumnEncryptionAzureKeyVaultProvider(String clientId, String clientKey) throws SQLServerException {
credentials = new KeyVaultCredential(clientId, clientKey);
keyVaultClient = new KeyVaultClient(credentials);
}

/**
* Constructs a SQLServerColumnEncryptionAzureKeyVaultProvider with a callback function to authenticate to AAD and
* an executor service.. This is used by KeyVaultClient at runtime to authenticate to Azure Key Vault.
Expand Down Expand Up @@ -129,23 +145,34 @@ public SQLServerColumnEncryptionAzureKeyVaultProvider(
}

/**
* Constructs a SQLServerColumnEncryptionAzureKeyVaultProvider with a client id and client key to authenticate to
* AAD. This is used by KeyVaultClient at runtime to authenticate to Azure Key Vault.
* Constructs a SQLServerColumnEncryptionAzureKeyVaultProvider to authenticate to AAD. This is used by
* KeyVaultClient at runtime to authenticate to Azure Key Vault.
*
* @throws SQLServerException
* when an error occurs
*/
SQLServerColumnEncryptionAzureKeyVaultProvider() throws SQLServerException {
credentials = new KeyVaultCredential();
keyVaultClient = new KeyVaultClient(credentials);
}

/**
* Constructs a SQLServerColumnEncryptionAzureKeyVaultProvider to authenticate to AAD. This is used by
* KeyVaultClient at runtime to authenticate to Azure Key Vault.
*
* @param clientId
* Identifier of the client requesting the token.
* @param clientKey
* Key of the client requesting the token.
*
* @throws SQLServerException
* when an error occurs
*/
public SQLServerColumnEncryptionAzureKeyVaultProvider(String clientId, String clientKey) throws SQLServerException {
credentials = new KeyVaultCredential(clientId, clientKey);
SQLServerColumnEncryptionAzureKeyVaultProvider(String clientId) throws SQLServerException {
credentials = new KeyVaultCredential(clientId);
keyVaultClient = new KeyVaultClient(credentials);
}

/**
* Decryptes an encrypted CEK with RSA encryption algorithm using the asymmetric key specified by the key path
* Decrypts an encrypted CEK with RSA encryption algorithm using the asymmetric key specified by the key path
*
* @param masterKeyPath
* - Complete path of an asymmetric key in AKV
Expand Down
Loading