Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Using X.509 certificate policy variables

Focus mode
Using X.509 certificate policy variables - AWS IoT Core

This topic provides details of how to use certificate policy variables. X.509 certificate policy variables are essential when you create AWS IoT Core policies that give permissions based on X.509 certificate attributes. If your X.509 certificate doesn't include a particular certificate attribute but the corresponding certificate policy variable is used in your policy document, the policy evaluation might lead to unexpected behavior. This is because the missing policy variable doesn't get evaluated in the policy statement.

X.509 certificate example

A typical X.509 certificate might appear as follows. This example certificate includes certificate attributes. During the evaluation of AWS IoT Core policies, the following certificate attributes will be populated as certificate policy variables: Serial Number, Issuer, Subject, X509v3 Issuer Alternative Name, and X509v3 Subject Alternative Name.

Certificate: Data: Version: 3 (0x2) Serial Number: 92:12:85:cb:b7:a5:e0:86 Signature Algorithm: sha256WithRSAEncryption Issuer: C=US, O=IoT Devices, OU=SmartHome, ST=WA, CN=IoT Devices Primary CA, GN=Primary CA1/initials=XY/dnQualifier=Example corp, SN=SmartHome/ title=CA1/pseudonym=Primary_CA/generationQualifier=2/serialNumber=987 Validity Not Before: Mar 26 03:25:40 2024 GMT Not After : Apr 28 03:25:40 2025 GMT Subject: C=US, O=IoT Devices, OU=LightBulb, ST=NY, CN=LightBulb Device Cert, GN=Bulb/initials=ZZ/dnQualifier=Bulb001, SN=Multi Color/title=RGB/pseudonym=RGB Device/generationQualifier=4/serialNumber=123 Subject Public Key Info: Public Key Algorithm: rsaEncryption RSA Public-Key: (2048 bit) Modulus: << REDACTED >> Exponent: 65537 (0x10001) X509v3 extensions: X509v3 Basic Constraints: CA:FALSE X509v3 Key Usage: Digital Signature, Non Repudiation, Key Encipherment X509v3 Subject Alternative Name: DNS:example.com, IP Address:1.2.3.4, URI:ResourceIdentifier001, email:device1@example.com, DirName:/C=US/O=IoT/OU=SmartHome/CN=LightBulbCert X509v3 Issuer Alternative Name: DNS:issuer.com, IP Address:5.6.7.8, URI:PrimarySignerCA, email:primary@issuer.com, DirName:/C=US/O=Issuer/OU=IoT Devices/CN=Primary Issuer CA Signature Algorithm: sha256WithRSAEncryption << REDACTED >>

Using certificate issuer attributes as certificate policy variables

The following table provides details of how certificate issuer attributes will be populated in an AWS IoT Core policy.

Issuer attributes to be populated in a policy
Certificate issuer attributes Certificate policy variables
  • C=US

  • O=IoT Devices

  • OU=SmartHome

  • ST=WA

  • CN=IoT Devices Primary CA

  • GN=Primary CA1

  • initials=XY

  • dnQualifier=Example corp

  • SN=SmartHome

  • title=CA1

  • pseudonym=Primary_CA

  • generationQualifier=2

  • serialNumber=987

  • iot:Certificate.Issuer.Country = US

  • iot:Certificate.Issuer.Organization = IoT Devices

  • iot:Certificate.Issuer.OrganizationalUnit = SmartHome

  • iot:Certificate.Issuer.State = WA

  • iot:Certificate.Issuer.CommonName = IoT Devices Primary CA

  • iot:Certificate.Issuer.GivenName = Primary CA1

  • iot:Certificate.Issuer.initials = XY

  • iot:Certificate.Issuer.DistinguishedNameQualifier = Example corp

  • iot:Certificate.Issuer.Surname = SmartHome

  • iot:Certificate.Issuer.Title = CA1

  • iot:Certificate.Issuer.Pseudonym = Primary_CA

  • iot:Certificate.Issuer.GenerationQualifier = 2

  • iot:Certificate.Issuer.SerialNumber = 987

Using certificate subject attributes as certificate policy variables

The following table provides details of how certificate subject attributes will be populated in an AWS IoT Core policy.

Subject attributes to be populated in a policy
Certificate subject attributes Certificate policy variables
  • C=US

  • O=IoT Devices

  • ST=NY

  • CN=LightBulb Device Cert

  • GN=Bulb

  • initials=ZZ

  • dnQualifier=Bulb001

  • SN=Multi Color

  • title=RGB

  • pseudonym=RGB Device

  • generationQualifier=4

  • serialNumber=123

  • iot:Certificate.Subject.Country = US

  • iot:Certificate.Subject.Organization = IoT Devices

  • iot:Certificate.Subject.State = NY

  • iot:Certificate.Subject.CommonName = LightBulb Device Cert

  • iot:Certificate.Subject.GivenName = Bulb

  • iot:Certificate.Subject.initials = ZZ

  • iot:Certificate.Subject.DistinguishedNameQualifier = Bulb001

  • iot:Certificate.Subject.Surname = Multi Color

  • iot:Certificate.Subject.Title = RGB

  • iot:Certificate.Subject.Pseudonym = RGB Device

  • iot:Certificate.Subject.GenerationQualifier = 4

  • iot:Certificate.Subject.SerialNumber = 123

Using certificate Issuer alternate name attributes as certificate policy variables

The following table provides details of how certificate issuer alternate name attributes will be populated in an AWS IoT Core policy.

Issuer alternate name attributes to be populated in a policy
X509v3 Issuer Alternative Name Attribute in a policy
  • DNS:issuer.com

  • IP Address:5.6.7.8

  • URI:PrimarySignerCA

  • email:primary@issuer.com

  • DirName:/C=US/O=Issuer/OU=IoT Devices/CN=Primary Issuer CA

  • iot:Certificate.Issuer.AlternativeName.DNSName = issuer.com

  • iot:Certificate.Issuer.AlternativeName.IPAddress = 5.6.7.8

  • iot:Certificate.Issuer.AlternativeName.UniformResourceIdentifier = PrimarySignerCA

  • iot:Certificate.Issuer.AlternativeName.RFC822Name = primary@issuer.com

  • iot:Certificate.Issuer.AlternativeName.DirectoryName = cn=Primary Issuer CA,ou=IoT Devices,o=Issuer,c=US

Using certificate subject alternate name attributes as certificate policy variables

The following table provides details of how certificate subject alternate name attributes will be populated in an AWS IoT Core policy.

Subject alternate name attributes to be populated in a policy
X509v3 Subject Alternative Name Attribute in a policy
  • DNS:example.com

  • IP Address:1.2.3.4

  • URI:ResourceIdentifier001

  • email:device1@example.com

  • DirName:/C=US/O=IoT/OU=SmartHome/CN=LightBulbCert

  • iot:Certificate.Subject.AlternativeName.DNSName = example.com

  • iot:Certificate.Subject.AlternativeName.IPAddress = 1.2.3.4

  • iot:Certificate.Subject.AlternativeName.UniformResourceIdentifier = ResourceIdentifier001

  • iot:Certificate.Subject.AlternativeName.RFC822Name = device1@example.com

  • iot:Certificate.Subject.AlternativeName.DirectoryName = cn=LightBulbCert,ou=SmartHome,o=IoT,c=US

Using other certificate attribute as a certificate policy variable

The following table provides details of how other certificate attributes will be populated in an AWS IoT Core policy.

Other attributes to be populated in a policy
Other certificate attribute Certificate policy variable

Serial Number: 92:12:85:cb:b7:a5:e0:86

iot:Certificate.SerialNumber = 10525622389124227206

X.509 Certificate policy variable limitations

The following limitations apply to X.509 certificate policy variables:

Missing policy variables

If your X.509 certificate doesn't include a particular certificate attribute but the corresponding certificate policy variable is used in your policy document, the policy evaluation might lead to unexpected behavior. This is because the missing policy variable doesn't get evaluated in the policy statement.

Certificate SerialNumber format

AWS IoT Core treats the certificate serial number as the string representation of a decimal integer. For example, if a policy only allows connections with Client ID matching the certificate serial number, the client ID must be the serial number in decimal format.

Wildcards

If wildcard characters are present in certificate attributes, the policy variable is not replaced by the certificate attribute value. This will leave the ${policy-variable} text in the policy document. This might cause authorization failure. The following wildcard characters can be used: *, $, +, ?, and #.

Array fields

Certificate attributes that contain arrays are limited to five items. Additional items are ignored.

String length

All string values are limited to 1024 characters. If a certificate attribute contains a string longer than 1024 characters, the policy variable is not replaced by the certificate attribute value. This will leave the ${policy-variable} in the policy document. This might cause authorization failure.

Special Characters

Any special character, such as ,, ", \, +, =, <, > and ; must be prefixed with a backslash (\) when used in a policy variable. For example, Amazon Web Services O=Amazon.com Inc. L=Seattle ST=Washington C=US becomes Amazon Web Service O\=Amazon.com Inc. L\=Seattle ST\=Washington C\=US.

Example policies using certificate policy variables

The following policy document allows connections with client ID that matches the certificate serial number and publishing to the topic that matches the pattern: ${iot:Certificate.Subject.Organization}/device-stats/${iot:ClientId}/*.

Important

If your X.509 certificate doesn't include a particular certificate attribute but the corresponding certificate policy variable is used in your policy document, the policy evaluation might lead to unexpected behavior. This is because the missing policy variable doesn't get evaluated in the policy statement. For example, if you attach the following policy document to a certificate that doesn't contain the iot:Certificate.Subject.Organization attribute, the iot:Certificate.Subject.Organization certificate policy variables won't be populated during the policy evaluation.

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "iot:Connect" ], "Resource": [ "arn:aws:iot:us-east-1:123456789012:client/${iot:Certificate.SerialNumber}" ] }, { "Effect": "Allow", "Action": [ "iot:Publish" ], "Resource": [ "arn:aws:iot:us-east-1:123456789012:topic/${iot:Certificate.Subject.Organization}/device-stats/${iot:ClientId}/*" ] } ] }

You can also use the Null condition operator to ensure that the certificate policy variables used in a policy are populated during policy evaluation. The following policy document allows iot:Connect with certificates only when the Certificate Serial Number and Certificate Subject Common name attributes are present.

All of the certificate policy variables have String values, so all of the String condition operators are supported.

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "iot:Connect" ], "Resource": [ "arn:aws:iot:us-east-1:123456789012:client/*" ], "Condition": { "Null": { "iot:Certificate.SerialNumber": "false", "iot:Certificate.Subject.CommonName": "false" } } } ] }
PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.