Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Couchbase 6.0 + springboot (InvalidPasswordException)

Hi i am newbie to Couchbase and created a Springboot application with Couchbase 6.0.

When i installed Couchbase, it asked me to create username and password and i set username="admin" and password="password" and then i created "student" bucket.

I have done all the requisite config in application.properties file.

spring.couchbase.bootstrap-hosts=127.0.0.1
spring.couchbase.bucket.name=student
spring.couchbase.bucket.password=password

On server start, i am getting following error

Caused by: com.couchbase.client.java.error.InvalidPasswordException: null

Couchbase web console, there is a Security tab, I added, username "admin" (which i created during Couchbase server installation) over there and given full admin access enter image description here

On server restart again, I have faced same issue

then i added one more user "student" (same as my bucket name) over there and given full admin access

enter image description here

this time my server started successfully and i did not get any exception

So i have two questions here,

1: Do i need to create as many as username as i have buckets in my Couchbase server in security tab ?.

2: Let say i want to use username "admin" only (which i created during Couchbase server installation), how would i achieve this ?.

Can someone throw some light on this behaviour ?

like image 575
Bifrost Avatar asked Nov 06 '18 18:11

Bifrost


2 Answers

Pre couchbase 4.5, buckets had passwords, where if you need to access a bucket you'll have to supply the bucket name and its password. After 4.5 they implemented rbac (Role-Based Access Control) and dropped bucket-level passwords.

So for people that upgraded their couchbase but don't want to change their code or make a new release, a work-around was suggested, create a username per bucket, where the username is the bucket name and the password is the same for all users, that way spring-data-couchbase still authenticates successfully when ran.

Now rbac is added to couchbase-java-client & spring-data-couchbase (considering you're using latest version, not sure at which specific version they added it), so if you want to use a single username to connect to all your buckets you will need a class that extends AbstractCouchbaseConfiguration and then

@Override
protected String getUsername() {
    return "admin";
}

And supply the password via the old bucketPassword() method.

I don't think you can do it through application.properties yet because the org.springframework.boot.autoconfigure dependency is still not updated to accommodate for the latest spring-data-couchbase changes.

Also a note, the username that you've created through the security tab have nothing to do with the user that you created through the installation wizard. The user you've created through the initial installation is a master user, can't be removed, you won't see it under the security tab and it have full admin privileges. You still can define a username with same name through the security tab (I just learned that) but then you'll have 2 accounts, same user, different pass (or maybe same pass even but I'm not even sure how it's handled by couchbase, I mean if we have 2 accounts called 'Administrator' with the same password and then a login happens on web console, which user is considered? Maybe someone can tell us.)

like image 118
prettyvoid Avatar answered Nov 05 '22 04:11

prettyvoid


I got an alternative for this by overriding couchbaseClusterInfo() method in config class.

    @Override
    @Bean(name = BeanNames.COUCHBASE_CLUSTER_INFO)
    public ClusterInfo couchbaseClusterInfo() throws Exception {
        return couchbaseCluster().authenticate("admin","password").clusterManager().info();
    }

this is working fine.

like image 43
Bifrost Avatar answered Nov 05 '22 03:11

Bifrost