-
Notifications
You must be signed in to change notification settings - Fork 48
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
PXP-7805 Push audit logs to an AWS SQS #923
Conversation
10e3759
to
cd0a2e9
Compare
The style in this PR agrees with This formatting comment was generated automatically by a script in uc-cdis/wool. |
Pull Request Test Coverage Report for Build 11210
💛 - Coveralls |
# `region` are required. Fields `aws_access_key_id` and | ||
# `aws_secret_access_key` are optional. | ||
PUSH_AUDIT_LOGS_CONFIG: | ||
type: aws_sqs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defaulting to this means that existing deployments with ENABLE_AUDIT_LOGS on will now error until they flip this to api
, right? We may want to note that in DEPLOYMENT CHANGES
. I know you note something about enabling them, but may want to explicitly mentioned that even for deployments that DON'T want this, they have to update the cfg (unless you change this default)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
fence/blueprints/data/indexd.py
Outdated
resource_paths = indexed_file.index_document.get("authz", []) | ||
if not resource_paths: | ||
# fall back on ACL | ||
resource_paths = indexed_file.index_document.get("acl", []) | ||
if not protocol and indexed_file.indexed_file_locations: | ||
if not protocol and len(indexed_file.indexed_file_locations) > 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't the truthy check above already handle this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which check? if the indexd record urls
field is empty, we need to check this here - we record no protocol, and then the presigned URL generation function errors 'there are no locations'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, I meant the previous code. like why are we switching from indexed_file.indexed_file_locations
to len(indexed_file.indexed_file_locations) > 0
. For situations where urls are empty the previous code should have been False
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
woops, yeah i'm not sure what happened there 😆
fence/__init__.py
Outdated
return request_url | ||
|
||
|
||
@app.after_request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this called after every request? 😬 I'm a little nervous of the overhead of this. I like the idea of consolidating and making it cleaner, but could we isolate this cleaning logic to only functions where we know we're capturing audit logs?
Maybe make a custom decorator and only decorate functions we know we want to audit log? Also only do the decorator logic if audit logs are enabled.
I also want to make sure that if someone doesn't want ANY logging, it shouldn't impact performance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, i'll look into that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like this conditional decorator based on if audit logs are enabled. And then this function basically becomes a decorator only used when it's enabled and only on functions where we know we want to audit log.
""" | ||
Attempt to parse the request for token to authenticate the user. fallback to | ||
populated information about an anonymous user. | ||
By default, cast `sub` to str. Use `sub_type` to override this behavior. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just always cast to string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't look too much into it, but authutils.current_token["sub"]
is a string and flask.g.user.id
is an int 🤔
I'm casting authutils.current_token["sub"]
to int here because audit-service expects an int, to match the type of sub
in the fence DB.
raise InternalError("Unable to create audit log") | ||
|
||
def create_audit_log(self, category, data): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have another function called create_audit_log
in a different module. Probably fine but might be confusing. Pending if/how we do the decorator/performance improvements
@@ -479,6 +479,8 @@ AUDIT_SERVICE: 'http://audit-service' | |||
ENABLE_AUDIT_LOGS: | |||
presigned_url: false | |||
login: false | |||
PUSH_AUDIT_LOGS_CONFIG: | |||
type: api |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should also write some tests that monkey patch this and add others for aws_sqs
and mock out the AWS call for better coverage of the new feature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah the current tests are testing "type: api", so the audit_service_client module without the SQS part. Tbh I wasn't sure how to test it since everything would be mocked. But i'll spend some more time on that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well just the boto call out to sqs would need to be mocked, you could check that it actually gets called with expected data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, I see you added some 🎊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments. tl;dr I think we should isolate this more to reduce potential impact to performance
fence/resources/audit/client.py
Outdated
) | ||
|
||
def ping(self): | ||
max_tries = 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you use backoff lib for this to remain consistent? we're using it elsewhere
fence/fence/resources/openid/ras_oauth2.py
Line 118 in b85118f
@backoff.on_exception(backoff.expo, Exception, **DEFAULT_BACKOFF_SETTINGS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can override the exception/handling of default if you need to
fence/resources/audit/client.py
Outdated
self.ping() | ||
self.validate_config() | ||
else: | ||
logger.warn("NOT enabling audit logs") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.warn
is deprecated I believe. you should use .warning
fence/resources/audit/client.py
Outdated
f"Audit logs are enabled but audit-service is unreachable at {status_url}: {r.text}" | ||
) | ||
|
||
def validate_config(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't hate me. I'm tempted to ask if we get some docstrings for all these public functions. Granted I think most are self explanatory. But for consistency, eh 🤷
Jira Ticket: PXP-7805
goes with uc-cdis/audit-service#2 and uc-cdis/cloud-automation#1603
New Features
Improvements
Deployment changes
gen3 sqs info $(gen3 api safe-name audit-sqs)
), seefence/fence/config-default.yaml
Lines 632 to 636 in fec3dd9
kubectl delete secret fence-config
andgen3 kube-setup-fence