Skip to content

Commit

Permalink
Merge pull request #56 from hervekhg/master
Browse files Browse the repository at this point in the history
Allow certificate Authentication
  • Loading branch information
Mongey authored May 14, 2024
2 parents da0448f + 7db3283 commit 6caa48c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
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 @@ package connect

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

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -29,6 +30,20 @@ func Provider() *schema.Provider {
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 Down Expand Up @@ -58,6 +73,23 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}
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

0 comments on commit 6caa48c

Please sign in to comment.