Skip to content

Commit fda358d

Browse files
authored
Merge pull request #77808 from michaelryanmcneill/OSDOCS-10980
OSDOCS-10980: Updating WAF Tutorials
2 parents 0dfb3e0 + 161f4b5 commit fda358d

File tree

2 files changed

+148
-94
lines changed

2 files changed

+148
-94
lines changed

cloud_experts_tutorials/cloud-experts-using-alb-and-waf.adoc

Lines changed: 57 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,21 @@ AWS WAF is a web application firewall that lets you monitor the HTTP and HTTPS r
2121

2222
You can use an AWS Application Load Balancer (ALB) to add a Web Application Firewall (WAF) to your {product-title} (ROSA) workloads. Using an external solution protects ROSA resources from experiencing denial of service due to handling the WAF.
2323

24-
[NOTE]
24+
[IMPORTANT]
2525
====
26-
It is recommended that you use the xref:../cloud_experts_tutorials/cloud-experts-using-cloudfront-and-waf.adoc#cloud-experts-using-cloudfront-and-waf[CloudFront method] unless you absolutely must use an ALB based solution.
26+
It is recommended that you use the more flexible xref:../cloud_experts_tutorials/cloud-experts-using-cloudfront-and-waf.adoc#cloud-experts-using-cloudfront-and-waf[CloudFront method] unless you absolutely must use an ALB based solution.
2727
====
2828

29-
//[Here](https://iamondemand.com/blog/elb-vs-alb-vs-nlb-choosing-the-best-aws-load-balancer-for-your-needs/)'s a good overview of AWS LB types and what they support
30-
31-
// Loosely based off EKS instructions here - https://aws.amazon.com/premiumsupport/knowledge-center/eks-alb-ingress-aws-waf/
32-
3329
[id="prerequisites_{context}"]
3430
== Prerequisites
3531

32+
* Multiple availability zone (AZ) ROSA (HCP or Classic) cluster.
33+
+
3634
[NOTE]
3735
====
38-
AWS ALBs require a multi-AZ cluster, as well as three public subnets split across three AZs in the same VPC as the cluster.
36+
AWS ALBs require at least two _public_ subnets across AZs, link:https://docs.aws.amazon.com/elasticloadbalancing/latest/application/application-load-balancers.html#availability-zones[per the AWS documentation]. For this reason, only multiple AZ ROSA clusters can be used with ALBs.
3937
====
40-
41-
* xref:../rosa_install_access_delete_clusters/rosa-sts-creating-a-cluster-quickly.adoc#rosa-sts-creating-a-cluster-quickly[A multi-AZ ROSA Classic cluster].
38+
+
4239
* You have access to the OpenShift CLI (`oc`).
4340
* You have access to the AWS CLI (`aws`).
4441

@@ -50,13 +47,13 @@ AWS ALBs require a multi-AZ cluster, as well as three public subnets split acros
5047
[source,terminal]
5148
----
5249
$ export AWS_PAGER=""
53-
$ export CLUSTER_NAME=$(oc get infrastructure cluster -o=jsonpath="{.status.infrastructureName}" | sed 's/-[a-z0-9]\{5\}$//')
50+
$ export CLUSTER=$(oc get infrastructure cluster -o=jsonpath="{.status.infrastructureName}")
5451
$ export REGION=$(oc get infrastructure cluster -o=jsonpath="{.status.platformStatus.aws.region}")
5552
$ export OIDC_ENDPOINT=$(oc get authentication.config.openshift.io cluster -o jsonpath='{.spec.serviceAccountIssuer}' | sed 's|^https://||')
5653
$ export AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
57-
$ export SCRATCH="/tmp/${CLUSTER_NAME}/alb-waf"
54+
$ export SCRATCH="/tmp/${CLUSTER}/alb-waf"
5855
$ mkdir -p ${SCRATCH}
59-
$ echo "Cluster: ${CLUSTER_NAME}, Region: ${REGION}, OIDC Endpoint: ${OIDC_ENDPOINT}, AWS Account ID: ${AWS_ACCOUNT_ID}"
56+
$ echo "Cluster: $(echo ${CLUSTER} | sed 's/-[a-z0-9]\{5\}$//'), Region: ${REGION}, OIDC Endpoint: ${OIDC_ENDPOINT}, AWS Account ID: ${AWS_ACCOUNT_ID}"
6057
----
6158

6259
[id="aws-vpc-and-subnets_{context}"]
@@ -71,65 +68,80 @@ This section only applies to clusters that were deployed into existing VPCs. If
7168
+
7269
[source,terminal]
7370
----
74-
$ export VPC_ID=<vpc-id>
75-
$ export PUBLIC_SUBNET_IDS=<public-subnets>
76-
$ export PRIVATE_SUBNET_IDS=<private-subnets>
71+
$ export VPC_ID=<vpc-id> <1>
72+
$ export PUBLIC_SUBNET_IDS=(<space-separated-list-of-ids>) <2>
73+
$ export PRIVATE_SUBNET_IDS=(<space-separated-list-of-ids>) <3>
7774
----
75+
<1> Replace with the VPC ID of the cluster, for example: `export VPC_ID=vpc-04c429b7dbc4680ba`.
76+
<2> Replace with a space-separated list of the private subnet IDs of the cluster, making sure to preserve the `()`. For example: `export PUBLIC_SUBNET_IDS=(subnet-056fd6861ad332ba2 subnet-08ce3b4ec753fe74c subnet-071aa28228664972f)`.
77+
<3> Replace with a space-separated list of the private subnet IDs of the cluster, making sure to preserve the `()`. For example: `export PRIVATE_SUBNET_IDS=(subnet-0b933d72a8d72c36a subnet-0817eb72070f1d3c2 subnet-0806e64159b66665a)`.
7878
+
79-
. Add a tag to your cluster's VPC with the cluster name:
79+
. Add a tag to your cluster's VPC with the cluster identifier:
8080
+
8181
[source,terminal]
8282
----
83-
$ aws ec2 create-tags --resources ${VPC_ID} --tags Key=kubernetes.io/cluster/${CLUSTER_NAME},Value=owned --region ${REGION}
83+
$ aws ec2 create-tags --resources ${VPC_ID} \
84+
--tags Key=kubernetes.io/cluster/${CLUSTER},Value=shared --region ${REGION}
8485
----
8586
+
8687
. Add a tag to your public subnets:
8788
+
8889
[source,terminal]
8990
----
9091
$ aws ec2 create-tags \
91-
--resources ${PUBLIC_SUBNET_IDS} \
92-
--tags Key=kubernetes.io/role/elb,Value='' \
93-
--region ${REGION}
92+
--resources ${PUBLIC_SUBNET_IDS} \
93+
--tags Key=kubernetes.io/role/elb,Value='1' \
94+
Key=kubernetes.io/cluster/${CLUSTER},Value=shared \
95+
--region ${REGION}
9496
----
9597
+
9698
. Add a tag to your private subnets:
9799
+
98100
[source,terminal]
99101
----
100102
$ aws ec2 create-tags \
101-
--resources "${PRIVATE_SUBNET_IDS}" \
102-
--tags Key=kubernetes.io/role/internal-elb,Value='' \
103-
--region ${REGION}
103+
--resources ${PRIVATE_SUBNET_IDS} \
104+
--tags Key=kubernetes.io/role/internal-elb,Value='1' \
105+
Key=kubernetes.io/cluster/${CLUSTER},Value=shared \
106+
--region ${REGION}
104107
----
105108

106109
[id="deploy-aws-load-balancer-operator_{context}"]
107110
== Deploy the AWS Load Balancer Operator
108111

109112
The link:https://github.com/openshift/aws-load-balancer-operator[AWS Load Balancer Operator] is used to used to install, manage and configure an instance of `aws-load-balancer-controller` in a ROSA cluster. To deploy ALBs in ROSA, we need to first deploy the AWS Load Balancer Operator.
110113

111-
. Create an AWS IAM policy for the AWS Load Balancer Controller:
114+
. Create a new project to deploy the AWS Load Balancer Operator into by running the following command:
115+
+
116+
[source,terminal]
117+
----
118+
$ oc new-project aws-load-balancer-operator
119+
----
120+
+
121+
. Create an AWS IAM policy for the AWS Load Balancer Controller if one does not already exist by running the following command:
112122
+
113123
[NOTE]
114124
====
115-
The policy is sourced from link:https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.4.4/docs/install/iam_policy.json[the upstream AWS Load Balancer Controller policy] plus permission to create tags on subnets. This is required by the operator to function.
125+
The policy is sourced from link:https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/main/docs/install/iam_policy.json[the upstream AWS Load Balancer Controller policy]. This is required by the operator to function.
116126
====
117127
+
118128
[source,terminal]
119129
----
120-
$ oc new-project aws-load-balancer-operator
121130
$ POLICY_ARN=$(aws iam list-policies --query \
122131
"Policies[?PolicyName=='aws-load-balancer-operator-policy'].{ARN:Arn}" \
123132
--output text)
133+
----
134+
+
135+
[source,terminal]
136+
----
124137
$ if [[ -z "${POLICY_ARN}" ]]; then
125138
wget -O "${SCRATCH}/load-balancer-operator-policy.json" \
126-
https://raw.githubusercontent.com/rh-mobb/documentation/main/content/rosa/aws-load-balancer-operator/load-balancer-operator-policy.json
139+
https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/main/docs/install/iam_policy.json
127140
POLICY_ARN=$(aws --region "$REGION" --query Policy.Arn \
128141
--output text iam create-policy \
129142
--policy-name aws-load-balancer-operator-policy \
130143
--policy-document "file://${SCRATCH}/load-balancer-operator-policy.json")
131144
fi
132-
$ echo $POLICY_ARN
133145
----
134146
+
135147
. Create an AWS IAM trust policy for AWS Load Balancer Operator:
@@ -161,13 +173,17 @@ EOF
161173
+
162174
[source,terminal]
163175
----
164-
$ ROLE_ARN=$(aws iam create-role --role-name "${CLUSTER_NAME}-alb-operator" \
176+
$ ROLE_ARN=$(aws iam create-role --role-name "${CLUSTER}-alb-operator" \
165177
--assume-role-policy-document "file://${SCRATCH}/trust-policy.json" \
166178
--query Role.Arn --output text)
167-
$ echo $ROLE_ARN
168-
169-
$ aws iam attach-role-policy --role-name "${CLUSTER_NAME}-alb-operator" \
170-
--policy-arn $POLICY_ARN
179+
----
180+
+
181+
. Attach the AWS Load Balancer Operator policy to the IAM role we created previously by running the following command:
182+
+
183+
[source,terminal]
184+
----
185+
$ aws iam attach-role-policy --role-name "${CLUSTER}-alb-operator" \
186+
--policy-arn ${POLICY_ARN}
171187
----
172188
+
173189
. Create a secret for the AWS Load Balancer Operator to assume our newly created AWS IAM role:
@@ -183,7 +199,7 @@ metadata:
183199
stringData:
184200
credentials: |
185201
[default]
186-
role_arn = $ROLE_ARN
202+
role_arn = ${ROLE_ARN}
187203
web_identity_token_file = /var/run/secrets/openshift/serviceaccount/token
188204
EOF
189205
----
@@ -382,11 +398,11 @@ This will enable the Core (Common) and SQL AWS Managed Rule Sets.
382398
[source,terminal]
383399
----
384400
$ WAF_ARN=$(aws wafv2 create-web-acl \
385-
--name ${CLUSTER_NAME}-waf \
401+
--name ${CLUSTER}-waf \
386402
--region ${REGION} \
387403
--default-action Allow={} \
388404
--scope REGIONAL \
389-
--visibility-config SampledRequestsEnabled=true,CloudWatchMetricsEnabled=true,MetricName=${CLUSTER_NAME}-waf-metrics \
405+
--visibility-config SampledRequestsEnabled=true,CloudWatchMetricsEnabled=true,MetricName=${CLUSTER}-waf-metrics \
390406
--rules file://${SCRATCH}/waf-rules.json \
391407
--query 'Summary.ARN' \
392408
--output text)
@@ -433,11 +449,15 @@ $ curl -X POST "http://${INGRESS}" \
433449
</html
434450
----
435451
+
452+
[NOTE]
453+
====
454+
Activation of the AWS WAF integration can sometimes take several minutes. If you do not receive a `403 Forbidden` error, please wait a few seconds and try again.
455+
====
456+
+
436457
The expected result is a `403 Forbidden` error, which means the AWS WAF is protecting your application.
437458

438459
[role="_additional-resources"]
439460
[id="additional-resources_{context}"]
440461
== Additional resources
441462

442-
* link:https://docs.openshift.com/rosa/applications/deployments/osd-config-custom-domains-applications.html[Custom domains for applications] in the Red{nbsp}Hat documentation
443463
* link:https://youtu.be/-HorEsl2ho4[Adding Extra Security with AWS WAF, CloudFront and ROSA | Amazon Web Services] on YouTube

0 commit comments

Comments
 (0)