This tour guide uses the istio authentication policy and identity platform to display the end users in the applications published in the cloud run of gke. For authentication, the validation logic does not need to belong to the application if istio is used. In this way, you can be responsible for applying application applications and authentication policies in different groups, and apply them to all of multiple application applications or services.
introduce
Gke's cloud run provides a developer center environment for the applications and functions gke runs. This is to provide the development team with a server RIS environment, automatic expansion of requirements, blue green deployment, and Internet management. Gke's cloud run is based on istio and knight and is connected with Google cloud platform (GCP) products.
The next chart shows the basis of this guide.
This guide uses the identity platform to support end-user login, but supports direct debugging of other openid connect providers (such as Google login, firebase authentication, other services (such as auth 0, gluu, OKTA, Ping identity), and openct connect.
target
- Cloud run add on to create gke claster
- Set up identity platform
- Sample distribution consisting of open front-end and back-end API
- Add back-end API certification policy
- Confirm authentication
cost
At the end of this street, you can delete the created resources so that the fee does not continue to be requested. Please refer to delete for details.
Before we start
- If you don't have a Google account or a Google account, you'll join the new account.
- Move from GCP console to project selector page. Move to project selector page
Move from the GCP console to the project selector page.
Move to project selector page
- Select the GCP project or create it.
Select the GCP project or create it.
- Verify that you have used settlement in your Google cloud platform project. Please query whether to use the settlement method in the project.
Verify that you have used settlement in your Google cloud platform project. Please query whether to use the settlement method in the project.
- Cloud Build,Cloud Run,Container Analysis,Google Kubernetes Engine API,Cloud API
API usage settings
Move from the GCP console to the project selector page.
Move to project selector page
Select the GCP project or create it.
Verify that you have used settlement in your Google cloud platform project. Please query whether to use the settlement method in the project.
API usage settings
Environment initialization
This sector sets the environment variables and gcloud defaults used by the back of the tour guide.
gcloud
gcloud
gcloud
ZONE=us-central1-c
CLUSTER=cloud-run-gke-auth-tutorial
gcloud config set compute/zone $ZONE
gcloud config set run/cluster $CLUSTER
gcloud config set run/cluster_location $ZONE
You can change the zone and client names.
Select the project to be used in the project whereabouts of GCP console.
Open Cloud shell
Move to cloud sell
Use the cloud shell to execute all the instructions of the tour guide.
The environment variable and gcloud default values for the compute engine area and the name gke claster used in this guide.
gcloud
gcloud
ZONE=us-central1-c
CLUSTER=cloud-run-gke-auth-tutorial
gcloud config set compute/zone $ZONE
gcloud config set run/cluster $CLUSTER
gcloud config set run/cluster_location $ZONE
You can change the zone and client names.
Gke claster used to create cloud run
Create the gke closer for cloud run and istio attachments.
Find public IP address
Gke's cloud run exposes external services to istio ingress gaeway's public IP address.
- Istio ingresgateway kubernetes service generates status with an external IP address. Kubectl get services istio ingresgateway-n istem system -- watch external IP value becomes IP address on pending. If a notfound error occurs, the command will be rerun after waiting for 1 minute. If you want to interrupt standby, press control + C.
The istio ingresgateway kubernetes service generates state with an external IP address.
istio-ingressgateway
kubectl get services istio-ingressgateway -n istio-system --watch
The external-ip value is converted from pending to IP address. If a notfound error occurs, the command will be rerun after waiting for 1 minute. If you want to interrupt standby, press control + C.
EXTERNAL-IP
pending
NotFound
- Istio Ingress Gateway의 공개 IP 주소를 저장할 환경 변수를 만듭니다.export EXTERNAL_IP=$(kubectl get services istio-ingressgateway \ --namespace istio-system \ --output jsonpath='{.status.loadBalancer.ingress[0].ip}') Istio Ingress Gateway의 공개 IP 주소를 저장할 환경 변수를 만듭니다.
export EXTERNAL_IP=$(kubectl get services istio-ingressgateway \
--namespace istio-system \
--output jsonpath='{.status.loadBalancer.ingress[0].ip}')
- Displays the public IP address of istio ingress gaeway. I need this address later. Echo $external
Displays the public IP address of istio ingress gaeway. I need this address in the future.
echo $EXTERNAL_IP
The istio ingresgateway kubernetes service generates state with an external IP address.
istio-ingressgateway
istio-ingressgateway
kubectl get services istio-ingressgateway -n istio-system --watch
The external-ip value is converted from pending to IP address. If a notfound error occurs, the command will be rerun after waiting for 1 minute. If you want to interrupt standby, press control + C.
EXTERNAL-IP
pending
NotFound
EXTERNAL-IP
pending
NotFound
An environment variable is created to hold the public IP address of istio ingress gaeway.
export EXTERNAL_IP=$(kubectl get services istio-ingressgateway \
--namespace istio-system \
--output jsonpath='{.status.loadBalancer.ingress[0].ip}')
Displays the public IP address of istio ingress gaeway. I need this address in the future.
echo $EXTERNAL_IP
$EXTERNAL_IP
Set up identity platform
- Cloud shell opens and accesses GCP marketplace to enable identity platform in a new web browser window. GCP marketplace moves identity platform
Open the cloud shell, access the GCP marketplace, and use the identity platform in a new web browser window.
Move from GCP marketplace to identity platform
- Select the GCP project of identity platform in the project location. Gke claster and identity platform can be set in another GCP project. For simplicity, the tour guide uses the same project.
Select the GCP project of identity platform in the project location. Gke claster and identity platform can be set in another GCP project. For simplicity, the tour guide uses the same project.
- Click identity platform to use settings. The current location is the identity platform vendor web page in the GCP console.
Click identity platform to use the settings.
The current location is the GCP console identity platform vendor page.
- Click Add supplier on the supplier page.
Click Add supplier on the supplier page.
- Move down from vendor selection and select email / password. The native application can choose the configured vendor.
Move down from vendor selection and select email / password. The native application can choose the configured vendor.
- Confirm that use is selected.
Confirm that use is selected.
- Allow login without password.
Allow login without password.
- Click save.
Click save.
- Move to the identity platform settings page.
Move to the identity platform settings page.
- Click domain name add. Opening the winning Domain Name dialog.
Click domain name add. Opening the winning Domain Name dialog.
- The public IP address ($external & up IP) of istio ingress gateway searched in the domain name box.
The public IP address ($external & up IP) of istio ingress gateway searched in the domain name box.
$EXTERNAL_IP
- Click mark up. The dialog box closes. The IP address entered is on the winning domain table.
Click mark up. The dialog box closes. The IP address entered is on the winning domain table.
- Click Save identity platform configuration page.
Click Save identity platform configuration page.
Open the cloud shell, access the GCP marketplace, and use the identity platform in a new web browser window.
Move from GCP marketplace to identity platform
Select the GCP project of identity platform in the project location. Gke claster and identity platform can be set in another GCP project. For simplicity, the tour guide uses the same project.
Click identity platform to use the settings.
The current location is the GCP console identity platform vendor page.
Click Add supplier on the supplier page.
Move down from vendor selection and select email / password. The native application can choose the configured vendor.
Confirm that use is selected.
Allow login without password.
Click save.
Move to the identity platform settings page.
Click domain name add. Opening the winning Domain Name dialog.
The public IP address ($external & up IP) of istio ingress gateway searched in the domain name box.
$EXTERNAL_IP
$EXTERNAL_IP
Click mark up. The dialog box closes. The IP address entered is on the winning domain table.
Click Save identity platform configuration page.
Create test user
Create sample application
Sample application for two services issued. One service is to expose the service back-end user interface, and the other service is the back-end API.
Click the application settings details link on the right side of the window. Open the application configuration dialog box.
Display the value of apikey and copy it to the clipboard (Chrome OS / Linux / Windows Control + C, Mac OS CMD + C).
Click close to close the application configuration dialog box.
Cloud shell creates environment variables and saves apikey. Here API key is API key in the application composition dialog box
api-key
api-key
export AUTH_APIKEY=api-key
Create an environment variable for authdomain.
export AUTH_DOMAIN=$GOOGLE_CLOUD_PROJECT.firebaseapp.com
Clone GitHub's cloud run sample repository.
Switch to a directory of tour guide files.
cd cloud-run-samples/identity-platform/gke
Change the identity platform variable in the foreground JavaScript file.
envsubst frontend/index.template.js frontend/index.js
Sample application distribution
Use cloud build to create the container image of the sample application. One is the front end, the other is the back end.
gcloud builds submit -t gcr.io/$GOOGLE_CLOUD_PROJECT/cloud-run-gke-auth-frontend frontend
gcloud builds submit -t gcr.io/$GOOGLE_CLOUD_PROJECT/cloud-run-gke-auth-backend backend
Cloud build saves the image in the container registry.
Create 2 public and API namespaces in gke closer.
public
api
public
api
kubectl create namespace public
kubectl create namespace api
Distribute the image of the front-end container to the public namespace service and send it to the cloud run of gke.
public
public
gcloud beta run deploy frontend \
--namespace public \
--image gcr.io/$GOOGLE_CLOUD_PROJECT/cloud-run-gke-auth-frontend \
--platform gke
Send the back-end container image to the service in the API namespace.
api
api
gcloud beta run deploy backend \
--namespace api \
--image gcr.io/$GOOGLE_CLOUD_PROJECT/cloud-run-gke-auth-backend \
--platform gke
Create a requested istio virtual service with a URI path.
kubectl apply -f istio/virtualservice.yaml
This virtual service will take the request initiated by URI path / API / as the back-end API browsing, and other requests are front-end user interfaces.
/api/
/api/
Verify that the non authentication request for the backend API is successful.
curl -si $EXTERNAL_IP/api/secure.json | head -n1
Add istio certification policy
Create istio certification policy.
envsubst istio/authenticationpolicy.template.yaml | kubectl apply -f -
This policy authenticates URI paths with the exception of / API / API / healtz paths. Istio virtual services rule published in the previous section, which certifies requests from back-end APIs.
/api/
/api/healthz
/api/
/api/healthz
while sleep 2; do
curl -si $EXTERNAL_IP/api/secure.json | head -n1
done
Solution test
$EXTERNAL_IP
This is a direct requirement for back-end APIs The request does not contain enough user authentication information, so origin authentication failed is displayed in the browser window.
Use the external IP address to open the browser window. To display the login form.
$EXTERNAL_IP
$EXTERNAL_IP
The test user login used to create the test user.
The test user email address and the secret message is: Hello world are displayed on the web page. It will take some time to display the information.
/api/secure.json
frontend/index.js
Solve the problem
If there is a problem with this guide, please check the next file.
- Solve the cloud run problem of gke
- Solve the gke problem
- Istio work guide
- Kubernetes solves the problem
delete
The cost of resources used in this tour guide is not applied for as GCP account as follows.
- Move from GCP console to resource management page. Move to material management page
Move to resource management page
- Select the items you want to delete from the list of items and click delete.
- Enter the item ID in the dialog box and click terminal to delete the item.
Move to resource management page
Delete resources
If you want to save the GCP items used in the tour guide, individual resources will be deleted.
Delete gke index
gcloud container clusters delete $CLUSTER --async --quiet
Delete the sample application container image in the container registry.
gcloud container images delete gcr.io/$GOOGLE_CLOUD_PROJECT/cloud-run-gke-auth-frontend \
--force-delete-tags --quiet
gcloud container images delete gcr.io/$GOOGLE_CLOUD_PROJECT/cloud-run-gke-auth-backend \
--force-delete-tags --quiet
Delete the email / password ID vendor in the identity platform.
- Move from GCP console to identity platform vendor page. Move to vendor page
Move from the GCP console to the identity platform vendor page.
Move to vendor page
- Click email / password ID supplier on the supplier table.
Click e-mail / password ID vendor on the vendor desk.
- Click delete in the displayed dialog box.
Click delete in the displayed dialog box.
Move from the GCP console to the identity platform vendor page.
Move to vendor page
Click e-mail / password ID vendor on the vendor desk.
Click delete in the displayed dialog box.
Delete the test user.
Move to the identity platform user page.
Move to user page
Click delete in the displayed dialog box.
Delete the winning domain name.
- Move to identity platform configuration page. Move to configuration page
Move to the identity platform settings page.
Move to configuration page
- Click the IP address ($external & IP) added in the identity platform configuration section.
Click the IP address ($external & IP) added in the identity platform configuration section.
$EXTERNAL_IP
- Click save.
Click save.
Move to the identity platform settings page.
Move to configuration page
Click the IP address ($external & IP) added in the identity platform configuration section.
$EXTERNAL_IP
$EXTERNAL_IP
Click save.