Skip to content

Commit 03ff16b

Browse files
committed
Replace Trusted Signer with Trusted Key Groups implemenation in Amazon CloudFront.
1 parent d6e13ad commit 03ff16b

10 files changed

Lines changed: 144 additions & 112 deletions

File tree

1-Create_S3_Bucket/README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
## Step 1: Create Amazon S3 Bucket
22

3-
In this step we will stage a private Amazon S3 bucket with a sample HTML file.
3+
In this step you will stage a private Amazon S3 bucket with a sample HTML file.
44

5-
**Note**: Use an IAM user account in this step for security best practices.
5+
**Note**: Amazon S3 routes any virtual hosted–style requests to the US East (N. Virginia) region by default if you use the US East (N. Virginia) endpoint (s3.amazonaws.com), When you create a new bucket, in any region, Amazon S3 updates DNS to reroute the request to the correct region, which might take time when using Amazon CloudFront for distribution in later section. For the purpose of this exercise, you will create a new bucket in AWS **region** `us-east-1`. Detailed explanation of **AWS Virtual hosting of buckets** is provided in [AWS User Guide](https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html).
66

77
### Create S3 Bucket
88
1. Log into your AWS account and navigate to the [Amazon S3 Management Console](https://s3.console.aws.amazon.com/).
9-
2. Select **Create Bucket**.
10-
3. Provide **Bucket name** and select any **Region**.
11-
4. Leave everything as default.
12-
5. Select **Create bucket** to create the Bucket.
13-
6. Select the bucket you just created.
14-
7. Select **Upload**.
15-
8. Select **Add files**.
16-
9. Select the sample file `sample.html` from your computer.
17-
10. Select **Upload** to upload the file.
9+
2. Choose **Create Bucket**.
10+
3. Provide a name for **Bucket name**.
11+
4. Select **US East (N. Virginia) us-east-1** for **AWS Region** .
12+
5. Leave everything as default.
13+
6. Choose **Create bucket** to create the bucket.
14+
7. Choose the bucket you just created.
15+
8. Choose **Upload**.
16+
9. Choose **Add files**.
17+
10. Choose the included sample file `sample.html` from your local drive.
18+
11. Choose **Upload** to upload the file.
1819

19-
We successfully created an Amazon S3 bucket and uploaded a sample HTML file. However if you try to access the sample HTML file using the S3 object URL, like `https://yourbucket.s3-us-west-2.amazonaws.com/sample.html`, in your browser you will get an access denied message. This is exactly what we want. We want to keep our S3 contents private and will only distribute them using an Amazon CloudFront distribution.
20+
You successfully created an Amazon S3 bucket and uploaded a sample HTML file. However if you try to access the sample HTML file using the S3 object URL, like `https://yourbucket.s3-us-west-2.amazonaws.com/sample.html`, in your browser you will get an access denied message. This is exactly what you want. You want to keep your S3 contents private and will only distribute them using an Amazon CloudFront distribution.
2021

21-
In [Step 2](../2-Create_CloudFront_Distribution/README.md), we will create the Amazon CloudFront Distribution.
22+
In [Step 2](../2-Create_CloudFront_Distribution/README.md), you will create the Amazon CloudFront Distribution.
Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,38 @@
11
## Step 2: Create Amazon CloudFront Distribution
22

3-
In this step we will create an Amazon CloudFront distribution with your Amazon S3 bucket created in Step 1 as source. We will also restrict access to the bucket by using an [Origin Access Identity (OAI)](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-restricting-access-to-s3.html).
4-
5-
**Note**: Use an IAM user account in this step for security best practices.
3+
In this step you will create an Amazon CloudFront distribution with your Amazon S3 bucket created in Step 1 as source. You will also restrict access to the bucket by using an [Origin Access Identity (OAI)](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-restricting-access-to-s3.html).
64

75
### Create Distribution
86
1. Log into your AWS account and navigate to the [Amazon CloudFront Management Console](https://console.aws.amazon.com/cloudfront).
9-
2. Select **Create Distribution**.
10-
3. Under Web, select **Get Started**.
11-
4. For **Origin Domain Name** select your Amazon S3 Bucket from Step 1.
12-
5. For **Restrict Bucket Access** select **Yes**.
13-
6. For **Origin Access Identity** select **Create a New Identity**.
14-
7. For **Grant Read Permissions on Bucket** select **Yes, Update Bucket Policy**. This will automatically add an Amazon Bucket policy to the your bucket allowing only this CloudFront distribution to read from the bucket.
15-
8. Leave everything else as default and select **Create Distribution**.
7+
2. Choose **Create Distribution**.
8+
3. Under Web, choose **Get Started**.
9+
4. For **Origin Domain Name** choose your Amazon S3 Bucket from Step 1.
10+
5. For **Restrict Bucket Access** choose **Yes**.
11+
6. For **Origin Access Identity** choose **Create a New Identity**.
12+
7. For **Grant Read Permissions on Bucket** choose **Yes, Update Bucket Policy**. This will automatically add an Amazon Bucket policy to the your bucket allowing only this CloudFront distribution to read from the bucket.
13+
8. Leave everything else as default and choose **Create Distribution**.
1614
9. In the distribution details screen, note the **Distribution Status**. Wait for the status to change from **In Progress** to **Deployed**. It can take upward of 5 minutes for the process to complete.
1715
10. Under **Domain Name** copy the FQDN, similar to `dxxxxxxxxxz.cloudfront.net`.
1816

1917
### Test Public Distribution
20-
We want to test to verify that the distribution is setup correctly and has access to the Amazon S3 contents.
18+
You want to test to verify that the distribution is setup correctly and has access to the Amazon S3 contents.
2119

2220
Use your browser and enter the URL https://dxxxxxxxxxz.cloudfront.net/sample.html. Remember to replace the domain name with your FQDN. Your sample webpage should come up correctly. However, anyone with your URL can access your Amazon S3 contents.
2321

2422
### Secure Distribution
25-
Next we want to secure the Amazon CloudFront distribution to restrict public access.
26-
1. Select the **Distribution ID** to open the detail view.
27-
2. Select the **Behaviors** tab.
28-
3. Checkbox the default **Origin or Origin Group** and select **Edit**.
29-
4. Under **Restrict Viewer Access (Use Signed URLs or Signed Cookies)** select **Yes** to expand the **Trusted Key Groups or Trusted Signer** option.
30-
5. Under **Trusted Key Groups or Trusted Sign**, select **Trusted Signer**.
31-
6. Under **Trusted Signers** select **Self** if you are using the same AWS Account for both the CloudFront distribution and the CloudFront key pair, which we will create in the next step. Select **Specify Accounts** and enter the account number of another AWS Account that you will be using to create the CloudFront key pair.
32-
7. Select **Yes, Edit** to save the changes.
23+
Next you want to secure the Amazon CloudFront distribution to restrict public access.
24+
1. Choose the **Distribution ID** to open the detail view.
25+
2. Choose the **Behaviors** tab.
26+
3. Select the default **Origin or Origin Group** and choose **Edit**.
27+
4. Under **Restrict Viewer Access (Use Signed URLs or Signed Cookies)** choose **Yes** to expand the **Trusted Key Groups or Trusted Signer** option.
28+
5. Under **Trusted Key Groups or Trusted Signer**, select **Trusted Signer**. (Note: you will change this to **Trusted Key Groups** in later section.)
29+
6. Under **Trusted Signers** select **Self**.
30+
7. Choose **Yes, Edit** to save the changes.
3331

3432
### Test Secured Distribution
35-
Now we want to test to verify that the distribution is restricted. Refresh the webpage and you should see the error message:
33+
Now you want to test to verify that the distribution is restricted. Refresh the webpage and you should see the error message:
3634
> Missing Key-Pair-Id query parameter or cookie value
3735
38-
In this step we created an Amazon CloudFront distribution to distribute your Amazon S3 private contents. We then secured the distribution by using the **Restrict Viewer Access** option.
36+
In this step you created an Amazon CloudFront distribution to distribute your Amazon S3 private contents. You then secured the distribution by using the **Restrict Viewer Access** option.
3937

40-
In [Step 3](../3-Create_CloudFront_Keypair/README.md), we will create the **CloudFront Key Pair**
38+
In [Step 3](../3-Create_CloudFront_Key_Groups/README.md), you will create the **CloudFront Key Groups**
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
## Step 3: Create CloudFront Key Group
2+
3+
In this step you will create a trusted [CloudFront key group](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-trusted-signers.html#choosing-key-groups-or-AWS-accounts). First you will create a public-private key pair. The key pair must meet the following requirements:
4+
- It must be an SSH-2 RSA key pair.
5+
- It must be in base64-encoded PEM format.
6+
- It must be a 2048-bit key pair.
7+
8+
9+
### Create Key Pair
10+
The following steps use OpenSSL as an example of one way to create a key pair. There are many other ways to create an RSA key pair.
11+
1. The following example command uses OpenSSL to generate an RSA key pair with a length of 2048 bits and save to the file named `private_key.pem`.
12+
```
13+
$ openssl genrsa -out private_key.pem 2048
14+
```
15+
2. The resulting file contains both the public and the private key. The following example command extracts the public key from the file named `private_key.pem` and save to the file named `public_key.pem`.
16+
```
17+
$ openssl rsa -pubout -in private_key.pem -out public_key.pem
18+
```
19+
20+
### Upload Public Key
21+
1. On [Amazon CloudFront Management Console](https://console.aws.amazon.com/cloudfront)
22+
2. In the navigation menu, choose **Public keys**.
23+
3. Choose **Add public key**.
24+
4. In the **Add public key** window, do the following:
25+
- For **Key name**, type a name to identify the public key.
26+
- For **Key value**, copy and paste the contents of the public key. If you followed the steps in the preceding procedure, the public key is in the file named `public_key.pem`.
27+
- (Optional) For **Comment**, add a comment to describe the public key.
28+
29+
When finished, choose **Add**.
30+
5. Record the public key ID. You will use it later section.
31+
32+
### Create Key group
33+
1. In the navigation menu, choose **Key groups**.
34+
2. Choose **Add key group**.
35+
3. On the **Create key group** page, do the following:
36+
- For **Key group name**, type a name to identify the key group.
37+
- (Optional) For **Comment**, type a comment to describe the key group.
38+
- For **Public keys**, select the public key to add to the key group, then choose **Add**.
39+
4. Choose **Create key group**.
40+
41+
### Associate Key group
42+
1. In the navigation menu, choose **Distributions**.
43+
2. Choose the **Distribution ID** link you created in Step 2.
44+
3. Choose the **Behaviors** tab.
45+
4. Select the cache behavior and then choose **Edit**.
46+
5. On the **Edit Behavior** page, do the following:
47+
- For **Trusted Key Groups or Trusted Signer**, choose **Trusted Key Groups**.
48+
- For **Trusted Key Groups**, choose the key group to add, and then choose **Add**.
49+
6. Choose **Yes, Edit** to update the cache behavior.
50+
51+
In this step you generated a public-private key pair, created a CloudFront Key group with a public key, and associated the Key group to your CloudFront distribution.
52+
53+
In [Step 4](../4-Create_Secrets_Manager/README.md) we will create a secret in **AWS Secrets Managers**.

3-Create_CloudFront_Keypair/README.md

Lines changed: 0 additions & 17 deletions
This file was deleted.

4-Create_Secrets_Manager/README.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
## Step 4: Create Secrets Manager
22

3-
In this step we will create a secret in **AWS Secrets Manager**. Up to this point, we have used **Amazon S3**, **Amazon CloudFront**, and **Amazon IAM**, which are AWS global services. As **AWS Secrets Manager** and **AWS Lambda** are regional services, you will need to pick an AWS region.
4-
5-
**Note**: Use an IAM user account in this step for security best practices.
3+
In this step you will create a secret in **AWS Secrets Manager**. Up to this point, you have used **Amazon S3** and **Amazon CloudFront**, which are AWS global services. As **AWS Secrets Manager** and **AWS Lambda** are regional services, you will need to pick an AWS **region** to use for the remainder of this sample.
64

75
### Create a Secret
8-
1. Log into your AWS account and navigate to the [AWS Secrets Manager Management Console](https://us-west-2.console.aws.amazon.com/secretsmanager).
9-
2. Select an AWS region.
10-
3. Select **Store a new secret**.
6+
1. Open the [AWS Secrets Manager Management Console](https://us-west-2.console.aws.amazon.com/secretsmanager).
7+
2. Select an AWS **region**.
8+
3. Choose **Store a new secret**.
119
4. For **Select secret type**, select **Other type of secrets**.
1210
5. For **Specify the key/value pairs to be stored in this secret** select **Plaintext**.
13-
6. Copy your CloudFront private key to your clipboard and paste it into the text box.
14-
7. Select **Next**.
11+
6. Copy and paste the contents of the private key in the file named **private_key.pem** from previous step.
12+
7. Choose **Next**.
1513
8. For **Secret name**, provide a name.
16-
9. Select **Next**.
14+
9. Choose **Next**.
1715
10. Leave rotation as **Disable automatic rotation** as checked.
18-
11. Select **Next**.
19-
12. Select **Store**.
20-
13. Copy both the Secret Name and the Secret ARN, which we will need for the next step.
16+
11. Choose **Next**.
17+
12. Choose **Store**.
18+
13. Select your **Secret** to view the details.
19+
13. Record both the **Secret name** and **Secret ARN**. You will need them for the next step.
2120

22-
In this step we configured **AWS Secrets Manager** to store the CloudFront private key to be consumed by a downstream client. Next we will configure an **AWS Lambda** function to generate CloudFront signed URLs. We provided steps for both CloudFront canned and custom polices.
21+
In this step you configured **AWS Secrets Manager** to store the CloudFront private key to be consumed by a downstream client. Next you will configure an **AWS Lambda** function to generate CloudFront signed URLs. We provide steps for both CloudFront canned and custom polices.
2322

2423
[Step 5: Create CloudFront SignedURL with Canned Policy](../5-Create_CloudFront_SignedURL_Canned/README.md)
2524
[Step 6: Create CloudFront SignedURL with Custom Policy](../6-Create_CloudFront_SignedURL_Custom/README.md)

0 commit comments

Comments
 (0)