Skip to content

Commit

Permalink
adds tls_insecure_skip_verify provider attribute (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
Filirom1 authored Mar 18, 2020
1 parent 04ff59d commit dab151b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions keycloak/keycloak_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,23 @@ 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,
})

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 != "" {
Expand Down
2 changes: 1 addition & 1 deletion keycloak/keycloak_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
9 changes: 8 additions & 1 deletion provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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)
}

0 comments on commit dab151b

Please sign in to comment.