gym-csle-stopping-game 0.6.2__tar.gz → 0.6.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of gym-csle-stopping-game might be problematic. Click here for more details.
- {gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/PKG-INFO +1 -1
- {gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/setup.cfg +5 -5
- gym_csle_stopping_game-0.6.3/src/gym_csle_stopping_game/__version__.py +1 -0
- {gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/src/gym_csle_stopping_game/envs/stopping_game_env.py +0 -103
- {gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/src/gym_csle_stopping_game/envs/stopping_game_pomdp_defender_env.py +0 -27
- {gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/src/gym_csle_stopping_game.egg-info/PKG-INFO +1 -1
- {gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/src/gym_csle_stopping_game.egg-info/requires.txt +5 -5
- {gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/tests/test_stopping_game_env.py +1 -9
- gym_csle_stopping_game-0.6.2/src/gym_csle_stopping_game/__version__.py +0 -1
- {gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/pyproject.toml +0 -0
- {gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/setup.py +0 -0
- {gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/src/gym_csle_stopping_game/__init__.py +0 -0
- {gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/src/gym_csle_stopping_game/constants/__init__.py +0 -0
- {gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/src/gym_csle_stopping_game/constants/constants.py +0 -0
- {gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/src/gym_csle_stopping_game/dao/__init__.py +0 -0
- {gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/src/gym_csle_stopping_game/dao/stopping_game_attacker_mdp_config.py +0 -0
- {gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/src/gym_csle_stopping_game/dao/stopping_game_config.py +0 -0
- {gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/src/gym_csle_stopping_game/dao/stopping_game_defender_pomdp_config.py +0 -0
- {gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/src/gym_csle_stopping_game/dao/stopping_game_state.py +0 -0
- {gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/src/gym_csle_stopping_game/envs/__init__.py +0 -0
- {gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/src/gym_csle_stopping_game/envs/stopping_game_mdp_attacker_env.py +0 -0
- {gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/src/gym_csle_stopping_game/util/__init__.py +0 -0
- {gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/src/gym_csle_stopping_game/util/stopping_game_util.py +0 -0
- {gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/src/gym_csle_stopping_game.egg-info/SOURCES.txt +0 -0
- {gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/src/gym_csle_stopping_game.egg-info/dependency_links.txt +0 -0
- {gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/src/gym_csle_stopping_game.egg-info/not-zip-safe +0 -0
- {gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/src/gym_csle_stopping_game.egg-info/top_level.txt +0 -0
- {gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/tests/test_stopping_game_dao.py +0 -0
- {gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/tests/test_stopping_game_mdp_attacker_env.py +0 -0
- {gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/tests/test_stopping_game_pomdp_defender_env.py +0 -0
- {gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/tests/test_stopping_game_util.py +0 -0
|
@@ -20,11 +20,11 @@ classifiers =
|
|
|
20
20
|
[options]
|
|
21
21
|
install_requires =
|
|
22
22
|
gymnasium>=0.27.1
|
|
23
|
-
csle-base>=0.6.
|
|
24
|
-
csle-common>=0.6.
|
|
25
|
-
csle-attacker>=0.6.
|
|
26
|
-
csle-defender>=0.6.
|
|
27
|
-
csle-collector>=0.6.
|
|
23
|
+
csle-base>=0.6.3
|
|
24
|
+
csle-common>=0.6.3
|
|
25
|
+
csle-attacker>=0.6.3
|
|
26
|
+
csle-defender>=0.6.3
|
|
27
|
+
csle-collector>=0.6.3
|
|
28
28
|
python_requires = >=3.8
|
|
29
29
|
package_dir =
|
|
30
30
|
=src
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = '0.6.3'
|
|
@@ -7,24 +7,10 @@ import math
|
|
|
7
7
|
import csle_common.constants.constants as constants
|
|
8
8
|
from csle_common.dao.simulation_config.base_env import BaseEnv
|
|
9
9
|
from csle_common.dao.simulation_config.simulation_trace import SimulationTrace
|
|
10
|
-
from csle_common.dao.training.policy import Policy
|
|
11
|
-
from csle_common.dao.emulation_config.emulation_env_state import EmulationEnvState
|
|
12
|
-
from csle_common.dao.emulation_config.emulation_env_config import EmulationEnvConfig
|
|
13
|
-
from csle_common.dao.simulation_config.simulation_env_config import SimulationEnvConfig
|
|
14
|
-
from csle_common.dao.emulation_config.emulation_simulation_trace import EmulationSimulationTrace
|
|
15
|
-
from csle_common.dao.emulation_action.attacker.emulation_attacker_stopping_actions \
|
|
16
|
-
import EmulationAttackerStoppingActions
|
|
17
|
-
from csle_common.dao.emulation_action.attacker.emulation_attacker_action import EmulationAttackerAction
|
|
18
|
-
from csle_common.dao.emulation_action.defender.emulation_defender_stopping_actions \
|
|
19
|
-
import EmulationDefenderStoppingActions
|
|
20
|
-
from csle_common.metastore.metastore_facade import MetastoreFacade
|
|
21
|
-
from csle_common.logging.log import Logger
|
|
22
|
-
from csle_system_identification.emulator import Emulator
|
|
23
10
|
from gym_csle_stopping_game.util.stopping_game_util import StoppingGameUtil
|
|
24
11
|
from gym_csle_stopping_game.dao.stopping_game_config import StoppingGameConfig
|
|
25
12
|
from gym_csle_stopping_game.dao.stopping_game_state import StoppingGameState
|
|
26
13
|
import gym_csle_stopping_game.constants.constants as env_constants
|
|
27
|
-
from csle_common.dao.emulation_config.emulation_trace import EmulationTrace
|
|
28
14
|
|
|
29
15
|
|
|
30
16
|
class StoppingGameEnv(BaseEnv):
|
|
@@ -244,95 +230,6 @@ class StoppingGameEnv(BaseEnv):
|
|
|
244
230
|
info[env_constants.ENV_METRICS.TIME_STEP] = self.state.t
|
|
245
231
|
return (defender_obs, attacker_obs), info
|
|
246
232
|
|
|
247
|
-
@staticmethod
|
|
248
|
-
def emulation_evaluation(env: "StoppingGameEnv", n_episodes: int, intrusion_seq: List[EmulationAttackerAction],
|
|
249
|
-
defender_policy: Policy,
|
|
250
|
-
attacker_policy: Policy,
|
|
251
|
-
emulation_env_config: EmulationEnvConfig,
|
|
252
|
-
simulation_env_config: SimulationEnvConfig
|
|
253
|
-
) -> List[EmulationSimulationTrace]:
|
|
254
|
-
"""
|
|
255
|
-
Utility function for evaluating a strategy profile in the emulation environment
|
|
256
|
-
|
|
257
|
-
:param env: the environment to use for evaluation
|
|
258
|
-
:param n_episodes: the number of evaluation episodes
|
|
259
|
-
:param intrusion_seq: the intrusion sequence for the evaluation (sequence of attacker actions)
|
|
260
|
-
:param defender_policy: the defender policy for the evaluation
|
|
261
|
-
:param attacker_policy: the attacker policy for the evaluation
|
|
262
|
-
:param emulation_env_config: configuration of the emulation environment for the evaluation
|
|
263
|
-
:param simulation_env_config: configuration of the simulation environment for the evaluation
|
|
264
|
-
:return: traces with the evaluation results
|
|
265
|
-
"""
|
|
266
|
-
logger = Logger.__call__().get_logger()
|
|
267
|
-
traces = []
|
|
268
|
-
s = EmulationEnvState(emulation_env_config=emulation_env_config)
|
|
269
|
-
s.initialize_defender_machines()
|
|
270
|
-
for i in range(n_episodes):
|
|
271
|
-
done = False
|
|
272
|
-
defender_obs_space = simulation_env_config.joint_observation_space_config.observation_spaces[0]
|
|
273
|
-
b = env.state.b1
|
|
274
|
-
o, _ = env.reset()
|
|
275
|
-
(d_obs, a_obs) = o
|
|
276
|
-
t = 0
|
|
277
|
-
s.reset()
|
|
278
|
-
emulation_trace = EmulationTrace(initial_attacker_observation_state=s.attacker_obs_state,
|
|
279
|
-
initial_defender_observation_state=s.defender_obs_state,
|
|
280
|
-
emulation_name=emulation_env_config.name)
|
|
281
|
-
simulation_trace = SimulationTrace(simulation_env=env.config.env_name)
|
|
282
|
-
while not done:
|
|
283
|
-
a1 = defender_policy.action(d_obs)
|
|
284
|
-
a2 = attacker_policy.action(a_obs)
|
|
285
|
-
o, r, done, info, _ = env.step((a1, a2))
|
|
286
|
-
(d_obs, a_obs) = o
|
|
287
|
-
r_1, r_2 = r
|
|
288
|
-
logger.debug(f"a1:{a1}, a2:{a2}, d_obs:{d_obs}, a_obs:{a_obs}, r:{r}, done:{done}, info: {info}")
|
|
289
|
-
if a1 == 0:
|
|
290
|
-
defender_action = EmulationDefenderStoppingActions.CONTINUE(index=-1)
|
|
291
|
-
else:
|
|
292
|
-
defender_action = EmulationDefenderStoppingActions.CONTINUE(index=-1)
|
|
293
|
-
if env.state.s == 1:
|
|
294
|
-
if t >= len(intrusion_seq):
|
|
295
|
-
t = 0
|
|
296
|
-
attacker_action = intrusion_seq[t]
|
|
297
|
-
else:
|
|
298
|
-
attacker_action = EmulationAttackerStoppingActions.CONTINUE(index=-1)
|
|
299
|
-
emulation_trace, s = Emulator.run_actions(
|
|
300
|
-
s=s,
|
|
301
|
-
emulation_env_config=emulation_env_config, attacker_action=attacker_action,
|
|
302
|
-
defender_action=defender_action, trace=emulation_trace,
|
|
303
|
-
sleep_time=emulation_env_config.kafka_config.time_step_len_seconds)
|
|
304
|
-
o_components = [s.defender_obs_state.snort_ids_alert_counters.severe_alerts,
|
|
305
|
-
s.defender_obs_state.snort_ids_alert_counters.warning_alerts,
|
|
306
|
-
s.defender_obs_state.aggregated_host_metrics.num_failed_login_attempts]
|
|
307
|
-
o_components_str = ",".join(list(map(lambda x: str(x), o_components)))
|
|
308
|
-
logger.debug(f"o_components:{o_components}")
|
|
309
|
-
logger.debug(f"observation_id_to_observation_vector_inv:"
|
|
310
|
-
f"{defender_obs_space.observation_id_to_observation_vector_inv}")
|
|
311
|
-
logger.debug(f"observation_id_to_observation_vector_inv:"
|
|
312
|
-
f"{o_components_str in defender_obs_space.observation_id_to_observation_vector_inv}")
|
|
313
|
-
emulation_o = 0
|
|
314
|
-
if o_components_str in defender_obs_space.observation_id_to_observation_vector_inv:
|
|
315
|
-
emulation_o = defender_obs_space.observation_id_to_observation_vector_inv[o_components_str]
|
|
316
|
-
logger.debug(f"o:{emulation_o}")
|
|
317
|
-
b = StoppingGameUtil.next_belief(o=emulation_o, a1=a1, b=b, pi2=a2, config=env.config,
|
|
318
|
-
l=env.state.l, a2=a2)
|
|
319
|
-
d_obs[1] = b[1]
|
|
320
|
-
a_obs[1] = b[1]
|
|
321
|
-
logger.debug(f"b:{b}")
|
|
322
|
-
simulation_trace.defender_rewards.append(r_1)
|
|
323
|
-
simulation_trace.attacker_rewards.append(r_2)
|
|
324
|
-
simulation_trace.attacker_actions.append(a2)
|
|
325
|
-
simulation_trace.defender_actions.append(a1)
|
|
326
|
-
simulation_trace.infos.append(info)
|
|
327
|
-
simulation_trace.states.append(s)
|
|
328
|
-
simulation_trace.beliefs.append(b[1])
|
|
329
|
-
simulation_trace.infrastructure_metrics.append(emulation_o)
|
|
330
|
-
|
|
331
|
-
em_sim_trace = EmulationSimulationTrace(emulation_trace=emulation_trace, simulation_trace=simulation_trace)
|
|
332
|
-
MetastoreFacade.save_emulation_simulation_trace(em_sim_trace)
|
|
333
|
-
traces.append(em_sim_trace)
|
|
334
|
-
return traces
|
|
335
|
-
|
|
336
233
|
def render(self, mode: str = 'human'):
|
|
337
234
|
"""
|
|
338
235
|
Renders the environment. Supported rendering modes: (1) human; and (2) rgb_array
|
|
@@ -4,12 +4,7 @@ import numpy.typing as npt
|
|
|
4
4
|
from csle_common.dao.simulation_config.base_env import BaseEnv
|
|
5
5
|
from gym_csle_stopping_game.dao.stopping_game_defender_pomdp_config import StoppingGameDefenderPomdpConfig
|
|
6
6
|
from csle_common.dao.simulation_config.simulation_trace import SimulationTrace
|
|
7
|
-
from csle_common.dao.training.policy import Policy
|
|
8
|
-
from csle_common.dao.emulation_config.emulation_env_config import EmulationEnvConfig
|
|
9
|
-
from csle_common.dao.simulation_config.simulation_env_config import SimulationEnvConfig
|
|
10
|
-
from csle_common.dao.emulation_config.emulation_simulation_trace import EmulationSimulationTrace
|
|
11
7
|
from csle_common.dao.emulation_config.emulation_trace import EmulationTrace
|
|
12
|
-
from csle_common.dao.emulation_action.attacker.emulation_attacker_action import EmulationAttackerAction
|
|
13
8
|
from gym_csle_stopping_game.envs.stopping_game_env import StoppingGameEnv
|
|
14
9
|
from gym_csle_stopping_game.util.stopping_game_util import StoppingGameUtil
|
|
15
10
|
|
|
@@ -103,28 +98,6 @@ class StoppingGamePomdpDefenderEnv(BaseEnv):
|
|
|
103
98
|
defender_obs = o[0]
|
|
104
99
|
return defender_obs, r[0], d, info
|
|
105
100
|
|
|
106
|
-
@staticmethod
|
|
107
|
-
def emulation_evaluation(env: "StoppingGamePomdpDefenderEnv",
|
|
108
|
-
n_episodes: int, intrusion_seq: List[EmulationAttackerAction],
|
|
109
|
-
defender_policy: Policy,
|
|
110
|
-
emulation_env_config: EmulationEnvConfig, simulation_env_config: SimulationEnvConfig) \
|
|
111
|
-
-> List[EmulationSimulationTrace]:
|
|
112
|
-
"""
|
|
113
|
-
Utility function for evaluating policies in the emulation environment
|
|
114
|
-
|
|
115
|
-
:param env: the environment to use for evaluation
|
|
116
|
-
:param n_episodes: the number of episodes to use for evaluation
|
|
117
|
-
:param intrusion_seq: the sequence of intrusion actions to use for evaluation
|
|
118
|
-
:param defender_policy: the defender policy to use for evaluation
|
|
119
|
-
:param emulation_env_config: the configuration of the emulation environment to use for evaluation
|
|
120
|
-
:param simulation_env_config: the configuration of the simulation environment to use for evaluation
|
|
121
|
-
:return: traces with the evaluation results
|
|
122
|
-
"""
|
|
123
|
-
return StoppingGameEnv.emulation_evaluation(
|
|
124
|
-
env=env.stopping_game_env, n_episodes=n_episodes, intrusion_seq=intrusion_seq,
|
|
125
|
-
defender_policy=defender_policy, attacker_policy=env.static_attacker_strategy,
|
|
126
|
-
emulation_env_config=emulation_env_config, simulation_env_config=simulation_env_config)
|
|
127
|
-
|
|
128
101
|
def is_defense_action_legal(self, defense_action_id: int) -> bool:
|
|
129
102
|
"""
|
|
130
103
|
Checks whether a defender action in the environment is legal or not
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
gymnasium>=0.27.1
|
|
2
|
-
csle-base>=0.6.
|
|
3
|
-
csle-common>=0.6.
|
|
4
|
-
csle-attacker>=0.6.
|
|
5
|
-
csle-defender>=0.6.
|
|
6
|
-
csle-collector>=0.6.
|
|
2
|
+
csle-base>=0.6.3
|
|
3
|
+
csle-common>=0.6.3
|
|
4
|
+
csle-attacker>=0.6.3
|
|
5
|
+
csle-defender>=0.6.3
|
|
6
|
+
csle-collector>=0.6.3
|
|
7
7
|
|
|
8
8
|
[testing]
|
|
9
9
|
pytest>=6.0
|
{gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/tests/test_stopping_game_env.py
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from typing import Dict, Any
|
|
2
2
|
import pytest
|
|
3
3
|
from unittest.mock import patch, MagicMock
|
|
4
|
-
from
|
|
4
|
+
from gymnasium.spaces import Box, Discrete
|
|
5
5
|
import numpy as np
|
|
6
6
|
from gym_csle_stopping_game.envs.stopping_game_env import StoppingGameEnv
|
|
7
7
|
from gym_csle_stopping_game.dao.stopping_game_config import StoppingGameConfig
|
|
@@ -418,11 +418,3 @@ class TestStoppingGameEnvSuite:
|
|
|
418
418
|
info: Dict[str, Any] = {}
|
|
419
419
|
updated_info = env._info(info)
|
|
420
420
|
assert updated_info[env_constants.ENV_METRICS.RETURN] == sum(env.trace.defender_rewards)
|
|
421
|
-
|
|
422
|
-
def test_emulation_evaluation(self) -> None:
|
|
423
|
-
"""
|
|
424
|
-
Tests the function for evaluating a strategy profile in the emulation environment
|
|
425
|
-
|
|
426
|
-
:return: None
|
|
427
|
-
"""
|
|
428
|
-
StoppingGameEnv(self.config)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = '0.6.2'
|
|
File without changes
|
|
File without changes
|
{gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/src/gym_csle_stopping_game/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/tests/test_stopping_game_dao.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{gym_csle_stopping_game-0.6.2 → gym_csle_stopping_game-0.6.3}/tests/test_stopping_game_util.py
RENAMED
|
File without changes
|