{"id":27375,"date":"2023-08-18T21:24:15","date_gmt":"2023-08-18T19:24:15","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/?p=27375"},"modified":"2023-08-20T22:50:00","modified_gmt":"2023-08-20T20:50:00","slug":"redis-using-access-control-list-acl-part2","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/","title":{"rendered":"Redis: Using Access Control List (ACL) part2"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"h-introduction\">Introduction<\/h2>\n\n\n\n<p>In the first part with have seen what are Redis ACL and why we are using it.WE also have seen how to list users with the ACL LIST command.<\/p>\n\n\n\n<p>Let&#8217;s continue and go deeper with command usage and also how to use an external file.<\/p>\n\n\n\n<p>So let&#8217;s go for Redis ACL part two !<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-multiple-calls-to-acl-setuser\">Multiple calls to ACL SETUSER<\/h2>\n\n\n\n<p>When ACL SETUSER is called multiple times every ACL SETUSER call will NOT reset the user, but will just apply incrementally the ACL rules to the existing user.<\/p>\n\n\n\n<p>The user is reset only if it was not known before, it cannot do anything, is disallowed, has no passwords, and so forth. This is the best default for safety<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li> Below an example of ACL rights incremental method:<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"953\" height=\"537\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-52.png\" alt=\"\" class=\"wp-image-27378\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-52.png 953w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-52-300x169.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-52-768x433.png 768w\" sizes=\"auto, (max-width: 953px) 100vw, 953px\" \/><\/figure>\n\n\n\n<p>We can see that the command add SET rights and GET rights , in that order because sometimes order can have its importance when configuring ACL for a user.<\/p>\n\n\n\n<p>You also notice that there is the off option which means user is disabled so we will turn it on.<\/p>\n\n\n\n<p>So to sum up you can now call both SET and GET commands for that user.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-command-categories\">Command categories<\/h2>\n\n\n\n<p>Now we know how to add rights but there are many commands so it can be fastidious to add it one by one.why not use directly the command categories ?<\/p>\n\n\n\n<p>First of all we will list the command categories which include a bunch of common command like get but also it can include critical commands.<\/p>\n\n\n\n<p>The following is a list of command categories and their meanings:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>admin<\/strong> &#8211; Administrative commands. Normal applications will never need to use these. Includes <a href=\"https:\/\/redis.io\/commands\/replicaof\"><code>REPLICAOF<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/config\"><code>CONFIG<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/debug\"><code>DEBUG<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/save\"><code>SAVE<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/monitor\"><code>MONITOR<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/acl\"><code>ACL<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/shutdown\"><code>SHUTDOWN<\/code><\/a>, etc.<\/li>\n\n\n\n<li><strong>bitmap<\/strong> &#8211; Data type: bitmaps related.<\/li>\n\n\n\n<li><strong>blocking<\/strong> &#8211; Potentially blocking the connection until released by another command.<\/li>\n\n\n\n<li><strong>connection<\/strong> &#8211; Commands affecting the connection or other connections. This includes <a href=\"https:\/\/redis.io\/commands\/auth\"><code>AUTH<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/select\"><code>SELECT<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/command\"><code>COMMAND<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/client\"><code>CLIENT<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/echo\"><code>ECHO<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/ping\"><code>PING<\/code><\/a>, etc.<\/li>\n\n\n\n<li><strong>dangerous<\/strong> &#8211; Potentially dangerous commands (each should be considered with care for various reasons). This includes <a href=\"https:\/\/redis.io\/commands\/flushall\"><code>FLUSHALL<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/migrate\"><code>MIGRATE<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/restore\"><code>RESTORE<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/sort\"><code>SORT<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/keys\"><code>KEYS<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/client\"><code>CLIENT<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/debug\"><code>DEBUG<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/info\"><code>INFO<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/config\"><code>CONFIG<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/save\"><code>SAVE<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/replicaof\"><code>REPLICAOF<\/code><\/a>, etc.<\/li>\n\n\n\n<li><strong>geo<\/strong> &#8211; Data type: geospatial indexes related.<\/li>\n\n\n\n<li><strong>hash<\/strong> &#8211; Data type: hashes related.<\/li>\n\n\n\n<li><strong>hyperloglog<\/strong> &#8211; Data type: hyperloglog related.<\/li>\n\n\n\n<li><strong>fast<\/strong> &#8211; Fast O(1) commands. May loop on the number of arguments, but not the number of elements in the key.<\/li>\n\n\n\n<li><strong>keyspace<\/strong> &#8211; Writing or reading from keys, databases, or their metadata in a type agnostic way. Includes <a href=\"https:\/\/redis.io\/commands\/del\"><code>DEL<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/restore\"><code>RESTORE<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/dump\"><code>DUMP<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/rename\"><code>RENAME<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/exists\"><code>EXISTS<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/dbsize\"><code>DBSIZE<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/keys\"><code>KEYS<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/expire\"><code>EXPIRE<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/ttl\"><code>TTL<\/code><\/a>, <a href=\"https:\/\/redis.io\/commands\/flushall\"><code>FLUSHALL<\/code><\/a>, etc. Commands that may modify the keyspace, key, or metadata will also have the <code>write<\/code> category. Commands that only read the keyspace, key, or metadata will have the <code>read<\/code> category.<\/li>\n\n\n\n<li><strong>list<\/strong> &#8211; Data type: lists related.<\/li>\n\n\n\n<li><strong>pubsub<\/strong> &#8211; PubSub-related commands.<\/li>\n\n\n\n<li><strong>read<\/strong> &#8211; Reading from keys (values or metadata). Note that commands that don&#8217;t interact with keys, will not have either <code>read<\/code> or <code>write<\/code>.<\/li>\n\n\n\n<li><strong>scripting<\/strong> &#8211; Scripting related.<\/li>\n\n\n\n<li><strong>set<\/strong> &#8211; Data type: sets related.<\/li>\n\n\n\n<li><strong>sortedset<\/strong> &#8211; Data type: sorted sets related.<\/li>\n\n\n\n<li><strong>slow<\/strong> &#8211; All commands that are not <code>fast<\/code>.<\/li>\n\n\n\n<li><strong>stream<\/strong> &#8211; Data type: streams related.<\/li>\n\n\n\n<li><strong>string<\/strong> &#8211; Data type: strings related.<\/li>\n\n\n\n<li><strong>transaction<\/strong> &#8211; <a href=\"https:\/\/redis.io\/commands\/watch\"><code>WATCH<\/code><\/a> \/ <a href=\"https:\/\/redis.io\/commands\/multi\"><code>MULTI<\/code><\/a> \/ <a href=\"https:\/\/redis.io\/commands\/exec\"><code>EXEC<\/code><\/a> related commands.<\/li>\n\n\n\n<li><strong>write<\/strong> &#8211; Writing to keys (values or metadata).<\/li>\n<\/ul>\n\n\n\n<p>Below you will have an example of a user  with a restriction to the blocking category<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"104\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-53-1024x104.png\" alt=\"\" class=\"wp-image-27384\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-53-1024x104.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-53-300x30.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-53-768x78.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-53.png 1447w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>When using +@all command it will allow all commands , then you can restrict the category you want jsut after like @Blocking commands or @dangerous commands .<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"426\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-54-1024x426.png\" alt=\"\" class=\"wp-image-27387\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-54-1024x426.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-54-300x125.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-54-768x319.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-54.png 1445w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-list-the-command-categories\">List the command categories <\/h2>\n\n\n\n<p>Use the ACL CAT command to list all the categories<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"810\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-55-1024x810.png\" alt=\"\" class=\"wp-image-27389\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-55-1024x810.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-55-300x237.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-55-768x607.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-55.png 1229w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-list-the-sub-commands\">List the sub-commands <\/h2>\n\n\n\n<p>Now you have identified the categories you can list them and see the sub-commands inside <\/p>\n\n\n\n<p>Use the command<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>ACL CAT &#091; categoryname ]<\/code><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"109\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-56-1024x109.png\" alt=\"\" class=\"wp-image-27390\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-56-1024x109.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-56-300x32.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-56-768x82.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-56.png 1231w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>This example lists the sub-commands within the dangerous category<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"864\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-57-1024x864.png\" alt=\"\" class=\"wp-image-27393\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-57-1024x864.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-57-300x253.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-57-768x648.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-57.png 1230w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Inside there is common but critical commands such as <strong>KEYS<\/strong>, <strong>SAVE, RESTORE, ACL <\/strong>commands <strong>BUT ALSO THE<\/strong> <strong>FLUSHALL <\/strong>command , I guess it should be only dedicated to the <strong>Redis admin<\/strong>.<\/p>\n\n\n\n<p>Aim is to get the Redis infra secure by avoiding blocking or dangerous commands, indeed it can slow the server or even worse harm it and delete data.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"allowblock-subcommands\">Allow\/block subcommands<\/h2>\n\n\n\n<p>Starting from <strong>Redis 7.0<\/strong> version , subcommands can be allowed\/blocked just like other commands (by using the separator <code>|<\/code> between the command and subcommand, for example: <code>+config|get<\/code> or <code>-config|set<\/code>)<\/p>\n\n\n\n<p>That is true for all commands except <strong>DEBUG<\/strong>. In order to allow\/block specific DEBUG sub-commands<\/p>\n\n\n\n<p>My current configuration doesn&#8217;t allow me to give examples as I am on Redis 6 but I will upgrade and show it in another incoming post \ud83d\ude42 <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"allow-the-first-arg-of-a-blocked-command\">Allow the first-arg of a blocked command<\/h2>\n\n\n\n<p><strong>Note that this feature is deprecated since Redis 7.0 and may be removed in the future.<\/strong><\/p>\n\n\n\n<p>( I am on Redis 6 version so we can test the command )<\/p>\n\n\n\n<p>Exclude or include a command or a subcommand as a whole may find some limits. For example many deployments may not be happy providing the ability to execute a <a href=\"https:\/\/redis.io\/commands\/select\"><code>SELECT<\/code><\/a> for any DB, but may still want to be able to run <code>SELECT 0<\/code>.<\/p>\n\n\n\n<p><span style=\"text-decoration: underline\">Example:<\/span><\/p>\n\n\n\n<p>We could alter the ACL of a user as the following way<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ACL SETUSER myuser -select +select|0<\/code><\/pre>\n\n\n\n<p>This command will remove the <a href=\"https:\/\/redis.io\/commands\/select\"><code>SELECT<\/code><\/a> command and then add the allowed first-arg.<\/p>\n\n\n\n<p>Note that <strong>it is not possible to do the reverse<\/strong> since first-args can be only added, not excluded.<\/p>\n\n\n\n<p>Best practice for more security is to specify all the first-args that are valid for some user since it is possible that new first-args may be added in the future.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"selectors\">Selectors<\/h2>\n\n\n\n<p>I will upgrade my Redis to 7.0 and test it in another post , for teh moment you can get the definition and method to understand the principle below ( from the <strong>Redis site<\/strong> ) <\/p>\n\n\n\n<p>&#8220;Starting with <strong>Redis 7.0<\/strong>, Redis supports adding multiple sets of rules that are evaluated independently of each other. These secondary sets of permissions are called selectors and added by wrapping a set of rules within parentheses. In order to execute a command, either the root permissions (rules defined outside of parenthesis) or any of the selectors (rules defined inside parenthesis) must match the given command. Internally, the root permissions are checked first followed by selectors in the order they were added.<\/p>\n\n\n\n<p>For example, consider a user with the ACL rules <code>+GET ~key1 (+SET ~key2)<\/code>. This user is able to execute <code>GET key1<\/code> and <code>SET key2 hello<\/code>, but not <code>GET key2<\/code> or <code>SET key1 world<\/code>.&#8221;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-key-permissions\">Key permissions<\/h2>\n\n\n\n<p>Need Redis 7.0 version minimum so it will be discussed during a next post \ud83d\ude42<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-passwords-are-stored-internally\">Passwords storage method<\/h2>\n\n\n\n<p> SHA256 is the method to store internally Redis hashed passwords .<\/p>\n\n\n\n<p>When you check your password by using  <a href=\"https:\/\/redis.io\/commands\/acl-list\"><code>ACL LIST<\/code><\/a> or <a href=\"https:\/\/redis.io\/commands\/acl-getuser\"><code>ACL GETUSER<\/code><\/a>, you&#8217;ll see a long hex string that looks pseudo random.<\/p>\n\n\n\n<p><span style=\"text-decoration: underline\">Example:<\/span><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"519\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-58-1024x519.png\" alt=\"\" class=\"wp-image-27416\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-58-1024x519.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-58-300x152.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-58-768x389.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-58.png 1224w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Using SHA256 provides the ability to avoid storing the password in clear text while still allowing for a very fast <a href=\"https:\/\/redis.io\/commands\/auth\"><code>AUTH<\/code><\/a> command, which is a very important feature of Redis and is coherent with what clients expect from Redis.<\/p>\n\n\n\n<p>Note that &#8220;ACL <em>passwords<\/em> are not really passwords. They are shared secrets between the server and the client, because the password is not an authentication token used by a human being&#8221;. <\/p>\n\n\n\n<p>For instance:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>There are no length limits, the password will just be memorized in some client software. There is no human that needs to recall a password in this context.<\/li>\n\n\n\n<li>The ACL password does not protect any other thing. For example, it will never be the password for some email account.<\/li>\n\n\n\n<li>Often when you are able to access the hashed password itself, by having full access to the Redis commands of a given server, or corrupting the system itself, you already have access to what the password is protecting: the Redis instance stability and the data it contains.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-security-matters\">Security matters<\/h2>\n\n\n\n<p>For the above reasons, slowing down the password authentication, in order to use an algorithm that uses time and space to make password cracking hard, is a very poor choice.<\/p>\n\n\n\n<p>We can instead generate strong passwords, so that nobody will be able to crack it using a dictionary or a brute force attack even if they have the hash.<\/p>\n\n\n\n<p>To perform that we can use  the ACL command <a href=\"https:\/\/redis.io\/commands\/acl-genpass\"><code>ACL GENPASS<\/code><\/a> that generates passwords using the system cryptographic pseudorandom generator:<\/p>\n\n\n\n<p>Syntax:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>127.0.0.1:6379&gt; ACL GENPASS &#091; bits ]<\/code><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"219\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-59-1024x219.png\" alt=\"\" class=\"wp-image-27422\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-59-1024x219.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-59-300x64.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-59-768x164.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-59.png 1229w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><span style=\"text-decoration: underline\">Example:<\/span><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"483\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-60-1024x483.png\" alt=\"\" class=\"wp-image-27423\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-60-1024x483.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-60-300x141.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-60-768x362.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-60.png 1233w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>By default this command outputs a 32-byte (256-bit) pseudorandom string converted to a 64-byte alphanumerical string but you can add the bit number as an argument like above 128 bits<\/p>\n\n\n\n<p>This password complexity is enough to avoid bruteforce attacks and short enough to be easy to manage, cut &amp; paste, store, and so forth. <\/p>\n\n\n\n<p>This is the recommended method you should use in order to generate Redis passwords.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"use-an-external-acl-file\">Use an external ACL file<\/h2>\n\n\n\n<p>We got 2 methods to store Redis users :<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First is to specify them directly in the <code>redis.conf<\/code> file.<\/li>\n\n\n\n<li>The second is to specify an external ACL file.<\/li>\n<\/ul>\n\n\n\n<p>As these two options can&#8217;t work together, You will have to make your choice. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-1st-choice-use-redis-conf-file\">1st choice: Use redis.conf file<\/h3>\n\n\n\n<p>For simple use cases it is the best choice. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-2nd-choice-use-the-acl-file\">2nd choice: Use the ACL file<\/h3>\n\n\n\n<p>Use the ACL file when there are multiple users to define, in a complex environment.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-user-definition-format-in-redis-conf-and-external-acl-file\">User definition format in redis.conf and external ACL file:<\/h2>\n\n\n\n<p><code><strong>redis.conf<\/strong><\/code> and in the <strong>external ACL file<\/strong> use exactly the same format to define users:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>user &#091;username] acl rules \u2026<\/code><\/code><\/pre>\n\n\n\n<p><span style=\"text-decoration: underline\">Example:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>\"user USER_RESTRICTED on #e198a9a8a4a2a5be789e9a11ecf8a48b9f2ed6a2293c99d56d31c74f3d1c43c8 ~* &amp;* +@all -@blocking\"<\/code><\/code><\/pre>\n\n\n\n<p>When you want to use an external ACL file, you must specify the configuration directive called <code>aclfile<\/code>, by adding the absolute path of the file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>127.0.0.1:6379&gt; aclfile \/etc\/redis\/users.acl<\/code><\/code><\/pre>\n\n\n\n<p>When you are just specifying a few users directly inside the <code>redis.conf<\/code> file, you can use <a href=\"https:\/\/redis.io\/commands\/config-rewrite\"><code>CONFIG REWRITE<\/code><\/a> in order to store the new user configuration inside the file by rewriting it.<\/p>\n\n\n\n<p>The external ACL file has more capabilities and allow you useful commands such as ACL LOAD \/SAVE.<\/p>\n\n\n\n<p>You can do the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use <a href=\"https:\/\/redis.io\/commands\/acl-load\"><code>ACL LOAD<\/code><\/a> if you modified the ACL file manually and you want Redis to reload the new configuration. Note that this command is able to load the file <em>only if all the users are correctly specified<\/em>. Otherwise, an error is reported to the user, and the old configuration will remain valid.<\/li>\n\n\n\n<li>Use <a href=\"https:\/\/redis.io\/commands\/acl-save\"><code>ACL SAVE<\/code><\/a> to save the current ACL configuration to the ACL file.<\/li>\n<\/ul>\n\n\n\n<p>Note that <a href=\"https:\/\/redis.io\/commands\/config-rewrite\"><code>CONFIG REWRITE<\/code><\/a> does not also trigger <a href=\"https:\/\/redis.io\/commands\/acl-save\"><code>ACL SAVE<\/code><\/a>. When you use an ACL file, the configuration and the ACLs are handled separately.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2>\n\n\n\n<p>That conclude the Redis ACL part.The secutrity topic is huge and we will probably come bakc to it another time.<\/p>\n\n\n\n<p>Thanks to the <a href=\"https:\/\/redis.io\/\">Redis site <\/a>which is fantastic and well documented.<\/p>\n\n\n\n<p>Feel free to take a look on it and also don&#8217;t forget to visit my other topics <a href=\"https:\/\/www.dbi-services.com\/blog\/author\/nabilsaoual\/\">here <\/a>and the dbi bloggers <a href=\"https:\/\/www.dbi-services.com\/blog\/\">here <\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In the first part with have seen what are Redis ACL and why we are using it.WE also have seen how to list users with the ACL LIST command. Let&#8217;s continue and go deeper with command usage and also how to use an external file. So let&#8217;s go for Redis ACL part two ! [&hellip;]<\/p>\n","protected":false},"author":40,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1739],"tags":[],"type_dbi":[],"class_list":["post-27375","post","type-post","status-publish","format-standard","hentry","category-nosql"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Redis: Using Access Control List (ACL) part2 - dbi Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Redis: Using Access Control List (ACL) part2\" \/>\n<meta property=\"og:description\" content=\"Introduction In the first part with have seen what are Redis ACL and why we are using it.WE also have seen how to list users with the ACL LIST command. Let&#8217;s continue and go deeper with command usage and also how to use an external file. So let&#8217;s go for Redis ACL part two ! [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2023-08-18T19:24:15+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-20T20:50:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-52.png\" \/>\n<meta name=\"author\" content=\"Middleware Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Middleware Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/\"},\"author\":{\"name\":\"Middleware Team\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d8563acfc6e604cce6507f45bac0ea1\"},\"headline\":\"Redis: Using Access Control List (ACL) part2\",\"datePublished\":\"2023-08-18T19:24:15+00:00\",\"dateModified\":\"2023-08-20T20:50:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/\"},\"wordCount\":1665,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-52.png\",\"articleSection\":[\"NoSQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/\",\"name\":\"Redis: Using Access Control List (ACL) part2 - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-52.png\",\"datePublished\":\"2023-08-18T19:24:15+00:00\",\"dateModified\":\"2023-08-20T20:50:00+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d8563acfc6e604cce6507f45bac0ea1\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/#primaryimage\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-52.png\",\"contentUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-52.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Redis: Using Access Control List (ACL) part2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d8563acfc6e604cce6507f45bac0ea1\",\"name\":\"Middleware Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/ddcae7ba0f9d1a0e7ae707f0e689e4a9c95bb48ec49c8e6d9cc86d43f4121cb6?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ddcae7ba0f9d1a0e7ae707f0e689e4a9c95bb48ec49c8e6d9cc86d43f4121cb6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/ddcae7ba0f9d1a0e7ae707f0e689e4a9c95bb48ec49c8e6d9cc86d43f4121cb6?s=96&d=mm&r=g\",\"caption\":\"Middleware Team\"},\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/middleware-team\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Redis: Using Access Control List (ACL) part2 - dbi Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/","og_locale":"en_US","og_type":"article","og_title":"Redis: Using Access Control List (ACL) part2","og_description":"Introduction In the first part with have seen what are Redis ACL and why we are using it.WE also have seen how to list users with the ACL LIST command. Let&#8217;s continue and go deeper with command usage and also how to use an external file. So let&#8217;s go for Redis ACL part two ! [&hellip;]","og_url":"https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/","og_site_name":"dbi Blog","article_published_time":"2023-08-18T19:24:15+00:00","article_modified_time":"2023-08-20T20:50:00+00:00","og_image":[{"url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-52.png","type":"","width":"","height":""}],"author":"Middleware Team","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Middleware Team","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/"},"author":{"name":"Middleware Team","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d8563acfc6e604cce6507f45bac0ea1"},"headline":"Redis: Using Access Control List (ACL) part2","datePublished":"2023-08-18T19:24:15+00:00","dateModified":"2023-08-20T20:50:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/"},"wordCount":1665,"commentCount":0,"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/#primaryimage"},"thumbnailUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-52.png","articleSection":["NoSQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/","url":"https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/","name":"Redis: Using Access Control List (ACL) part2 - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/#primaryimage"},"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/#primaryimage"},"thumbnailUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-52.png","datePublished":"2023-08-18T19:24:15+00:00","dateModified":"2023-08-20T20:50:00+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d8563acfc6e604cce6507f45bac0ea1"},"breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/#primaryimage","url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-52.png","contentUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/08\/image-52.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/redis-using-access-control-list-acl-part2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Redis: Using Access Control List (ACL) part2"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d8563acfc6e604cce6507f45bac0ea1","name":"Middleware Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/ddcae7ba0f9d1a0e7ae707f0e689e4a9c95bb48ec49c8e6d9cc86d43f4121cb6?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/ddcae7ba0f9d1a0e7ae707f0e689e4a9c95bb48ec49c8e6d9cc86d43f4121cb6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ddcae7ba0f9d1a0e7ae707f0e689e4a9c95bb48ec49c8e6d9cc86d43f4121cb6?s=96&d=mm&r=g","caption":"Middleware Team"},"url":"https:\/\/www.dbi-services.com\/blog\/author\/middleware-team\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/27375","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/40"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=27375"}],"version-history":[{"count":67,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/27375\/revisions"}],"predecessor-version":[{"id":27455,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/27375\/revisions\/27455"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=27375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=27375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=27375"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=27375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}