X509CertificatePem

class aws_rfdk.X509CertificatePem(scope, id, *, subject, encryption_key=None, signing_certificate=None, valid_for=None)

Bases: Construct

architecture diagram

A Construct that uses a Lambda to generate an X.509 certificate and then saves the certificate’s components into Secrets. On an update, if any properties of the construct are changed, then a new certificate will be generated. When the Stack is destroyed or the Construct is removed, the Secrets will all be deleted. An X.509 certificate is comprised of the certificate, a certificate chain with the chain of signing certificates (if any), and a private key that is password protected by a randomly generated passphrase.

Cost: The cost of four AWS SecretsManager Secrets in the deployed region. The other resources created by this construct have negligible ongoing costs.

architecture diagram

Resources Deployed

  • DynamoDB Table - Used for tracking resources created by the Custom Resource.

  • Secrets - 4 in total, for the certificate, it’s private key, the passphrase to the key, and the cert chain.

  • Lambda Function, with role - Used to create/update/delete the Custom Resource

Security Considerations

  • The AWS Lambda that is deployed through this construct will be created from a deployment package that is uploaded to your CDK bootstrap bucket during deployment. You must limit write access to your CDK bootstrap bucket to prevent an attacker from modifying the actions performed by this Lambda. We strongly recommend that you either enable Amazon S3 server access logging on your CDK bootstrap bucket, or enable AWS CloudTrail on your account to assist in post-incident analysis of compromised production environments.

  • Access to the AWS SecretsManager Secrets that are created by this construct should be tightly restricted to only the principal(s) that require access.

Parameters:
  • scope (Construct) –

  • id (str) –

  • subject (Union[DistinguishedName, Dict[str, Any]]) – The subject, or identity, for the generated certificate.

  • encryption_key (Optional[IKey]) – If provided, then this KMS is used to secure the cert, key, and passphrase Secrets created by the construct. [disable-awslint:ref-via-interface] Default: : Uses the account’s default CMK (the one named aws/secretsmanager). If a AWS KMS CMK with that name doesn’t yet exist, then Secrets Manager creates it for you automatically the first time it needs to encrypt a version’s SecretString or SecretBinary fields.

  • signing_certificate (Optional[X509CertificatePem]) – If provided, then use this certificate to sign the generated certificate forming a chain of trust. Default: : None. The generated certificate will be self-signed

  • valid_for (Union[int, float, None]) – The number of days that the generated certificate will be valid for. Default: 1095 days (3 years)

Methods

grant_cert_read(grantee)

Grant read permissions for the certificate.

Parameters:

grantee (IGrantable) –

Return type:

Grant

grant_full_read(grantee)

Grant read permissions for the certificate, key, and passphrase.

Parameters:

grantee (IGrantable) –

Return type:

Grant

to_string()

Returns a string representation of this construct.

Return type:

str

Attributes

cert

//en.wikipedia.org/wiki/Privacy-Enhanced_MailPEM format}. The text of the chain is stored in the ‘SecretString’ of the given secret. To extract the public certificate simply copy the contents of the SecretString to a file.

Type:

The public certificate chain for this X.509 Certificate encoded in {@link https

cert_chain

A Secret that contains the chain of Certificates used to sign this Certificate.

key

//en.wikipedia.org/wiki/Privacy-Enhanced_MailPEM format}. The text of the key is stored in the ‘SecretString’ of the given secret. To extract the public certificate simply copy the contents of the SecretString to a file.

Note that the private key is encrypted. The passphrase is stored in the the passphrase Secret.

If you need to decrypt the private key into an unencrypted form, then you can: 0. Caution. Decrypting a private key adds a security risk by making it easier to obtain your private key.

  1. Copy the contents of the Secret to a file called ‘encrypted.key’

  2. Run: openssl rsa -in encrypted.key -out decrypted.key

  3. Enter the passphrase at the prompt

Type:

The private key for this X509Certificate encoded in {@link https

node

The tree node.

passphrase

The encryption passphrase for the private key is in the ‘SecretString’ of this secret.

Static Methods

classmethod is_construct(x)

Checks if x is a construct.

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters:

x (Any) – Any object.

Return type:

bool

Returns:

true if x is an object created from a class which extends Construct.