Skip to content
This repository was archived by the owner on May 7, 2025. It is now read-only.

Commit 22d19bd

Browse files
author
Mathieu Benoit
committed
Add Secure Memorystore access with TLS from cartservice
1 parent e2c0fc3 commit 22d19bd

File tree

3 files changed

+38
-32
lines changed

3 files changed

+38
-32
lines changed

content/onlineboutique/create-memorystore.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ tags: ["kcc", "platform-admin"]
77
![Platform Admin](/images/platform-admin.png)
88
_{{< param description >}}_
99

10-
In this section, you will create a Memorystore (redis) instance for the Online Boutique's `cartservice` app to connect to.
10+
In this section, you will create a Memorystore (redis) instance for the Online Boutique's `cartservice` app to connect to. We will also create a second Memorystore (redis) with TLS enabled.
1111

1212
Initialize variables:
1313
```Bash
1414
WORK_DIR=~/
1515
source ${WORK_DIR}acm-workshop-variables.sh
16-
echo "export REDIS_NAME=cart2" >> ${WORK_DIR}acm-workshop-variables.sh
16+
echo "export REDIS_NAME=cart" >> ${WORK_DIR}acm-workshop-variables.sh
17+
echo "export REDIS_TLS_NAME=cart-tls" >> ${WORK_DIR}acm-workshop-variables.sh
1718
source ${WORK_DIR}acm-workshop-variables.sh
1819
```
1920

@@ -44,6 +45,29 @@ spec:
4445
EOF
4546
```
4647

48+
## Define Memorystore (redis) with TLS enabled
49+
50+
Define the [Memorystore (redis) resource](https://cloud.google.com/config-connector/docs/reference/resource-docs/redis/redisinstance) with TLS enabled:
51+
```Bash
52+
cat <<EOF > ${WORK_DIR}$TENANT_PROJECT_DIR_NAME/$ONLINEBOUTIQUE_NAMESPACE/memorystore-tls.yaml
53+
apiVersion: redis.cnrm.cloud.google.com/v1beta1
54+
kind: RedisInstance
55+
metadata:
56+
name: ${REDIS_TLS_NAME}
57+
namespace: ${TENANT_PROJECT_ID}
58+
annotations:
59+
config.kubernetes.io/depends-on: compute.cnrm.cloud.google.com/namespaces/${TENANT_PROJECT_ID}/ComputeNetwork/${GKE_NAME}
60+
spec:
61+
authorizedNetworkRef:
62+
name: ${GKE_NAME}
63+
memorySizeGb: 1
64+
redisVersion: REDIS_6_X
65+
region: ${GKE_LOCATION}
66+
tier: BASIC
67+
transitEncryptionMode: SERVER_AUTHENTICATION
68+
EOF
69+
```
70+
4771
## Deploy Kubernetes manifests
4872

4973
```Bash

content/onlineboutique/secure-memorystore-access.md

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,10 @@ title: "Secure Memorystore access"
33
weight: 12
44
description: "Duration: 10 min | Persona: Apps Operator"
55
tags: ["apps-operator", "asm", "security-tips"]
6-
hidden: true
76
---
87
![Apps Operator](/images/apps-operator.png)
98
_{{< param description >}}_
109

11-
{{% notice warning %}}
12-
This section is under construction and is not working currently, this page is hidden. Do not use it yet.
13-
{{% /notice %}}
14-
1510
In this section, you will secure the access by TLS to the Memorystore (redis) instance from the OnlineBoutique's `cartservice` appl, without updating the source code of the app, just with Istio's capabilities.
1611

1712
Initialize variables:
@@ -29,21 +24,20 @@ The `CART_MEMORYSTORE_HOST` has been built in order to explicitly represent the
2924

3025
Get Memorystore (redis) connection information:
3126
```Bash
32-
export REDIS_IP=$(gcloud redis instances describe $REDIS_NAME --region=$GKE_LOCATION --project=$TENANT_PROJECT_ID --format='get(host)')
33-
export REDIS_PORT=$(gcloud redis instances describe $REDIS_NAME --region=$GKE_LOCATION --project=$TENANT_PROJECT_ID --format='get(port)')
27+
export REDIS_TLS_IP=$(gcloud redis instances describe $REDIS_TLS_NAME --region=$GKE_LOCATION --project=$TENANT_PROJECT_ID --format='get(host)')
28+
export REDIS_TLS_PORT=$(gcloud redis instances describe $REDIS_TLS_NAME --region=$GKE_LOCATION --project=$TENANT_PROJECT_ID --format='get(port)')
3429
export REDIS_TLS_CERT_NAME=redis-cert
35-
gcloud redis instances describe $REDIS_NAME --region=$GKE_LOCATION --project=$TENANT_PROJECT_ID --format='get(serverCaCerts[0].cert)' > ${WORK_DIR}${REDIS_TLS_CERT_NAME}.pem
30+
gcloud redis instances describe $REDIS_TLS_NAME --region=$GKE_LOCATION --project=$TENANT_PROJECT_ID --format='get(serverCaCerts[0].cert)' > ${WORK_DIR}${REDIS_TLS_CERT_NAME}.pem
3631
```
3732

3833
Update the Online Boutique apps with the new Memorystore (redis) connection information:
3934
```Bash
4035
cd ${WORK_DIR}$ONLINE_BOUTIQUE_DIR_NAME/staging
4136
cp -r ../upstream/base/for-memorystore/ .
42-
sed -i "s/REDIS_IP/${REDIS_IP}/g;s/REDIS_PORT/${REDIS_PORT}/g" for-memorystore/kustomization.yaml
43-
kustomize edit add component for-memorystore
37+
sed -i "s/REDIS_IP/${REDIS_TLS_IP}/g;s/REDIS_PORT/${REDIS_TLS_PORT}/g" for-memorystore/kustomization.yaml
4438
```
4539
{{% notice info %}}
46-
This will change the `REDIS_ADDR` environment variable of the `cartservice` to point to the Memorystore (redis) instance as well as removing the `Deployment` and the `Service` of the default in-cluster `redis` database container.
40+
This will change the `REDIS_ADDR` environment variable of the `cartservice` to point to the Memorystore (redis) instance with TLS enabled.
4741
{{% /notice %}}
4842

4943
Define the `Secret` with the Certificate Authority:
@@ -68,13 +62,13 @@ spec:
6862
hosts:
6963
- ${CART_MEMORYSTORE_HOST}
7064
addresses:
71-
- ${REDIS_IP}/32
65+
- ${REDIS_TLS_IP}/32
7266
endpoints:
73-
- address: ${REDIS_IP}
67+
- address: ${REDIS_TLS_IP}
7468
location: MESH_EXTERNAL
7569
resolution: STATIC
7670
ports:
77-
- number: ${REDIS_PORT}
71+
- number: ${REDIS_TLS_PORT}
7872
name: tcp-redis
7973
protocol: TCP
8074
EOF
@@ -116,12 +110,10 @@ patches:
116110
EOF
117111
```
118112

119-
Update the previously deployed `Sidecars`, `NetworkPolicies` and `AuthorizationPolicies`:
113+
Update the previously deployed `Sidecars`:
120114
```Bash
121115
cd ${WORK_DIR}$ONLINE_BOUTIQUE_DIR_NAME/staging
122-
kustomize edit add component ../upstream/sidecars/for-memorystore
123116
cat <<EOF >> kustomization.yaml
124-
patchesJson6902:
125117
- target:
126118
kind: Sidecar
127119
name: cartservice
@@ -132,18 +124,6 @@ patchesJson6902:
132124
- "istio-system/*"
133125
- "./${CART_MEMORYSTORE_HOST}"
134126
EOF
135-
cd ${WORK_DIR}$ONLINE_BOUTIQUE_DIR_NAME/base
136-
cat <<EOF >> network-policies/kustomization.yaml
137-
patchesStrategicMerge:
138-
- |-
139-
apiVersion: networking.k8s.io/v1
140-
kind: NetworkPolicy
141-
metadata:
142-
name: redis-cart
143-
\$patch: delete
144-
EOF
145-
kustomize edit add component ../upstream/service-accounts/for-memorystore
146-
kustomize edit add component ../upstream/authorization-policies/for-memorystore
147127
```
148128

149129
## Deploy Kubernetes manifests

content/service-mesh/set-up-asm-configs.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,14 @@ rules:
117117
- "virtualservices"
118118
- "authorizationpolicies"
119119
- "sidecars"
120+
- "serviceentries"
121+
- "destinationrules"
120122
verbs:
121123
- "*"
122124
EOF
123125
```
124126
{{% notice tip %}}
125-
Later in this workshop, for each app namespace, we will define a Config Sync's `RepoSync` which will be bound to the `edit` `ClusterRole`. With that new extension, it will allow each namespace to deploy Istio resources such as `Sidecar`, `VirtualService` and `AuthorizationPolicy` while meeting with the least privilege principle requirement.
127+
Later in this workshop, for each app namespace, we will define a Config Sync's `RepoSync` which will be bound to the `edit` `ClusterRole`. With that new extension, it will allow each namespace to deploy Istio resources such as `Sidecar`, `VirtualService`, `AuthorizationPolicy`, `ServiceEntry` and `DestinationRule` while meeting with the least privilege principle requirement.
126128
{{% /notice %}}
127129

128130
## Deploy Kubernetes manifests

0 commit comments

Comments
 (0)