Argon2 password hashing parameters
Ory Kratos supports password hashing using Argon2 in the Argon2id variant. It's important to set up it's parameters to ensure a stable and reliable operation of Ory Kratos. In essence, you want to fulfill the following constrains:
- Duration: the execution time of one hashing operation - this translates to the response time of Ory Kratos on login and registration.
- Memory: the amount of available memory on the server
- Space: the amount of space for persistent storage
We recommend choosing a duration of 0.5s to 1s and as much memory as possible. To determine the exact recommended values following security best practices, run the CLI helper included in Ory Kratos:
kratos hashers argon2 calibrate 1s
It will output the exact values to use in the configuration.
Head to our blogpost about Argon2 parameters to learn how this command and password checking in Ory Kratos works.
Memory limit for password hashing
Ory Kratos can limit the memory that memory-hard password hashing uses at once in one process. The limit applies to Argon2 hashing and to verifying imported Argon2, scrypt, and Firebase scrypt hashes. It doesn't apply to bcrypt or PBKDF2.
The limit is off by default. To turn it on, set hashers.memory_limit:
hashers:
memory_limit: 1GiB
argon2:
memory: 128MB
With these values, Ory Kratos runs up to eight Argon2 operations at the same time. An operation that doesn't fit waits up to 5
seconds for memory. If no memory becomes available, the request fails with a 429 Too Many Requests error and the client can
retry.
- A hash that needs more memory than the limit isn't rejected. It runs once no other memory-hard operation is running.
- To serve more concurrent password logins, increase
memory_limitand the memory available to Ory Kratos. - To turn the limit off, remove
memory_limitor set it to0B.
Metrics
Ory Kratos exposes these Prometheus metrics for the limit:
| Metric | Description |
|---|---|
kratos_hash_memory_reserved_bytes | Memory in use by password hashing. |
kratos_hash_memory_wait_seconds | Time operations waited for memory. |
kratos_hash_memory_rejections_total | Operations that failed because no memory was free. |
If you encounter any problems like timeouts or out-of-memory errors, consolidate our troubleshooting guide.
