SlideShare a Scribd company logo
1 of 30
Copyright © 2020 HashiCorp
Using New Sentinel Features in
Terraform Cloud and Terraform
Enterprise
Roger Berlind
Technology Specialist
HashiCorp
Copyright © 2020 HashiCorp
▪ Sentinel in Terraform Cloud (TFC) and Terraform Enterprise (TFE)
▪ Two New Sentinel Features
– Sentinel Modules
– Terraform Sentinel v2 Imports
▪ The Evolution of Sentinel Policies
▪ Some Prototypical Third-Generation Sentinel Policies
▪ The Third-Generation Common Functions
▪ Testing and Using the Third Generation Sentinel Policies
▪ A Demo
Agenda
Copyright © 2020 HashiCorp
Sentinel in Terraform Cloud and
Terraform Enterprise
Copyright © 2020 HashiCorp
▪ HashiCorp's Sentinel is a framework for implementing governance
policies as code in the same way that Terraform implements
infrastructure as code.
▪ It includes its own language and is embedded in HashiCorp's
enterprise products.
▪ Using Sentinel ensures that your governance policies are actually
being checked rather than just being listed in a spreadsheet.
▪ It supports fine-grained policies that use conditional logic.
▪ It includes a CLI that allows you to test and run policies.
What is Sentinel?
Copyright © 2020 HashiCorp
Terraform Cloud and Terraform Enterprise
▪ A User Interface
▪ Workspace Management
▪ Team Management
▪ State Management
▪ Secure Variable Management
▪ Remote Runs and State
▪ VCS Integrations
▪ HTTP/JSON API
▪ Private Module Registry
▪ Configuration Editor
▪ Sentinel (policy as code)
▪ SSO via SAML Integration
▪ Audit Logging
Terraform Cloud (TFC) includes the following advanced functionality that
makes it easier for teams and organizations to use Terraform:
Customers can install Terraform Enterprise (TFE) servers to self-host
TFC in their own virtual private networks or in their data centers.
Copyright © 2020 HashiCorp
▪ Sentinel policies are checked between the standard plan and apply
steps of Terraform runs.
▪ Policies have different enforcement levels: advisory, soft-mandatory, and
hard-mandatory.
▪ Violations prevent runs from being applied unless a user with sufficient
authority overrides them.
▪ Sentinel policies can evaluate the attributes (arguments and exported
attributes) of existing and new resources and data sources based on
information from the current run:
– the plan, the configuration, the current state, and other run data
including cost estimates
▪ This ensures that resources comply with all policies before they are
provisioned.
Where is Sentinel Used in Terraform?
Copyright © 2020 HashiCorp
How Terraform Works Without Sentinel
VCS Terraform Infrastructureplan & apply
Copyright © 2020 HashiCorp
How Terraform Works With Sentinel
VCS Terraform
Cloud
Workspace
Infrastructureplan Sentinel
Policy
Checks
apply
If cost estimates are enabled, they run right after the plan.
Copyright © 2020 HashiCorp
All Policy Checks Passed
Copyright © 2020 HashiCorp
▪ HashiCorp customers are using Sentinel to implement governance
policies like the following in Terraform Cloud/Enterprise:
– Enforce security standards:
▪ Require all S3 buckets use the private ACL and be encrypted by KMS.
▪ Restrict which roles the AWS provider can assume.
▪ Blacklist/whitelist resources, data sources, providers, or provisioners.
– Avoid excessive costs:
▪ Limit the sizes of VMs and Kubernetes clusters in public clouds.
▪ Limit the monthly spend of each Terraform workspace.
– Enforce mandatory tags on resources provisioned by Terraform.
– Mandate that all modules come from a Private Module Registry.
– Enforce specific Terraform coding conventions.
How Customers are Using Sentinel in Terraform
Copyright © 2020 HashiCorp
Two New Sentinel
Features
Copyright © 2020 HashiCorp
▪ A Sentinel Module defines Sentinel functions and rules in a file that can
be used by Sentinel policies with a single import statement.
▪ This avoids the need to paste the functions into every policy that calls
them, improving the reusability of Sentinel functions.
▪ Sentinel modules are registered in Sentinel CLI configuration files and in
TFC/TFE policy set configuration files.
▪ The terraform-guides repository includes 5 "third-generation" modules:
– tfplan-functions, tfstate-functions, tfconfig-functions, tfrun-functions,
and aws-functions
▪ Each function is documented in a separate MD file.
▪ Note that these are NOT standard functions.
Sentinel Modules
Copyright © 2020 HashiCorp
▪ The new v2 versions of three Terraform Sentinel imports (tfplan,
tfstate, and tfconfig) are aligned more closely with native
Terraform 0.12 data structures.
▪ This makes the v2 imports easier to use than the v1 imports.
▪ Additionally, since resource instances are stored in a single flat
map that spans across all Terraform modules and resource types, it
is much easier to find all resources instances of a specific type or a
sub-collection of them.
▪ However, there is a catch:
– The v2 imports can only be used with Terraform 0.12.
New v2 Versions of the Terraform Sentinel Imports
Copyright © 2020 HashiCorp
▪ The tfplan/v2 gives data generated from Terraform plans.
– https://www.terraform.io/docs/cloud/sentinel/import/tfplan-v2.html
▪ The tfconfig/v2 import gives data about the Terraform configuration.
– https://www.terraform.io/docs/cloud/sentinel/import/tfconfig-v2.html
▪ The tfstate/v2 import gives data about the current state of a
workspace.
– https://www.terraform.io/docs/cloud/sentinel/import/tfstate-v2.html
▪ The tfrun import provides metadata for Terraform runs and their
workspaces as well as cost estimate data. (There is no v2 version of it.)
– https://www.terraform.io/docs/cloud/sentinel/import/tfrun.html
Sentinel Imports in Terraform
Copyright © 2020 HashiCorp
The Evolution of Sentinel Policies
Copyright © 2020 HashiCorp
▪ The first-generation policies were written in late 2018 and used the
original Terraform Sentinel v1 imports.
▪ They had several short-comings, including the following:
– Most of the policies did not print violation messages for resources
that violated them.
– They stopped evaluating conditions as soon as a single resource
instance violated them.
– They failed when resources that were being destroyed violated
conditions.
– Their use of default Sentinel output was overly verbose.
The First-Generation Policies
Copyright © 2020 HashiCorp
▪ The second-generation policies were written in 2019 and used the original
Terraform Sentinel v1 imports:
▪ They made the following improvements:
– They offloaded most processing from rules into some common
parameterized functions.
– Those common functions were written in a way that caused all violations
of all rules to be reported.
– They printed out the full address of each resource instance that did
violate a policy.
– By using a single main rule, they suppressed most of Sentinel’s default,
overly verbose output.
– They skipped resources that were being destroyed but not recreated.
The Second-Generation Policies
Copyright © 2020 HashiCorp
▪ The new third-generation policies were written in the spring of 2020 and
use the new Terraform Sentinel v2 imports and Sentinel modules.
▪ They have the following advantages:
– Their use of the v2 imports and the Sentinel filter expression makes it
easier to restrict policies to specific operations performed by Terraform.
– The common functions defined in Sentinel modules do not need to be
pasted into policies that use them.
– Most of the policies do not have any for loops of if/else conditionals. This
makes the policies easier to understand and copy.
– They can evaluate the value of any attribute of any resource or data
source, even those that are deeply nested.
▪ However, since they do use the v2 imports, they can only be used with
Terraform 0.12
The New Third-Generation Policies
Copyright © 2020 HashiCorp
Some Prototypical Third-
Generation Sentinel Policies
Copyright © 2020 HashiCorp
▪ I'll review four prototypical third-generation Sentinel policies in
order of increasing sophistication:
– restrict-ec2-instance-type.sentinel (AWS)
– restrict-vm-cpu-and-memory.sentinel (VMware)
– restrict-vm-disk-size.sentinel (VMware)
– restrict-publishers-of-current-vms.sentinel (Azure)
Some Prototypical Third-Generation Policies
Copyright © 2020 HashiCorp
The Third-Generation Common
Functions
Copyright © 2020 HashiCorp
▪ As mentioned earlier, there are third-generation Sentinel modules
with common functions for each of the Terraform Sentinel imports.
▪ The tfplan and tfstate modules have the following functions:
– Find functions that find resources, data sources, and blocks.
– Filter functions that filter collections of resources, data sources, or
blocks. These each return two maps: resources and messages.
– The evaluate_attribute function that can evaluate any attribute
of any resource, data source, or block, even if deeply nested.
– The to_string and print_violation functions that are used by the
other functions.
▪ There is also a Sentinel module with some AWS-specific functions.
The Third-Generation Common Functions
Copyright © 2020 HashiCorp
Testing and Using the Third-
Generation Sentinel Policies
Copyright © 2020 HashiCorp
▪ All the third-generation Sentinel policies have test cases and mocks
that support testing the policies with the Sentinel CLI
▪ Do the following:
– Download the Sentinel CLI from the Sentinel Downloads page.
– Unzip the zip file and place the sentinel binary in your path.
– Fork the terraform-guides repository and clone your fork to your
local machine.
– Navigate to any of the cloud directories (aws, azure, gcp, or
vmware) or to the cloud-agnostic directory.
– Run sentinel test to test all policies for that cloud.
– Run sentinel test -run=<partial_policy_name> -verbose to
test individual policies, using a string that partially matches name.
Testing Policies with the Sentinel CLI
Copyright © 2020 HashiCorp
{
"modules": {
"tfplan-functions": {
"path": "../../../common-functions/tfplan-functions/
tfplan-functions.sentinel"
}
},
"mock": {
"tfplan/v2": "mock-tfplan-pass.sentinel"
},
"test": {
"main": true
}
}
An Example Test Case that References a Module
Copyright © 2020 HashiCorp
▪ After successfully testing a policy with the CLI and possibly also on
TFC itself, you will want to deploy it to your TFC/TFE organizations.
▪ If you have not already added the policy to a policy set in your
organizations, do that at this time.
▪ Add the new policy to an existing policy set that is already applied
against desired workspaces, or create a new policy set for the
policy and apply that policy set to desired workspaces across your
organizations.
▪ Also add any parameters the policy requires to your policy set.
▪ And add references to any Sentinel Modules that policies in it use.
Deploying Policies in TFC or TFE
Copyright © 2020 HashiCorp
▪ Here is an example policy set:
module "tfplan-functions" {
source = "../common-functions/tfplan-functions/tfplan
-functions.sentinel"
}
policy "restrict-ec2-instance-type" {
source = "./restrict-ec2-instance-type.sentinel"
enforcement_level = "soft-mandatory"
}
Example Policy Set
Copyright © 2020 HashiCorp
Demo
Copyright © 2020 HashiCorp
▪ Here are some useful Links
▪ Documentation
– https://www.terraform.io/docs/cloud/sentinel/index.html
– https://www.terraform.io/docs/cloud/sentinel/manage-
policies.html
– https://docs.hashicorp.com/sentinel
▪ Other Resources:
– Blog for this webinar
– Sentinel in Terraform v2 Workshop (including hands-on Instruqt
track that teaches you how to write and test policies)
Some Useful Links
Thank you.
hello@hashicorp.comwww.hashicorp.com

More Related Content

What's hot

Apache Phoenix: Transforming HBase into a SQL Database
Apache Phoenix: Transforming HBase into a SQL DatabaseApache Phoenix: Transforming HBase into a SQL Database
Apache Phoenix: Transforming HBase into a SQL Database
DataWorks Summit
 

What's hot (20)

Terraform Enterprise: Clustering & cost estimation webinar
Terraform Enterprise: Clustering & cost estimation webinarTerraform Enterprise: Clustering & cost estimation webinar
Terraform Enterprise: Clustering & cost estimation webinar
 
Terraform -- Infrastructure as Code
Terraform -- Infrastructure as CodeTerraform -- Infrastructure as Code
Terraform -- Infrastructure as Code
 
Introduction to IAC and Terraform
Introduction to IAC and Terraform Introduction to IAC and Terraform
Introduction to IAC and Terraform
 
Terraform
TerraformTerraform
Terraform
 
Terraform on Azure
Terraform on AzureTerraform on Azure
Terraform on Azure
 
Introduce to Terraform
Introduce to TerraformIntroduce to Terraform
Introduce to Terraform
 
Terraform: Infrastructure as Code
Terraform: Infrastructure as CodeTerraform: Infrastructure as Code
Terraform: Infrastructure as Code
 
Terraform
TerraformTerraform
Terraform
 
Terraform
TerraformTerraform
Terraform
 
Metrics-Driven Performance Tuning for AWS Glue ETL Jobs (ANT332) - AWS re:Inv...
Metrics-Driven Performance Tuning for AWS Glue ETL Jobs (ANT332) - AWS re:Inv...Metrics-Driven Performance Tuning for AWS Glue ETL Jobs (ANT332) - AWS re:Inv...
Metrics-Driven Performance Tuning for AWS Glue ETL Jobs (ANT332) - AWS re:Inv...
 
Cloudera training: secure your Cloudera cluster
Cloudera training: secure your Cloudera clusterCloudera training: secure your Cloudera cluster
Cloudera training: secure your Cloudera cluster
 
Infrastructure-as-Code (IaC) using Terraform
Infrastructure-as-Code (IaC) using TerraformInfrastructure-as-Code (IaC) using Terraform
Infrastructure-as-Code (IaC) using Terraform
 
infrastructure as code
infrastructure as codeinfrastructure as code
infrastructure as code
 
Apache Phoenix: Transforming HBase into a SQL Database
Apache Phoenix: Transforming HBase into a SQL DatabaseApache Phoenix: Transforming HBase into a SQL Database
Apache Phoenix: Transforming HBase into a SQL Database
 
Infrastructure as Code
Infrastructure as CodeInfrastructure as Code
Infrastructure as Code
 
Ozone- Object store for Apache Hadoop
Ozone- Object store for Apache HadoopOzone- Object store for Apache Hadoop
Ozone- Object store for Apache Hadoop
 
Terraform Basics
Terraform BasicsTerraform Basics
Terraform Basics
 
Terraform
TerraformTerraform
Terraform
 
AWS big-data-demystified #1.1 | Big Data Architecture Lessons Learned | English
AWS big-data-demystified #1.1  | Big Data Architecture Lessons Learned | EnglishAWS big-data-demystified #1.1  | Big Data Architecture Lessons Learned | English
AWS big-data-demystified #1.1 | Big Data Architecture Lessons Learned | English
 
Terraform on Azure
Terraform on AzureTerraform on Azure
Terraform on Azure
 

Similar to Using new sentinel features in terraform cloud

Kafka/SMM Crash Course
Kafka/SMM Crash CourseKafka/SMM Crash Course
Kafka/SMM Crash Course
DataWorks Summit
 
Developing Tizen OS Based Solutions (IDF13) - Chris Norman
Developing Tizen OS Based Solutions (IDF13) - Chris NormanDeveloping Tizen OS Based Solutions (IDF13) - Chris Norman
Developing Tizen OS Based Solutions (IDF13) - Chris Norman
Ryo Jin
 

Similar to Using new sentinel features in terraform cloud (20)

RIMA-Infrastructure as a code with Terraform.pptx
RIMA-Infrastructure as a code with Terraform.pptxRIMA-Infrastructure as a code with Terraform.pptx
RIMA-Infrastructure as a code with Terraform.pptx
 
Terraform Abstractions for Safety and Power
Terraform Abstractions for Safety and PowerTerraform Abstractions for Safety and Power
Terraform Abstractions for Safety and Power
 
Policy Guided Fulfillmentof Murano Applications
Policy Guided Fulfillmentof Murano ApplicationsPolicy Guided Fulfillmentof Murano Applications
Policy Guided Fulfillmentof Murano Applications
 
3 Reasons to Select Time Series Platforms for Cloud Native Applications Monit...
3 Reasons to Select Time Series Platforms for Cloud Native Applications Monit...3 Reasons to Select Time Series Platforms for Cloud Native Applications Monit...
3 Reasons to Select Time Series Platforms for Cloud Native Applications Monit...
 
Terraform vs Pulumi
Terraform vs PulumiTerraform vs Pulumi
Terraform vs Pulumi
 
DevOps Online Training in Hyderabad
DevOps Online Training in HyderabadDevOps Online Training in Hyderabad
DevOps Online Training in Hyderabad
 
Kafka/SMM Crash Course
Kafka/SMM Crash CourseKafka/SMM Crash Course
Kafka/SMM Crash Course
 
Git ops & Continuous Infrastructure with terra*
Git ops  & Continuous Infrastructure with terra*Git ops  & Continuous Infrastructure with terra*
Git ops & Continuous Infrastructure with terra*
 
OpenStack Murano
OpenStack MuranoOpenStack Murano
OpenStack Murano
 
Terraform day 1
Terraform day 1Terraform day 1
Terraform day 1
 
Unicorn Platform; Basic Usage Guide
Unicorn Platform; Basic Usage GuideUnicorn Platform; Basic Usage Guide
Unicorn Platform; Basic Usage Guide
 
Controlling Cloud Costs with HashiCorp Terraform
Controlling Cloud Costs with HashiCorp TerraformControlling Cloud Costs with HashiCorp Terraform
Controlling Cloud Costs with HashiCorp Terraform
 
Installing your influx enterprise cluster
Installing your influx enterprise clusterInstalling your influx enterprise cluster
Installing your influx enterprise cluster
 
3 reasons to pick a time series platform for monitoring dev ops driven contai...
3 reasons to pick a time series platform for monitoring dev ops driven contai...3 reasons to pick a time series platform for monitoring dev ops driven contai...
3 reasons to pick a time series platform for monitoring dev ops driven contai...
 
Developing Tizen OS Based Solutions (IDF13) - Chris Norman
Developing Tizen OS Based Solutions (IDF13) - Chris NormanDeveloping Tizen OS Based Solutions (IDF13) - Chris Norman
Developing Tizen OS Based Solutions (IDF13) - Chris Norman
 
Self-service PR-based Terraform
Self-service PR-based TerraformSelf-service PR-based Terraform
Self-service PR-based Terraform
 
Infrastructure as Code with Terraform.pptx
Infrastructure as Code with Terraform.pptxInfrastructure as Code with Terraform.pptx
Infrastructure as Code with Terraform.pptx
 
The Flink - Apache Bigtop integration
The Flink - Apache Bigtop integrationThe Flink - Apache Bigtop integration
The Flink - Apache Bigtop integration
 
Build cloud native solution using open source
Build cloud native solution using open source Build cloud native solution using open source
Build cloud native solution using open source
 
Online spanish meetup #2
Online spanish meetup #2Online spanish meetup #2
Online spanish meetup #2
 

More from Mitchell Pronschinske

More from Mitchell Pronschinske (20)

Getting Started with Kubernetes and Consul
Getting Started with Kubernetes and ConsulGetting Started with Kubernetes and Consul
Getting Started with Kubernetes and Consul
 
Multi-Cloud with Nomad and Consul Connect
Multi-Cloud with Nomad and Consul ConnectMulti-Cloud with Nomad and Consul Connect
Multi-Cloud with Nomad and Consul Connect
 
Code quality for Terraform
Code quality for TerraformCode quality for Terraform
Code quality for Terraform
 
Dynamic Azure Credentials for Applications and CI/CD Pipelines
Dynamic Azure Credentials for Applications and CI/CD PipelinesDynamic Azure Credentials for Applications and CI/CD Pipelines
Dynamic Azure Credentials for Applications and CI/CD Pipelines
 
Migrating from VMs to Kubernetes using HashiCorp Consul Service on Azure
Migrating from VMs to Kubernetes using HashiCorp Consul Service on AzureMigrating from VMs to Kubernetes using HashiCorp Consul Service on Azure
Migrating from VMs to Kubernetes using HashiCorp Consul Service on Azure
 
Empowering developers and operators through Gitlab and HashiCorp
Empowering developers and operators through Gitlab and HashiCorpEmpowering developers and operators through Gitlab and HashiCorp
Empowering developers and operators through Gitlab and HashiCorp
 
Automate and simplify multi cloud complexity with f5 and hashi corp
Automate and simplify multi cloud complexity with f5 and hashi corpAutomate and simplify multi cloud complexity with f5 and hashi corp
Automate and simplify multi cloud complexity with f5 and hashi corp
 
Vault 1.5 Overview
Vault 1.5 OverviewVault 1.5 Overview
Vault 1.5 Overview
 
Military Edge Computing with Vault and Consul
Military Edge Computing with Vault and ConsulMilitary Edge Computing with Vault and Consul
Military Edge Computing with Vault and Consul
 
Unlocking the Cloud operating model with GitHub Actions
Unlocking the Cloud operating model with GitHub ActionsUnlocking the Cloud operating model with GitHub Actions
Unlocking the Cloud operating model with GitHub Actions
 
Vault 1.4 integrated storage overview
Vault 1.4 integrated storage overviewVault 1.4 integrated storage overview
Vault 1.4 integrated storage overview
 
Unlocking the Cloud Operating Model
Unlocking the Cloud Operating ModelUnlocking the Cloud Operating Model
Unlocking the Cloud Operating Model
 
Cisco ACI with HashiCorp Terraform (APAC)
Cisco ACI with HashiCorp Terraform (APAC)Cisco ACI with HashiCorp Terraform (APAC)
Cisco ACI with HashiCorp Terraform (APAC)
 
Governance for Multiple Teams Sharing a Nomad Cluster
Governance for Multiple Teams Sharing a Nomad ClusterGovernance for Multiple Teams Sharing a Nomad Cluster
Governance for Multiple Teams Sharing a Nomad Cluster
 
Integrating Terraform and Consul
Integrating Terraform and ConsulIntegrating Terraform and Consul
Integrating Terraform and Consul
 
Unlocking the Cloud Operating Model: Deployment
Unlocking the Cloud Operating Model: DeploymentUnlocking the Cloud Operating Model: Deployment
Unlocking the Cloud Operating Model: Deployment
 
Keeping a Secret with HashiCorp Vault
Keeping a Secret with HashiCorp VaultKeeping a Secret with HashiCorp Vault
Keeping a Secret with HashiCorp Vault
 
Modern Scheduling for Modern Applications with Nomad
Modern Scheduling for Modern Applications with NomadModern Scheduling for Modern Applications with Nomad
Modern Scheduling for Modern Applications with Nomad
 
Moving to a Microservice World: Leveraging Consul on Azure
Moving to a Microservice World: Leveraging Consul on AzureMoving to a Microservice World: Leveraging Consul on Azure
Moving to a Microservice World: Leveraging Consul on Azure
 
Remote Culture at HashiCorp
Remote Culture at HashiCorpRemote Culture at HashiCorp
Remote Culture at HashiCorp
 

Recently uploaded

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 

Recently uploaded (20)

Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 

Using new sentinel features in terraform cloud

  • 1. Copyright © 2020 HashiCorp Using New Sentinel Features in Terraform Cloud and Terraform Enterprise Roger Berlind Technology Specialist HashiCorp
  • 2. Copyright © 2020 HashiCorp ▪ Sentinel in Terraform Cloud (TFC) and Terraform Enterprise (TFE) ▪ Two New Sentinel Features – Sentinel Modules – Terraform Sentinel v2 Imports ▪ The Evolution of Sentinel Policies ▪ Some Prototypical Third-Generation Sentinel Policies ▪ The Third-Generation Common Functions ▪ Testing and Using the Third Generation Sentinel Policies ▪ A Demo Agenda
  • 3. Copyright © 2020 HashiCorp Sentinel in Terraform Cloud and Terraform Enterprise
  • 4. Copyright © 2020 HashiCorp ▪ HashiCorp's Sentinel is a framework for implementing governance policies as code in the same way that Terraform implements infrastructure as code. ▪ It includes its own language and is embedded in HashiCorp's enterprise products. ▪ Using Sentinel ensures that your governance policies are actually being checked rather than just being listed in a spreadsheet. ▪ It supports fine-grained policies that use conditional logic. ▪ It includes a CLI that allows you to test and run policies. What is Sentinel?
  • 5. Copyright © 2020 HashiCorp Terraform Cloud and Terraform Enterprise ▪ A User Interface ▪ Workspace Management ▪ Team Management ▪ State Management ▪ Secure Variable Management ▪ Remote Runs and State ▪ VCS Integrations ▪ HTTP/JSON API ▪ Private Module Registry ▪ Configuration Editor ▪ Sentinel (policy as code) ▪ SSO via SAML Integration ▪ Audit Logging Terraform Cloud (TFC) includes the following advanced functionality that makes it easier for teams and organizations to use Terraform: Customers can install Terraform Enterprise (TFE) servers to self-host TFC in their own virtual private networks or in their data centers.
  • 6. Copyright © 2020 HashiCorp ▪ Sentinel policies are checked between the standard plan and apply steps of Terraform runs. ▪ Policies have different enforcement levels: advisory, soft-mandatory, and hard-mandatory. ▪ Violations prevent runs from being applied unless a user with sufficient authority overrides them. ▪ Sentinel policies can evaluate the attributes (arguments and exported attributes) of existing and new resources and data sources based on information from the current run: – the plan, the configuration, the current state, and other run data including cost estimates ▪ This ensures that resources comply with all policies before they are provisioned. Where is Sentinel Used in Terraform?
  • 7. Copyright © 2020 HashiCorp How Terraform Works Without Sentinel VCS Terraform Infrastructureplan & apply
  • 8. Copyright © 2020 HashiCorp How Terraform Works With Sentinel VCS Terraform Cloud Workspace Infrastructureplan Sentinel Policy Checks apply If cost estimates are enabled, they run right after the plan.
  • 9. Copyright © 2020 HashiCorp All Policy Checks Passed
  • 10. Copyright © 2020 HashiCorp ▪ HashiCorp customers are using Sentinel to implement governance policies like the following in Terraform Cloud/Enterprise: – Enforce security standards: ▪ Require all S3 buckets use the private ACL and be encrypted by KMS. ▪ Restrict which roles the AWS provider can assume. ▪ Blacklist/whitelist resources, data sources, providers, or provisioners. – Avoid excessive costs: ▪ Limit the sizes of VMs and Kubernetes clusters in public clouds. ▪ Limit the monthly spend of each Terraform workspace. – Enforce mandatory tags on resources provisioned by Terraform. – Mandate that all modules come from a Private Module Registry. – Enforce specific Terraform coding conventions. How Customers are Using Sentinel in Terraform
  • 11. Copyright © 2020 HashiCorp Two New Sentinel Features
  • 12. Copyright © 2020 HashiCorp ▪ A Sentinel Module defines Sentinel functions and rules in a file that can be used by Sentinel policies with a single import statement. ▪ This avoids the need to paste the functions into every policy that calls them, improving the reusability of Sentinel functions. ▪ Sentinel modules are registered in Sentinel CLI configuration files and in TFC/TFE policy set configuration files. ▪ The terraform-guides repository includes 5 "third-generation" modules: – tfplan-functions, tfstate-functions, tfconfig-functions, tfrun-functions, and aws-functions ▪ Each function is documented in a separate MD file. ▪ Note that these are NOT standard functions. Sentinel Modules
  • 13. Copyright © 2020 HashiCorp ▪ The new v2 versions of three Terraform Sentinel imports (tfplan, tfstate, and tfconfig) are aligned more closely with native Terraform 0.12 data structures. ▪ This makes the v2 imports easier to use than the v1 imports. ▪ Additionally, since resource instances are stored in a single flat map that spans across all Terraform modules and resource types, it is much easier to find all resources instances of a specific type or a sub-collection of them. ▪ However, there is a catch: – The v2 imports can only be used with Terraform 0.12. New v2 Versions of the Terraform Sentinel Imports
  • 14. Copyright © 2020 HashiCorp ▪ The tfplan/v2 gives data generated from Terraform plans. – https://www.terraform.io/docs/cloud/sentinel/import/tfplan-v2.html ▪ The tfconfig/v2 import gives data about the Terraform configuration. – https://www.terraform.io/docs/cloud/sentinel/import/tfconfig-v2.html ▪ The tfstate/v2 import gives data about the current state of a workspace. – https://www.terraform.io/docs/cloud/sentinel/import/tfstate-v2.html ▪ The tfrun import provides metadata for Terraform runs and their workspaces as well as cost estimate data. (There is no v2 version of it.) – https://www.terraform.io/docs/cloud/sentinel/import/tfrun.html Sentinel Imports in Terraform
  • 15. Copyright © 2020 HashiCorp The Evolution of Sentinel Policies
  • 16. Copyright © 2020 HashiCorp ▪ The first-generation policies were written in late 2018 and used the original Terraform Sentinel v1 imports. ▪ They had several short-comings, including the following: – Most of the policies did not print violation messages for resources that violated them. – They stopped evaluating conditions as soon as a single resource instance violated them. – They failed when resources that were being destroyed violated conditions. – Their use of default Sentinel output was overly verbose. The First-Generation Policies
  • 17. Copyright © 2020 HashiCorp ▪ The second-generation policies were written in 2019 and used the original Terraform Sentinel v1 imports: ▪ They made the following improvements: – They offloaded most processing from rules into some common parameterized functions. – Those common functions were written in a way that caused all violations of all rules to be reported. – They printed out the full address of each resource instance that did violate a policy. – By using a single main rule, they suppressed most of Sentinel’s default, overly verbose output. – They skipped resources that were being destroyed but not recreated. The Second-Generation Policies
  • 18. Copyright © 2020 HashiCorp ▪ The new third-generation policies were written in the spring of 2020 and use the new Terraform Sentinel v2 imports and Sentinel modules. ▪ They have the following advantages: – Their use of the v2 imports and the Sentinel filter expression makes it easier to restrict policies to specific operations performed by Terraform. – The common functions defined in Sentinel modules do not need to be pasted into policies that use them. – Most of the policies do not have any for loops of if/else conditionals. This makes the policies easier to understand and copy. – They can evaluate the value of any attribute of any resource or data source, even those that are deeply nested. ▪ However, since they do use the v2 imports, they can only be used with Terraform 0.12 The New Third-Generation Policies
  • 19. Copyright © 2020 HashiCorp Some Prototypical Third- Generation Sentinel Policies
  • 20. Copyright © 2020 HashiCorp ▪ I'll review four prototypical third-generation Sentinel policies in order of increasing sophistication: – restrict-ec2-instance-type.sentinel (AWS) – restrict-vm-cpu-and-memory.sentinel (VMware) – restrict-vm-disk-size.sentinel (VMware) – restrict-publishers-of-current-vms.sentinel (Azure) Some Prototypical Third-Generation Policies
  • 21. Copyright © 2020 HashiCorp The Third-Generation Common Functions
  • 22. Copyright © 2020 HashiCorp ▪ As mentioned earlier, there are third-generation Sentinel modules with common functions for each of the Terraform Sentinel imports. ▪ The tfplan and tfstate modules have the following functions: – Find functions that find resources, data sources, and blocks. – Filter functions that filter collections of resources, data sources, or blocks. These each return two maps: resources and messages. – The evaluate_attribute function that can evaluate any attribute of any resource, data source, or block, even if deeply nested. – The to_string and print_violation functions that are used by the other functions. ▪ There is also a Sentinel module with some AWS-specific functions. The Third-Generation Common Functions
  • 23. Copyright © 2020 HashiCorp Testing and Using the Third- Generation Sentinel Policies
  • 24. Copyright © 2020 HashiCorp ▪ All the third-generation Sentinel policies have test cases and mocks that support testing the policies with the Sentinel CLI ▪ Do the following: – Download the Sentinel CLI from the Sentinel Downloads page. – Unzip the zip file and place the sentinel binary in your path. – Fork the terraform-guides repository and clone your fork to your local machine. – Navigate to any of the cloud directories (aws, azure, gcp, or vmware) or to the cloud-agnostic directory. – Run sentinel test to test all policies for that cloud. – Run sentinel test -run=<partial_policy_name> -verbose to test individual policies, using a string that partially matches name. Testing Policies with the Sentinel CLI
  • 25. Copyright © 2020 HashiCorp { "modules": { "tfplan-functions": { "path": "../../../common-functions/tfplan-functions/ tfplan-functions.sentinel" } }, "mock": { "tfplan/v2": "mock-tfplan-pass.sentinel" }, "test": { "main": true } } An Example Test Case that References a Module
  • 26. Copyright © 2020 HashiCorp ▪ After successfully testing a policy with the CLI and possibly also on TFC itself, you will want to deploy it to your TFC/TFE organizations. ▪ If you have not already added the policy to a policy set in your organizations, do that at this time. ▪ Add the new policy to an existing policy set that is already applied against desired workspaces, or create a new policy set for the policy and apply that policy set to desired workspaces across your organizations. ▪ Also add any parameters the policy requires to your policy set. ▪ And add references to any Sentinel Modules that policies in it use. Deploying Policies in TFC or TFE
  • 27. Copyright © 2020 HashiCorp ▪ Here is an example policy set: module "tfplan-functions" { source = "../common-functions/tfplan-functions/tfplan -functions.sentinel" } policy "restrict-ec2-instance-type" { source = "./restrict-ec2-instance-type.sentinel" enforcement_level = "soft-mandatory" } Example Policy Set
  • 28. Copyright © 2020 HashiCorp Demo
  • 29. Copyright © 2020 HashiCorp ▪ Here are some useful Links ▪ Documentation – https://www.terraform.io/docs/cloud/sentinel/index.html – https://www.terraform.io/docs/cloud/sentinel/manage- policies.html – https://docs.hashicorp.com/sentinel ▪ Other Resources: – Blog for this webinar – Sentinel in Terraform v2 Workshop (including hands-on Instruqt track that teaches you how to write and test policies) Some Useful Links

Editor's Notes

  1. These slides are intended to accompany the Sentinel for Terraform v2 workshop They should be used with the Sentinel for Terraform v2 Instruqt track: https://instruqt.com/hashicorp/tracks/sentinel-for-terraform-v2
  2. Let's talk about Sentinel and how it fits into Terraform Cloud and Terraform Enterprise. We'll also discuss how customers are using Sentinel in TFC and TFE.
  3. Sentinel is a framework for implementing governance policies as code It has its own language It has a CLI for testing and running policies
  4. Let's level set about Terraform Cloud and Terraform Enterprise Note that Terraform Cloud (TFC) refers both to the actual application used and the implementation hosted by HashiCorp at app.terraform.io. Since TFE uses the TFC application, we will mostly just talk about TFC. But anything we say about TFC is true of TFE too except when we discuss very new features that have been released to TFC. But those new features generally end up in TFE within 4-6 weeks.
  5. Let's talk about where Sentinel is used in TFC and TFE. It is run between the plan and the apply of a run. If cost estimates are enabled for a workspace, the Sentinel policies are checked after the cost estimates are collected. "Arguments" are the inputs to Terraform resources and data sources. Each resource and data source also exports certain attributes that are computed during the apply. These are called "exported attributes". But since the arguments or a resource are also exported, it is common to use "attributes" to refer to the union of a resource's arguments and exported attributes.
  6. Here is how Terraform works without Sentinel.
  7. Here is how Terraform works with Sentinel. Note that if cost estimates are enabled for the workspace, they will run right after the plan.
  8. A screenshot from TFC showing that all policy checks passed for a run.
  9. Let's talk about some use cases for Sentinel in TFC and TFE.
  10. Let's spend some time discussing the Sentinel language.
  11. Sentinel modules allow for the reuse of Sentinel functions and rules. They are registered in Sentinel CLI configuration files and in TFC/TFE policy set configuration files.
  12. Sentinel has some builtin functions that you can use in any policy.
  13. This is a good point to discuss the Terraform-specific Sentinel imports. Terraform Cloud/Enterprise adds 4 Sentinel imports beyond the standard ones. This version of the workshop uses the v2 versions of the tfplan, tfconfig, and tfstate imports. The v2 versions are more closely aligned to Terraform 0.12's internal data structures. There is only 1 version of the tfrun import.
  14. Now we will do the first two workshop challenges on the Instruqt platform
  15. The first-generation policies had several limitations.
  16. The second-generation policies made many improvements.
  17. The new workshop exercises leverage the Instruqt platform and make solving the exercises much easier. Be sure to use the Sentinel Instruqt track that ends in v2, not the one that ends in v1.
  18. Now let's walk through the basic 8 step methodology of the Writing and Testing Sentinel Policies for Terraform guide.
  19. This slide gives the basic 8 step methodology of writing and testing Sentinel policies from the Writing and Testing Sentinel Policies for Terraform guide. We will focus on 5-7 in this workshop.
  20. Now let's walk through the basic 8 step methodology of the Writing and Testing Sentinel Policies for Terraform guide.
  21. After testing new Sentinel policies with the Sentinel CLI, you can test them in an organization on a TFC or TFE server.
  22. While we won't be using Sentinel in Terraform Cloud or Terraform Enterprise today, we did want to review this topic After all, that is where your Sentinel policies will really be running. You'll get a chance to complete and test some more Sentinel policies with the Sentinel CLI after this section.
  23. After testing new Sentinel policies with the Sentinel CLI, you can test them in an organization on a TFC or TFE server.
  24. The stanza at the top declares a Sentinel Modules with functions that can be called by Sentinel policies that import them. In this case, the file "tfplan-functions.sentinel" is being declared as the module "tfplan-functions". Recall that when we imported it in our policy, we gave it the alias "plan". We also indicate that the test case should use the mock-tfplan-pass.sentinel mock and that the main rule should evaluate to true. If using tfconfig/v2, tfstate/v2, or tfrun mock files, you need to specify the mock type accordingly (instead of using "tfplan/v2").
  25. After testing a policy with the Sentinel CLI and possibly in a TFC/TFE organization, you'll want to deploy it to your TFC organizations.
  26. You'll need to create policy sets that contain the policies you want to use in TFC or TFE You can now specify Sentinel modules in your policy sets, but the modules must be in or under the directory with the sentinel.hcl file at this time. In the near future, we will support loading of modules from remote locations.
  27. While we won't be using Sentinel in Terraform Cloud or Terraform Enterprise today, we did want to review this topic After all, that is where your Sentinel policies will really be running. You'll get a chance to complete and test some more Sentinel policies with the Sentinel CLI after this section.
  28. Thanks for attending the Sentinel in Terraform Workshop or reviewing these slides.