Security and Authentication with the Go Client

Tip
The source code for this tutorial is available on GitHub.

This tutorial demonstrates SASL authentication and role-based cache authorization with the Go Hot Rod client.

Prerequisites

  • A running Infinispan server with the default admin user.

  • Go 1.25 or later.

Running the Example

go run ./security

Code Walkthrough

Connecting with Credentials

The client connects using SCRAM-SHA-256 authentication via the URI.

client, err := hotrod.NewClient(ctx, "hotrod://admin:password@localhost:11222")

Role-Based Authorization

The example creates a secured cache that requires the deployer role. The admin user does not have this role, so operations on the secured cache fail with an authorization error.

const securedCacheConfig = `<distributed-cache name="securedCache">
    <security>
        <authorization enabled="true" roles="deployer"/>
    </security>
</distributed-cache>`

Expected Output

Successfully put value in 'test' cache.
Put to secured cache failed as expected: <authorization error>
Caches removed.