Skip to content
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

[BUG] Spring application.properties azure-spring-boot-sample-keyvault-certificates uses camel case. Others use hyphens #17740

Closed
edburns opened this issue Nov 21, 2020 · 9 comments
Assignees
Labels
azure-spring-keyvault Spring keyvault related issues. Client This issue points to a problem in the data-plane of the library.

Comments

@edburns
Copy link
Member

edburns commented Nov 21, 2020

Describe the bug
Consider sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-keyvault-certificates/src/main/resources/application.properties. This file uses camel case for property names, while the other samples use hyphens in the same context.

@ghost ghost added the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Nov 21, 2020
@edburns edburns self-assigned this Nov 21, 2020
@edburns
Copy link
Member Author

edburns commented Nov 22, 2020

Examples

            app.property("azure.activedirectory.client-id", clientId);
./azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/groups/AADGroupsCountIT.java
            app.property("azure.keyvault.client-id", CLIENT_SECRET_ACCESS.clientId());
            app.property("azure.keyvault.client-id", CLIENT_SECRET_ACCESS.clientId());
./azure-spring-boot-test-keyvault/src/test/java/com/azure/test/keyvault/ActuatorIT.java

@edburns
Copy link
Member Author

edburns commented Nov 22, 2020

@edburns
Copy link
Member Author

edburns commented Nov 22, 2020

Hello @mnriem here is another question. Even with adjusting for using the hyphenated instead of camel case, I have a question about this property:

azure.keyvault.client-secret

Other places use client-key to represent this property. For example:

KeyVaultCertificatesEnvironmentPostProcessor.java
azure.keyvault.client-id=<the client ID with access to Azure Key Vault>
azure.keyvault.client-secret=<the client secret associated wit the client ID>
azure.keyvault.client-id=<the client ID with access to Azure Key Vault>
azure.keyvault.client-secret=<the client secret associated wit the client ID>
./azure-spring-boot-starter-keyvault-certificates/README.md
        testProperties.put("azure.keyvault.client-id", "aaaa-bbbb-cccc-dddd");
./azure-spring-boot/src/test/java/com/azure/spring/keyvault/KeyVaultEnvironmentPostProcessorTest.java
#azure.keyvault.client-id=put-your-azure-client-id-here
#azure.keyvault.client-key=put-your-azure-client-key-here
./azure-spring-boot-test-application/src/main/resources/application.properties
azure.keyvault.client-id=put-your-azure-client-id-here
azure.keyvault.client-key=put-your-azure-client-key-here
azure.keyvault.client-id=put-your-azure-client-id-here
./azure-spring-boot-starter-keyvault-secrets/README.md
azure.keyvault.client-id=put-your-azure-client-id-here
azure.keyvault.client-key=put-your-azure-client-key-here
azure.keyvault.client-id=put-your-azure-client-id-here
./azure-spring-boot-starter-keyvault-secrets/javadocTemp/README.md
azure.keyvault.client-id=put-your-azure-client-id-here
azure.keyvault.client-key=put-your-azure-client-key-here
azure.keyvault.client-id=put-your-azure-client-id-here
./azure-spring-boot-starter-keyvault-secrets/sourceTemp/README.md
            app.property("azure.keyvault.client-id", CLIENT_SECRET_ACCESS.clientId());
            app.property("azure.keyvault.client-key", CLIENT_SECRET_ACCESS.clientSecret());         

So might it not be better to do the same for certificates?

@edburns
Copy link
Member Author

edburns commented Nov 25, 2020

@jialindai wrote:

Hi Ed,

To use data binding, one simple approach is to use @ConfigurationProperties annotation, some explains can be found at:

https://www.baeldung.com/configuration-properties-in-spring-boot
https://www.baeldung.com/spring-enable-config-properties

The underlying API is data binder: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/validation/DataBinder.html

It has one bind() API to bind PropertyValues into an object.

In general, the @ConfigurationProperties approach is preferred.

Regards,
Jialin

@edburns
Copy link
Member Author

edburns commented Nov 26, 2020

Hello @jialindai

Thanks for your suggestion about using @ConfigurationProperties. Due to the layered nature of this feature, with the proprietary Spring support on top of the standard JCA KeyStore, using @ConfiurationProperties will only benefit those using the feature from Spring. I think this is acceptable, but I want to explicitly mention it.

I am unsure if the approach you suggest of using @ConfigurationProperties is feasible. I would like @mnriem to offer his opinion. As far as I can tell, we must continue to use system properties directly because the underlying JCA KeyStore does not know anything about Spring, as it is a proprietary non-standard technology.

If this is true, I am happy to do the little bit of coding work.

Rationale

Here is my sketch of the proposed modifications to enable the tolerance
of property names supported by @ConfigurationProperties, as described
in the Baeldung article you cited.
With these modifications, we can support Spring property declarations
that treat the following as identical.

azure.keyvault.client-id
azure.keyvault.client_id
azure.keyvault.CLIENT_ID
azure.keyvault.CLIENT-ID
azure.keyvault.clientId
azure.keyvault.clientid

The JCA entry point will still use the single preferred usage of
azure.keyvault.client-id as a system property. They will not have the
benefit of this tolerance.

Proposed Modifications

Consider this code, in KeyVaultCertificatesEnvironmentPostProcessor.

String aadAuthenticationUrl = environment.getProperty("azure.keyvault.aad-authentication-url");
if (aadAuthenticationUrl != null) {
    systemProperties.put("azure.keyvault.aad-authentication-url", aadAuthenticationUrl);
}

I propose we use the @ConfigurationProperties mechanism to cause a
properties pojo bean, say certProperties to be made available to the
KeyVaultCertificatesEnvironmentPostProcessor and used like so:

if (null != certProperties.getAadAuthenticationUrl()) {
    systemProperties.put("azure.keyvault.aad-authentication-url", aadAuthenticationUrl);
}

with a similar usage for the other properties.

I would like comments from @jialindai and @mnriem on this before I proceed.

@jialindai
Copy link
Contributor

@edburns, I think above is a good idea. It makes Spring config file more flexible in property names.

@mnriem
Copy link
Contributor

mnriem commented Dec 1, 2020

@edburns Go for it. Make sure you test the variations ;)

@joshfree joshfree added azure-spring-keyvault Spring keyvault related issues. Client This issue points to a problem in the data-plane of the library. labels Dec 2, 2020
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Dec 2, 2020
@jialindai
Copy link
Contributor

We may want to keep both camel case and hyphen case in system properties, so that we don't break customers using our beta version.

@jialindai jialindai reopened this Dec 22, 2020
@edburns
Copy link
Member Author

edburns commented Dec 22, 2020

@jialindai We can keep this closed because I am working on it now in #18273 .

@edburns edburns closed this as completed Dec 22, 2020
saragluna pushed a commit that referenced this issue Dec 30, 2020
…18273 property name consistency (#18340)

This commit addresses the damage apparently done by the apparently prematurely merged #17741.  That PR was seeking conceptual review in the associated issue #17740 (see [this comment](#17740 (comment))).  While I received the conceptual review, I had not yet completed the corresponding implementation work.

This commit does not complete that work either.  However, it does make
the system work again, but only with property names that strictly
conform to the "hyphens not camel case" syntax.

Before this commit, the system did not work at all.

After this commit, the system works, but only with the new conforming
properties, which means it will break existing customers.

I am continuing to work on #18273, which will make the system work
without breaking existing customers.

modified:   sdk/keyvault/azure-security-keyvault-jca/README.md
modified:   sdk/keyvault/azure-security-keyvault-jca/pom.xml

- Several tests were using non-conforming test property names, such as:

   -    System.getProperty("azure.tenant.id"),
   -    System.getProperty("azure.client.id"),
   -    System.getProperty("azure.client.secret"));

   I changed these to

   +    System.getProperty("azure.keyvault.tenant-id"),
   +    System.getProperty("azure.keyvault.client-id"),
   +    System.getProperty("azure.keyvault.client-secret"));

modified:   sdk/keyvault/azure-security-keyvault-jca/src/main/java/com/azure/security/keyvault/jca/KeyVaultKeyStore.java

- This is where the damage happened.  When #17741 was merged, those
  changes invalidated the contract with this code.  This change
  modifies this side of the contract to conform with that in the
  existing #17741 change.

modified:   sdk/keyvault/azure-security-keyvault-jca/src/samples/java/sample/com/azure/security/keyvault/jca/ClientSSLSample.java
modified:   sdk/keyvault/azure-security-keyvault-jca/src/samples/java/sample/com/azure/security/keyvault/jca/ServerSSLSample.java
modified:   sdk/keyvault/azure-security-keyvault-jca/src/test/java/com/azure/security/keyvault/jca/AuthClientTest.java
modified:   sdk/keyvault/azure-security-keyvault-jca/src/test/java/com/azure/security/keyvault/jca/KeyVaultJcaProviderTest.java
modified:   sdk/keyvault/azure-security-keyvault-jca/src/test/java/com/azure/security/keyvault/jca/KeyVaultKeyStoreTest.java
modified:   sdk/keyvault/azure-security-keyvault-jca/src/test/java/com/azure/security/keyvault/jca/KeyVaultLoadStoreParameterTest.java
modified:   sdk/keyvault/azure-security-keyvault-jca/src/test/java/com/azure/security/keyvault/jca/ServerSocketTest.java
modified:   sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-keyvault-certificates/pom.xml
modified:   sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-keyvault-certificates/src/main/resources/application.properties

- These changes all bring the samples and tests into sync with the new contract.
openapi-sdkautomation bot pushed a commit to AzureSDKAutomation/azure-sdk-for-java that referenced this issue Feb 15, 2022
openapi-sdkautomation bot pushed a commit to AzureSDKAutomation/azure-sdk-for-java that referenced this issue Feb 15, 2022
openapi-sdkautomation bot pushed a commit to AzureSDKAutomation/azure-sdk-for-java that referenced this issue Feb 15, 2022
openapi-sdkautomation bot pushed a commit to AzureSDKAutomation/azure-sdk-for-java that referenced this issue Feb 15, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
azure-spring-keyvault Spring keyvault related issues. Client This issue points to a problem in the data-plane of the library.
Projects
None yet
Development

No branches or pull requests

4 participants