-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add scope when get token * adding scope adding scope * fix code * remove main * Update SECURITY.md * upgrade spring version * Update SECURITY.md * Update SECURITY.md * Update code * update * Update mlc_config.json * Update custom-config-server-client/README.md Co-authored-by: Xiaolu Dai <31124698+saragluna@users.noreply.github.com> * update pom * Update CustomBootstrapRegistryInitializer.java * Update spring.factories * Update setup-env-variables-template.sh --------- Co-authored-by: Xiaoyun Ding <xiading@microsoft.com> Co-authored-by: yorkzhang <yorkzhangsir@gmail.com> Co-authored-by: Dingmeng Xue <dixue@microsoft.com> Co-authored-by: Xiaolu Dai <31124698+saragluna@users.noreply.github.com>
- Loading branch information
1 parent
3d07481
commit 4c61c9f
Showing
13 changed files
with
204 additions
and
648 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,87 @@ | ||
# Access Azure Spring Apps managed Config Server | ||
|
||
This sample shows how to access Azure Spring Apps managed Config Server through Azure RBAC when your applications are running outside Azure Spring Apps. | ||
> [!NOTE] | ||
> This sample project applies to Azure Spring Apps standard pricing plan. | ||
As Config Server is a protected resource in Azure Spring Apps service, the client from outside needs to [customize the request](https://docs.spring.io/spring-cloud-config/docs/current/reference/html/#custom-rest-template) when using Config Data or Bootstrap. Since Spring Boot 2.4, the latter approach has been deprecated. This sample shows how to custom RestTemplate using Config Data and send Bearer token in the `Authorization` header to access Config Server. | ||
|
||
## Prerequisite | ||
|
||
* [JDK 8](https://docs.microsoft.com/azure/java/jdk/java-jdk-install) | ||
* [JDK 17](https://docs.microsoft.com/azure/java/jdk/java-jdk-install) | ||
* [Maven 3.0 and above](http://maven.apache.org/install.html) | ||
* [Azure CLI](https://docs.microsoft.com/cli/azure/install-azure-cli?view=azure-cli-latest) or [Azure Cloud Shell](https://docs.microsoft.com/azure/cloud-shell/overview) | ||
* [Azure CLI](https://docs.microsoft.com/cli/azure/install-azure-cli) or [Azure Cloud Shell](https://docs.microsoft.com/azure/cloud-shell/overview) | ||
|
||
## How to run | ||
## Prepare your sample applications | ||
|
||
1. Clone this repo and go to folder | ||
Clone the sample repository to your develop environment. | ||
```bash | ||
git clone https://github.com/Azure-Samples/Azure-Spring-Cloud-Samples | ||
cd Azure-Spring-Cloud-Samples/custom-config-server-client | ||
``` | ||
|
||
```bash | ||
git clone https://github.com/Azure-Samples/Azure-Spring-Cloud-Samples | ||
cd Azure-Spring-Cloud-Samples/custom-config-server-client | ||
``` | ||
## Provision your Azure Spring Apps instance | ||
Please reference doc to provision Azure Spring Apps instance: https://learn.microsoft.com/azure/spring-apps/quickstart?pivots=sc-standard | ||
|
||
1. Install Azure CLI extension for Azure Spring Apps | ||
Create environment variables file `setup-env-variables.sh` based on template. | ||
```bash | ||
cp setup-env-variables-template.sh setup-env-variables.sh | ||
``` | ||
|
||
```bash | ||
az extension add --name spring-cloud | ||
``` | ||
Update below resource information in `setup-env-variables.sh`. | ||
```bash | ||
export SUBSCRIPTION='subscription-id' # replace it with your subscription-id | ||
export RESOURCE_GROUP='resource-group-name' # existing resource group or one that will be created in next steps | ||
export SPRING_APPS_SERVICE='azure-spring-apps-name' # name of the service that will be created in the next steps | ||
``` | ||
|
||
1. Create an instance of Azure Spring Apps | ||
Source setting. | ||
```bash | ||
source ./setup-env-variables.sh | ||
``` | ||
|
||
```bash | ||
az spring-cloud create -n <service name> -g <resource group name> | ||
``` | ||
Update default subscription. | ||
```bash | ||
az account set --subscription ${SUBSCRIPTION} | ||
``` | ||
|
||
## Create and Configure Azure Spring Service instance in Standard Pricing Plan | ||
```bash | ||
# Install Azure CLI extension for Azure Spring Apps | ||
az extension add --name spring | ||
|
||
# Create an instance of Azure Spring Apps | ||
az spring create -g ${RESOURCE_GROUP} -n ${SPRING_APPS_SERVICE} | ||
|
||
# Using piggymetrics-config as the backend git repo from which Azure Spring Apps to pull config | ||
az spring config-server git set -g ${RESOURCE_GROUP} -n ${SPRING_APPS_SERVICE} --uri "https://github.com/Azure-Samples/piggymetrics-config.git" | ||
``` | ||
|
||
## Create Microsoft Entra Service Principal for Sample App | ||
|
||
1. Using piggymetrics-config as the backend git repo from which Azure Spring Apps to pull config | ||
|
||
```bash | ||
az spring-cloud config-server git set --name <service name> --uri "https://github.com/Azure-Samples/piggymetrics-config.git" | ||
``` | ||
|
||
1. Create a service principal to access the Config Server in your application. Please mark down | ||
```bash | ||
az ad sp create-for-rbac --scopes /subscriptions/<subscription id>/resourceGroups/<resource group name>/providers/Microsoft.AppPlatform/Spring/<service name> --role "Azure Spring Cloud Config Server Reader" | ||
``` | ||
The output includes credentials you will need in the next step. | ||
```bash | ||
# Get resource id of service instance | ||
RESOURCE_ID=$(az spring show -g ${RESOURCE_GROUP} -n ${SPRING_APPS_SERVICE} --query id -o tsv) | ||
|
||
# Create service principal and create role assignment | ||
az ad sp create-for-rbac --scopes ${RESOURCE_ID} --role "Azure Spring Cloud Config Server Reader" | ||
``` | ||
|
||
The output includes credentials you will need in the next step. | ||
|
||
1. Update the `application.properties` under `src/main/resources` with the credentials you get above and your Azure Spring Apps instance. | ||
```properties | ||
spring.cloud.config.uri=https://<service name>.svc.asc-test.net/config | ||
spring.config.import=configserver:https://<service name>.svc.asc-test.net/config | ||
access.token.clientId=<appId> | ||
access.token.secret=<password> | ||
access.token.tenantId=<tenant> | ||
``` | ||
|
||
1. Package the app using maven and run it locally | ||
```bash | ||
mvn clean package -D skipTests | ||
mvn spring-boot:run | ||
``` | ||
|
||
1. The endpoint should be access now with the configuration content | ||
```bash | ||
curl http://127.0.0.1:8080/config | ||
20000% | ||
``` | ||
## Execute Sample App | ||
```bash | ||
mvn clean package -D skipTests | ||
mvn spring-boot:run | ||
# Get output of config and check its value | ||
curl http://127.0.0.1:8080/config | ||
``` |
Oops, something went wrong.