Skip to content

RFC: API Gateway IAM (AWS_IAM) Authorizers #781

Closed

Description

@brettstack

This is an RFC for enabling IAM (AWS_IAM) auth type on APIs.

SAM Template:

Resources:
  MyApi:
    ...
    Properties:
      Auth:
        # Sets auth type for all resources+methods of this API
        # Can be overridden at method level
        DefaultAuthorizer: AWS_IAM

        # Sets integration credentials for all resources+methods to this value
        # When this value is CALLER_CREDENTIALS, it sets it to the special value of "arn:aws:iam::*:user/*"
        # Can be overridden at method level
        # Default: CALLER_CREDENTIALS (when DefaultAuthorizer=AWS_IAM; otherwise  null)
        # Alternate names: `InvokeCredentials`
        # Values: IAM Role (e.g arn:aws:iam::123456789012:role/S3Access) or CALLER_CREDENTIALS (special case)
        InvokeRole: CALLER_CREDENTIALS 

  MyFunction:
    ...
    Events:
      MyApiEvent:
        Type: Api
        Properties:
          Path: /
          Method: get

          # Override at resource+method level
          # Setting `Authorizer` to null makes this endpoint open/public
          # These properties accept the same values as DefaultAuthorizer and InvokeRole on the API resource
          Auth:
            Authorizer: null
            InvokeRole: null

CloudFormation/Swagger Output:

  1. Adds a sigv4 security scheme to Swagger
  2. Adds sigv4 to list of security for each resource+method using AWS_IAM
  3. Adds credentials to x-amazon-apigateway-integration for each resource+method using AWS_IAM
paths:
  /:
    get:
      security:
      - sigv4: []
      x-amazon-apigateway-integration:
        # This is set to "arn:aws:iam::*:user/*" when `InvokeRole: CALLER_CREDENTIALS`; otherwise it is set to the IAM Role specified.
        credentials: "arn:aws:iam::*:user/*"

securityDefinitions:
  sigv4:
    type: "apiKey"
    name: "Authorization"
    in: "header"
    x-amazon-apigateway-authtype: "awsSigv4"

Invoking APIs with IAM auth requires requests to be signed using Signature Version 4 https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html (derived from an AWS secret access key). The generated API Gateway SDK performs Signature Version 4 signing for you. Alternatively, libraries such as https://github.com/mhart/aws4 exist to make signing requests simpler.

Resources:

Activity

  1. pinned this issue on Jan 23, 2019
  2. jlhood commented on Jan 23, 2019

    @jlhood
    Contributor

    I don't get what this part means:

              Auth:
                Authorizer: null
                InvokeRole: null

    Is that showing how to override auth for a specific path using function events?

  3. brettstack commented on Jan 23, 2019

    @brettstack
    ContributorAuthor

    @jlhood that's correct. I will update with clarification.

  4. jlhood commented on Jan 23, 2019

    @jlhood
    Contributor

    @brettstack Ok. Would also be good to add a Path/Method? Otherwise it looks incomplete to me. Also a yaml comment to explain what this is demonstrating.

  5. brettstack commented on Jan 25, 2019

    @brettstack
    ContributorAuthor

    We'll begin implementation based on this spec.

  6. unpinned this issue on Jan 25, 2019
  7. added
    contributors/good-first-issue
    on Feb 8, 2019
  8. keetonian commented on Apr 26, 2019

    @keetonian
    Contributor

    Released with SAM v1.11.0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    contributors/good-first-issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions