micronaut-projects / micronaut-cassandra

Integration with the DataStax Cassandra Driver for Micronaut
Apache License 2.0
8 stars 9 forks source link

Micronaut cannot authentication with Cassandra #83

Closed oo00spy00oo closed 1 year ago

oo00spy00oo commented 4 years ago

Task List

Expected Behaviour

Cassandra with authentication should be worked :(

Actual Behaviour

[application] 14:19:46.873 [default-nioEventLoopGroup-1-2] INFO  c.d.o.d.i.c.DefaultMavenCoordinates - DataStax Java driver for Apache Cassandra(R) (com.datastax.oss:java-driver-core) version 4.9.0
[application] 14:19:49.072 [<REDACTED>-admin-0] INFO  c.d.o.d.internal.core.time.Clock - Using native clock for microsecond precision
[application] 14:19:49.385 [<REDACTED>-admin-1] WARN  c.d.o.d.i.c.c.ControlConnection - [<REDACTED>] Authentication error (AuthenticationException: Authentication error on node /<REDACTED>:9042: Node /<REDACTED>:9042 requires authentication (org.apache.cassandra.auth.PasswordAuthenticator), but no authenticator configured)
[application] 14:19:49.422 [<REDACTED>-admin-1] WARN  c.d.o.d.i.c.c.ControlConnection - [<REDACTED>] Authentication errors encountered on all contact points. Please check your authentication configuration.
[application] 14:19:49.566 [default-nioEventLoopGroup-1-2] ERROR i.m.h.s.netty.RoutingInBoundHandler - Unexpected error occurred: Error instantiating bean of type  [io.micronaut.configuration.cassandra.health.CassandraHealthIndicator]
[application] 
[application] Message: Could not reach any contact point, make sure you've provided valid addresses (showing first 1 nodes, use getAllErrors() for more): Node(endPoint=/<REDACTED>:9042, hostId=null, hashCode=8fcafc67): [com.datastax.oss.driver.api.core.auth.AuthenticationException: Authentication error on node /<REDACTED>:9042: Node /<REDACTED>:9042 requires authentication (org.apache.cassandra.auth.PasswordAuthenticator), but no authenticator configured]
[application] Path Taken: new HealthEndpoint(HealthAggregator healthAggregator,[HealthIndicator[] healthIndicators],HealthIndicator[] livenessHealthIndicators) --> new CassandraHealthIndicator([CqlSession cqlSession])
[application] io.micronaut.context.exceptions.BeanInstantiationException: Error instantiating bean of type  [io.micronaut.configuration.cassandra.health.CassandraHealthIndicator]
[application] 
[application] Message: Could not reach any contact point, make sure you've provided valid addresses (showing first 1 nodes, use getAllErrors() for more): Node(endPoint=/<REDACTED>:9042, hostId=null, hashCode=8fcafc67): [com.datastax.oss.driver.api.core.auth.AuthenticationException: Authentication error on node /<REDACTED>:9042: Node /<REDACTED>:9042 requires authentication (org.apache.cassandra.auth.PasswordAuthenticator), but no authenticator configured]
[application] Path Taken: new HealthEndpoint(HealthAggregator healthAggregator,[HealthIndicator[] healthIndicators],HealthIndicator[] livenessHealthIndicators) --> new CassandraHealthIndicator([CqlSession cqlSession])
[application]   at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1925)
[application]   at io.micronaut.context.DefaultBeanContext.createAndRegisterSingletonInternal(DefaultBeanContext.java:2647)
[application]   at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:2633)
[application]   at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:2305)
[application]   at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:2279)
[application]   at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:1245)
[application]   at io.micronaut.context.AbstractBeanDefinition.getBeanForConstructorArgument(AbstractBeanDefinition.java:1013)
[application]   at io.micronaut.configuration.cassandra.health.$CassandraHealthIndicatorDefinition.build(Unknown Source)
[application]   at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1898)
[application]   at io.micronaut.context.DefaultBeanContext.addCandidateToList(DefaultBeanContext.java:2990)
[application]   at io.micronaut.context.DefaultBeanContext.getBeansOfTypeInternal(DefaultBeanContext.java:2891)
[application]   at io.micronaut.context.DefaultBeanContext.getBeansOfType(DefaultBeanContext.java:1045)
[application]   at io.micronaut.context.AbstractBeanDefinition.lambda$getBeansOfTypeForConstructorArgument$9(AbstractBeanDefinition.java:1143)
[application]   at io.micronaut.context.AbstractBeanDefinition$$Lambda$177/0000000089006150.resolveBean(Unknown Source)
[application]   at io.micronaut.context.AbstractBeanDefinition.resolveBeanWithGenericsFromConstructorArgument(AbstractBeanDefinition.java:1820)
[application]   at io.micronaut.context.AbstractBeanDefinition.getBeansOfTypeForConstructorArgument(AbstractBeanDefinition.java:1138)
[application]   at io.micronaut.context.AbstractBeanDefinition.getBeanForConstructorArgument(AbstractBeanDefinition.java:987)
[application]   at io.micronaut.management.endpoint.health.$HealthEndpointDefinition.build(Unknown Source)
[application]   at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1898)
[application]   at io.micronaut.context.DefaultBeanContext.createAndRegisterSingletonInternal(DefaultBeanContext.java:2647)
[application]   at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:2633)
[application]   at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:2305)
[application]   at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:2279)
[application]   at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:721)
[application]   at io.micronaut.context.DefaultBeanContext$BeanExecutionHandle.getTarget(DefaultBeanContext.java:3240)
[application]   at io.micronaut.context.DefaultBeanContext$BeanExecutionHandle.invoke(DefaultBeanContext.java:3261)
[application]   at io.micronaut.web.router.AbstractRouteMatch.execute(AbstractRouteMatch.java:312)
[application]   at io.micronaut.web.router.RouteMatch.execute(RouteMatch.java:118)
[application]   at io.micronaut.http.server.netty.RoutingInBoundHandler.lambda$buildResultEmitter$10(RoutingInBoundHandler.java:1363)
[application]   at io.micronaut.http.server.netty.RoutingInBoundHandler$$Lambda$453/0000000014095AD0.call(Unknown Source)
[application]   at io.reactivex.internal.operators.flowable.FlowableDefer.subscribeActual(FlowableDefer.java:35)
[application]   at io.reactivex.Flowable.subscribe(Flowable.java:14918)
[application]   at io.reactivex.Flowable.subscribe(Flowable.java:14865)
[application]   at io.micronaut.http.server.context.ServerRequestContextFilter.lambda$doFilter$0(ServerRequestContextFilter.java:62)
[application]   at io.micronaut.http.server.context.ServerRequestContextFilter$$Lambda$466/00000000140C0810.subscribe(Unknown Source)
[application]   at io.reactivex.internal.operators.flowable.FlowableFromPublisher.subscribeActual(FlowableFromPublisher.java:29)
[application]   at io.reactivex.Flowable.subscribe(Flowable.java:14918)
[application]   at io.reactivex.Flowable.subscribe(Flowable.java:14868)
[application]   at io.micronaut.http.server.netty.RoutingInBoundHandler.lambda$buildExecutableRoute$6(RoutingInBoundHandler.java:1068)
[application]   at io.micronaut.http.server.netty.RoutingInBoundHandler$$Lambda$452/0000000014094DF0.apply(Unknown Source)
[application]   at io.micronaut.web.router.DefaultUriRouteMatch$1.execute(DefaultUriRouteMatch.java:80)
[application]   at io.micronaut.web.router.RouteMatch.execute(RouteMatch.java:118)
[application]   at io.micronaut.http.server.netty.RoutingInBoundHandler.handleRouteMatch(RoutingInBoundHandler.java:693)
[application]   at io.micronaut.http.server.netty.RoutingInBoundHandler.channelRead0(RoutingInBoundHandler.java:549)
[application]   at io.micronaut.http.server.netty.RoutingInBoundHandler.channelRead0(RoutingInBoundHandler.java:144)
[application]   at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99)
[application]   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
[application]   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
[application]   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
[application]   at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:102)
[application]   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
[application]   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
[application]   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
[application]   at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
[application]   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
[application]   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
[application]   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
[application]   at io.micronaut.http.netty.stream.HttpStreamsHandler.channelRead(HttpStreamsHandler.java:197)
[application]   at io.micronaut.http.netty.stream.HttpStreamsServerHandler.channelRead(HttpStreamsServerHandler.java:121)
[application]   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
[application]   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
[application]   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
[application]   at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
[application]   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
[application]   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
[application]   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
[application]   at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
[application]   at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111)
[application]   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
[application]   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
[application]   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
[application]   at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93)
[application]   at io.netty.handler.codec.http.HttpServerKeepAliveHandler.channelRead(HttpServerKeepAliveHandler.java:64)
[application]   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
[application]   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
[application]   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
[application]   at io.netty.handler.flow.FlowControlHandler.dequeue(FlowControlHandler.java:200)
[application]   at io.netty.handler.flow.FlowControlHandler.channelRead(FlowControlHandler.java:162)
[application]   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
[application]   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
[application]   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
[application]   at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436)
[application]   at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)
[application]   at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296)
[application]   at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251)
[application]   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
[application]   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
[application]   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
[application]   at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)
[application]   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
[application]   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
[application]   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
[application]   at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
[application]   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
[application]   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
[application]   at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
[application]   at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
[application]   at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714)
[application]   at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)
[application]   at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576)
[application]   at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
[application]   at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
[application]   at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
[application]   at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
[application]   at java.base/java.lang.Thread.run(Unknown Source)
[application] Caused by: com.datastax.oss.driver.api.core.AllNodesFailedException: Could not reach any contact point, make sure you've provided valid addresses (showing first 1 nodes, use getAllErrors() for more): Node(endPoint=/<REDACTED>:9042, hostId=null, hashCode=8fcafc67): [com.datastax.oss.driver.api.core.auth.AuthenticationException: Authentication error on node /<REDACTED>:9042: Node /<REDACTED>:9042 requires authentication (org.apache.cassandra.auth.PasswordAuthenticator), but no authenticator configured]
[application]   at com.datastax.oss.driver.api.core.AllNodesFailedException.copy(AllNodesFailedException.java:141)
[application]   at com.datastax.oss.driver.internal.core.util.concurrent.CompletableFutures.getUninterruptibly(CompletableFutures.java:149)
[application]   at com.datastax.oss.driver.api.core.session.SessionBuilder.build(SessionBuilder.java:697)
[application]   at io.micronaut.configuration.cassandra.CassandraSessionFactory.cassandraCluster(CassandraSessionFactory.java:86)
[application]   at io.micronaut.configuration.cassandra.$CassandraSessionFactory$CassandraCluster1Definition.build(Unknown Source)
[application]   at io.micronaut.context.BeanDefinitionDelegate.build(BeanDefinitionDelegate.java:143)
[application]   at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1898)
[application]   ... 104 common frames omitted
[application]   Suppressed: com.datastax.oss.driver.api.core.auth.AuthenticationException: Authentication error on node /<REDACTED>:9042: Node /<REDACTED>:9042 requires authentication (org.apache.cassandra.auth.PasswordAuthenticator), but no authenticator configured
[application]           at com.datastax.oss.driver.internal.core.channel.ProtocolInitHandler$InitRequest.lambda$buildAuthenticator$5(ProtocolInitHandler.java:366)
[application]           at com.datastax.oss.driver.internal.core.channel.ProtocolInitHandler$InitRequest$$Lambda$628/000000000C075730.get(Unknown Source)
[application]           at java.base/java.util.Optional.orElseThrow(Unknown Source)
[application]           at com.datastax.oss.driver.internal.core.channel.ProtocolInitHandler$InitRequest.buildAuthenticator(ProtocolInitHandler.java:362)
[application]           at com.datastax.oss.driver.internal.core.channel.ProtocolInitHandler$InitRequest.onResponse(ProtocolInitHandler.java:216)
[application]           at com.datastax.oss.driver.internal.core.channel.ChannelHandlerRequest.onResponse(ChannelHandlerRequest.java:94)
[application]           at com.datastax.oss.driver.internal.core.channel.InFlightHandler.channelRead(InFlightHandler.java:257)
[application]           at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
[application]           at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
[application]           at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
[application]           at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)
[application]           at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296)
[application]           ... 16 common frames omitted

Environment Information

Example Application

build.gradle

plugins {
    id "groovy"
    id "io.micronaut.application" version '1.0.3'
    id "com.google.protobuf" version "0.8.13"
    id "com.google.cloud.tools.jib" version "2.5.0"
}

version "1.0.0"
group "com.example"

repositories {
    jcenter()
    mavenCentral()
}

micronaut {
    runtime "netty"
    testRuntime "spock2"
    processing {
        incremental true
        annotations "com.example.*"
    }
}

dependencies {
    compileOnly("org.projectlombok:lombok:$lombokVersion")
    annotationProcessor("org.projectlombok:lombok:$lombokVersion")
    implementation("io.micronaut:micronaut-validation")
    implementation("io.micronaut:micronaut-runtime")
    implementation("io.micronaut.grpc:micronaut-grpc-runtime")
    implementation("javax.annotation:javax.annotation-api")
    implementation("io.micronaut:micronaut-http-client")
    implementation("io.micronaut:micronaut-management")
    implementation("io.micronaut.cassandra:micronaut-cassandra")
    implementation 'com.datastax.oss:java-driver-core:4.9.0'
    implementation 'com.datastax.oss:java-driver-query-builder:4.9.0'
    implementation 'com.datastax.oss:java-driver-mapper-runtime:4.9.0'
    runtimeOnly("ch.qos.logback:logback-classic")
    testCompileOnly("org.projectlombok:lombok:$lombokVersion")
    testAnnotationProcessor("org.projectlombok:lombok:$lombokVersion")
    testImplementation("io.micronaut:micronaut-http-client")
    testImplementation(platform("org.testcontainers:testcontainers-bom:$testContainerVersion"))
    testRuntimeOnly("org.testcontainers:cassandra")
}

mainClassName = "io.passiontech.Application"
java {
    sourceCompatibility = JavaVersion.toVersion('14')
    targetCompatibility = JavaVersion.toVersion('14')
}

sourceSets {
    main {
        java {
            srcDirs 'build/generated/source/proto/main/grpc'
            srcDirs 'build/generated/source/proto/main/java'
        }
    }
}

protobuf {
    protoc { artifact = "com.google.protobuf:protoc:$protocVersion" }
    plugins {
        grpc { artifact = "io.grpc:protoc-gen-grpc-java:$protocGenGrpcVersion" }
    }
    generateProtoTasks {
        all()*.plugins { grpc {} }
    }
}

gradle.properties

micronautVersion=2.1.0
lombokVersion=1.18.12
testContainerVersion=1.14.3
protocVersion=3.13.0
protocGenGrpcVersion=1.32.1

application.yml

cassandra:
  default:
    advanced:
      ssl-engine-factory: false
      metadata:
        schema:
          enabled: false
      auth-provider:
        username: "<REDACTED>"
        password: "<REDACTED>"
    basic:
      load-balancing-policy:
        local-datacenter: <REDACTED>
      contact-points:
        - "<REDACTED>:9042"
      session-name: "<REDACTED>"
racevedoo commented 3 years ago

@oo00spy00oo you probably need to specify the auth provider class in the application.yml, like:

cassandra:
  default:
    advanced:
      ssl-engine-factory: false
      metadata:
        schema:
          enabled: false
      auth-provider:
        class: PlainTextAuthProvider
        username: "<REDACTED>"
        password: "<REDACTED>"
    basic:
      load-balancing-policy:
        local-datacenter: <REDACTED>
      contact-points:
        - "<REDACTED>:9042"
      session-name: "<REDACTED>"
pollend commented 3 years ago

you can look at this issue for the full list of configuration items for reference: https://github.com/micronaut-projects/micronaut-cassandra/issues/8 . the config is mapped onto datastax driver so the config starts after the key.

wetted commented 1 year ago

@oo00spy00oo Is this still a problem for you?

Please see the datastax driver manual for auth. It states you must provide an auth provider, using – as noted in comments above - the advanced.auth-provider.class property. The driver provides PlainTextAuthProvider for that. Your example is missing that. Please try adding that, or programmatically, as per the driver docs.

If you still have a problem, feel free to reopen this issue with a complete example that exposes the issue you are having with it (not just your build scripts).