Skip to content

Commit

Permalink
fix: redis return string not byte slices, need to type check
Browse files Browse the repository at this point in the history
  • Loading branch information
lsjostro committed Feb 12, 2024
1 parent dcfb7ce commit 1c07fe1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
1 change: 1 addition & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ tasks:
env:
ENVOY_AUTHZ_SECRET_KEY: "G_TdvPJ9T8C4p&A?Wr3YAUYW$*9vn4?t"
ENVOY_AUTHZ_OPA_URL: http://localhost:9191
ENVOY_AUTHZ_REDIS_ADDRS: localhost:26379
ENVOY_AUTHZ_PROVIDERS_CONFIG: run/config/providers.yaml
ENVOY_AUTHZ_LOG_LEVEL: debug
cmds:
Expand Down
9 changes: 8 additions & 1 deletion authz/authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,14 @@ func (s *Service) getSessionCookieData(ctx context.Context, req *auth.AttributeC
return nil, ""
}

sessionData, err = session.DecryptSession(ctx, [32]byte(s.secretKey), enc)
switch v := enc.(type) {
case []byte:
enc = v
case string:
enc = []byte(v)
}

sessionData, err = session.DecryptSession(ctx, [32]byte(s.secretKey), enc.([]byte))
if err != nil {
slog.Error("error decrypt session data", slog.String("err", err.Error()))
return nil, ""
Expand Down
26 changes: 26 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,32 @@ services:
- "${PORT_OTEL:-4317}:4317"
network_mode: host

redis-master:
image: redis
network_mode: host

redis-slave:
image: redis
command: >
bash -c "echo 'port 6380' > slave.conf &&
echo 'replicaof 127.0.0.1 6379' >> slave.conf &&
cat slave.conf &&
redis-server slave.conf"
network_mode: host

redis-sentinel:
image: redis
command: >
bash -c "echo 'port 26379' > sentinel.conf &&
echo 'dir /tmp' >> sentinel.conf &&
echo 'sentinel monitor mymaster 127.0.0.1 6379 1' >> sentinel.conf &&
echo 'sentinel down-after-milliseconds mymaster 5000' >> sentinel.conf &&
echo 'sentinel parallel-syncs mymaster 1' >> sentinel.conf &&
echo 'sentinel failover-timeout mymaster 5000' >> sentinel.conf &&
cat sentinel.conf &&
redis-server sentinel.conf --sentinel"
network_mode: host

podinfo:
image: ghcr.io/stefanprodan/podinfo
network_mode: host
13 changes: 6 additions & 7 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

type Store struct {
*cache.ChainCache[[]byte]
*cache.ChainCache[any]
}

func NewStore(redisAddrs []string) *Store {
Expand All @@ -22,8 +22,8 @@ func NewStore(redisAddrs []string) *Store {

if redisAddrs == nil {
return &Store{
cache.NewChain[[]byte](
cache.New[[]byte](gocacheStore),
cache.NewChain[any](
cache.New[any](gocacheStore),
),
}
}
Expand All @@ -35,11 +35,10 @@ func NewStore(redisAddrs []string) *Store {
SentinelAddrs: redisAddrs,
})
redisStore := redis_store.NewRedis(redisClient, store.WithExpiration(24*time.Hour))

return &Store{
cache.NewChain[[]byte](
cache.New[[]byte](gocacheStore),
cache.New[[]byte](redisStore),
cache.NewChain[any](
cache.New[any](gocacheStore),
cache.New[any](redisStore),
),
}
}

0 comments on commit 1c07fe1

Please sign in to comment.