-
Notifications
You must be signed in to change notification settings - Fork 135
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
PMM-9947: Encryption #897
PMM-9947: Encryption #897
Conversation
d949477
to
79ae423
Compare
var privateKey []byte | ||
|
||
//go:embed test.pub | ||
var publicKey []byte |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci-lint] reported by reviewdog 🐶publicKey
is unused (deadcode)
assert.Nil(t, err) | ||
textWithEmbeddedBlock := fmt.Sprintf("--arg=%s", block) | ||
|
||
fmt.Println(textWithEmbeddedBlock) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci-lint] reported by reviewdog 🐶
use of fmt.Println
forbidden by pattern ^(fmt\.Print(|f|ln)|print|println)$
(forbidigo)
var publicKey []byte | ||
|
||
func TestDecryptEmbeddedWithFormat(t *testing.T) { | ||
key := "key1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci-lint] reported by reviewdog 🐶
string key1
has 3 occurrences, make it a constant (goconst)
utils/rsa_encryptor/encryptor.go
Outdated
|
||
// extract key | ||
bodyStart := strings.Index(text, EncryptedTextBlockCipherStart) | ||
key := text[:bodyStart] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci-lint] reported by reviewdog 🐶
offBy1: Index() can return -1; maybe you wanted to do text[:bodyStart+1] (gocritic)
utils/rsa_encryptor/encryptor.go
Outdated
@@ -0,0 +1,293 @@ | |||
package rsa_encryptor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci-lint] reported by reviewdog 🐶
don't use an underscore in package name (golint)
utils/rsa_encryptor/encryptor.go
Outdated
Type: "PUBLIC KEY", | ||
Bytes: publicKeyBytes, | ||
} | ||
publicPem, err := os.Create(publicKeyPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci-lint] reported by reviewdog 🐶
G304: Potential file inclusion via variable (gosec)
utils/rsa_encryptor/encryptor.go
Outdated
}, nil | ||
} | ||
|
||
func (s *Service) DecryptDsn(dsn string) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci-lint] reported by reviewdog 🐶
exported: exported method Service.DecryptDsn should have comment or be unexported (revive)
utils/rsa_encryptor/encryptor.go
Outdated
} | ||
privateKeyPem, err := os.Create(privateKeyPath) | ||
if err != nil { | ||
return errors.Wrapf(err, "Error when create [%s]: %s \n", privateKeyPath, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci-lint] reported by reviewdog 🐶
error-strings: error strings should not be capitalized or end with punctuation or a newline (revive)
utils/rsa_encryptor/encryptor.go
Outdated
} | ||
err = privateKeyPem.Chmod(perm) | ||
if err != nil { | ||
return errors.Wrapf(err, "Error when changing file permissions [%s]: %s \n", privateKeyPath, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci-lint] reported by reviewdog 🐶
error-strings: error strings should not be capitalized or end with punctuation or a newline (revive)
utils/rsa_encryptor/encryptor.go
Outdated
} | ||
err = pem.Encode(privateKeyPem, privateKeyBlock) | ||
if err != nil { | ||
return errors.Wrapf(err, "Error when encode private pem: %s \n", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci-lint] reported by reviewdog 🐶
error-strings: error strings should not be capitalized or end with punctuation or a newline (revive)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, finally I found a time to review this PR. Sorry for that.
How are we going to share public and private keys between pmm-admin and pmm-agent? Are we going to inject them during the build of PMM or just store them in repository or generate them on PMM managed side and share accross clients?
If we will store them in repository than still it's not secure. pmm-admin allows to add agents to another host and if pmm-agent on another host doesn't support ecryption we will have a problem.
If we will inject keys during build we should disable encryption by default for builds made by community to not have problems with compatability.
Tests are failing. Please fix them.
Please fix linters as well.
@@ -150,6 +157,13 @@ func (cmd *addMongoDBCommand) Run() (commands.Result, error) { | |||
} | |||
} | |||
|
|||
encryptor := rsa_encryptor.GetEncryptor(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we pass the encryptor instead of passing context and trying to extract the encryptor from context. As far as I see there is no check for the existence of an encryptor and that's why your tests are failing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll fix the tests
utils/rsa_encryptor/encryptor.go
Outdated
type Formatter func(string) string | ||
|
||
// Service provides RSA encryption interface for sensitive data. | ||
type Service struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we call it Encryptor
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too many public methods, let's make methods private if we don't use them outside of this package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we call it Encryptor?
ok
Too many public methods, let's make methods private if we don't use them outside of this package.
What method/methods you think should be made private?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I was clear here. All methods are not used outside of this package.
utils/rsa_encryptor/encryptor.go
Outdated
} | ||
|
||
// GenerateKeys creates asymmetric keys. | ||
func (s *Service) GenerateKeys(privateKeyPath, publicKeyPath string, bits int, perm fs.FileMode) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any usage of this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it be a method at all? looks like it can be just a function
utils/rsa_encryptor/encryptor.go
Outdated
"github.com/pkg/errors" | ||
) | ||
|
||
const ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need all these constants be public?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Will make them private
We have multiple options: 2: Inject keys in the build time. Someone needs to generate keys and put in secrets in the repo. 3: Inject keys before pmm starts. We can start with any of these, the key can be rotated later. I think any solution would be better if we compare it with the current one.
Actually, it is not needed. It will all work. It is backward compatible. We can start with key being even stored in source code (just because it is easy). Later we can provide better key management solution and create simple rotation job. The key name is embedded into metadata, so that we can have multiple keys. |
|
Admin perform encryption, for that public key is used. It doesn't need to be kept in secret. |
@BupycHuk @ritbl Options 1 and 2 have no sense, it's increasing complexity with almost zero profit. Option 3 may work, but again system administrator should take care for keys management. For now I thinks we can notify user in logs/UI that connection is insecure and ask him to setup TLS. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ritbl Do you mind if I convert it to draft to suppress notifications?
PMM-9947
E2E encryption proposal.
FB: