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

Commit

Permalink
fix: change secure cookie to unsecure (#1138)
Browse files Browse the repository at this point in the history
PR Close #1135
  • Loading branch information
tamazlykar authored Jul 4, 2018
1 parent 77f3735 commit 721b6cd
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 18 deletions.
15 changes: 15 additions & 0 deletions .build/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ server {
}

location /client {
header_filter_by_lua '
local cookies = ngx.header["Set-Cookie"]
if cookies then
if type(cookies) == "string" then
cookies = {cookies}
end
for i, cookie in ipairs(cookies) do
local match = ngx.re.match(cookie, "Secure", "i")
if match then
cookies[i] = ngx.re.sub(cookie , "Secure", "", "i")
end
end
ngx.header["Set-Cookie"] = cookies
end
';
proxy_pass CLIENT_ENDPOINT;
}

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RUN yarn install
COPY . /tmp/cloudstackui
RUN yarn run build:aot

FROM nginx:stable-alpine
FROM firesh/nginx-lua

COPY .build/nginx.conf /etc/nginx/conf.d/default.conf
COPY .build/startup.sh /etc/nginx/startup.sh
Expand Down
18 changes: 1 addition & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ Here domain administrators can manage existing accounts, create new accounts and
1. Before you start, please, prepare Node development environment. Install Node.js or update your current node.js to latest stable version (We recomend Node.js v8.11.2).
2. Clone the CSUI project from GitHub.
3. Run "npm install" command. This command installs all dependencies, which are used in the project. Also, you may use "yarn" command.
4. Put your own proxy-conf.js file in the project folder and set the API endpoint in this file.
4. Add your own proxy-conf.js file in the project folder and set the API endpoint in this file. See [proxy-conf-example](https://github.com/bwsw/cloudstack-ui/blob/master/proxy-conf-example.js).

### Main commands

Expand All @@ -208,22 +208,6 @@ Here domain administrators can manage existing accounts, create new accounts and
|npm run build| use this command to build the project, the build artifacts will be stored in the dist/ directory|
|npm start| use this command to compile the application, it will be available at URL - "localhost:8080".|

### Proxy-conf.js file example

<pre>
const PROXY_CONFIG = [
{
context: [
"/client/api",
],
target: "http://api.endpoint/",
secure: false
}
];

module.exports = PROXY_CONFIG;
</pre>

## Deployment

### Main UI container
Expand Down
60 changes: 60 additions & 0 deletions proxy-conf-example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const CLOUDSTACK_ENDPOINT = 'https://example.com/';
/*
* Plugins endpoint
* https://github.com/bwsw/cloudstack-ui#plugins-supported
* */
const PULSE_PLUGIN_ENDPOINT = 'http://example.com:8081';
const WEBSHELL_PLUGIN_ENDPOINT = 'http://example.com:8082';

function onProxyRes(proxyRes, req, res) {
var cookies = proxyRes.headers[ 'set-cookie' ];
var cookieRegex = /Secure/i;
console.log(cookies);

if (cookies) {
var newCookie = cookies.map(function (cookie) {
if (cookieRegex.test(cookie)) {
return cookie.replace(cookieRegex, '');
}
return cookie;
});
delete proxyRes.headers[ 'set-cookie' ];
proxyRes.headers[ 'set-cookie' ] = newCookie;
}
}

const apiProxyConfig = {
context: [
'/client/api',
'/client/console'
],
target: CLOUDSTACK_ENDPOINT,
secure: false
};

// If server works over https need to change Secure Cookie
if (CLOUDSTACK_ENDPOINT.indexOf('https') === 0) {
apiProxyConfig.onProxyRes = onProxyRes;
}

const pulseProxyConfig = {
context: [ '/cs-extensions/pulse/**' ],
target: PULSE_PLUGIN_ENDPOINT,
secure: false,
pathRewrite: { '^/cs-extensions/pulse': '' }
};

const webShellProxyConfig = {
context: [ '/cs-extensions/webshell/**' ],
target: WEBSHELL_PLUGIN_ENDPOINT,
secure: false,
pathRewrite: { '^/cs-extensions/webshell': '' }
}

const PROXY_CONFIG = [
apiProxyConfig,
// pulseProxyConfig,
// webShellProxyConfig
];

module.exports = PROXY_CONFIG;

0 comments on commit 721b6cd

Please sign in to comment.