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

Question: change default password #545

Open
thoefkens opened this issue Feb 28, 2025 · 1 comment
Open

Question: change default password #545

thoefkens opened this issue Feb 28, 2025 · 1 comment

Comments

@thoefkens
Copy link

Hi all,

what is the best way to change the default "secret" password for the restheart admin?

Can we write to the collection directly or do we have to go via the REST api or is there some other means of initializing the restheart user collection with a predefined set of users/admins - what is your recommended approach?

thanks
Thomas

@ujibang
Copy link
Contributor

ujibang commented Feb 28, 2025

1 Via configuration at first startup

You can set the configuration option /mongoRealmAuthenticator/create-user-document. This is used to create the admin user on the very first startup:

Look in the configuration you find this comment:

  # create-user-document.password must be hashed when bcrypt-hashed-password=true
  # default password is 'secret'
  # see https://bcrypt-generator.com but replace initial '$2y' with '$2a'

The following configuration override defines the password to be supersecret:

RHO='/mongoRealmAuthenticator/create-user-document->{"_id": "admin", "password": "$2a$12$HjQZAOoW0q9SB0xgMy362O8.d.Ve.ywJm7M0c0c9h7qmmq25gBv.m", "roles": ["admin"]}'

2 Using the REST API

You can also update it using the REST API. In this case just send the plain password, RESTHeart will encrypt it automatically.

With curl you can

$ curl -u admin:secret -X PATCH localhost:8080/users/admin -H "Content-Type: application/json" -d '{ "password": "my-strong-password" }'

More info at https://restheart.org/docs/security/user-management

3 writing to the collection directly

Finally yuo can update the admin document, setting the password. In this case you need to bcrypt it.

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

No branches or pull requests

2 participants