Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Added UserInfo Filter Logging Function #661

Merged
48 commits merged into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
293dd06
Updating yml file to run config endpoint command with tenant/authorit…
nharper285 Nov 23, 2020
cbf9dd3
Adding -DD parameter to unzip command. Forces file replacement irresp…
nharper285 Nov 25, 2020
deb6c5d
Revert "Adding -DD parameter to unzip command. Forces file replacemen…
nharper285 Nov 25, 2020
5a7d9bb
Merge branch 'main' into main
bmc-msft Nov 30, 2020
daddaa1
Adding -DD parameter to unzip command. Forces file replacement irresp…
nharper285 Nov 25, 2020
4fa2486
Revert "Adding -DD parameter to unzip command. Forces file replacemen…
nharper285 Nov 25, 2020
d84ac5d
Merge branch 'main' of https://github.com/nharper285/onefuzz into main
nharper285 Jan 26, 2021
4273a01
Merge remote-tracking branch 'upstream/main' into main
nharper285 Feb 24, 2021
4bf731e
Adding -DD parameter to unzip command. Forces file replacement irresp…
nharper285 Nov 25, 2020
5771fc9
Revert "Adding -DD parameter to unzip command. Forces file replacemen…
nharper285 Nov 25, 2020
7dab9e5
Adding -DD parameter to unzip command. Forces file replacement irresp…
nharper285 Nov 25, 2020
63b966b
Revert "Adding -DD parameter to unzip command. Forces file replacemen…
nharper285 Nov 25, 2020
7aa20a3
Merge branch 'main' of https://github.com/nharper285/onefuzz
nharper285 Mar 4, 2021
23bd81a
Adding -DD parameter to unzip command. Forces file replacement irresp…
nharper285 Nov 25, 2020
0cbfc50
Revert "Adding -DD parameter to unzip command. Forces file replacemen…
nharper285 Nov 25, 2020
7dbb77f
Adding -DD parameter to unzip command. Forces file replacement irresp…
nharper285 Nov 25, 2020
e0916ed
Revert "Adding -DD parameter to unzip command. Forces file replacemen…
nharper285 Nov 25, 2020
3dca8ca
Adding -DD parameter to unzip command. Forces file replacement irresp…
nharper285 Nov 25, 2020
b4f22aa
Revert "Adding -DD parameter to unzip command. Forces file replacemen…
nharper285 Nov 25, 2020
c603b1b
Adding -DD parameter to unzip command. Forces file replacement irresp…
nharper285 Nov 25, 2020
359c96c
Revert "Adding -DD parameter to unzip command. Forces file replacemen…
nharper285 Nov 25, 2020
b447bb2
Merge branch 'main' of https://github.com/nharper285/onefuzz
nharper285 Mar 8, 2021
60a1120
Adding UserInfo filter function for logging.
nharper285 Mar 10, 2021
da1a6ea
Removed __main__
nharper285 Mar 10, 2021
39fed4b
Adding unit tests
nharper285 Mar 10, 2021
71e677c
Reformatted with black
nharper285 Mar 10, 2021
5252576
Comment changes
nharper285 Mar 10, 2021
cb6bb15
Using isort to fix imports.
nharper285 Mar 11, 2021
11ff21c
Getting rid of unused imports
nharper285 Mar 11, 2021
b705f3b
leftover imports
nharper285 Mar 11, 2021
b7d0bce
Revert "Using isort to fix imports."
nharper285 Mar 11, 2021
7a1e9bf
Fixing events.py format
nharper285 Mar 11, 2021
41546db
Fixing unit test formatting
nharper285 Mar 11, 2021
4cda392
AzCopy failed?
nharper285 Mar 11, 2021
f054251
formatting
nharper285 Mar 11, 2021
a246289
Replacing BaseModel with BaseEvent
nharper285 Mar 11, 2021
02a1dcc
formatting
nharper285 Mar 11, 2021
4d7f2d6
formatting
nharper285 Mar 11, 2021
8a7afa2
removing test script
nharper285 Mar 11, 2021
bf92a7b
Fixed return statement and BaseModel argument type
nharper285 Mar 11, 2021
1b6c38a
Fixing return types
nharper285 Mar 11, 2021
aa32241
Adding third logging function to distinguish between filtering and lo…
nharper285 Mar 11, 2021
aac8195
Merge branch 'main' into user/noharper/scrub-user-info
bmc-msft Mar 11, 2021
397a34a
Merge branch 'main' into user/noharper/scrub-user-info
bmc-msft Mar 11, 2021
bd81232
Fixing log_event call
nharper285 Mar 15, 2021
181d876
Merge branch 'user/noharper/scrub-user-info' of https://github.com/nh…
nharper285 Mar 15, 2021
fe12253
Merge branch 'main' into user/noharper/scrub-user-info
bmc-msft Mar 15, 2021
a1e37de
Merge branch 'main' into user/noharper/scrub-user-info
bmc-msft Mar 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 56 additions & 3 deletions src/api-service/__app__/onefuzzlib/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import json
import logging
from queue import Empty, Queue
from typing import Optional
from typing import List, Optional, Set

from onefuzztypes.events import Event, EventMessage, get_event_type
from onefuzztypes.events import Event, EventMessage, EventType, get_event_type
from onefuzztypes.models import UserInfo
from pydantic import BaseModel

from .azure.creds import get_instance_id, get_instance_name
from .webhooks import Webhook
Expand All @@ -33,9 +35,60 @@ def get_events() -> Optional[str]:
return None


def log_event(event: Event, event_type: EventType) -> None:
chkeita marked this conversation as resolved.
Show resolved Hide resolved
scrubbed_event = filter_event(event, event_type)
logging.info("sending event: %s - %s", event_type, scrubbed_event)


def filter_event(event: Event, event_type: EventType) -> Event:

clone_event = event.copy(deep=True)
filter_event_recurs(clone_event)

return clone_event

bmc-msft marked this conversation as resolved.
Show resolved Hide resolved

def filter_event_recurs(clone_event: BaseModel, visited: Set[int] = set()) -> BaseModel:

if id(clone_event) in visited:
return clone_event

visited.add(id(clone_event))

for field in clone_event.__fields__:
field_data = getattr(clone_event, field)

if isinstance(field_data, UserInfo):

field_data = None

elif isinstance(field_data, List):

if len(field_data) > 0 and not isinstance(field_data[0], BaseModel):
continue
for data in field_data:
filter_event_recurs(data, visited)

elif isinstance(field_data, dict):

for key in field_data:
if not isinstance(field_data[key], BaseModel):
continue
filter_event_recurs(field_data[key], visited)

else:

if isinstance(field_data, BaseModel):
filter_event_recurs(field_data, visited)

setattr(clone_event, field, field_data)

return clone_event


def send_event(event: Event) -> None:
event_type = get_event_type(event)
logging.info("sending event: %s - %s", event_type, event)
log_event(event, event_type)
event_message = EventMessage(
event_type=event_type,
event=event,
Expand Down
76 changes: 76 additions & 0 deletions src/api-service/tests/test_secret_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env python
#
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.


import unittest
from uuid import uuid4

from onefuzztypes.enums import ContainerType, TaskType
from onefuzztypes.events import EventTaskCreated, get_event_type
from onefuzztypes.models import (
TaskConfig,
TaskContainers,
TaskDetails,
TaskPool,
UserInfo,
)
from onefuzztypes.primitives import Container, PoolName

from __app__.onefuzzlib.events import filter_event


class TestSecretFilter(unittest.TestCase):
def test_secret_filter(self) -> None:
job_id = uuid4()
task_id = uuid4()
application_id = uuid4()
object_id = uuid4()
upn = "testalias@contoso.com"

user_info = UserInfo(
application_id=application_id, object_id=object_id, upn=upn
)

task_config = TaskConfig(
job_id=job_id,
containers=[
TaskContainers(
type=ContainerType.inputs, name=Container("test-container")
)
],
tags={},
task=TaskDetails(
type=TaskType.libfuzzer_fuzz,
duration=12,
target_exe="fuzz.exe",
target_env={},
target_options=[],
),
pool=TaskPool(count=2, pool_name=PoolName("test-pool")),
)

test_event = EventTaskCreated(
job_id=job_id,
task_id=task_id,
config=task_config,
user_info=user_info,
)

control_test_event = EventTaskCreated(
job_id=job_id,
task_id=task_id,
config=task_config,
user_info=None,
)

test_event_type = get_event_type(test_event)

scrubbed_test_event = filter_event(test_event, test_event_type)

self.assertEqual(scrubbed_test_event, control_test_event)


if __name__ == "__main__":
unittest.main()