Skip to content

Commit

Permalink
remove RSAHandler from the module
Browse files Browse the repository at this point in the history
It was a nice exercise to build it out, but ultimately I'm realizing
that it's a bit premature and presumptuous to be adding in a very
specific secret handler. I'm not even using it yet in my own projects!
I'm also finding that the way a project or organization chooses to
handle it's secrets is typically pretty bespoke, from determining how
secrets are loaded, where/how encryption/decryption is handled, their
encryption scheme, how they're stored and even rotated. There's a lot
to consider.

Either way, I think it's best to remove this footgun from the module
altogether and rethink how, or even if, a secret handler should be
implemented in a way that is considered a "sensible default".
  • Loading branch information
kevinfalting committed Dec 14, 2023
1 parent dd4dccb commit 99950de
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 324 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ The precedence of the default configuration is applied in the following order:
1. Environment Variable
1. Command Line Flag

### Secrets

The builtin secret handler expects base64 encoded RSA strings, prefixed with `secret://`, to look like `secret://<some_base64_encoded_rsa_encrypted_ciphertext>`.

The advantage of this is that handlers can read in encrypted or decrypted values, and once they get to the secret handler, it will either skip it or decrypt a value prefixed with `secret://`, since you may want to provide a decrypted value as an environment variable or flag. You can also provide an encrypted value with that prefix as an environment variable or flag, and it will be decrypted using the provided key.

## Supporting Unsupported Types

The parser will prioritize value fields that satisfy the `encoding.TextUnmarshaler` or `encoding.BinaryUnmarshaler`, in that order. If you need to support an unsupported type like a map or slice, then create a user defined type that satisfies either interface.
Expand Down
7 changes: 0 additions & 7 deletions conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ func New[T any](opts ...confOptionFunc) (*Conf[T], error) {
},
}

if confOpt.rsaPrivateKey != nil {
conf.Handlers = append(conf.Handlers, &confhandler.RSAHandler{
PrivateKey: confOpt.rsaPrivateKey,
Label: confOpt.rsaLabel,
})
}

return &conf, nil
}

Expand Down
173 changes: 0 additions & 173 deletions confhandler/rsa.go

This file was deleted.

119 changes: 0 additions & 119 deletions confhandler/rsa_test.go

This file was deleted.

20 changes: 1 addition & 19 deletions confoption.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package structconf

import (
"crypto/rsa"
"flag"
)

type confOption struct {
flagSet *flag.FlagSet
rsaPrivateKey *rsa.PrivateKey
rsaLabel []byte
flagSet *flag.FlagSet
}

type confOptionFunc func(opt *confOption)
Expand All @@ -20,18 +17,3 @@ func WithFlagSet(fset *flag.FlagSet) confOptionFunc {
opt.flagSet = fset
}
}

// WithRSAPrivateKey is a functional option for passing an [rsa.PrivateKey] to
// the default Conf's RSAHandler.
func WithRSAPrivateKey(priv *rsa.PrivateKey) confOptionFunc {
return func(opt *confOption) {
opt.rsaPrivateKey = priv
}
}

// WithRSALabel sets the label to use with the RSA Private Key.
func WithRSALabel(label []byte) confOptionFunc {
return func(opt *confOption) {
opt.rsaLabel = label
}
}

0 comments on commit 99950de

Please sign in to comment.