Skip to content

Commit 1b9089e

Browse files
committed
Add redis auth support sameersbn#1026 auto commit
1 parent 36e6bac commit 1b9089e

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,12 @@ The internal redis server has been removed from the image. Please use a [linked
327327

328328
The image can be configured to use an external redis server. The configuration should be specified using environment variables while starting the GitLab image.
329329

330-
*Assuming that the redis server host is 192.168.1.100*
330+
*Assuming that the redis server host is 192.168.1.100*, and configured to use authentication*
331331

332332
```bash
333333
docker run --name gitlab -it --rm \
334334
--env 'REDIS_HOST=192.168.1.100' --env 'REDIS_PORT=6379' \
335+
--env 'REDIS_PASSWORD=p4ssw0rd' \
335336
sameersbn/gitlab:13.0.6
336337
```
337338

assets/runtime/config/gitlabhq/resque.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ test:
1414
url: redis://localhost:6379
1515
production:
1616
# Redis (single instance)
17-
url: redis://{{REDIS_HOST}}:{{REDIS_PORT}}/{{REDIS_DB_NUMBER}}
17+
url: redis://{{REDIS_PASSWORD}}{{REDIS_HOST}}:{{REDIS_PORT}}/{{REDIS_DB_NUMBER}}
1818
##
1919
# Redis + Sentinel (for HA)
2020
#

assets/runtime/functions

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,12 @@ gitlab_finalize_redis_parameters() {
205205
}
206206

207207
gitlab_check_redis_connection() {
208+
REDIS_FLAG=""
209+
if [[ -n ${REDIS_PASSWORD} ]]; then
210+
REDIS_FLAG="-a ${REDIS_PASSWORD}"
211+
fi
208212
timeout=60
209-
while ! redis-cli -h ${REDIS_HOST} -p ${REDIS_PORT} -n ${REDIS_DB_NUMBER} ping >/dev/null 2>&1
213+
while ! redis-cli -h ${REDIS_HOST} ${REDIS_FLAG} -p ${REDIS_PORT} -n ${REDIS_DB_NUMBER} ping >/dev/null 2>&1
210214
do
211215
timeout=$(expr $timeout - 1)
212216
if [[ $timeout -eq 0 ]]; then
@@ -226,10 +230,15 @@ gitlab_configure_redis() {
226230
gitlab_finalize_redis_parameters
227231
gitlab_check_redis_connection
228232

233+
if [[ -n ${REDIS_PASSWORD} ]]; then
234+
REDIS_PASSWORD=':'${REDIS_PASSWORD}'@'
235+
fi
236+
229237
update_template ${GITLAB_RESQUE_CONFIG} \
230238
REDIS_HOST \
231239
REDIS_PORT \
232-
REDIS_DB_NUMBER
240+
REDIS_DB_NUMBER \
241+
REDIS_PASSWORD
233242
}
234243

235244
gitlab_configure_gitaly() {

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ services:
66
image: redis:5.0.9
77
command:
88
- --loglevel warning
9+
- --requirepass "p4ssw0rd"
910
volumes:
1011
- redis-data:/var/lib/redis:Z
1112

0 commit comments

Comments
 (0)