Schedule artifact version revocation for compliance
Over the lifecycle of an artifact, you may need to prevent access to it if it becomes outdated. In addition to immediately revoking insecure artifact versions, HCP Packer lets you schedule a future artifact revocation by setting a Time To Live (TTL). This strengthens your compliance posture by by preventing usage of outdated artifacts.
Note
Scheduled revocation is an HCP Packer Plus tier feature.
In this tutorial, you will schedule a revocation. In the process, you will learn the relationship between HCP Packer artifact channels and revoked versions, and how artifact revocation prevents downstream artifact consumers from referencing outdated artifacts.
Prerequisites
To complete this tutorial, you must have completed the HCP Packer Get Started tutorials. In the tutorials, you:
- Created a service principal with Contributor access to HCP.
- Set your client ID and secret as environment variables.
- Configured your AWS credentials as environment variables.
- Built an artifact and push its metadata to HCP Packer.
- Set up a channel named
production
for your bucket.
In addition, you will need:
- Terraform 1.2.0+ installed locally.
Schedule artifact version revocation
Assume that your company policy requires that artifacts expire after 30 days to ensure no one deploys a stale artifact. To enforce this policy, you can schedule a revocation date and time.
Go to the learn-packer-ubuntu
's Versions page. Schedule a revocation date for the first version by clicking on ... then Revoke version. Scheduled revocations, unlike immediate ones, can apply to versions assigned to artifact channels.
Select Revoke at a future date and enter the time for 5 minutes from your current time. The time is in UTC (current time in UTC). For example, if it is currently 10:00
, enter 10:05
.
Enter Learning about scheduling revocation
for the revocation reason, and click Revoke Version to revoke the version.
Under Revoke descendants choose No, only revoke v1. Under Rollback channels, choose No, do not rollback channel.
The dashboard now shows a scheduled revocation for the first version.
Open the first version by clicking on v1. HCP Packer displays the reason why this artifact was scheduled to be revoked.
Verify scheduled artifact version revocation
In the tf-channel
directory, generate a Terraform plan. Terraform will successfully create the plan.
The hcp_packer_version
and hcp_packer_artifact
Terraform data sources still retrieve information for revoked or scheduled to be revoked versions. However, the hcp_packer_artifact
data source's revoke_at
attribute is set to the revocation timestamp.
In main.tf
, update the EC2 instance to only create an instance if the artifact is not revoked.
The lifecycle precondition will succeed if revoke_at
is scheduled to the future or is null.
In outputs.tf
, add the following output to view the artifact's revocation time.
Wait until the five minute revocation time you configured earlier passes. HCP Packer will automatically revoke your version. Check the Versions dashboard to confirm HCP Packer revoked the first version.
Notice that even though the first version is revoked, the production
channel still references it.
Because the lifecycle custom precondition depends on timestamp()
which is unknown during a Terraform plan, the condition will be checked during the Terraform apply.
Apply your configuration. Since the production
channel references a revoked image, the image_revocation_date
output is set to to the revocation timestamp, the app_server
lifecycle precondition will fail, and Terraform will not create the EC2 instance.
If your Terraform configuration references a revoked artifact, contact your HCP Packer administrator to re-assign the channel to a valid artifact version.
Restore revoked version
If you accidentally revoke the wrong version, you can restore the version so your team can use its artifacts again.
In the HCP Packer UI, navigate to the first version. Then, click Manage and Restore version.
Click Restore version to restore your version.
Verify restoration
In the tf-channels
directory, apply your configuration. Since the version is restored, Terraform successfully creates the EC2 instance.
To clean up your provisioned infrastructure, run terraform destroy
and respond yes
to the prompt to confirm the operation.
Next steps
In this tutorial, you used scheduled a version revocation and restored a revoked version. In the process, you reviewed how scheduled revocations strengthen your compliance posture by setting expiration dates on versions, preventing users from using outdated artifacts. Though you can schedule a revocation for a version assigned to an artifact channel, when the revocation date passes, the channel will reference a revoked version. Any attempts to query a channel with a revoked version will fail.
By integrating both immediate and scheduled version revocation in your workflows, you can ensure your organization uses secure and compliant artifacts.
For more information on topics covered in this tutorial, check out the following resources:
- Complete the Immediately Revoke Insecure Artifact Versions tutorial to learn how to prevent users from referencing insecure artifacts.
- Read more about revoking artifact versions in the HCP Packer documentation.
- Visit the Terraform
hcp
provider for a full list of arguments and attributes for thehcp_packer_version
andhcp_packer_artifact
data resources. - Complete the Set Up HCP Terraform Run Task for HCP Packer tutorial to learn how to ensure your Terraform configuration uses compliant artifacts.