Sentinel HTTP import
Enterprise Only
Sentinel requires Vault Enterprise.
Sentinel is a language framework for policy built to embed in Vault Enterprise, and enable fine-grained, logic-based policy decisions which cannot be fully handled by the ACL policies.
If you are not yet familiar with using Sentinel policies in Vault, review Sentinel Policies.
Challenge
Sentinel Endpoint Governing Policies (EGP) are flexible and offer rich capabilities and rules to enable uses like Multi Factor Authentication requirements or per path policy delegation. What if your use case requires policy rules which get information from the output of an external HTTP API?
Solution
The Sentinel http import enables the use of HTTP-accessible data from outside the runtime in Sentinel policy rules. At a basic level, the import uses an HTTP GET request and by default, any request response that is not a successful "200 OK" HTTP response causes a policy error. This behavior can be further customized to your particular use case.
In this tutorial you will write a Sentinel EGP that uses the HTTP import to query the Vault server API for information about enabled secrets engines. The Sentinel EGP will either allow or deny certain operations based on the specific criteria defined in the policy.
Personas
Sentinel policies provide a declarative way to grant or forbid access to certain paths and operations in Vault. Therefore, the steps described in this tutorial are performed by Vault admins or security operations.
Prerequisites
To perform the tasks described in this tutorial, you need to have:
- Vault Enterprise binary and license key.
- jq binary installed in your system PATH.
- Git binary installed in your system PATH.
You should have familiarity with Vault and Sentinel, and be comfortable authoring and deploying a Sentinel EGP for Vault to follow the example in this tutorial.
Policy requirements
This tutorial requires two Vault tokens - one for the Vault admin who will be creating and testing the Sentinel EGP, and one to use to for the EGP.
You need to authenticate to Vault with a token that has the required capabilities to follow the example workflow.
Warning
Do not use the initial root token for any purpose other than creating the required tokens. A root token is not subject to Sentinel policy enforcement, and will cause issues with policy development and testing.
Vault admin token policy
Review the Vault ACL policy which the admin user's token needs to create the EGP.
Going forward, the tutorial refers to this token as the admin token.
Sentinel EGP token policy
The Sentinel EGP example in this tutorial makes a call to the /sys/mounts API to learn about the enabled secrets engines.
This is an authenticated API endpoint, so the EGP requires a Vault token with the minimum required ACL policy capability
to read from /sys/mounts
.
That policy is as follows.
Going forward, the tutorial refers to this token as the EGP token.
Lab setup
Before you can use the Sentinel HTTP import module, you need to configure Vault and define additional enabled modules. You can do this with the additional_enabled_modules parameter.
For this tutorial, you will use a Vault server in dev mode and pass just the Sentinel specific configuration to it at runtime from the configuration file,
vault-sentinel-configuration.hcl
.Write the configuration file to enable the HTTP module.
Export an environment variable for the Vault Enterprise license .
In the same terminal session where you created the configuration file and
VAULT_LICENSE
environment variable, start the Vault dev mode server and pass the configuration file to the-config
flag.The Vault dev server defaults to running at
127.0.0.1:8200
. The server is automatically initialized, and unsealed.Insecure operation
Do not run a Vault dev server in production. This tutorial uses a dev mode server to simplify the unsealing process for the hands on lab.
Open a new terminal and export an environment variable for the
vault
CLI to address the Vault server.Export an environment variable for the
vault
CLI to authenticate with the Vault server.Note
For these tasks, you can use Vault's root token. Keep in mind though, that the best practice is to use root tokens just for initial setup or in emergencies.
The Vault server is ready.
Write ACL policies
Create two ACL policies and generate the admin token and EGP token.
Create the admin ACL policy.
Example output:
Create the EGP ACL policy.
Example output:
Capture the admin user token value to the
VAULT_ADMIN_TOKEN
environment variable.Review the
VAULT_ADMIN_TOKEN
token.Capture the EGP token value to the
VAULT_EGP_TOKEN
environment variable.Review the
VAULT_EGP_TOKEN
token.Unset the
VAULT_TOKEN
environment variable.Login with the admin token.
Review Sentinel EGP
With the initial Vault configuration in place, you will now create the Sentinel EGP.
In this example, you will limit the number of enabled Transit secrets engines instances to just a single one.
You do so by leveraging Sentinel with the HTTP import to query the Vault API, and check the number of enabled Transit secrets engines.
The Sentinel policy can then further choose to allow or deny enabling of new secrets engines based on the current count of enabled transit secrets engines.
Example policy
Review the details in the Sentinel policy.
1 2 3 4 5 6 7 8 9 1011121314151617181920212223242526272829303132333435363738394041424344
- Lines 3-4 declare the http and json imports needed for making HTTP requests and processing JSON.
- Lines 7-8 define parameter values for the Vault address and Vault token for the EGP itself. You should replace http://127.0.0.1:8200 with the address of your Vault server in the same URL format with port (ex. http://localhost:8200) and replace \$VAULT_EGP_TOKEN with the actual token value for your EGP token that you created in step 3.
- Lines 12-14 print statements which are useful for debugging. Vault prints this information whenever a request violates the policy and fails.
- Lines 16-37 includes the EGP logic in a single function,
validate_transit_not_present()
. It makes the HTTP request to the Vault /sys/mounts API endpoint to query the state of enabled secrets engines by examining each enabled engine. If one is the type "transit", then the validated variable value returns as false, causing the main rule evaluation to fail; permission to enable a transit secrets engine for a non-root token users gets denied. - Lines 40-44 includes the main rule and sets conditions for its evaluation based on request parameters; the request must be for the /sys/mounts path, it must be an update operation, and the data type for the operation needs to be transit. If the request matches these conditions, then
validate_transit_not_present
checks for an enabled transit secrets engine.
Create and test Sentinel EGP
Write the
transit-check.sentinel
Sentinel EGP.Warning
If you deploy the Sentinel EGP with the HTTP API or Web UI, you need to replace the
$VAULT_EGP_TOKEN
value with the actual EGP token value before deploying the policy.Test the Sentinel policy before deployment to check syntax and to document expected behavior by downloading the Sentinel simulator.
Unzip the downloaded file.
Create the
test/transit-check
directory structure.Create the tests under the
test/<policy_name>
folder.Write a passing test case for the
transit-check
policy,test/transit-check/success.json
.This test will pass because it does not include an enabled transit secrets engine.
The optional
test
definition adds more context to why the test should pass. The expected behavior is that the test passes becausevalidate_transit_not_present
returnstrue
andmain
returnstrue
.Write a failing test for the
transit-check
policy,test/transit-check/fail.json
.This test will fail because it includes an enabled transit secrets engine.
The optional
test
definition adds more context to why the test should fail. The expected behavior is that the test fails becausevalidate_transit_not_present
returnsfalse
andmain
returnsfalse
.Verify success and failure tests creation.
Execute the Sentinel test.
Example output:
Note
If you want to see the tracing and log output for tests, run the command with a
-verbose
flag.
Deploy Sentinel EGP
Sentinel policies have three enforcement levels:
Level | Description |
---|---|
advisory | The policy permitted to fail. Useful as a tool to educate new users. |
soft-mandatory | The policy must pass unless user specifies override. |
hard-mandatory | The policy must pass no matter what! |
Deploy the Sentinel policy with an enforcement level of hard-mandatory.
Login with the admin token.
Store the Base64 encoded
transit-check.sentinel
policy in an environment variable namedPOLICY
.Create a policy
transit-check
with enforcement level of hard-mandatory if there is more than one transit secrets engine enabled.Example output:
Read the
transit-check
policy.Example output:
Verification
Once you've deployed the policy, Vault will deny permission for all operations which fail the policy rule assertions when the server learns there is already a transit secrets engine enabled.
Login with the admin token.
Enable one instance of the transit secrets engine.
Try to enable another instance of the transit secrets engine at the path another-transit-secrets-engine.
Example output:
A policy violation results in the inclusion of debug
print()
statement output.Warning
As with ACL policies,
root
tokens are NOT subject to Sentinel policy checks. Be sure to use a non-root token for the verification test.
Going even further with Vault Enterprise Namespaces
If you want to try a more advanced example involving the Vault Enterprise Namespaces feature, you can follow the guidance in Restrict Members of a Group with Sentinel. You will learn how to restrict the subgroups and entities of a group by requiring all subgroups and entities of a group to belong to the same namespace.
Cleanup
To clean up the example files and stop your Vault dev server follow these steps.
Remove the files.
Remove the Sentinel tests.
In the terminal session where you started the Vault dev server, press CTRL+C to stop Vault.
Troubleshooting
If you have an error such as this example while testing the EGP.
Note the Import "http" is not available part of the error. This indicates that Vault is not configured to allow the HTTP import. Check the instructions in the Lab setup section and make sure you have configured and restarted your Vault.