Skip to content

Commit 0f016e6

Browse files
authored
Merge pull request #109 from yossigo/acl-auth-support
Add support for Redis 6.x ACL AUTH.
2 parents 02c2e17 + 1954ca3 commit 0f016e6

File tree

3 files changed

+103
-16
lines changed

3 files changed

+103
-16
lines changed

memtier_benchmark.1

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.3.
2-
.TH MEMTIER_BENCHMARK "1" "December 2016" "memtier_benchmark 1.2.7" "User Commands"
1+
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.11.
2+
.TH MEMTIER_BENCHMARK "1" "January 2020" "memtier_benchmark 1.2.17" "User Commands"
33
.SH NAME
44
memtier_benchmark \- NoSQL benchmark tool
55
.SH SYNOPSIS
@@ -23,6 +23,27 @@ Protocol to use (default: redis). Other
2323
supported protocols are memcache_text,
2424
memcache_binary.
2525
.TP
26+
\fB\-a\fR, \fB\-\-authenticate\fR=\fI\,CREDENTIALS\/\fR Authenticate using specified credentials.
27+
A simple password is used for memcache_text
28+
and Redis <= 5.x. <USER>:<PASSWORD> can be
29+
specified for memcache_binary or Redis 6.x
30+
or newer with ACL user support.
31+
.TP
32+
\fB\-\-tls\fR
33+
Enable SSL/TLS transport security
34+
.TP
35+
\fB\-\-cert\fR=\fI\,FILE\/\fR
36+
Use specified client certificate for TLS
37+
.TP
38+
\fB\-\-key\fR=\fI\,FILE\/\fR
39+
Use specified private key for TLS
40+
.TP
41+
\fB\-\-cacert\fR=\fI\,FILE\/\fR
42+
Use specified CA certs bundle for TLS
43+
.TP
44+
\fB\-\-tls\-skip\-verify\fR
45+
Skip verification of server certificate
46+
.TP
2647
\fB\-x\fR, \fB\-\-run\-count\fR=\fI\,NUMBER\/\fR
2748
Number of full\-test iterations to perform
2849
.TP
@@ -35,12 +56,18 @@ Produce per\-client stats file
3556
\fB\-\-out\-file\fR=\fI\,FILE\/\fR
3657
Name of output file (default: stdout)
3758
.TP
59+
\fB\-\-json\-out\-file\fR=\fI\,FILE\/\fR
60+
Name of JSON output file, if not set, will not print to json
61+
.TP
3862
\fB\-\-show\-config\fR
3963
Print detailed configuration before running
4064
.TP
4165
\fB\-\-hide\-histogram\fR
4266
Don't print detailed latency histogram
4367
.TP
68+
\fB\-\-cluster\-mode\fR
69+
Run client in cluster mode
70+
.TP
4471
\fB\-\-help\fR
4572
Display this help
4673
.TP
@@ -73,9 +100,6 @@ Number of requests after which re\-connection is performed
73100
\fB\-\-multi\-key\-get\fR=\fI\,NUM\/\fR
74101
Enable multi\-key get commands, up to NUM keys (default: 0)
75102
.TP
76-
\fB\-a\fR, \fB\-\-authenticate\fR=\fI\,CREDENTIALS\/\fR Authenticate to redis using CREDENTIALS, which depending
77-
on the protocol can be PASSWORD or USER:PASSWORD.
78-
.TP
79103
\fB\-\-select\-db\fR=\fI\,DB\/\fR
80104
DB number to select, when testing a redis server
81105
.TP
@@ -84,6 +108,26 @@ Use a different random seed for each client
84108
.TP
85109
\fB\-\-randomize\fR
86110
random seed based on timestamp (default is constant value)
111+
.SS "Arbitrary command:"
112+
.TP
113+
\fB\-\-command\fR=\fI\,COMMAND\/\fR
114+
Specify a command to send in quotes.
115+
Each command that you specify is run with its ratio and key\-pattern options.
116+
For example: \fB\-\-command=\fR"set __key__ 5" \fB\-\-command\-ratio\fR=\fI\,2\/\fR \fB\-\-command\-key\-pattern\fR=\fI\,G\/\fR
117+
To use a generated key or object, enter:
118+
.TP
119+
__key__: Use key generated from Key Options.
120+
__data__: Use data generated from Object Options.
121+
.TP
122+
\fB\-\-command\-ratio\fR
123+
The number of times the command is sent in sequence.(default: 1)
124+
.TP
125+
\fB\-\-command\-key\-pattern\fR
126+
Key pattern for the command (default: R):
127+
G for Gaussian distribution.
128+
R for uniform Random.
129+
S for Sequential.
130+
P for Parallel (Sequential were each client has a subset of the key\-range).
87131
.SS "Object Options:"
88132
.TP
89133
\fB\-d\fR \fB\-\-data\-size\fR=\fI\,SIZE\/\fR
@@ -163,7 +207,7 @@ WAIT for a random number of slaves in the specified range
163207
WAIT for a random number of milliseconds in the specified range (normal
164208
distribution with the center in the middle of the range)
165209
.SH COPYRIGHT
166-
Copyright \(co 2011\-2016 Redis Labs Ltd.
210+
Copyright \(co 2011\-2017 Redis Labs Ltd.
167211
.br
168212
This is free software. You may redistribute copies of it under the terms of
169213
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.

memtier_benchmark.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ static int config_parse_args(int argc, char *argv[], struct benchmark_config *cf
462462
case 'v':
463463
puts(PACKAGE_STRING);
464464
// FIXME!!
465-
puts("Copyright (C) 2011-2017 Redis Labs Ltd.");
465+
puts("Copyright (C) 2011-2020 Redis Labs Ltd.");
466466
puts("This is free software. You may redistribute copies of it under the terms of");
467467
puts("the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.");
468468
puts("There is NO WARRANTY, to the extent permitted by law.");
@@ -840,7 +840,11 @@ void usage() {
840840
" -P, --protocol=PROTOCOL Protocol to use (default: redis). Other\n"
841841
" supported protocols are memcache_text,\n"
842842
" memcache_binary.\n"
843-
" -a, --authenticate=CREDENTIALS Authenticate to redis using CREDENTIALS, which depending\n"
843+
" -a, --authenticate=CREDENTIALS Authenticate using specified credentials.\n"
844+
" A simple password is used for memcache_text\n"
845+
" and Redis <= 5.x. <USER>:<PASSWORD> can be\n"
846+
" specified for memcache_binary or Redis 6.x\n"
847+
" or newer with ACL user support.\n"
844848
#ifdef USE_TLS
845849
" --tls Enable SSL/TLS transport security\n"
846850
" --cert=FILE Use specified client certificate for TLS\n"
@@ -849,7 +853,6 @@ void usage() {
849853
" --tls-skip-verify Skip verification of server certificate\n"
850854
" --sni=STRING Add an SNI header\n"
851855
#endif
852-
" on the protocol can be PASSWORD or USER:PASSWORD.\n"
853856
" -x, --run-count=NUMBER Number of full-test iterations to perform\n"
854857
" -D, --debug Print debug output\n"
855858
" --client-stats=FILE Produce per-client stats file\n"

protocol.cpp

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,53 @@ int redis_protocol::authenticate(const char *credentials)
203203
int size = 0;
204204
assert(credentials != NULL);
205205

206-
size = evbuffer_add_printf(m_write_buf,
207-
"*2\r\n"
208-
"$4\r\n"
209-
"AUTH\r\n"
210-
"$%u\r\n"
211-
"%s\r\n",
212-
(unsigned int)strlen(credentials), credentials);
206+
/* Credentials may be one of:
207+
* <PASSWORD> For Redis <6.0 simple AUTH commands.
208+
* <USER>:<PASSWORD> For Redis 6.0+ AUTH with both username and password.
209+
*
210+
* A :<PASSWORD> will be handled as a special case of quoting a password that
211+
* contains a colon.
212+
*/
213+
214+
const char *user = NULL;
215+
const char *password;
216+
217+
if (credentials[0] == ':') {
218+
password = credentials + 1;
219+
} else {
220+
password = strchr(credentials, ':');
221+
if (!password) {
222+
password = credentials;
223+
} else {
224+
user = credentials;
225+
password++;
226+
}
227+
}
228+
229+
if (!user) {
230+
size = evbuffer_add_printf(m_write_buf,
231+
"*2\r\n"
232+
"$4\r\n"
233+
"AUTH\r\n"
234+
"$%zu\r\n"
235+
"%s\r\n",
236+
strlen(password), password);
237+
} else {
238+
size_t user_len = password - user - 1;
239+
size = evbuffer_add_printf(m_write_buf,
240+
"*3\r\n"
241+
"$4\r\n"
242+
"AUTH\r\n"
243+
"$%zu\r\n"
244+
"%.*s\r\n"
245+
"$%zu\r\n"
246+
"%s\r\n",
247+
user_len,
248+
(int) user_len,
249+
user,
250+
strlen(password),
251+
password);
252+
}
213253
return size;
214254
}
215255

0 commit comments

Comments
 (0)