Using Vault as an OIDC provider for single sign-on
Implementing zero-trust architecture requires providing identity-based access to services within an organization. OpenID Connect (OIDC) allows clients to confirm their identity through an identity provider. Vault 1.9.0 introduced the ability to configure Vault as an OIDC identity provider with authorization code flow, and Nomad 1.5.0 introduced support for OIDC as a single sign-on method. With Nomad 1.5.0, you can use OIDC to authenticate users and map their permissions to Nomad ACL roles and policies.
In this tutorial, you will setup Vault as an OIDC provider and Nomad as its client.
Note: Nomad operates as a confidential OIDC client in this tutorial. To configure a public OIDC client, refer to the OIDC Provider documentation.
Prerequisites
To perform the tasks described in this tutorial, you need to have:
A Nomad environment. Refer to the get started tutorials to install Nomad and create a cluster.
A Vault environment of version 1.10 or later. Refer to the Getting Started tutorial to install Vault locally or create a Vault cluster on HCP.
NOTE: This feature was first introduced in Vault 1.9 as a Technical Preview feature. As of Vault 1.10, it is generally available.
Policy requirements
For the purpose of this tutorial, you will use the root
token to work with Vault
running in development mode.
When you are working with a non-development Vault environment, your token policy must include the following permissions:
Refer to the Vault policies tutorial for more information.
Lab setup
Start Vault
In your terminal, start a Vault development server with root
as the root token.
The Vault development server defaults to running at 127.0.0.1:8200
. The server is now
initialized and unsealed.
Warning
Do not run a Vault development server in production. This approach starts a Vault server with an in-memory database and is only for testing purposes.
Open another terminal session, and export an environment variable for the address to the Vault server.
Export an environment variable for the Vault token.
Note: For these tasks, you can use Vault's root token. However, we recommend that you use root tokens only for the initial setup or in emergencies. As a best practice, use an authentication method or token that meets the policy requirements.
The Vault server is ready.
Configure Vault authentication
Vault auth methods authenticate and assign identity and policies to a client. When Vault acts as an OIDC provider, it is the source of identity and these auth methods verify that identity.
Enable the userpass auth method at the default path.
Create a user named
end-user
with the passwordpassword
.This user authenticates with Vault and is assigned the default access policy.
Learn More: For more information refer to the Userpass Auth Method documentation.
Create Vault identity entity and group
A client may have multiple accounts with various identity providers that are enabled on the Vault server. Vault clients can be mapped as entities and their corresponding accounts with authentication providers can be mapped as aliases.
Create an identity entity with details about the
end-user
.Create an environment variable named
ENTITY_ID
that stores the ID assigned to the entity.Create an identity group with the name
engineering
and addend-user
as a member.Create an environment variable named
GROUP_ID
that stores the ID assigned to the group.The
end-user
entity is a member of theengineering
group. An entity alias maps an entity to client of an authentication method. This mapping requires the entity ID and the authentication accessor ID.Create a variable named
USERPASS_ACCESSOR
that stores the accessor value of the userpass authentication method.Create an entity alias that maps the
end-user
entity with theend-user
user.The entity and the user are aliases of one another.
Learn More: Learn more about identity in the entities and groups tutorial.
Create a Vault OIDC client
A Vault OIDC client connects a resource called an OIDC assignment, an encryption key, a client callback URL and a time-to-live on verification together.
An OIDC assignment describes the list of the Vault entities and groups allowed to authenticate with this client.
Create an assignment named
my-assignment
that authorizes theend-user
entity andengineering
group.The Vault OIDC authentication process requires an encryption key to sign and verify the JSON web tokens (JWT) that are produced by the authentication flow.
Create a key named
my-key
.The key is usable by all Vault OIDC clients as
allowed_client_ids
is set to*
.Create an OIDC client named
nomad
.The
redirect_uris
flag describes the callback URL for the client, the value is the address of a Nomad service running on its default port. Theassignments
flag limits access to only the entities and groups defined inmy-assignment
. Theid_token_ttl
flag sets the expiration on the ID token to 30 minutes. Theaccess_token_ttl
flag sets the expiration of the access token to 1 hour.Create an environment variable named CLIENT_ID to store the
client_id
field of thenomad
client.
Create a Vault OIDC provider
A Vault OIDC provider supports one or more clients and Vault OIDC scopes. These scopes define metadata claims expressed in a template. Claims are key-value pairs that contain information about a user and the OIDC service.
Create an environment variable named
USER_SCOPE_TEMPLATE
that stores the user scope template.Define a Vault OIDC scope named
user
with the user scope template.Create an environment variable named
GROUPS_SCOPE_TEMPLATE
that stores the group scope. template.This template retrieves the names of all the groups defined.
Define a Vault OIDC scope named
groups
with the groups scope template.Create a Vault OIDC provider named
my-provider
and provide it a list of client IDs and scopes. The provider grants access to thenomad
client.
Display the Vault OIDC configuration endpoint.
Show Vault OIDC public keys.
Start Nomad
The Nomad development agent brings up an instance of Nomad with a server and client. Refer to the start a cluster tutorial for more information.
In another terminal, start a Nomad agent in development mode with ACL enabled.
The Nomad server is ready.
Configure Nomad OIDC auth
Create an environment variable named
ISSUER
that stores theissuer
field of the Vault OIDC provider namedmy-provider
.Create an environment variable named
CLIENT_SECRET
that stores theclient_secret
field of the Vault OIDC client namednomad
.Run the bootstrap process, store the value of the management token, and export it as the
NOMAD_TOKEN
environment variable.Create a Nomad policy that allows read access to the "default" namespace.
Create a file named
acl_policy_engineering_read.hcl
, add the following contents, and save the file.Apply the policy.
Create a corresponding role that contains the policies to assign to engineers.
Create a configuration for the OIDC auth method.
Create a file named
acl_auth_method.json
, add the following contents, replace$ISSUER
,$CLIENT_ID
and$CLIENT_SECRET
with the values stored in their respective environment variables, and save the file.The
ListClaimMappings
field specifies which claims of the OIDC provider should be mapped to which ACL concepts of Nomad. The Vault "group" created before will map to a "role" in Nomad.Create a new OIDC authentication method and configure it to use the Vault OIDC provider.
Create a binding rule to evaluate OIDC claims into Nomad policies and roles.
Nomad OIDC authentication is configured and ready for the end-user
to
authenticate.
Authenticate with Nomad
Authenticate to Nomad. The -method
flag is optional since vault
has been configured as the default method.
The Vault login screen will open in your browser. Select Username from the
Method dropdown selection and enter end-user
and password
as the credentials.
The nomad login
command confirms the authentication was successful and
displays the Nomad ACL token generated.
Next steps
In this tutorial, you configured Vault as an OIDC provider with Nomad as a client. Learn more about configuring Vault as an OIDC provider.
To learn more about Nomad ACL, check out the access control tutorials.