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

[BUG] Still use connection string auth even if the connection string property is set as empty string #42880

Closed
3 tasks done
haoozhang opened this issue Nov 11, 2024 · 6 comments · Fixed by #42919 or #43076
Closed
3 tasks done
Assignees
Labels
azure-spring All azure-spring related issues Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Milestone

Comments

@haoozhang
Copy link

Describe the bug
Even if the connection string property is set as empty, the application still tries to auth via connection string.

The application is a simple spring cloud stream + kafka, refering to the sample project https://github.com/Azure-Samples/azure-spring-boot-samples/tree/main/eventhubs/spring-cloud-azure-starter/spring-cloud-azure-sample-eventhubs-kafka.

In the application.yaml, when we specify the auth as follows, we want to use managed identity auth, instead of connection string (we leave it empty), but the application still try to use connection string for auth, causing it cannot startup.

spring:
  cloud:
        azure:
          eventhubs:
            credential:
              managed-identity-enabled: true
              client-id:  XXX
          connection-string:  # empty string

Exception or Stack Trace

In the following file, when the property is set as empty, it should not enter the method. but now it will execute this method even if empty.

public class AzureEventHubsKafkaAutoConfiguration {

    private static final Logger LOGGER = LoggerFactory.getLogger(AzureEventHubsKafkaAutoConfiguration.class);

    @Bean
    @ConditionalOnProperty("spring.cloud.azure.eventhubs.connection-string")
    @ConditionalOnMissingBean(value = AzureServiceType.EventHubs.class, parameterizedContainer = ServiceConnectionStringProvider.class)
    StaticConnectionStringProvider<AzureServiceType.EventHubs> eventHubsKafkaConnectionString(Environment environment) {
        String connectionString = environment.getProperty("spring.cloud.azure.eventhubs.connection-string");

        try {
            new EventHubsConnectionString(connectionString);
        } catch (Exception e) {
            LOGGER.error("A valid Event Hubs connection string must be provided");
            throw e;
        }

        return new StaticConnectionStringProvider<>(AzureServiceType.EVENT_HUBS, connectionString);
    }

To Reproduce
Steps to reproduce the behavior:

  1. Clone the sample project.
  2. As described above, specify the application properties and then run.

Code Snippet
Add the code snippet that causes the issue.

Expected behavior

When setting connection string as empty, it should auto-use MI configuration for auth.

Screenshots
If applicable, add screenshots to help explain your problem.

Setup (please complete the following information):

  • OS: [e.g. iOS] Windows 11
  • IDE: [e.g. IntelliJ]: IDEA
  • Library/Libraries: spring-boot-starter-web 3.3.5, spring-cloud-starter-stream-kafka 4.1.3, spring-cloud-azure-starter 5.18.0
  • Java version: [e.g. 8] 17
  • App Server/Environment: Tomcat
  • Frameworks: Spring Boot

If you suspect a dependency version mismatch (e.g. you see NoClassDefFoundError, NoSuchMethodError or similar), please check out Troubleshoot dependency version conflict article first. If it doesn't provide solution for the problem, please provide:

  • verbose dependency tree (mvn dependency:tree -Dverbose)
  • exception message, full stack trace, and any available logs

Additional context
Add any other context about the problem here.

Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • Bug Description Added
  • Repro Steps Added
  • Setup information Added
@github-actions github-actions bot added azure-spring All azure-spring related issues Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Nov 11, 2024
Copy link

Copy link

Thank you for your feedback. Tagging and routing to the team member best able to assist.

@rujche
Copy link
Member

rujche commented Nov 12, 2024

Another problem is that for spring-cloud-starter-stream-kafka, SPRING_CLOUD_AZURE_EVENTHUBS_CONNECTIONSTRING not work, SPRING_CLOUD_AZURE_EVENTHUBS_CONNECTION_STRING works.

But for spring-cloud-azure-stream-binder-eventhubs, SPRING_CLOUD_AZURE_EVENTHUBS_CONNECTIONSTRING works well. This behavior will make customer confused.

@rujche
Copy link
Member

rujche commented Nov 12, 2024

FYI: More information about environment variable used in Spring Boot can be found here: https://github.com/azure-javaee/azure-dev/wiki/Knowledge-Sharing#2-sometimes-the-environment-variable-not-take-effect-in-spring-boot-application

@moarychan
Copy link
Member

Another problem is that for spring-cloud-starter-stream-kafka, SPRING_CLOUD_AZURE_EVENTHUBS_CONNECTIONSTRING not work, SPRING_CLOUD_AZURE_EVENTHUBS_CONNECTION_STRING works.

But for spring-cloud-azure-stream-binder-eventhubs, SPRING_CLOUD_AZURE_EVENTHUBS_CONNECTIONSTRING works well. This behavior will make customer confused.

The behavior is not expected, I opened an issue on SCS side, see more from spring-cloud/spring-cloud-stream#3039

@rujche
Copy link
Member

rujche commented Nov 24, 2024

This problem also exists in Service Bus.
Here is related code:

@Bean
@ConditionalOnProperty("spring.cloud.azure.servicebus.connection-string")
StaticConnectionStringProvider<AzureServiceType.ServiceBus> staticServiceBusConnectionStringProvider() {
return new StaticConnectionStringProvider<>(AzureServiceType.SERVICE_BUS,
this.serviceBusProperties.getConnectionString());
}

I'll reopen this issue.

Hi, @moarychan
Could you please help to fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
azure-spring All azure-spring related issues Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
Status: Done
4 participants