Skip to content

Commit 98f31fa

Browse files
committed
Auth: Support reading username/password from files
1 parent ff04936 commit 98f31fa

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ List of environment variables for more customization:
8181
| ENABLE_AUTHENTICATION | true | `false` by default. |
8282
| AUTHENTICATION_REALM | MyRealm | Use this env if ENABLE_AUTHENTICATION is `true`. |
8383
| USERNAME | admin | Use this env if ENABLE_AUTHENTICATION is `true`. |
84+
| USERNAME_FILE | /run/secrets/username | Alternative to `USERNAME`. |
8485
| PASSWORD | supersecret | Use this env if ENABLE_AUTHENTICATION is `true`. |
86+
| PASSWORD_FILE | /run/secrets/password | Alternative to `PASSWORD`. |
8587
| ENABLE_HTTPS | true | `false` by default. |
8688
| LEGO_PATH | /lego-files | Use this env if ENABLE_HTTPS is `true`. Lego is used to create the SSL certificates. Create a named volume for this path to avoid the creation of a new certificate on each run. |
8789
| HTTPS_HOSTNAME | swarm-dashboard.example.com | Use this env if ENABLE_HTTPS is `true`. |

compose.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ services:
1919
# ENABLE_AUTHENTICATION: "true"
2020
# AUTHENTICATION_REALM: "KuW2i9GdLIkql"
2121
# USERNAME: "admin"
22+
# USERNAME_FILE: "/run/secrets/username"
2223
# PASSWORD: "supersecret"
24+
# PASSWORD_FILE: "/run/secrets/password"
2325
# ENABLE_HTTPS: "false"
2426
# ENABLE_HTTPS: "true"
2527
# HTTPS_HOSTNAME: "example.com"
@@ -40,4 +42,4 @@ services:
4042
- node.role == manager
4143

4244
volumes:
43-
lego-files:
45+
lego-files:

server/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ import moment from 'moment';
1515
const port = process.env.PORT || 8080;
1616
const realm = process.env.AUTHENTICATION_REALM || "KuW2i9GdLIkql";
1717
const enableAuthentication = process.env.ENABLE_AUTHENTICATION === "true"
18-
const username = process.env.USERNAME || "admin";
19-
const password = process.env.PASSWORD || "supersecret";
18+
const username = process.env.USERNAME_FILE
19+
? readFileSync(process.env.USERNAME_FILE, 'utf-8')
20+
: process.env.USERNAME || "admin";
21+
const password = process.env.PASSWORD_FILE
22+
? readFileSync(process.env.PASSWORD_FILE, 'utf-8')
23+
: process.env.PASSWORD || "supersecret";
2024
const enableHTTPS = process.env.ENABLE_HTTPS === "true";
2125
const legoPath = process.env.LEGO_PATH || "/lego-files";
2226
const httpsHostname = process.env.HTTPS_HOSTNAME;

0 commit comments

Comments
 (0)