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

Fix truststore certificate validation and improve function naming #459

Open
awattez opened this issue Dec 5, 2024 · 1 comment · May be fixed by #460
Open

Fix truststore certificate validation and improve function naming #459

awattez opened this issue Dec 5, 2024 · 1 comment · May be fixed by #460

Comments

@awattez
Copy link

awattez commented Dec 5, 2024

Description
The certificate validation process in the cp-demo script is failing on MacOS due to the wc command behavior which includes leading spaces in its output. Additionally, the current implementation check_num_certs() uses a non-standard return code convention (1 for success, 0 for failure) which can lead to confusion and maintenance issues.

This causes the script to unnecessarily regenerate cryptographic material even when valid certificates exist, significantly impacting the development workflow.

Troubleshooting
I validated that this issue occurs by:

  1. Following the standard setup procedure from the documentation
  2. Observing that even with valid certificates, the script triggers regeneration
  3. Investigating the check_num_certs function output on MacOS:
$ echo "trusted" | wc -l
       1

vs Linux:

$ echo "trusted" | wc -l
1

The leading spaces in the MacOS output cause the numeric comparison to fail, triggering certificate regeneration.

Related issues:

Proposed Solution

  1. Rename the function to better reflect its purpose:
check_truststore_valid() {
  local DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
  NUM_CERTS=$(docker run --rm -v $DIR/../security:/etc/kafka/secrets localbuild/connect:${CONFLUENT_DOCKER_TAG}-${CONNECTOR_VERSION} \
    keytool --list --keystore /etc/kafka/secrets/kafka.connect.truststore.jks --storepass confluent | grep trusted | wc -l | xargs)
  if [[ "$NUM_CERTS" -eq "1" ]]; then
    return 0
  fi
  return 1
}

Key changes:

  1. Added xargs to trim whitespace from wc output
  2. Fixed return code convention (0 for success)
  3. Renamed function for clarity

Environment

  • GitHub branch: 7.7.1-post
  • Operating System: macOS 14.7.1 (23H222)
  • Docker Version: 27.2.0
  • Docker Compose Version: v2.29.2-desktop.2
awattez added a commit to awattez/cp-demo that referenced this issue Dec 5, 2024
@awattez awattez linked a pull request Dec 9, 2024 that will close this issue
5 tasks
@awattez
Copy link
Author

awattez commented Dec 12, 2024

@confluentinc/technical-marketing

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 a pull request may close this issue.

1 participant