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

Assign user a given password and check connection status for a given password #430

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

piif
Copy link

@piif piif commented Aug 19, 2024

Implements APIs entrypoints to set and check a user password :

  • PATCH /api/namespaces/[namespace]/users/[user]/set-password with new password as body ; returns same result than reset-password (open to discussion : it may just return a status ?)
  • POST /api/namespaces/[namespace]/users/[user]/check-password with new password as body ; return 200 is password matches current one, 401 else

Christian Lefebvre added 4 commits August 16, 2024 17:19
TODO : why PUT or PATCH are refused at runtime but POST works ??
TODO : need more tests
Copy link
Collaborator

@loicgreffier loicgreffier left a comment

Choose a reason for hiding this comment

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

@piif Here is my review. Overall:

  • resetPassword and setPassword could be a single endpoint
  • checkPassword could rely on AdminClient

* @return void
*/
@Patch("/{user}/set-password")
public HttpResponse<KafkaUserResetPassword> setPassword(String namespace, String user, @Body String password) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

As suggested in michelin/kafkactl#91, I think we can use a single endpoint for that, following this logic:

  • if @Body is not empty, calling userAsyncExecutor#resetPassword with the given username/password
  • if @Body is empty, generate a random password, then calling userAsyncExecutor#resetPassword with the given username/random password.

➡️ I think userAsyncExecutor#resetPassword and userAsyncExecutor#setPassword can be a single method as well:

  • Add a password parameter to userAsyncExecutor#resetPassword
  • Extract the generation of the random password outside of userAsyncExecutor#resetPassword in order to generate it if the @Body is empty

UserAsyncExecutor userAsyncExecutor =
applicationContext.getBean(UserAsyncExecutor.class, Qualifiers.byName(ns.getMetadata().getCluster()));

if (userAsyncExecutor.checkPassword(ns.getSpec().getKafkaUser(), password)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

As suggested in michelin/kafkactl#91, a status that specifies if the connection with the given password ends with SUCCESS or FAIL may be more significant.

@@ -200,6 +233,66 @@ public String resetPassword(String user) {
return password;
}

@Override
public void setPassword(String user, String password) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

See suggestions from above:

➡️ I think userAsyncExecutor#resetPassword and userAsyncExecutor#setPassword can be a single method as well:

  • Add a password parameter to userAsyncExecutor#resetPassword
  • Extract the generation of the random password outside of userAsyncExecutor#resetPassword in order to generate it if the @Body is empty

@Override
public boolean checkPassword(String user, String password, Properties config) {
Properties props = new Properties();
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, config.get("bootstrap.servers"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Using an AdminClient to verify the connexion may be more elegant than instantiating a dedicated producer, let me sleep on that

@loicgreffier loicgreffier added the feature This issue adds a new feature label Sep 19, 2024
@loicgreffier loicgreffier changed the title partially solve kafkactl issue 91 Assign user a given password and check connection status for a given password Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This issue adds a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants