summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2019-02-07 17:20:03 +0100
committerantirez <antirez@gmail.com>2019-02-07 17:20:03 +0100
commit80f987726d8ccf9ffc0ce73599226e0e14f26a8a (patch)
treeee1d6375b232ed5bff75920cda12bf2247d9d67f
parentdb30727547d7b48b73f92c19bebad2aef1514dfe (diff)
downloadredis-80f987726d8ccf9ffc0ce73599226e0e14f26a8a.tar.gz
ACL: load ACL file at startup. Prevent silly configurations.
-rw-r--r--src/acl.c33
-rw-r--r--src/server.c6
-rw-r--r--src/server.h1
3 files changed, 35 insertions, 5 deletions
diff --git a/src/acl.c b/src/acl.c
index fecd33e8a..4ae5830bd 100644
--- a/src/acl.c
+++ b/src/acl.c
@@ -1227,6 +1227,39 @@ sds ACLLoadFromFile(const char *filename) {
}
}
+/* This function is called once the server is already running, modules are
+ * loaded, and we are ready to start, in order to load the ACLs either from
+ * the pending list of users defined in redis.conf, or from the ACL file.
+ * The function will just exit with an error if the user is trying to mix
+ * both the loading methods. */
+void ACLLoadUsersAtStartup(void) {
+ if (server.acl_filename[0] != '\0' && listLength(UsersToLoad) != 0) {
+ serverLog(LL_WARNING,
+ "Configuring Redis with users defined in redis.conf and at "
+ "the same setting an ACL file path is invalid. This setup "
+ "is very likely to lead to configuration errors and security "
+ "holes, please define either an ACL file or declare users "
+ "directly in your redis.conf, but not both.");
+ exit(1);
+ }
+
+ if (ACLLoadConfiguredUsers() == C_ERR) {
+ serverLog(LL_WARNING,
+ "Critical error while loading ACLs. Exiting.");
+ exit(1);
+ }
+
+ if (server.acl_filename[0] != '\0') {
+ sds errors = ACLLoadFromFile(server.acl_filename);
+ if (errors) {
+ serverLog(LL_WARNING,
+ "Aborting Redis startup because of ACL errors: %s", errors);
+ sdsfree(errors);
+ exit(1);
+ }
+ }
+}
+
/* =============================================================================
* ACL related commands
* ==========================================================================*/
diff --git a/src/server.c b/src/server.c
index de84e430e..c257d0573 100644
--- a/src/server.c
+++ b/src/server.c
@@ -4908,11 +4908,7 @@ int main(int argc, char **argv) {
linuxMemoryWarnings();
#endif
moduleLoadFromQueue();
- if (ACLLoadConfiguredUsers() == C_ERR) {
- serverLog(LL_WARNING,
- "Critical error while loading ACLs. Exiting.");
- exit(1);
- }
+ ACLLoadUsersAtStartup();
loadDataFromDisk();
if (server.cluster_enabled) {
if (verifyClusterConfigWithData() == C_ERR) {
diff --git a/src/server.h b/src/server.h
index d2c6aa1e0..59f7cbe10 100644
--- a/src/server.h
+++ b/src/server.h
@@ -1746,6 +1746,7 @@ int ACLAppendUserForLoading(sds *argv, int argc, int *argc_err);
char *ACLSetUserStringError(void);
int ACLLoadConfiguredUsers(void);
sds ACLDescribeUser(user *u);
+void ACLLoadUsersAtStartup(void);
/* Sorted sets data type */