Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
s4ke committed Nov 12, 2023
1 parent d239529 commit 7cccfaf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion deploy/stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3.8'

services:
app:
image: ghcr.io/s4ke/docker-swarm-multitenant-proxy:0.2.3
image: ghcr.io/s4ke/docker-swarm-multitenant-proxy:0.2.4
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
Expand Down
15 changes: 11 additions & 4 deletions docker-swarm-multitenant-proxy/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ morgan.token('client-cn', (req: any) => {
return 'Unauthorized';
});

const clientCertAuthMiddleware = (req: any, res: any, next: any) => {
const healthMiddleware = (req: any, res: any, next: any) => {
if(req.path == '/_healthz') {
const ip = req.ip || req.connection.remoteAddress || req.socket.remoteAddress || req.connection.socket.remoteAddress;
if (ip === "127.0.0.1" || ip === "::1") {
console.log(ip);
if (ip === "127.0.0.1" || ip === "::1" || ip === "::ffff:127.0.0.1") {
// only respond to healthchecks from inside the container
(async () => {
try {
Expand All @@ -63,6 +64,10 @@ const clientCertAuthMiddleware = (req: any, res: any, next: any) => {
return;
}
}
return next();
}

const clientCertAuthMiddleware = (req: any, res: any, next: any) => {
if (TLS_DISABLED) {
return next();
}
Expand All @@ -74,13 +79,15 @@ const clientCertAuthMiddleware = (req: any, res: any, next: any) => {
res.status(401).send('Access denied: Invalid client certificate');
}
};
app.use(clientCertAuthMiddleware);
app.use(bodyParser.json());
if(!TLS_DISABLED) {
app.use(morgan(':remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent" - Client-CN: :client-cn'));
} else {
app.use(morgan(':remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent" - Client-CN: TLS Disabled'))
}
app.use(healthMiddleware);
app.use(clientCertAuthMiddleware);
app.use(bodyParser.json());


// app.use(audit());

Expand Down

0 comments on commit 7cccfaf

Please sign in to comment.