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(stepfunctions-tasks): cloudwatchlogs service generates wrong action in role policy #27623

Merged
merged 4 commits into from
Oct 24, 2023

Conversation

go-to-k
Copy link
Contributor

@go-to-k go-to-k commented Oct 20, 2023

This PR fixes the bug that a wrong action in role policy is generated when cloudwatchlogs service is specified.

A correct action is logs:xxx, but current behavior is to cloudwatchlogs:xxx by using the service property.

Closes #27573.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation aws-cdk-automation requested a review from a team October 20, 2023 10:57
@github-actions github-actions bot added bug This issue is a bug. p2 admired-contributor [Pilot] contributed between 13-24 PRs to the CDK labels Oct 20, 2023
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@go-to-k go-to-k marked this pull request as ready for review October 20, 2023 11:18
@aws-cdk-automation aws-cdk-automation dismissed their stale review October 20, 2023 11:21

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Oct 20, 2023
@scanlonp scanlonp added the pr/do-not-merge This PR should not be merged at this time. label Oct 20, 2023
Copy link
Contributor

@scanlonp scanlonp left a comment

Choose a reason for hiding this comment

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

Hey @go-to-k, this change looks great. Before approval, do you have a link to docs that state the correct action is logs:createLogStream?
Also in the original issue, the user states that the action should be logs:CreateLogStream with a capital C on Create. Another case where the docs would be helpful in confirming the correct action is being created.

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Oct 20, 2023
@scanlonp scanlonp removed the pr/do-not-merge This PR should not be merged at this time. label Oct 20, 2023
@go-to-k
Copy link
Contributor Author

go-to-k commented Oct 21, 2023

@scanlonp

Thanks for your review. It cannot be pascal case like logs:CreateLogStream with a capital C on Create for the following reasons.

At first, the following description is in the UserGuide reference.

The prefix and the action name are case insensitive.

https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_action.html

The documentation link is also in the CDK codes.

// The prefix and the action name are case insensitive
// https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_action.html
actions: [props.iamAction ?? `${iamService}:${props.action}`],

But the IAM actions are case insensitive, while StepFunctions SDK service integrations are case sensitive for API actions. The actions for StepFunctions must be camel case only. Also, by default, the action property for StepFunctions is used in IAM policies. So the action names as camel case will be used in the IAM actions.

/**
* The API action to call.
*
* Use camelCase.
*/
readonly action: string;

The API action will always be camel case, and parameter names will be Pascal case. For example, you could use Step Functions API action startSyncExecution and specify its parameter as StateMachineArn.

https://docs.aws.amazon.com/step-functions/latest/dg/supported-services-awssdk.html

So, if you use CreateLogStream (Pascal case) for the action in CDK props, an error will occur in StepFunction definitions.

Deployment failed: Error: The stack named aws-stepfunctions-tasks-call-aws-service-logs-integ failed to deploy: UPDATE_ROLLBACK_COMPLETE: Resource handler returned message: "Invalid State Machine Definition: 'SCHEMA_VALIDATION_FAILED: The resource provided arn:aws:states:::aws-sdk:cloudwatchlogs:CreateLogStream is not recognized. The value is not a valid resource ARN, or the resource is not available in this region. at /States/SendTaskSuccess/Resource' (Service: AWSStepFunctions; Status Code: 400; Error Code: InvalidDefinition; Request ID: xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx; Proxy: null)" (RequestToken: xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx, HandlerErrorCode: InvalidRequest)

In this regard, I may submit submitted an another PR that the construct validates inputs or translates to camel cases in StepFunctions props if you use pascal cases for action in props.

#27635

scanlonp
scanlonp previously approved these changes Oct 24, 2023
Copy link
Contributor

@scanlonp scanlonp left a comment

Choose a reason for hiding this comment

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

Perfect, thanks for the docs links! Looks good.

@mergify
Copy link
Contributor

mergify bot commented Oct 24, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot dismissed scanlonp’s stale review October 24, 2023 19:22

Pull request has been modified.

@mergify
Copy link
Contributor

mergify bot commented Oct 24, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

mergify bot pushed a commit that referenced this pull request Oct 24, 2023
…n CallAwsService (#27635)

This PR adds the following validations in CallAwsService.

- `action` must be camelCase.
- parameter names in `parameters` must be PascalCase.

See the doc: https://docs.aws.amazon.com/step-functions/latest/dg/supported-services-awssdk.html

> The API action will always be camel case, and parameter names will be Pascal case. For example, you could use Step Functions API action startSyncExecution and specify its parameter as StateMachineArn.

CloudFormation fails with a following error if there are not these validations.

```
Deployment failed: Error: The stack named aws-stepfunctions-tasks-call-aws-service-logs-integ failed to deploy: UPDATE_ROLLBACK_COMPLETE: Resource handler returned message: "Invalid State Machine Definition: 'SCHEMA_VALIDATION_FAILED: The resource provided arn:aws:states:::aws-sdk:cloudwatchlogs:CreateLogStream is not recognized. The value is not a valid resource ARN, or the resource is not available in this region. at /States/SendTaskSuccess/Resource' (Service: AWSStepFunctions; Status Code: 400; Error Code: InvalidDefinition; Request ID: xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx; Proxy: null)" (RequestToken: xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx, HandlerErrorCode: InvalidRequest)
```

I think it is a good thing to make these errors in the synth phase, since there were actually cases of confusion as follows.

#27623 (comment)

I also thought to not validate but translate to camel (or pascal) cases. However I thought it would allow input that violates the explanation defined in the API documentation, so I decided not to.

On the other hands, the `action` is also used for IAM actions so the IAM actions will be to camel cases (like `logs:createLogStream`). But I allowed it because IAM actions are case insensitive. If a translation is a better way to do it rather than the validation, I will consider that as well.

https://github.com/aws/aws-cdk/blob/09c809b52fd2eeb27ac5bbc91d425ecf54e31bf9/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/aws-sdk/call-aws-service.ts#L92-L94

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 6cb06f3
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit de7fb04 into aws:main Oct 24, 2023
8 checks passed
@mergify
Copy link
Contributor

mergify bot commented Oct 24, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@go-to-k go-to-k deleted the fix/stepfunctions-tasks-logs-polocy branch October 25, 2023 00:50
mrgrain pushed a commit that referenced this pull request Nov 1, 2023
…n CallAwsService (#27635)

This PR adds the following validations in CallAwsService.

- `action` must be camelCase.
- parameter names in `parameters` must be PascalCase.

See the doc: https://docs.aws.amazon.com/step-functions/latest/dg/supported-services-awssdk.html

> The API action will always be camel case, and parameter names will be Pascal case. For example, you could use Step Functions API action startSyncExecution and specify its parameter as StateMachineArn.

CloudFormation fails with a following error if there are not these validations.

```
Deployment failed: Error: The stack named aws-stepfunctions-tasks-call-aws-service-logs-integ failed to deploy: UPDATE_ROLLBACK_COMPLETE: Resource handler returned message: "Invalid State Machine Definition: 'SCHEMA_VALIDATION_FAILED: The resource provided arn:aws:states:::aws-sdk:cloudwatchlogs:CreateLogStream is not recognized. The value is not a valid resource ARN, or the resource is not available in this region. at /States/SendTaskSuccess/Resource' (Service: AWSStepFunctions; Status Code: 400; Error Code: InvalidDefinition; Request ID: xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx; Proxy: null)" (RequestToken: xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx, HandlerErrorCode: InvalidRequest)
```

I think it is a good thing to make these errors in the synth phase, since there were actually cases of confusion as follows.

#27623 (comment)

I also thought to not validate but translate to camel (or pascal) cases. However I thought it would allow input that violates the explanation defined in the API documentation, so I decided not to.

On the other hands, the `action` is also used for IAM actions so the IAM actions will be to camel cases (like `logs:createLogStream`). But I allowed it because IAM actions are case insensitive. If a translation is a better way to do it rather than the validation, I will consider that as well.

https://github.com/aws/aws-cdk/blob/09c809b52fd2eeb27ac5bbc91d425ecf54e31bf9/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/aws-sdk/call-aws-service.ts#L92-L94

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
mrgrain pushed a commit that referenced this pull request Nov 1, 2023
…on in role policy (#27623)

This PR fixes the bug that a wrong action in role policy is generated when `cloudwatchlogs` service is specified.

A correct action is `logs:xxx`, but current behavior is to `cloudwatchlogs:xxx` by using the `service` property.

Closes #27573.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
mergify bot pushed a commit that referenced this pull request Dec 5, 2023
… policy (#28082)

When we use CallAwsService for Step Functions task, CDK generates IAM policy to grant permission regarding the API call. However, if we specify `mwaa` as service in CallAwsService, CDK generates wrong policy statement such as `mwaa:listEnvironments`. Correct service prefix for MWAA is `airflow`.

https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonmanagedworkflowsforapacheairflow.html
> Amazon Managed Workflows for Apache Airflow (service prefix: airflow) provides the following service-specific resources, actions, and condition context keys for use in IAM permission policies.

This PR solves the issue by adding `mwaa` into iamServiceMap. This is similar with #27623.

Closes #28081

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
chenjane-dev pushed a commit to chenjane-dev/aws-cdk that referenced this pull request Dec 5, 2023
… policy (aws#28082)

When we use CallAwsService for Step Functions task, CDK generates IAM policy to grant permission regarding the API call. However, if we specify `mwaa` as service in CallAwsService, CDK generates wrong policy statement such as `mwaa:listEnvironments`. Correct service prefix for MWAA is `airflow`.

https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonmanagedworkflowsforapacheairflow.html
> Amazon Managed Workflows for Apache Airflow (service prefix: airflow) provides the following service-specific resources, actions, and condition context keys for use in IAM permission policies.

This PR solves the issue by adding `mwaa` into iamServiceMap. This is similar with aws#27623.

Closes aws#28081

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
mergify bot pushed a commit that referenced this pull request Jan 31, 2024
…ion in role policy (#28775)

When we use CallAwsService for Step Functions task, CDK generates IAM policy to grant permission regarding the API call. However, if we specify `mediapackagevod` as service in CallAwsService, CDK generates wrong policy statement such as `mediapackagevod:deleteAsset`. Correct service prefix for MediaPackageVOD is `mediapackage-vod`.

https://docs.aws.amazon.com/service-authorization/latest/reference/list_awselementalmediapackagevod.html

> Amazon MediaPackageVOD (service prefix: mediapackage-vod) provides the following service-specific resources, actions, and condition context keys for use in IAM permission policies.

This PR solves the issue by adding mediapackagevod into iamServiceMap. This is similar with #27623 and #28082.

Closes #28774.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
SankyRed pushed a commit that referenced this pull request Feb 8, 2024
…ion in role policy (#28775)

When we use CallAwsService for Step Functions task, CDK generates IAM policy to grant permission regarding the API call. However, if we specify `mediapackagevod` as service in CallAwsService, CDK generates wrong policy statement such as `mediapackagevod:deleteAsset`. Correct service prefix for MediaPackageVOD is `mediapackage-vod`.

https://docs.aws.amazon.com/service-authorization/latest/reference/list_awselementalmediapackagevod.html

> Amazon MediaPackageVOD (service prefix: mediapackage-vod) provides the following service-specific resources, actions, and condition context keys for use in IAM permission policies.

This PR solves the issue by adding mediapackagevod into iamServiceMap. This is similar with #27623 and #28082.

Closes #28774.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
admired-contributor [Pilot] contributed between 13-24 PRs to the CDK bug This issue is a bug. p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws_stepfunctions_tasks : Generates wrong action in role policy
3 participants