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

Adds support for the Confluent CLI against Confluent Cloud #184

Merged
merged 3 commits into from
May 31, 2023

Conversation

nerdynick
Copy link
Contributor

This adds support for Confluent's Official CLI. However due to current limits of the Plugin framework, only support for Confluent Cloud has been enabled. However the code is made ready for the eventual support for Confluent Platform installations.

Copy link
Member

@hculea hculea left a comment

Choose a reason for hiding this comment

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

Thank you for this contribution! It's awesome that you thought about adding all the credential types from the get-go. We hope to support multiple credential types in the future, you've really made it easy to ensure that having support for both Confluent Cloud and Platform will be a breeze, at that point 😄

Only a few comments and good to go!

plugins/confluent/credentials.go Outdated Show resolved Hide resolved
plugins/confluent/credentials.go Outdated Show resolved Hide resolved
plugins/confluent/credentials.go Outdated Show resolved Hide resolved
plugins/confluent/plugin.go Outdated Show resolved Hide resolved
Copy link
Member

@SimonBarendse SimonBarendse left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution! Confluent will make for a great addition to the ecosystem! ❤️

Runs: []string{"confluent"},
DocsURL: sdk.URL("https://docs.confluent.io/confluent-cli/current/overview.html"),
NeedsAuth: needsauth.IfAll(
needsauth.ForCommand("login"),
Copy link
Member

Choose a reason for hiding this comment

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

Does the login command write credentials to disk to pass them to the other commands? One of the goals of Shell Plugins is to avoid credentials ever having to touch the disk in plaintext. Instead they're stored encrypted in 1Password and are only passed to the tools that need the credential in memory and only to authorized terminal sessions.

In case Confluent uses a file to pass the credentials between the login and other commands, we can use the file-provisioner to pass the crednetials directly to the commands that require them (without needing to run login beforehand). It uses a temporary in-memory file to pass the credentials to the CLI. As a reference example, a.o. the MySQL plugin use a temporary file to pass the credential.

Let us know if we can help out. In addition to here on GitHub we're also on Slack for quick back-and-forth and you can book a pairing session with us.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The login command performs the exchange of credentials for a JWT Token that has a TTL (Default 1hr if I recall). So without implementing the login API calls within the OP Plugin itself and writing out the token to a temp file. This was the only way I could see fit to connect the 2. As credentials aren't able to be provide in any other way at this time.

It also worth adding that the APIs themselves are rate limited. So even attempting to login, get the token, write it to disk, then performance the user intended action. Would be problematic for the end power user.

Copy link
Member

Choose a reason for hiding this comment

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

It also worth adding that the APIs themselves are rate limited. So even attempting to login, get the token, write it to disk, then performance the user intended action. Would be problematic for the end power user.

For this the plugin ecosystem offers an encrypted cache to persist the token between command executions. An example of this in use are temporary AWS credentials.

So without implementing the login API calls within the OP Plugin itself and writing out the token to a temp file.

Is there a Confluent SDK we could use? Or could we possibly capture the output of the login command before it hits the disk?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As it stands, there currently is no way to provide the token to the CLI. So while there is a GoLang SDK, there wouldn't be a way at this time to then translate that token to the CLI. I will open a separate ticket/issue with the Confluent CLI team and see about addressing this at a later date. But for now this seems to be the only route forward.

Copy link
Contributor

Choose a reason for hiding this comment

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

@nerdynick Is there a reason we cannot use this exact logic that Confluent CLI is using? The project is open source so we could even re-use those exact functions.

Copy link
Member

Choose a reason for hiding this comment

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

A possible reason would be that this code currently lives in the internal dir (see https://github.com/golang-standards/project-layout#internal). 🤔

@nerdynick what would be the way to go about asking for some changes in the Confluent CLI's codebase, if we were to go down this route?

Copy link
Contributor Author

@nerdynick nerdynick Apr 5, 2023

Choose a reason for hiding this comment

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

I'd be slightly hesitant about attempting to manipulate the internal state cache that the CLI manages. It's constantly changing without backward compatibility, since it's deemed ephemeral and internal to the CLI itself and would require keeping up with new releases, which happen regularly.

Outside of going the route that I did with this PR so far. Our next option would be to file an issue against the project or do the work ourselves and get a PR accepted to extend support for a Token to be provided via ENV Vars like the User/Pass can be. For which I started exploring down that route when this thread was brought up. It'd take a bit of time to complete and then go through that PR process.

The follow on question would then be, if we go down the route of asking the Confluent CLI team to make the needed change, would this project, 1Pass CLI Plugins, be OK with importing an external project (SDK) to acquire that token or would we need to duplicate that logic in a minimal fashion within this plugin to achieve that?

Copy link
Contributor

Choose a reason for hiding this comment

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

The follow on question would then be, if we go down the route of asking the Confluent CLI team to make the needed change, would this project, 1Pass CLI Plugins, be OK with importing an external project (SDK) to acquire that token or would we need to duplicate that logic in a minimal fashion within this plugin to achieve that?

The best way forward here seems to start work on the Confluent CLI to be able to take in the token via the env var, as you said. After this is done, we are more than open to import any external SDK that would retrieve that token.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, I was able to modify the plugin and make use of what is essentially an undocumented feature. In that the Confluent CLI is able to take the credentials on every command. So the plugin now provides credentials on all calls but the Help and Version ones. This should mitigate the security concern that have been brought up I believe. This should also be a future proof route as the API documents the use of Credentials on all calls rather then the use of a Token.

Copy link
Contributor

@accraw accraw Jun 5, 2023

Choose a reason for hiding this comment

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

Hi @nerdynick !
I was just trying to use this shell plugin but can't get the username + password to work with commands without first running confluent login and writing an auth_token to disk. Is there a trick to get this to work without that step?

~ confluent kafka topic list --url https://<my-domain>.us-east-2.aws.confluent.cloud:443
No session token found, please enter user credentials. To avoid being prompted, run `confluent login`.
Username:

@AndyTitu AndyTitu added in-progress this PR is being worked on/comments are in the process of being addressed by the contributor waiting-on-3rd-party-tool-changes labels Apr 26, 2023
plugins/confluent/credentials.go Outdated Show resolved Hide resolved
plugins/confluent/credentials.go Outdated Show resolved Hide resolved
Copy link
Contributor

@AndyTitu AndyTitu left a comment

Choose a reason for hiding this comment

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

lgtm, excited to get this out! Thank you for the contribution and making it happen with the confluent env vars! @nerdynick

plugins/confluent/credentials.go Show resolved Hide resolved
@AndyTitu AndyTitu added waiting-on-sec-review and removed in-progress this PR is being worked on/comments are in the process of being addressed by the contributor waiting-on-3rd-party-tool-changes labels May 11, 2023
Copy link
Member

@jpcoenen jpcoenen 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! 🙌 This looks good to me.

@accraw
Copy link
Contributor

accraw commented May 30, 2023

Hi @nerdynick !

We're about ready to merge this in, but you have some unsigned commits preventing that from happening. Are you able to take a minute to sign them? git commit -S --amend --no-edit && git push --force-with-lease or something similar should do the trick.

Thank you!
Amanda

@accraw
Copy link
Contributor

accraw commented May 30, 2023

Actually that doesn't look like it did the trick - I think you might need a rebase: https://stackoverflow.com/questions/41882919/is-there-a-way-to-gpg-sign-all-previous-commits

@nerdynick nerdynick force-pushed the Confluent-CLI branch 2 times, most recently from 5a97c5f to 62caf8e Compare May 30, 2023 18:57
Signed-off-by: Nikoleta Verbeck <nerdynick@gmail.com>

Revert to using Username field instead of Email to improve Import from Login Credential Types. Improve outputs for helpfulness

Signed-off-by: Nikoleta Verbeck <nerdynick@gmail.com>

Change MDS URL to URL and update Description.

Remove Custom Names in favor of just Credentials

Comment out all things related to Platform with TODOs

Remove TODO in Plugin
Add aditional CMDs not neeting AuthN details

Changes per latest Review
@nerdynick nerdynick force-pushed the Confluent-CLI branch 2 times, most recently from 8781739 to 2ffbdbf Compare May 30, 2023 19:01
@nerdynick
Copy link
Contributor Author

Alright, it took some creativity but I believe it's all Rebased, squashed, and signed now.

@nerdynick nerdynick requested a review from accraw May 30, 2023 19:04
@accraw accraw merged commit af0b949 into 1Password:main May 31, 2023
4 checks passed
@arunsathiya arunsathiya mentioned this pull request Jun 13, 2023
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants