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

(aws-cdk-lib): aws-sam.CfnApi does not support auth.ResourcePolicy and other options #31518

Open
1 task
tsuga opened this issue Sep 21, 2024 · 2 comments
Open
1 task
Assignees
Labels
aws-cdk-lib Related to the aws-cdk-lib package bug This issue is a bug. effort/small Small work item – less than a day of effort needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. p2

Comments

@tsuga
Copy link

tsuga commented Sep 21, 2024

Describe the bug

AWS::Serverless::Api supports various auth methods.

AddApiKeyRequiredToCorsPreflight: Boolean
AddDefaultAuthorizerToCorsPreflight: Boolean
ApiKeyRequired: Boolean
Authorizers: CognitoAuthorizer | LambdaTokenAuthorizer | LambdaRequestAuthorizer
DefaultAuthorizer: String
InvokeRole: String
ResourcePolicy: ResourcePolicyStatement
UsagePlan: ApiUsagePlan

https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-api-apiauth.html

However, only AddDefaultAuthorizerToCorsPreflight, Authorizers, and DefaultAuthorizer are supported.
Others such as ResourcePolicy and ApiKeyRequired are not supported.

./node_modules/aws-cdk-lib/aws-sam/lib/sam.generated.d.ts

export interface CfnApiProps {
    [...]
    /**
     * @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-serverless-api.html#cfn-serverless-api-auth
     */
    readonly auth?: CfnApi.AuthProperty | cdk.IResolvable;
    interface AuthProperty {
        /**
         * @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-serverless-api-auth.html#cfn-serverless-api-auth-adddefaultauthorizertocorspreflight
         */
        readonly addDefaultAuthorizerToCorsPreflight?: boolean | cdk.IResolvable;
        /**
         * @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-serverless-api-auth.html#cfn-serverless-api-auth-authorizers
         */
        readonly authorizers?: any | cdk.IResolvable;
        /**
         * @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-serverless-api-auth.html#cfn-serverless-api-auth-defaultauthorizer
         */
        readonly defaultAuthorizer?: string;

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

It should cover all supported options.

Current Behavior

only AddDefaultAuthorizerToCorsPreflight, Authorizers, and DefaultAuthorizer are supported.

Reproduction Steps

See above

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.159.1 (build c66f4e3)

Framework Version

No response

Node.js Version

20

OS

ubuntu

Language

TypeScript

Language Version

No response

Other information

No response

@tsuga tsuga added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 21, 2024
@github-actions github-actions bot added the aws-cdk-lib Related to the aws-cdk-lib package label Sep 21, 2024
@ashishdhingra ashishdhingra self-assigned this Sep 23, 2024
@ashishdhingra ashishdhingra added investigating This issue is being investigated and/or work is in progress to resolve the issue. p2 and removed needs-triage This issue or PR still needs to be triaged. labels Sep 23, 2024
@ashishdhingra
Copy link
Contributor

ashishdhingra commented Sep 23, 2024

Findings:

  • AWS::Serverless::Api > Auth defined the below properties (as reported by user):
    AddApiKeyRequiredToCorsPreflight: Boolean
    AddDefaultAuthorizerToCorsPreflight: Boolean
    ApiKeyRequired: Boolean
    Authorizers: CognitoAuthorizer | LambdaTokenAuthorizer | LambdaRequestAuthorizer
    DefaultAuthorizer: String
    InvokeRole: String
    ResourcePolicy: ResourcePolicyStatement
    UsagePlan: ApiUsagePlan
    
  • For generating L1 constructs, AWS service spec is loaded here.
    • loadAwsServiceSpec ins imported from @aws-cdk/aws-service-spec module.
  • loadAwsServiceSpec() loads compressed db.json.gz into buffer.
  • db.json.gz is generated via build-db.main() which creates instance of FullDatabase.
  • FullDatabase imports CloudFormation resource spec, SAM resource spec, etc. here.
    • SAM resource schema is loaded from CloudFormationResourceSpecification/us-east-1/100_sam and SAMSpec/sam.schema.json.
    • SAMSpec/sam.schema.json was updated 5 months ago and for AWS::Serverless::Api.Auth, it only defines below properties:
      • DefaultAuthorizer
      • Authorizers
      • AddDefaultAuthorizerToCorsPreflight

Will monitor to check if SAMSpec/sam.schema.json is updated in few days.

@ashishdhingra ashishdhingra added needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. effort/small Small work item – less than a day of effort p1 p2 and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. p2 p1 labels Sep 23, 2024
@ashishdhingra ashishdhingra removed their assignment Sep 30, 2024
@jiayiwang7 jiayiwang7 assigned HBobertz and jiayiwang7 and unassigned HBobertz Sep 30, 2024
@jiayiwang7
Copy link
Member

jiayiwang7 commented Oct 1, 2024

We will be loading the SAM resources from the official SAM schema https://raw.githubusercontent.com/aws/serverless-application-model/develop/schema_source/sam.schema.json

Once cdklabs/awscdk-service-spec#898 is merged, you shall see the updated schemas with ResourcePolicy, ApiKeyRequired in it.

@jiayiwang7 jiayiwang7 assigned kaizencc and unassigned jiayiwang7 Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws-cdk-lib Related to the aws-cdk-lib package bug This issue is a bug. effort/small Small work item – less than a day of effort needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. p2
Projects
None yet
Development

No branches or pull requests

5 participants