You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add another approach - to encrypt property values with Jasypt (#4361)
* Add another approach - to encrypt property values with Jasypt
In spring boot apps, propery values can be encrypted inline with Jasypt. This update demonstrates simple steps to do that.
* implementing language review recommendations
* fix language recommendations
* address review comments
- note about jasypt (what/why)
- explain that @EnableEncryptableProperties can be added in any configuration class
* add guidance on source control management for encrypted files
* address vale comments
* address review comments and add caution note
caution node added to highlight that password used for encryption should not be committed to source control
Copy file name to clipboardExpand all lines: articles/flow/security/advanced-topics/external-configuration.adoc
+93-1Lines changed: 93 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ It's often bad practice to put sensitive information, such as database URI, user
13
13
14
14
To avoid leaking sensitive information, you should consider storing sensitive information outside of your project files. In no case should you ever `git commit` passwords or other secrets into the repository.
15
15
16
-
This guide demonstrates two ways to externalize sensitive data: using system environment variables; and using an external properties file
16
+
This guide demonstrates three ways to externalize sensitive data: using system environment variables; using an external properties file; and using encrypted property values with Jasypt.
Jasypt (Java Simplified Encryption) is a Java library that provides simple and transparent encryption/decryption for application data. It integrates with Spring Boot to encrypt sensitive values (e.g., database passwords) directly in properties files like `application.properties`.
96
+
97
+
This prevents accidental exposure of sensitive values by decrypting values at runtime using a master password.
98
+
99
+
For using this in your project, add the Jasypt Spring Boot starter dependency in the project like this:
Add the Jasypt Maven plugin to the plugins section.
114
+
115
+
.pom.xml
116
+
[source,xml]
117
+
----
118
+
...
119
+
<plugin>
120
+
<groupId>com.github.ulisesbocchio</groupId>
121
+
<artifactId>jasypt-maven-plugin</artifactId>
122
+
<version>3.0.4</version>
123
+
</plugin>
124
+
...
125
+
----
126
+
127
+
128
+
Enable Jasypt for properties decryption by annotating a `@Configuration` class with `@EnableEncryptableProperties`. Only one occurrence of this annotation is needed.
129
+
130
+
For example, add `@EnableEncryptableProperties` annotation to the Spring Boot `Application` class like this:
131
+
132
+
.Application.java
133
+
[source,java]
134
+
----
135
+
...
136
+
@SpringBootApplication
137
+
@EnableEncryptableProperties
138
+
public class Application implements AppShellConfigurator {
139
+
...
140
+
----
141
+
142
+
Now, wrap the values that you want to encrypt with `DEC()`, for example, `DEC(your-secret-value-here)` in any properties file that is used in the Spring Boot application like this:
Run the following command to encrypt the values in place. The `jasypt.plugin.path` should point to the properties file where you have the `DEC()` wrapped value which you want to encrypt.
153
+
154
+
The file path specified is relative to the directory the command is executed in.
Once the above command completes, all `DEC()` wrapped values in the properties file should have been encrypted in place and replaced with `ENC(....)` like this:
The Jasypt encrypted property files can be checked into source control, since the values are now encrypted.
172
+
173
+
.Do not commit the password used for encryption
174
+
[CAUTION]
175
+
If the password is leaked all encrypted values are compromised. Attackers with read access to both the encrypted file and the password can recover the sensitive values.
176
+
177
+
When starting the application, set the system property `jasypt.encryptor.password` to the password that was used for encryption in the step above.
0 commit comments