Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no available namenodes: SASL handshake: wrong Token ID. Expected 0504, was 607d #338

Open
mountainhua opened this issue May 7, 2024 · 1 comment

Comments

@mountainhua
Copy link

mountainhua commented May 7, 2024

I think it is similar with this issue:#274
here is my code

func newHDFSWithKerberosClient(volume models.Volume) (*HDFSClient, error) {
	addresses := strings.Split(volume.Storage.ServerAddresses, ",")
	credential := volume.Credential.HDFSKerberosCredential
	properties := volume.Storage.PropertiesMap
	kerberosClient, err := newKerberosClientWithKeyTab(
		properties[models.KerberosRealm], properties[models.KerberosKDC], credential)
	if err != nil {
		log.Logger.Error("new kerberos client failed, volume id[%s], err[%v]", volume.ID, err)
		return nil, err
	}

	dialFunc := (&net.Dialer{
		Timeout:   time.Duration(HDFSConnTimeOut) * time.Second,
		KeepAlive: 5 * time.Second,
		DualStack: true,
	}).DialContext

	principalName := strings.Split(volume.Storage.PropertiesMap[models.KerberosNameNodePrincipal], "@")[0]
	option := hdfs.ClientOptions{
		Addresses:                    addresses,
		NamenodeDialFunc:             dialFunc,
		DatanodeDialFunc:             dialFunc,
		KerberosClient:               kerberosClient,
		KerberosServicePrincipleName: principalName,
		DataTransferProtection:       volume.Storage.PropertiesMap[models.DataTransferProtection],
	}

	log.Logger.Info("new hdfs kerberos client volume id[%s], options[%+v]", volume.ID, option)
	client, err := hdfs.NewClient(option)
	if err != nil {
		log.Logger.Error("Create HDFS kerberos client failed, volume id[%s], credential[%+v], principalName[%s], err[%v]",
			volume.ID, credential, principalName, err)
		return nil, err
	}
	return &HDFSClient{Client: client}, nil
}

when it connected to hdfs with Kerberos,it returns no available namenodes: SASL handshake: wrong Token ID. Expected 0504, was 607d.
the error message is occured in this line
Actually, I have no idea what 607d stands for

@meoww-bot
Copy link

Here's my code, hope it helps

func NewHDFSClient(principal, password string, nodenames []string) (*hdfs.Client, error) {

	conf, err := hadoopconf.LoadFromEnvironment()

	principalUser := strings.Split(principal, "@")[0]
	if err != nil {
		slog.Error("Problem loading configuration ", "msg", err)
		return nil, err
	}
	options := hdfs.ClientOptionsFromConf(conf)

	// log.Printf("ClientOptionsFromConf options: %+v\n", options)

	options.Addresses = nodenames
	options.KerberosClient, err = lib.CreateKerberosClientWithPassword(principal, password)
	if err != nil {
		slog.Error("CreateKerberosClientWithPassword error", "msg", err)
		return nil, err
	}
	options.KerberosServicePrincipleName = "nn/_HOST"
	options.DataTransferProtection = "privacy"
	options.User = principalUser

	creds := options.KerberosClient.Credentials

	slog.Debug("options ", "Addresses:", options.Addresses)
	slog.Debug("options ", "KerberosClient:", options.KerberosClient)
	slog.Debug("options ", "KerberosServicePrincipleName:", options.KerberosServicePrincipleName)
	slog.Debug("options ", "User:", options.User)
	slog.Debug("options ", "creds:", options.KerberosClient.Credentials)
	slog.Debug("options ", "creds User", creds.UserName())
	slog.Debug("options ", "creds realm", creds.Realm())

	// log.Printf("reformat options: %+v\n", options)

	client, err := hdfs.NewClient(options)

	if err != nil {
		return nil, err
	}

	return client, nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants