Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove obfuscator #3317

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions internal/configuration/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ type Secrets struct{}

func (Secrets) String() string { return "secrets" }

func (Secrets) Obfuscator() Obfuscator {
return NewObfuscator([]byte("obfuscatesecrets")) // 16 characters (AES-128), not meant to provide security
}

type Configuration struct{}

func (Configuration) String() string { return "configuration" }
Expand Down
31 changes: 5 additions & 26 deletions internal/configuration/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ import (
// Manager is a high-level configuration manager that abstracts the details of
// the Router and Provider interfaces.
type Manager[R configuration.Role] struct {
provider configuration.Provider[R]
router configuration.Router[R]
obfuscator optional.Option[configuration.Obfuscator]
cache *cache[R]
provider configuration.Provider[R]
router configuration.Router[R]
cache *cache[R]
}

func ConfigFromEnvironment() []string {
Expand Down Expand Up @@ -59,9 +58,6 @@ func NewDefaultConfigurationManagerFromConfig(ctx context.Context, registry *pro
// New configuration manager.
func New[R configuration.Role](ctx context.Context, router configuration.Router[R], provider configuration.Provider[R]) (*Manager[R], error) {
m := &Manager[R]{provider: provider}
if provider, ok := any(new(R)).(configuration.ObfuscatorProvider); ok {
m.obfuscator = optional.Some(provider.Obfuscator())
}
m.router = router

var asyncProvider optional.Option[configuration.AsynchronousProvider[R]]
Expand Down Expand Up @@ -110,12 +106,6 @@ func (m *Manager[R]) getData(ctx context.Context, ref configuration.Ref) ([]byte
return nil, fmt.Errorf("provider for %s does not support on demand access or syncing", ref)
}
}
if obfuscator, ok := m.obfuscator.Get(); ok {
data, err = obfuscator.Reveal(data)
if err != nil {
return nil, fmt.Errorf("could not reveal obfuscated value: %w", err)
}
}
return data, nil
}

Expand Down Expand Up @@ -153,22 +143,11 @@ func (m *Manager[R]) SetJSON(ctx context.Context, ref configuration.Ref, value j
if err := checkJSON(value); err != nil {
return fmt.Errorf("invalid value for %s, must be JSON: %w", m.router.Role(), err)
}
var bytes []byte
if obfuscator, ok := m.obfuscator.Get(); ok {
var err error
bytes, err = obfuscator.Obfuscate(value)
if err != nil {
return fmt.Errorf("could not obfuscate: %w", err)
}
} else {
bytes = value
}

key, err := m.provider.Store(ctx, ref, bytes)
key, err := m.provider.Store(ctx, ref, value)
if err != nil {
return err
}
m.cache.updatedValue(ref, bytes, key)
m.cache.updatedValue(ref, value, key)
return m.router.Set(ctx, ref, key)
}

Expand Down
80 changes: 0 additions & 80 deletions internal/configuration/obfuscator.go

This file was deleted.

72 changes: 0 additions & 72 deletions internal/configuration/obfuscator_test.go

This file was deleted.

18 changes: 4 additions & 14 deletions internal/configuration/providers/asm_follower.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func (f *asmFollower) syncInterval() time.Duration {
func (f *asmFollower) sync(ctx context.Context, values *xsync.MapOf[configuration.Ref, configuration.SyncedValue]) error {
// values must store obfuscated values, but f.client gives unobfuscated values
logger := log.FromContext(ctx)
obfuscator := configuration.Secrets{}.Obfuscator()
module := ""
includeValues := true
resp, err := f.client.SecretsList(ctx, connect.NewRequest(&ftlv1.ListSecretsRequest{
Expand All @@ -72,13 +71,9 @@ func (f *asmFollower) sync(ctx context.Context, values *xsync.MapOf[configuratio
if err != nil {
return fmt.Errorf("invalid ref %q: %w", s.RefPath, err)
}
obfuscatedValue, err := obfuscator.Obfuscate(s.Value)
if err != nil {
return fmt.Errorf("asm follower could not obfuscate value for ref %q: %w", s.RefPath, err)
}
visited[ref] = true
values.Store(ref, configuration.SyncedValue{
Value: obfuscatedValue,
Value: s.Value,
})
}
// delete old values
Expand All @@ -91,18 +86,13 @@ func (f *asmFollower) sync(ctx context.Context, values *xsync.MapOf[configuratio
return nil
}

func (f *asmFollower) store(ctx context.Context, ref configuration.Ref, obfuscatedValue []byte) (*url.URL, error) {
obfuscator := configuration.Secrets{}.Obfuscator()
unobfuscatedValue, err := obfuscator.Reveal(obfuscatedValue)
if err != nil {
return nil, fmt.Errorf("asm follower could not unobfuscate: %w", err)
}
_, err = f.client.SecretSet(ctx, connect.NewRequest(&ftlv1.SetSecretRequest{
func (f *asmFollower) store(ctx context.Context, ref configuration.Ref, value []byte) (*url.URL, error) {
_, err := f.client.SecretSet(ctx, connect.NewRequest(&ftlv1.SetSecretRequest{
Ref: &ftlv1.ConfigRef{
Module: ref.Module.Ptr(),
Name: ref.Name,
},
Value: unobfuscatedValue,
Value: value,
}))
if err != nil {
return nil, err
Expand Down
Loading