Skip to content
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

feat(stream): add nkey and jwt auth methods for nats connector #12227

Merged
merged 10 commits into from
Sep 19, 2023

Conversation

yufansong
Copy link
Member

@yufansong yufansong commented Sep 12, 2023

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

This PR try to refactor the nats client connection code and add some new methods (credential) to connect. The nats rust package support it here.

  1. The connection with/without passworda and username already test and correct.
  2. Test credential connection methods in sink parts. If you want to test it, firstly you need to make sure you launch the nats server in this way which can enable the credential auth methods. Then you can connect it in this way.

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

Release note

If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.
Add filed: connect_mode, value can be user_and_password, credential or plain.
When use credential, need to fill jwt and nkey
When use user_and_password need to fild username and password
If plain, no extra filed required.

code example:

-- plain
CREATE TABLE test
(
  id integer,
  name varchar,
)
WITH (
  connector='nats',
    server_url='0.0.0.0:4222',
    subject='event1',
    username='a',
    password='b',
    connect_mode='plain'
) FORMAT PLAIN ENCODE JSON;
-- user pass
CREATE TABLE test
(
  id integer,
  name varchar,
)
WITH (
  connector='nats',
    server_url='0.0.0.0:4222',
    subject='event1',
    username='a',
    password='b',
    connect_mode='user_and_password'
) FORMAT PLAIN ENCODE JSON;


-- make sure replace the jwt and nkey as your own value
CREATE SINK s_nats FROM personnel WITH (
    connector='nats',
    server_url='0.0.0.0:4222,0.0.0.0:4221',
    subject='event1',
    type='append-only',
    force_append_only='true',
    connect_mode='credential',
    jwt='xxxx,
    nkey='xxxx',

);

@github-actions github-actions bot requested a review from a team as a code owner September 12, 2023 07:29
@yufansong yufansong marked this pull request as draft September 12, 2023 07:45
@yufansong yufansong marked this pull request as ready for review September 13, 2023 06:41
@neverchanje
Copy link
Contributor

Thanks Yufan! I wonder how did you test this functionality? There is no unit test nor intergation test.

@yufansong
Copy link
Member Author

yufansong commented Sep 13, 2023

Thanks Yufan! I wonder how did you test this functionality? There is no unit test nor intergation test.

Yeah, I have checked other intergration test code, will add it like others. For unit test, currently the nats logic is not complex. I didn't find too much nessesary to add it. What do you think?

I think it may take several days to write the test code. So after finishing this PR and that PR, and no more urgent feature appears, I will work in the test parts.

@tabVersion
Copy link
Contributor

lets do some validation before merging into main

@codecov
Copy link

codecov bot commented Sep 13, 2023

Codecov Report

Merging #12227 (a0b34e8) into main (f304ed2) will decrease coverage by 0.03%.
Report is 15 commits behind head on main.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main   #12227      +/-   ##
==========================================
- Coverage   69.85%   69.83%   -0.03%     
==========================================
  Files        1417     1417              
  Lines      235533   235599      +66     
==========================================
- Hits       164533   164531       -2     
- Misses      71000    71068      +68     
Flag Coverage Δ
rust 69.83% <0.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
src/connector/src/common.rs 2.26% <0.00%> (-0.45%) ⬇️
src/connector/src/source/nats/enumerator/mod.rs 0.00% <0.00%> (ø)
src/connector/src/source/nats/mod.rs 0.00% <ø> (ø)
src/connector/src/source/nats/source/message.rs 0.00% <0.00%> (ø)
src/connector/src/source/nats/source/reader.rs 0.00% <0.00%> (ø)
src/connector/src/source/nats/split.rs 0.00% <0.00%> (ø)

... and 3 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@neverchanje
Copy link
Contributor

I just want to ensure there is manual testing at least. Once developed, we don't expect extra back-and-forth communication with users

Comment on lines 350 to 359
#[serde(rename = "nats.connect_mode")]
pub connect_mode: Option<String>,
#[serde(rename = "username")]
pub user: Option<String>,
#[serde(rename = "nats.password")]
#[serde(rename = "password")]
pub password: Option<String>,
#[serde(rename = "nats.jwt")]
pub jwt: Option<String>,
#[serde(rename = "nats.nkey")]
pub nkey: Option<String>,
Copy link
Contributor

Choose a reason for hiding this comment

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

I wanted to propose stripping off all 'nats.' or 'cassandra.' prefixes given that it has been specified in 'connector'.

Copy link
Member Author

Choose a reason for hiding this comment

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

removed.

Copy link
Contributor

@tabVersion tabVersion left a comment

Choose a reason for hiding this comment

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

rest LGTM, good work!

));
}
}
_ => {}
Copy link
Contributor

Choose a reason for hiding this comment

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

does it mean rw also accepts Nats without auth?
if so, user should connect with 'plain' or sth else, instead of leaving it empty.
also, we need to reject unrecognized string here.

Comment on lines +496 to +501
"-----BEGIN NATS USER JWT-----\n{}\n------END NATS USER JWT------\n\n\
************************* IMPORTANT *************************\n\
NKEY Seed printed below can be used to sign and prove identity.\n\
NKEYs are sensitive and should be treated as secrets.\n\n\
-----BEGIN USER NKEY SEED-----\n{}\n------END USER NKEY SEED------\n\n\
*************************************************************",
Copy link
Contributor

Choose a reason for hiding this comment

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

incredible the func need the format

Copy link
Member Author

@yufansong yufansong Sep 18, 2023

Choose a reason for hiding this comment

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

Yes, this is what the nats documents said, and also what syntropy told me

@yufansong yufansong requested a review from hzxa21 September 18, 2023 22:14
Copy link
Collaborator

@hzxa21 hzxa21 left a comment

Choose a reason for hiding this comment

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

Cargo.lock changes are related to the nats dependency. LGTM!

@yufansong yufansong added this pull request to the merge queue Sep 19, 2023
Merged via the queue into main with commit b17569d Sep 19, 2023
@yufansong yufansong deleted the yufan/nats-connect branch September 19, 2023 03:41
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.

4 participants