Skip to content

Commit 1dee011

Browse files
committed
Override ClientOptions.User if KerberosClient is set
This prevents a subtle misconfiguration whereby User being set prevents the realm from being set, which then breaks any communication with the namenode.
1 parent ff27ef8 commit 1dee011

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ type ClientOptions struct {
5757
// Addresses specifies the namenode(s) to connect to.
5858
Addresses []string
5959
// User specifies which HDFS user the client will act as. It is required
60-
// unless kerberos authentication is enabled, in which case it will be
61-
// determined from the provided credentials if empty.
60+
// unless kerberos authentication is enabled, in which case it is overridden
61+
// by the username set in KerberosClient.
6262
User string
6363
// UseDatanodeHostname specifies whether the client should connect to the
6464
// datanodes via hostname (which is useful in multi-homed setups) or IP

internal/rpc/namenode.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ type NamenodeConnectionOptions struct {
5858
// Addresses specifies the namenode(s) to connect to.
5959
Addresses []string
6060
// User specifies which HDFS user the client will act as. It is required
61-
// unless kerberos authentication is enabled, in which case it will be
62-
// determined from the provided credentials if empty.
61+
// unless kerberos authentication is enabled, in which case it is overridden
62+
// by the username set in KerberosClient.
6363
User string
6464
// DialFunc is used to connect to the namenodes. If nil, then
6565
// (&net.Dialer{}).DialContext is used.
@@ -94,14 +94,12 @@ func NewNamenodeConnection(options NamenodeConnectionOptions) (*NamenodeConnecti
9494

9595
var user, realm string
9696
user = options.User
97-
if user == "" {
98-
if options.KerberosClient != nil {
99-
creds := options.KerberosClient.Credentials
100-
user = creds.UserName()
101-
realm = creds.Realm()
102-
} else {
103-
return nil, errors.New("user not specified")
104-
}
97+
if options.KerberosClient != nil {
98+
creds := options.KerberosClient.Credentials
99+
user = creds.UserName()
100+
realm = creds.Realm()
101+
} else if user == "" {
102+
return nil, errors.New("user not specified")
105103
}
106104

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

0 commit comments

Comments
 (0)