onetwopunch / terraform-vault-okta

Terraform module to configure Vault to use Okta with OIDC
17 stars 12 forks source link

terraform-vault-okta

Terraform configuration to configure Vault with Okta using the OIDC auth plugin

Usage

module "okta" {
  source  = "onetwopunch/okta/vault"
  version = "<version>"

  okta_discovery_url = "<Okta Authorization Server Issuer>"
  okta_client_id     = "<Okta Vault App Client ID>"
  okta_client_secret = "<Okta Vault App Client Secret>"
  vault_addr         = "https://<Vault Domain>:8200"
  okta_bound_audiences = [
    "api://vault",
    "<Okta Vault App Client ID>"
  ]

  roles = {
    okta_admin = {
      token_policies = ["admin"]
      bound_groups   = ["vault_admins"]
    },
    okta_devs = {
      token_policies = ["devs"]
      bound_groups   = ["vault_devs"]
    }
  }
}

Login via the CLI

Login either via the UI or the CLI. If you want to get a local vault token, you'll need to run the following command, which will spin up a listener process by default on port 8250. You can override this with port=xxx in this command but you'll need to also update the redirect URIs in Okta and add the cli_port terraform variable.

vault login -method=oidc -path=okta_oidc role=okta-admin

Setting up Okta OIDC Auth

For this to work, you'll need to be an Okta administrator:

Setting up Groups

Let's create two groups: vault_admins or something similar. These groups will be given permissions to do things within Vault. Within those groups, let's add some users in the Okta Admin console.

Configuring the Authorization Server

Okta has a default authorization server that you can either edit or create another one. You get to this setting by going to Security > API > Authorization Servers. For this, we'll create a new one.

New Authorization Server for Vault

Click Add Authorization Server. For name enter Vault, for audience enter api://vault, and then enter a meaningful description.

Update Groups Claim

Now click into the authz server you just created and go to the Claims tab. We need to add a groups claim so Vault knows what group this user belongs to.

In the Claims tab, click on Add Claim with the following attributes:

Click Create

Access Policy

This policy grants Vault access to read the necessary scopes to the authorization

In the Access Policy tab, click Add Policy and give it the following attributes:

In that policy, we need to add a rule with the following attributes:

The rest of the config is dependent on your standards.

Terraform Variables

Take note of the following fields from this step, which we'll input into Terraform:

Vault Okta Application

We need to actually create a new web application for Vault to pop open the UI for Okta when requested.

Under Applications click, Add Application > Create New App with the following attributes:

Then in the configuration:

Note the <vault-path> denoted in the login URI is whatever value you are planning on using for the mount path for the OIDC plugin. In our case we used okta_oidc

Click Save

Now edit the general settings to ensure:

Click the Sign On tab and edit:

Under Assignments add all the users or groups you want assigned to use Vault.

Under Okta API Scopes you'll need to grant the application acess to the following:

Terraform Variables

Take note of the following fields from this step, which we'll input into Terraform:

Deploy

First export the following variables to point at your Vault cluster

export VAULT_ADDR=https://<vault-domain>:8200
export VAULT_CACERT=<path-to-ca-cert>

Then we use terraform to apply the changes:

terraform apply

Providers

Name Version
vault ~> 2.11

Inputs

Name Description Type Default Required
okta_bound_audiences A list of allowed token audiences list n/a yes
okta_client_id Okta Vault app client ID string n/a yes
okta_client_secret Okta Vault app client secret string n/a yes
okta_discovery_url Okta Authz server Issuer URI: i.e. https://.okta.com/oauth2/ string n/a yes
vault_addr Vault address in the form of https://domain:8200 string n/a yes
cli_port Port to open locally to login with the CLI number 8250 no
okta_allowed_groups Okta group for Vault admins list
[
"vault_admins"
]
no
okta_mount_path Mount path for Okta auth string "okta_oidc" no
roles Map of Vault role names to their bound groups and token policies. Structure looks like this:
roles = {
okta_admin = {
token_policies = ["admin"]
bound_groups = ["vault_admins"]
},
okta_devs = {
token_policies = ["devs"]
bound_groups = ["vault_devs"]
}
}
map {} no
okta_default_lease_ttl Default lease TTL for Vault tokens string "768h" no
okta_max_lease_ttl Maximum lease TTL for Vault tokens string "768h" no
okta_token_type Token type for Vault tokens string "default-service" no

Outputs

Name Description
path Okta OIDC auth path
roles Role names created by this module