Skip to content

Instantly share code, notes, and snippets.

@r6m
Last active November 18, 2021 12:59
Show Gist options
  • Save r6m/51d83358b0b16db59d458b2cba47b54d to your computer and use it in GitHub Desktop.
Save r6m/51d83358b0b16db59d458b2cba47b54d to your computer and use it in GitHub Desktop.
hashicorp vault OIDC authentication

installation

after installing vault run the following command to login:

the root token is printed to stdout on the first run.

$ vault login -method=token [your root token]

OIDC (openid connect)

write down your oidc configs, such as client_id and client_secret ...

enable oidc method in vault:

$ vault auth enable oidc

set oidc config in vault:

$ vault write auth/oidc/config \
  oidc_discovery_url="[provider url]" \
  oidc_client_id="[client_id]" \
  oidc_client_secret="[client_secret]" \
  default_role="reader" \
  oidc_scopes="openid profile email phone address groups" \
  bound_issuer="localhost"

create a reader policy in vault, we are going to assign this policy to our role:

path "secret/*" {
	capabilities = ["read", "list"]
}

create a role for our oidc, here we create a reader role

$ vault write auth/oidc/role/reader \
  bound_audiences="[client_id]" \
  allowed_redirect_uris="http://localhost:8200/ui/vault/auth/oidc/oidc/callback" \
  allowed_redirect_uris="http://localhost:8250/oidc/callback" \
  groups_claim="groups" \
  user_claim="sub" \
  policies=reader

login to vault using oidc method. this command opens your browser to log you in.

$ vault login -method=oidc role=reader

NOTE

after a successful login in any of above methods, if you want to change something in vault that requires root permissions, you need to login again with token method with the following command:

$ vault login -method=token [token]
@r6m
Copy link
Author

r6m commented Nov 18, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment