Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit b6b83eb

Browse files
committed
Adding support for API GW configuration
Lots of options including authentication, rate limiting and more...
1 parent cb1ea67 commit b6b83eb

File tree

9 files changed

+875
-189
lines changed

9 files changed

+875
-189
lines changed

README.md

Lines changed: 95 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,6 @@ functions:
777777
HTTP event configuration also supports using explicit parameters.
778778

779779
- `method` - HTTP method (mandatory).
780-
- `basepath` - base path of the API in which the event is added (optional, defaults to service name)
781780
- `path` - URI path for API gateway (mandatory).
782781
- `resp` - controls [web action content type](https://github.com/apache/incubator-openwhisk/blob/master/docs/webactions.md#additional-features), values include: `json`, `html`, `http`, `svg`or `text` (optional, defaults to `json`).
783782

@@ -788,8 +787,7 @@ functions:
788787
events:
789788
- http:
790789
method: GET
791-
basepath: /mybasepath
792-
path: /api/http
790+
path: /api/greeting
793791
resp: http
794792
```
795793

@@ -799,7 +797,7 @@ API Gateway hosts serving the API endpoints will be shown during deployment.
799797
$ serverless deploy
800798
...
801799
endpoints:
802-
GET https://xxx-gws.api-gw.mybluemix.net/service_name/api/path --> service_name-dev-my_function
800+
GET https://xxx-gws.api-gw.mybluemix.net/service_name/api/greeting --> service_name-dev-my_function
803801
```
804802

805803
Calling the configured API endpoints will execute the deployed functions.
@@ -849,6 +847,99 @@ resources:
849847
cors: false
850848
```
851849

850+
### Application Authentication
851+
852+
API endpoints can be protected by API keys with a secret or API keys alone.
853+
854+
Setting the HTTP headers used to pass keys and secrets automatically enables API Gateway authentication.
855+
856+
This parameter configures the HTTP header containing the API key. Without the additional secret header, authentication uses an API key alone.
857+
858+
```yaml
859+
resources:
860+
apigw:
861+
auth:
862+
key: API-Key-Header
863+
```
864+
865+
Adding the secret header parameter enables authentication using keys with secrets.
866+
867+
```yaml
868+
resources:
869+
apigw:
870+
auth:
871+
key: API-Key-Header
872+
secret: API-Key-Secret-Header
873+
```
874+
875+
*See the API Gateway [configuration panel](https://cloud.ibm.com/openwhisk/apimanagement) to manage API keys and secrets after authentication is enabled.*
876+
877+
### Application Authentication with OAuth
878+
879+
API endpoints can also be protected by an external OAuth providers.
880+
881+
OAuth tokens must be included as the Authorization header of each API request. Token will be validated with the specified token provider. If the token is invalid, requests are rejected with response code 401.
882+
883+
The following OAuth providers are supported: *[IBM Cloud App ID](https://cloud.ibm.com/catalog/services/app-id), Google, Facebook and Github.*
884+
885+
```yaml
886+
resources:
887+
apigw:
888+
oauth:
889+
provider: app-id || google || facebook || github
890+
```
891+
892+
If the `app-id` provider is selected, the tenant identifier must be provided as an additional configuration token. This can be retrieved from the `tenantId` property of provisioned service credentials for the instance
893+
894+
```yaml
895+
resources:
896+
apigw:
897+
oauth:
898+
provider: app-id
899+
tenant: uuid
900+
```
901+
902+
*Application Authentication with keys (and secrets) and OAuth support are mutually exclusive configuration options.*
903+
904+
### Rate Limiting
905+
906+
API Gateways endpoints support rate limiting to reject excess traffic. When rate limiting is enabled, API calls falling outside of the limit will be rejected and response code 429 will be returned.
907+
908+
**Rate limiting is on a per-key basis and application authentication (without oauth) must be enabled.**
909+
910+
The leaky bucket algorithm is used to prevent sudden bursts of invocations of APIs. If the limit is set as 10 calls per minute, users will be restricted to 1 call every 6 seconds (60/10 = 6).
911+
912+
```yaml
913+
resources:
914+
apigw:
915+
rate_limit:
916+
rate: 100
917+
unit: minute || second || hour || day
918+
```
919+
920+
- `rate`: number of API calls per unit of time.
921+
- `unit`: unit of time (*minute, second, hour, day*) used to threshold API calls with rate.
922+
923+
### Base Path
924+
925+
All API Gateway endpoints defined as HTTP events in the `serverless.yml` are deployed under the default base path (`/`). This basepath can be configured explicitly using the following parameter.
926+
927+
```yaml
928+
resources:
929+
apigw:
930+
basepath: /api
931+
```
932+
933+
### API Name
934+
935+
The service name is used as the API identifier in the API Gateway swagger files. This can be configured explicitly using the following parameter.
936+
937+
```yaml
938+
resources:
939+
apigw:
940+
name: my-api-name
941+
```
942+
852943
## Exporting Web Actions
853944

854945
Functions can be turned into "*web actions*" which return HTTP content without use of an API Gateway. This feature is enabled by setting an annotation (`web-export`) in the configuration file.

0 commit comments

Comments
 (0)