Skip to content

Commit

Permalink
Override ClientOptions.User if KerberosClient is set
Browse files Browse the repository at this point in the history
This prevents a subtle misconfiguration whereby User being set prevents the
realm from being set, which then breaks any communication with the namenode.
  • Loading branch information
colinmarc committed Mar 23, 2022
1 parent ff27ef8 commit 1dee011
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ type ClientOptions struct {
// Addresses specifies the namenode(s) to connect to.
Addresses []string
// User specifies which HDFS user the client will act as. It is required
// unless kerberos authentication is enabled, in which case it will be
// determined from the provided credentials if empty.
// unless kerberos authentication is enabled, in which case it is overridden
// by the username set in KerberosClient.
User string
// UseDatanodeHostname specifies whether the client should connect to the
// datanodes via hostname (which is useful in multi-homed setups) or IP
Expand Down
18 changes: 8 additions & 10 deletions internal/rpc/namenode.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ type NamenodeConnectionOptions struct {
// Addresses specifies the namenode(s) to connect to.
Addresses []string
// User specifies which HDFS user the client will act as. It is required
// unless kerberos authentication is enabled, in which case it will be
// determined from the provided credentials if empty.
// unless kerberos authentication is enabled, in which case it is overridden
// by the username set in KerberosClient.
User string
// DialFunc is used to connect to the namenodes. If nil, then
// (&net.Dialer{}).DialContext is used.
Expand Down Expand Up @@ -94,14 +94,12 @@ func NewNamenodeConnection(options NamenodeConnectionOptions) (*NamenodeConnecti

var user, realm string
user = options.User
if user == "" {
if options.KerberosClient != nil {
creds := options.KerberosClient.Credentials
user = creds.UserName()
realm = creds.Realm()
} else {
return nil, errors.New("user not specified")
}
if options.KerberosClient != nil {
creds := options.KerberosClient.Credentials
user = creds.UserName()
realm = creds.Realm()
} else if user == "" {
return nil, errors.New("user not specified")
}

// The ClientID is reused here both in the RPC headers (which requires a
Expand Down

0 comments on commit 1dee011

Please sign in to comment.