Error 401 running chef report on Chef workstation 21.5.420

Hello,

Running chef report I get error 401, while knife search node still works

PS C:\Users\pni0bey\.chef> chef report nodes -n myserver.mydomain
Analyzing nodes...
Error: unable to get node(s) information: POST https://mychefserver/organizations/myorga/search/node?q=%2A%3A%2A&rows=1000&sort=X_CHEF_id_CHEF_X+asc&start=0: 401
Usage:
  chef report nodes [flags]
  
PS C:\Users\pni0bey\.chef> knife search node 'name:myserver.mydomain'
1 items found

Node Name:   myserver.mydomain
Environment: _default
FQDN:        myserver.mydomain
IP:          10.*.*.*
Run List:    role[is4f_mqclient], role[is4f_perl], role[is4f_dimensionsagent], role[prd_ucdJavaUpgrade_1-0-0]
Roles:       is4f_mqclient, prd_mqclient_1-1-3, is4f_perl, prd_perl_1-1-0, is4f_dimensionsagent, prd_dimensionsagent_1-3-5, prd_ucdJavaUpgrade_1-0-0
Recipes:     is4f_mqclient::default, IS4F_perl, IS4F_perl::default, IS4F_dimensionsagent, IS4F_dimensionsagent::default, is4f_ucdjavaUpgrade::default, IS4F_perl::checkNodeStatus, IS4F_dimensionsagent::map
Platform:    windows 6.3.9600
Tags:

The config.rb file and credentials file in ~/.chef folder contain the same chef_server_url & same client_key, yet this error appears.
I suspected the credentials file was also a ruby file, so I also tried escaping backslashes in this file, but to no avail.
So, my question is, for the credentials file, do we need another chef_server_url than the one in knife's config.rb? Thanks so much.

In the meantime I found that config.rb & credentials file are mutually exclusive; but same error after renaming config.rb to config.rb.old

Hi,

Please submit a ticket if you have a support account.

Otherwise, yes, it looks like your 401 is coming from either an invalid key, a missing key, or the wrong key being configured when running chef report nodes.

You can find the docs at Upgrade Lab: Chef Infra Client 12 to latest

Hey there! I'll get a PR in to get the docs page updated a bit, but for the credentials file, make sure you are using client_name instead of node_name for the user bit -- does this help?

# A working knife config.rb
$ cat ~/chef-repo/.chef/config.rb                                                                                                                                                                 
# See http://docs.chef.io/config_rb.html for more information on knife configuration options

current_dir = File.dirname(__FILE__)
log_level                :info
log_location             STDOUT
node_name                "myuser"
client_key               "#{current_dir}/myuser.pem"
chef_server_url          "https://api.chef.io/organizations/myuser-chef"
cookbook_path            ["#{current_dir}/../cookbooks"]


# Example credentials file based on config.rb
$ cat ~/chef-repo/.chef/credentials 
[default]
client_name = "myuser"
client_key = "/Users/myuser.pem/chef-repo/.chef/myuser.pem"
chef_server_url = "https://api.chef.io/organizations/myuser-chef"
1 Like