Skip to content

Authentication and permissions

PostgreSQL-role authentication, Redis ACL mode, TLS and the grants each role needs.

pgredis enforces permissions inside the pg_redis C dispatcher on every command. Even if a client bypasses the Go gateway and calls redis.command(...) directly over SQL, the C extension verifies the active PostgreSQL role capabilities or Redis ACL session before touching redis._keyspace or any typed value table.

Authentication modes

The gateway -auth-mode flag selects how Redis clients authenticate:

ModeFlagClient AUTH syntaxIdentity enforced by pg_redis
PostgreSQL role mode-auth-mode native (default)AUTH <pg_role> <password> or AUTH <password> (uses -default-user)PostgreSQL login role and SQL EXECUTE grants on capability functions
Redis ACL mode-auth-mode redis-aclAUTH <acl_user> <password> or AUTH <password> (for default)Redis ACL user row in redis._acl_user accessed via a bound PostgreSQL service role

Before authentication succeeds on a connection that requires AUTH, the gateway restricts incoming command headers to at most 10 arguments and 16,384 bytes per bulk argument so unauthenticated callers cannot allocate large buffers.

PostgreSQL role permissions

In native mode, CREATE EXTENSION pg_redis revokes public access from all internal redis._* tables and functions. Database administrators grant access by granting USAGE ON SCHEMA redis, EXECUTE on entry functions, and EXECUTE on three empty capability marker functions checked by the C dispatcher:

  • redis._read() — required for read-only commands (GET, HGETALL, LRANGE, XRANGE, SUBSCRIBE, WAIT)
  • redis._write() — required for data-modifying commands (SET, DEL, LPUSH, XADD, PUBLISH, EXEC with writes)
  • redis._admin() — required for administrative commands (FLUSHDB, FLUSHALL, CONFIG, SLOWLOG, ACL, DEBUG, MONITOR, MIGRATE)
-- Read/write application role (no admin commands)
CREATE ROLE app_rw LOGIN PASSWORD 'replace-with-strong-password';
GRANT USAGE ON SCHEMA redis TO app_rw;
GRANT EXECUTE ON FUNCTION
  redis._authorize(), redis._abi_version(), redis._read(), redis._write(),
  redis._dispatch(bytea[], integer),
  redis._dispatch(bytea[], integer, integer),
  redis._dispatch_single(bytea[], integer, integer),
  redis._pool_reset(),
  redis.command(text[], integer),
  redis.command_bin(bytea[], integer),
  redis.blocking_begin(bytea[], bytea, integer),
  redis.blocking_begin(bytea[], bytea, integer, integer),
  redis.blocking_poll(bytea, integer),
  redis.blocking_cancel(bytea, integer),
  redis.pubsub_open(bytea, integer),
  redis.pubsub_change(bytea, bytea[]),
  redis.pubsub_poll(bytea),
  redis.pubsub_cancel(bytea)
TO app_rw;

For a read-only role, omit redis._write() from the GRANT EXECUTE list. For an operational administrator role, add redis._admin().

Redis ACL mode

When -auth-mode redis-acl is enabled, the gateway connects to PostgreSQL using a single dedicated service role, and client sessions authenticate against rules stored in redis._acl_user.

  1. Create and bind the PostgreSQL service role

    Create a login role with read, write, and admin dispatch grants, then bind its regrole identity in redis._acl_service as an extension administrator:

    CREATE ROLE redis_service LOGIN PASSWORD 'replace-with-service-password';
    GRANT USAGE ON SCHEMA redis TO redis_service;
    GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA redis TO redis_service;
    
    SELECT redis._dispatch(ARRAY['ACLSERVICE', 'redis_service', 'ON']::bytea[], 0, 0);

    Once bound in redis._acl_service, redis_service cannot execute commands without an active redis._acl_session token.

  2. Configure ACL users and passwords

    Manage users over SQL or from an admin Redis connection:

    SELECT redis.command(ARRAY[
      'ACL', 'SETUSER', 'alice',
      'on', '>alice-secret',
      '~app:*', '&events:*',
      '+@read', '+@write', '-@admin'
    ]);

    Supported ACL subcommands include SETUSER, DELUSER, GETUSER, LIST, USERS, WHOAMI, CAT, GENPASS, DRYRUN, LOG, LOAD, and SAVE (LOAD and SAVE report that no external aclfile is configured because ACLs persist in PostgreSQL WAL).

  3. Start the gateway in redis-acl mode

    Do not place credentials in -pg; pass -acl-service-user and -acl-service-password-file (or PGREDIS_ACL_SERVICE_PASSWORD):

    pgredis \
      -listen 127.0.0.1:6379 \
      -auth-mode redis-acl \
      -acl-service-user redis_service \
      -acl-service-password-file /etc/pgredis/service.pass \
      -pg "postgres://127.0.0.1:5432/postgres?sslmode=disable"

CONFIG SET requirepass updates the password of the default ACL user in redis._acl_config (never a PostgreSQL LOGIN role). CONFIG SET acl-pubsub-default controls the default Pub/Sub channel policy (resetchannels by default, or allchannels) for newly created ACL users and RESET. redis._acl_user, redis._acl_config, and redis._acl_service are registered with pg_extension_config_dump, so pg_dump and pg_restore preserve ACL users and service role bindings across clusters.

Transport and tenant isolation

  • Remote TLS enforcement: Listening on any non-loopback address (0.0.0.0, ::, or a LAN IP) requires -tls-cert and -tls-key (minimum TLS 1.2). Starting without TLS on a non-loopback address fails immediately.
  • Database link security: Never embed a password in the -pg endpoint URL. When PostgreSQL runs on a separate host, configure sslmode=verify-full in the -pg connection string.
  • Tenant isolation: All 16 logical Redis databases (SELECT 0 through SELECT 15) share the same redis._keyspace table, Pub/Sub event queue, and MONITOR ring within one PostgreSQL database. Isolate untrusted tenants in separate PostgreSQL databases with separate pgredis gateway instances.
Scan to open this page
https://mimus.pgsty.com/docs/redis/operations/security/

Table reader