Introduction
This guide explains how to use data from external JSON-based APIs within HashiCorp Sentinel policies. This allows you to enrich policy decisions with external data sources.
Prerequisites
- Sentinel runtime version 0.13.0 or newer.
Procedure
The process involves making an HTTP request to an external API, parsing the JSON response, and then using that data in your policy logic.
-
Make the HTTP Request
First, use the Sentinel
httpimport to make a request to your external API. Thehttp.requestfunction is typically used for this purpose. -
Unmarshal the JSON Response
Once you receive the API response, use the Sentinel
jsonimport to unmarshal the JSON body into a usable data structure within Sentinel. -
Process the Data
After unmarshalling the data, you can process it to find the information you need for your policy. The specific approach depends on the structure of the API response, but common methods include iterating over the data with a
forloop or using afilterexpression.
Additional Information
- For further questions and community support, visit the Sentinel Discuss Forum.