You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/index.md
+26-3Lines changed: 26 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,8 +16,7 @@ If you are using the legacy Wildfly distribution of Keycloak, you will need to s
16
16
17
17
## Keycloak Setup
18
18
19
-
This Terraform provider can be configured to use the [client credentials](https://www.oauth.com/oauth2-servers/access-tokens/client-credentials/)
20
-
or [password](https://www.oauth.com/oauth2-servers/access-tokens/password-grant/) grant types. If you aren't
19
+
This Terraform provider can be configured to use the [client credentials](https://www.oauth.com/oauth2-servers/access-tokens/client-credentials/) or [password](https://www.oauth.com/oauth2-servers/access-tokens/password-grant/) grant types. If you aren't
21
20
sure which to use, the client credentials grant is recommended, as it was designed for machine to machine authentication.
22
21
23
22
### Client Credentials Grant Setup (recommended)
@@ -31,6 +30,18 @@ like to manage your entire Keycloak instance, or in any other realm if you only
31
30
1. Set `Service Accounts Enabled` to `ON`.
32
31
1. Grant required roles for managing Keycloak via the `Service Account Roles` tab in the client you created in step 1, see [Assigning Roles](#assigning-roles) section below.
33
32
33
+
Out of the many [authentication methods](https://openid.net/specs/openid-connect-core-1_0.html#ClientAuthentication) of the client credentials grant type, this Terraform provider supports the authentication using the `client secret` or the `private key signed JWT`.
34
+
35
+
#### Client Secret Authentication Type Setup
36
+
37
+
This is the default client authentication type and requires no further step.
38
+
39
+
#### Private Key Signed JWT Authentication Type Setup
40
+
These steps assume that you have already followed the steps for the client credentials grant and have created the client `terraform`.
41
+
42
+
1. Change the `Client authenticator` in the `Credentials`tab to `Signed JWT`.
43
+
1. Generate or import a key pair via `Keys`. In case the key pair is generated by the Keycloak server, a keystore file would be downloaded and you have to extract the private key and keep it safe.
44
+
34
45
### Password Grant Setup
35
46
36
47
These steps will assume that you are using the `admin-cli` client, which is already correctly configured for this type
@@ -52,7 +63,7 @@ account within the `foo` realm.
52
63
the realm clients to a user or service account within the `master` realm. For example, given a Keycloak instance with realms
53
64
`master`, `foo`, and `bar`, assign the `create-client` client role from the clients `master-realm`, `foo-realm`, and `bar-realm`.
54
65
55
-
## Example Usage (client credentials grant)
66
+
## Example Usage (client credentials grant - client secret)
56
67
57
68
```hcl
58
69
provider "keycloak" {
@@ -62,6 +73,16 @@ provider "keycloak" {
62
73
}
63
74
```
64
75
76
+
## Example Usage (client credentials grant - private key signed JWT)
77
+
78
+
```hcl
79
+
provider "keycloak" {
80
+
client_id = "terraform"
81
+
jwt_signing_key = "<pem-formatted-private-key>"
82
+
url = "http://localhost:8080"
83
+
}
84
+
```
85
+
65
86
## Example Usage (password grant)
66
87
67
88
```hcl
@@ -82,6 +103,8 @@ The following arguments are supported:
82
103
-`client_secret` - (Optional) The secret for the client used by the provider for authentication via the client credentials grant. This can be found or changed using the "Credentials" tab in the client settings. Defaults to the environment variable `KEYCLOAK_CLIENT_SECRET`. This attribute is required when using the client credentials grant, and cannot be set when using the password grant.
83
104
-`username` - (Optional) The username of the user used by the provider for authentication via the password grant. Defaults to the environment variable `KEYCLOAK_USER`. This attribute is required when using the password grant, and cannot be set when using the client credentials grant.
84
105
-`password` - (Optional) The password of the user used by the provider for authentication via the password grant. Defaults to the environment variable `KEYCLOAK_PASSWORD`. This attribute is required when using the password grant, and cannot be set when using the client credentials grant.
106
+
-`jwt_signing_key` - (Optional) The PEM-formatted private key used by provider to generate a signed JWT for authentication.
107
+
-`jwt_signing_alg` - (Optional) The signing algorithm used by provider to generate a signed JWT for authentication. Defaults to `RS256`.
85
108
-`realm` - (Optional) The realm used by the provider for authentication. Defaults to the environment variable `KEYCLOAK_REALM`, or `master` if the environment variable is not specified.
86
109
-`initial_login` - (Optional) Optionally avoid Keycloak login during provider setup, for when Keycloak itself is being provisioned by terraform. Defaults to true, which is the original method.
87
110
-`client_timeout` - (Optional) Sets the timeout of the client when addressing Keycloak, in seconds. Defaults to the environment variable `KEYCLOAK_CLIENT_TIMEOUT`, or `15` if the environment variable is not specified.
returnnil, fmt.Errorf("must specify client id, username and password for password grant, or client id and secret for client credentials grant")
85
+
returnnil, fmt.Errorf("must specify client id, username and password for password grant, either client id and client secret or JWT Signing Key for client credentials grant")
77
86
} else {
78
87
tflog.Warn(ctx, "missing required keycloak credentials, but proceeding anyways as initial_login is false")
0 commit comments