rajesh
rajesh

Reputation: 179

is it possible to refer environmental variable as values for properties in the kafkaProducer.properties and KafkaConsumer.properties files of Kafka

Im have a producer and consumer java code and Im trying to upgrade it to connect with the Kafka which is secured with SSL. I'm in a situation that the ssl related passwords should be given only via environmental variables. So is it possible to directly refer to the values refered by Environmental variables in the KafkaProducer.properties and KafkaConsumer.properties files

For Example: I declare an environmental variable in linux system SSL_KEY_PASSWORD=password

And inside the KafkaProducer/Consumer properties, I declare as, ''' ssl.key.password=${SSL_KEY_PASSWORD} '''

Sample KAFKA Consumer/Producer property file config may look like,

# For SSL
security.protocol=SSL
ssl.truststore.location=/var/private/ssl/client.truststore.jks
ssl.truststore.password=${TRUSTSTORE_PASS_ENV_VARIABLE}
# For SSL auth
ssl.keystore.location=/var/private/ssl/client.keystore.jks
ssl.keystore.password=${KEYSTORE_PASS_ENV_VARIABLE}
ssl.key.password=${KEY_PASS_ENV_VARIABLE}

Upvotes: 1

Views: 1687

Answers (2)

OneCricketeer
OneCricketeer

Reputation: 191743

No, they cannot.

Unclear how you are using the files or Kafka clients. If from the shell commands, you should create a bash wrapper around the command you're running that uses sed or other templating scripts that generates the files before running the final command.

If you are actually writing Java code, then build the Properties from the environment there, and not using files.

Upvotes: 1

Pravin
Pravin

Reputation: 14

Don't think properties file values are interpolated but probably you can test it once. Alternatively you can also remove these lines from property file and do it from code something like below...

   final Properties properties = new Properties();
   final FileInputStream input = new FileInputStream(yourExistingFile);
   
   properties.load(input); 
   properties.put("ssl.key.password",System.getenv("SSL_KEY_PASSWORD"));//this is additional property

Upvotes: 0

Related Questions