Skip to content

Conversation

@nlu90
Copy link
Member

@nlu90 nlu90 commented Nov 2, 2020

(If this PR fixes a github issue, please add Fixes #<xyz>.)

Fixes #8382

Motivation

Add the e2e encryption support for Pulsar Functions

Modifications

  • Add CryptoConfig the encapsulate all the crypto related configs set by user
  • Add CryptoSpec to Function protobuf to container crypto information internally
  • Add CryptoUtils to help create instance, convert between CryptoConfig and CryptoSpec
  • Add crypto validation method in ValidatorUtils to ensure the provided CryptoKeyReader Class has a ctor with Map arg
  • Updated the cli to allow user set crypto for consumer/producer when submitting the function
  • Update PulsarSource, PulsarSink to use the crypto config if provided

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

(example:)

  • Added integration tests for end-to-end deployment with large payloads (10MB)
  • Extended integration test for recovery after broker failure

Does this pull request potentially affect one of the following parts:

If yes was chosen, please highlight the changes

  • Dependencies (does it add or upgrade a dependency): Added pulsar-client-messagecrypto-bc into puslar-function instance
  • The admin cli options: Added --producer-config to allow setting crypto related configs.

Documentation

  • Does this pull request introduce a new feature? Yes
  • If yes, how is the feature documented? not documented
  • If a feature is not documented yet in this PR, please create a followup issue for adding the documentation: #8431

Now user can enable e2e encryption as follows:

./bin/pulsar-admin functions create --jar pulsar-functions/java-examples/target/pulsar-functions-api-examples.jar \
--classname org.apache.pulsar.functions.api.examples.ExclamationFunction  \
--inputs "persistent://public/default/input" --output persistent://public/default/output --producer-config '{"cryptoConfig": {"cryptoKeyReaderClassName": "org.apache.pulsar.functions.api.examples.RawFileKeyReader", "cryptoKeyReaderConfig": {"PUBLIC": "/Users/nlu/workspace/stream-native/pulsar/keys/test_ecdsa_pubkey.pem", "PRIVATE":"/Users/nlu/workspace/stream-native/pulsar/keys/test_ecdsa_privkey.pem"}, "producerCryptoFailureAction": "FAIL", "encryptionKeys":["myapp1"]}}'
./bin/pulsar-admin functions create --jar pulsar-functions/java-examples/target/pulsar-functions-api-examples.jar \
--classname org.apache.pulsar.functions.api.examples.ExclamationFunction  \
--input-specs '{"persistent://public/default/output": {"cryptoConfig": {"cryptoKeyReaderClassName": "org.apache.pulsar.functions.api.examples.RawFileKeyReader", "cryptoKeyReaderConfig": {"PUBLIC": "/Users/nlu/workspace/stream-native/pulsar/keys/test_ecdsa_pubkey.pem", "PRIVATE":"/Users/nlu/workspace/stream-native/pulsar/keys/test_ecdsa_privkey_2.pem"}, "consumerCryptoFailureAction": "FAIL"}}}' \
--output persistent://public/default/output-2 

One requirement is the provided cryptoKeyReaderClass must has a constructor with Map<String, Object> parameter for initialization. And the argument is provided via cryptoKeyReaderConfig in the cli

@wolfstudy wolfstudy added area/function doc-required Your PR changes impact docs and you will update later. labels Nov 3, 2020
@wolfstudy wolfstudy added this to the 2.7.0 milestone Nov 3, 2020
DISCARD = 1;
CONSUME = 2;

SEND = 10;
Copy link
Member

Choose a reason for hiding this comment

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

Why the SEND command value is 10, Is there any special meaning here? We still reserve the middle value?

Copy link
Member Author

Choose a reason for hiding this comment

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

Reserve some single digit values just in case there're new actions added for the consumer failure.

Logically it's more clear. FAIL or 0 is the default behavior; 1~9 is for consumer; 10 and above is for producer.

@codelipenghui
Copy link
Contributor

ping @sijie @srkukarni Could you please help review this PR?

@sijie
Copy link
Member

sijie commented Nov 6, 2020

@nlu90 great contribution!

@sijie sijie merged commit 2c9fe27 into apache:master Nov 8, 2020
@sijie sijie deleted the neng/e2e-encryption-function branch November 8, 2020 08:45
flowchartsman pushed a commit to flowchartsman/pulsar that referenced this pull request Nov 17, 2020
…on (apache#8432)

Fixes apache#8382 


### Motivation

Add the e2e encryption support for Pulsar Functions

### Modifications

- Add `CryptoConfig` the encapsulate all the crypto related configs set by user
- Add `CryptoSpec` to `Function` protobuf to container crypto information internally
- Add `CryptoUtils` to help create instance, convert between `CryptoConfig` and `CryptoSpec`
- Add crypto validation method in `ValidatorUtils` to ensure the provided `CryptoKeyReader` Class has a ctor with `Map` arg
- Updated the cli to allow user set crypto for consumer/producer when submitting the function
- Update `PulsarSource`, `PulsarSink` to use the crypto config if provided

### Verifying this change

- [x] Make sure that the change passes the CI checks.
@Anonymitaet Anonymitaet added doc-complete Your PR changes impact docs and the related docs have been already added. and removed doc-required Your PR changes impact docs and you will update later. labels Mar 29, 2022
@Anonymitaet
Copy link
Member

Doc has been added in https://github.com/apache/pulsar/pull/8648/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/function doc-complete Your PR changes impact docs and the related docs have been already added.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

e2e encryption for pulsar functions

5 participants