Skip to content

Commit 3713135

Browse files
authored
Support for Secure Headers and Github Actions (#72)
* Support for Secure Headers and Github Actions * Reformat main.py * Add working dir to python checks * Add line length to black
1 parent 8237263 commit 3713135

File tree

6 files changed

+74
-24
lines changed

6 files changed

+74
-24
lines changed

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"
7+
- package-ecosystem: "pip"
8+
directory: "/api"
9+
schedule:
10+
interval: "daily"

.github/workflows/python-lint.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Python Lint
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
paths-ignore:
8+
- 'docs/**'
9+
- 'extras/**'
10+
- '**.md'
11+
- '**.adoc'
12+
13+
jobs:
14+
lint-python-code:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
- uses: actions/setup-python@v4
19+
with:
20+
python-version: "3.x"
21+
- name: Run ruff check
22+
uses: chartboost/ruff-action@v1
23+
with:
24+
src: "./gdash"
25+
args: "--verbose"
26+
- name: Run black check
27+
uses: psf/black@stable
28+
with:
29+
options: "--check --diff --verbose -l 120"
30+
src: "./gdash"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ __pycache__
88
node_modules
99
.DS_Store
1010
gdash/ui
11+
**/.ruff_cache

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Other available options are
4747
```
4848
$ gdash --help
4949
usage: gdash [-h] [--version] [--port PORT] [--gluster-binary GLUSTER_BINARY]
50-
[--auth-file AUTH_FILE] [--ssl-cert CERT_FILE] [--ssl-key KEY_FILE] [--ssl-ca CA_CERT_FILE]
50+
[--auth-file AUTH_FILE] [--ssl-cert CERT_FILE] [--ssl-key KEY_FILE] [--ssl-ca CA_CERT_FILE] [--ssl-ciphers LIST_OF_CIPHERS]
5151
host
5252
5353
gdash - GlusterFS Dashboard
@@ -68,6 +68,7 @@ optional arguments:
6868
--ssl-cert CERT_FILE Path to SSL Certificate file
6969
--ssl-key KEY_FILE Path to SSL Key file
7070
--ssl-ca CA_FILE Path to SSL CA Certificate file
71+
--ssl-ciphers List of SSL Ciphers to allow
7172
```
7273

7374
## Blog

gdash/__main__.py

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,21 @@
2323
"/": {
2424
"tools.staticdir.on": True,
2525
"tools.sessions.on": True,
26-
"tools.sessions.secure" = True,
27-
"tools.sessions.httponly" = True,
28-
"tools.secureheaders.on" = True,
29-
"tools.staticdir.dir": os.path.join(
30-
os.path.dirname(os.path.abspath(__file__)), "ui"
31-
),
26+
"tools.sessions.secure": True,
27+
"tools.sessions.httponly": True,
28+
"tools.secureheaders.on": True,
29+
"tools.staticdir.dir": os.path.join(os.path.dirname(os.path.abspath(__file__)), "ui"),
3230
},
3331
}
3432

3533

34+
def secureheaders():
35+
headers = cherrypy.response.headers
36+
headers["X-Frame-Options"] = "DENY"
37+
headers["X-XSS-Protection"] = "1; mode=block"
38+
headers["Content-Security-Policy"] = "default-src='self'"
39+
40+
3641
def is_valid_admin_login(username, password):
3742
if USERS is None:
3843
return True
@@ -162,24 +167,12 @@ def get_args():
162167
parser.add_argument("--gluster-binary", default="gluster")
163168
parser.add_argument(
164169
"--auth-file",
165-
help=(
166-
"Users Credentials file. One user entry per row "
167-
"in the format <username>=<password_hash>"
168-
),
169-
)
170-
parser.add_argument(
171-
"--ssl-cert", default=None, help=("Path to SSL Certificate used by Gdash")
170+
help=("Users Credentials file. One user entry per row " "in the format <username>=<password_hash>"),
172171
)
173-
parser.add_argument(
174-
"--ssl-key", default=None, help=("Path to SSL Key used by Gdash")
175-
)
176-
parser.add_argument(
177-
"--ssl-ca", default=None, help=("Path to SSL CA Certificate used by Gdash")
178-
)
179-
parser.add_argument(
180-
"--ssl-ciphers", default=None, help=("List of SSL Ciphers to allow")
181-
)
182-
172+
parser.add_argument("--ssl-cert", default=None, help=("Path to SSL Certificate used by Gdash"))
173+
parser.add_argument("--ssl-key", default=None, help=("Path to SSL Key used by Gdash"))
174+
parser.add_argument("--ssl-ca", default=None, help=("Path to SSL CA Certificate used by Gdash"))
175+
parser.add_argument("--ssl-ciphers", default=None, help=("List of SSL Ciphers to allow"))
183176
return parser.parse_args()
184177

185178

@@ -217,6 +210,7 @@ def main():
217210
cherrypy_cfg["server.ssl_module"] = "builtin"
218211

219212
cherrypy.config.update(cherrypy_cfg)
213+
cherrypy.tools.secureheaders = cherrypy.Tool("before_finalize", secureheaders, priority=60)
220214
webapp = GdashWeb()
221215
webapp.api = GdashApis()
222216
cherrypy.quickstart(webapp, "/", conf)

ruff.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Enable flake8-bugbear (`B`) rules.
2+
select = ["E", "F", "B"]
3+
4+
# Never enforce `E501` (line length violations).
5+
ignore = ["E501"]
6+
7+
# Avoid trying to fix flake8-bugbear (`B`) violations.
8+
unfixable = ["B"]
9+
10+
# Ignore `E402` (import violations) in all `__init__.py` files, and in `path/to/file.py`.
11+
[per-file-ignores]
12+
"__init__.py" = ["E402"]
13+
"path/to/file.py" = ["E402"]
14+

0 commit comments

Comments
 (0)