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: handle error message field in structure deserializer #2889

Merged
merged 5 commits into from
Nov 7, 2024

Conversation

RanVaknin
Copy link
Contributor

fixes: #2859

Error messages from AWS services can be returned with inconsistent casing (message or Message).
This change updates the error deserialization logic to handle case-insensitive message field matching.

Driver code setup:

This code uses a profile configuration that would assume a restricted role that does not have permissions to call ecs:CreateService. This will trigger an AccessDeniedException in the server's response that includes a Message field which breaks deserialization since ECS models message (lower case). The result is that the message is omitted from the error.

package main

import (
	"context"
	"fmt"
	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/aws/aws-sdk-go-v2/service/ecs"
	"log"
)

func main() {
	cfg, err := config.LoadDefaultConfig(
		context.TODO(),
		config.WithRegion("us-east-1"),
		config.WithSharedConfigProfile("restricted_role_profile"),
	)
	if err != nil {
		log.Fatalf("unable to load SDK config, %v", err)
	}

	client := ecs.NewFromConfig(cfg)

	out, err := client.CreateService(context.Background(), &ecs.CreateServiceInput{
		ServiceName:    aws.String("foo"),
		TaskDefinition: aws.String("arn:aws:ecs:us-east-1:REDACTED:task-definition/my-test-task:1"),
	})

	if err != nil {
		panic(err)
	}

	fmt.Println(out.Service.ServiceName)
}

Outputs:

panic: operation error ECS: CreateService, https response error StatusCode: 400, RequestID: REDACTED, AccessDeniedException: 

Output after change:

panic: operation error ECS: CreateService, https response error StatusCode: 400, RequestID: REDACTED, AccessDeniedException: User: arn:aws:sts::REDACTED:assumed-role/restricted_role/aws-go-sdk-1730854295921846000 is not authorized to perform: ecs:CreateService on resource: arn:aws:ecs:us-east-1:REDACTED:service/default/foo because no identity-based policy allows the ecs:CreateService action

@RanVaknin RanVaknin requested a review from a team as a code owner November 6, 2024 01:02
Copy link
Contributor

@lucix-aws lucix-aws left a comment

Choose a reason for hiding this comment

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

I can understand why you might have gone about it this way, but you've pushed complexity into the runtime that should really be handled in codegen.

The real (generated) code change that needs to happen here is less complicated than what you have currently. Basically, if we had

case "message":

before, we should now just be able to have

case "message", "Message":

That's going to be of significantly less runtime complexity than what you have currently.

@RanVaknin RanVaknin merged commit 5d0eb23 into main Nov 7, 2024
13 checks passed
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.

Error message isn't displayed when some ECS operations fail due to AccessDeniedException
4 participants