Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 13, 2025

Overview

This PR implements automatic certificate renewal functionality for the TRE certificate shared service, addressing the need for hands-off certificate management in production environments. The feature uses Azure Logic Apps to monitor certificate expiry and automatically trigger renewals before certificates expire.

Problem Statement

Previously, TRE administrators had to manually monitor certificate expiry dates and trigger renewals through the API or UI. This created operational overhead and risk of service disruption if certificates expired unexpectedly. The manual process was particularly challenging for:

  • Main TRE web and API certificates that are critical for system access
  • Nexus service certificates required for package repository functionality
  • Any other certificates managed by the certificate service across multiple environments

Solution

The implementation adds three new configurable parameters to the certificate service template:

  • enable_auto_renewal (boolean, default: false): Master toggle for auto-renewal functionality
  • renewal_threshold_days (integer, 1-60, default: 30): Days before expiry to trigger renewal
  • renewal_schedule_cron (string, default: "0 2 * * 0"): Schedule for checking certificate expiry

When enabled, the system deploys an Azure Logic App that:

  1. Monitors: Periodically queries Key Vault for certificate expiry dates using managed identity
  2. Evaluates: Compares expiry dates against the configured threshold
  3. Acts: Automatically calls the existing TRE API renewal endpoint when renewal is needed
  4. Logs: Records all activities for monitoring and audit purposes

Key Features

Secure Architecture

  • Uses managed identity with least-privilege access (Key Vault Certificates Officer + scoped Contributor)
  • No additional credentials or secrets to manage
  • Leverages existing Let's Encrypt integration and renewal logic

Flexible Configuration

  • All parameters are updateable without redeployment
  • Configurable schedule supports various operational requirements
  • Conditional deployment - resources only created when auto-renewal is enabled

Production Ready

  • Comprehensive error handling and validation
  • Full backward compatibility (feature disabled by default)
  • Clear upgrade path for existing certificate services
  • Extensive documentation with troubleshooting guide

Technical Details

Infrastructure Components

  • Azure Logic App: Handles scheduling and workflow execution
  • ARM Template: Defines complete workflow with certificate checking and API integration
  • Managed Identity: Provides secure access to Key Vault and TRE API
  • Role Assignments: Minimal required permissions for Key Vault and API operations

Integration Points

  • Extends existing certificate service template schema with proper validation
  • Integrates with current /shared-services/{id}/invoke-action?action=renew API endpoint
  • Maintains compatibility with existing manual renewal processes
  • Updates Porter bundle to version 0.8.0 with full parameter support across all actions

Testing

The implementation includes comprehensive testing coverage:

  • JSON schema validation for all parameter types and constraints
  • End-to-end deployment flow simulation from API to infrastructure
  • Terraform syntax and ARM template structure validation
  • Porter bundle parameter handling across install/upgrade/uninstall actions
  • Integration scenarios covering all supported certificate types

Documentation

Added complete documentation including:

  • Auto-renewal guide: Configuration, deployment, and usage instructions
  • Updated Nexus documentation: Integration with auto-renewal for Nexus certificates
  • Security considerations: Permissions, network access, and best practices
  • Troubleshooting guide: Common issues, monitoring, and manual fallback procedures
  • Upgrade instructions: How to enable auto-renewal on existing certificate services

Example Usage

Deploy a certificate with auto-renewal enabled:

{
  "templateName": "tre-shared-service-certs",
  "properties": {
    "display_name": "Nexus Certificate with Auto-renewal",
    "domain_prefix": "nexus",
    "cert_name": "nexus-ssl", 
    "enable_auto_renewal": true,
    "renewal_threshold_days": 30,
    "renewal_schedule_cron": "0 2 * * 0"
  }
}

The system will automatically check the nexus-ssl certificate every Sunday at 2 AM and trigger renewal when it has 30 or fewer days until expiry.

Backward Compatibility

This change is fully backward compatible:

  • Auto-renewal is disabled by default on new deployments
  • Existing certificate services continue to work unchanged
  • Manual renewal processes remain available as fallback options
  • No breaking changes to existing APIs or templates

Migration Path

Existing certificate services can enable auto-renewal by upgrading to version 0.8.0 and updating their configuration to include the new auto-renewal parameters. The upgrade process maintains existing certificates and settings while adding the new automation capability.

Original prompt

This section details on the original issue you should resolve

<issue_title>Auto-renew Certs</issue_title>
<issue_description>## Description

As a TRE Administrator I want to be able to tell the cert servise to auto-renew the certs that are used for the main TRE webpage/api and also for nexus. This would also be ideal if we can expand the function of the cert servise to allow things like certs for internal resorcese.

Acceptance criteria

  • Abilty to enable Auto-renew for main tre web and api certs
  • Abilty to enable Auto-renew for nexus servise.
  • Abilty to enable Auto-renew for any other certs provided by the cert servise.
    </issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #4701


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Add auto-renew capability for certs Add certificate auto-renewal capability to TRE certificate shared service Oct 13, 2025
Copilot AI requested a review from james-annages October 13, 2025 12:38
Copilot finished work on behalf of james-annages October 13, 2025 12:38
@github-actions
Copy link

github-actions bot commented Oct 28, 2025

Unit Test Results

0 tests   0 ✅  0s ⏱️
0 suites  0 💤
0 files    0 ❌

Results for commit 30eeab9.

♻️ This comment has been updated with latest results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto-renew Certs

2 participants