Skip to content

Add support for Couchbase's role based access #16389

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

Closed
Closed
Show file tree
Hide file tree
Changes from 4 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 @@ -57,7 +57,14 @@ public DefaultCouchbaseEnvironment couchbaseEnvironment() {
@Bean
@Primary
public Cluster couchbaseCluster() {
return CouchbaseCluster.create(couchbaseEnvironment(), determineBootstrapHosts());
CouchbaseCluster couchbaseCluster = CouchbaseCluster
.create(couchbaseEnvironment(), determineBootstrapHosts());
CouchbaseProperties.Bucket bucket = this.properties.getBucket();
if (bucket.isRoleBaseAccessEnabled()) {
return couchbaseCluster.authenticate(bucket.getUserName(),
bucket.getPassword());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also need to change CouchbaseConfiguration.couchbaseClient() to call openBucket(bucket.name) if RBAC is enabled or openBucket(bucket.name, bucket.password) if RBAC is disabled. Otherwise the client will throw MixedAuthenticationException.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right thanks :)
added also here with RBAC control.

}
return couchbaseCluster;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.boot.autoconfigure.couchbase;

import java.time.Duration;
Expand Down Expand Up @@ -70,6 +69,16 @@ public static class Bucket {
*/
private String password = "";

/**
* Username of the bucket.
*/
private String userName = "";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RBAC credentials are for the whole cluster, not just one bucket. Instead of adding the username to the bucket, please add username and password as top level properties of CouchbaseProperties. Note the capitalization; "username" is one word in this context, and should be all lowercase.

Please keep the separate bucket password for backwards compatibility with non-RBAC clusters.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved username and password to top level of properties.


/**
* RoleBaseAccessEnable for support Couchbase bucket after version 5.0.
*/
private boolean roleBaseAccessEnabled = false;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than requiring the user to explicitly enable RBAC, RABC should automtatically be enabled when the username is set.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed roleBaseAccessEnabled properties.


public String getName() {
return this.name;
}
Expand All @@ -86,6 +95,22 @@ public void setPassword(String password) {
this.password = password;
}

public String getUserName() {
return this.userName;
}

public void setUserName(String userName) {
this.userName = userName;
}

public boolean isRoleBaseAccessEnabled() {
return this.roleBaseAccessEnabled;
}

public void setRoleBaseAccessEnabled(boolean roleBaseAccessEnabled) {
this.roleBaseAccessEnabled = roleBaseAccessEnabled;
}

}

public static class Env {
Expand Down