Coder Social home page Coder Social logo

microsoft / vmss-distribute-unique-certificates Goto Github PK

View Code? Open in Web Editor NEW
6.0 25.0 6.0 12.69 MB

Example Python / C# project that generates a unique certificate per Linux VM in a VM Scale Set and stores certs in KeyVault.

License: MIT License

Python 24.38% Shell 0.47% C# 49.58% HCL 25.56%

vmss-distribute-unique-certificates's Introduction

Unique VM Certificate Provisioning

Introduction

A Microsoft customer is implementing IPSec networking between all the VMs in a deployment. This project prepares the VMs in an Azure VM scale set for IPSec by installing signed digital certificates on each VM.

The scale set is defined and deployed via a Terraform template. The template defines a custom script extension that downloads and runs the necessary scripts to each VM. The script files are hosted as blobs in Azure Storage.

Certificates may be retrieved using one of two methods:

  • Pre-created certificates are securely stored in Key Vault. Access to Key Vault is secured via Managed Service Identity (MSI).
  • A certificate service creates certificates on demand. (Certificate signing can be delegated to an intermediate certificate authority (CA)).

Components

  • Python script that uploads the scripts to Azure
  • Docker container to generate test certificates
  • Docker container to test script download
  • A certificate generation service to generate signed certificates on demand. (Written in .NET Core so that it runs on Windows and Linux.)
  • Terraform template that provides the following:
    • Deploys the VM scale set
    • Specifies a custom script extension that downloads and execute the scripts on first boot
    • Configures MSI on the VM scale set. (Note: MSI for scale sets is not yet in the official terraform-azurerm repo. A binary version of terraform-provider-azurerm is included for use until the capability is more generally supported).
    • Creates a Key Vault access policy that gives each VM in the scale set permission to authenticate to Key Vault using MSI and retreive its certficate.

Prerequisites

Config Setup

Config is located in ~/build/config.py. Config values must be updated with your Azure subscription information before building deploying the project.

Azure subscription config

  1. Create a new [Azure Service Principal] a. Go to Active Directory --> App Registrationsb. b. Follow the "Create an Azure Active Directory application" on the second half of the following web page: (https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal)
  2. Create a new Azure KeyVault a. Add the Service Principal created in step 1 to the Key Vault's access policies
  3. Open ~/scripts/config.py in an editor
  4. Replace values of the config properties with the SPN APP ID and key secret you created above

Storage account config

  1. Create a new Azure storage account
  2. Create a new SAS token for access to the storage account
  3. Open ~/build/config.py in an editor
  4. Replace values of storage account config properties with your storage account

Copy scripts to storage account

Create an archive (.tar) file containing the scripts and upload it to Azure. Also uploads a bootstrap.sh script that is executed on first launch.

cd <root>
python ./build/build.py

Terraform config

Update the variables.tf file with configuration info from your Azure subscription.

Build and Deploy Docker images to test the solution

  1. Open a terminal / console
cd <root>
  1. Build the docker image
docker-compose build
  1. Update ~/scripts/vm-names.json with VM names you're going to provision

  2. Create root\intermediate CAs & certs for all your VMs and upload them to Key Vault.

docker-compose up generator
  1. Test that the secrets can be accessed via the VM scripts
docker-compose up worker
  1. Initialize Terraform
cd terraform
terraform init
  1. Deploy VMSS cluster with 5 VMs. They download scripts from blob storage & scripts will download certs from KV (pre-provisioned)
terraform apply
  1. Debugging may require that you re-deploy the Azure infrastructure. You can do so using the following Terraform command:
terraform destroy

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

vmss-distribute-unique-certificates's People

Contributors

aaron-schnieder avatar day-jeff avatar logachev avatar microsoftopensource avatar msftgits avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.