It is not possible to provide they encryption key properties in later stage of application startup (e.g via EnvironmentPostProcessor).

Aperta
#1,619 6 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
java, spring, spring-boot
Ambito
backend

Direzione di ricerca

Iniziate da spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/TextEncryptorConfigBootstrapper.java, in particolare dalle righe 67-85, e riproducete l’esempio usando spring-cloud-config-server e un EnvironmentPostProcessor. Tracciate come vengono promossi KeyProperties, RsaProperties e TextEncryptor quando le proprietà di bootstrap sono assenti. Il lavoro è completato quando le proprietà fornite successivamente producono un encryptor utilizzabile invece di FailsafeTextEncryptor senza richiedere il legacy bootstrap.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement help wanted

Describe the bug
TextEncryptorConfigBootstrapper.java#L67-L85 promotes KeyProperties, RsaProperties and TextEncryptor beans to ApplicationContext. When key properties are not available during bootstrap, default instances of KeyProperties, RsaProperties, and TextEncryptor (FailsafeTextEncryptor) are promoted.

In later stage of startup, if key properties are supplied (in my case via EnvironmentPostProcessor), they will be ignored by AutoConfiguration classes, because the relevant bean (TextEncryptor) is present in the ApplicationContext.

Sample

A simple spring-boot app like the following, with org.springframework.cloud:spring-cloud-config-server as dependency, shows the issue:

@SpringBootApplication
public class DemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}
}

class Processor implements EnvironmentPostProcessor {
	@Override
	public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
		final MutablePropertySources propertySources = environment.getPropertySources();

		propertySources.addFirst(new MapPropertySource("test", Map.of("encrypt.key", "my-secret-key")));
	}
}


@Component
class Test {

	@Autowired
	private TextEncryptor encryptor;

	@PostConstruct
	void test() {
		System.out.println("### Encryptor:: " + encryptor.getClass().getSimpleName());
	}
}

sample output:

### Encryptor:: FailsafeTextEncryptor

The output shows that FailsafeTextEncryptor is registered which cannot encrypt/decrypt any secret.

Workaround

Currently I workaround the issue by enabling the legacy bootstrap (e.g adding org.springframework.cloud:spring-cloud-starter-bootstrap as dependency). See the if condition in TextEncryptorConfigBootstrapper.java#L69-L71 which cancels the promotion, in case legacy bootstrap is enabled.

Lingua principale
Java
Stelle
751
Fork
771
Merge medio
3g 15h
PR unite (30g)
19

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di spring-cloud/spring-cloud-commons

Tutte le issue di spring-cloud/spring-cloud-commons

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.