Skip to content
This repository was archived by the owner on Mar 25, 2023. It is now read-only.

Commit 54e3452

Browse files
andrewbentsfeatures94
authored andcommitted
Smart HTTP VM Access Helper (#1681)
* add vm http address pipe * add smart link component with polling * implement http access helper * http access helper (wip) * add tests for http access helper * add http helper endpoint to config files * markup improvements * encode url param * translation * take helper vars from env * improve wording for the notice * supply http access helper with the built in docker image * add README for the helper * extract helper port to config file * fix cookies rewriting script Co-authored-by: features94 <36263814+features94@users.noreply.github.com>
1 parent c440803 commit 54e3452

38 files changed

Lines changed: 1383 additions & 51 deletions

.build/nginx.conf

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,24 @@ server {
1111
}
1212

1313
location /client {
14-
header_filter_by_lua '
15-
local cookies = ngx.header["Set-Cookie"]
16-
if cookies then
17-
if type(cookies) == "string" then
18-
cookies = {cookies}
19-
end
20-
for i, cookie in ipairs(cookies) do
21-
local match = ngx.re.match(cookie, "Secure", "i")
22-
if match then
23-
cookies[i] = ngx.re.sub(cookie , "Secure", "", "i")
24-
end
25-
local match2 = ngx.re.match(cookie, "Path=/client", "i")
26-
if match2 then
27-
cookies[i] = ngx.re.sub(cookie , "Path=/client", "Path=BASE_HREFclient", "i")
28-
end
29-
end
30-
ngx.header["Set-Cookie"] = cookies
31-
end
32-
';
14+
header_filter_by_lua_block {
15+
local cookies = ngx.header["Set-Cookie"]
16+
if cookies then
17+
if type(cookies) == "string" then
18+
cookies = {cookies}
19+
end
20+
for i, cookie in ipairs(cookies) do
21+
--- Remove "Secure" from a cookie to handle proxying
22+
--- http to https
23+
cookie = ngx.re.sub(cookie , "Secure", "", "i")
24+
--- Rewrite the path of the cookie
25+
cookie = ngx.re.sub(cookie , "Path=([^;?]+)", "Path=BASE_HREFclient", "i")
26+
27+
cookies[i] = cookie
28+
end
29+
ngx.header["Set-Cookie"] = cookies
30+
end
31+
}
3332
proxy_pass CLIENT_ENDPOINT;
3433
}
3534

@@ -41,6 +40,11 @@ server {
4140
proxy_pass WEBSHELL_PLUGIN_ENDPOINT;
4241
}
4342

43+
location /cs-extensions/http-access-helper {
44+
rewrite /cs-extensions/http-access-helper(/?)(.*) /$2 break;
45+
proxy_pass HTTP_ACCESS_HELPER_ENDPOINT;
46+
}
47+
4448
gzip on;
4549
gzip_comp_level 5;
4650
gzip_min_length 256;

.build/startup.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@
22

33
EXTENSION_PULSE_URL=${PULSE_PLUGIN_ENDPOINT-"http://localhost/cs-extensions/pulse"}
44
EXTENSION_WEBSHELL_URL=${WEBSHELL_PLUGIN_ENDPOINT-"http://localhost/cs-extensions/webshell"}
5+
6+
# get the http access helper port from its config.js file
7+
helper_port=$(node --print "require('/cloudstack-http-access-helper/config').port")
8+
# http access helper is run in the same docker image
9+
EXTENSION_HTTP_ACCESS_HELPER_URL="http://localhost:$helper_port/"
10+
511
# replace placeholders
612
sed -i -e 's#CLIENT_ENDPOINT#'"$CLIENT_ENDPOINT"'#g' /etc/nginx/conf.d/default.conf
713
sed -i -e 's#PULSE_PLUGIN_ENDPOINT#'"$EXTENSION_PULSE_URL"'#g' /etc/nginx/conf.d/default.conf
814
sed -i -e 's#WEBSHELL_PLUGIN_ENDPOINT#'"$EXTENSION_WEBSHELL_URL"'#g' /etc/nginx/conf.d/default.conf
15+
sed -i -e 's#HTTP_ACCESS_HELPER_ENDPOINT#'"$EXTENSION_HTTP_ACCESS_HELPER_URL"'#g' /etc/nginx/conf.d/default.conf
916

1017
# add base href
1118
if [ -n "$BASE_HREF" ]; then

.build/supervisor.conf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[supervisord]
2+
nodaemon=true
3+
4+
[program:http-access-helper]
5+
directory=/cloudstack-http-access-helper
6+
command=node index.js
7+
autostart=true
8+
autorestart=true
9+
environment=NODE_ENV="production"
10+
stdout_logfile=/dev/fd/1
11+
stdout_logfile_maxbytes=0
12+
stderr_logfile=/dev/fd/2
13+
stderr_logfile_maxbytes=0
14+
15+
[program:nginx]
16+
command=/bin/sh -e /etc/nginx/startup.sh
17+
autostart=true
18+
autorestart=true
19+
stdout_logfile=/dev/fd/1
20+
stdout_logfile_maxbytes=0
21+
stderr_logfile=/dev/fd/2
22+
stderr_logfile_maxbytes=0
23+
24+
[supervisorctl]

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Thumbs.db
3030

3131
# Node Files #
3232
/node_modules
33+
/projects/**/node_modules
3334
/bower_components
3435
package-lock.json
3536

Dockerfile

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
11
FROM node:8 as builder
22

3+
# Build cloudstack UI app
34
WORKDIR /tmp/cloudstackui
4-
55
COPY package.json yarn.lock /tmp/cloudstackui/
66
RUN yarn install
7-
87
COPY . /tmp/cloudstackui
98
RUN yarn build --prod
109

11-
FROM firesh/nginx-lua
1210

11+
FROM openresty/openresty:alpine-nosse42
12+
13+
# Copy nginx and supervisor configs and scripts
1314
COPY .build/nginx.conf /etc/nginx/conf.d/default.conf
1415
COPY .build/startup.sh /etc/nginx/startup.sh
16+
COPY .build/supervisor.conf /etc/supervisord.conf
1517

18+
# Copy cloustack UI assets
1619
COPY --from=builder /tmp/cloudstackui/dist/cloudstack-ui /static/
1720

21+
RUN apk update \
22+
&& apk add --update curl supervisor nodejs \
23+
&& apk add --update npm \
24+
&& rm -rf /var/cache/apk/*
25+
26+
# Copy and init http access helper server
27+
WORKDIR /cloudstack-http-access-helper
28+
COPY projects/http-access-helper/ /cloudstack-http-access-helper/
29+
RUN npm install --production
30+
1831
RUN chmod 777 /etc/nginx/startup.sh
1932

2033
VOLUME /config/
2134

22-
RUN apk update \
23-
&& apk add --update curl \
24-
&& rm -rf /var/cache/apk/*
25-
26-
CMD ["/bin/sh", "-e", "/etc/nginx/startup.sh"]
35+
# Run supervisor which starts nginx and node (http access helper)
36+
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
"karma-jasmine-html-reporter": "^0.2.2",
100100
"karma-junit-reporter": "^1.2.0",
101101
"karma-mocha-reporter": "^2.2.3",
102+
"ng-mocks": "^8.1.0",
102103
"ngrx-store-freeze": "^0.2.0",
103104
"prettier": "^1.16.4",
104105
"pretty-quick": "^1.8.0",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Http Access Helper
2+
Node.js microservice for checking HTTP resource availability
3+
4+
## Getting Started
5+
### Installing
6+
```bash
7+
yarn install
8+
```
9+
### Start
10+
```bash
11+
yarn start
12+
```
13+
14+
The following environment variables are supported:
15+
1. `HTTP_ACCESS_HELPER_PORT` for customizing the server's port
16+
2. `HTTP_ACCESS_HELPER_TIMEOUT` for customizing request timeout.
17+
18+
### Test
19+
```bash
20+
yarn test
21+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const requestTimeout = +process.env.HTTP_ACCESS_HELPER_TIMEOUT || 60000; // 1 min
2+
const port = +process.env.HTTP_ACCESS_HELPER_PORT || 8989;
3+
4+
module.exports = {
5+
requestTimeout,
6+
port,
7+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const { createApp } = require('./src/app');
2+
const { requestTimeout, port } = require('./config');
3+
4+
const app = createApp(requestTimeout);
5+
6+
app.listen(port, () => console.log(`Http Access Helper app listening on port ${port}!\n`));
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "http-access-helper",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"license": "Apache-2.0",
6+
"private": true,
7+
"scripts": {
8+
"start": "node index.js",
9+
"test": "jasmine"
10+
},
11+
"dependencies": {
12+
"axios": "^0.19.0",
13+
"express": "^4.17.1"
14+
},
15+
"devDependencies": {
16+
"jasmine": "^3.5.0",
17+
"moxios": "^0.4.0",
18+
"supertest": "^4.0.2"
19+
}
20+
}

0 commit comments

Comments
 (0)