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

INI Parsing Failures silently ignored #2276

Closed
daemonl opened this issue Sep 13, 2023 · 2 comments · Fixed by #2286
Closed

INI Parsing Failures silently ignored #2276

daemonl opened this issue Sep 13, 2023 · 2 comments · Fixed by #2286
Assignees
Labels
bug This issue is a bug. p2 This is a standard priority issue

Comments

@daemonl
Copy link

daemonl commented Sep 13, 2023

Describe the bug

Config INI files with certain strings which look like numbers silently cause the config file to be entirely skipped.

E.g.

color = 970b00

Expected Behavior

Either an error should be thrown for corrupted ini files, or in this case the string should be parsed correctly.

Current Behavior

  • The config file is skipped entirely, with no warning or error
  • Meaning the profile specified in the $AWS_PROFILE variable isn't found
  • Which also silently fails
  • The SDK falls back to attempting to load EC2 IMDS credentials

Reproduction Steps

Add the color line to ~/.aws/config under any profile

[profile foobar]
color = 970b00
... existing creds ...

export AWS_PROFILE=foobar

and attempt to use that profile through config.LoadDefaultConfig

cfg, err := config.LoadDefaultConfig(ctx)
if err != nil {
return fmt.Errorf("failed to load configuration: %w", err)
}

cfClient := cloudformation.NewFromConfig(cfg)
res, err := d.CFClient.DescribeStacks(ctx, &cloudformation.DescribeStacksInput{
StackName: aws.String(stackName),
})

Possible Solution

Error is thrown here
Ignored here

func countTokens(runes []rune) int {
...
		if err != nil {
			return 0
		}

Leading to the tokenize function simply not iterating over any tokens.

Returning an error from countTokens passes it up the chain:

failed to load configuration: failed to load shared config file, [redacted], incorrect base format found b at 3 index

Additional Information/Context

No response

AWS Go SDK V2 Module Versions Used

ithub.com/google/go-cmp@v0.5.8
github.com/aws/aws-sdk-go-v2/service/sso@v1.13.6 github.com/aws/aws-sdk-go-v2@v1.21.0
github.com/aws/aws-sdk-go-v2/service/sso@v1.13.6 github.com/aws/aws-sdk-go-v2/internal/configsources@v1.1.41
github.com/aws/aws-sdk-go-v2/service/sso@v1.13.6 github.com/aws/aws-sdk-go-v2/internal/endpoints/v2@v2.4.35
github.com/aws/aws-sdk-go-v2/service/sso@v1.13.6 github.com/aws/smithy-go@v1.14.2
github.com/aws/aws-sdk-go-v2/service/sso@v1.13.6 github.com/google/go-cmp@v0.5.8
github.com/aws/aws-sdk-go-v2/service/ssooidc@v1.15.6 github.com/aws/aws-sdk-go-v2@v1.21.0
github.com/aws/aws-sdk-go-v2/service/ssooidc@v1.15.6 github.com/aws/aws-sdk-go-v2/internal/configsources@v1.1.41
github.com/aws/aws-sdk-go-v2/service/ssooidc@v1.15.6 github.com/aws/aws-sdk-go-v2/internal/endpoints/v2@v2.4.35
github.com/aws/aws-sdk-go-v2/service/ssooidc@v1.15.6 github.com/aws/smithy-go@v1.14.2
github.com/aws/aws-sdk-go-v2/service/ssooidc@v1.15.6 github.com/google/go-cmp@v0.5.8
github.com/aws/aws-sdk-go-v2/service/sts@v1.21.5 github.com/aws/aws-sdk-go-v2@v1.21.0
github.com/aws/aws-sdk-go-v2/service/sts@v1.21.5 github.com/aws/aws-sdk-go-v2/internal/configsources@v1.1.41
github.com/aws/aws-sdk-go-v2/service/sts@v1.21.5 github.com/aws/aws-sdk-go-v2/internal/endpoints/v2@v2.4.35
github.com/aws/aws-sdk-go-v2/service/sts@v1.21.5 github.com/aws/aws-sdk-go-v2/service/internal/presigned-url@v1.9.35
github.com/aws/aws-sdk-go-v2/service/sts@v1.21.5 github.com/aws/smithy-go@v1.14.2
github.com/aws/aws-sdk-go-v2/service/sts@v1.21.5 github.com/google/go-cmp@v0.5.8
github.com/aws/smithy-go@v1.14.2 github.com/google/go-cmp@v0.5.8
github.com/aws/smithy-go@v1.14.2 github.com/jmespath/go-jmespath@v0.4.0

Compiler and Version used

go version go1.20.5 darwin/arm64

Operating System and version

OSX 13.5.2 (22G91)

@daemonl daemonl added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 13, 2023
@RanVaknin RanVaknin self-assigned this Sep 13, 2023
@RanVaknin RanVaknin added investigating This issue is being investigated and/or work is in progress to resolve the issue. p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Sep 13, 2023
@lucix-aws
Copy link
Contributor

lucix-aws commented Sep 15, 2023

This is a good find- after taking a closer look, frankly I'm going to say the tokenization behavior we have today is fundamentally wrong.

Basically, in the section where we handle "literals", we first decide whether something is a number, string, or bool, and then parse that type accordingly. There are two issues with this:

  • The code that decides whether some token is "numeric" is clearly wrong - it can decide that something is a number that the number parser can't actually handle
  • This whole notion of parsing typed literals isn't right to begin with. They should all be treated as strings at this stage. The format of literals doesn't mean anything to the parser - it should only matter for the actual consumer of the values.

Ultimately point (1) above is moot - we need to get rid of typed literal parsing in the first place. The actual config structure we have that consumes the parsed config is responsible for determining whether the config values are actually valid.

@lucix-aws lucix-aws removed the investigating This issue is being investigated and/or work is in progress to resolve the issue. label Sep 15, 2023
@RanVaknin RanVaknin added p3 This is a minor priority issue queued This issues is on the AWS team's backlog and removed p2 This is a standard priority issue labels Sep 15, 2023
@lucix-aws lucix-aws added p2 This is a standard priority issue and removed p3 This is a minor priority issue labels Sep 18, 2023
@lucix-aws lucix-aws self-assigned this Sep 19, 2023
@lucix-aws lucix-aws removed the queued This issues is on the AWS team's backlog label Sep 19, 2023
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. p2 This is a standard priority issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants