Writing Sentinel Policy | Sentinel | HashiCorp Developer (2024)

Table of Contents
Mocking Imports Custom Imports

Imports enable a Sentinel policy to access reusable libraries and external dataand functions. Anyone can write their own custom import.Imports are what enable Sentinel policies to do more than look at only localcontext for making policy decisions.

Sentinel also comes with a set of standard imports.Standard imports are available to every Sentinel policy to help policy writerswith common tasks such as working with the time, network addresses, and more.

This page is about writing policies that use imports. If you'reinterested in creating a new import, please see the section on extendingSentinel for information on how to write modules andimport plugins.

To use an import, you use the import keyword at the top of your policy. Thisspecifies the name of the import you want to use. The application you're writingthe policy for must already beconfigured to provide thatimport.

Details on imports can be found in theimport section in the language reference.

In the example below, we use the time import:

There are two options to develop a policy locally when using imports:configure Sentinel to launch the import on apply, or mock the importusing mock. The former requires access to the import while thelatter is faster (doesn't have to launch a process for plugins) anddoesn't require the import.

Mocking Imports

The first option to developing policies locally is to mock the import values.When mocking an import, you don't need the import to be available. This can beuseful since some imports may not be available as a plugin and may only beavailable to the application the policy runs in.

Mocks are specified via the configurationfile. Mocks can also be used fortesting.

You can supply mock configuration one of two ways, depending on your use case:

  • Using static data:Use this method when you can accurately represent your mock data in JSON anddo not need to mock complex Sentinel features such as functions.
  • Using Sentinel code:Use this method when using a static JSON object is insufficient, such as whenyou need to mock functions or other complex Sentinel features.

Our example does not require complex data to be mocked, so a static objectis sufficient:

mock "time" { data = { now = { hour = 12 weekday_name = "Tuesday" } }}

This can be used via the CLI:

$ sentinel apply -config=config.hcl policy.sentinelPass

If you have access to the plugin binary, you can launch the import. Thebenefit of this is that it is really using the import to test yourpolicy. If the import changes, your policies may start failing. If youonly use mock data and the import changes, your policies will stillappear to work.

Imports are configured in the configuration file:

import "plugin" "custom_time" { source = "/path/to/sentinel-time-import"}

This would require the sentinel-time-import binary. For this examplethis doesn't currently exist. We plan on writing one to provide for thissection of the documentation.

Custom Imports

You can also create your own imports.

If your policy decisions could benefit from accessing external information,then you can use custom imports as a way to do this.

Writing Sentinel Policy | Sentinel | HashiCorp Developer (2024)
Top Articles
Ideas for Starting a Salad Bar Restaurant: A Complete Guide | Blog | CKitchen.com
Plastic Tarpaulin Market Share | Industry Outlook, 2030
Fiskars X27 Kloofbijl - 92 cm | bol
Maxtrack Live
Joe Taylor, K1JT – “WSJT-X FT8 and Beyond”
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Alan Miller Jewelers Oregon Ohio
Amtrust Bank Cd Rates
Dr Lisa Jones Dvm Married
Miles City Montana Craigslist
Puretalkusa.com/Amac
Clafi Arab
Kentucky Downs Entries Today
Lichtsignale | Spur H0 | Sortiment | Viessmann Modelltechnik GmbH
What Happened To Father Anthony Mary Ewtn
Gina's Pizza Port Charlotte Fl
Pwc Transparency Report
Craigslist Apartments In Philly
Theresa Alone Gofundme
Soccer Zone Discount Code
Wal-Mart 140 Supercenter Products
Lcwc 911 Live Incident List Live Status
NBA 2k23 MyTEAM guide: Every Trophy Case Agenda for all 30 teams
Erica Banks Net Worth | Boyfriend
How to Watch the Fifty Shades Trilogy and Rom-Coms
Vegito Clothes Xenoverse 2
Sef2 Lewis Structure
Governor Brown Signs Legislation Supporting California Legislative Women's Caucus Priorities
Jermiyah Pryear
Meridian Owners Forum
Carroway Funeral Home Obituaries Lufkin
Jailfunds Send Message
By.association.only - Watsonville - Book Online - Prices, Reviews, Photos
Craigslist/Phx
Davita Salary
Acuity Eye Group - La Quinta Photos
140000 Kilometers To Miles
Kelley Blue Book Recalls
2023 Fantasy Football Draft Guide: Rankings, cheat sheets and analysis
Man Stuff Idaho
Bmp 202 Blue Round Pill
Myra's Floral Princeton Wv
Plumfund Reviews
Secrets Exposed: How to Test for Mold Exposure in Your Blood!
Www Pig11 Net
Jimmy John's Near Me Open
Aaca Not Mine
Billings City Landfill Hours
Charlotte North Carolina Craigslist Pets
Ingersoll Greenwood Funeral Home Obituaries
Latest Posts
Article information

Author: Melvina Ondricka

Last Updated:

Views: 6450

Rating: 4.8 / 5 (48 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Melvina Ondricka

Birthday: 2000-12-23

Address: Suite 382 139 Shaniqua Locks, Paulaborough, UT 90498

Phone: +636383657021

Job: Dynamic Government Specialist

Hobby: Kite flying, Watching movies, Knitting, Model building, Reading, Wood carving, Paintball

Introduction: My name is Melvina Ondricka, I am a helpful, fancy, friendly, innocent, outstanding, courageous, thoughtful person who loves writing and wants to share my knowledge and understanding with you.