Skip to content

feat(rest-api): SecurityPolicy & EndpointAccessMode support#144

Closed
afa4 wants to merge 4 commits into
oss-serverless:mainfrom
afa4:feat/api-securtity-policy-support
Closed

feat(rest-api): SecurityPolicy & EndpointAccessMode support#144
afa4 wants to merge 4 commits into
oss-serverless:mainfrom
afa4:feat/api-securtity-policy-support

Conversation

@afa4
Copy link
Copy Markdown
Contributor

@afa4 afa4 commented Feb 25, 2026

Summary

  • Add support for securityPolicy property under provider.apiGateway to configure TLS version on REST APIs
  • Add support for endpointAccessMode property under provider.apiGateway to control API endpoint access mode (STRICT or BASIC)
  • Add documentation for both new properties in docs/events/apigateway.md

Fixes #133

Example of usage:

provider:
  name: aws
  apiGateway:
    securityPolicy: SecurityPolicy_TLS13_2025_EDGE  # Recommended: Use TLS 1.2 or higher
    endpointAccessMode: STRICT

important notice:

both securityPolicy and endpointAccessMode configs are available only for AWS REST API Gateways, which are created when httpevents are used:

functions:
  testFunctionAwsRest:
    handler: index.handler
    events:
      - http:
          path: /test
          method: get

These properties have no effect if httpApi events are being used since this creates an AWS HTTP API (v2) in the CloudFormation stack:

# securityPolicy and endpointAccessMode configs wont have any effect because of httpApi event config
functions:
  testFunctionAwsHttp:
    handler: index.handler
    events:
      - httpApi:
          # ...

@afa4 afa4 force-pushed the feat/api-securtity-policy-support branch from 67fb215 to f9719ab Compare February 25, 2026 15:08
Copy link
Copy Markdown
Contributor

@mnapoli mnapoli left a comment

Choose a reason for hiding this comment

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

Could you cover this with tests?

Comment thread lib/plugins/aws/provider.js Outdated
@afa4
Copy link
Copy Markdown
Contributor Author

afa4 commented Feb 25, 2026

Could you cover this with tests?

sure, wip

@afa4 afa4 force-pushed the feat/api-securtity-policy-support branch from f9719ab to 3de444a Compare February 25, 2026 17:12
@afa4 afa4 requested a review from mnapoli February 25, 2026 17:17
@afa4
Copy link
Copy Markdown
Contributor Author

afa4 commented Feb 25, 2026

I had to fix some lint issues

@afa4 afa4 marked this pull request as ready for review February 25, 2026 18:24
@mnapoli
Copy link
Copy Markdown
Contributor

mnapoli commented Mar 25, 2026

This needs docs too, sorry I didn't spot that before. Have a look at other merged PRs to get an idea on what's needed to be merged.

@afa4
Copy link
Copy Markdown
Contributor Author

afa4 commented Apr 7, 2026

This needs docs too, sorry I didn't spot that before. Have a look at other merged PRs to get an idea on what's needed to be merged.

No problem, I'll check everything to ensure the best release possible.

@afa4 afa4 changed the title feat(api-gateway): SecurityPolicy support feat(rest-api): SecurityPolicy & EndpointAccessMode support Apr 7, 2026
@afa4
Copy link
Copy Markdown
Contributor Author

afa4 commented Apr 8, 2026

@mnapoli I think something is wrong with "Validate Windows" check. It's being running for 5 hours :s

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds new AWS REST API Gateway configuration options under provider.apiGateway to control TLS security policy and endpoint access mode, wiring them through CloudFormation compilation and documenting their usage.

Changes:

  • Extend REST API compilation to include SecurityPolicy and EndpointAccessMode on AWS::ApiGateway::RestApi.
  • Add provider schema validation for apiGateway.securityPolicy and apiGateway.endpointAccessMode.
  • Add unit tests and documentation covering the new options.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
lib/plugins/aws/package/compile/events/api-gateway/lib/rest-api.js Passes through securityPolicy/endpointAccessMode into the compiled REST API CloudFormation properties.
lib/plugins/aws/provider.js Adds config schema entries for provider.apiGateway.securityPolicy and provider.apiGateway.endpointAccessMode.
test/unit/lib/plugins/aws/package/compile/events/api-gateway/lib/rest-api.test.js Adds/updates unit assertions to cover the new compiled properties.
docs/events/apigateway.md Documents securityPolicy and endpointAccessMode usage for REST APIs.
lib/plugins/aws/custom-resources/resources/api-gateway-cloud-watch-role/handler.js Minor formatting change in error handling condition.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +30 to +31
if (apiGateway.endpointAccessMode) {
EndpointAccessMode = apiGateway.endpointAccessMode.toUpperCase();
Copy link

Copilot AI Apr 26, 2026

Choose a reason for hiding this comment

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

endpointAccessMode is allowed to be an empty string by the provider schema/docs, but this truthy check skips the assignment when users set it to ''. If the intention is to let users explicitly pass an empty value through to CloudFormation (e.g. for legacy SecurityPolicy behavior), change the condition to check for null/undefined (or property presence) instead of truthiness, and only uppercase when the value is non-empty.

Suggested change
if (apiGateway.endpointAccessMode) {
EndpointAccessMode = apiGateway.endpointAccessMode.toUpperCase();
if (apiGateway.endpointAccessMode != null) {
EndpointAccessMode =
apiGateway.endpointAccessMode === ''
? apiGateway.endpointAccessMode
: apiGateway.endpointAccessMode.toUpperCase();

Copilot uses AI. Check for mistakes.
type: 'string',
},
endpointAccessMode: {
anyOf: ['strict', 'basic', ''].map(caseInsensitive),
Copy link

Copilot AI Apr 26, 2026

Choose a reason for hiding this comment

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

Schema allows endpointAccessMode to be '', but compileRestApi currently ignores empty-string values. Either drop '' from the schema if it’s not meant to be user-configurable, or adjust the compiler to preserve an explicitly configured empty value so config validation and generated CloudFormation stay consistent.

Suggested change
anyOf: ['strict', 'basic', ''].map(caseInsensitive),
anyOf: ['strict', 'basic'].map(caseInsensitive),

Copilot uses AI. Check for mistakes.
Comment thread docs/events/apigateway.md
### Security Policy

You can configure the TLS version for your API Gateway REST API by setting the `securityPolicy` property under `apiGateway` in the `provider` block. This maps directly to the [SecurityPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-securitypolicy) property of the `AWS::ApiGateway::RestApi` CloudFormation resource.
Specific explanation about Security Policy types and structure can be found [here](https://aws.amazon.com/blogs/compute/enhancing-api-security-with-amazon-api-gateway-tls-security-policies/)
Copy link

Copilot AI Apr 26, 2026

Choose a reason for hiding this comment

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

Missing ending punctuation and an article: this sentence reads unpolished in the docs. Consider changing it to “A specific explanation of security policy types and structure can be found here: …” (and end with a period).

Suggested change
Specific explanation about Security Policy types and structure can be found [here](https://aws.amazon.com/blogs/compute/enhancing-api-security-with-amazon-api-gateway-tls-security-policies/)
A specific explanation of security policy types and structure can be found [here](https://aws.amazon.com/blogs/compute/enhancing-api-security-with-amazon-api-gateway-tls-security-policies/).

Copilot uses AI. Check for mistakes.
Comment thread docs/events/apigateway.md

### Endpoint Access Mode

You can control how clients access your API Gateway endpoint by setting the `endpointAccessMode` property under `apiGateway` in the `provider` block. Valid values are `STRICT` and `BASIC`. This maps directly to the [EndpointAccessMode](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-endpointaccessmode) property of the `AWS::ApiGateway::RestApi` CloudFormation resource. According to AWS documentation, if a security policy is configured with a legacy template (that doesn't have the `SecurityPolicy_` prefix) access Mode should be empty)
Copy link

Copilot AI Apr 26, 2026

Choose a reason for hiding this comment

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

Grammar/parentheses issue: the last clause ends with an extra ) and “access Mode” should be “access mode”. Please rephrase the sentence and end it with proper punctuation (and consider formatting the note as a separate sentence).

Suggested change
You can control how clients access your API Gateway endpoint by setting the `endpointAccessMode` property under `apiGateway` in the `provider` block. Valid values are `STRICT` and `BASIC`. This maps directly to the [EndpointAccessMode](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-endpointaccessmode) property of the `AWS::ApiGateway::RestApi` CloudFormation resource. According to AWS documentation, if a security policy is configured with a legacy template (that doesn't have the `SecurityPolicy_` prefix) access Mode should be empty)
You can control how clients access your API Gateway endpoint by setting the `endpointAccessMode` property under `apiGateway` in the `provider` block. Valid values are `STRICT` and `BASIC`. This maps directly to the [EndpointAccessMode](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-endpointaccessmode) property of the `AWS::ApiGateway::RestApi` CloudFormation resource. According to AWS documentation, if a security policy is configured with a legacy template (that does not have the `SecurityPolicy_` prefix), access mode should be empty.

Copilot uses AI. Check for mistakes.
@GrahamCampbell
Copy link
Copy Markdown
Contributor

Thanks for getting started here. I've finished off the PR at #167.

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.

Specify Security Policy option for API Gateway

4 participants