Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -293,6 +293,51 @@ The Google Cloud Source credentials provider will use Google Cloud Platform appl
NOTE: `com.google.auth:google-auth-library-oauth2-http` is an optional dependency.
If the `google-auth-library-oauth2-http` jar is not on your classpath, the Google Cloud Source credential provider is not created, regardless of the git server URI.

[[authentication-with-azure-devops]]
== Authentication with Azure DevOps

Spring Cloud Config Server also supports authenticating against https://dev.azure.com[Azure DevOps] Git repositories using Azure Managed Identity.

When your Git URI uses `http` or `https` and targets Azure DevOps (host `dev.azure.com`), you can enable managed identity authentication by setting `spring.cloud.config.server.git.azure.identity.managed-identity-enabled` to `true`. Spring Cloud Config Server will automatically acquire an Azure AD access token for Azure DevOps and configure HTTP Bearer token authentication on the JGit transport.

[source,yaml]
----
spring:
cloud:
config:
server:
git:
uri: https://dev.azure.com/{organization}/{project}/_git/{repo}
azure:
identity:
managed-identity-enabled: true
client-id: 00000000-0000-0000-0000-000000000000 # optional, for user-assigned managed identity
----

If using a user-assigned managed identity, specify the client ID using `spring.cloud.config.server.git.azure.identity.client-id`. For system-assigned managed identity, `client-id` can be omitted.

The property can also be configured per-repository when using multiple repositories:

[source,yaml]
----
spring:
cloud:
config:
server:
git:
repos:
my-azure-repo:
pattern: azure-app*
uri: https://dev.azure.com/{organization}/{project}/_git/{repo}
azure:
identity:
managed-identity-enabled: true
client-id: 00000000-0000-0000-0000-000000000000
----

NOTE: `com.azure:azure-identity` is an optional dependency.
If the `azure-identity` jar is not on your classpath, the Azure DevOps managed identity credentials provider will not be created, regardless of the Git server URI.

[[git-ssh-configuration-using-properties]]
== Git SSH configuration using properties

Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<bintray.package>config</bintray.package>
<spring-cloud-commons.version>5.0.3-SNAPSHOT</spring-cloud-commons.version>
<aws-java-sdk.version>2.39.6</aws-java-sdk.version>
<azure-identity.version>1.18.4</azure-identity.version>
<google-libraries-bom.version>26.71.0</google-libraries-bom.version>
<google-api-services-iam.version>v2-rev20250502-2.0.0</google-api-services-iam.version>
<google-cloud-iamcredentials.version>2.60.0</google-cloud-iamcredentials.version>
Expand Down
6 changes: 6 additions & 0 deletions spring-cloud-config-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@
<artifactId>google-auth-library-oauth2-http</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>${azure-identity.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2013-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.cloud.config.server.config;

import com.azure.identity.ManagedIdentityCredential;
import org.eclipse.jgit.api.TransportConfigCallback;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cloud.config.server.support.AzureDevOpsWorkloadIdentitySupport;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ ManagedIdentityCredential.class, TransportConfigCallback.class })
public class AzureDevOpsWorkloadIdentityConfiguration {

@Bean
public AzureDevOpsWorkloadIdentitySupport createAzureDevOpsWorkloadIdentitySupport() {
return new AzureDevOpsWorkloadIdentitySupport();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
import org.springframework.cloud.config.server.environment.vault.SpringVaultEnvironmentRepositoryFactory;
import org.springframework.cloud.config.server.environment.vault.SpringVaultTemplateBuilder;
import org.springframework.cloud.config.server.support.GitCredentialsProviderFactory;
import org.springframework.cloud.config.server.support.GoogleCloudSourceSupport;
import org.springframework.cloud.config.server.support.GitTransportConfigCallbackProvider;
import org.springframework.cloud.config.server.support.TransportConfigCallbackFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -126,7 +126,8 @@
@Import({ CompositeRepositoryConfiguration.class, JdbcRepositoryConfiguration.class, VaultConfiguration.class,
SpringVaultRepositoryConfiguration.class, CredhubConfiguration.class, CredhubRepositoryConfiguration.class,
SvnRepositoryConfiguration.class, NativeRepositoryConfiguration.class, GitRepositoryConfiguration.class,
RedisRepositoryConfiguration.class, GoogleCloudSourceConfiguration.class, AwsS3RepositoryConfiguration.class,
RedisRepositoryConfiguration.class, GoogleCloudSourceConfiguration.class,
AzureDevOpsWorkloadIdentityConfiguration.class, AwsS3RepositoryConfiguration.class,
AwsSecretsManagerRepositoryConfiguration.class, AwsParameterStoreRepositoryConfiguration.class,
GoogleSecretManagerRepositoryConfiguration.class, MongoRepositoryConfiguration.class,
// DefaultRepositoryConfiguration must be last
Expand Down Expand Up @@ -189,11 +190,11 @@ public MultipleJGitEnvironmentRepositoryFactory gitEnvironmentRepositoryFactory(
ConfigurableEnvironment environment, ConfigServerProperties server,
Optional<ConfigurableHttpConnectionFactory> jgitHttpConnectionFactory,
Optional<TransportConfigCallback> customTransportConfigCallback,
Optional<GoogleCloudSourceSupport> googleCloudSourceSupport,
ObjectProvider<GitTransportConfigCallbackProvider> callbackProviders,
GitCredentialsProviderFactory gitCredentialsProviderFactory,
List<HttpClient4BuilderCustomizer> customizers) {
final TransportConfigCallbackFactory transportConfigCallbackFactory = new TransportConfigCallbackFactory(
customTransportConfigCallback.orElse(null), googleCloudSourceSupport.orElse(null));
customTransportConfigCallback.orElse(null), callbackProviders.orderedStream().toList());
return new MultipleJGitEnvironmentRepositoryFactory(environment, server, jgitHttpConnectionFactory,
transportConfigCallbackFactory, gitCredentialsProviderFactory, customizers);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ public class JGitEnvironmentProperties extends AbstractScmAccessorProperties
*/
private boolean strictHostKeyChecking = true;

/**
* Azure DevOps properties.
*/
private AzureProperties azure = new AzureProperties();

/**
* HTTP proxy configuration.
*/
Expand Down Expand Up @@ -273,4 +278,58 @@ public void setTryMasterBranch(boolean tryMasterBranch) {
this.tryMasterBranch = tryMasterBranch;
}

public AzureProperties getAzure() {
return this.azure;
}

public void setAzure(AzureProperties azure) {
this.azure = azure;
}

public static class AzureProperties {

Comment thread
abhiramaab marked this conversation as resolved.
Resolved
private Identity identity = new Identity();

public Identity getIdentity() {
return this.identity;
}

public void setIdentity(Identity identity) {
this.identity = identity;
}

public static class Identity {

/**
* Client ID of the Azure managed identity used for Azure DevOps
* authentication.
*/
private String clientId;

/**
* Whether managed identity authentication is enabled for Azure DevOps
* repositories.
*/
private boolean managedIdentityEnabled;

public String getClientId() {
return this.clientId;
}

public void setClientId(String clientId) {
this.clientId = clientId;
}

public boolean isManagedIdentityEnabled() {
return this.managedIdentityEnabled;
}

public void setManagedIdentityEnabled(boolean managedIdentityEnabled) {
this.managedIdentityEnabled = managedIdentityEnabled;
}

}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright 2013-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.cloud.config.server.support;

import java.net.URISyntaxException;
import java.util.Map;
import java.util.function.Supplier;

import com.azure.core.credential.AccessToken;
import com.azure.core.credential.TokenCredential;
import com.azure.core.credential.TokenRequestContext;
import com.azure.identity.ManagedIdentityCredentialBuilder;
import org.eclipse.jgit.api.TransportConfigCallback;
import org.eclipse.jgit.transport.TransportHttp;
import org.eclipse.jgit.transport.URIish;

import org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentProperties;
import org.springframework.util.StringUtils;

public class AzureDevOpsWorkloadIdentitySupport implements GitTransportConfigCallbackProvider {

private static final String AZURE_DEVOPS_HOST = "dev.azure.com";

private static final String AZURE_DEVOPS_SCOPE = "499b84ac-1321-427f-aa17-267ca6975798/.default";

@Override
public boolean canHandle(MultipleJGitEnvironmentProperties properties) {
return properties.getAzure() != null && properties.getAzure().getIdentity() != null
&& properties.getAzure().getIdentity().isManagedIdentityEnabled() && canHandle(properties.getUri());
}

@Override
public TransportConfigCallback createTransportConfigCallback(MultipleJGitEnvironmentProperties properties) {
String clientId = properties.getAzure() != null && properties.getAzure().getIdentity() != null
? properties.getAzure().getIdentity().getClientId() : null;
return createTransportConfigCallback(clientId);
}

public boolean canHandle(String uri) {
if (!StringUtils.hasText(uri)) {
return false;
}
try {
URIish urish = new URIish(uri);
Comment thread
abhiramaab marked this conversation as resolved.
Resolved
return ("http".equals(urish.getScheme()) || "https".equals(urish.getScheme()))
&& AZURE_DEVOPS_HOST.equalsIgnoreCase(urish.getHost());
}
catch (URISyntaxException ex) {
return false;
}
}

public TransportConfigCallback createTransportConfigCallback(String clientId) {
ManagedIdentityCredentialBuilder builder = new ManagedIdentityCredentialBuilder();
if (StringUtils.hasText(clientId)) {
builder.clientId(clientId);
}
TokenCredential credential = builder.build();
return createTransportConfigCallback(() -> {
AccessToken accessToken = credential.getToken(new TokenRequestContext().addScopes(AZURE_DEVOPS_SCOPE))
.block();
return accessToken != null ? accessToken.getToken() : null;
});
}

TransportConfigCallback createTransportConfigCallback(Supplier<String> tokenSupplier) {
return transport -> {
if (transport instanceof TransportHttp && canHandle(transport.getURI().toString())) {
String accessToken = tokenSupplier.get();

if (accessToken != null) {
((TransportHttp) transport).setAdditionalHeaders(Map.of("Authorization", "Bearer " + accessToken));
}
}
};
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2013-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.cloud.config.server.support;

import org.eclipse.jgit.api.TransportConfigCallback;

import org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentProperties;

/**
* Strategy interface for providing a JGit {@link TransportConfigCallback} for a specific
* type of Git hosting service.
*
* <p>
* Implementations are registered as optional Spring beans. The
* {@link TransportConfigCallbackFactory} iterates through all available providers and
* delegates to the first one that can handle the repository URI.
*/
public interface GitTransportConfigCallbackProvider {

/**
* Returns {@code true} if this provider can handle the given properties.
* @param properties the JGit environment properties for the repository
* @return {@code true} if this provider should be used
*/
boolean canHandle(MultipleJGitEnvironmentProperties properties);

/**
* Creates a {@link TransportConfigCallback} for the given properties.
* @param properties the JGit environment properties for the repository
* @return a configured {@link TransportConfigCallback}
*/
TransportConfigCallback createTransportConfigCallback(MultipleJGitEnvironmentProperties properties);

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import org.eclipse.jgit.transport.TransportHttp;
import org.eclipse.jgit.transport.URIish;

import org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentProperties;
import org.springframework.util.StringUtils;

import static java.util.stream.Collectors.toMap;

/**
Expand All @@ -42,9 +45,22 @@
* "https://cloud.google.com/sdk/gcloud/reference/auth/application-default/login"> gcloud
* auth application-default login</a>
*/
public final class GoogleCloudSourceSupport {
public final class GoogleCloudSourceSupport implements GitTransportConfigCallbackProvider {

@Override
public boolean canHandle(MultipleJGitEnvironmentProperties properties) {
return properties != null && canHandle(properties.getUri());
}

@Override
public TransportConfigCallback createTransportConfigCallback(MultipleJGitEnvironmentProperties properties) {
return createTransportConfigCallback();
}

boolean canHandle(String uri) {
if (!StringUtils.hasText(uri)) {
return false;
}
try {
return GCSTransportConfigCallback.canHandle(new URIish(uri));
}
Expand Down
Loading
Loading