Skip to content

Commit 80c4c56

Browse files
committed
Revert "Add X509 TLS client authentication (#10)"
This reverts commit b656057.
1 parent 8a98e3b commit 80c4c56

File tree

5 files changed

+6
-22
lines changed

5 files changed

+6
-22
lines changed

docs/index.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ The following arguments are supported:
8787
- `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.
8888
- `tls_insecure_skip_verify` - (Optional) Allows ignoring insecure certificates when set to `true`. Defaults to `false`. Disabling this security check is dangerous and should only be done in local or test environments.
8989
- `root_ca_certificate` - (Optional) Allows x509 calls using an unknown CA certificate (for development purposes)
90-
- `tls_client_certificate` - (Optional) The TLS client certificate in PEM format when the Keycloak server is configured with TLS mutual authentication.
91-
- `tls_client_auth` - (Optional) When true, also uses the TLS client certificate for Keycloak X509 authentication.
90+
- `tls_client_certificate` - (Optional) The TLS client certificate in PEM format when the keycloak server is configured with TLS mutual authentication.
9291
- `tls_client_private_key` - (Optional) The TLS client pkcs1 private key in PEM format when the keycloak server is configured with TLS mutual authentication.
9392
- `base_path` - (Optional) The base path used for accessing the Keycloak REST API. Defaults to the environment variable `KEYCLOAK_BASE_PATH`, or an empty string if the environment variable is not specified. Note that users of the legacy distribution of Keycloak will need to set this attribute to `/auth`.
9493
- `additional_headers` - (Optional) A map of custom HTTP headers to add to each request to the Keycloak API.

keycloak/keycloak_client.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ type KeycloakClient struct {
3636
additionalHeaders map[string]string
3737
debug bool
3838
redHatSSO bool
39-
tlsClientAuth bool
4039
}
4140

4241
type ClientCredentials struct {
@@ -62,7 +61,7 @@ var redHatSSO7VersionMap = map[int]string{
6261
4: "9.0.17",
6362
}
6463

65-
func NewKeycloakClient(ctx context.Context, url, basePath, clientId, clientSecret, realm, username, password string, initialLogin bool, clientTimeout int, caCert string, tlsClientCert string, tlsClientAuth bool, tlsClientPrivateKey string, tlsInsecureSkipVerify bool, userAgent string, redHatSSO bool, additionalHeaders map[string]string) (*KeycloakClient, error) {
64+
func NewKeycloakClient(ctx context.Context, url, basePath, clientId, clientSecret, realm, username, password string, initialLogin bool, clientTimeout int, caCert string, tlsClientCert string, tlsClientPrivateKey string, tlsInsecureSkipVerify bool, userAgent string, redHatSSO bool, additionalHeaders map[string]string) (*KeycloakClient, error) {
6665
clientCredentials := &ClientCredentials{
6766
ClientId: clientId,
6867
ClientSecret: clientSecret,
@@ -73,8 +72,6 @@ func NewKeycloakClient(ctx context.Context, url, basePath, clientId, clientSecre
7372
clientCredentials.GrantType = "password"
7473
} else if clientSecret != "" {
7574
clientCredentials.GrantType = "client_credentials"
76-
} else if tlsClientAuth {
77-
clientCredentials.GrantType = "client_credentials"
7875
} else {
7976
if initialLogin {
8077
return nil, fmt.Errorf("must specify client id, username and password for password grant, or client id and secret for client credentials grant")
@@ -97,7 +94,6 @@ func NewKeycloakClient(ctx context.Context, url, basePath, clientId, clientSecre
9794
userAgent: userAgent,
9895
redHatSSO: redHatSSO,
9996
additionalHeaders: additionalHeaders,
100-
tlsClientAuth: tlsClientAuth,
10197
}
10298

10399
if keycloakClient.initialLogin {
@@ -275,14 +271,10 @@ func (keycloakClient *KeycloakClient) getAuthenticationFormData() url.Values {
275271
authenticationFormData.Set("client_secret", keycloakClient.clientCredentials.ClientSecret)
276272
}
277273

278-
} else if keycloakClient.clientCredentials.GrantType == "client_credentials" && keycloakClient.clientCredentials.ClientSecret != "" {
274+
} else if keycloakClient.clientCredentials.GrantType == "client_credentials" {
279275
authenticationFormData.Set("client_secret", keycloakClient.clientCredentials.ClientSecret)
280276
}
281277

282-
if keycloakClient.tlsClientAuth {
283-
authenticationFormData.Set("client_assertion_type", "urn:ietf:params:oauth:client-assertion-type:tls_client_auth")
284-
}
285-
286278
return authenticationFormData
287279
}
288280

keycloak/keycloak_client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func TestAccKeycloakApiClientRefresh(t *testing.T) {
4949
t.Fatal("KEYCLOAK_CLIENT_TIMEOUT must be an integer")
5050
}
5151

52-
keycloakClient, err := NewKeycloakClient(ctx, os.Getenv("KEYCLOAK_URL"), "", os.Getenv("KEYCLOAK_CLIENT_ID"), os.Getenv("KEYCLOAK_CLIENT_SECRET"), os.Getenv("KEYCLOAK_REALM"), os.Getenv("KEYCLOAK_USER"), os.Getenv("KEYCLOAK_PASSWORD"), true, clientTimeout, "", "", false, "", false, "", false, map[string]string{
52+
keycloakClient, err := NewKeycloakClient(ctx, os.Getenv("KEYCLOAK_URL"), "", os.Getenv("KEYCLOAK_CLIENT_ID"), os.Getenv("KEYCLOAK_CLIENT_SECRET"), os.Getenv("KEYCLOAK_REALM"), os.Getenv("KEYCLOAK_USER"), os.Getenv("KEYCLOAK_PASSWORD"), true, clientTimeout, "", "", "", false, "", false, map[string]string{
5353
"foo": "bar",
5454
})
5555
if err != nil {

provider/provider.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,6 @@ func KeycloakProvider(client *keycloak.KeycloakClient) *schema.Provider {
180180
Description: "Allows ignoring insecure certificates when set to true. Defaults to false. Disabling security check is dangerous and should be avoided.",
181181
Default: false,
182182
},
183-
"tls_client_auth": {
184-
Optional: true,
185-
Type: schema.TypeString,
186-
Description: "When true, uses also the TLS client certificate for authentication in Keycloak",
187-
Default: "",
188-
},
189183
"tls_client_certificate": {
190184
Optional: true,
191185
Type: schema.TypeString,
@@ -235,7 +229,6 @@ func KeycloakProvider(client *keycloak.KeycloakClient) *schema.Provider {
235229
clientTimeout := data.Get("client_timeout").(int)
236230
tlsInsecureSkipVerify := data.Get("tls_insecure_skip_verify").(bool)
237231
tlsClientCertificate := data.Get("tls_client_certificate").(string)
238-
tlsClientAuth := data.Get("tls_client_auth").(bool)
239232
tlsClientPrivateKey := data.Get("tls_client_private_key").(string)
240233
rootCaCertificate := data.Get("root_ca_certificate").(string)
241234
redHatSSO := data.Get("red_hat_sso").(bool)
@@ -248,7 +241,7 @@ func KeycloakProvider(client *keycloak.KeycloakClient) *schema.Provider {
248241

249242
userAgent := fmt.Sprintf("HashiCorp Terraform/%s (+https://www.terraform.io) Terraform Plugin SDK/%s", provider.TerraformVersion, meta.SDKVersionString())
250243

251-
keycloakClient, err := keycloak.NewKeycloakClient(ctx, url, basePath, clientId, clientSecret, realm, username, password, initialLogin, clientTimeout, rootCaCertificate, tlsClientCertificate, tlsClientAuth, tlsClientPrivateKey, tlsInsecureSkipVerify, userAgent, redHatSSO, additionalHeaders)
244+
keycloakClient, err := keycloak.NewKeycloakClient(ctx, url, basePath, clientId, clientSecret, realm, username, password, initialLogin, clientTimeout, rootCaCertificate, tlsClientCertificate, tlsClientPrivateKey, tlsInsecureSkipVerify, userAgent, redHatSSO, additionalHeaders)
252245
if err != nil {
253246
diags = append(diags, diag.Diagnostic{
254247
Severity: diag.Error,

provider/provider_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func init() {
6060
}
6161
}
6262

63-
keycloakClient, err = keycloak.NewKeycloakClient(testCtx, os.Getenv("KEYCLOAK_URL"), "", os.Getenv("KEYCLOAK_CLIENT_ID"), os.Getenv("KEYCLOAK_CLIENT_SECRET"), os.Getenv("KEYCLOAK_REALM"), "", "", true, 5, "", "", false, "", false, userAgent, false, map[string]string{
63+
keycloakClient, err = keycloak.NewKeycloakClient(testCtx, os.Getenv("KEYCLOAK_URL"), "", os.Getenv("KEYCLOAK_CLIENT_ID"), os.Getenv("KEYCLOAK_CLIENT_SECRET"), os.Getenv("KEYCLOAK_REALM"), "", "", true, 5, "", "", "", false, userAgent, false, map[string]string{
6464
"foo": "bar",
6565
})
6666
if err != nil {

0 commit comments

Comments
 (0)