com.github.chrisgleissner.config:microprofile-config-jasypt-quarkus-example

Java configuration utilities

License

License

Categories

Categories

Quarkus Container Microservices config Application Layer Libs Configuration
GroupId

GroupId

com.github.chrisgleissner.config
ArtifactId

ArtifactId

microprofile-config-jasypt-quarkus-example
Last Version

Last Version

1.0.5
Release Date

Release Date

Type

Type

jar
Description

Description

Java configuration utilities

Download microprofile-config-jasypt-quarkus-example

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.chrisgleissner.config/microprofile-config-jasypt-quarkus-example/ -->
<dependency>
    <groupId>com.github.chrisgleissner.config</groupId>
    <artifactId>microprofile-config-jasypt-quarkus-example</artifactId>
    <version>1.0.5</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.chrisgleissner.config/microprofile-config-jasypt-quarkus-example/
implementation 'com.github.chrisgleissner.config:microprofile-config-jasypt-quarkus-example:1.0.5'
// https://jarcasting.com/artifacts/com.github.chrisgleissner.config/microprofile-config-jasypt-quarkus-example/
implementation ("com.github.chrisgleissner.config:microprofile-config-jasypt-quarkus-example:1.0.5")
'com.github.chrisgleissner.config:microprofile-config-jasypt-quarkus-example:jar:1.0.5'
<dependency org="com.github.chrisgleissner.config" name="microprofile-config-jasypt-quarkus-example" rev="1.0.5">
  <artifact name="microprofile-config-jasypt-quarkus-example" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.chrisgleissner.config', module='microprofile-config-jasypt-quarkus-example', version='1.0.5')
)
libraryDependencies += "com.github.chrisgleissner.config" % "microprofile-config-jasypt-quarkus-example" % "1.0.5"
[com.github.chrisgleissner.config/microprofile-config-jasypt-quarkus-example "1.0.5"]

Dependencies

compile (7)

Group / Artifact Type Version
com.github.chrisgleissner.config : microprofile-config-jasypt jar 1.0.5
io.quarkus : quarkus-resteasy jar
io.quarkus : quarkus-hibernate-orm jar
io.quarkus : quarkus-resteasy-jackson jar
io.quarkus : quarkus-flyway jar
io.quarkus : quarkus-jdbc-h2 jar
io.quarkus : quarkus-jackson jar

provided (1)

Group / Artifact Type Version
org.projectlombok : lombok jar 1.18.10

test (3)

Group / Artifact Type Version
io.quarkus : quarkus-junit5 jar
io.rest-assured : rest-assured jar 4.2.0
org.assertj : assertj-core jar 3.15.0

Project Modules

There are no modules declared in this project.

microprofile-config-jasypt

Maven Central Build Status Coverage Status Maintainability

Encrypted properties for Quarkus and Eclipse Microprofile Config.

Eclipse MicroProfile Config with Jasypt Encryption

An Eclipse Microprofile Config library for Jasypt-encrypted properties. This means you can use secrets in publicly accessible property files and decrypt them transparently at runtime.

  • For an example on how to use this library with Quarkus see below.
  • This repo requires at least Java 8 and is automatically tested on OpenJDK 11.

Encryption

First, encrypt a property. For example, either of the following two commands encrypts a property foo using a password pwd:

./microprofile-config-jasypt/encrypt.sh pwd foo
mvn -f microprofile-config-jasypt/pom.xml validate -Pencrypt -Djasypt.password=pwd -Dproperty=foo

This will print the encrypted property:

foo -> ENC(eu82k78q/boBye5P574UwNdafDuy9VRy19tdlmM9IeYXWkVIdChdZybEx41rRbdv)

Then use the entire ENC(...)-delimited string as your property value, e.g. in a src/main/resources/application.properties file.

The name of the property file is configurable, and it may be on the classpath or the filesystem. See the configuration section below for details.

Decryption

Add this to your pom.xml:

<dependency>
    <groupId>com.github.chrisgleissner.config</groupId>
    <artifactId>microprofile-config-jasypt</artifactId>
    <version>1.0.5</version>
</dependency>

Then add a file at src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource with the content

com.github.chrisgleissner.config.microprofile.jasypt.JasyptConfigSource

Finally set the JASYPT_PASSWORD environment variable when starting your application. As per the previous example, set JASYPT_PASSWORD=pwd.

Any ENC(...)-delimited property in a classpath:application.properties file (configurable) gets decoded at run-time.

Configuration

You can customize microprofile-config-jasypt via environment variables or system properties as per the following table.

Alternatively, you can subclass com.github.chrisgleissner.config.microprofile.jasypt.JasyptConfigSource, override its methods, and specify the fully qualified name of your subclass in a META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource file on the classpath.

Environment variable System property name Default value Description
JASYPT_PASSWORD jasypt.password none Password used for encrypting property values
JASYPT_KEY jasypt.key none Synonym for JASYPT_PASSWORD
JASYPT_ALGORITHM jasypt.algorithm PBEWithHMACSHA512AndAES_256 Encryption algorithm
JASYPT_ITERATIONS jasypt.iterations 1000 Jasypt key obtention iterations
JASYPT_PROPERTIES jasypt.properties classpath:application.properties,config/application.properties Comma-separated property filenames, see below.

Property filenames specified via JASYPT_PROPERTIES are resolved against the classpath if using the classpath: prefix, otherwise against the filesystem relative to the current working directory.

Encrypted Properties in Quarkus

Two Quarkus-based examples are included.

The microprofile-config-jasypt-quarkus-example module shows how to configure the default JasyptConfigSource as per the instructions above:

  • Encrypted properties can be used both for normal and for profile-specific properties, eg. properties with the %prod. prefix.
  • For demonstration purposes only, the LogPropertiesBean in this module logs all properties on startup.

The microprofile-config-jasypt-quarkus-override-example module expands on this and shows how to override the default JasyptConfigSource with a CustomJasyptConfigSource.

Decryption Example

To verify successful decryption, run the following from the repository root:

mvn clean install
(cd microprofile-config-jasypt-quarkus-example && JASYPT_PASSWORD=pwd java -jar target/*-runner.jar)

...and observe the log contains decrypted passwords:

2020-05-24 11:52:53,598 INFO  [com.git.chr.con.mic.jas.qua.LogPropertiesBean] (main) ConfigSource(name=jasypt-config, ordinal=275):
{quarkus.datasource.password=sa, quarkus.log.console.color=true, quarkus.datasource.username=sa, quarkus.log.console.level=TRACE, quarkus.flyway.migrate-at-start=true, quarkus.hibernate-orm.database.generation=validate, config.password=sa, quarkus.datasource.db-kind=h2, quarkus.hibernate-orm.log.sql=false, quarkus.datasource.jdbc.url=jdbc:h2:mem:test, quarkus.log.console.enable=true, quarkus.http.port=8080}

Failed Decryption Example

To verify a failed decryption, run the following from repository root whilst intentionally specifying a wrong JASYPT_PASSWORD:

mvn clean install
(cd microprofile-config-jasypt-quarkus-example && JASYPT_PASSWORD=wrong-pwd java -jar target/*-runner.jar)

...and observe the log contains encrypted passwords:

2020-05-24 11:53:19,318 INFO  [com.git.chr.con.mic.jas.qua.LogPropertiesBean] (main) ConfigSource(name=jasypt-config, ordinal=275):
{quarkus.datasource.password=ENC(MCK/0Y9BnM7WVAyNq4gxjcPpGkDvu379ymjnsN2GCtowKxiPJXFHiSK7jI4rYfop), quarkus.log.console.color=true, quarkus.datasource.username=sa, quarkus.log.console.level=TRACE, quarkus.flyway.migrate-at-start=true, quarkus.hibernate-orm.database.generation=validate, config.password=ENC(MCK/0Y9BnM7WVAyNq4gxjcPpGkDvu379ymjnsN2GCtowKxiPJXFHiSK7jI4rYfop), quarkus.datasource.db-kind=h2, quarkus.hibernate-orm.log.sql=false, quarkus.datasource.jdbc.url=jdbc:h2:mem:test, quarkus.log.console.enable=true, quarkus.http.port=8080}

Versions

Version
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1