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

Commit bed4cf7

Browse files
author
Chris Wiechmann
authored
Merge pull request #20 from Axway-API-Management-Plus/org-support
Adding support for Org-Admins to use the Traffic-Monitor
2 parents ecabb3b + a7e3a5c commit bed4cf7

File tree

65 files changed

+5104
-105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+5104
-105
lines changed

.env

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,42 @@
1+
# ----------------------------------------------------------------------------------------------
12
# Filebeat will mount that folder into the Filebeat Docker-Container to have access to the files
23
APIGATEWAY_LOGS_FOLDER=/home/localuser/Axway-x.y.z/apigateway/logs/opentraffic
34
APIGATEWAY_TRACES_FOLDER=/home/localuser/Axway-x.y.z/apigateway/groups/group-2/instance-1/trace
45

5-
# This variable is used by the API-Builder project to locate the Elasticsearch instance
6-
# Using the default docker-compose.yaml this setting is sufficient
7-
# When running the API-Builder on a different host, this variable needs to be made available to the
8-
# container.
9-
ELASTIC_NODE=http://elasticsearch1:9200
6+
# ----------------------------------------------------------------------------------------------
7+
# This variable is used by the API-Builder to locate the Elasticsearch instance
8+
# When using the default docker-compose.yaml this setting is optional.
9+
# But, when running the ElasticSearch on a difference host (e.g. existing Elastic-Search cluster)
10+
# this environment variable is used by the API-Builder to locate the ElasticSearch cluster.
11+
# ELASTIC_NODE=http://elasticsearch1:9200
12+
13+
# ----------------------------------------------------------------------------------------------
14+
# This variable is used by Logstash to communicate with the Lookup-API, which is used to
15+
# enrich documents before sending it to ElasticSearch.
16+
# When using the default docker-compose.yml the default setting will work.
17+
# But, if the API-Builder process is running somewhere else (e.g. externally), you have to make
18+
# this environment variable available to the Logstash Docker-Container.
19+
API_BUILDER_URL=http://elk-traffic-monitor-api:8080
20+
21+
22+
# ----------------------------------------------------------------------------------------------
23+
# The following three variables are used by the API-Builder project to communicate with the
24+
# API-Management platform (Admin-Node-Manager & API-Manager)
25+
26+
# The Connection/URL to the Admin-Node-Manager.
27+
# IMPORTANT NOTE:
28+
# This URL must be reachable/resolveable from within the API-Builder Docker-Container!
29+
ADMIN_NODE_MANAGER=https://api-env:8090
30+
31+
# ----------------------------------------------------------------------------------------------
32+
# The Connection/URL to the API-Manager. If not given, the same as Admin-Node-Manager URL with
33+
# port 8075 is used.
34+
# IMPORTANT NOTE:
35+
# This URL must be reachable/resolveable from within the API-Builder Docker-Container!
36+
# API_MANAGER=https://api-env:8075
37+
38+
# ----------------------------------------------------------------------------------------------
39+
# This user is used by API-Builder to lookup APIs & User-Information in API-Manager.
40+
# Therefore it must be a user having "admin" role.
41+
API_MANAGER_USERNAME=apiadmin
42+
API_MANAGER_PASSWORD=changeme
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# This workflow is validating the API-Builder exposed Traffic-Monitor API.
2+
# For that an Elasticsearch instance is started, test-data inserted and the
3+
# API-Builder Traffic-Monitor API is executed with all possible parameters.
4+
5+
name: API-Builder API-Utils Flow-Node
6+
7+
8+
on:
9+
push:
10+
branches: [ master ]
11+
pull_request:
12+
branches: [ master ]
13+
release:
14+
types: [ published ]
15+
16+
jobs:
17+
build:
18+
if: "!contains(github.event.head_commit.message, 'skip ci')"
19+
env:
20+
workingDirectory: 'elk-traffic-monitor-api/custom_flow_nodes/api-builder-plugin-axway-api-management'
21+
22+
runs-on: ubuntu-latest
23+
24+
strategy:
25+
matrix:
26+
node-version: [12.x]
27+
28+
steps:
29+
- uses: actions/checkout@v2
30+
- name: Use Node.js ${{ matrix.node-version }}
31+
uses: actions/setup-node@v1
32+
with:
33+
node-version: ${{ matrix.node-version }}
34+
- name: Run npm ci, npm test
35+
working-directory: ${{env.workingDirectory}}
36+
env:
37+
LOG_LEVEL: DEBUG
38+
CI: true
39+
run: |
40+
npm ci
41+
npm run build --if-present
42+
npm test
43+
44+

.github/workflows/traffic-monitor-api.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: Starting Elasticsearch instance
3535
uses: nyaruka/elasticsearch-action@v1
3636
with:
37-
elastic version: '7.6.1'
37+
elastic version: '7.8.1'
3838
- name: Sleep 15 seconds to make sure ES is ready
3939
uses: jakejarvis/wait-action@master
4040
with:

README.md

Lines changed: 72 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
# API-Management Traffic-Monitor based ELK stack
22

3+
This project has 3 main objectives in relation to the Axway API management solution.
4+
5+
__Performance__
6+
37
When having many API-Gateway instances with millions of requests the API-Gateway Traffic Monitor can become slow and the observation period quite short. The purpose of this project is to solve that performance issue, make it possible to observe a long time-frame and get other benefits by using a standard external datastore: [Elasticsearch](https://www.elastic.co/elasticsearch).
48

9+
__Visibility__
10+
11+
This solution allows API service providers to give access to the Standard Traffic Monitor so that they only see the API traffic of their own organization. This allows API service providers to analyze their own traffic using the extensive information in the traffic monitor.
12+
13+
__Analytics__
14+
15+
With the help of Kibana, the goal of the project is to deliver standard dashboards that provide analysis capabilities across multiple perspectives.
16+
It should still be possible to add your own dashboards as you wish.
17+
18+
## Architecture
19+
520
The overall architecture this project provides looks like this:
621
![Architecture][img1]
722

@@ -11,20 +26,35 @@ It also helps, when running the Axway API-Gateway in Docker-Orchestration-Enviro
1126
Watch this video to see a side by side compare betwen the classical and ElasticSearch based Traffic-Monitor:
1227
[![API-Management CLI](https://img.youtube.com/vi/MUbx4m9EtpY/0.jpg)](https://youtu.be/MUbx4m9EtpY)
1328

14-
### How it works
29+
## How it works
1530
Each API-Gateway instance is writing, [if configured](#enable-open-traffic-event-log), Open-Traffic Event-Log-Files, which are streamed by [Filebeat](https://www.elastic.co/beats/filebeat) into a Logstash-Instance. [Logstash](https://www.elastic.co/logstash) performs data pre-processing, combines different events and finally forwards these so called documents into an Elasticsearch cluster.
1631

1732
Once the data is indexed by Elasticsearch it can be used by different clients. This process allows almost realtime monitoring of incoming requests. It takes around 5 seconds until a request is available in Elasticsearch.
1833

19-
## Using the existing Traffic-Monitor
20-
Use the existing API-Gateway Traffic-Monitor. That means, you use the same tooling as of today, but the underlying implementation of the Traffic-Monitor API is now pointing to Elasticsearch instead of the internal OPSDB hosted by each API-Gateway instance. This improves performance damatically, as Elasticsearch can scale across multiple machines if required and other dashboards can be created for instance with Kibana.
34+
## The Traffic-Monitor
35+
36+
The standard API-Gateway Traffic-Monitor which is shipped with the solution is based on a REST-API that is provided by the Admin-Node-Manager. By default the Traffic-Information is loaded from the OBSDB running on each API-Gateway instance. This project is partly re-implementing this REST-API, which makes it possible, that the Traffic-Monitor is using data from ElasticSearch instead of the internal OBSDB.
37+
That means, you can use the same tooling as of today, but the underlying implementation of the Traffic-Monitor is now pointing to Elasticsearch instead of the internal OPSDB hosted by each API-Gateway instance. This improves performance damatically, as Elasticsearch can scale across multiple machines if required and other dashboards can be created for instance with Kibana.
2138
The glue between Elasticsearch and the API-Gateway Traffic-Monitor is an [API-Builder project](./elk-traffic-monitor-api), that is exposing the same Traffic-Monitor API, but it is implemented using Elasticsearch instead of the OPSDB. The API-Builder is available as a ready to use Docker-Image and preconfigured in the docker-compose file.
2239
Optionally you can import the API-Builder API into your API-Management system to apply additional security and by that secure access to your Elasticsearch instance.
2340

24-
Finally, the Admin-Node-Manager has to be [configured](#configure-the-admin-node-manager) to use the API-Builder API instead of the internal implementation.
41+
## Restrict the Traffic-Monitor
2542

26-
API-Builder exposing Traffic-Monitor API:
27-
[![Traffic-Monitor API](https://github.com/Axway-API-Management-Plus/apigateway-openlogging-elk/workflows/Traffic-Monitor%20API/badge.svg)](https://github.com/Axway-API-Management-Plus/apigateway-openlogging-elk/actions)
43+
In larger companies hundreds of API service providers are using the API Manager to register their own services/APIs and want or should be able to monitor their own API independently. During registration, the corresponding APIs are assigned to API Manager organizations. However, the standard traffic monitor does not know the organization concept and therefore cannot restrict the view for a user based on the organization of an API.
44+
This project solves the problem by storing the API transactions in Elasticsearch with the appropriate organization. This API organization is used when reading the traffic data from Elasticsearch according to the following rules.
45+
46+
| API-Gateway Manager | API-Manager | Restriction | Comment |
47+
| :--- | :--- | :--- | :--- |
48+
| **Administrator** | N/A | Unrestricted access | A GW-Manager user is considered as an Admin, when is owns the permission: `adminusers_modify` |
49+
| **Operator** | API-Admin | All APIs having a Service-Context | By default each API processed by the API-Manager has a Service-Context. Pure Gateway APIs (e.g. /healthcheck) will not be visible.|
50+
| **Operator** | Org-Admin | APIs of its own organization | Such a user will only see the APIs that belong to the same organization as himself. |
51+
| **Operator** | User | APIs of its own organization | The same rules apply as for the Org-Admin |
52+
53+
### Setup Restricted user
54+
55+
To give a user limited access to the API Traffic Monitor, the user must use the same login name in the API Manager and API Gateway Manager. Here, for example, an LDAP connection can be a simplification.
56+
In order to give the user a restricted view in the API Gateway Manager, none of his roles must contain the permission: `adminusers_modify`. A suitable standard role is the `API Gateway Operator role`.
57+
You can, of course, create additional roles in the API Gateway Manager to adjust the user's rights according to your needs.
2858

2959
## Prerequisites
3060
For a simple deployment the prerequisites are very simple as all services can be started as a Docker-Container. In order to start all components in PoC-Like-Mode you just need:
@@ -81,31 +111,54 @@ You may add a custom success message (e.g. `Used ElasticSearch API`) if you like
81111
:point_right:
82112
Please remember to copy the changed Admin-Node-Manager configuration from the Policy-Studio project folder (path on Linux: `/home/<user>/apiprojects/\<project-name\>`) back to the ANM folder (`\<install-dir\>/apigateway/conf/fed`). Afterwards the ANM must be restarted.
83113

114+
## Setup
115+
116+
Before you start the environment based on the `docker-compose.yml` file, please adjust the `.env` file accordingly. The configuration is already used by the different modules as described below.
117+
84118
### Setup filebeat
85119
:exclamation: __This is an important step, as otherwise Filebeat will not see and send any Open-Traffic Event data!__
86-
Before starting the container using docker-compose, make sure to setup the paths in the project `*.env` file. The variables must point to your running API-Gateway instance. These parameters are used to mount the Open-Traffic-Folder into the Filebeat container. For a typical Linux installation it looks like this (APIM beeing a symlink to current software version):
120+
Setup the paths in the project `*.env` file. The variables must point to your running API-Gateway instance. These parameters are used to mount the Open-Traffic-Folder into the Filebeat container. For a typical Linux installation it looks like this (APIM being a symlink to current software version):
87121
```
88122
APIGATEWAY_LOGS_FOLDER=/opt/Axway/APIM/apigateway/logs/opentraffic
89123
APIGATEWAY_TRACES_FOLDER=/opt/Axway/APIM/apigateway/groups/group-2/instance-1/trace
90124
```
91125

126+
### Setup Logstash
127+
128+
Logstash receives the open traffic and open trace events from Filebeat and processes them. Among other things, an HTTP lookup is performed on an API detail lookup REST-API to enrich the API information. Therefore Logstash must know under which URL the API builder can be reached.
129+
This parameter is optional if you use the default docker-compose.yml file.
130+
```
131+
API_BUILDER_URL=http://my-api-builder:8080
132+
```
133+
92134
### Setup API-Builder
93-
As the API-Builder container needs to communicate with Elasticsearch it needs to know where Elasticsearch is running. Again, this environment variable must be configured within `.env`:
135+
As the API-Builder container needs to communicate with Elasticsearch it needs to know where Elasticsearch is running:
136+
Please note, when using the default docker-compose.yaml the default setting is sufficient, as it's using the internal Docker-Network `elastic`.
94137
```
95138
ELASTIC_NODE=http://elasticsearch1:9200
96139
```
97-
Please note, when using the default docker-compose.yaml the default setting is sufficient, as it's using the internal Docker-Network `elastic`.
98-
99-
### Update vm.max_map_count kernel setting to at least 262144
140+
Furthermore, the API Builder communicates with the Admin Node Manager and API Manager. Therefore the following parameters must be configured in the `.env` file.
141+
```
142+
ADMIN_NODE_MANAGER=https://api-env:8090
143+
API_MANAGER_USERNAME=<admin-user>
144+
API_MANAGER_PASSWORD=<admin-password>
145+
```
100146

101-
See https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html#docker-prod-prerequisites
147+
Build status API-Builder Traffic-Monitor API:
148+
[![Traffic-Monitor API](https://github.com/Axway-API-Management-Plus/apigateway-openlogging-elk/workflows/Traffic-Monitor%20API/badge.svg)](https://github.com/Axway-API-Management-Plus/apigateway-openlogging-elk/actions)
102149

103-
### Start local Elasticsearch cluster
104-
Bring the cluster up using docker-compose:
150+
## Start the environment
151+
To bring up the entire environment using docker-compose:
105152
````
106153
docker-compose up -d
107154
````
108-
Of course, the components can also run on different machines or on a Docker-Orchestration framework such as Kubernetes.
155+
You can also run the individual components on different environments. To do this, you can check out the project on the appropriate machines, adjust the docker-compose.yml and .env file and start the desired services.
156+
To start a single service (e.g. the API-Builder project):
157+
```
158+
docker-compose up -d elk-traffic-monitor-api
159+
```
160+
161+
Of course it is also possible to run the containers in a docker orchestration framework, like Kubernetes or OpenShift.
109162

110163
### Stop local Elasticsearch cluster
111164
````
@@ -179,7 +232,10 @@ When Logstash is successfully started you should see the following:
179232
[INFO ][logstash.agent ] Pipelines running {:count=>2, :running_pipelines=>[:main, :".monitoring-logstash"], :non_running_pipelines=>[]}
180233
[INFO ][logstash.agent ] Successfully started Logstash API endpoint {:port=>9600}
181234
```
182-
235+
If you see the following or similar error message during processing of events the API-Builder Lookup-API cannot be reached. In case, please make sure the environment variable: `API_BUILDER_URL`is set correctly.
236+
```
237+
[2020-08-19T10:51:05,671][ERROR][logstash.filters.http ][main][......] error during HTTP request {:url=>"/api/elk/v1/api/lookup/api", :body=>nil, :client_error=>"Target host is not specified"}
238+
```
183239

184240
### Check Elasticsearch processing
185241
It takes a while until Elasticsearch is finally started and reports it with the following line:

docker-compose.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ services:
7676
environment:
7777
- PIPELINE_WORKERS=1
7878
- XPACK_MONITORING_ELASTICSEARCH_HOSTS=["elasticsearch1:9200"]
79+
- API_BUILDER_URL=${API_BUILDER_URL}
7980
ports:
8081
- 5044:5044
8182
volumes:
@@ -84,6 +85,7 @@ services:
8485
command: logstash --path.config /usr/share/logstash/pipeline/pipeline.conf --pipeline.batch.size 400 --log.level info
8586
depends_on:
8687
- elasticsearch1
88+
- elk-traffic-monitor-api
8789
networks:
8890
- elastic
8991

@@ -93,7 +95,10 @@ services:
9395
links:
9496
- elasticsearch1
9597
environment:
96-
- ELASTIC_NODE=http://elasticsearch1:9200
98+
- ELASTIC_NODE=${ELASTIC_NODE}
99+
- ADMIN_NODE_MANAGER=${ADMIN_NODE_MANAGER}
100+
- API_MANAGER_USERNAME=${API_MANAGER_USERNAME}
101+
- API_MANAGER_PASSWORD=${API_MANAGER_PASSWORD}
97102
#- LOG_LEVEL=debug
98103
ports:
99104
- 8889:8080
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = {
2+
pluginConfig: {
3+
'api-builder-plugin-axway-api-management': {
4+
'apigateway': {
5+
url: process.env.ADMIN_NODE_MANAGER,
6+
//username: process.env.ANM_USERNAME, // For future use
7+
//password: process.env.ANM_PASSWORD // For future use
8+
},
9+
'apimanager': {
10+
url: process.env.API_MANAGER, // If not set, the Admin-Node-Manager hostname is used
11+
username: process.env.API_MANAGER_USERNAME, // User with Admin-Privileges required
12+
password: process.env.API_MANAGER_PASSWORD
13+
}
14+
}
15+
}
16+
};

elk-traffic-monitor-api/conf/elasticsearch.default.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module.exports = {
22
pluginConfig: {
33
'@axway-api-builder-ext/api-builder-plugin-fn-elasticsearch': {
44
'elastic': {
5-
node: process.env.ELASTIC_NODE,
5+
node: (process.env.ELASTIC_NODE) ? process.env.ELASTIC_NODE : 'http://elasticsearch1:9200',
66
auth: {
77
/* Use an API-Key
88
apiKey: process.env.ELASTIC_API_KEY
@@ -12,7 +12,7 @@ module.exports = {
1212
*/
1313
},
1414
// The name to identify the client instance in the events.
15-
name: 'api-builder'
15+
name: 'elk-traffic-monitor-api'
1616
// You can use all configuration options documented here:
1717
// https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/7.x/client-configuration.html
1818
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# api-builder-plugin-axway-api-management
2+
3+
## About flow-nodes
4+
5+
Flow-nodes are used within [Axway API Builder's](https://www.axway.com/en/datasheet/axway-api-builder)
6+
flow editor that is a low-code / no-code solution to designing and developing services
7+
that integrate to many different connected components, such as databases and APIs.
8+
9+
## Getting started
10+
11+
1. Follow the [Getting Started Guide](https://docs.axway.com/bundle/API_Builder_4x_allOS_en/page/api_builder_getting_started_guide.html) to create an API Builder service
12+
1. Follow the [API Builder SDK](https://docs.axway.com/bundle/API_Builder_4x_allOS_en/page/api_builder_sdk.html) guide to get started creating flow-node plugins.
13+
14+
## Publish
15+
16+
After developing this plugin you can publish it to [npm](https://www.npmjs.com) to make it public.
17+
18+
## Install
19+
20+
After creating your API Builder service (`api-builder init`), you can install this plugin using npm:
21+
22+
```
23+
npm install api-builder-plugin-axway-api-management
24+
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = {
2+
pluginConfig: {
3+
'api-builder-plugin-axway-api-management': {
4+
'apigateway': {
5+
url: process.env.ADMIN_NODE_MANAGER,
6+
//username: process.env.API_GATEWAY_USERNAME, // For future use
7+
//password: process.env.API_GATEWAY_PASSWORD // For future use
8+
},
9+
'apimanager': {
10+
url: process.env.API_MANAGER, // If not set, the API-Gateway hostname is used
11+
username: process.env.API_MANAGER_USERNAME, // User with Admin-Privileges required
12+
password: process.env.API_MANAGER_PASSWORD
13+
}
14+
}
15+
}
16+
};

0 commit comments

Comments
 (0)