redis: create redis user in client

This commit is contained in:
egarette@silique.fr 2023-06-23 08:10:03 +02:00
parent cc56ea6286
commit 84e583f8a4
16 changed files with 56 additions and 43 deletions

View file

@ -1,3 +1,5 @@
format: '0.1' format: '0.1'
description: Application service needs interact with a Redis server description: Application service needs interact with a Redis server
website: https://redis.io/ website: https://redis.io/
depends:
- redis-common

View file

@ -1,15 +1,17 @@
<?xml version='1.0' encoding='UTF-8'?> <?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.10"> <rougail version="0.10">
<services> <services>
<service name="redis-client" target="risotto" engine="cheetah"> <service name="redis-client" target="risotto" engine="ansible">
<certificate authority="Redis" owner="redis_client_key_owner" owner_type="variable" server="redis_client_server_domainname">redis</certificate> <certificate authority="Redis" owner="redis_client_key_owner" owner_type="variable" server="redis_client_server_domainname">redis</certificate>
</service> </service>
</services> </services>
<variables> <variables>
<family name="redis" description="Redis"> <family name="redis" description="Redis">
<variable name="redis_client_server_domainname" type="domainname" description="Nom de domaine du serveur" mandatory="True" supplier="Redis"/> <variable name="redis_client_server_domainname" type="domainname" description="Nom de domaine du serveur Redis" mandatory="True" supplier="Redis"/>
<variable name="redis_client_username" description="Nom d'utilisateur" mandatory="True" supplier="Redis:username"/> <variable name="redis_client_username" description="Nom d'utilisateur" mandatory="True" supplier="Redis:username"/>
<variable name="redis_client_password" type="password" description="Mot de passe de connexion" mandatory="True" supplier="Redis:password"/> <variable name="redis_client_password" type="password" description="Mot de passe de connexion" mandatory="True" supplier="Redis:password"/>
<variable name="redis_server" description="Remote" type="domainname" multi="True" provider="RedisClient" hidden="True"/>
<variable name="redis_client_index" type="number" description="Redis index" mandatory='True' provider="RedisClient:index"/>
<variable name="redis_client_key_owner" type="unix_user" description="Key owner" mandatory="True" hidden="True"> <variable name="redis_client_key_owner" type="unix_user" description="Key owner" mandatory="True" hidden="True">
<value>apache</value> <value>apache</value>
</variable> </variable>

View file

@ -1 +0,0 @@
PKG="$PKG redis"

View file

@ -4,5 +4,5 @@ Before=risotto.target
[Service] [Service]
Type=oneshot Type=oneshot
User=%%redis_client_key_owner User={{ general.redis.redis_client_key_owner }}
ExecStart=/usr/bin/timeout 90 bash -c 'while ! /usr/bin/redis-cli --tls -a %%redis_client_password --cacert %%tls_ca_directory/Redis.crt --cert %%tls_cert_directory/redis.crt --key %%tls_key_directory/redis.key -h %%redis_client_server_domainname -p 6380 PING; do sleep 1; done' ExecStart=/usr/bin/timeout 90 bash -c 'while ! /usr/bin/redis-cli --tls -a {{ general.redis.redis_client_password }} --cacert {{ general.tls_ca_directory }}/Redis.crt --cert {{ general.tls_cert_directory }}/redis.crt --key {{ general.tls_key_directory }}/redis.key -h {{ general.redis.redis_client_server_domainname }} -p 6380 PING; do sleep 1; done'

View file

@ -0,0 +1,3 @@
format: '0.1'
description: Redis, an in-memory data structure store
website: https://redis.io/

View file

@ -0,0 +1,8 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.10">
<services>
<service name="redis">
<file engine="none" source="sysuser-redis.conf">/sysusers.d/0redis.conf</file>
</service>
</services>
</rougail>

View file

@ -2,4 +2,5 @@ format: '0.1'
description: Redis, an in-memory data structure store description: Redis, an in-memory data structure store
website: https://redis.io/ website: https://redis.io/
depends: depends:
- base-fedora-37 - base-fedora-38
- redis-common

View file

@ -2,12 +2,11 @@
<rougail version="0.10"> <rougail version="0.10">
<services> <services>
<service name="redis" target="multi-user"> <service name="redis" target="multi-user">
<ip ip_type='variable'>account.remote_ip</ip> <ip ip_type='variable'>accounts.remote_.ip_</ip>
<certificate authority="Redis" owner="redis" type="server">redis</certificate> <certificate authority="Redis" owner="redis" type="server">redis</certificate>
<file>/etc/redis/redis.conf</file> <file engine="ansible">/etc/redis/redis.conf</file>
<file engine="none" source="sysuser-redis.conf">/sysusers.d/0redis.conf</file>
<file engine="none" source="tmpfile-redis.conf">/tmpfiles.d/0redis.conf</file> <file engine="none" source="tmpfile-redis.conf">/tmpfiles.d/0redis.conf</file>
<file filelist="copy_tests">/tests/redis.yml</file> <file engine="ansible" filelist="copy_tests">/tests/redis.yml</file>
</service> </service>
</services> </services>
<variables> <variables>

View file

@ -1,17 +0,0 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.10">
<variables>
<variable name="remote" description="Remote Redis client needing an account" type="domainname" provider="Redis" mandatory="True"/>
<variable name="remote_ip" description="Remote IP" type="ip" mandatory="True"/>
<variable name="username" auto_save="False" hidden="True" type="password" mandatory="True" provider="Redis:username"/>
<variable name="password" auto_save="False" hidden="True" type="password" mandatory="True" provider="Redis:password"/>
</variables>
<constraints>
<fill name="get_ip">
<param type="information">zones</param>
<param type="variable">account.remote</param>
<target>account.remote_ip</target>
</fill>
</constraints>
</rougail>

View file

@ -0,0 +1,8 @@
def redis_index_of(remotes, suffix):
return remotes.index(suffix)
def redis_only_one(idx):
if idx:
# see https://github.com/redis/redis/issues/8099#issuecomment-741868975
raise Exception('Redis only works for one service')

View file

@ -1 +0,0 @@
PKG="$PKG redis"

View file

@ -178,7 +178,7 @@ timeout 0
# Redis default starting with Redis 3.2.1. # Redis default starting with Redis 3.2.1.
#>GNUNUX #>GNUNUX
#tcp-keepalive 300 #tcp-keepalive 300
tcp-keepalive %%redis_tcp_keepalive tcp-keepalive {{ general.redis.redis_tcp_keepalive }}
#<GNUNUX #<GNUNUX
# Apply OS-specific mechanism to mark the listening socket with the specified # Apply OS-specific mechanism to mark the listening socket with the specified
@ -243,9 +243,9 @@ tcp-keepalive %%redis_tcp_keepalive
# tls-ca-cert-dir /etc/ssl/certs # tls-ca-cert-dir /etc/ssl/certs
#>GNUNUX #>GNUNUX
tls-port 6380 tls-port 6380
tls-cert-file %%tls_cert_directory/redis.crt tls-cert-file {{ general.tls_cert_directory }}/redis.crt
tls-key-file %%tls_key_directory/redis.key tls-key-file {{ general.tls_key_directory }}/redis.key
tls-ca-cert-file %%tls_ca_directory/Redis.crt tls-ca-cert-file {{ general.tls_ca_directory }}/Redis.crt
#<GNUNUX #<GNUNUX
# By default, clients (including replica servers) on a TLS port are required # By default, clients (including replica servers) on a TLS port are required
@ -396,7 +396,7 @@ syslog-enabled yes
# Set the number of databases. The default database is DB 0, you can select # Set the number of databases. The default database is DB 0, you can select
# a different one on a per-connection basis using SELECT <dbid> where # a different one on a per-connection basis using SELECT <dbid> where
# dbid is a number between 0 and 'databases'-1 # dbid is a number between 0 and 'databases'-1
databases 16 databases {{ accounts.remotes | length }}
# By default Redis shows an ASCII art logo only when started to log to the # By default Redis shows an ASCII art logo only when started to log to the
# standard output and if the standard output is a TTY and syslog logging is # standard output and if the standard output is a TTY and syslog logging is
@ -452,9 +452,9 @@ proc-title-template "{title} {listen-addr} {server-mode}"
# #
# save 3600 1 300 100 60 10000 # save 3600 1 300 100 60 10000
#>GNUNUX #>GNUNUX
%if %%redis_save {% if redis_save %}
save 900 1 300 10 60 10000 save 900 1 300 10 60 10000
%end if {% endif %}
#<GNUNUX #<GNUNUX
# By default Redis will stop accepting writes if RDB snapshots are enabled # By default Redis will stop accepting writes if RDB snapshots are enabled
@ -1035,7 +1035,11 @@ replica-priority 100
# For more information about ACL configuration please refer to # For more information about ACL configuration please refer to
# the Redis web site at https://redis.io/topics/acl # the Redis web site at https://redis.io/topics/acl
#>GNUNUX #>GNUNUX
user %%account.username on >%%account.password ~* &* +@all {% for remote in accounts.remotes %}
{% set remote = remote|normalize_family %}
{% set account = accounts['remote_' + remote] %}
user {{ account['username_' + remote] }} on >{{ account['password_' + remote] }} ~* &* +@all
{% endfor %}
#<GNUNUX #<GNUNUX
# ACL LOG # ACL LOG
@ -1069,7 +1073,8 @@ acllog-max-len 128
# #
# requirepass foobared # requirepass foobared
#>GNUNUX #>GNUNUX
requirepass %%account.password {% set remote = accounts.remotes[0]|normalize_family %}
requirepass {{ accounts['remote_' + remote]['password_' + remote] }}
#<GNUNUX #<GNUNUX
# New users are initialized with restrictive permissions by default, via the # New users are initialized with restrictive permissions by default, via the
@ -1128,7 +1133,7 @@ requirepass %%account.password
# #
# maxclients 10000 # maxclients 10000
#>GNUNUX #>GNUNUX
maxclients %%redis_max_clients maxclients {{ general.redis.redis_max_clients }}
#<GNUNUX #<GNUNUX
############################## MEMORY MANAGEMENT ################################ ############################## MEMORY MANAGEMENT ################################
@ -1158,7 +1163,7 @@ maxclients %%redis_max_clients
# #
# maxmemory <bytes> # maxmemory <bytes>
#>GNUNUX #>GNUNUX
maxmemory %%{redis_max_memory}mb maxmemory {{ redis_max_memory }}mb
#<GNUNUX #<GNUNUX
# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
@ -1190,7 +1195,7 @@ maxmemory %%{redis_max_memory}mb
# #
# maxmemory-policy noeviction # maxmemory-policy noeviction
#>GNUNUX #>GNUNUX
maxmemory-policy %%redis_memory_policy maxmemory-policy {{ redis_memory_policy }}
#<GNUNUX #<GNUNUX
# LRU, LFU and minimal TTL algorithms are not precise algorithms but approximated # LRU, LFU and minimal TTL algorithms are not precise algorithms but approximated

View file

@ -1,3 +1,7 @@
address: %%ip_eth0 address: {{ general.network.interface_0.ip_eth0 }}
username: %%account.username {% for remote in accounts.remotes %}
password: %%account.password {% set remote = remote|normalize_family %}
{% set account = accounts['remote_' + remote] %}
username: {{ account['username_' + remote] }}
password: {{ account['password_' + remote] }}
{% endfor %}