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

Change how KeyNotInstalledException check works

Open
#551 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

closable
Dominant language
Java
Stars
2k
Forks
1.3k
Avg merge
2d 59m
Merged PRs (30d)
16

Description

I am implementing my own TextEncryptor and in order for it to work I must verify that the caller passed in a key. What I noticed was that in the EncryptionController there is a method checkEncryptorInstalled(...) which tries to locate a TextEncryptor and then does a dummy encryption to make sure that the NoOpTextEncryptor is not being used. This breaks me because the checkEncryptorInstalled(...) method does not pass in the parsed "encryptorKeys". Also, the dummy encryption call concerns me because I am using AWS Key Management Service so I would not want to do a dummy encryption every time the encrypt endpoint is called.

Would it make more sense to instead check to see if a TextEncryptorLocator bean exists, and if not, then throw the KeyNotInstalledException such as below? This would mean removing the NoOpTextEncryptor, and SingleTextEncryptorLocator from being autoconfigured unless if the "encrypt.key" system property was set.

OLD:

private void checkEncryptorInstalled(String name, String profiles) {
    if (this.encryptor == null || this.encryptor.locate(this.helper.getEncryptorKeys(name, profiles, ""))
        .encrypt("FOO").equals("FOO")) {
            throw new KeyNotInstalledException();
    }
}

NEW:

private void checkEncryptorInstalled(String name, String profiles) {
    if (this.encryptor == null) {
            throw new KeyNotInstalledException();
    }
}

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 at EncryptionController.checkEncryptorInstalled(...) and trace how NoOpTextEncryptor and SingleTextEncryptorLocator are autoconfigured. Determine how the parsed "encryptorKeys" reach the custom TextEncryptor, then verify that missing-key handling avoids dummy encryption and still raises KeyNotInstalledException when appropriate.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.