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

internal/ini: INI Parser Fails Subsequent Section Parsing With Missing Right Hand Value in Previous Section #2800

Closed
bflad opened this issue Aug 29, 2019 · 1 comment · Fixed by #2860 or #2869
Labels
bug This issue is a bug.

Comments

@bflad
Copy link
Contributor

bflad commented Aug 29, 2019

Please fill out the sections below to help us address your issue.

Version of AWS SDK for Go?

v1.23.0

Version of Go (go version)?

go version go1.12.9 darwin/amd64

What issue did you see?

Given an errant ~/.aws/credentials file such as the following (missing right hand values in the first section):

[foo]
aws_access_key_id = 
aws_secret_access_key = 
aws_session_token = 
[bar]
aws_access_key_id = valid
aws_secret_access_key = valid
aws_session_token = valid
[baz]
aws_access_key_id = valid
aws_secret_access_key = valid
aws_session_token = valid

In the AWS Go SDK, attempting to use bar credentials fails while using baz credentials works. In the AWS CLI, attempting to use bar credentials works. Verbose errors from the chain credential provider reports: SharedCredsLoad: failed to load profile, bar.

Any of these INI file fixes/workarounds allow bar to work as expected:

  • Removing the errant INI section completely
  • Adding right hand values in the errant INI section
  • Adding a new line above the [bar] section header

Steps to reproduce

Summed up fairly well downstream in: hashicorp/terraform-provider-aws#9854

bflad added a commit to bflad/aws-sdk-go that referenced this issue Aug 29, 2019
Reference: aws#2800

```
--- FAIL: TestParser (0.00s)
    --- FAIL: TestParser/complex_section_statement#02 (0.00s)
        ini_parser_test.go:302: expected same length 4, but received 3
        ini_parser_test.go:317: expected:
            	0: {completed_stmt {0 NONE 0 []} false [{section_stmt {1 STRING 0 [100 101 102 97 117 108 116]} true []}]}
            	1: {skip {0 NONE 0 []} false [{ {4 NONE 0 [61]} true [{expr {1 STRING 0 [115 51]} true []}]}]}
            	2: {completed_stmt {0 NONE 0 []} false [{section_stmt {1 STRING 0 [97 115 115 117 109 101 114 111 108 101]} true []}]}
            	3: {expr_stmt {0 NONE 0 []} false [{ {4 NONE 0 [61]} true [{expr {1 STRING 0 [111 117 116 112 117 116]} true []} {expr {1 STRING 0 [106 115 111 110]} true []}]}]}

            received:
            	0: {completed_stmt {0 NONE 0 []} false [{section_stmt {1 STRING 0 [100 101 102 97 117 108 116]} true []}]}
            	1: {skip {0 NONE 0 []} false [{ {4 NONE 0 [61]} true [{expr {1 STRING 0 [115 51]} true []}]}]}
            	2: {expr_stmt {0 NONE 0 []} false [{ {4 NONE 0 [61]} true [{expr {1 STRING 0 [111 117 116 112 117 116]} true []} {expr {1 STRING 0 [106 115 111 110]} true []}]}]}
--- FAIL: TestValidDataFiles (0.01s)
    walker_test.go:59: could not find profile bar
```
bflad added a commit to bflad/aws-sdk-go that referenced this issue Aug 29, 2019
Reference: aws#2800

```
--- FAIL: TestParser (0.00s)
    --- FAIL: TestParser/complex_section_statement#02 (0.00s)
        ini_parser_test.go:302: expected same length 4, but received 3
        ini_parser_test.go:317: expected:
            	0: {completed_stmt {0 NONE 0 []} false [{section_stmt {1 STRING 0 [100 101 102 97 117 108 116]} true []}]}
            	1: {skip {0 NONE 0 []} false [{ {4 NONE 0 [61]} true [{expr {1 STRING 0 [115 51]} true []}]}]}
            	2: {completed_stmt {0 NONE 0 []} false [{section_stmt {1 STRING 0 [97 115 115 117 109 101 114 111 108 101]} true []}]}
            	3: {expr_stmt {0 NONE 0 []} false [{ {4 NONE 0 [61]} true [{expr {1 STRING 0 [111 117 116 112 117 116]} true []} {expr {1 STRING 0 [106 115 111 110]} true []}]}]}

            received:
            	0: {completed_stmt {0 NONE 0 []} false [{section_stmt {1 STRING 0 [100 101 102 97 117 108 116]} true []}]}
            	1: {skip {0 NONE 0 []} false [{ {4 NONE 0 [61]} true [{expr {1 STRING 0 [115 51]} true []}]}]}
            	2: {expr_stmt {0 NONE 0 []} false [{ {4 NONE 0 [61]} true [{expr {1 STRING 0 [111 117 116 112 117 116]} true []} {expr {1 STRING 0 [106 115 111 110]} true []}]}]}
--- FAIL: TestValidDataFiles (0.01s)
    walker_test.go:59: could not find profile bar
```
@jasdel jasdel added the bug This issue is a bug. label Aug 29, 2019
@jasdel
Copy link
Contributor

jasdel commented Aug 29, 2019

Thanks for reporting this issue @bflad, and providing the test cases. I'm able to reproduce the behavior being reported, and we can investigate a solution for this bug.

I think this issue is related to the SDK's INI parser parsing nested key/value pairs as a value of a field. While the SDK does not make use of these nested key/value pairs, the AWS CLI commonly will use these in the shared config file, (e.g. aws/aws-sdk-go-v2#345).

@jasdel jasdel changed the title INI Parser Fails Subsequent Section Parsing With Missing Right Hand Value in Previous Section internal/init: INI Parser Fails Subsequent Section Parsing With Missing Right Hand Value in Previous Section Sep 24, 2019
@jasdel jasdel changed the title internal/init: INI Parser Fails Subsequent Section Parsing With Missing Right Hand Value in Previous Section internal/ini: INI Parser Fails Subsequent Section Parsing With Missing Right Hand Value in Previous Section Sep 24, 2019
skotambkar added a commit that referenced this issue Oct 1, 2019
The ini parser incorrectly decided whether a statement should be skipped. As a result, valid statements in the ini files were being squashed. The PR fixes incorrect modifications to the previous token value of the skipper. We also add checks for cases where a skipped statement should be marked as complete and not be ignored.

Adds test cases for cases for statements that need to be skipped. Also adds suggested tests from #2801 . Fixes #2800
jasdel pushed a commit that referenced this issue Oct 20, 2020
…is missed in the last statement of the ini file (#3596)

Fixes ini file parsing for cases when Right Hand Value is missed in the last statement of the ini file 
  * related to #2800
aws-sdk-go-automation pushed a commit that referenced this issue Oct 21, 2020
===

### Service Client Updates
* `service/cloudfront`: Updates service API and documentation
  * CloudFront adds support for managing the public keys for signed URLs and signed cookies directly in CloudFront (it no longer requires the AWS root account).
* `service/ec2`: Updates service API and documentation
  * instance-storage-info nvmeSupport added to DescribeInstanceTypes API
* `service/globalaccelerator`: Updates service API and documentation
* `service/glue`: Updates service API and documentation
  * AWS Glue crawlers now support incremental crawls for the Amazon Simple Storage Service (Amazon S3) data source.
* `service/kendra`: Updates service API and documentation
  * This release adds custom data sources: a new data source type that gives you full control of the documents added, modified or deleted during a data source sync while providing run history metrics.
* `service/organizations`: Updates service documentation
  * AWS Organizations renamed the 'master account' to 'management account'.

### SDK Bugs
* `aws/credentials`: Fixed a race condition checking if credentials are expired. ([#3448](#3448))
  * Fixes [#3524](#3524)
* `internal/ini`: Fixes ini file parsing for cases when Right Hand Value is missed in the last statement of the ini file ([#3596](#3596))
  * related to [#2800](#2800)
aws-sdk-go-automation added a commit that referenced this issue Oct 21, 2020
Release v1.35.12 (2020-10-21)
===

### Service Client Updates
* `service/cloudfront`: Updates service API and documentation
  * CloudFront adds support for managing the public keys for signed URLs and signed cookies directly in CloudFront (it no longer requires the AWS root account).
* `service/ec2`: Updates service API and documentation
  * instance-storage-info nvmeSupport added to DescribeInstanceTypes API
* `service/globalaccelerator`: Updates service API and documentation
* `service/glue`: Updates service API and documentation
  * AWS Glue crawlers now support incremental crawls for the Amazon Simple Storage Service (Amazon S3) data source.
* `service/kendra`: Updates service API and documentation
  * This release adds custom data sources: a new data source type that gives you full control of the documents added, modified or deleted during a data source sync while providing run history metrics.
* `service/organizations`: Updates service documentation
  * AWS Organizations renamed the 'master account' to 'management account'.

### SDK Bugs
* `aws/credentials`: Fixed a race condition checking if credentials are expired. ([#3448](#3448))
  * Fixes [#3524](#3524)
* `internal/ini`: Fixes ini file parsing for cases when Right Hand Value is missed in the last statement of the ini file ([#3596](#3596)) 
  * related to [#2800](#2800)
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.
Projects
None yet
2 participants