Encryption: Stop decrypting EE encrypted secrets with legacy encryption (#50090) (#50176)

(cherry picked from commit 7a614fd8a1)
This commit is contained in:
Tania
2022-06-03 17:35:53 +02:00
committed by GitHub
parent f037b23f9f
commit 711ea1c2cb
+8 -6
View File
@@ -180,8 +180,15 @@ func (s *SecretsService) keyName(scope string) string {
}
func (s *SecretsService) Decrypt(ctx context.Context, payload []byte) ([]byte, error) {
// Use legacy encryption service if featuremgmt.FlagEnvelopeEncryption toggle is off
if len(payload) == 0 {
return nil, fmt.Errorf("unable to decrypt empty payload")
}
// Use legacy encryption service if featuremgmt.FlagDisableEnvelopeEncryption toggle is on
if !s.features.IsEnabled(featuremgmt.FlagEnvelopeEncryption) {
if len(payload) > 0 && payload[0] == '#' {
return nil, fmt.Errorf("failed to decrypt a secret encrypted with envelope encryption: envelope encryption is disabled")
}
return s.enc.Decrypt(ctx, payload, setting.SecretKey)
}
@@ -194,11 +201,6 @@ func (s *SecretsService) Decrypt(ctx context.Context, payload []byte) ([]byte, e
}).Inc()
}()
if len(payload) == 0 {
err = fmt.Errorf("unable to decrypt empty payload")
return nil, err
}
var dataKey []byte
if payload[0] != '#' {