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

[apps] Aliyun ActionTrail app #792

Merged
merged 8 commits into from Jul 27, 2018

Conversation

@GarretReece
Copy link
Contributor

@GarretReece GarretReece commented Jul 25, 2018

to: @airbnb/streamalert-maintainers
cc:
size: medium

Background

SteamAlert doesn't have an app that collects ActionTrail events from Aliyun

Changes

  • Adds an app that collects ActionTrail events from Aliyun
  • Schema definition for the new log type is included
  • Unit tests for the app as well as schema validation tests are included
  • Documentation for authorizing the app is included in the README in the apps directory as well as in a section of the app-configuration.rst in the docs directory

Testing

Barebones StreamAlert session created, the Aliyun app configured and deployed, and verifying that events are listed as captured in the log

@coveralls
Copy link

@coveralls coveralls commented Jul 25, 2018

Coverage Status

Coverage increased (+0.03%) to 97.418% when pulling 32a1757 on trailofbits:garret/actiontrail_app into fae89fb on airbnb:master.

Copy link
Contributor

@ryandeivert ryandeivert left a comment

this is nice work!! added a few quick first round comments :)


from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException

This comment has been minimized.

@ryandeivert

ryandeivert Jul 25, 2018
Contributor

can you group this exception with the import above pls


from app_integrations import LOGGER
from app_integrations.apps.app_base import StreamAlertApp, AppIntegration

This comment has been minimized.

@ryandeivert

ryandeivert Jul 25, 2018
Contributor

add an extra new line here please (2 lines between imports and class declarations)


def _gather_logs(self):
auth = self._config.auth
client = AcsClient(auth['access_key_id'], auth['access_key_secret'], auth['region_id'])

This comment has been minimized.

@ryandeivert

ryandeivert Jul 25, 2018
Contributor

the _gather_logs method could be called a bunch of times in an execution - therefore, would it make sense to have the AcsClient created upon __init__ and cached as an instance property?


return json_response['Events']

except ServerException as e:

This comment has been minimized.

@ryandeivert

ryandeivert Jul 25, 2018
Contributor

These two except blocks could be consolidated into one with:

except (ServerException, ClientException) as err:
    LOGGER.exception("%s exception occurred", err.get_error_type())
    return False

also, there's no need to include the actual content of the exception (with str(e)) when using LOGGER.exception - this call handles all of that for you.

def region_validator(region):
"""Region names pulled from https://www.alibabacloud.com/help/doc-detail/40654.htm"""

if region in ["cn-qingdao", "cn-beijing", "cn-zhangjiakou", "cn-huhehaote",

This comment has been minimized.

@ryandeivert

ryandeivert Jul 25, 2018
Contributor

please use single (') quotes on string literals and not double (") quotes

This comment has been minimized.

@chunyong-lin

chunyong-lin Jul 25, 2018
Contributor

Small request, can we use set instead of list, it is not big a deal though.

'access_key_id': {
'description': ('The access key id generated for a RAM user. This '
'should be a string of alphanumeric characters.'),
'format': re.compile(r'.*')

This comment has been minimized.

@ryandeivert

ryandeivert Jul 25, 2018
Contributor

are there no restrictions similar to AWS for their access and secret keys? ie - AWS access keys are 20 alphanumeric all-caps characters and must start with A, etc

This comment has been minimized.

@GarretReece

GarretReece Jul 26, 2018
Author Contributor

I can't find any documentation anywhere regarding the format. The values I have are a mix of digits and upper and lower case letters, with the id 16 characters in length and the secret 30 characters in length. I'm perfectly willing to put those in as restrictions, but I don't have any reference for that being the supported format.

'region_id': {
'description': ('The region for the Aliyun API. This should be '
'a string like \'ap-northeast-1\'.'),
'format': region_validator

This comment has been minimized.

@ryandeivert

ryandeivert Jul 25, 2018
Contributor

++ this is great

Returns:
int: Number of seconds the polling function should sleep for
"""
return 0

This comment has been minimized.

@ryandeivert

ryandeivert Jul 25, 2018
Contributor

I think if this is 0 it can be left off completely. I do like the context you've added in the docstring, though, so I'm not sure if I feel strongly about removing the method

@@ -203,6 +203,8 @@ class AppIntegrationPackage(LambdaPackage):
package_name = 'stream_alert_app'
precompiled_libs = {'boxsdk[jwt]==2.0.0a11'}
third_party_libs = {
'aliyun-python-sdk-core==2.8.5',

This comment has been minimized.

@ryandeivert

ryandeivert Jul 25, 2018
Contributor

this is great - thank you for pinning the version!

def service(cls):
return 'aliyun'


This comment has been minimized.

@ryandeivert

ryandeivert Jul 25, 2018
Contributor

Looks like there's an extra new line here

Copy link
Contributor

@chunyong-lin chunyong-lin left a comment

Hey @GarretReece thanks for working on this App. It looks great too me. I added some comments.

https://www.alibabacloud.com/help/doc-detail/28849.htm
"""

_MAX_RESULTS = 50

This comment has been minimized.

@chunyong-lin

chunyong-lin Jul 25, 2018
Contributor

Any reason we don't pull 100 results each time?

This comment has been minimized.

@GarretReece

GarretReece Jul 26, 2018
Author Contributor

The documentation lists the range for the MaxResult parameter as 0-50; I'll admit I haven't tested with higher values to see if it worked anyhow.

This comment has been minimized.

@chunyong-lin

chunyong-lin Jul 26, 2018
Contributor

Can I have one more testing request? Can you add a test case when NextToken is available in your testing environment? (I am not talking about unit test)

A while ago, I have a simple script to retrieve ActionTrail events, and set max results per request to 2. I encountered the issue that NextToken doesn't take effect, and the 2nd request returned as same events as 1st request recieved.
Can you verify this in the testing environment? Thanks!


@classmethod
def _type(cls):
return 'events'

This comment has been minimized.

@chunyong-lin

chunyong-lin Jul 25, 2018
Contributor

actiontrail would be more descriptive.

@@ -1,3 +1,5 @@
aliyun-python-sdk-core==2.8.5
aliyun-python-sdk-actiontrail==2.0.0

This comment has been minimized.

@chunyong-lin

chunyong-lin Jul 25, 2018
Contributor

Can you add these two packages to requirements-top-level.txt as well?

This comment has been minimized.

@GarretReece

GarretReece Jul 26, 2018
Author Contributor

added them in!

def region_validator(region):
"""Region names pulled from https://www.alibabacloud.com/help/doc-detail/40654.htm"""

if region in ["cn-qingdao", "cn-beijing", "cn-zhangjiakou", "cn-huhehaote",

This comment has been minimized.

@chunyong-lin

chunyong-lin Jul 25, 2018
Contributor

Small request, can we use set instead of list, it is not big a deal though.

auth = self._config.auth
client = AcsClient(auth['access_key_id'], auth['access_key_secret'], auth['region_id'])

request = LookupEventsRequest.LookupEventsRequest()

This comment has been minimized.

@chunyong-lin

chunyong-lin Jul 25, 2018
Contributor

I think we also can cache request to __init__.

@@ -1666,5 +1666,40 @@
"reason"
]
}
},
"aliyun:events": {

This comment has been minimized.

@chunyong-lin

chunyong-lin Jul 25, 2018
Contributor

Remind to update schema name if you agree with me renaming _type to actiontrail.

Copy link
Contributor

@chunyong-lin chunyong-lin left a comment

LGTM! 🎉

@chunyong-lin chunyong-lin merged commit 18735de into airbnb:master Jul 27, 2018
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.03%) to 97.418%
Details
@dguido dguido deleted the trailofbits:garret/actiontrail_app branch Jul 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.