Package APIs

Related Documentation
OpenAPI Specifications
Minimum Version
Kong Gateway - 3.13
Incompatible with
on-prem

This is a reference guide, you can also follow along with our Package APIs for partners with Dev Portal tutorial.

You can compose API packages from existing APIs in Dev Portal. API packages allow you to:

  • Create distinct APIs for specific use cases or partners based on existing API operations.
  • Link to multiple Gateway Services and/or Routes for developer self-service and application registration.
  • Apply rate limiting policies to an API Package, or per operation.
  • Manage role-based access control to specific developers and teams.

The following table describes common API package use cases:

Use case

Description

Example

Customize APIs for partners Using API packages, you can customize which operations/endpoints are included in Dev Portals for partners. If you have multiple APIs/services, you can select specific operations from each API (for example, GET /billing and GET /flights) creating an API package for partners in an external Dev Portal, called “Flight Billing API”. Meanwhile, Billing and Flights APIs can also be published to your internal Dev Portal.
Apply rate limits to applications While Gateway Services or Routes may have systemic rate limits in place, it’s often necessary to apply lower rate limits to applications when exposing those capabilities to partners. When creating the “Flight Billing API” package, GET /billing may need a lower rate limit of 10 request per minute, while the overall API package could have something higher, like five requests per second.

How API packages work

API packages are composed from operations. Operations allow you to compose REST-style APIs from a combination of the hostname, path, and method that are processed by the control plane. They are used to map between the operations in your API and Gateway Routes. If an OpenAPI spec is added to the API, the operations are autogenerated.

The following diagram shows an example of how API packages can be composed from operations:

 
flowchart LR
 subgraph subGraph0["Control plane"]
        1["Billing Gateway Service"]
        2["Flights Gateway Service"]
  end
 subgraph subGraph1["Partners API package"]
        3["POST /flights"]
        4["GET /flights"]
  end
 subgraph subGraph2["Org API package"]
        5["POST /billing"]
        6["GET /billing"]
        7["POST /flights"]
        8["GET /flights"]
  end
    1 --> 5 & 6
    2 --> 7 & 8 & 3 & 4
  

Packaging APIs involves the following steps:

  1. Create an API and attach an OpenAPI spec. Operations from your API’s OpenAPI spec should overlap with Routes to ensure requests will be routed to the correct Service. Gateway routing configuration isn’t directly modified by adding operations.
  2. Link a control plane to allow developer consumption.
  3. Apply the Access Control Enforcement (ACE) plugin globally.
  4. Create an API package by adding operations and package rate limits. Operations are automatically mapped to Routes using your API’s OpenAPI spec or you can create them manually. The Gateway configuration isn’t directly modified – any unmatched operations will be highlighted to indicate that a user needs Gateway Manager permissions needs to perform an action.

ACE plugin

The Access Control Enforcement (ACE) plugin manages developer access control to APIs published with Dev Portal.

Previously, when you created an API catalog in Dev Portal and linked the APIs to a Gateway Service, Konnect would automatically apply the Konnect application auth (KAA) plugin. API packages use the ACE plugin instead to manage developer access control to APIs. Unlike the KAA plugin, the ACE plugin can link to control planes to configure access control and create operations for Gateway Services.

The ACE plugin runs after all other authentication plugins run. For example, if you have Key Authentication configured and it rejects a request, the ACE plugin will not run.

To allow for multiple authentication plugins, each one must set the config.anonymous plugin configuration. Additionally, the choice to allow or reject an anonymous result after all authentication plugins have run needs to be controlled as described in using multiple authentication methods.

Route matching policy

When you configure the ACE plugin, you must set either required or present for config.match_policy. This determines how the ACE plugin will behave when a request doesn’t match an existing Route.

Keep in mind that misconfigurations can overexpose unintended Routes.

The following table describes what the match_policy values do and when to use each:

Setting

Description

Limitations

Use cases

required Requires every incoming request to match a defined operation from an API or API package in Dev Portal. If a request doesn’t match, ACE rejects the request outright with a 404. All traffic will be rejected except operations or Routes in published APIs linked to an ACE-enabled Kong Gateway.

Warning: Setting the match_policy to required can block all traffic with a 404. Any undefined endpoints will be blocked. If you accidentally enable this in your control planes, this could cause a potential outage in production.

  • Shuts down all traffic outside of ACE-enabled Dev Portal APIs.
  • If the plugin is improperly configured, potentially all traffic could be terminated.
  • You want to lock down Konnect so that only traffic that is part of an explicitly defined API operation is allowed through.
  • You only plan to provide self-service access via your Dev Portal.
if_present By default, the ACE plugin only engages with a request when it matches an operation. If a request doesn’t match, ACE lets the request pass through untouched. This means that non-matching requests aren’t rejected, but ACE also won’t perform authentication and authorization on them. This allows a request to still be processed by other plugins with a lower priority than ACE.
  • All traffic outside of published APIs linked to an ACE-enabled Kong Gateway won’t be access controlled; this must be configured with a different authentication plugin. Dev Portal will not be able to protect all operations.
  • Since Routes aren’t protected by default in this mode, any mistyped or omitted operation in API entities could result in open access.
  • You have an environment where some Gateway Services or Routes are governed by Dev Portal–exposed APIs (with ACE), while others are regular Routes that should be left alone.
  • You already have existing traffic and other access controls in place and want to avoid interruption.

Package rate limits

You can set individual rate limits on an API package as well as operations in that package. Keep the following in mind when configuring rate limits:

  • API package rate limits apply across all operations in the API package cumulatively, not individually.
  • Each operation in an API Package can additionally have an individual rate limit defined. When an operation-level override is present, the package-level limit is ignored for that operation.
  • API package rate limits are applied simultaneously with rate limits from other plugins on gateway entities:
    • Requests that are under the current limit for the Service and API Package will be counted towards both.
    • Requests that surpass the rate limit of an API package won’t be counted towards rate limits applied from other rate limiting plugins.
    • Requests that surpass the rate limit of other rate limiting plugins are still counted towards the rate limits applied for API packages. This is because the ACE plugin runs before other rate limiting plugins under the default plugin priorities. You can adjust this behavior with custom plugin priority values.
    • Rate limiting is applied per credential.

For example, if you have the following rate limits set:

  • API package A: 10 requests per second
  • Operation 1: 5 requests per second

Because an operation-level override is present, the package-level limit is ignored for that operation. This means a request authorized for Operation 1 will only count toward its specific operation-level limit. So, if one request is sent, the authorized application will have four requests remaining for Operation 1 for the configured time period (per second). The package-level limit of API Package A doesn’t apply to this request.

API package limitations

When configuring API packages, keep the following limitations in mind:

  • If you have two endpoints in your spec, one with a trailing slash and one without, both are generated as the same operation.
  • If two operations have the same path and method, they are generated as the same operation.
  • All operations for a control plane are removed when you unlink the control plane.
  • APIs can only be mapped to one control plane at a time.
  • You can’t change a version or edit a spec for an API if it would remove an operation because this would result in a breaking change. To remove an operation, we recommend unlinking the control plane from the API.

Package APIs with Dev Portal

This guide shows you how to create an API package in the Konnect UI.

For an end-to-end tutorial with sample data that walks you through setting up and using API Packages, see Package APIs with Dev Portal.

Prerequisites

To package APIs with Dev Portal, you need:

  • A v3 Dev Portal created in Konnect
  • A Gateway Service and/or Route added to your control plane (Kong Gateway 3.13 or later)
  • The following roles:
    • Editor role for APIs
    • Publisher role for the API and API package
    • API Creator
  • An API created with an OpenAPI spec associated with it
  • A Gateway control plane linked to your API in Catalog > APIs

Create an API package

  1. In Konnect, click Catalog.
  2. Click the API packages tab.
  3. Click Create API package.
  4. In the API package name field, enter a name for your package.
  5. Enable the Package rate limit and configure your rate limit.
  6. Click Add operations from APIs in the API operations settings.
  7. In the Add API operations pane, click your API and click Add next to the operations you want to package.
  8. Click Create API package.

Your operations should now be autogenerated based on how your OpenAPI spec maps to your Routes.

Publish packages to Dev Portal

  1. In Konnect, click Catalog.
  2. Click the API packages tab.
  3. Click your API package.
  4. Click Publish API.
  5. From the Portal dropdown menu, select your Dev Portal.
  6. From the Authentication strategy dropdown menu, select an auth strategy.
  7. Click Public.
  8. Click Publish API.

Your API package will now be published to your Dev Portal. Published API packages appear the same as published APIs in the Dev Portal, and both allow developers to register applications with them.

Something wrong?

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!