-
Notifications
You must be signed in to change notification settings - Fork 3
/
recommended_permissions.py
293 lines (285 loc) · 10 KB
/
recommended_permissions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#! /usr/bin/env python3
# vim: ts=4 filetype=python expandtab shiftwidth=4 softtabstop=4 syntax=python
#
# Copyright the Cluster Management Toolkit for Kubernetes contributors.
# SPDX-License-Identifier: MIT
"""
List of recommended permissions for files and directories;
used when auditing the local system.
"""
import os
from typing import Dict, List
from cmttypes import FilePath
from cmtpaths import BINDIR, CMTDIR, CMT_LOGS_DIR
from cmtpaths import ANSIBLE_DIR, ANSIBLE_INVENTORY, ANSIBLE_LOG_DIR, ANSIBLE_PLAYBOOK_DIR
from cmtpaths import DEPLOYMENT_DIR, CMT_CONFIG_FILE_DIR, CMT_HOOKS_DIR
from cmtpaths import KUBE_CONFIG_DIR, PARSER_DIR, THEME_DIR, VIEW_DIR
from cmtpaths import CMT_CONFIG_FILE, KUBE_CONFIG_FILE, KUBE_CREDENTIALS_FILE
# TODO:
# Check file permissions:
# .ssh should be 700
# .ssh/authorized_keys should be 644, 640, or 600
# .ssh/known_hosts should be 600
# .ssh/config should be 644, 640, or 600
# .ssh/id_*.pub should be 644, 640, or 600
# .ssh/id_* should be 600
recommended_directory_permissions: List[Dict] = [
{
"path": BINDIR,
"alertmask": 0o022,
"usergroup_alertmask": 0o002,
"severity": "critical",
"justification": [
("If other users can create or overwrite files in ", "default"),
(f"{BINDIR}", "path"),
(" they can obtain elevated privileges", "default")]
},
{
"path": CMTDIR,
"alertmask": 0o022,
"usergroup_alertmask": 0o002,
"severity": "critical",
"justification": [
(" If other users can create or replace files in ", "default"),
(f"{CMTDIR}", "path"),
(" they may be able to obtain elevated privileges", "default")]
},
{
"path": CMT_LOGS_DIR,
"alertmask": 0o077,
"usergroup_alertmask": 0o027,
"severity": "error",
"justification": [
(" If other users can read, create or replace files in ", "default"),
(f"{CMT_LOGS_DIR}\n", "path"),
(" they can cause ", "default"),
("cmu", "programname"),
(" to malfunction and possibly hide signs\n", "default"),
(" of a compromised cluster and may be able to "
"obtain sensitive information\n", "default"),
(" from audit messages.", "default")]
},
{
"path": CMT_CONFIG_FILE_DIR,
"alertmask": 0o022,
"usergroup_alertmask": 0o002,
"severity": "critical",
"justification": [
("If other users can create or replace files in ", "default"),
(f"{CMT_CONFIG_FILE_DIR}", "path"),
(" they may be able to obtain elevated privileges", "default")]
},
{
"path": ANSIBLE_DIR,
"alertmask": 0o022,
"usergroup_alertmask": 0o002,
"severity": "critical",
"justification": [
("If other users can create or replace files in ", "default"),
(f"{ANSIBLE_DIR}", "path"),
(" they can obtain elevated privileges", "default")]
},
{
"path": CMT_HOOKS_DIR,
"alertmask": 0o022,
"usergroup_alertmask": 0o002,
"severity": "critical",
"justification": [
("If other users can create or replace files in ", "default"),
(f"{CMT_HOOKS_DIR}", "path"),
(" they can obtain elevated privileges", "default")]
},
{
"path": FilePath(os.path.join(CMT_HOOKS_DIR, "pre-upgrade.d")),
"alertmask": 0o022,
"usergroup_alertmask": 0o002,
"severity": "critical",
"justification": [
("If other users can create or replace files in ", "default"),
(f"{os.path.join(CMT_HOOKS_DIR, 'pre-upgrade.d')}", "path"),
(" they can obtain elevated privileges", "default")]
},
{
"path": FilePath(os.path.join(CMT_HOOKS_DIR, "post-upgrade.d")),
"alertmask": 0o022,
"usergroup_alertmask": 0o002,
"severity": "critical",
"justification": [
("If other users can create or replace files in ", "default"),
(f"{os.path.join(CMT_HOOKS_DIR, 'post-upgrade.d')}", "path"),
(" they can obtain elevated privileges", "default")]
},
{
"path": DEPLOYMENT_DIR,
"alertmask": 0o022,
"usergroup_alertmask": 0o002,
"severity": "critical",
"justification": [
("If other users can create or replace files in ", "default"),
(f"{DEPLOYMENT_DIR}", "path"),
(" they can obtain elevated privileges", "default")]
},
{
"path": ANSIBLE_LOG_DIR,
"alertmask": 0o022,
"usergroup_alertmask": 0o002,
"severity": "warning",
"justification": [
("If others users can create or replace files in ", "default"),
(f"{ANSIBLE_LOG_DIR}", "path"),
(" they can spoof results from playbook runs", "default")]
},
{
"path": KUBE_CONFIG_DIR,
"alertmask": 0o077,
"usergroup_alertmask": 0o027,
"severity": "critical",
"justification": [
("If others users can read, create or replace files in ", "default"),
(f"{KUBE_CONFIG_DIR}", "path"),
(" they can obtain cluster access", "default")]
},
{
"path": THEME_DIR,
"alertmask": 0o022,
"usergroup_alertmask": 0o002,
"severity": "error",
"justification": [
("If others users can create or replace files in ", "default"),
(f"{THEME_DIR}", "path"),
(" they can cause ", "default"),
("cmu", "programname"),
(" to malfunction", "default")]
},
{
"path": PARSER_DIR,
"alertmask": 0o022,
"usergroup_alertmask": 0o002,
"severity": "error",
"justification": [
("If others users can create or replace files in ", "default"),
(f"{PARSER_DIR}", "path"),
(" they can cause ", "default"),
("cmu", "programname"),
(" to malfunction and possibly hide signs "
"of a compromised cluster", "default")]
},
{
"path": VIEW_DIR,
"alertmask": 0o022,
"usergroup_alertmask": 0o002,
"severity": "error",
"justification": [
("If others users can create or replace files in ", "default"),
(f"{VIEW_DIR}", "path"),
(" they can cause ", "default"),
("cmu", "programname"),
(" to malfunction and possibly hide signs of a "
"compromised cluster", "default")]
},
]
recommended_file_permissions: List[Dict] = [
{
"path": FilePath(os.path.join(BINDIR, "cmtadm")),
"alertmask": 0o022,
"usergroup_alertmask": 0o002,
"executable": True,
"severity": "critical",
"justification": [
("If others users can modify executables they can obtain "
"elevated privileges", "default")]
},
{
"path": FilePath(os.path.join(BINDIR, "cmtinv")),
"alertmask": 0o022,
"usergroup_alertmask": 0o002,
"executable": True,
"severity": "critical",
"justification": [
("If others users can modify executables they can obtain "
"elevated privileges", "default")]
},
{
"path": FilePath(os.path.join(BINDIR, "cmt")),
"alertmask": 0o022,
"usergroup_alertmask": 0o002,
"executable": True,
"severity": "critical",
"justification": [
("If others users can modify executables they can obtain "
"elevated privileges", "default")]
},
{
"path": FilePath(os.path.join(BINDIR, "cmu")),
"alertmask": 0o022,
"usergroup_alertmask": 0o002,
"executable": True,
"severity": "critical",
"justification": [
("If others users can modify configlets they may be able "
"to obtain elevated privileges", "default")]
},
{
"path": CMT_CONFIG_FILE,
"alertmask": 0o022,
"usergroup_alertmask": 0o002,
"executable": False,
"severity": "critical",
"justification": [
("If others users can modify the CMT configuration file they may be "
"able to obtain elevated privileges", "default")]
},
{
"path": CMT_CONFIG_FILE_DIR,
"suffixes": (".yml", ".yaml"),
"alertmask": 0o022,
"usergroup_alertmask": 0o002,
"executable": False,
"severity": "critical",
"justification": [
("If others users can modify configlets they may be "
"able to obtain elevated privileges", "default")]
},
{
"path": ANSIBLE_PLAYBOOK_DIR,
"suffixes": (".yml", ".yaml"),
"alertmask": 0o022,
"usergroup_alertmask": 0o002,
"executable": False,
"severity": "critical",
"justification": [
("If other users can modify playbooks they can obtain "
"elevated privileges", "default")]
},
{
"path": ANSIBLE_INVENTORY,
"alertmask": 0o077,
"usergroup_alertmask": 0o007,
"severity": "critical",
"justification": [
("If other users can read or modify the Ansible inventory "
"they can obtain elevated privileges", "default")]
},
{
"path": KUBE_CONFIG_FILE,
"alertmask": 0o077,
"usergroup_alertmask": 0o077,
"executable": False,
"severity": "critical",
"justification": [
("If others users can read or modify cluster configuration files "
"they can obtain cluster access", "default")]
},
{
"path": KUBE_CREDENTIALS_FILE,
"alertmask": 0o077,
"usergroup_alertmask": 0o077,
"executable": False,
"severity": "critical",
"justification": [
("If others users can read or modify cluster credential "
"files they can obtain cluster access", "default")],
# This is not a required file, so don't warn if it doesn't exist
"optional": True,
},
]