forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Kerberos support to Kafka input and output (elastic#16871)
## What does this PR do? This PR adds initial Kerberos support to Kafka input and output. Until end to end tests are added or there are no bugs reported after the release, I am marking it as beta. ## Why is it important? This lets Beats connect to Kerberos-aware Kafka instances. Users have two options when authenticating to Kerberos - using a keytab file or providing a username and password pair. #### Example authentication using keytab file ```yaml # Authentication type to use with Kerberos. Available options: keytab, password. kerberos.auth_type: keytab # Path to the keytab file. It is used when auth_type is set to keytab. kerberos.keytab: /etc/krb5kdc/kafka.keytab # Path to the Kerberos configuration. kerberos.config_path: /etc/path/config # The service principal name. kerberos.service_name: HTTP/kafka@ELASTIC # Kerberos realm. kerberos.realm: ELASTIC ``` #### Example authentication using username and password ```yaml # Authentication type to use with Kerberos. Available options: keytab, password. kerberos.auth_type: password # Path to the Kerberos configuration. kerberos.config_path: /etc/path/config # The service principal name. kerberos.service_name: HTTP/kafka@ELASTIC # Name of the Kerberos user. It is used when auth_type is set to password. kerberos.username: elastic # Password of the Kerberos user. It is used when auth_type is set to password. kerberos.password: changeme # Kerberos realm. kerberos.realm: ELASTIC ```
- Loading branch information
Showing
17 changed files
with
408 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package kerberos | ||
|
||
import "fmt" | ||
|
||
type AuthType uint | ||
|
||
const ( | ||
AUTH_PASSWORD = 1 | ||
AUTH_KEYTAB = 2 | ||
|
||
authPassword = "password" | ||
authKeytabStr = "keytab" | ||
) | ||
|
||
var ( | ||
authTypes = map[string]AuthType{ | ||
authPassword: AUTH_PASSWORD, | ||
authKeytabStr: AUTH_KEYTAB, | ||
} | ||
) | ||
|
||
type Config struct { | ||
AuthType AuthType `config:"auth_type" validate:"required"` | ||
KeyTabPath string `config:"keytab"` | ||
ConfigPath string `config:"config_path"` | ||
ServiceName string `config:"service_name"` | ||
Username string `config:"username"` | ||
Password string `config:"password"` | ||
Realm string `config:"realm"` | ||
} | ||
|
||
// Unpack validates and unpack "auth_type" config option | ||
func (t *AuthType) Unpack(value string) error { | ||
authT, ok := authTypes[value] | ||
if !ok { | ||
return fmt.Errorf("invalid authentication type '%s'", value) | ||
} | ||
|
||
*t = authT | ||
|
||
return nil | ||
} | ||
|
||
func (c *Config) Validate() error { | ||
if c.AuthType == AUTH_PASSWORD { | ||
if c.Username == "" { | ||
return fmt.Errorf("password authentication is selected for Kerberos, but username is not configured") | ||
} | ||
if c.Password == "" { | ||
return fmt.Errorf("password authentication is selected for Kerberos, but password is not configured") | ||
} | ||
} | ||
|
||
if c.AuthType == AUTH_KEYTAB { | ||
if c.KeyTabPath == "" { | ||
return fmt.Errorf("keytab authentication is selected for Kerberos, but path to keytab is not configured") | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.