Repository navigation
Add Azure DevOps workload identity support #3272
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
Merged
ryanjbaxter
merged 6 commits into
spring-cloud:main
from
abhiramaab:fix/azure-devops-workload-identity
Sep 17, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d4f8317
Add Azure DevOps workload identity support
abhiramaab 745b727
Address Copilot review comments for Azure DevOps workload identity su…
abhiramaab 1c6702c
Refactor transport callback to use GitTransportConfigCallbackProvider…
abhiramaab 44af7f3
Address review comments for Azure DevOps workload identity and transp…
abhiramaab b6e572d
Nest Azure identity properties under azure.identity and restore Googl…
abhiramaab 2f7b405
Document Azure DevOps workload identity authentication
abhiramaab 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
36 changes: 36 additions & 0 deletions
36
.../springframework/cloud/config/server/config/AzureDevOpsWorkloadIdentityConfiguration.java
This file contains hidden or 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,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(); | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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 hidden or 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
92 changes: 92 additions & 0 deletions
92
...a/org/springframework/cloud/config/server/support/AzureDevOpsWorkloadIdentitySupport.java
This file contains hidden or 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,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); | ||
|
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)); | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| } | ||
48 changes: 48 additions & 0 deletions
48
...a/org/springframework/cloud/config/server/support/GitTransportConfigCallbackProvider.java
This file contains hidden or 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,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); | ||
|
|
||
| } |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.