Skip to content

Commit 58e4f7e

Browse files
committed
[#4] no login, token transferred to the broker
The jolokia api server is now in a mode where it doesn't perform any login verification and just forward the Bearer token to the broker. The user needs to provide a targetEndpoint and a Bearer token on every request except api-info. Based on @gaohoward's work there: artemiscloud#23
1 parent d5186b1 commit 58e4f7e

21 files changed

+684
-721
lines changed

.dockerignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.git/
2+
.gitignore
3+
node_modules/
4+
dist/
5+
*.md
6+
logs/
7+
tmp
8+
.eslintrc.yml
9+
.prettierrc.yml
10+
.test*
11+
.jest.config.js
12+
.users.json

.env

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ PLUGIN_NAME='ActiveMQ Artemis Jolokia api-server'
66
SERVER_CERT=/var/serving-cert/tls.crt
77
SERVER_KEY=/var/serving-cert/tls.key
88

9-
# replace the token in production deployment
10-
SECRET_ACCESS_TOKEN=1e13d44f998dee277deae621a9012cf300b94c91
11-
12-
# to trust jolokia certs
13-
NODE_TLS_REJECT_UNAUTHORIZED='0'
14-
159
# logging
1610
LOG_LEVEL='info'
1711
ENABLE_REQUEST_LOG='false'
12+
13+
# security
14+
15+
# replace the token in production deployment
16+
SECRET_ACCESS_TOKEN=1e13d44f998dee277deae621a9012cf300b94c91
17+
18+
API_SERVER_SECURITY_ENABLED=true
19+
API_SERVER_SECURITY_AUTH_TYPE=jwt
20+
USERS_FILE_URL=.users.json
21+
ENDPOINTS_FILE_URL=.endpoints.json

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,8 @@ dist
121121
.yarn/build-state.yml
122122
.yarn/install-state.gz
123123
.pnp.*
124+
125+
# vs code config
126+
.vscode
127+
128+

README.md

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ yarn run build-api-doc
3737
### deploy the service
3838

3939
```sh
40-
./deploy.sh [-i <image>]
40+
./deploy.sh [-i <image> -n]
4141
```
4242

4343
The optional `-i <image>` (or `--image <image>`) argument allows you to pass in
@@ -49,6 +49,17 @@ deployed. for example:
4949
./deploy.sh -i quay.io/<repo-username>/activemq-artemis-jolokia-api-server:1.0.1
5050
```
5151

52+
The optional -ns (or --nosec) argument can be used to disable security.
53+
54+
---
55+
56+
**Note:**
57+
58+
you should enable security in your application. Disable security can only
59+
be used for test purposes.
60+
61+
---
62+
5263
The `deploy.sh` script uses `oc kustomize` (built-in
5364
[kustomize](https://github.com/kubernetes-sigs/kustomize)) command to configure
5465
and deploy the plugin using resources and patches defined under ./deploy
@@ -67,6 +78,53 @@ jwt tokens. It has a default value in .env for dev purposes.
6778

6879
In production you should override it with your own secret.
6980

70-
The jwt-key-gen.sh is a tool to generate a random key and used in Dockerfile.
81+
The jwt-key-gen.sh is a tool to generate a random key and used in Dockerfile.
7182
It makes sure when you build the api server image a new random key is used.
7283

84+
## Security Model of the API Server
85+
86+
The API Server provides a security model that provides authentication and authorization of incoming clients.
87+
The security can be enabled/disabled (i.e. via `API_SERVER_SECURITY_ENABLED` env var)
88+
89+
### Authentication
90+
91+
Currently the api server support `jwt` token authentication.
92+
93+
#### The login api
94+
95+
The login api is defined in openapi.yml
96+
97+
```yaml
98+
/server/login
99+
```
100+
101+
A client logs in to an api server by sending a POST request to the login path. The request body contains login information (i.e. username and password for jwt authentication type)
102+
103+
Please refer to [api.md](api.md) for details of the log api.
104+
105+
Currently the security manager uses local file to store user's info. The default users file name is `.users.json`
106+
The users file name can be configured using `USERS_FILE_URL` env var. See `.test.users.json` for sample values.
107+
108+
### Authorization
109+
110+
Currently the api server doesn't perform authorization on logged in users.
111+
112+
### Endpoints Management
113+
114+
The server keeps a list of jolokia endpoints for clients to access. The endpoints are loaded from a local file named
115+
`.endpoints.json`. Each top level entry represents a jolokia endpoint. An entry has a unique name and details to access the jolokia api. See `.test.endpoints.json` for sample values.
116+
117+
### Accessing a jolokia endpoint
118+
119+
When an authenticated client sends a request to the api-server, it should present its token in the request header
120+
121+
'Authorization: Bearer `token`'
122+
123+
It also need to give the `targetEndpoint` in the query part of the request if the request is to access an jolokia endpoint.
124+
125+
For example `/execBrokerOperation?targetEndpoint=broker1`.
126+
127+
### Direct Proxy
128+
129+
Direct Proxy means a client can pass a broker's endpoint info to the api-server in order to access it via the api-server.
130+
For example the [self-provisioning plugin](https://github.com/artemiscloud/activemq-artemis-self-provisioning-plugin) uses this api to access the jolokia of a broker's jolokia endpoint.

0 commit comments

Comments
 (0)