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
IRA Benefits & Drawbacks: What You Should Know ❘ Wealthfront
Micro Flipping: What It Means In Real Estate
Matgyn
Skycurve Replacement Mat
Dricxzyoki
Best Team In 2K23 Myteam
Blanchard St Denis Funeral Home Obituaries
Culver's Flavor Of The Day Wilson Nc
Apnetv.con
Xrarse
About Goodwill – Goodwill NY/NJ
Derpixon Kemono
Jasmine Put A Ring On It Age
Explore Top Free Tattoo Fonts: Style Your Ink Perfectly! 🖌️
Miss America Voy Forum
What Time Chase Close Saturday
Wildflower1967
Bowie Tx Craigslist
Minecraft Jar Google Drive
Condogames Xyz Discord
Illinois Gun Shows 2022
Char-Em Isd
Tnt Forum Activeboard
Katherine Croan Ewald
Q Management Inc
Craigslist In Flagstaff
Unterwegs im autonomen Freightliner Cascadia: Finger weg, jetzt fahre ich!
Toyota Camry Hybrid Long Term Review: A Big Luxury Sedan With Hatchback Efficiency
Parkeren Emmen | Reserveren vanaf €9,25 per dag | Q-Park
Violent Night Showtimes Near Amc Dine-In Menlo Park 12
Ltg Speech Copy Paste
His Only Son Showtimes Near Marquee Cinemas - Wakefield 12
Vlacs Maestro Login
Family Fare Ad Allendale Mi
Hell's Kitchen Valley Center Photos Menu
Boone County Sheriff 700 Report
Koninklijk Theater Tuschinski
Atlanta Musicians Craigslist
Craigslist Pa Altoona
Torrid Rn Number Lookup
Lucifer Morningstar Wiki
Comanche Or Crow Crossword Clue
Yale College Confidential 2027
Amy Zais Obituary
Star Sessions Snapcamz
The Quiet Girl Showtimes Near Landmark Plaza Frontenac
Food and Water Safety During Power Outages and Floods
17 of the best things to do in Bozeman, Montana
Heat Wave and Summer Temperature Data for Oklahoma City, Oklahoma
Roller Znen ZN50QT-E
Cognitive Function Test Potomac Falls
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.