Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow certificate Authentication #56

Merged
merged 6 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ provider "kafka-connect" {
url = "http://localhost:8083"
basic_auth_username = "user" # Optional
basic_auth_password = "password" # Optional

# For TLS
tls_auth_crt = "/tmp/cert.pem" # Optional
tls_auth_key = "/tmp/key.pem " # Optional
tls_auth_is_insecure = true # Optionnal if you do not want to check CA
}

resource "kafka-connect_connector" "sqlite-sink" {
Expand All @@ -40,11 +45,14 @@ resource "kafka-connect_connector" "sqlite-sink" {

## Provider Properties

| Property | Type | Example | Alternative environment variable name |
|-----------------------|-------------------|-------------------------|---------------------------------------|
| `url` | URL | "http://localhost:8083" | `KAFKA_CONNECT_URL` |
| `basic_auth_username` | String | "user" | `KAFKA_CONNECT_BASIC_AUTH_USERNAME` |
| `basic_auth_password` | String | "password" | `KAFKA_CONNECT_BASIC_AUTH_PASSWORD` |
| Property | Type | Example | Alternative environment variable name |
|-----------------------|--------|-------------------------|---------------------------------------|
| `url` | URL | "http://localhost:8083" | `KAFKA_CONNECT_URL` |
| `basic_auth_username` | String | "user" | `KAFKA_CONNECT_BASIC_AUTH_USERNAME` |
| `basic_auth_password` | String | "password" | `KAFKA_CONNECT_BASIC_AUTH_PASSWORD` |
| `tls_auth_crt` | String | "certificate" | `KAFKA_CONNECT_TLS_AUTH_CRT` |
| `tls_auth_key` | String | "Key" | `KAFKA_CONNECT_TLS_AUTH_KEY` |
| `tls_auth_is_insecure`| String | "Key" | `KAFKA_CONNECT_TLS_IS_INSECURE` |
| `headers` | Map[String]String | {foo = "bar"} | N/A |

## Resource Properties
Expand Down
32 changes: 32 additions & 0 deletions connect/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import (
"context"
"crypto/tls"
"log"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -29,6 +30,20 @@
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("KAFKA_CONNECT_BASIC_AUTH_PASSWORD", ""),
},
"tls_auth_crt": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("KAFKA_CONNECT_TLS_AUTH_CRT", ""),
},
"tls_auth_key": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("KAFKA_CONNECT_TLS_AUTH_KEY", ""),
},
"tls_auth_is_insecure": {
Type: schema.TypeBool,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("KAFKA_CONNECT_TLS_IS_INSECURE", ""),
"headers": {
Type: schema.TypeMap,
Elem: &schema.Schema{
Expand All @@ -43,8 +58,8 @@
ResourcesMap: map[string]*schema.Resource{
"kafka-connect_connector": kafkaConnectorResource(),
},
}

Check failure on line 61 in connect/provider.go

View workflow job for this annotation

GitHub Actions / test

syntax error: unexpected newline, expecting comma or }

Check failure on line 61 in connect/provider.go

View workflow job for this annotation

GitHub Actions / test

syntax error: unexpected newline, expecting comma or }

Check failure on line 61 in connect/provider.go

View workflow job for this annotation

GitHub Actions / acctest

syntax error: unexpected newline, expecting comma or }

Check failure on line 61 in connect/provider.go

View workflow job for this annotation

GitHub Actions / acctest

syntax error: unexpected newline, expecting comma or }
log.Printf("[INFO] Created provider: %v", provider)

Check failure on line 62 in connect/provider.go

View workflow job for this annotation

GitHub Actions / test

syntax error: unexpected ) at end of statement

Check failure on line 62 in connect/provider.go

View workflow job for this annotation

GitHub Actions / test

syntax error: unexpected ) at end of statement

Check failure on line 62 in connect/provider.go

View workflow job for this annotation

GitHub Actions / acctest

syntax error: unexpected ) at end of statement

Check failure on line 62 in connect/provider.go

View workflow job for this annotation

GitHub Actions / acctest

syntax error: unexpected ) at end of statement
return &provider
}

Expand All @@ -58,6 +73,23 @@
c.SetBasicAuth(user, pass)
}

crt := d.Get("tls_auth_crt").(string)
key := d.Get("tls_auth_key").(string)
is_insecure := d.Get("tls_auth_is_insecure").(bool)
log.Printf("[INFO]Cert : %s\nKey: %s", crt, key)
log.Printf("[INFO]SSl connection is insecure : %t", is_insecure)

if crt != "" && key != "" {
cert, err := tls.LoadX509KeyPair(crt, key)
if err != nil {
log.Fatalf("client: loadkeys: %s", err)
} else {
if is_insecure {
c.SetInsecureSSL()
}
c.SetClientCertificates(cert)
}
}
headers := d.Get("headers").(map[string]interface{})
if headers != nil {
for k, v := range headers {
Expand Down
Loading