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

fix: improve error message for invalid provider credentials #290

Merged
merged 2 commits into from
Oct 17, 2022

Conversation

ddebko
Copy link
Contributor

@ddebko ddebko commented Oct 17, 2022

Summary:

When creating the boundary terraform provider:

provider "boundary" {
  addr                            = "http://127.0.0.1:9200"
  auth_method_id                  = "ampw_1234567890" 
  password_auth_method_login_name = "admin"          
  password_auth_method_password   = "password"       
}

When an error is returned from a failed authentication, we describe the raw api response. Example:

 Error: {"kind":"NotFound", "message":"Resource not found."}
│ 
│   with provider["registry.terraform.io/hashicorp/boundary"],
│   on main.tf line 10, in provider "boundary":
│   10: provider "boundary" {

This error is not really helpful and the true source of the issue is an invalid auth method id.

Solution

Perform an api error casting check from the authentication request. On a 401 return an error describing that the login name or password are invalid. On a 404 return an error describing that the auth method id is invalid. Otherwise just return the error from the response.

Examples:

Bad login name or password:

Error: invalid login name or password: {"kind":"Unauthenticated","message":"Unable to authenticate."}
│ 
│   with provider["localhost/providers/boundary"],
│   on main.tf line 10, in provider "boundary":
│   10: provider "boundary" {

Bad auth method id:

 Error: unknown auth_method_id: {"kind":"NotFound","message":"Resource not found."}
│ 
│   with provider["localhost/providers/boundary"],
│   on main.tf line 10, in provider "boundary":
│   10: provider "boundary" {

Bad url:

│ Error: error performing client request during Authenticate call: Post "http://127.0.0.1:9201/v1/auth-methods/ampw_1234567890:authenticate": EOF
│ 
│   with provider["localhost/providers/boundary"],
│   on main.tf line 10, in provider "boundary":
│   10: provider "boundary" {

Copy link
Contributor

@johanbrandhorst johanbrandhorst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job!

@ddebko ddebko merged commit 1882bef into main Oct 17, 2022
@ddebko ddebko deleted the ddebko-fix-err-msg branch October 17, 2022 18:13
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

Successfully merging this pull request may close these issues.

2 participants