Skip to content

Commit b0c6d04

Browse files
authored
Merge pull request #11 from lpiwowar/lpiwowar/ruff-security
Enable ruff and pre-commit
2 parents 45549e3 + 6ded951 commit b0c6d04

16 files changed

Lines changed: 605 additions & 158 deletions

.github/workflows/pre-commit.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: "Pre-commit checks"
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
pull_request:
9+
branches:
10+
- main
11+
types:
12+
- opened
13+
- synchronize
14+
- reopened
15+
16+
jobs:
17+
pre-commit:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
23+
24+
- name: Set up Python
25+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
26+
with:
27+
python-version: "3.12"
28+
29+
- name: Run pre-commit
30+
uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.15.14
4+
hooks:
5+
- id: ruff-check
6+
- id: ruff-format

Containerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ EXPOSE 8080
4242

4343
USER 1001
4444

45-
ENTRYPOINT ["rhos-ls-mcps"]
45+
ENTRYPOINT ["rhos-ls-mcps", "--ip", "0.0.0.0"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ The configuration file has 4 sections:
8282
- MCP Security
8383

8484
## General
85-
- `ip`: IP address the server will bind to. Default `0.0.0.0`.
85+
- `ip`: IP address the server will bind to. Default `127.0.0.1`.
8686
- `port`: TCP port the server will bind to. Default `8080`.
8787
- `debug`: Default `false`.
8888
- `workers`: Number of different uvicorn workers. Default `1`.

config.yaml.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ip: 0.0.0.0
1+
ip: 127.0.0.1
22
port: 8901
33
debug: true
44
workers: 1

pyproject.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,19 @@ requires-python = ">=3.12,<3.13"
1818
readme = "README.md"
1919
license = {text = "Apache-2.0"}
2020

21+
[dependency-groups]
22+
dev = [
23+
"cliff>=4.14.0",
24+
"ruff>=0.15.14",
25+
"pre-commit>=4.6.0"
26+
]
27+
2128
[build-system]
2229
requires = ["uv_build>=0.11.16,<0.12"]
2330
build-backend = "uv_build"
2431

2532
[project.scripts]
2633
rhos-ls-mcps = "rhos_ls_mcps.main:main"
34+
35+
[tool.ruff.lint]
36+
extend-select = ["S"]

scripts/allow-deny-list.py

Lines changed: 151 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
The accept commands list is generated using the rhros_ls_mcps package itself,
1616
where the reject and ignore list of commands come from this script.
1717
"""
18+
1819
from importlib.metadata import entry_points
1920

2021
import sys
@@ -28,43 +29,159 @@
2829
# - export:
2930
# - cp:
3031
REJECT_COMMANDS: set[str] = {
31-
"create", "delete", "update", "set", "unset", "remove", "add", "abort",
32-
"complete", "revoke", "issue", "cleanup", "migrate", "resize", "cleanup",
33-
"shelve", "unshelve", "reboot", "restart", "rebuild", "stop", "restore",
34-
"import", "failover", "associate", "revert", "run", "save", "shrink",
35-
"reset", "del", "onboard", "commit", "unrescue", "adopt", "on", "off",
36-
"forcedown", "detach", "edit", "lock", "unlock", "purge", "rerun",
37-
"attach", "resume", "start", "pause", "create-from-file", "request-refresh",
38-
"rename", "post", "clear", "move", "manage", "enable", "register", "rescue",
39-
"deploy", "unpause", "disable", "benchmark metric create", "abandon",
40-
"renew", "ssh", "export", "replace", "alarm create", "alarm update",
41-
"alarm quota set", "alarm state set", "recover", "cancel", "unhold", "accept",
42-
"pull", "exec", "upgrade", "suspend", "disassociate", "undeploy", "grow",
43-
"scale", "execute", "grant", "confirm", "kill", "mark", "eject", "op",
44-
"verification", "reprocess", "expand", "evacuate", "signed", "axfr",
45-
"unregister", "clean", "download", "authorize", "cp", "submit", "stage",
46-
"promote", "configure", "inject", "signal", "release",
47-
32+
"create",
33+
"delete",
34+
"update",
35+
"set",
36+
"unset",
37+
"remove",
38+
"add",
39+
"abort",
40+
"complete",
41+
"revoke",
42+
"issue",
43+
"cleanup",
44+
"migrate",
45+
"resize",
46+
"cleanup",
47+
"shelve",
48+
"unshelve",
49+
"reboot",
50+
"restart",
51+
"rebuild",
52+
"stop",
53+
"restore",
54+
"import",
55+
"failover",
56+
"associate",
57+
"revert",
58+
"run",
59+
"save",
60+
"shrink",
61+
"reset",
62+
"del",
63+
"onboard",
64+
"commit",
65+
"unrescue",
66+
"adopt",
67+
"on",
68+
"off",
69+
"forcedown",
70+
"detach",
71+
"edit",
72+
"lock",
73+
"unlock",
74+
"purge",
75+
"rerun",
76+
"attach",
77+
"resume",
78+
"start",
79+
"pause",
80+
"create-from-file",
81+
"request-refresh",
82+
"rename",
83+
"post",
84+
"clear",
85+
"move",
86+
"manage",
87+
"enable",
88+
"register",
89+
"rescue",
90+
"deploy",
91+
"unpause",
92+
"disable",
93+
"benchmark metric create",
94+
"abandon",
95+
"renew",
96+
"ssh",
97+
"export",
98+
"replace",
99+
"alarm create",
100+
"alarm update",
101+
"alarm quota set",
102+
"alarm state set",
103+
"recover",
104+
"cancel",
105+
"unhold",
106+
"accept",
107+
"pull",
108+
"exec",
109+
"upgrade",
110+
"suspend",
111+
"disassociate",
112+
"undeploy",
113+
"grow",
114+
"scale",
115+
"execute",
116+
"grant",
117+
"confirm",
118+
"kill",
119+
"mark",
120+
"eject",
121+
"op",
122+
"verification",
123+
"reprocess",
124+
"expand",
125+
"evacuate",
126+
"signed",
127+
"axfr",
128+
"unregister",
129+
"clean",
130+
"download",
131+
"authorize",
132+
"cp",
133+
"submit",
134+
"stage",
135+
"promote",
136+
"configure",
137+
"inject",
138+
"signal",
139+
"release",
48140
# These are full names
49-
"secret_store", "baremetal_node_inspect", "baremetal_node_service",
50-
"baremetal_node_provide", "aggregate_cache_image", "alarm delete",
51-
"cached_image_queue", "baremetal_driver_passthru_call",
52-
"baremetal_node_passthru_call", "static-action_call",
53-
"metric_benchmark measures add", "metric_measures_batch-metrics",
141+
"secret_store",
142+
"baremetal_node_inspect",
143+
"baremetal_node_service",
144+
"baremetal_node_provide",
145+
"aggregate_cache_image",
146+
"alarm delete",
147+
"cached_image_queue",
148+
"baremetal_driver_passthru_call",
149+
"baremetal_node_passthru_call",
150+
"static-action_call",
151+
"metric_benchmark measures add",
152+
"metric_measures_batch-metrics",
54153
"metric_measures_batch-resources-metrics",
55-
56154
# This sounds intrusive: https://docs.openstack.org/senlin/rocky/user/nodes.html#checking-a-node
57155
"cluster_node_check",
58156
}
59157

60158
# These must be full names with the "_" suffix, and they are not really commands but artifacts
61159
# from the arg parsing mechanism
62160
IGNORE_COMMANDS: set[str] = {
63-
"database_", "infra_optim_", "load_balancer_", "identity_", "neutronclient_",
64-
"rca_", "object_store_", "compute_", "container_", "dns_", "key_manager_",
65-
"application_catalog_", "congressclient_", "messaging_", "baremetal_", "image_",
66-
"volume_", "network_", "clustering_", "metric_", "baremetal-introspection_",
67-
"cluster_profile_type_ops_", "workflow_engine_", "data_processing_",
161+
"database_",
162+
"infra_optim_",
163+
"load_balancer_",
164+
"identity_",
165+
"neutronclient_",
166+
"rca_",
167+
"object_store_",
168+
"compute_",
169+
"container_",
170+
"dns_",
171+
"key_manager_",
172+
"application_catalog_",
173+
"congressclient_",
174+
"messaging_",
175+
"baremetal_",
176+
"image_",
177+
"volume_",
178+
"network_",
179+
"clustering_",
180+
"metric_",
181+
"baremetal-introspection_",
182+
"cluster_profile_type_ops_",
183+
"workflow_engine_",
184+
"data_processing_",
68185
"orchestration_",
69186
}
70187

@@ -92,13 +209,17 @@ def osp_list_commands(verbs: set[str]) -> tuple[list[str], list[str]]:
92209

93210
def get_openstackclient_version() -> str | None:
94211
import openstackclient
212+
95213
return openstackclient.__version__
96214

215+
97216
def main() -> None:
98217
accept_commands, non_accept_commands = osc.osp_list_commands(osc.ACCEPT_COMMANDS)
99218
reject_commands, non_reject_commands = osc.osp_list_commands(REJECT_COMMANDS)
100219

101-
undefined_commands: list[str] = list(set(non_accept_commands).intersection(non_reject_commands) - IGNORE_COMMANDS)
220+
undefined_commands: list[str] = list(
221+
set(non_accept_commands).intersection(non_reject_commands) - IGNORE_COMMANDS
222+
)
102223

103224
result = {
104225
"undefined_commands": undefined_commands,
@@ -109,5 +230,6 @@ def main() -> None:
109230
}
110231
yaml.dump(result, sys.stdout)
111232

233+
112234
if __name__ == "__main__":
113235
main()

scripts/diff-allow-deny.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
UNDEFINED_COMMANDS_MSG = "check ACCEPT_COMMANDS, REJECT_COMMANDS, and IGNORE_COMMANDS"
1919

2020

21-
def show_diff(list_name: str, data_1: list[str], data_2: list[str], change_msg: str) -> None:
21+
def show_diff(
22+
list_name: str, data_1: list[str], data_2: list[str], change_msg: str
23+
) -> None:
2224
in_list_1_not_in_list_2 = set(data_1[list_name]) - set(data_2[list_name])
2325
in_list_2_not_in_list_1 = set(data_2[list_name]) - set(data_1[list_name])
2426

@@ -37,7 +39,9 @@ def show_diff(list_name: str, data_1: list[str], data_2: list[str], change_msg:
3739

3840
def main() -> None:
3941
if len(sys.argv) != 3:
40-
print("Usage: diff-allow-deny.py <allow-deny-list-1.yaml> <allow-deny-list-2.yaml>")
42+
print(
43+
"Usage: diff-allow-deny.py <allow-deny-list-1.yaml> <allow-deny-list-2.yaml>"
44+
)
4145
sys.exit(1)
4246

4347
file_name_1 = sys.argv[1]
@@ -48,17 +52,23 @@ def main() -> None:
4852
with open(file_name_2, "r") as f:
4953
list_2 = yaml.safe_load(f)
5054

51-
print("Differences between python-openstackclient version "
52-
f"{list_1['python_osc_version']} and version {list_2['python_osc_version']}")
55+
print(
56+
"Differences between python-openstackclient version "
57+
f"{list_1['python_osc_version']} and version {list_2['python_osc_version']}"
58+
)
5359
changes = show_diff("allow_commands", list_1, list_2, RIGHT_GROUP_MSG)
5460
changes |= show_diff("deny_commands", list_1, list_2, RIGHT_GROUP_MSG)
5561

56-
undefined_changes = show_diff("undefined_commands", list_1, list_2, UNDEFINED_COMMANDS_MSG)
62+
undefined_changes = show_diff(
63+
"undefined_commands", list_1, list_2, UNDEFINED_COMMANDS_MSG
64+
)
5765
changes |= undefined_changes
5866
if not undefined_changes and list_2["undefined_commands"]:
59-
print("Undefined commands have not changed, but there are undefined commands, "
60-
"so ACCEPT_COMMANDS, REJECT_COMMANDS, and IGNORE_COMMANDS need to be "
61-
f"revised to include them: {sorted(list_2['undefined_commands'])}")
67+
print(
68+
"Undefined commands have not changed, but there are undefined commands, "
69+
"so ACCEPT_COMMANDS, REJECT_COMMANDS, and IGNORE_COMMANDS need to be "
70+
f"revised to include them: {sorted(list_2['undefined_commands'])}"
71+
)
6272
sys.exit(1)
6373

6474
if not changes:

0 commit comments

Comments
 (0)