View a markdown version of this page

证书策略示例 - Amazon IoT Core
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)。

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

证书策略示例

对于在中注册的设备 Amazon IoT Core 注册表,以下策略授予连接权限 Amazon IoT Core 使用与事物名称匹配的客户端 ID,并发布到名称等于的主题 certificateId 设备用于自我验证的证书中:

{ "Version":"2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "iot:Publish" ], "Resource": ["arn:aws:iot:us-east-1:123456789012:topic/${iot:CertificateId}"] }, { "Effect": "Allow", "Action": [ "iot:Connect" ], "Resource": ["arn:aws:iot:us-east-1:123456789012:client/${iot:Connection.Thing.ThingName}"] } ] }

对于未注册的设备 Amazon IoT Core 注册表,以下策略授予连接权限 Amazon IoT Core 使用客户端 ID, client1, client2,以及 client3 并发布到名称等于 certificateId 设备用于自我验证的证书中:

{ "Version":"2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "iot:Publish" ], "Resource": ["arn:aws:iot:us-east-1:123456789012:topic/${iot:CertificateId}"] }, { "Effect": "Allow", "Action": [ "iot:Connect" ], "Resource": [ "arn:aws:iot:us-east-1:123456789012:client/client1", "arn:aws:iot:us-east-1:123456789012:client/client2", "arn:aws:iot:us-east-1:123456789012:client/client3" ] } ] }

对于在中注册的设备 Amazon IoT Core 注册表,以下策略授予连接权限 Amazon IoT Core 使用与事物名称匹配的客户端 ID,并发布到名称等于主题的主题 CommonName 设备用于自我验证的证书字段:

{ "Version":"2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "iot:Publish" ], "Resource": ["arn:aws:iot:us-east-1:123456789012:topic/${iot:Certificate.Subject.CommonName}"] }, { "Effect": "Allow", "Action": [ "iot:Connect" ], "Resource": ["arn:aws:iot:us-east-1:123456789012:client/${iot:Connection.Thing.ThingName}"] } ] }
注意

在此示例中,证书的使用者公用名用作主题标识符,并假设使用者公用名对于每个已注册的证书都是唯一的。如果证书在多个设备之间共享,则共享此证书的所有设备的使用者公用名将相同,因而允许从多个设备向同一主题发布权限(不推荐)。

对于未在中注册的设备 Amazon IoT Core 注册表,以下策略授予连接权限 Amazon IoT Core 使用客户端 ID, client1, client2,以及 client3 并发布到名称等于该主题的主题上 CommonName 设备用于自我验证的证书字段:

{ "Version":"2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "iot:Publish" ], "Resource": ["arn:aws:iot:us-east-1:123456789012:topic/${iot:Certificate.Subject.CommonName}"] }, { "Effect": "Allow", "Action": [ "iot:Connect" ], "Resource": [ "arn:aws:iot:us-east-1:123456789012:client/client1", "arn:aws:iot:us-east-1:123456789012:client/client2", "arn:aws:iot:us-east-1:123456789012:client/client3" ] } ] }
注意

在此示例中,证书的使用者公用名用作主题标识符,并假设使用者公用名对于每个已注册的证书都是唯一的。如果证书在多个设备之间共享,则共享此证书的所有设备的使用者公用名将相同,因而允许从多个设备向同一主题发布权限(不推荐)。

对于在中注册的设备 Amazon IoT Core 注册表,以下策略授予连接权限 Amazon IoT Core 使用与事物名称匹配的客户端 ID,并发布到名称前缀为的主题 admin/ 当用于对设备进行身份验证的证书有其时 Subject.CommonName.2 字段设置为 Administrator:

{ "Version":"2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "iot:Connect" ], "Resource": ["arn:aws:iot:us-east-1:123456789012:client/${iot:Connection.Thing.ThingName}"] }, { "Effect": "Allow", "Action": [ "iot:Publish" ], "Resource": ["arn:aws:iot:us-east-1:123456789012:topic/admin/*"], "Condition": { "StringEquals": { "iot:Certificate.Subject.CommonName.2": "Administrator" } } } ] }

对于未在中注册的设备 Amazon IoT Core 注册表,以下策略授予连接权限 Amazon IoT Core 使用客户端 ID client1, client2,以及 client3 并发布到名称前缀为的主题 admin/ 当用于对设备进行身份验证的证书有其时 Subject.CommonName.2 字段设置为 Administrator:

{ "Version":"2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "iot:Connect" ], "Resource": [ "arn:aws:iot:us-east-1:123456789012:client/client1", "arn:aws:iot:us-east-1:123456789012:client/client2", "arn:aws:iot:us-east-1:123456789012:client/client3" ] }, { "Effect": "Allow", "Action": [ "iot:Publish" ], "Resource": ["arn:aws:iot:us-east-1:123456789012:topic/admin/*"], "Condition": { "StringEquals": { "iot:Certificate.Subject.CommonName.2": "Administrator" } } } ] }

对于在中注册的设备 Amazon IoT Core 注册表,以下策略允许设备使用其事物名称发布包含以下内容的特定主题 admin/ 其次是 ThingName 当用于对设备进行身份验证的证书有其中的任何一个时 Subject.CommonName 字段设置为 Administrator:

{ "Version":"2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "iot:Connect" ], "Resource": ["arn:aws:iot:us-east-1:123456789012:client/${iot:Connection.Thing.ThingName}"] }, { "Effect": "Allow", "Action": [ "iot:Publish" ], "Resource": ["arn:aws:iot:us-east-1:123456789012:topic/admin/${iot:Connection.Thing.ThingName}"], "Condition": { "ForAnyValue:StringEquals": { "iot:Certificate.Subject.CommonName.List": "Administrator" } } } ] }

对于未在中注册的设备 Amazon IoT Core 注册表,以下策略授予连接权限 Amazon IoT Core 使用客户端 ID client1, client2,以及 client3 并发布到该主题 admin 当用于对设备进行身份验证的证书有其中的任何一个时 Subject.CommonName 字段设置为 Administrator:

{ "Version":"2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "iot:Connect" ], "Resource": [ "arn:aws:iot:us-east-1:123456789012:client/client1", "arn:aws:iot:us-east-1:123456789012:client/client2", "arn:aws:iot:us-east-1:123456789012:client/client3" ] }, { "Effect": "Allow", "Action": [ "iot:Publish" ], "Resource": ["arn:aws:iot:us-east-1:123456789012:topic/admin"], "Condition": { "ForAnyValue:StringEquals": { "iot:Certificate.Subject.CommonName.List": "Administrator" } } } ] }