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

Improve the error message when there are no valid credentials. #2285

Closed
lukehoban opened this issue Dec 23, 2022 · 10 comments
Closed

Improve the error message when there are no valid credentials. #2285

lukehoban opened this issue Dec 23, 2022 · 10 comments
Assignees
Labels
impact/upstream-regression Upstream regression - manifests on upstream the same way impact/usability Something that impacts users' ability to use the product easily and intuitively kind/enhancement Improvements or new features resolution/fixed This issue was fixed

Comments

@lukehoban
Copy link
Contributor

The error when there are not valid credentials is quite complex and awkward at the moment.

  aws:lb:LoadBalancer (foobar-alb):
    error: unable to validate AWS credentials.
    Details: no valid credential sources for  found.
    
    Please see
    for more information about providing credentials.
    
    Error: failed to refresh cached credentials, the SSO session has expired or is invalid: access token is expired
    
    
    Make sure you have:
    
         • Set your AWS region, e.g. `pulumi config set aws:region us-west-2`
         • Configured your AWS credentials as per https://pulumi.io/install/aws.html
         You can also set these via cli using `aws configure`.

There are a number of opportunities to improve:

  • Fix or remove the missing and misformatted "Please see \n for more ...".
  • Remove one or more of the repeated error statements "error: unable to validate AWS credentials.", "Details: no valid credential sources for found.", "Error: failed to refresh cached credentials,". The last of these is necessary and has critical information - the others are nice to have at best.
  • Remove the note about AWS region - that is not related to this class of error - and especially as the first bullet - is likely to mislead users on where the problem is - as ~all users who see this will already have taken that action.
  • Clean up formatting overall: (1) consistent use of newlines, (2) consistent indentation (see the very last line).
@lukehoban lukehoban added kind/enhancement Improvements or new features impact/usability Something that impacts users' ability to use the product easily and intuitively needs-triage Needs attention from the triage team labels Dec 23, 2022
@mikhailshilkov mikhailshilkov removed the needs-triage Needs attention from the triage team label Dec 27, 2022
@lukehoban
Copy link
Contributor Author

This seems to be even worse now. I see this when I have invalid credentials (but notably, do have aws:region set).

Diagnostics:
  pulumi:providers:aws (default_6_2_1):
    error: rpc error: code = Unknown desc = 2 errors occurred:
    	* unable to validate AWS credentials.
    Details: [{0x14008da4000 0x14008d90440}]
    Make sure you have set your AWS region, e.g. `pulumi config set aws:region us-west-2`.

    	* unable to validate AWS credentials.
    Details: [{0x14008d350e0 0x14008e60e20}]
    Make sure you have set your AWS region, e.g. `pulumi config set aws:region us-west-2`.

@EvanBoyle EvanBoyle added the p1 A bug severe enough to be the next item assigned to an engineer label Oct 5, 2023
@mikhailshilkov mikhailshilkov added the needs-triage Needs attention from the triage team label Oct 5, 2023
@mikhailshilkov
Copy link
Member

mikhailshilkov commented Oct 6, 2023

I opened #2858 as a tactical improvement to avoid dumping Go addresses, which should hopefully enough to remove P1 from this.

Now, the experience is still not great. This is what I get after the fix:

Diagnostics:
  pulumi:providers:aws (default_6_4_0):
    error: rpc error: code = Unknown desc = 2 errors occurred:
    	* unable to validate AWS credentials.
    Details: validating provider credentials: retrieving caller identity from STS: operation error STS: GetCallerIdentity, failed to resolve service endpoint, endpoint rule error, Invalid Configuration: Missing Region
    Make sure you have set your AWS region, e.g. `pulumi config set aws:region us-west-2`.
    
    	* unable to validate AWS credentials.
    Details: validating provider credentials: retrieving caller identity from STS: operation error STS: GetCallerIdentity, failed to resolve service endpoint, endpoint rule error, Invalid Configuration: Missing Region
    Make sure you have set your AWS region, e.g. `pulumi config set aws:region us-west-2`.

The next step is to figure out how to:

  • Avoid duplicating the message twice
  • Avoid showing the rpc error

From my brief investigation:

  • We return the diagnostics message as an error from preConfigureCallback here
  • It's called from CheckConfigWithContext here. Notably, the error is returned as an RPC error (third result) and not as []plugin.CheckFailure (second result), which I guess causes the RPC error part of UX
  • Muxer's CheckConfig, which processes the results of CheckConfigWithContext, has some logic to de-duplicate check failures here, but it doesn't do the same for errors, so the error is returned twice (once for TFPF, once for SDK), which results in the duplicated message

cc @iwahbe @t0yv0 I'm curious to get your thoughts on the above.

@mikhailshilkov mikhailshilkov removed the needs-triage Needs attention from the triage team label Oct 6, 2023
@mikhailshilkov mikhailshilkov self-assigned this Oct 6, 2023
@t0yv0
Copy link
Member

t0yv0 commented Oct 6, 2023

Good investigation. Yes I think the duplication is certainly stemming from the split design where aws = muxed(aws_pf, aws_sdkv2). Currently muxer broadcasts Configure calls.

From what I've seen earlier, it might be a possibility to not broadcast the calls but only run Configure on sdkv2 for AWS since last time I looked PF branch used a wrapper around the same identical object representing the provider. This is not at the level of confidence though where I would recommend it right away. Thinking further, there might be an opportunity to reduce startup time if we're doing expensive Configure work twice.

Deduplicating errors better is a no-brainer in terms of self rollout.

@t0yv0
Copy link
Member

t0yv0 commented Oct 6, 2023

CC @mjeffryes

@iwahbe
Copy link
Member

iwahbe commented Oct 6, 2023

I opened pulumi/pulumi-terraform-bridge#1418 to track muxer error de-duplication in the bridge.

@t0yv0
Copy link
Member

t0yv0 commented Oct 6, 2023

Related: pulumi/pulumi-gcp#1236

mikhailshilkov added a commit that referenced this issue Oct 9, 2023
…v format dump (#2858)

A tactical improvement for
#2285 to avoid Go pointers
leaking into error messages.

Before:

> unable to validate AWS credentials.
    Details: [{0x14009acaee0}]
Make sure you have set your AWS region, e.g. `pulumi config set
aws:region us-west-2`.

After:

> unable to validate AWS credentials.
Details: validating provider credentials: retrieving caller identity
from STS: operation error STS: GetCallerIdentity, failed to resolve
service endpoint, endpoint rule error, Invalid Configuration: Missing
Region
Make sure you have set your AWS region, e.g. `pulumi config set
aws:region us-west-2`.
@mikhailshilkov
Copy link
Member

#2858 shipped a fix for hex addresses in the message, so I think I can remove P1 for now.

We'll plan pulumi/pulumi-terraform-bridge#1418 for M96 as the next step.

@mikhailshilkov mikhailshilkov removed the p1 A bug severe enough to be the next item assigned to an engineer label Oct 10, 2023
@joeduffy joeduffy added the impact/upstream-regression Upstream regression - manifests on upstream the same way label Oct 20, 2023
@VenelinMartinov
Copy link
Contributor

De-duplicating the errors with no valid credentials doesn't fix the issue since the errors are slightly different:

Diagnostics:
  pulumi:providers:aws (default):
    error: rpc error: code = Unknown desc = 2 errors occurred:
    	* unable to validate AWS credentials.
    Details: No valid credential sources found. Please see https://www.pulumi.com/registry/packages/aws/installation-configuration/
    for more information about providing credentials.

    Error: failed to refresh cached credentials, no EC2 IMDS role found, operation error ec2imds: GetMetadata, request canceled, context deadline exceeded

    Make sure you have set your AWS region, e.g. `pulumi config set aws:region us-west-2`.

    	* unable to validate AWS credentials.
    Details: No valid credential sources found. Please see https://www.pulumi.com/registry/packages/aws/installation-configuration/
    for more information about providing credentials.

    Error: failed to refresh cached credentials, no EC2 IMDS role found, operation error ec2imds: GetMetadata, access disabled to EC2 IMDS via client option, or "AWS_EC2_METADATA_DISABLED" environment variable

    Make sure you have set your AWS region, e.g. `pulumi config set aws:region us-west-2`.

It does however fix the duplicated error message when no region is specified:

  pulumi:providers:aws (default):
    error: rpc error: code = Unknown desc = unable to validate AWS credentials.
    Details: validating provider credentials: retrieving caller identity from STS: operation error STS: GetCallerIdentity, failed to resolve service endpoint, endpoint rule error, Invalid Configuration: Missing Region
    Make sure you have set your AWS region, e.g. `pulumi config set aws:region us-west-2`.

VenelinMartinov added a commit that referenced this issue Nov 3, 2023
This should address the error duplication reported in
#2285 as suggested by @t0yv0.

We now have a global counter which guard the credentials check and makes
sure we only run it once.

For testing, I ran a few programs both with and without errors and it
does seem to do the right thing.


```
Previewing update (dedev)

View in Browser (Ctrl+O): https://app.pulumi.com/venelin-pulumi-corp/aws_bucket_go/dedev/previews/88831526-f63f-42f2-98d9-957fbea78fc0

     Type                     Name                 Plan     Info
     pulumi:pulumi:Stack      aws_bucket_go-dedev           4 war
     └─ pulumi:providers:aws  default                       1 err

Diagnostics:
  pulumi:providers:aws (default):
    error: rpc error: code = Unknown desc = unable to validate AWS credentials.
    Details: No valid credential sources found. Please see https://www.pulumi.com/registry/packages/aws/installation-configuration/
    for more information about providing credentials.

    Error: failed to refresh cached credentials, failed to read cached SSO token file, open /Users/vvm/.aws/sso/cache/55357933a7310d2db90c3fa1ed0970a7bb34ed39.json: no such file or directory

    Make sure you have set your AWS region, e.g. `pulumi config set aws:region us-west-2`.

  pulumi:pulumi:Stack (aws_bucket_go-dedev):
    warning: using pulumi-language-go from $PATH at /opt/homebrew/bin/pulumi-language-go
    warning: using pulumi-resource-aws from $PATH at /Users/vvm/code/pulumi-aws/bin/pulumi-resource-aws
    warning: using pulumi-language-go from $PATH at /opt/homebrew/bin/pulumi-language-go
    warning: using pulumi-resource-aws from $PATH at /Users/vvm/code/pulumi-aws/bin/pulumi-resource-aws
```
@t0yv0
Copy link
Member

t0yv0 commented Nov 3, 2023

Great job on removing duplication @VenelinMartinov ! Can you post how the error message presents with the latest changes, so we can cross-check Luke's concerns above on the message being "quite complex and awkward"? Thank you! We're very close to closing this out.

@VenelinMartinov
Copy link
Contributor

Here is the error which shows when I delete my aws config and login cache:

View in Browser (Ctrl+O): https://app.pulumi.com/venelin-pulumi-corp/aws_bucket_go/dev/previews/d6b31694-92b2-4a07-aa7d-69c85273dfd2

     Type                     Name               Plan       Info
 +   pulumi:pulumi:Stack      aws_bucket_go-dev  create     3 war
     └─ pulumi:providers:aws  default                       1 err

Diagnostics:
  pulumi:providers:aws (default):
    error: rpc error: code = Unknown desc = unable to validate AWS credentials.
    Details: failed to get shared config profile, aws
    Make sure you have set your AWS region, e.g. `pulumi config set aws:region us-west-2`.

    NEW: You can use Pulumi ESC to set up dynamic credentials with AWS OIDC to ensure the correct and valid credentials are used.
    Learn more: https://www.pulumi.com/blog/esc-env-run-aws/

#2949 should now remove all the duplication.

VenelinMartinov added a commit to pulumi/pulumi-terraform-bridge that referenced this issue Nov 16, 2023
The muxer previously de-duplicated `CheckFailure`s but not go errors.
This PR should add that and address
#1418 but not
the original issue in
pulumi/pulumi-aws#2285 (comment).
See
#1418 (comment)

This fixes duplicated error messages in the aws-provider when no aws
region is specified.

Before:
```
    error: rpc error: code = Unknown desc = 2 errors occurred:
    	* unable to validate AWS credentials.
    Details: validating provider credentials: retrieving caller identity from STS: operation error STS: GetCallerIdentity, failed to resolve service endpoint, endpoint rule error, Invalid Configuration: Missing Region
    Make sure you have set your AWS region, e.g. `pulumi config set aws:region us-west-2`.

    	* unable to validate AWS credentials.
    Details: validating provider credentials: retrieving caller identity from STS: operation error STS: GetCallerIdentity, failed to resolve service endpoint, endpoint rule error, Invalid Configuration: Missing Region
    Make sure you have set your AWS region, e.g. `pulumi config set aws:region us-west-2`.
```

After:
```
    error: rpc error: code = Unknown desc = unable to validate AWS credentials.
    Details: validating provider credentials: retrieving caller identity from STS: operation error STS: GetCallerIdentity, failed to resolve service endpoint, endpoint rule error, Invalid Configuration: Missing Region
    Make sure you have set your AWS region, e.g. `pulumi config set aws:region us-west-2`.
```
@VenelinMartinov VenelinMartinov self-assigned this Jan 24, 2024
VenelinMartinov added a commit to pulumi/pulumi-terraform-bridge that referenced this issue Jan 25, 2024
Helps with pulumi/pulumi-aws#2285

This removes the bad error message `error: rpc error: code = Unknown
desc =` and makes it more comprehensible: `pulumi:providers:aws resource
'default_6_18_2' has a problem:`


The error message was this before:
```
Diagnostics:
  pulumi:providers:aws (default):
    error: rpc error: code = Unknown desc = unable to validate AWS credentials.
    Details: failed to get shared config profile, aws
    Make sure you have set your AWS region, e.g. `pulumi config set aws:region us-west-2`.
```


The distinction between an error and a failure seems to be if it was
expected/unexpected IIUC. If that is true then this must be a failure
instead of an error.
VenelinMartinov added a commit to pulumi/pulumi-terraform-bridge that referenced this issue Jan 29, 2024
Similar to #1640,
should help with pulumi/pulumi-aws#2285.

Allow `PreConfigureCallback` to return failures in PF bridge as well as
sdkv2.
VenelinMartinov added a commit that referenced this issue Jan 31, 2024
Should fully address #2285
after pulumi/pulumi-terraform-bridge#1640

This makes the error messages when the user has no credentials or no
region configured better and more actionable:

Before, no credentials configured:

```
error: pulumi:providers:aws resource 'default_6_18_2' has a problem: could not validate provider configuration: unable to validate AWS credentials.
    Details: No valid credential sources found. Please see https://www.pulumi.com/registry/packages/aws/installation-configuration/
    for more information about providing credentials.

    Error: failed to refresh cached credentials, no EC2 IMDS role found, operation error ec2imds: GetMetadata, request canceled, context deadline exceeded

    Make sure you have set your AWS region, e.g. `pulumi config set aws:region us-west-2`.
```

The line about the region is irrelevant here.

After, no credentials configured:
```
Diagnostics:
  pulumi:providers:aws (default_6_18_2):
    error: pulumi:providers:aws resource 'default_6_18_2' has a problem: could not validate provider configuration: unable to validate AWS credentials.
    Details: No valid credential sources found. Please see https://www.pulumi.com/registry/packages/aws/installation-configuration/
    for more information about providing credentials.

    Error: failed to refresh cached credentials, no EC2 IMDS role found, operation error ec2imds: GetMetadata, request canceled, context deadline exceeded
```


Before, no region configured:
```
Diagnostics:
  pulumi:providers:aws (default_6_18_2):
    error: pulumi:providers:aws resource 'default_6_18_2' has a problem: could not validate provider configuration: unable to validate AWS credentials.
    Details: validating provider credentials: retrieving caller identity from STS: operation error STS: GetCallerIdentity, https response error StatusCode: 0, RequestID: , request send failed, Post "https://sts..amazonaws.com/": dial tcp: lookup sts..amazonaws.com: no such host
    Make sure you have set your AWS region, e.g. `pulumi config set aws:region us-west-2`.
```

Here, it is not at all clear that it is the region at fault, since the
note about setting the region shows up every time.

After, no region configured:
```
Diagnostics:
  pulumi:providers:aws (default_6_18_2):
    error: pulumi:providers:aws resource 'default_6_18_2' has a problem: could not validate provider configuration: missing region information
    Make sure you have set your AWS region, e.g. `pulumi config set aws:region us-west-2`.
    Details: validating provider credentials: retrieving caller identity from STS: operation error STS: GetCallerIdentity, https response error StatusCode: 0, RequestID: , request send failed, Post "https://sts/..amazonaws.com/": dial tcp: lookup sts..amazonaws.com: no such host
```
The note about `config set aws:region` only shows up in this error case,
so clearly actionable.


For comparison, upstream, no credentials configured:
```
│ Error: configuring Terraform AWS Provider: no valid credential sources for Terraform AWS Provider found.
│
│ Please see https://registry.terraform.io/providers/hashicorp/aws
│ for more information about providing credentials.
│
│ AWS Error: failed to refresh cached credentials, no EC2 IMDS role found, operation error ec2imds: GetMetadata, http response error StatusCode: 404, request to EC2 IMDS failed
│
│
│   with provider["registry.terraform.io/hashicorp/aws"],
│   on main.tf line 12, in provider "aws":
│   12: provider "aws" {
│
╵
```
@VenelinMartinov VenelinMartinov added the resolution/fixed This issue was fixed label Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
impact/upstream-regression Upstream regression - manifests on upstream the same way impact/usability Something that impacts users' ability to use the product easily and intuitively kind/enhancement Improvements or new features resolution/fixed This issue was fixed
Projects
None yet
Development

No branches or pull requests

7 participants