Skip to content

Commit 79b33fa

Browse files
committed
Merge branch '4.0'
2 parents bd60d0a + fab3ec9 commit 79b33fa

149 files changed

Lines changed: 2483 additions & 1683 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,52 @@ All notable changes to this project will be documented in this file.
88
### Added
99

1010
- Wazuh API:
11-
- Embedded Wazuh API with Wazuh Manager, there is no need to install Wazuh API ([9860823](https://github.com/wazuh/wazuh/commit/9860823d568f5e6d93550d9b139507c04d2c2eb9))
12-
- Migrated Wazuh API server from nodejs to python ([#2640](https://github.com/wazuh/wazuh/pull/2640))
13-
- Added asynchronous aiohttp server for the Wazuh API ([#4474](https://github.com/wazuh/wazuh/issues/4474))
14-
- New Wazuh API is approximately 5 times faster on average ([#5834](https://github.com/wazuh/wazuh/issues/5834))
15-
- Added OpenAPI based Wazuh API specification ([#2413](https://github.com/wazuh/wazuh/issues/2413))
16-
- Improved Wazuh API reference documentation based on OpenAPI spec using redoc ([#4967](https://github.com/wazuh/wazuh/issues/4967))
17-
- Added new yaml Wazuh API configuration file ([#2570](https://github.com/wazuh/wazuh/issues/2570))
18-
- Added new endpoints to manage API configuration and deprecated configure_api.sh ([#2570](https://github.com/wazuh/wazuh/issues/4822))
19-
- Added RBAC support to Wazuh API ([#3287](https://github.com/wazuh/wazuh/issues/3287))
20-
- Added new endpoints for Wazuh API security management ([#3410](https://github.com/wazuh/wazuh/issues/3410))
21-
- Added SQLAlchemy ORM based database for RBAC ([#3375](https://github.com/wazuh/wazuh/issues/3375))
22-
- Added new JWT authentication method ([7080ac3](https://github.com/wazuh/wazuh/commit/7080ac352774bb0feaf07cab76df58ea5503ff4b))
23-
- Wazuh API up and running by default in all nodes for a clustered environment
24-
- Added new and improved error handling ([#2843](https://github.com/wazuh/wazuh/issues/2843) ([#5345](https://github.com/wazuh/wazuh/issues/5345))
25-
- Added tavern and docker based Wazuh API integration tests ([#3612](https://github.com/wazuh/wazuh/issues/3612))
26-
- Added new and unified Wazuh API responses structure ([3421015](https://github.com/wazuh/wazuh/commit/34210154016f0a63211a81707744dce0ec0a54f9))
27-
- Added new endpoints for Wazuh API users management ([#3280](https://github.com/wazuh/wazuh/issues/3280))
28-
- Added new endpoint to restart agents which belong to a node ([#5381](https://github.com/wazuh/wazuh/issues/5381))
29-
- Added and improved q filter in several endpoints ([#5431](https://github.com/wazuh/wazuh/pull/5431))
30-
- Tested and improved Wazuh API security ([#5318](https://github.com/wazuh/wazuh/issues/5318))
31-
- Added DDOS blocking system ([#5318](https://github.com/wazuh/wazuh/issues/5318#issuecomment-654303933))
32-
- Added brute force attack blocking system ([#5318](https://github.com/wazuh/wazuh/issues/5318#issuecomment-652892858))
33-
- Added content-type validation ([#5318](https://github.com/wazuh/wazuh/issues/5318#issuecomment-654807980))
34-
- Added and updated framework unit tests to increase coverage ([#3287](https://github.com/wazuh/wazuh/issues/3287))
11+
- Embedded Wazuh API with Wazuh Manager, there is no need to install Wazuh API. ([9860823](https://github.com/wazuh/wazuh/commit/9860823d568f5e6d93550d9b139507c04d2c2eb9))
12+
- Migrated Wazuh API server from nodejs to python. ([#2640](https://github.com/wazuh/wazuh/pull/2640))
13+
- Added asynchronous aiohttp server for the Wazuh API. ([#4474](https://github.com/wazuh/wazuh/issues/4474))
14+
- New Wazuh API is approximately 5 times faster on average. ([#5834](https://github.com/wazuh/wazuh/issues/5834))
15+
- Added OpenAPI based Wazuh API specification. ([#2413](https://github.com/wazuh/wazuh/issues/2413))
16+
- Improved Wazuh API reference documentation based on OpenAPI spec using redoc. ([#4967](https://github.com/wazuh/wazuh/issues/4967))
17+
- Added new yaml Wazuh API configuration file. ([#2570](https://github.com/wazuh/wazuh/issues/2570))
18+
- Added new endpoints to manage API configuration and deprecated configure_api.sh. ([#2570](https://github.com/wazuh/wazuh/issues/4822))
19+
- Added RBAC support to Wazuh API. ([#3287](https://github.com/wazuh/wazuh/issues/3287))
20+
- Added new endpoints for Wazuh API security management. ([#3410](https://github.com/wazuh/wazuh/issues/3410))
21+
- Added SQLAlchemy ORM based database for RBAC. ([#3375](https://github.com/wazuh/wazuh/issues/3375))
22+
- Added new JWT authentication method. ([7080ac3](https://github.com/wazuh/wazuh/commit/7080ac352774bb0feaf07cab76df58ea5503ff4b))
23+
- Wazuh API up and running by default in all nodes for a clustered environment.
24+
- Added new and improved error handling. ([#2843](https://github.com/wazuh/wazuh/issues/2843) ([#5345](https://github.com/wazuh/wazuh/issues/5345))
25+
- Added tavern and docker based Wazuh API integration tests. ([#3612](https://github.com/wazuh/wazuh/issues/3612))
26+
- Added new and unified Wazuh API responses structure. ([3421015](https://github.com/wazuh/wazuh/commit/34210154016f0a63211a81707744dce0ec0a54f9))
27+
- Added new endpoints for Wazuh API users management. ([#3280](https://github.com/wazuh/wazuh/issues/3280))
28+
- Added new endpoint to restart agents which belong to a node. ([#5381](https://github.com/wazuh/wazuh/issues/5381))
29+
- Added and improved q filter in several endpoints. ([#5431](https://github.com/wazuh/wazuh/pull/5431))
30+
- Tested and improved Wazuh API security. ([#5318](https://github.com/wazuh/wazuh/issues/5318))
31+
- Added DDOS blocking system. ([#5318](https://github.com/wazuh/wazuh/issues/5318#issuecomment-654303933))
32+
- Added brute force attack blocking system. ([#5318](https://github.com/wazuh/wazuh/issues/5318#issuecomment-652892858))
33+
- Added content-type validation. ([#5318](https://github.com/wazuh/wazuh/issues/5318#issuecomment-654807980))
34+
- Added and updated framework unit tests to increase coverage. ([#3287](https://github.com/wazuh/wazuh/issues/3287))
3535
- Added improved support for monitoring paths from environment variables. ([#4961](https://github.com/wazuh/wazuh/pull/4961))
3636
- Added auto enrollment capability. Agents are now able to request a key from the manager if current key is missing or wrong. ([#5609](https://github.com/wazuh/wazuh/pull/5609))
37+
- Vulnerability Detector:
38+
- Redhat vulnerabilities are now fetched from OVAL benchmarks. ([#5352](https://github.com/wazuh/wazuh/pull/5352))
39+
- Debian vulnerable packages are now fetched from the Security Tracker. ([#5304](https://github.com/wazuh/wazuh/pull/5304))
40+
- The Debian Security Tracker feed can be loaded from a custom location. ([#5449](https://github.com/wazuh/wazuh/pull/5449))
41+
- Allow compressed feeds for offline updates. ([#5745](https://github.com/wazuh/wazuh/pull/5745))
42+
- The manager now updates the MSU feed automatically. ([#5678](https://github.com/wazuh/wazuh/pull/5678))
43+
- CVEs with no affected version defined in all the feeds are now reported. ([#5284](https://github.com/wazuh/wazuh/pull/5284))
44+
- CVEs vulnerable for the vendor and missing in the NVD are now reported. ([#5305](https://github.com/wazuh/wazuh/pull/5305))
3745

3846
### Changed
3947

40-
- Changed multiple Wazuh API endpoints ([#2640](https://github.com/wazuh/wazuh/pull/2640)) ([#2413](https://github.com/wazuh/wazuh-documentation/issues/2413))
41-
- Refactored framework module in SDK and core ([#5263](https://github.com/wazuh/wazuh/issues/5263))
48+
- Changed multiple Wazuh API endpoints. ([#2640](https://github.com/wazuh/wazuh/pull/2640)) ([#2413](https://github.com/wazuh/wazuh-documentation/issues/2413))
49+
- Refactored framework module in SDK and core. ([#5263](https://github.com/wazuh/wazuh/issues/5263))
4250
- FIM Windows events handling refactored. ([#5144](https://github.com/wazuh/wazuh/pull/5144))
43-
- Changed framework to access global.db using wazuh-db ([#6095](https://github.com/wazuh/wazuh/pull/6095))
51+
- Changed framework to access global.db using wazuh-db. ([#6095](https://github.com/wazuh/wazuh/pull/6095))
4452
- Changed agent-info synchronization task in Wazuh cluster. ([#5585](https://github.com/wazuh/wazuh/issues/5585))
4553

4654
### Fixed
4755

48-
- Fixed an error with last scan time in syscheck endpoints ([a9acd3a](https://github.com/wazuh/wazuh/commit/a9acd3a216a7e0075a8efa5a91b2587659782fd8))
56+
- Fixed an error with last scan time in syscheck endpoints. ([a9acd3a](https://github.com/wazuh/wazuh/commit/a9acd3a216a7e0075a8efa5a91b2587659782fd8))
4957
- Added support for monitoring directories which contain commas. ([#4961](https://github.com/wazuh/wazuh/pull/4961))
5058
- Fixed a bug where configuring a directory to be monitored as realtime and whodata resulted in realtime prevailing. ([#4961](https://github.com/wazuh/wazuh/pull/4961))
5159
- Fixed using an incorrect mutex while deleting inotify watches. ([#5126](https://github.com/wazuh/wazuh/pull/5126))
@@ -55,12 +63,20 @@ All notable changes to this project will be documented in this file.
5563
- Fixed an error where monitoring a drive in Windows under scheduled or realtime mode would generate alerts from the recycle bin. ([#4771](https://github.com/wazuh/wazuh/pull/4771))
5664
- When monitoring a drive in Windows in the format `U:`, it will monitor `U:\` instead of the agent's working directory. ([#5259](https://github.com/wazuh/wazuh/pull/5259))
5765
- Fixed a bug where monitoring a drive in Windows with recursion_level set to 0 would trigger alerts from files inside its subdirectories. ([#5235](https://github.com/wazuh/wazuh/pull/5235))
66+
- Vulnerability Detector:
67+
- Vulnerabilities of Windows Server 2019 which not affects to Windows 10 were not being reported. ([#5524](https://github.com/wazuh/wazuh/pull/5524))
68+
- Vulnerabilities patched by a Microsoft update with no supersedence were not being reported. ([#5524](https://github.com/wazuh/wazuh/pull/5524))
69+
- Vulnerabilities patched by more than one Microsoft update were not being evaluated agains all the patches. ([#5717](https://github.com/wazuh/wazuh/pull/5717))
70+
- Duplicated alerts in Windows 10. ([#5600](https://github.com/wazuh/wazuh/pull/5600))
71+
- Syscollector now discards hotfixes that are not fully installed. ([#5792](https://github.com/wazuh/wazuh/pull/5792))
72+
- Syscollector now collects hotfixes that were not being parsed. ([#5792](https://github.com/wazuh/wazuh/pull/5792))
73+
- Fixed an Azure wodle dependency error. The package azure-storage-blob>12.0.0 does not include a component used. ([#6109](https://github.com/wazuh/wazuh/pull/6109))
5874

5975
### Removed
6076

61-
- Removed Wazuh API cache endpoints ([#3042](https://github.com/wazuh/wazuh/pull/3042))
62-
- Removed Wazuh API rootcheck endpoints ([#5246](https://github.com/wazuh/wazuh/issues/5246))
63-
77+
- Removed Wazuh API cache endpoints. ([#3042](https://github.com/wazuh/wazuh/pull/3042))
78+
- Removed Wazuh API rootcheck endpoints. ([#5246](https://github.com/wazuh/wazuh/issues/5246))
79+
- Deprecated Debian Jessie and Wheezy for Vulnerability Detector (EOL). ([#5660](https://github.com/wazuh/wazuh/pull/5660))
6480

6581
## [v3.13.2] - 2020-09-21
6682

api/api/authentication.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2015-2019, Wazuh Inc.
1+
# Copyright (C) 2015-2020, Wazuh Inc.
22
# Created by Wazuh, Inc. <info@wazuh.com>.
33
# This program is a free software; you can redistribute it and/or modify it under the terms of GPLv2
44

@@ -14,12 +14,14 @@
1414
from jose import JWTError, jwt
1515
from werkzeug.exceptions import Unauthorized
1616

17-
import api.configuration as configuration
17+
import api.configuration as conf
18+
from api.constants import SECURITY_CONFIG_PATH
1819
from api.constants import SECURITY_PATH
1920
from api.util import raise_if_exc
2021
from wazuh import WazuhInternalError
2122
from wazuh.core.cluster.dapi.dapi import DistributedAPI
2223
from wazuh.rbac.orm import AuthenticationManager, TokenManager, UserRolesManager, Roles
24+
from wazuh.rbac.preprocessor import optimize_resources
2325

2426
pool = concurrent.futures.ThreadPoolExecutor()
2527

@@ -110,18 +112,20 @@ def change_secret():
110112

111113

112114
def get_security_conf():
113-
return copy.deepcopy(configuration.security_conf)
115+
conf.security_conf.update(conf.read_yaml_config(config_file=SECURITY_CONFIG_PATH,
116+
default_conf=conf.default_security_configuration))
117+
return copy.deepcopy(conf.security_conf)
114118

115119

116-
def generate_token(user_id=None, rbac_policies=None):
120+
def generate_token(user_id=None, data=None):
117121
"""Generate an encoded jwt token. This method should be called once a user is properly logged on.
118122
119123
Parameters
120124
----------
121125
user_id : str
122126
Unique username
123-
rbac_policies : dict
124-
Permissions for the user
127+
data : dict
128+
Roles permissions for the user
125129
126130
Returns
127131
-------
@@ -135,17 +139,15 @@ def generate_token(user_id=None, rbac_policies=None):
135139
)
136140
result = raise_if_exc(pool.submit(asyncio.run, dapi.distribute_function()).result()).dikt
137141
timestamp = int(time())
138-
roles = rbac_policies['roles']
139-
rbac_policies = rbac_policies['policies']
140-
rbac_policies['rbac_mode'] = result['rbac_mode']
142+
141143
payload = {
142144
"iss": JWT_ISSUER,
143145
"aud": "Wazuh API REST",
144146
"nbf": int(timestamp),
145147
"exp": int(timestamp + result['auth_token_exp_timeout']),
146148
"sub": str(user_id),
147-
"rbac_roles": roles,
148-
"rbac_policies": rbac_policies
149+
"rbac_roles": data['roles'],
150+
"rbac_mode": result['rbac_mode']
149151
}
150152

151153
return jwt.encode(payload, generate_secret(), algorithm=JWT_ALGORITHM)
@@ -182,11 +184,13 @@ def check_token(username, roles, token_nbf_time):
182184
if not tm.is_token_valid(role_id=role, user_id=user_id, token_nbf_time=int(token_nbf_time)):
183185
return {'valid': False}
184186

185-
return {'valid': True}
187+
policies = optimize_resources(roles)
188+
189+
return {'valid': True, 'policies': policies}
186190

187191

188192
def decode_token(token):
189-
"""Decode a jwt formatted token. Raise an Unauthorized exception in case validation fails.
193+
"""Decode a jwt formatted token and add processed policies. Raise an Unauthorized exception in case validation fails.
190194
191195
Parameters
192196
----------
@@ -198,7 +202,10 @@ def decode_token(token):
198202
Dict payload ot the token
199203
"""
200204
try:
205+
# Decode JWT token with local secret
201206
payload = jwt.decode(token, generate_secret(), algorithms=[JWT_ALGORITHM], audience='Wazuh API REST')
207+
208+
# Check token and add processed policies in the Master node
202209
dapi = DistributedAPI(f=check_token,
203210
f_kwargs={'username': payload['sub'],
204211
'roles': payload['rbac_roles'], 'token_nbf_time': payload['nbf']},
@@ -207,10 +214,12 @@ def decode_token(token):
207214
wait_for_complete=True,
208215
logger=logging.getLogger('wazuh')
209216
)
210-
data = raise_if_exc(pool.submit(asyncio.run, dapi.distribute_function()).result())
217+
data = raise_if_exc(pool.submit(asyncio.run, dapi.distribute_function()).result()).to_dict()
211218

212-
if not data.to_dict()['result']['valid']:
219+
if not data['result']['valid']:
213220
raise Unauthorized
221+
payload['rbac_policies'] = data['result']['policies']
222+
payload['rbac_policies']['rbac_mode'] = payload.pop('rbac_mode')
214223

215224
# Detect local changes
216225
dapi = DistributedAPI(f=get_security_conf,
@@ -220,10 +229,11 @@ def decode_token(token):
220229
logger=logging.getLogger('wazuh')
221230
)
222231
result = raise_if_exc(pool.submit(asyncio.run, dapi.distribute_function()).result())
232+
223233
current_rbac_mode = result['rbac_mode']
224234
current_expiration_time = result['auth_token_exp_timeout']
225-
if payload['rbac_policies']['rbac_mode'] != current_rbac_mode or \
226-
(payload['exp'] - payload['nbf']) != current_expiration_time:
235+
if payload['rbac_policies']['rbac_mode'] != current_rbac_mode \
236+
or (payload['exp'] - payload['nbf']) != current_expiration_time:
227237
raise Unauthorized
228238

229239
return payload

api/api/configuration.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ def generate_private_key(private_key_path, public_exponent=65537, key_size=2048)
136136
format=serialization.PrivateFormat.PKCS8,
137137
encryption_algorithm=serialization.NoEncryption()
138138
))
139+
os.chmod(private_key_path, 0o400)
140+
139141
return key
140142

141143

@@ -181,6 +183,7 @@ def generate_self_signed_certificate(private_key, certificate_path):
181183
# Write our certificate out to disk.
182184
with open(certificate_path, 'wb') as f:
183185
f.write(cert.public_bytes(serialization.Encoding.PEM))
186+
os.chmod(certificate_path, 0o400)
184187

185188

186189
def read_yaml_config(config_file=common.api_config_path, default_conf=None) -> Dict:

0 commit comments

Comments
 (0)