Lab 9: Event Handlers and Automation
Event Handlers and Automation Lab Activity
Event handlers are a core extensibility point for the Keyfactor platform. An event handler is available for each Alert type and will be executed for each certificate found during alert processing. For example, a pending request alert that finds 10 outstanding certificate requests. Each request will generate an event that gets processed by the handler and there are three types of handlers available:
Logger
The logger handler will enable writing output to the Windows Event Log for each certificate or request found by the alertPowerShell
The PowerShell handler enables the execution of a PowerShell script for each certificate or request found by the alertRenewal
The Renewal handler is a special handler for the Expiration alert type. This handler will renew the expiring certificate using the Keyfactor API and if the certificate is part of a certificate store, Keyfactor will generate the required job to replace the expiring certificate.
Automated Renewal Permissions
In preparation for our automation lab, we need to make sure our Keyfactor Service account has the appropriate API permissions to renew a certificate and create the associated jobs to replace the expiring certificate.
Navigate to the Gear Icon > Security Roles & Claims.
Click Add in the ribbon to create a new Security Role with the following values:
Configuration | Value |
Name | Reporting API Access |
Description | Default Role For API use |
Email Address | Leave blank |
Permission Set | Global |
On the Global Permissions tab, enable the following permissions:
Permission Header | Permission Object |
Certificates | PFX |
Certificate Stores | Read, Schedule |
Collections | Read |
Portal | Read |
Click the Claims tab.
On the Claims tab, add the kftrain\kf_service account to the new role.
Click Include and Close.
Click Save.
Note: By creating this role and adding the service account, we've enabled the Orchestrator service access to the API. This access will be used later to process an automated renewal based on an expiration alert.
Event Handler Configuration
Short-Lived Template
In order to configure our event handlers, we will need to make sure we have certificates and alerts to support our demo scenarios. In order to ensure we have some expiring certificates, let's duplicate the Web Server template and make it valid for 7 days.
Open the Lab Console on the Desktop.
Click the Certificate Templates folder
Right click the 2YearWebServer template and select right click Duplicate Template
Click the General tab and give it a new name (i.e. Web Server 7 Day).
Change the Validity Period to 7 days
Click Ok on the pop up message.
Click Ok to Save and Close the new template.
Expand the Certification Authority folder
Expand the KFTRAIN-LAB-CA object
Right Click the Certificate Templates folder
Choose New > Certificate Template to Issue
Select the new 7 day template and click Ok.
We have created a new template we can now use to issue certificates that expire quickly in order to test our Expiration Alerts. We still need to enable enrollment of this new template in Keyfactor. Take a minute to enable PFX enrollment for the new template in the Keyfactor Portal. (Note: Private Key Retention must be configured in order to use PFX Enrollment) After issuing some of the short lived certificates, send at least one to the Windows Certificate store we created earlier.
Expiration Alert Configuration
Now that we have some certificates that will expire in the next week, we can begin configuration of our expiration alerts. All expiration alerts are driven by a collection. Go ahead and create a new collection that contains all certificates that use our new template. Once that is done, follow the steps below to create a new Expiration Alert.
Navigate to Alerts > Expiration.
Click Add in the ribbon menu
Configure your alert with the following configuration:
Configuration | Value |
Certificate Collection | <<Your Collection for our Short Term Certificates>> |
Timeframe | 7 Days |
Display Name | Lab 9: 7 day Renewal |
Subject | Your certificate is about to expire |
Use Workflows | Off |
Message | Hi - A certificate with the following details is near expiration and will be renewed automatically. Subject: {cn} Thanks, Keyfactor |
Use Handler | Enable ExpirationRenewal. |
Recipients | renew@kftrain.lab |
Click Save.
Once the alert is saved, we can force the process to run by executing a test of the Expiration Alert. Otherwise, we could configure our daily execution time and wait. Let's run the test and see what happens.
Navigate to Alerts > Expiration
Select the Lab 9: 7 day Renewal alert
Click test in the ribbon menu.
Set the Start Date to yesterday
Set the End Date date to today
Enable Send Alerts
Click Generate
Note: Testing an expiration alert will execute the renewal and create the automation jobs associated with the certificate if it finds a certificate located in a store.