Last active
June 10, 2024 21:48
-
-
Save nastacio/87c6347c1ca5c627770a25f5bf745170 to your computer and use it in GitHub Desktop.
AI Response to prompt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original Prompt | |
> Write the step-by-step instructions for the following problem, grouping the information in sections titled "Overview," "Prerequisites," "Steps," "Validation," "Troubleshooting," and "References." | |
> | |
> I want the result in markdown format that I can use on a README.md file. | |
> | |
> On each step, add a "Command reference" link to the original documentation page describing the commands. | |
> | |
> Here is the problem: | |
> | |
> How do I configure Keycloak as an authentication method for HashiCorp Vault? | |
> | |
> My Keycloak server is running on https://keycloak.server.com, using a custom certificate. The Realm name is "example". | |
> | |
> The Vault server is running on https://vault.server.com | |
Reply: | |
# Overview | |
This tutorial shows how to configure Keycloak as an authentication method for HashiCorp Vault. | |
## Prerequisites | |
- Keycloak server - https://keycloak.server.com | |
- Custom certificate for Keycloak server - https://github.com/myreposotory/blob/main/keycloak/tls.crt | |
- Realm name for Keycloak server - "example" | |
- HashiCorp Vault server - https://vault.server.com | |
## Steps | |
1. Log in to the Vault server using the root token. | |
```sh | |
vault login root | |
``` | |
[Command reference](https://developer.hashicorp.com/vault/docs/commands/login) | |
2. Enable the Keycloak authentication method. | |
```sh | |
vault auth enable keycloak | |
``` | |
[Command reference](https://developer.hashicorp.com/vault/docs/commands/auth/enable) | |
3. Configure the Keycloak authentication method. | |
```sh | |
vault write auth/keycloak/config \ | |
oidc_discovery_url="https://keycloak.server.com/auth/realms/master/.well-known/openid-configuration" \ | |
default_role="oidc-role" \ | |
tls_client_cert_pem=@/path/to/custom-certificate.pem \ | |
tls_client_key_pem=@/path/to/custom-certificate-key.pem | |
``` | |
[Command reference](https://developer.hashicorp.com/vault/docs/commands/write) | |
4. Create a role that maps a user in Keycloak to a set of Vault policies. | |
```sh | |
vault write auth/keycloak/role/oidc-role \ | |
bound_realm="mcsp" \ | |
user_claim="preferred_username" \ | |
groups_claim="groups" \ | |
policies="vault-policy" | |
``` | |
[Command reference](https://developer.hashicorp.com/vault/docs/commands/write) | |
## Validation | |
1. Log in to the Keycloak server using a user account that belongs to the mcsp realm. | |
2. Access the Vault UI at https://vault.server.com/ui and click on the Tokens tab. | |
3. Click on the Create Token button and select the vault-policy policy from the list of policies. | |
4. Click on the Create Token button to generate a new token. | |
5. Copy the generated token and log in to the Vault server using the token. | |
```sh | |
vault login <generated-token> | |
``` | |
[Command reference](https://developer.hashicorp.com/vault/docs/commands/login) | |
6. Verify that the login was successful by checking the output of the vault status command. | |
```sh | |
vault status | |
``` | |
[Command reference](https://developer.hashicorp.com/vault/docs/commands/status) | |
## Troubleshooting | |
If you encounter any issues while following the steps, please refer to the [troubleshooting guide](https://developer.hashicorp.com/vault/docs/platform/k8s/helm/troubleshooting) for Vault Helm charts. | |
## References | |
- [HashiCorp Vault](https://www.vaultproject.io/) | |
- [Keycloak](https://www.keycloak.org/) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment