Skip to content

Commit 225b00a

Browse files
committed
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>
1 parent be0e411 commit 225b00a

2 files changed

Lines changed: 37 additions & 3 deletions

File tree

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ func NewRedisOnlineStore(project string, config *registry.RepoConfig, onlineStor
8181
} else {
8282
parts := strings.Split(redisConnStr, ",")
8383
for _, part := range parts {
84-
if strings.Contains(part, ":") {
85-
address = append(address, part)
86-
} 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, "=") {
8787
kv := strings.SplitN(part, "=", 2)
8888
if kv[0] == "password" {
8989
password = kv[1]
@@ -104,6 +104,8 @@ func NewRedisOnlineStore(project string, config *registry.RepoConfig, onlineStor
104104
} else {
105105
return nil, fmt.Errorf("unrecognized option in connection_string: %s. Must be one of 'password', 'username', 'ssl', 'db'", kv[0])
106106
}
107+
} else if strings.Contains(part, ":") {
108+
address = append(address, part)
107109
} else {
108110
return nil, fmt.Errorf("unable to parse a part of connection_string: %s. Must contain either ':' (addresses) or '=' (options", part)
109111
}

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,38 @@ func TestNewRedisOnlineStoreWithEqualsInValue(t *testing.T) {
138138
assert.Equal(t, "a=b", opts.Password)
139139
}
140140

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+
141173
func TestNewRedisOnlineStoreUnrecognizedOption(t *testing.T) {
142174
var config = map[string]interface{}{
143175
"connection_string": "redis://localhost:6379,foo=bar",

0 commit comments

Comments
 (0)