spring-cloud / spring-cloud/spring-cloud-config

Support plain text decryption for XML file extension

Open
#2,767 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

waiting-for-triage
Dominant language
Java
Stars
2k
Forks
1.3k
Avg merge
2d 59m
Merged PRs (30d)
16

Description

Is your feature request related to a problem? Please describe.
I need to serve decrypted XML files as plain text, but only YAML, JSON, and properties file extensions are currently supported.

Describe the solution you'd like
Implement a ResourceEncryptor for the xml file extension.

https://github.com/FasterXML/jackson-dataformat-xml provides an XML extension of JsonFactory, which fits in nicely with AbstractCipherResourceEncryptor#decryptWithJacksonParser and hence could make this a straightforward implementation.

Describe alternatives you've considered
I implemented such a ResourceEncryptor, albeit not using jackson-dataformat-xml, and plugged it in using the following configuration:

@Configuration
public class ResourceEncryptorConfiguration {

    @Bean
    @Primary
    public Map<String, ResourceEncryptor> augmentedResourceEncryptors(Map<String, ResourceEncryptor> existing,
                                                                      TextEncryptorLocator encryptor) {
        var resourceEncryptorMap = new HashMap<>(existing);
        registerBySupportedExtensions(resourceEncryptorMap, new CipherResourceXmlEncryptor(encryptor));
        return resourceEncryptorMap;
    }

    private void registerBySupportedExtensions(Map<String, ResourceEncryptor> resourceEncryptorMap,
                                               ResourceEncryptor resourceEncryptor) {
        for (String ext : resourceEncryptor.getSupportedExtensions()) {
            resourceEncryptorMap.put(ext, resourceEncryptor);
        }
    }

}

Not only is this a carbon copy of org.springframework.cloud.config.server.config.ResourceEncryptorConfiguration, but AbstractCipherResourceEncryptor is package-private so I can't reuse the CIPHER_MARKER constant or decryptValue method in my implementation; the latter is especially important because EnvironmentPrefixHelper is also package-private.

This would be a more workable solution if:

  1. There were an easier way to plug in custom ResourceEncryptor implementations, e.g. by simply defining ResourceEncryptor beans
  2. AbstractCipherResourceEncryptor were open for extension

Additional context
N/A

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with AbstractCipherResourceEncryptor and ResourceEncryptorConfiguration, then inspect decryptWithJacksonParser and the existing YAML, JSON, and properties encryptors. The work is complete when XML files are registered and can be decrypted and served as plain text using the existing resource-encryption flow.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend, security
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.