-
Notifications
You must be signed in to change notification settings - Fork 305
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
[AMORO-3335] Add interface ConfigShade to support encryption of sensitive configuration items and provide a base64 encoding implementation #3396
base: master
Are you sure you want to change the base?
Conversation
9c8a517
to
141d556
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Jzjsnow thanks for the contribution, I left some comments, please have a look when you're free.
amoro-common/src/main/java/org/apache/amoro/config/shade/utils/ConfigShadeUtils.java
Outdated
Show resolved
Hide resolved
BiFunction<String, Object, String> processFunction = | ||
(key, value) -> configShade.decrypt(value.toString()); | ||
|
||
Preconditions.checkArgument( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need to check this here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we can skip checking for an empty map, as it will be returned ahead of time when the configshade is recognized as the default value.
|
||
@VisibleForTesting | ||
public static String decryptOption(String identifier, String content) { | ||
ConfigShade configShade = CONFIG_SHADES.getOrDefault(identifier, DEFAULT_SHADE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to add some logs here if there is no ConfigShade
with the given identifier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is necessary to print the log. The method decryptConfig
is called for normal use, and if the given identifier cannot be loaded, it will log ERROR and throw an IllegalStateException exception. Here, the method decryptOption
is only used for unit testing.
public void testDecryptOptions() { | ||
String encryptUsername = "YWRtaW4="; | ||
String encryptPassword = "cGFzc3dvcmQ="; | ||
String decryptUsername = ConfigShadeUtils.decryptOption("base64", encryptUsername); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to change the identifier to Base64ConfigShade.getIdentifier()
here,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed the identifier string to a static final string with the value of Base64ConfigShade.getIdentifier()
.
|
||
@Test | ||
public void testDecryptOptions() { | ||
String encryptUsername = "YWRtaW4="; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could add some comments here to show that these are the message have been transformed by base64
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the new commit, TestConfigShade#getBase64EncodedText
is provided to show the base64 encoding process and can be used to encode plaintext for testing.
amoro-common/src/main/java/org/apache/amoro/config/shade/ConfigShade.java
Outdated
Show resolved
Hide resolved
ConfigOptions.key("shade.sensitive-keywords") | ||
.stringType() | ||
.asList() | ||
.defaultValues("admin-password", "database.password") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems the the key here is only located in ams
part in the configuration, not sure if this needs to be apply the whole config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, the sensitive keywords are all in the ams
part, so first I put the shade-related configurations under ams
part and only decrypt the ams
configurations . If in the future the containers also contain sensitive information, I think it may be necessary to put the shade-related configurations in a separate part, alongside the ams
and containers
.
Iterator<ConfigShade> it = serviceLoader.iterator(); | ||
it.forEachRemaining( | ||
configShade -> { | ||
CONFIG_SHADES.put(configShade.getIdentifier(), configShade); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to log the relationship for the identifier and the configShade here? I assume the shade loaded here would not a big number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I add the log to indicate the identifier of the ConfigShade
implementation and the full name of the class.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3396 +/- ##
============================================
- Coverage 21.59% 21.59% -0.01%
- Complexity 2309 2313 +4
============================================
Files 426 429 +3
Lines 39719 39791 +72
Branches 5624 5632 +8
============================================
+ Hits 8577 8591 +14
- Misses 30414 30473 +59
+ Partials 728 727 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution. So, how should we handle this logic in the Helm Chart section
4210df3
to
b6b9437
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@czy006 Thanks for the heads up, I've changed the script in helm charts in the latest commit and verified it locally: |
…tive configuration items and provide a base64 encoding implementation
…f sensitive configuration items and provide a base64 encoding implementation
…f sensitive configuration items and provide a base64 encoding implementation
…f sensitive configuration items and provide a base64 encoding implementation
0947524
to
5b1d475
Compare
Why are the changes needed?
When we start Amoro Management Service , we need to set configuration items in plaintext in the config file, including sensitive configurations such as admin-password and the passwords for connecting to databases (e.g., mysql, pg, etc.), which may be a security risk. To avoid the use of plaintext passwords, we provide an interface (
ConfigShade
) by implementing which developers can customize the decryption method themselves.We also provide an implementation for base64 encoding first, not only as an example implementation of the interface, but also to solve the current problem of plaintext passwords.
Close #3335.
Brief change log
ConfigShade
to theamoro-common
module to provide the ability to customize decryption of sensitive options in the config fileorg.apache.amoro.config.shade.impl.Base64ConfigShade
for base64 encodingHow was this patch tested?
Add some test cases that check the changes thoroughly including negative and positive cases if possible
Add screenshots for manual tests if appropriate
Run test locally before making a pull request
Documentation
How to use
Using the base64 implementation as an example, the following shows how to use a configuration file with sensitive items encrypted:
shade.identifier
andshade.sensitive-keywords
to theams
part inconfig.yaml
to specify the encryption algorithm and the encrypted sensitive keywords.shade.sensitive-keywords
with the encrypted ciphertext.Example config file (partial):
How to customize the encryption algorithm
To use a user-defined encryption algorithm, we expect the developer to provide a dependency package that implements the
ConfigShade
interface.In it, the method
getIdentifier()
can be called to get the unique identifier of the algorithm, which is used to configure theshade.identifier
, and the methoddecrypt(String content)
can be used to decrypt the input cipher text.