diff --git a/docs/index.md b/docs/index.md index d8b1719e0..a9f403ee8 100644 --- a/docs/index.md +++ b/docs/index.md @@ -57,6 +57,7 @@ The following provider attributes are supported: - `realm` (Optional) - The realm used by the provider for authentication. Defaults to environment variable `KEYCLOAK_REALM`, or `master` if the environment variable is not specified. - `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. - `client_timeout` (Optional) - Sets the timeout of the client when addressing Keycloak, in seconds. Defaults to environment variable `KEYCLOAK_CLIENT_TIMEOUT`, or 5 is the environment variable is not specified. +- `tls_insecure_skip_verify` (Optional) - Allows ignoring insecure certificates when set to true. Defaults to false. Disabling security check is dangerous and should be avoided. - `root_ca_certificate` (Optional) - Allows x509 calls using an unknown CA certificate (for development purposes) #### Example (client credentials) diff --git a/keycloak/keycloak_client.go b/keycloak/keycloak_client.go index fce3701cc..b2c04ea9e 100644 --- a/keycloak/keycloak_client.go +++ b/keycloak/keycloak_client.go @@ -43,7 +43,7 @@ const ( tokenUrl = "%s/auth/realms/%s/protocol/openid-connect/token" ) -func NewKeycloakClient(baseUrl, clientId, clientSecret, realm, username, password string, initialLogin bool, clientTimeout int, caCert string) (*KeycloakClient, error) { +func NewKeycloakClient(baseUrl, clientId, clientSecret, realm, username, password string, initialLogin bool, clientTimeout int, caCert string, tlsInsecureSkipVerify bool) (*KeycloakClient, error) { cookieJar, err := cookiejar.New(&cookiejar.Options{ PublicSuffixList: publicsuffix.List, }) @@ -51,10 +51,15 @@ func NewKeycloakClient(baseUrl, clientId, clientSecret, realm, username, passwor if err != nil { return nil, err } + transport := &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: tlsInsecureSkipVerify}, + Proxy: http.ProxyFromEnvironment, + } httpClient := &http.Client{ - Timeout: time.Second * time.Duration(clientTimeout), - Jar: cookieJar, + Timeout: time.Second * time.Duration(clientTimeout), + Transport: transport, + Jar: cookieJar, } if caCert != "" { diff --git a/keycloak/keycloak_client_test.go b/keycloak/keycloak_client_test.go index f640f49ed..7c33c9fe9 100644 --- a/keycloak/keycloak_client_test.go +++ b/keycloak/keycloak_client_test.go @@ -51,7 +51,7 @@ func TestAccKeycloakApiClientRefresh(t *testing.T) { t.Fatal("KEYCLOAK_CLIENT_TIMEOUT must be an integer") } - keycloakClient, err := NewKeycloakClient(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, "") + keycloakClient, err := NewKeycloakClient(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) if err != nil { t.Fatalf("%s", err) } diff --git a/provider/provider.go b/provider/provider.go index 5bd281123..14153444b 100644 --- a/provider/provider.go +++ b/provider/provider.go @@ -126,6 +126,12 @@ func KeycloakProvider() *schema.Provider { Description: "Allows x509 calls using an unknown CA certificate (for development purposes)", Default: "", }, + "tls_insecure_skip_verify": { + Optional: true, + Type: schema.TypeBool, + Description: "Allows ignoring insecure certificates when set to true. Defaults to false. Disabling security check is dangerous and should be avoided.", + Default: false, + }, }, ConfigureFunc: configureKeycloakProvider, } @@ -140,7 +146,8 @@ func configureKeycloakProvider(data *schema.ResourceData) (interface{}, error) { realm := data.Get("realm").(string) initialLogin := data.Get("initial_login").(bool) clientTimeout := data.Get("client_timeout").(int) + tlsInsecureSkipVerify := data.Get("tls_insecure_skip_verify").(bool) rootCaCertificate := data.Get("root_ca_certificate").(string) - return keycloak.NewKeycloakClient(url, clientId, clientSecret, realm, username, password, initialLogin, clientTimeout, rootCaCertificate) + return keycloak.NewKeycloakClient(url, clientId, clientSecret, realm, username, password, initialLogin, clientTimeout, rootCaCertificate, tlsInsecureSkipVerify) }