Skip to content

Encryption support in Go client #552

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

Closed
wants to merge 26 commits into from

Conversation

GPrabhudas
Copy link
Contributor

Motivation

Added Go client changes to encrypt messages published to pulsar. Once encrypted, it only allows the consumer with the right set of keys to be able to decrypt the original message published by the producer. Only RSA encryption of data key is supported.

Modifications

Changes are implemented as per PIP-4

Followed Java client Encryption support changes

Addresses issue #333

PGarule added 24 commits June 7, 2021 18:28
- add interface to support encryption
- provide default encryption/decryption support
- add ability to add custom encryption/decryption of data key
- make initial changes in producer for encryption[needs refactoring]
- make changes for decrypting in consumer
- add test case to produce encrypted message and receive decrypted message
- adding encryption & decryption needs to have access to MessageMetadata
- so making the pulsar proto package public from internal
Copy link
Contributor

@cckellogg cckellogg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution. I took a quick look and left a few comments. A few suggestions:

In go file names are generally snake case so please try to follow that to keep things consistent. For example this crypto_key_reader.go instead of CryptoKeyReader.go

Can we break this up into multiple pull requests? Can we start with the crypto package that adds the interfaces and base implementations. Then some followup pull requests can be added for the consumer and producer implementation. This will make it easier on people to review the code.

"github.com/apache/pulsar-client-go/pulsar/log"
pb "github.com/apache/pulsar-client-go/pulsar/pulsar_proto"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to avoid exposing the proto as a public api. We should move this back to internal

Copy link
Contributor Author

@GPrabhudas GPrabhudas Jun 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Client need access to MessagaMetada if they do not want to use default implementation of crypto. And it is not possible unless we make it public or create a wrapper around it.

if c.options.KeyReader != nil && c.options.MessageCrypto == nil {
logCtx := fmt.Sprintf("[%v] [%v]", pt, c.options.SubscriptionName)
messageCrypto, err := crypto.NewDefaultMessageCrypto(logCtx, false, c.log)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is an error ok here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Let me fix it


// use default message crypto if not already created
if c.options.KeyReader != nil && c.options.MessageCrypto == nil {
logCtx := fmt.Sprintf("[%v] [%v]", pt, c.options.SubscriptionName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is log context and why is it needed?

Copy link
Contributor Author

@GPrabhudas GPrabhudas Jun 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is just a log message that default crypto implementation uses while logging.

errMsg := fmt.Errorf(errDecryptingPayload, err.Error())
switch pc.options.consumerCryptoFailureAcrion {
case crypto.FailConsume:
pc.log.Warnf(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This info about the consumer will already be logged

pc.log = client.log.SubLogger(log.Fields{
		"name":         pc.name,
		"topic":        options.topic,
		"subscription": options.subscription,
		"consumerID":   pc.consumerID,
	})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I'll remove the redundant info

import "io/ioutil"

// DefaultKeyReader default implementation of KeyReader
type DefaultKeyReader struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FileKeyReader?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be yeah that looks good. I'll rename it.

@GPrabhudas
Copy link
Contributor Author

GPrabhudas commented Jun 25, 2021

Thanks for your contribution. I took a quick look and left a few comments. A few suggestions:

In go file names are generally snake case so please try to follow that to keep things consistent. For example this crypto_key_reader.go instead of CryptoKeyReader.go

Can we break this up into multiple pull requests? Can we start with the crypto package that adds the interfaces and base implementations. Then some followup pull requests can be added for the consumer and producer implementation. This will make it easier on people to review the code.

Thanks for the suggestions. Actually I've gone too far to put all the functionality in the single PR. If it is absolutely necessary to breakdown into multiple pull requests I'll go ahead to do it.

PGarule added 2 commits June 25, 2021 18:57
@cckellogg
Copy link
Contributor

Yes, please break this down into multiple pull requests. The crypto package would be a good one to start with.

@GPrabhudas
Copy link
Contributor Author

GPrabhudas commented Jun 28, 2021

Motivation

Added Go client changes to encrypt messages published to pulsar. Once encrypted, it only allows the consumer with the right set of keys to be able to decrypt the original message published by the producer. Only RSA encryption of data key is supported.

Modifications

Changes are implemented as per PIP-4

Followed Java client Encryption support changes

Addresses issue #333

As per suggestions breaking down this into multiple pull requests.

  1. #555 base interface and default implementation
  2. Producer side changes
  3. Consumer side changes

@cckellogg

@wolfstudy wolfstudy added this to the 0.6.0 milestone Jun 29, 2021
wolfstudy pushed a commit that referenced this pull request Jul 5, 2021
Breakdown of PR  [#552 ](#552)

This PR includes base interface and default implementation.
@GPrabhudas
Copy link
Contributor Author

Motivation

Added Go client changes to encrypt messages published to pulsar. Once encrypted, it only allows the consumer with the right set of keys to be able to decrypt the original message published by the producer. Only RSA encryption of data key is supported.

Modifications

Changes are implemented as per PIP-4
Followed Java client Encryption support changes
Addresses issue #333

As per suggestions breaking down this into multiple pull requests.

  1. #555 base interface and default implementation
  2. #560 Producer side changes
  3. Consumer side changes

@cckellogg

@wolfstudy
Copy link
Member

@cckellogg @GPrabhudas Any update for this? We are ready to initiate a new version of the release, hoping to include this new change in the new version (because some of the code has been merged in), can we consider advancing the progress here.

@GPrabhudas
Copy link
Contributor Author

@cckellogg @GPrabhudas Any update for this? We are ready to initiate a new version of the release, hoping to include this new change in the new version (because some of the code has been merged in), can we consider advancing the progress here.

I'll work on it and address the review suggestions.

@wolfstudy wolfstudy modified the milestones: 0.6.0, 0.7.0 Jul 21, 2021
@GPrabhudas
Copy link
Contributor Author

GPrabhudas commented Sep 7, 2021

Motivation

Added Go client changes to encrypt messages published to pulsar. Once encrypted, it only allows the consumer with the right set of keys to be able to decrypt the original message published by the producer. Only RSA encryption of data key is supported.

Modifications

Changes are implemented as per PIP-4
Followed Java client Encryption support changes
Addresses issue #333

As per suggestions breaking down this into multiple pull requests.

  1. #555 base interface and default implementation
  2. #560 Producer side changes
  3. #612 Consumer side changes

@cckellogg

@wolfstudy
Copy link
Member

ping @cckellogg @GPrabhudas What is the latest status here?

@GPrabhudas
Copy link
Contributor Author

ping @cckellogg @GPrabhudas What is the latest status here?

@wolfstudy We can close this PR as all of its sub PRs are merged into master.
#555 base interface and default implementation
#560 Producer side changes
#612 Consumer side changes

we can add tag 0.7.0 to above PRs and close this one.

@wolfstudy
Copy link
Member

ping @cckellogg @GPrabhudas What is the latest status here?

@wolfstudy We can close this PR as all of its sub PRs are merged into master. #555 base interface and default implementation #560 Producer side changes #612 Consumer side changes

we can add tag 0.7.0 to above PRs and close this one.

Cool, i will close this pull request.

@wolfstudy wolfstudy closed this Oct 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants