Skip to content

Commit 021e9af

Browse files
authored
feat: Support Redis ACL username in the Go feature server's Redis online store (#7130)
* feat: Support Redis ACL username in the Go feature server's Redis online store The Go Redis online store accepted only password, ssl and db in connection_string and never set Username on the go-redis options, so it always authenticated as the default user. Accept username=<name> and set it on both the single-node and cluster clients, matching the Python SDK. List all supported options in the unrecognized-option error. Signed-off-by: gavishtea <10455554+gavishtea@users.noreply.github.com> * test: Allowlist dummy Redis passwords for detect-secrets Mark the placeholder passwords in the new Redis ACL username tests with pragma: allowlist secret, and refresh the line number of the existing redisonlinestore_test.go entry in .secrets.baseline. Signed-off-by: gavishtea <10455554+gavishtea@users.noreply.github.com> * fix: Parse Redis connection_string options before addresses Options were matched only after the ':' address check, so an option value containing ':' (such as username=team:feast or a password with a colon) was treated as a host:port address. The client then authenticated as the default user, and the cluster client got an extra bogus seed address. Check for '=' first, as the Python SDK parser does. Signed-off-by: gavishtea <10455554+gavishtea@users.noreply.github.com> --------- Signed-off-by: gavishtea <10455554+gavishtea@users.noreply.github.com>
1 parent 9a8ed5a commit 021e9af

4 files changed

Lines changed: 147 additions & 8 deletions

File tree

‎.secrets.baseline‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/reference/online-stores/redis.md‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ online_store:
6565
```
6666
{% endcode %}
6767
68+
Connecting as a named Redis ACL user (Redis 6+, e.g. AWS ElastiCache RBAC user groups where the `default` user is disabled):
69+
70+
{% code title="feature_store.yaml" %}
71+
```yaml
72+
project: my_feature_repo
73+
registry: data/registry.db
74+
provider: local
75+
online_store:
76+
type: redis
77+
connection_string: "redis1:6379,username=feast,password=my_password,ssl=true"
78+
```
79+
{% endcode %}
80+
81+
{% hint style="info" %}
82+
The Go feature server's Redis online store supports `redis` and `redis_cluster` and accepts only the `password`, `username`, `ssl`, and `db` options in `connection_string` (`db` is ignored for clusters). Any other option causes an error.
83+
{% endhint %}
84+
6885
## TTL configuration
6986

7087
The Redis online store supports two complementary TTL mechanisms:
@@ -195,7 +212,7 @@ The Redis online store implements `online_write_batch_async()` using the async R
195212
| --- | --- | --- |
196213
| `type` | `redis` | Online store type selector |
197214
| `redis_type` | `redis` | Connection type: `redis`, `redis_cluster`, or `redis_sentinel` |
198-
| `connection_string` | `localhost:6379` | Host:port and optional parameters. For cluster: `redis1:6379,redis2:6379,ssl=true,password=...` |
215+
| `connection_string` | `localhost:6379` | Host:port and optional parameters (e.g. `password`, `username`, `ssl`, `db`). For cluster: `redis1:6379,redis2:6379,ssl=true,username=...,password=...` |
199216
| `sentinel_master` | `mymaster` | Sentinel master name (only used when `redis_type: redis_sentinel`) |
200217
| `key_ttl_seconds` | `null` | Redis `EXPIRE` TTL in seconds applied to the entity hash key after each write. Expires all feature views for that entity together. |
201218
| `full_scan_for_deletion` | `true` | When `true`, deleting or renaming a feature view scans Redis to remove its hash fields. Set `false` to skip deletion scans (faster `feast apply`, but leaves orphaned data). |

‎go/internal/feast/onlinestore/redisonlinestore.go‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func NewRedisOnlineStore(project string, config *registry.RepoConfig, onlineStor
5959

6060
var address []string
6161
var password string
62+
var username string
6263
var tlsConfig *tls.Config
6364
var db int // Default to 0
6465

@@ -69,7 +70,7 @@ func NewRedisOnlineStore(project string, config *registry.RepoConfig, onlineStor
6970
}
7071
store.t = redisStoreType
7172

72-
// Parse connection_string and write it into conf.address, conf.password, and conf.ssl
73+
// Parse connection_string and write it into conf.address, conf.username, conf.password, and conf.ssl
7374
redisConnJson, ok := onlineStoreConfig["connection_string"]
7475
if !ok {
7576
// Default to "localhost:6379"
@@ -80,12 +81,14 @@ func NewRedisOnlineStore(project string, config *registry.RepoConfig, onlineStor
8081
} else {
8182
parts := strings.Split(redisConnStr, ",")
8283
for _, part := range parts {
83-
if strings.Contains(part, ":") {
84-
address = append(address, part)
85-
} else if strings.Contains(part, "=") {
84+
// Check for options before addresses so that option values containing ':'
85+
// (e.g. username=team:feast) are not mistaken for host:port addresses.
86+
if strings.Contains(part, "=") {
8687
kv := strings.SplitN(part, "=", 2)
8788
if kv[0] == "password" {
8889
password = kv[1]
90+
} else if kv[0] == "username" {
91+
username = kv[1]
8992
} else if kv[0] == "ssl" {
9093
result, err := strconv.ParseBool(kv[1])
9194
if err != nil {
@@ -99,8 +102,10 @@ func NewRedisOnlineStore(project string, config *registry.RepoConfig, onlineStor
99102
return nil, err
100103
}
101104
} else {
102-
return nil, fmt.Errorf("unrecognized option in connection_string: %s. Must be one of 'password', 'ssl'", kv[0])
105+
return nil, fmt.Errorf("unrecognized option in connection_string: %s. Must be one of 'password', 'username', 'ssl', 'db'", kv[0])
103106
}
107+
} else if strings.Contains(part, ":") {
108+
address = append(address, part)
104109
} else {
105110
return nil, fmt.Errorf("unable to parse a part of connection_string: %s. Must contain either ':' (addresses) or '=' (options", part)
106111
}
@@ -117,6 +122,7 @@ func NewRedisOnlineStore(project string, config *registry.RepoConfig, onlineStor
117122
log.Info().Msgf("Using Redis: %s", address[0])
118123
store.client = redis.NewClient(&redis.Options{
119124
Addr: address[0],
125+
Username: username,
120126
Password: password,
121127
DB: db,
122128
TLSConfig: tlsConfig,
@@ -128,6 +134,7 @@ func NewRedisOnlineStore(project string, config *registry.RepoConfig, onlineStor
128134
log.Info().Msgf("Using Redis Cluster: %s", address)
129135
store.clusterClient = redis.NewClusterClient(&redis.ClusterOptions{
130136
Addrs: address,
137+
Username: username,
131138
Password: password,
132139
TLSConfig: tlsConfig,
133140
ReadOnly: true,

‎go/internal/feast/onlinestore/redisonlinestore_test.go‎

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/feast-dev/feast/go/protos/feast/types"
88

99
"github.com/stretchr/testify/assert"
10+
"github.com/stretchr/testify/require"
1011
)
1112

1213
func TestNewRedisOnlineStore(t *testing.T) {
@@ -21,6 +22,7 @@ func TestNewRedisOnlineStore(t *testing.T) {
2122
assert.Nil(t, err)
2223
var opts = store.client.Options()
2324
assert.Equal(t, opts.Addr, "redis://localhost:6379")
25+
assert.Equal(t, opts.Username, "")
2426
assert.Equal(t, opts.Password, "")
2527
assert.Equal(t, opts.DB, 0)
2628
assert.Nil(t, opts.TLSConfig)
@@ -38,6 +40,7 @@ func TestNewRedisOnlineStoreWithPassword(t *testing.T) {
3840
assert.Nil(t, err)
3941
var opts = store.client.Options()
4042
assert.Equal(t, opts.Addr, "redis://localhost:6379")
43+
assert.Equal(t, opts.Username, "")
4144
assert.Equal(t, opts.Password, "secret")
4245
}
4346

@@ -71,6 +74,118 @@ func TestNewRedisOnlineStoreWithSsl(t *testing.T) {
7174
assert.NotNil(t, opts.TLSConfig)
7275
}
7376

77+
func TestNewRedisOnlineStoreWithUsername(t *testing.T) {
78+
var config = map[string]interface{}{
79+
"connection_string": "redis://localhost:6379,username=feast,password=secret",
80+
}
81+
rc := &registry.RepoConfig{
82+
OnlineStore: config,
83+
EntityKeySerializationVersion: 3,
84+
}
85+
store, err := NewRedisOnlineStore("test", rc, config)
86+
require.NoError(t, err)
87+
var opts = store.client.Options()
88+
assert.Equal(t, "redis://localhost:6379", opts.Addr)
89+
assert.Equal(t, "feast", opts.Username)
90+
assert.Equal(t, "secret", opts.Password)
91+
}
92+
93+
func TestNewRedisOnlineStoreWithUsernameAfterPassword(t *testing.T) {
94+
var config = map[string]interface{}{
95+
"connection_string": "redis://localhost:6379,password=secret,username=feast", // pragma: allowlist secret
96+
}
97+
rc := &registry.RepoConfig{
98+
OnlineStore: config,
99+
EntityKeySerializationVersion: 3,
100+
}
101+
store, err := NewRedisOnlineStore("test", rc, config)
102+
require.NoError(t, err)
103+
var opts = store.client.Options()
104+
assert.Equal(t, "feast", opts.Username)
105+
assert.Equal(t, "secret", opts.Password)
106+
}
107+
108+
func TestNewRedisOnlineStoreClusterWithUsername(t *testing.T) {
109+
var config = map[string]interface{}{
110+
"redis_type": "redis_cluster",
111+
"connection_string": "node1:6379,node2:6379,username=feast,password=secret,ssl=true", // pragma: allowlist secret
112+
}
113+
rc := &registry.RepoConfig{
114+
OnlineStore: config,
115+
EntityKeySerializationVersion: 3,
116+
}
117+
store, err := NewRedisOnlineStore("test", rc, config)
118+
require.NoError(t, err)
119+
var opts = store.clusterClient.Options()
120+
assert.Equal(t, []string{"node1:6379", "node2:6379"}, opts.Addrs)
121+
assert.Equal(t, "feast", opts.Username)
122+
assert.Equal(t, "secret", opts.Password)
123+
assert.NotNil(t, opts.TLSConfig)
124+
}
125+
126+
func TestNewRedisOnlineStoreWithEqualsInValue(t *testing.T) {
127+
var config = map[string]interface{}{
128+
"connection_string": "redis://localhost:6379,username=feast,password=a=b", // pragma: allowlist secret
129+
}
130+
rc := &registry.RepoConfig{
131+
OnlineStore: config,
132+
EntityKeySerializationVersion: 3,
133+
}
134+
store, err := NewRedisOnlineStore("test", rc, config)
135+
require.NoError(t, err)
136+
var opts = store.client.Options()
137+
assert.Equal(t, "feast", opts.Username)
138+
assert.Equal(t, "a=b", opts.Password)
139+
}
140+
141+
func TestNewRedisOnlineStoreWithColonInOptionValues(t *testing.T) {
142+
var config = map[string]interface{}{
143+
"connection_string": "localhost:6379,username=team:feast,password=p:w", // pragma: allowlist secret
144+
}
145+
rc := &registry.RepoConfig{
146+
OnlineStore: config,
147+
EntityKeySerializationVersion: 3,
148+
}
149+
store, err := NewRedisOnlineStore("test", rc, config)
150+
require.NoError(t, err)
151+
var opts = store.client.Options()
152+
assert.Equal(t, "localhost:6379", opts.Addr)
153+
assert.Equal(t, "team:feast", opts.Username)
154+
assert.Equal(t, "p:w", opts.Password)
155+
}
156+
157+
func TestNewRedisOnlineStoreClusterWithColonInUsername(t *testing.T) {
158+
var config = map[string]interface{}{
159+
"redis_type": "redis_cluster",
160+
"connection_string": "node1:6379,node2:6379,username=team:feast,password=secret", // pragma: allowlist secret
161+
}
162+
rc := &registry.RepoConfig{
163+
OnlineStore: config,
164+
EntityKeySerializationVersion: 3,
165+
}
166+
store, err := NewRedisOnlineStore("test", rc, config)
167+
require.NoError(t, err)
168+
var opts = store.clusterClient.Options()
169+
assert.Equal(t, []string{"node1:6379", "node2:6379"}, opts.Addrs)
170+
assert.Equal(t, "team:feast", opts.Username)
171+
}
172+
173+
func TestNewRedisOnlineStoreUnrecognizedOption(t *testing.T) {
174+
var config = map[string]interface{}{
175+
"connection_string": "redis://localhost:6379,foo=bar",
176+
}
177+
rc := &registry.RepoConfig{
178+
OnlineStore: config,
179+
EntityKeySerializationVersion: 3,
180+
}
181+
_, err := NewRedisOnlineStore("test", rc, config)
182+
require.Error(t, err)
183+
assert.Contains(t, err.Error(), "foo")
184+
for _, opt := range []string{"'password'", "'username'", "'ssl'", "'db'"} {
185+
assert.Contains(t, err.Error(), opt)
186+
}
187+
}
188+
74189
func TestBuildFeatureViewIndices(t *testing.T) {
75190
r := &RedisOnlineStore{}
76191

0 commit comments

Comments
 (0)