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

Backport of cli: fixed HOME not set error into release/1.16.x #26244

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/26243.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:bug
cli: fixed a bug where the Vault CLI would error out if
HOME was not set.
```
23 changes: 17 additions & 6 deletions command/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/hashicorp/vault/command/token"
"github.com/hashicorp/vault/helper/namespace"
"github.com/mattn/go-isatty"
"github.com/mitchellh/go-homedir"
"github.com/pkg/errors"
"github.com/posener/complete"
)
Expand Down Expand Up @@ -84,8 +85,13 @@ type BaseCommand struct {
func (c *BaseCommand) Client() (*api.Client, error) {
// Read the test client if present
if c.client != nil {
if err := c.applyHCPConfig(); err != nil {
return nil, err
// Ignoring homedir errors here and moving on to avoid
// spamming user with warnings/errors that homedir isn't set.
path, err := homedir.Dir()
if err == nil {
if err := c.applyHCPConfig(path); err != nil {
return nil, err
}
}

return c.client, nil
Expand Down Expand Up @@ -196,8 +202,13 @@ func (c *BaseCommand) Client() (*api.Client, error) {

c.client = client

if err := c.applyHCPConfig(); err != nil {
return nil, err
// Ignoring homedir errors here and moving on to avoid
// spamming user with warnings/errors that homedir isn't set.
path, err := homedir.Dir()
if err == nil {
if err := c.applyHCPConfig(path); err != nil {
return nil, err
}
}

if c.addrWarning != "" && c.UI != nil {
Expand All @@ -211,12 +222,12 @@ func (c *BaseCommand) Client() (*api.Client, error) {
return client, nil
}

func (c *BaseCommand) applyHCPConfig() error {
func (c *BaseCommand) applyHCPConfig(path string) error {
if c.hcpTokenHelper == nil {
c.hcpTokenHelper = c.HCPTokenHelper()
}

hcpToken, err := c.hcpTokenHelper.GetHCPToken()
hcpToken, err := c.hcpTokenHelper.GetHCPToken(path)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ require (
github.com/hashicorp/raft-boltdb/v2 v2.3.0
github.com/hashicorp/raft-snapshot v1.0.4
github.com/hashicorp/raft-wal v0.4.0
github.com/hashicorp/vault-hcp-lib v0.0.0-20240126195955-473e9a48e7b7
github.com/hashicorp/vault-hcp-lib v0.0.0-20240402205111-2312b38227ab
github.com/hashicorp/vault-plugin-auth-alicloud v0.17.0
github.com/hashicorp/vault-plugin-auth-azure v0.17.0
github.com/hashicorp/vault-plugin-auth-centrify v0.15.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2520,8 +2520,8 @@ github.com/hashicorp/raft-wal v0.4.0/go.mod h1:A6vP5o8hGOs1LHfC1Okh9xPwWDcmb6Vvu
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
github.com/hashicorp/serf v0.10.1 h1:Z1H2J60yRKvfDYAOZLd2MU0ND4AH/WDz7xYHDWQsIPY=
github.com/hashicorp/serf v0.10.1/go.mod h1:yL2t6BqATOLGc5HF7qbFkTfXoPIY0WZdWHfEvMqbG+4=
github.com/hashicorp/vault-hcp-lib v0.0.0-20240126195955-473e9a48e7b7 h1:D9XTgYgpQgdZHToRpJQ6fZwWyOOSpLX3Y+D2aMlxQh4=
github.com/hashicorp/vault-hcp-lib v0.0.0-20240126195955-473e9a48e7b7/go.mod h1:KpSNItDH9ojFPf4UkGCB0vv3cAAwvVxBU2On4EZ0f7c=
github.com/hashicorp/vault-hcp-lib v0.0.0-20240402205111-2312b38227ab h1:n1GzFf7LwpVebVIjh5XKW2IQa/BqI/zPlFg2mmB26dQ=
github.com/hashicorp/vault-hcp-lib v0.0.0-20240402205111-2312b38227ab/go.mod h1:Nb41BTPvmFbKB73D/+XpxIw6Nf2Rt+AOUvLzlDxwAGQ=
github.com/hashicorp/vault-plugin-auth-alicloud v0.17.0 h1:0SOkYxjMjph3Tbtv37+pANJQnYDvlAdjKpdEbK6zzZs=
github.com/hashicorp/vault-plugin-auth-alicloud v0.17.0/go.mod h1:79KUWOxY6Ftoad7b+vEmyCmY6eYKdHiADTP0w0TunsE=
github.com/hashicorp/vault-plugin-auth-azure v0.17.0 h1:nFsWQV+sMEdJCvKpVODNeTPP36n5bi6yiQpBOdBsQWw=
Expand Down
Loading