Skip to content

Commit b9cb18e

Browse files
Update coreHTTP S3 Download Instructions (FreeRTOS#1127)
* Update coreHTTP S3 Download Instructions * Revert to 85d531916 * Update comment for S3 Root CA in Upload and Download Multithreaded demos * Wrap changes to 80 characters * Uncrustify: triggered by comment. * Run Github Actions. * Fix broken section link in README * Wrap README text on 90 characters * Uncrustify: triggered by comment. * Run Github Actions --------- Co-authored-by: GitHub Action <[email protected]>
1 parent fee933f commit b9cb18e

File tree

4 files changed

+113
-83
lines changed

4 files changed

+113
-83
lines changed

FreeRTOS-Plus/Demo/coreHTTP_Windows_Simulator/HTTP_S3_Download/README.md

Lines changed: 110 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,78 @@
1-
# Configure HTTP S3 Download Demo using SigV4 Library.
1+
# Configure HTTP S3 Download Demo using SigV4 Library
22

33
Following steps needs to be followed to configure HTTP S3 Download Demo to use SigV4 library for authenticating the requests sent to AWS S3.
44

5-
### Prerequisites
5+
## Prerequisites
66

7-
1. You will need an AWS Account with S3 access before beginning. You must be familiar with AWS IoT and IAM to perform steps using the AWS CLI. You must install and configure the AWS CLI in order to follow the steps.
8-
For information on AWS S3 please see: https://docs.aws.amazon.com/AmazonS3/latest/dev/Welcome.html
9-
For AWS CLI installation information please see: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html
10-
For AWS CLI configuration information please see: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html
7+
1. You will need an AWS Account with S3 access before beginning. You must be familiar with
8+
AWS IoT and IAM to perform steps using the AWS CLI. You must install and configure the AWS
9+
CLI in order to follow the steps.
10+
11+
* For information on AWS S3 please refer to the
12+
[Welcome Guide](https://docs.aws.amazon.com/AmazonS3/latest/dev/Welcome.html)
13+
14+
* [AWS CLI Installation guide](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html)
15+
16+
* [AWS CLI Configuration Guide](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)
1117

1218
```sh
1319
aws configure
1420
```
1521

1622
### Detailed Steps
1723

18-
#### 1. Create an AWS IoT thing:
24+
#### 1. Create an AWS IoT thing
1925

20-
You may utilize an already existing AWS IoT Thing or create a new one in the IoT Core section of the AWS Management Console UI.
26+
You may utilize an already existing AWS IoT Thing or create a new one in the IoT Core
27+
section of the AWS Management Console UI.
28+
29+
You may also use the AWS CLI with the following command to create a Thing,
30+
keeping track of its name:
2131

22-
You may also use the AWS CLI with the following command to create a Thing, keeping track of its name:
2332
```sh
2433
aws iot create-thing --thing-name device_thing_name
2534
```
2635

27-
#### 2. Register a certificate:
36+
#### 2. Register a certificate
2837

29-
If your AWS IoT Thing already has a certificate attached to it, then that certificate's ARN can be used in [step 5](#5. attach-a-policy). Otherwise, you can create a certificate and attach it to the thing through IoT Core in the AWS Management Console UI. By doing any of these, you may skip to [step 3](#3-configure-an-iam-role).
38+
If your AWS IoT Thing already has a certificate attached to it, then that certificate's
39+
ARN can be used in [step 5](#5-attach-a-policy). Otherwise, you can create a certificate
40+
and attach it to the thing through IoT Core in the AWS Management Console UI. By doing
41+
any of these, you may skip to [step 3](#3-configure-an-iam-role).
3042

31-
It is also possible to sign the Thing's certificate using your own Certificate Authority (CA) certificate, and register both certificates with AWS IoT before your device can authenticate to AWS IoT. If you do not already have a CA certificate, you can use OpenSSL to create a CA certificate, as described in [Use Your Own Certificate](https://docs.aws.amazon.com/iot/latest/developerguide/device-certs-your-own.html). To register your CA certificate with AWS IoT, follow the steps on [Registering Your CA Certificate](https://docs.aws.amazon.com/iot/latest/developerguide/device-certs-your-own.html#register-CA-cert).
43+
It is also possible to sign the Thing's certificate using your own Certificate Authority
44+
(CA) certificate, and register both certificates with AWS IoT before your device can
45+
authenticate to AWS IoT. If you do not already have a CA certificate, you can use OpenSSL
46+
to create a CA certificate, as described in
47+
[Use Your Own Certificate](https://docs.aws.amazon.com/iot/latest/developerguide/device-certs-your-own.html).
48+
To register your CA certificate with AWS IoT, follow the steps on
49+
[Registering Your CA Certificate](https://docs.aws.amazon.com/iot/latest/developerguide/device-certs-your-own.html#register-CA-cert).
3250

33-
You then have to create a device certificate signed by the CA certificate and register it with AWS IoT, which you can do by following the steps on [Creating a Device Certificate Using Your CA Certificate](https://docs.aws.amazon.com/iot/latest/developerguide/device-certs-your-own.html#create-device-cert). Save the certificate and the corresponding key pair; you will use them when you request a security token later. Also, remember the password you provide when you create the certificate.
51+
You then have to create a device certificate signed by the CA certificate and register it
52+
with AWS IoT, which you can do by following the steps on
53+
[Creating a Device Certificate Using Your CA Certificate](https://docs.aws.amazon.com/iot/latest/developerguide/device-certs-your-own.html#create-device-cert).
54+
Save the certificate and the corresponding key pair; you will use them when you request a
55+
security token later. Also, remember the password you provide when you create the
56+
certificate.
3457

35-
Run the following command in the AWS CLI to attach the device certificate to your thing so that you can use thing attributes in policy variables.
58+
Run the following command in the AWS CLI to attach the device certificate to your thing
59+
so that you can use thing attributes in policy variables.
3660

3761
```sh
3862
aws iot attach-thing-principal --thing-name device_thing_name --principal <certificate-arn>
3963
```
4064

41-
#### 3. Configure an IAM role:
65+
#### 3. Configure an IAM role
4266

43-
Next, configure an IAM role in your AWS account that will be assumed by the credentials provider on behalf of your device. You are required to associate two policies with the role: a trust policy that controls who can assume the role, and an access policy that controls which actions can be performed on which resources by assuming the role.
67+
Next, configure an IAM role in your AWS account that will be assumed by the credentials
68+
provider on behalf of your device. You are required to associate two policies with the
69+
role: a trust policy that controls who can assume the role, and an access policy that
70+
controls which actions can be performed on which resources by assuming the role.
4471

45-
The following trust policy grants the credentials provider permission to assume the role. Put it in a text document and save the document with the name, trustpolicyforiot.json.
72+
The following trust policy grants the credentials provider permission to assume the role.
73+
Put it in a text document and save the document with the name, trustpolicyforiot.json.
4674

47-
```
75+
```json
4876
{
4977
"Version": "2012-10-17",
5078
"Statement": {
@@ -54,13 +82,20 @@ The following trust policy grants the credentials provider permission to assume
5482
}
5583
}
5684
```
57-
Run the following command in the AWS CLI to create an IAM role with the preceding trust policy.
85+
86+
Run the following command in the AWS CLI to create an IAM role with the preceding trust
87+
policy.
5888

5989
```sh
6090
aws iam create-role --role-name s3-access-role --assume-role-policy-document file://trustpolicyforiot.json
6191
```
62-
The following s3 access policy allows you to perform actions on S3. Put the following policy in a text document and save the document with the name `accesspolicyfors3.json`.
63-
```
92+
93+
The following s3 access policy allows you to perform actions on S3. Put the
94+
following policy in a text document and save the document with the name
95+
`accesspolicyfors3.json`. Make Sure to replace "BUCKET_NAME" with the name
96+
of the S3 bucket you are using for this demo.
97+
98+
```json
6499
{
65100
"Version": "2012-10-17",
66101
"Statement": {
@@ -72,19 +107,29 @@ The following s3 access policy allows you to perform actions on S3. Put the foll
72107
}
73108
}
74109
```
110+
75111
Run the following command in the AWS CLI to create the access policy.
112+
76113
```sh
77114
aws iam create-policy --policy-name accesspolicyfors3 --policy-document file://accesspolicyfors3.json
78115
```
116+
79117
Finally, run the following command in the AWS CLI to attach the access policy to your role.
118+
80119
```sh
81120
aws iam attach-role-policy --role-name s3-access-role --policy-arn arn:aws:iam::<your_aws_account_id>:policy/accesspolicyfors3
82121
```
83122

84123
Configure the PassRole permissions
85124

86-
The IAM role that you have created must be passed to AWS IoT to create a role alias, as described in Step 4. The IAM user who performs the operation requires `iam:PassRole` permission to authorize this action. You also should add permission for the `iam:GetRole` action to allow the IAM user to retrieve information about the specified role. Create the following policy to grant `iam:PassRole` and `iam:GetRole` permissions. Name this policy `passrolepermission.json`.
87-
```
125+
The IAM role that you have created must be passed to AWS IoT to create a role alias, as
126+
described in Step 4. The IAM user who performs the operation requires `iam:PassRole`
127+
permission to authorize this action. You also should add permission for the `iam:GetRole`
128+
action to allow the IAM user to retrieve information about the specified role. Create the
129+
following policy to grant `iam:PassRole` and `iam:GetRole` permissions. Name this policy
130+
`passrolepermission.json`.
131+
132+
```json
88133
{
89134
"Version": "2012-10-17",
90135
"Statement": {
@@ -99,33 +144,51 @@ The IAM role that you have created must be passed to AWS IoT to create a role al
99144
```
100145

101146
Run the following command in the AWS CLI to create the policy in your AWS account.
147+
102148
```sh
103149
aws iam create-policy --policy-name passrolepermission --policy-document file://passrolepermission.json
104150
```
105151

106152
Now, run the following command to attach the policy to the IAM user.
153+
107154
```sh
108155
aws iam attach-user-policy --policy-arn arn:aws:iam::<your_aws_account_id>:policy/passrolepermission --user-name <user_name>
109156
```
110157

111-
#### 4. Create a role alias:
158+
#### 4. Create a role alias
159+
160+
Now that you have configured the IAM role, you will create a role alias with AWS IoT.
161+
You must provide the following pieces of information when creating a role alias:
162+
163+
RoleAlias: This is the primary key of the role alias data model and hence a mandatory
164+
attribute. It is a string; the minimum length is 1 character, and the maximum length is
165+
128 characters.
112166

113-
Now that you have configured the IAM role, you will create a role alias with AWS IoT. You must provide the following pieces of information when creating a role alias:
167+
RoleArn: This is the
168+
[Amazon Resource Name (ARN)](https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html)
169+
of the IAM role you have created. This is also a mandatory attribute.
114170

115-
RoleAlias: This is the primary key of the role alias data model and hence a mandatory attribute. It is a string; the minimum length is 1 character, and the maximum length is 128 characters.
171+
CredentialDurationSeconds: This is an optional attribute specifying the validity
172+
(in seconds) of the security token. The minimum value is 900 seconds (15 minutes),
173+
and the maximum value is 43,200 seconds (12 hours); the default value is 3,600 seconds,
174+
if not specified.
116175

117-
RoleArn: This is the [Amazon Resource Name (ARN)](https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html) of the IAM role you have created. This is also a mandatory attribute.
176+
**Note**: The credentialDurationSeconds value must be less than or equal to the
177+
maximum session duration of the IAM role that the role alias references,
178+
otherwise the request will be rejected by the credentials provider.
118179

119-
CredentialDurationSeconds: This is an optional attribute specifying the validity (in seconds) of the security token. The minimum value is 900 seconds (15 minutes), and the maximum value is 3,600 seconds (60 minutes); the default value is 3,600 seconds, if not specified.
180+
Run the following command in the AWS CLI to create a role alias. Use the credentials of
181+
the user to whom you have given the iam:PassRole permission.
120182

121-
Run the following command in the AWS CLI to create a role alias. Use the credentials of the user to whom you have given the iam:PassRole permission.
122183
```sh
123184
aws iot create-role-alias --role-alias name-s3-access-role-alias --role-arn arn:aws:iam::<your_aws_account_id>:role/s3-access-role --credential-duration-seconds 3600
124185
```
125186

126-
#### 5. Attach a policy:
187+
#### 5. Attach a policy
188+
127189
You created and registered a certificate with AWS IoT earlier for successful authentication of your device. Now, you need to create and attach a policy to the certificate to authorize the request for the security token.
128-
```
190+
191+
```json
129192
{
130193
"Version": "2012-10-17",
131194
"Statement": [
@@ -137,65 +200,50 @@ You created and registered a certificate with AWS IoT earlier for successful aut
137200
]
138201
}
139202
```
203+
140204
Run the following command in the AWS CLI to create the policy in your AWS IoT database.
205+
141206
```sh
142207
aws iot create-policy --policy-name Thing_Policy_Name --policy-document file://thingpolicy.json
143208
```
209+
144210
Use the following command to attach the policy with the certificate you registered earlier.
211+
145212
```sh
146213
aws iot attach-policy --policy-name Thing_Policy_Name --target <certificate-arn>
147214
```
148215

149-
#### 6. Request a security token:
150-
151-
Make an HTTPS request to the credentials provider to fetch a security token. You have to supply the following information:
216+
#### 6. Obtain the Credentials Provider Endpoint
152217

153-
Certificate and key pair: Because this is an HTTP request over TLS mutual authentication, you have to provide the certificate and the corresponding key pair to your client while making the request. Use the same certificate and key pair that you used during certificate registration with AWS IoT.
154-
155-
RoleAlias: Provide the role alias (in this example, Thermostat-dynamodb-access-role-alias) to be assumed in the request.
156-
157-
ThingName: Provide the thing name that you created earlier in the AWS IoT thing registry database. This is passed as a header with the name, x-amzn-iot-thingname. Note that the thing name is mandatory only if you have thing attributes as policy variables in AWS IoT or IAM policies.
158-
159-
Run the following command in the AWS CLI to obtain your AWS account-specific endpoint for the credentials provider. See the [DescribeEndpoint API documentation](https://docs.aws.amazon.com/iot/latest/apireference/API_DescribeEndpoint.html) for further details.
218+
Run the following command in the AWS CLI to obtain your AWS account-specific
219+
endpoint for the credentials provider. See the
220+
[DescribeEndpoint API documentation](https://docs.aws.amazon.com/iot/latest/apireference/API_DescribeEndpoint.html)
221+
for further details.
160222

161223
```sh
162224
aws iot describe-endpoint --endpoint-type iot:CredentialProvider
163225
```
226+
164227
The following is sample output of the describe-endpoint command. It contains the endpointAddress.
165-
```
228+
229+
```json
166230
{
167231
"endpointAddress": "<your_aws_account_specific_prefix>.credentials.iot.us-east-1.amazonaws.com"
168232
}
169233
```
170234

171-
#### 7. Copy and paste the output to `demo_config.h` for macros `democonfigIOT_CREDENTIAL_PROVIDER_ENDPOINT`.
235+
Next, copy this endpoint to the macro below in `demo_config.h`.
236+
172237
```c
173238
#define democonfigIOT_CREDENTIAL_PROVIDER_ENDPOINT "<your_aws_account_specific_prefix>.credentials.iot.us-east-1.amazonaws.com"
174-
175-
#define CLIENT_CERT_PATH "path of the client certificate downloaded when setting up the device certificate in AWS IoT Account Setup"
176-
177-
#define CLIENT_PRIVATE_KEY_PATH "path of the private key downloaded when setting up the device certificate in AWS IoT Account Setup"
178239
```
179240

180-
#### 8. After the following the above steps, configure the below macros in `demo_config.h`.
241+
#### 7. After the following the above steps, configure the below macros in `demo_config.h`
242+
181243
```c
182244
#define democonfigIOT_THING_NAME "Name of IOT Thing that you provided in STEP 1"
183245
#define democonfigIOT_CREDENTIAL_PROVIDER_ROLE "Name of ROLE ALIAS that you provided in STEP 4"
184246
#define democonfigS3_BUCKET_NAME "Name of Bucket that contains the object that needs to be downloaded"
185247
#define democonfigS3_BUCKET_REGION "Region where Bucket is located"
186248
#define democonfigS3_OBJECT_NAME "Name of object that needs to be downloaded from AWS S3"
187249
```
188-
189-
### Parameters
190-
191-
#### device_thing_name
192-
The name of the AWS IoT thing for your device registered with AWS IoT core.
193-
194-
#### thing_name-s3-access-role-alias
195-
The name for the role alias for S3.
196-
197-
#### Thing_Policy_Name
198-
The name of the policy attached to the device certificate in [step 5](#5-attach-a-policy).
199-
200-
#### BUCKET_NAME
201-
The name of the S3 bucket from which the demo will download.

FreeRTOS-Plus/Demo/coreHTTP_Windows_Simulator/HTTP_S3_Download/demo_config.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,7 @@ extern void vLoggingPrintf( const char * pcFormatString,
7979
/**
8080
* @brief Server's root CA certificate for TLS authentication with S3.
8181
*
82-
* The Baltimore Cybertrust root CA certificate is often used for authentication
83-
* with S3. It can be found at:
84-
* https://baltimore-cybertrust-root.chain-demos.digicert.com/info/index.html.
85-
*
86-
* S3 has started migrating certificates to Amazon Trust Services. If
87-
* authentication errors persist, re-attempt the connection with an Amazon root
88-
* CA certificate: https://www.amazontrust.com/repository.
82+
* The CA can be found at https://www.amazontrust.com/repository.
8983
*
9084
* @note This certificate should be PEM-encoded.
9185
*

FreeRTOS-Plus/Demo/coreHTTP_Windows_Simulator/HTTP_S3_Download_Multithreaded/demo_config.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,7 @@ extern void vLoggingPrintf( const char * pcFormatString,
7979
/**
8080
* @brief Server's root CA certificate for TLS authentication with S3.
8181
*
82-
* The Baltimore Cybertrust root CA certificate is often used for authentication
83-
* with S3. It can be found at:
84-
* https://baltimore-cybertrust-root.chain-demos.digicert.com/info/index.html.
85-
*
86-
* S3 has started migrating certificates to Amazon Trust Services. If
87-
* authentication errors persist, re-attempt the connection with an Amazon root
88-
* CA certificate: https://www.amazontrust.com/repository.
82+
* The CA can be found at https://www.amazontrust.com/repository.
8983
*
9084
* @note This certificate should be PEM-encoded.
9185
*

FreeRTOS-Plus/Demo/coreHTTP_Windows_Simulator/HTTP_S3_Upload/demo_config.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,7 @@ extern void vLoggingPrintf( const char * pcFormatString,
7979
/**
8080
* @brief Server's root CA certificate for TLS authentication with S3.
8181
*
82-
* The Baltimore Cybertrust root CA certificate is often used for authentication
83-
* with S3. It can be found at:
84-
* https://baltimore-cybertrust-root.chain-demos.digicert.com/info/index.html.
85-
*
86-
* S3 has started migrating certificates to Amazon Trust Services. If
87-
* authentication errors persist, re-attempt the connection with an Amazon root
88-
* CA certificate: https://www.amazontrust.com/repository.
82+
* The CA can be found at https://www.amazontrust.com/repository.
8983
*
9084
* @note This certificate should be PEM-encoded.
9185
*

0 commit comments

Comments
 (0)