2

I am figuring out the couchbase java SDK 3.3 and how to manage users. Using the User Management documentation, I can run this snippet of code:

# Example Read Only User
User user = new User(testUsername).password(userPassword);
user.roles(new Role("data_reader","*"),new Role("query_select","*"));
cluster.users().upsertUser(user);

My question is it possible to create a user this way with administrator privileges (security, cluster, full, etc.), add the user to an existing group (which looking at lack of a Group field in the User object from the SDK, I don't think so), or are there additional privileges assignable other than Data Reader/Writer and Query Select/Insert/Delete/Manage Index

GrimThor3
  • 171
  • 1
  • 10
  • 1
    At the time you posted this question, the [User object](https://docs.couchbase.com/java-sdk/current/concept-docs/sdk-user-management-overview.html#listing_users) documentation was not up-to-date. A User object _does_ have a "groups" field. – dnault Jul 25 '22 at 21:07

1 Answers1

3

Yes, you can use the management API to create admin users. You can do this by assigning the various admin roles to the user.

And yes, you can assign users to groups.

To view all available roles:

cluster.users().getRoles().forEach(System.out::println);

For a more detailed description of the roles, see Roles and Privileges. Note: Couchbase Server Enterprise Edition provides many more roles than Community Edition.

To create a read-only admin user that's a member of group "existing-group":

cluster.users().upsertUser(
    new User("example-admin")
        .displayName("Example Admin")
        .password("Correct Horse Battery Staple")
        .roles(new Role("ro_admin")) // Read-Only Admin
        .groups("existing-group") // must already exist
);
dnault
  • 8,340
  • 1
  • 34
  • 53
  • 1
    I appreciate the answer! Is there some documentation you can point me to with more about using roles? – GrimThor3 Jul 26 '22 at 04:02
  • Sure thing! I updated the answer to include a link to the documentation. Is that what you're looking for? – dnault Jul 26 '22 at 20:00
  • I was thinking more the java documentation, if that exists – GrimThor3 Jul 28 '22 at 19:00
  • The only other documentation I'm aware of is the [Javadoc](https://docs.couchbase.com/sdk-api/couchbase-java-client/com/couchbase/client/java/manager/user/package-summary.html). If you'd like to provide feedback on the [User Management documentation](https://docs.couchbase.com/java-sdk/current/howtos/sdk-user-management-example.html) you linked above, please click the "Leave Additional Feedback?" link in the right sidebar of that page (you might need to maximize the browser window to see the sidebar). Your feedback will turn into a Jira issue for the documentation team. – dnault Jul 28 '22 at 20:44