How do I set up username/password authentication with Hashicorp Vault - hashicorp-vault

I'm just trying out the new Vault UI. I'd like to be able to log in with a username and password. How do I create a new user from the command line so I can log in with a username and password?

Create a new user like so:
vault write auth/userpass/users/<username> policies=default password=<passwd>
You have to be authenticated as root (or another user with sufficient permissions) and have enabled the userpass auth method.

Related

Keycloak: Prevent client from logging in specific user

Is it possible in keycloak to prevent the account client from logging in a specific user? I have a user that is only supposed to log in via the admin-cli endpoints, but it is in the same realm as the account client.
You can try to remove the
default-roles-<realm-name> role
for this user. This will remove the effective roles for the account client role

Keycloak doesn't offer passwordless authentication as the first option during login

I've configured Keycloak authentication for the following behaviour:
The user inputs its userid
Keycloak should try to authenticate it with the passwordless flow
As an alternative the user could switch to password authentication
NOTE: The user already has a registered passwordless device:
The authentication flow has been configured as follows:
I access localhost:8080/realms/myrealm/account and click on Sign in:
I input the userid:
But, instead of being offered to sign up with the security device, I'm asked for the password:
If I select Try another way and click on Security Key:
I am now offered to login with the device:
Which I can do successfully.
The problem here is that I need the passwordless login to be offered directly, not the password form. Passwordless is actually configured as the first alternative option so why isn't it working as expected?
Looking at the code of AuthenticationSelectionResolver this seems to be intended behaviour.
Try to change the order/position of credentials for your user from within the admin console.
The order of credentials should affect the order in which alternative authenticators will be executed.

Keycloak get user password

In my project, I need to get current user password from Rest API.
I searched keycloak 4.8.3 final documentation but I could not find it. With admin user I can change password without knowing the current password. But my logged in user can be admin or not. I found that keycloak does not give me permission to that because of security. Wrap up is there any way to active that settings or is there a way to get password with Rest API ?
Thank you.
Update: The /auth path was removed starting with Keycloak 17 Quarkus distribution. So you might need to remove the /auth from the endpoint calls presented on this answer.
Via the Rest API, one cannot get the password for obvious reasons. Ideally, in a secure setting, even if one is the admin one should not have access to the users' passwords.
From the comments you wrote:
I could use method like boolean isPasswordCorrect(username,password)
An approach is to create a client on your Realm as follows:
Go to your Realm;
Clients;
Create Client;
Set Access Type to public;
Set Direct Access Grants Enabled to ON;
Save;
Now request from the newly created client a token on behalf of the user that you want to check if the password is correct:
As you can see the endpoint is:
<KEYCLOAK_HOST>/auth/realms/<REALM_NAME/protocol/openid-connect/token
and the body is:
client_id : <The client ID of the newly create client>
username : <The username>
password : <The password to be tested>
grant_type : password
If the password is correct you will get back a token object, otherwise you will get the following response:
{
"error": "invalid_grant",
"error_description": "Invalid user credentials"
}

Is it possible for ldap users to revoke/renew/copy the root token in Hashicorp Vault?

I have recently started using vault and trying to integrate with one of my application to hold secrets. I have set up the LDAP authentication for my users to access vault and create/access secrets. BUT after login successfully, at the top right there is an option of copy token renew token revoke token.
Is it right for these users to access the root token? Is there a way to disable that feature?
I just want my users to access/create secrets that's it and nothing else.
If you're logged in with LDAP, then those options don't apply to the root token, they apply to the user-login-session token. All authentication with Vault uses tokens, not just the root one. Whenever someone logs in with LDAP, they will be issued a new token - that's the token that the menu refers to.
You can see this for yourself - assuming you already have a valid root token, log in with LDAP, then select Revoke token from that menu. Now try doing something with that root token (e.g., log in to the web UI or run a CLI command). You'll see that it still works - it has not been revoked.

Exclude a user with realm-management role from keycloak's password policy

I have a user with Client Roles realm-management in a realm which contains password policy.
I want to exclude this user from the password policy since I use this user to do some operation fetch the roles get all the user via Java API and I don't want all the operation to be drop when the password needs to be updated.
I tried to use the admin user from the master realms but I did not get any result
Any ideas?
When you create a realm in keycloak with password policy and you want to exclude the admin user from this policy do this follow these steps :
When a user creates new realm e.g "FooRealm" keycloak adds sibling client inside the master realm with a suffix -realm, in this case, we will see FooRealm-realm
Inside this client, FooRealm-realm do those changes (settings tab)
access type = confidential
Standard Flow Enables = ON
Direct Access Grants Enables = ON
Create user inside the master realm, In user details, go to: Role Mappings >> Clients Roles and from the drop down menu select the sibling client
(FooRealm-realm) and make sure it is own all the roles inside
Now To fetch all the user from the Slave realm FooRealm
Keycloak keycloak = KeycloakBuilder.builder()
.serverUrl("http://localhost/auth")
.realm("master")
.grantType(OAuth2Constants.PASSWORD)
.clientId(FooRealm-realm)
.clientSecret("7f0080cf-xxxx-xxxxx-9115-xxxxxxxxxx")
.username("sysadmin")
.password("x123456")
.build();
RealmResource realmResource = keycloak.realm("FooRealm");
realmResource.users().list(0, 1000);