-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add kafka kerberos authentication support for collector/ingester
Signed-off-by: Ruben Vargas <[email protected]>
- Loading branch information
1 parent
cf752d7
commit dc68b14
Showing
11 changed files
with
320 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
requires connection to Kafka |
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,60 @@ | ||
// Copyright (c) 2019 The Jaeger Authors. | ||
// | ||
// Licensed 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 auth | ||
|
||
import ( | ||
"log" | ||
"strings" | ||
|
||
"github.com/Shopify/sarama" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
const none = "none" | ||
const kerberos = "kerberos" | ||
|
||
// AuthenticationConfig describes the configuration properties needed authenticate with kafka cluster | ||
type AuthenticationConfig struct { | ||
Authentication string | ||
Kerberos KerberosConfig | ||
} | ||
|
||
//SetConfiguration set configure authentication into sarama config structure | ||
func (config *AuthenticationConfig) SetConfiguration(saramaConfig *sarama.Config) { | ||
authentication := strings.ToLower(config.Authentication) | ||
if strings.Trim(authentication, " ") == "" { | ||
authentication = none | ||
} | ||
switch authentication { | ||
case kerberos: | ||
setKerberosConfiguration(&config.Kerberos, saramaConfig) | ||
case none: | ||
return | ||
default: | ||
log.Fatalf("Unknown/Unsupported authentication method %s to kafka cluster.", config.Authentication) | ||
} | ||
} | ||
|
||
// InitFromViper loads authentication configuration from viper flags. | ||
func (config *AuthenticationConfig) InitFromViper(configPrefix string, v *viper.Viper) { | ||
config.Authentication = v.GetString(configPrefix + suffixAuthentication) | ||
config.Kerberos.ServiceName = v.GetString(configPrefix + kerberosPrefix + suffixKerberosServiceName) | ||
config.Kerberos.Realm = v.GetString(configPrefix + kerberosPrefix + suffixKerberosRealm) | ||
config.Kerberos.UseKeyTab = v.GetBool(configPrefix + kerberosPrefix + suffixKerberosUseKeyTab) | ||
config.Kerberos.Username = v.GetString(configPrefix + kerberosPrefix + suffixKerberosUserName) | ||
config.Kerberos.Password = v.GetString(configPrefix + kerberosPrefix + suffixKerberosPassword) | ||
config.Kerberos.ConfigPath = v.GetString(configPrefix + kerberosPrefix + suffixKerberosConfig) | ||
config.Kerberos.KeyTabPath = v.GetString(configPrefix + kerberosPrefix + suffixKerberosKeyTab) | ||
} |
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,46 @@ | ||
// Copyright (c) 2019 The Jaeger Authors. | ||
// | ||
// Licensed 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 auth | ||
|
||
import ( | ||
"github.com/Shopify/sarama" | ||
) | ||
|
||
// KerberosConfig describes the configuration properties needed for Kerberos authentication with kafka consumer | ||
type KerberosConfig struct { | ||
ServiceName string | ||
Realm string | ||
UseKeyTab bool | ||
Username string | ||
Password string | ||
ConfigPath string | ||
KeyTabPath string | ||
} | ||
|
||
func setKerberosConfiguration(config *KerberosConfig, saramaConfig *sarama.Config) { | ||
saramaConfig.Net.SASL.Mechanism = sarama.SASLTypeGSSAPI | ||
saramaConfig.Net.SASL.Enable = true | ||
if config.UseKeyTab { | ||
saramaConfig.Net.SASL.GSSAPI.KeyTabPath = config.KeyTabPath | ||
saramaConfig.Net.SASL.GSSAPI.AuthType = sarama.KRB5_KEYTAB_AUTH | ||
} else { | ||
saramaConfig.Net.SASL.GSSAPI.AuthType = sarama.KRB5_USER_AUTH | ||
saramaConfig.Net.SASL.GSSAPI.Password = config.Password | ||
} | ||
saramaConfig.Net.SASL.GSSAPI.KerberosConfigPath = config.ConfigPath | ||
saramaConfig.Net.SASL.GSSAPI.Username = config.Username | ||
saramaConfig.Net.SASL.GSSAPI.Realm = config.Realm | ||
saramaConfig.Net.SASL.GSSAPI.ServiceName = config.ServiceName | ||
} |
Oops, something went wrong.