-
Notifications
You must be signed in to change notification settings - Fork 676
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
ParseInt Error with role duration seconds key #1192
Comments
…o use raw instead of int64
Thanks for reporting this issue @Zeouterlimits I added comment in the PR, about compatibility of this change with other SDKs. I don't think the trailing Because of this we couldn't take this change, because it changes the behavior of this field, and would not be compatible with the other SDKs. |
Thanks for the feedback, @jasdel, but I am somewhat confused, my roles don't have a trailing 's', its duration seconds is The result of running it through the SharedConfig loading path / LoadDefaultConfig is what creates a string that has a trailing s. |
Thanks for clarifying that @Zeouterlimits I miss read the PR and reported issue. I've re-opened the PR. Could you help clarify where the Also any additional background for using |
Ah no worries, ty for taking another look :) 28800 = decimal value of the html entity for this particular ideograph - 炀 I used raw as that is what shared config is expecting / is retrieved in loading these shared local configs. |
@jasdel this is still an issue. Any plans to merge the PR? |
Took a look at this PR and issue but have not been able to reproduce the issue. I created PR #1568 that adds a test case to the SDK for the issue outlined in this issue associated PR. Is it possible that the shared config file being passed to the SDK is not UTF-8 encoded? The SDK requires the file to be encoded in this file. Please let us know if you're still able to reproduce this issue, and is so please share the shared config file that is able to reproduce the problem. |
Thanks @jasdel. I am still able to reproduce this. The file is technically UTF-8 as it has no special characters but has no BOM. It's just the file that AWS CLI created. If I add BOM, I get:
|
Which version of the AWS CLI are you using to create the config file? Are you able to reproduce this with a newly created shared config file? Does the SDK parse the file correctly if the BOM is not present?
|
The SDK doesn't parse it correctly if BOM is not present and fails completely if BOM is present. In fact, I get the same error even with this simple file:
|
Thanks for the update, could you link that file to the GitHub issue, or run the config file through a hex dump, and paste the output to the issue? For example a utility like package main
import (
"encoding/hex"
"fmt"
"io"
"log"
"os"
)
// Usage: go run main.go <filename>
func main() {
b, err := io.ReadAll(os.Args[1])
if err != nil {
log.Fatalf("failed to read file, %v", err)
}
fmt.Println(hex.Dump(b))
} e.g. I would expect to see something like the following for a file without any extra encodings in it.
But something in the file(s) you're using is triggering some unexpected behavior in the SDK's ini file handling. |
It's just a normal text file. I swear :)
|
The only difference between the two dumps looks to be |
I am using Windows. If this happens because Go's INI parser doesn't handle |
Could you include a hex dump of the file saved with just The SDK uses a custom ini file parser due to additional rules and behaviors the SDKs need to support. the |
And this is the relevant part of my
|
Does the following script fail for you? This specifies a mock file created that will be created in the local directory and uses the SDK's I've not been able to reproduce this issue with What version of Go are you using by the way? package main
import (
"context"
"fmt"
"log"
"os"
"github.com/aws/aws-sdk-go-v2/config"
)
func main() {
v := []byte("[default]\r\nduration_seconds = 10800\r\n")
os.WriteFile("mock_config_test", v, 0644)
cfg, err := config.LoadSharedConfigProfile(context.Background(), "default", func(o *config.LoadSharedConfigOptions) {
o.CredentialsFiles = []string{}
o.ConfigFiles = []string{"mock_config_test"}
})
if err != nil {
log.Fatalf("failed to load shared config, %v", err)
}
if cfg.RoleDurationSeconds == nil {
log.Fatalf("duration_seconds, not read from config file, %#v", cfg)
}
fmt.Println(*cfg.RoleDurationSeconds)
} |
|
That script doesn't fail. I'm using go 1.17. |
Guessing this is going to fail, but if the above script is modified to read your file does it fail? package main
import (
"context"
"fmt"
"log"
"os"
"github.com/aws/aws-sdk-go-v2/config"
)
func main() {
cfg, err := config.LoadSharedConfigProfile(context.Background(), "default", func(o *config.LoadSharedConfigOptions) {
o.CredentialsFiles = []string{}
o.ConfigFiles = []string{os.Args[1]}
})
if err != nil {
log.Fatalf("failed to load shared config, %v", err)
}
if cfg.RoleDurationSeconds == nil {
log.Fatalf("duration_seconds, not read from config file, %#v", cfg)
}
fmt.Println(*cfg.RoleDurationSeconds)
}
|
That one worked with the reduced credentials file. But it failed a different way with the full file which still suggests a parsing error. It said it couldn't find the source profile.
I would guess this is not related to the actual parsing issue though. Sounds like the code just doesn't have everything setup right for this use case. The important part is the |
Thanks, that's helpful!
Is your configuration spread across a Could you try a similar script that uses package main
import (
"context"
"log"
"os"
"github.com/aws/aws-sdk-go-v2/config"
)
func main() {
_, err := config.LoadDefaultConfig(context.Background(), func(o *config.LoadOptions) error {
o.SharedConfigProfile = "default"
o.SharedConfigFiles = []string{os.Args[1]}
o.SharedCredentialsFiles = []string{}
return nil
})
if err != nil {
log.Fatalf("failed to load config, %v", err)
}
} |
Yes, my configuration is split between The latest script doesn't fail on the duration number, but does fail finding the source profile again. Both those profiles are in If put If I don't include So this works:
With:
But as soon as I put |
My original code also just works if I physically move |
The problem seems to be here: aws-sdk-go-v2/config/shared_config.go Lines 655 to 656 in 6625113
|
Good find. i was able to reproduce this via unit test. Looks like the actual root issue is that The value needs to be a I'll get a fixed and included in PR #1568 |
Fixes the SDK's handling of `duration_sections` in the shared credentials file or specified in multiple shared config and shared credentials files under the same profile. Fixes aws#1192
Thanks @jasdel !!! |
|
Confirm by changing [ ] to [x] below to ensure that it's a bug:
Describe the bug
Unable to use configured roles due to parsing error of duration_seconds
When instiating an aws client (s3 in my case), the aws go v2 sdk is trying to parse my local roles duration_seconds (28800) and throwing a parse int error exception:
error merging role duration seconds key, strconv.ParseInt: parsing "炀": invalid syntax
Checking out the SDK locally and running the tests reproduces this issue:
Version of AWS SDK for Go?
aws-sdk-go-v2 1.3.0
Version of Go (
go version
)?1.15.2
Update: Occurs on go1.15.10 too
To Reproduce (observed behavior)
Have a configured local aws profile with duration_seconds e.g:
Run the sdk unit tests
Expected behavior
No error occurs, duration_seconds correctly applied to client config
Additional context
The text was updated successfully, but these errors were encountered: