Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send select logs to Panther #442

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion confidant/authnz/userauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from confidant.lib import cryptolib
from confidant.utils.misc import dict_deep_update
from confidant.authnz import errors
from confidant.services.panther import panther_client

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -586,7 +587,11 @@ def consume_saml_assertion(self):

attributes = auth.get_attributes()
logger.info('SAML attributes: {!r}'.format(attributes))

panther_client.send_event({
Copy link
Author

@masoudv-lyft masoudv-lyft Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fail open calls to Panther can be found in the lyft_lumos_common library

'event_type': 'saml_user_authenticated',
'id': nameid,
'attributes': attributes,
})
# normalize attributes by flattening single-item arrays
for key, val in attributes.items():
if isinstance(val, list) and len(val) == 1:
Expand Down
10 changes: 10 additions & 0 deletions confidant/routes/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from confidant.services.ciphermanager import CipherManager
from confidant.utils import maintenance, misc, stats
from confidant.utils.dynamodb import decode_last_evaluated_key
from confidant.services.panther import panther_client

logger = logging.getLogger(__name__)
blueprint = blueprints.Blueprint('credentials', __name__)
Expand Down Expand Up @@ -255,6 +256,11 @@ def get_credential(id):
id
)
logger.info(log_line)
panther_client.send_event({
'event_type': 'get_credential',
'user': authnz.get_logged_in_user(),
'credential': id,
})

credential_response = CredentialResponse.from_credential(
credential,
Expand Down Expand Up @@ -363,6 +369,10 @@ def diff_credential(id, old_revision, new_revision):
logger.warning(
'Item with id {0} does not exist.'.format(id)
)
panther_client.send_event({
'event_type': 'get_credential',
'credential': id,
})
return jsonify({}), 404
if new_credential.data_type != 'archive-credential':
msg = 'id provided is not a credential.'
Expand Down
6 changes: 6 additions & 0 deletions confidant/routes/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
)
from confidant.utils import maintenance, misc, stats
from confidant.utils.dynamodb import decode_last_evaluated_key
from confidant.services.panther import panther_client

logger = logging.getLogger(__name__)
blueprint = blueprints.Blueprint('services', __name__)
Expand Down Expand Up @@ -272,6 +273,11 @@ def get_service(id):
f'get_service called on id={id} by '
f'user={logged_in_user} metadata_only={metadata_only}'
)
panther_client.send_event({
'event_type': 'get_service_called',
'user': logged_in_user,
'metadata_only': metadata_only,
})

with stats.timer('get_service_by_id.db_get_service'):
try:
Expand Down
13 changes: 13 additions & 0 deletions confidant/services/panther.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from lyft_lumos_common.services.panther import PantherClient

from confidant.settings import PANTHER_BASE_URL
from confidant.settings import PANTHER_BEARER_TOKEN


def get_panther_client() -> PantherClient:
return PantherClient(
bearer_token=PANTHER_BEARER_TOKEN,
base_url=PANTHER_BASE_URL)


panther_client = get_panther_client()
4 changes: 4 additions & 0 deletions confidant/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,3 +743,7 @@ def get(name, default=None):

# Module that will perform an external ACL check on API endpoints
ACL_MODULE = str_env('ACL_MODULE', 'confidant.authnz.rbac:default_acl')

# Panther settings
PANTHER_BASE_URL = str_env('CREDENTIALS_PANTHER_BASE_URL')
PANTHER_BEARER_TOKEN = str_env('CREDENTIALS_PANTHER_BEARER_TOKEN')
3 changes: 3 additions & 0 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,6 @@ mypy
# Upstream url: https://pypi.org/project/fakeredis/
# Use: To mock redis in unit tests
fakeredis

# For persisting to Panther
lyft-lumos-common==0.1.4
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,5 @@ setuptools==68.0.0
# -r piptools_requirements.txt
# zope-event
# zope-interface
lyft-lumos-common==0.1.4
# via -r requirements.in
Loading