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

Add support for Couchbase's role based access #16389

Closed

Conversation

enesacikoglu
Copy link

Couchbase role-based access for bucket released after version 5.X.But ,there is no configuration support for Spring Data Couchbase auto configuration after couchbase version 5.X takes username for authentication.

Related problem as linked below;

https://stackoverflow.com/questions/47169384/couchbase-bucket-authentication-error

So, I added username to couchbase properties to solve problem.

@pivotal-issuemaster
Copy link

@enesacikoglu Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-issuemaster
Copy link

@enesacikoglu Thank you for signing the Contributor License Agreement!

@snicoll snicoll changed the title #16388 couchbase 5.x and later auth Support for role-based access for Couchbase bucket Mar 29, 2019
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 29, 2019
@snicoll
Copy link
Member

snicoll commented Apr 1, 2019

@bsubhashni wondering if you have a bit of time to look at this one.

@bsubhashni
Copy link

Adding @dnault

@enesacikoglu
Copy link
Author

Hello,

Waiting for review.

Thanks

@snicoll
Copy link
Member

snicoll commented Apr 6, 2019

@enesacikoglu please be patient, I've already triaged your PR and asked for some feedback from the Couchbase team.

Copy link

@dnault dnault left a comment

Choose a reason for hiding this comment

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

@enesacikoglu Thank you. Support for Role Based Access Control (RBAC) is a much needed feature. Here are some notes.

/**
* 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.

/**
* 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.

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.

@enesacikoglu
Copy link
Author

@enesacikoglu Thank you. Support for Role Based Access Control (RBAC) is a much needed feature. Here are some notes.

@dnault thanks for your kindly review and comments.
I try to implement new feature via your suggestions.

Could you review again ?

Copy link

@dnault dnault left a comment

Choose a reason for hiding this comment

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

Thanks for updating the PR. One more comment:

CouchbaseCluster couchbaseCluster = CouchbaseCluster
.create(couchbaseEnvironment(), determineBootstrapHosts());
if (this.properties.getUsername() != null
&& this.properties.getPassword() != null) {
Copy link

Choose a reason for hiding this comment

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

The username and password properties are initialized to empty string (""). Will they ever be null? A better check might be .isEmpty().

Copy link
Author

Choose a reason for hiding this comment

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

Opps how can ı miss 👎 Thanks for your awesome attention

@@ -79,6 +86,10 @@ public ClusterInfo couchbaseClusterInfo() {
@Bean
@Primary
public Bucket couchbaseClient() {
if (this.properties.getUsername().isEmpty()
|| this.properties.getPassword().isEmpty()) {
return couchbaseCluster().openBucket(this.properties.getBucket().getName());
Copy link

Choose a reason for hiding this comment

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

This condition should be inverted. If RBAC username or password are empty we should call the openBucket method that takes a bucket password.

Sorry if I missed this earlier.

Copy link
Author

Choose a reason for hiding this comment

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

This condition should be inverted. If RBAC username or password are empty we should call the openBucket method that takes a bucket password.

Sorry if I missed this earlier.

Thanks. I inverted it. 👍

Copy link

@dnault dnault left a comment

Choose a reason for hiding this comment

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

@enesacikoglu Thank you, nice work.

@snicoll Couchbase approves the code change. Is there documentation that needs to be updated?

@snicoll snicoll added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels May 15, 2019
@snicoll snicoll added this to the 2.2.x milestone May 15, 2019
@snicoll snicoll self-assigned this May 15, 2019
@snicoll snicoll changed the title Support for role-based access for Couchbase bucket Add support for Couchbase's role based access May 21, 2019
@snicoll snicoll modified the milestones: 2.2.x, 2.2.0.M4 May 21, 2019
snicoll pushed a commit that referenced this pull request May 21, 2019
@snicoll snicoll closed this in 2949561 May 21, 2019
snicoll added a commit that referenced this pull request May 21, 2019
* pr/16389:
  Polish "Add support for Couchbase's role-based access"
  Add support for Couchbase's role-based access
@snicoll
Copy link
Member

snicoll commented May 21, 2019

@enesacikoglu thanks for making your first contribution to Spring Boot. This is now merged with a polish commit.

In particular, I didn't like that username and password are set to blank and that the condition that checks if RBA is enabled wasn't shared. There are now null and we check they are both set, as this article states that:

You cannot create a user without a password.

@snicoll
Copy link
Member

snicoll commented May 21, 2019

Support for Role Based Access Control (RBAC) is a much needed feature.

@dnault in the future, please feel free to reach out to us if there are changes in Couchbase that require a change on our side. Thanks!

@sadikkuzu
Copy link

Congrats @enesacikoglu
You're doing the best!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants