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

Add EnvVar AZURE_AUTHORITY_HOST #9324

Closed
wants to merge 60 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
b5f7596
Make azure resource creation can be disabled. (#7335)
mitchdenny Jan 10, 2020
a781f99
Keyvault ARM template for live test (#7340)
hemanttanwar Jan 10, 2020
a68aca1
Fix dyanmic resource deprovision (#7343)
danieljurek Jan 10, 2020
0213d7c
Update README.md
weshaggard Jan 10, 2020
dd6c261
Remove OpenCensus tracing support for Java SDKs (#7167)
samvaity Jan 10, 2020
574f7bc
port https://github.com/Azure/azure-sdk-for-java/pull/6835 from v4 (#…
moderakh Jan 10, 2020
409efc5
Return empty string on empty content response from backend (#7347)
kushagraThapar Jan 11, 2020
14c8c1d
Added missing variables from ARM deployment, fixed expected environme…
alzimmermsft Jan 13, 2020
10e4bd5
Initial commit to add API to retrieve min throughput for a CosmosCont…
abinav2307 Jan 13, 2020
0c76069
Support AM/PM in MSI token (#7356)
jianghaolu Jan 13, 2020
7a16996
Encryption client from regular client (#7242)
gapra-msft Jan 13, 2020
72f8152
Jan Release readme fix/ changes (#7395)
hemanttanwar Jan 13, 2020
eaad511
Post release version update (#7399)
kushagraThapar Jan 13, 2020
8c44c17
Update identity to 1.0.3 (#7398)
jianghaolu Jan 13, 2020
7d14750
Move cosmosdb to cosmos (#7384)
mitchdenny Jan 14, 2020
585add2
Disabld feature CI trigger. (#7363)
mitchdenny Jan 14, 2020
105660c
Update documentation and in-memory checkpoint store sample (#7389)
srnagar Jan 14, 2020
e9e5e53
Prep for doc warden updates (#7405)
chidozieononiwu Jan 14, 2020
9def363
Post identity 1.0.3 release version update (#7407)
jianghaolu Jan 14, 2020
379dddf
Continue to use same .receive() method on disconnection (#7336)
conniey Jan 14, 2020
f93ec77
Updated storage versions post January release (#7397)
gapra-msft Jan 14, 2020
48171b1
Fixed retry logic on writes on forbidden status (#7402)
kushagraThapar Jan 14, 2020
0f27ea7
Add az namespace span attribute for App config (#7097)
samvaity Jan 14, 2020
3670d35
[After MSAL 1.3] Pluggable HTTP in identity/msal (#7120)
jianghaolu Jan 14, 2020
5b62f09
[After Jan 7] Removing dependency on java.desktop module. (#6877)
JonathanGiles Jan 14, 2020
d68f40b
Lower branch coverage threshold for Identity (#7433)
srnagar Jan 15, 2020
572a47a
Update Download To File Write Logic (#7403)
alzimmermsft Jan 15, 2020
f819bb4
Updated release version to 3.6.0 (#7428)
kushagraThapar Jan 15, 2020
7232b92
Feature/release verify (#7386)
JimSuplizio Jan 15, 2020
a5aba4c
revert license changes (#7387)
sima-zhu Jan 15, 2020
44cc9c4
Update TextSentimentClass to extend ExpandableStringEnum (#7427)
samvaity Jan 15, 2020
74f58ab
Added an overload for listing with a continuation token (#7388)
gapra-msft Jan 15, 2020
62ceaf6
Added ability to create service clients anonymously (#7421)
gapra-msft Jan 15, 2020
ee1925d
Fixed upload from file using FluxUtil.write in a manner where the und…
alzimmermsft Jan 15, 2020
b89d97c
Added client side checks for account set props (#7426)
gapra-msft Jan 15, 2020
cc9158a
Post release version update to 3.7.0-beta.1 (#7478)
kushagraThapar Jan 15, 2020
481cf3b
fixes some bugs and add tests to improve code coveragwe (#7401)
mssfang Jan 15, 2020
3e65a46
Updated Readme and changelog for storage release (#7484)
gapra-msft Jan 15, 2020
bbeeed3
Placeholder pipeline for aggregate report generation. (#7486)
mitchdenny Jan 16, 2020
274ae66
Move aggregate reports up.: (#7487)
mitchdenny Jan 16, 2020
6b2c11e
Implements a slf4j logger impl as default logger in azure core (#7298)
sima-zhu Jan 16, 2020
9b198d6
Replace AutoCloseable with reactor's Disposable. Retry and timeout fi…
conniey Jan 16, 2020
fb3937a
Eventhubs ARM template for live test (#7344)
hemanttanwar Jan 16, 2020
3c3900a
Fix cancellation handling (#7430)
mitchdenny Jan 16, 2020
fc90101
add build qualifier to unreleased version (#7501)
JimSuplizio Jan 16, 2020
a18cd1a
Retry network operations in resources scripts (#7510)
heaths Jan 17, 2020
9ef4b0d
Fix up SDKType parameter condition. (#7512)
mitchdenny Jan 17, 2020
570f57f
Paged Flux abstractions (#6465)
anuchandy Jan 17, 2020
6b58732
Clears closed/errored sessions and links (#7534)
conniey Jan 18, 2020
f6b17a9
add support for AuthFileCredential
Luyunmt Jan 20, 2020
ddf0754
change comments in AuthFileCredentialBuilder.java
Luyunmt Jan 20, 2020
bec2c22
change exception,add test and move method ensurecredential
Jan 22, 2020
e923537
change extends and change exception
Jan 22, 2020
74799df
remove method ensurecredential
Luyunmt Feb 4, 2020
f7bb92a
move ensurecredential to gettoken
Luyunmt Feb 5, 2020
b0a7bcd
add synchronize and update code format
Luyunmt Feb 28, 2020
6fedf1d
change test and field
Luyunmt Mar 2, 2020
210fa43
add String constant
Luyunmt Mar 3, 2020
6cf7679
add authfilecredential into environmentcredential
Luyunmt Mar 18, 2020
9cbbb8c
add environment variable authorityhost
Luyunmt Mar 20, 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
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public class Configuration implements Cloneable {
*/
public static final String PROPERTY_AZURE_TENANT_ID = "AZURE_TENANT_ID";

/**
* Path of a PEM certificate file to use when performing service principal authentication with Azure.
*/
public static final String PROPERTY_AZURE_CLIENT_CERTIFICATE_PATH = "AZURE_CLIENT_CERTIFICATE_PATH";

/**
* Name of the Azure resource group.
*/
Expand All @@ -83,7 +88,7 @@ public class Configuration implements Cloneable {
/**
* Name of the Azure cloud to connect to.
*/
public static final String PROPERTY_AZURE_CLOUD = "AZURE_CLOUD";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing/renaming a public env variable that is already released is considered a breaking change. Can this env var be retained and PROPERTY_AZURE_AUTHORITY_HOST be added as a new env var?

public static final String PROPERTY_AZURE_AUTHORITY_HOST = "AZURE_AUTHORITY_HOST";

/**
* Disables telemetry collection.
Expand Down Expand Up @@ -115,8 +120,9 @@ public class Configuration implements Cloneable {
PROPERTY_AZURE_CLIENT_ID,
PROPERTY_AZURE_CLIENT_SECRET,
PROPERTY_AZURE_TENANT_ID,
PROPERTY_AZURE_CLIENT_CERTIFICATE_PATH,
PROPERTY_AZURE_RESOURCE_GROUP,
PROPERTY_AZURE_CLOUD,
PROPERTY_AZURE_AUTHORITY_HOST,
PROPERTY_AZURE_TELEMETRY_DISABLED,
PROPERTY_AZURE_LOG_LEVEL,
PROPERTY_AZURE_TRACING_DISABLED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,28 @@
import reactor.core.publisher.Mono;

/**
* A credential provider that provides token credentials based on environment variables. The environment variables
* A credential provider that provides token credentials based on environment variables. The sets of environment variables
* expected are:
* <p>
* <ul>
* <li>{@link Configuration#PROPERTY_AZURE_CLIENT_ID AZURE_CLIENT_ID}</li>
* <li>{@link Configuration#PROPERTY_AZURE_CLIENT_SECRET AZURE_CLIENT_SECRET}</li>
* <li>{@link Configuration#PROPERTY_AZURE_TENANT_ID AZURE_TENANT_ID}</li>
* </ul>
* or:
* <p>
* <ul>
* <li>{@link Configuration#PROPERTY_AZURE_CLIENT_ID AZURE_CLIENT_ID}</li>
* <li>{@link Configuration#PROPERTY_AZURE_CLIENT_CERTIFICATE_PATH AZURE_CLIENT_CERTIFICATE_PATH}</li>
* <li>{@link Configuration#PROPERTY_AZURE_TENANT_ID AZURE_TENANT_ID}</li>
* </ul>
* or:
* <p>
* <ul>
* <li>{@link Configuration#PROPERTY_AZURE_CLIENT_ID AZURE_CLIENT_ID}</li>
* <li>{@link Configuration#PROPERTY_AZURE_USERNAME AZURE_USERNAME}</li>
* <li>{@link Configuration#PROPERTY_AZURE_PASSWORD AZURE_PASSWORD}</li>
* </ul>
*/
@Immutable
public class EnvironmentCredential implements TokenCredential {
Expand All @@ -41,15 +55,22 @@ public class EnvironmentCredential implements TokenCredential {

@Override
public Mono<AccessToken> getToken(TokenRequestContext request) {
String clientId = configuration.get(Configuration.PROPERTY_AZURE_CLIENT_ID);
String tenantId = configuration.get(Configuration.PROPERTY_AZURE_TENANT_ID);
String clientSecret = configuration.get(Configuration.PROPERTY_AZURE_CLIENT_SECRET);
String certPath = configuration.get(Configuration.PROPERTY_AZURE_CLIENT_CERTIFICATE_PATH);
String username = configuration.get(Configuration.PROPERTY_AZURE_USERNAME);
String password = configuration.get(Configuration.PROPERTY_AZURE_PASSWORD);
Comment on lines +58 to +63
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason these have to be initialized synchronously?

return Mono.fromSupplier(() -> {
if (configuration.contains(Configuration.PROPERTY_AZURE_CLIENT_ID)
&& configuration.contains(Configuration.PROPERTY_AZURE_CLIENT_SECRET)
&& configuration.contains(Configuration.PROPERTY_AZURE_TENANT_ID)) {
// TODO: support other clouds
return new ClientSecretCredential(configuration.get(Configuration.PROPERTY_AZURE_TENANT_ID),
configuration.get(Configuration.PROPERTY_AZURE_CLIENT_ID),
configuration.get(Configuration.PROPERTY_AZURE_CLIENT_SECRET),
identityClientOptions);
if (verifyNotNull(clientId)) {
if (verifyNotNull(tenantId, clientSecret)) {
// TODO: support other clouds
return new ClientSecretCredential(tenantId, clientId, clientSecret, identityClientOptions);
} else if (verifyNotNull(tenantId, certPath)) {
return new ClientCertificateCredential(tenantId, clientId, certPath, null, identityClientOptions);
} else if (verifyNotNull(username, password)) {
return new UsernamePasswordCredential(clientId, tenantId, username, password, identityClientOptions);
}
}

// Other environment variables
Expand All @@ -58,4 +79,13 @@ public Mono<AccessToken> getToken(TokenRequestContext request) {
null));
}).flatMap(cred -> cred.getToken(request));
}

private boolean verifyNotNull(String... configs){
for(String config: configs){
if(config == null){
return false;
}
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.azure.core.credential.AccessToken;
import com.azure.core.credential.TokenRequestContext;
import com.azure.core.exception.ClientAuthenticationException;
import com.azure.core.http.ProxyOptions;
import com.azure.core.util.serializer.SerializerAdapter;
import com.azure.core.util.serializer.SerializerEncoding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public final class IdentityClientOptions {
* Creates an instance of IdentityClientOptions with default settings.
*/
public IdentityClientOptions() {
authorityHost = DEFAULT_AUTHORITY_HOST;
Configuration configuration = Configuration.getGlobalConfiguration();
authorityHost = configuration.contains(configuration.PROPERTY_AZURE_AUTHORITY_HOST)
? configuration.get(configuration.PROPERTY_AZURE_AUTHORITY_HOST) : DEFAULT_AUTHORITY_HOST;
maxRetry = MAX_RETRY_DEFAULT_LIMIT;
retryTimeout = i -> Duration.ofSeconds((long) Math.pow(2, i.getSeconds() - 1));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

public class EnvironmentCredentialTests {
@Test
public void testCreateEnvironmentCredential() {
Configuration configuration = Configuration.getGlobalConfiguration();
configuration.put(Configuration.PROPERTY_AZURE_CLIENT_ID, "foo");
configuration.put(Configuration.PROPERTY_AZURE_CLIENT_SECRET, "bar");
configuration.put(Configuration.PROPERTY_AZURE_TENANT_ID, "baz");
public void testCreateEnvironmentClientSecretCredential() {
Configuration.getGlobalConfiguration()
.put(Configuration.PROPERTY_AZURE_CLIENT_ID, "foo")
.put(Configuration.PROPERTY_AZURE_USERNAME, "bar")
.put(Configuration.PROPERTY_AZURE_PASSWORD, "baz");

EnvironmentCredential credential = new EnvironmentCredentialBuilder().build();

Expand All @@ -36,4 +36,46 @@ public void testCreateEnvironmentCredential() {
.expectNextMatches(token -> "token".equals(token.getToken()))
.verifyComplete();
}

@Test
public void testCreateEnvironmentClientCertificateCredential() {
Configuration.getGlobalConfiguration()
.put(Configuration.PROPERTY_AZURE_CLIENT_ID, "foo")
.put(Configuration.PROPERTY_AZURE_USERNAME, "bar")
.put(Configuration.PROPERTY_AZURE_PASSWORD, "baz");

EnvironmentCredential credential = new EnvironmentCredentialBuilder().build();

// authentication will fail client-id=foo, but should be able to create ClientCertificateCredential
StepVerifier.create(credential.getToken(new TokenRequestContext().addScopes("qux/.default"))
.doOnSuccess(s -> fail())
.onErrorResume(t -> {
String message = t.getMessage();
Assert.assertFalse(message != null && message.contains("Cannot create any credentials with the current environment variables"));
return Mono.just(new AccessToken("token", OffsetDateTime.MAX));
}))
.expectNextMatches(token -> "token".equals(token.getToken()))
.verifyComplete();
}

@Test
public void testCreateEnvironmentUserPasswordCredential() {
Configuration.getGlobalConfiguration()
.put(Configuration.PROPERTY_AZURE_CLIENT_ID, "foo")
.put(Configuration.PROPERTY_AZURE_USERNAME, "bar")
.put(Configuration.PROPERTY_AZURE_PASSWORD, "baz");

EnvironmentCredential credential = new EnvironmentCredentialBuilder().build();

// authentication will fail client-id=foo, but should be able to create UsernamePasswordCredential
StepVerifier.create(credential.getToken(new TokenRequestContext().addScopes("qux/.default"))
.doOnSuccess(s -> fail())
.onErrorResume(t -> {
String message = t.getMessage();
Assert.assertFalse(message != null && message.contains("Cannot create any credentials with the current environment variables"));
return Mono.just(new AccessToken("token", OffsetDateTime.MAX));
}))
.expectNextMatches(token -> "token".equals(token.getToken()))
.verifyComplete();
}
}