From d1ced6b63f30a052e6f4f885958eda255d7d6826 Mon Sep 17 00:00:00 2001 From: Mesut Gungor Date: Thu, 9 Mar 2023 13:31:52 +0100 Subject: [PATCH 1/4] Enable using AWS services with ec2role --- aws-cloudwatch/1.0.0/api.yaml | 4 ++-- aws-cloudwatch/1.0.0/src/app.py | 18 ++++++++++++------ aws-dynamodb/1.0.0/api.yaml | 4 ++-- aws-dynamodb/1.0.0/src/app.py | 18 ++++++++++++------ aws-ec2/1.0.0/api.yaml | 4 ++-- aws-ec2/1.0.0/src/app.py | 18 ++++++++++++------ aws-guardduty/1.0.0/api.yaml | 4 ++-- aws-guardduty/1.0.0/src/app.py | 21 +++++++++++++-------- aws-iam/1.0.0/api.yaml | 4 ++-- aws-iam/1.0.0/src/app.py | 18 ++++++++++++------ aws-lambda/1.0.0/api.yaml | 4 ++-- aws-lambda/1.0.0/src/app.py | 20 +++++++++++++------- aws-s3/1.0.0/api.yaml | 4 ++-- aws-s3/1.0.0/src/app.py | 18 ++++++++++++------ 14 files changed, 100 insertions(+), 59 deletions(-) diff --git a/aws-cloudwatch/1.0.0/api.yaml b/aws-cloudwatch/1.0.0/api.yaml index 10dad9ce..50b082bf 100644 --- a/aws-cloudwatch/1.0.0/api.yaml +++ b/aws-cloudwatch/1.0.0/api.yaml @@ -15,13 +15,13 @@ authentication: - name: access_key description: The access key to use example: "*****" - required: true + required: false schema: type: string - name: secret_key description: The secret key to use example: "*****" - required: true + required: false schema: type: string - name: region diff --git a/aws-cloudwatch/1.0.0/src/app.py b/aws-cloudwatch/1.0.0/src/app.py index 9003a705..05fa7db6 100644 --- a/aws-cloudwatch/1.0.0/src/app.py +++ b/aws-cloudwatch/1.0.0/src/app.py @@ -49,12 +49,18 @@ def auth_cloudwatch(self, access_key, secret_key, region): }, ) - self.cloudwatch = boto3.client( - 'logs', - config = my_config, - aws_access_key_id = access_key, - aws_secret_access_key = secret_key, - ) + if access_key!="": + self.cloudwatch = boto3.resource( + 'logs', + config=my_config, + aws_access_key_id=access_key, + aws_secret_access_key=secret_key, + ) + else: + self.cloudwatch = boto3.resource( + 'logs', + config=my_config, + ) print(self.cloudwatch) return self.cloudwatch diff --git a/aws-dynamodb/1.0.0/api.yaml b/aws-dynamodb/1.0.0/api.yaml index 0806d26e..b0ccf061 100644 --- a/aws-dynamodb/1.0.0/api.yaml +++ b/aws-dynamodb/1.0.0/api.yaml @@ -17,13 +17,13 @@ authentication: - name: access_key description: The access key to use example: "*****" - required: true + required: false schema: type: string - name: secret_key description: The secret key to use example: "*****" - required: true + required: false schema: type: string - name: region diff --git a/aws-dynamodb/1.0.0/src/app.py b/aws-dynamodb/1.0.0/src/app.py index 538be935..bc1f3231 100644 --- a/aws-dynamodb/1.0.0/src/app.py +++ b/aws-dynamodb/1.0.0/src/app.py @@ -32,12 +32,18 @@ def auth_dynamodb(self, access_key, secret_key, region): }, ) - self.dynamodb = boto3.resource( - 'dynamodb', - config=my_config, - aws_access_key_id=access_key, - aws_secret_access_key=secret_key, - ) + if access_key!="": + self.dynamodb = boto3.resource( + 'dynamodb', + config=my_config, + aws_access_key_id=access_key, + aws_secret_access_key=secret_key, + ) + else: + self.dynamodb = boto3.resource( + 'dynamodb', + config=my_config, + ) return self.dynamodb diff --git a/aws-ec2/1.0.0/api.yaml b/aws-ec2/1.0.0/api.yaml index 8f84bbec..6918110b 100644 --- a/aws-ec2/1.0.0/api.yaml +++ b/aws-ec2/1.0.0/api.yaml @@ -17,13 +17,13 @@ authentication: - name: access_key description: The access key to use example: "*****" - required: true + required: false schema: type: string - name: secret_key description: The secret key to use example: "*****" - required: true + required: false schema: type: string - name: region diff --git a/aws-ec2/1.0.0/src/app.py b/aws-ec2/1.0.0/src/app.py index 938ad0fd..49dbe3cf 100644 --- a/aws-ec2/1.0.0/src/app.py +++ b/aws-ec2/1.0.0/src/app.py @@ -41,12 +41,18 @@ def auth_ec2(self, access_key, secret_key, region): }, ) - self.ec2 = boto3.resource( - 'ec2', - config = my_config, - aws_access_key_id = access_key, - aws_secret_access_key = secret_key, - ) + if access_key!="": + self.ec2 = boto3.resource( + 'ec2', + config=my_config, + aws_access_key_id=access_key, + aws_secret_access_key=secret_key, + ) + else: + self.ec2 = boto3.resource( + 'ec2', + config=my_config, + ) return self.ec2 diff --git a/aws-guardduty/1.0.0/api.yaml b/aws-guardduty/1.0.0/api.yaml index 4e2d784d..5cb09cf9 100644 --- a/aws-guardduty/1.0.0/api.yaml +++ b/aws-guardduty/1.0.0/api.yaml @@ -17,13 +17,13 @@ authentication: - name: access_key description: The access key to use example: "*****" - required: true + required: false schema: type: string - name: secret_key description: The secret key to use example: "*****" - required: true + required: false schema: type: string - name: region diff --git a/aws-guardduty/1.0.0/src/app.py b/aws-guardduty/1.0.0/src/app.py index fd90f85a..78d0e256 100644 --- a/aws-guardduty/1.0.0/src/app.py +++ b/aws-guardduty/1.0.0/src/app.py @@ -32,14 +32,19 @@ def auth_guardduty(self, access_key, secret_key, region): }, ) - return boto3.client( - 'guardduty', - config=my_config, - aws_access_key_id=access_key, - aws_secret_access_key=secret_key, - ) - - + if access_key!="": + return boto3.client( + 'guardduty', + config=my_config, + aws_access_key_id=access_key, + aws_secret_access_key=secret_key, + ) + else: + return boto3.client( + 'guardduty', + config=my_config, + ) + def create_detector(self, access_key, secret_key, region, enable): client = self.auth_guardduty(access_key, secret_key, region) try: diff --git a/aws-iam/1.0.0/api.yaml b/aws-iam/1.0.0/api.yaml index 5ffaf18e..26922422 100644 --- a/aws-iam/1.0.0/api.yaml +++ b/aws-iam/1.0.0/api.yaml @@ -16,13 +16,13 @@ authentication: - name: access_key description: The access key to use example: "*****" - required: true + required: false schema: type: string - name: secret_key description: The secret key to use example: "*****" - required: true + required: false schema: type: string - name: region diff --git a/aws-iam/1.0.0/src/app.py b/aws-iam/1.0.0/src/app.py index 1e341fb3..a464854f 100644 --- a/aws-iam/1.0.0/src/app.py +++ b/aws-iam/1.0.0/src/app.py @@ -41,12 +41,18 @@ def auth_iam(self, access_key, secret_key, region): }, ) - self.iam = boto3.resource( - 'iam', - config=my_config, - aws_access_key_id=access_key, - aws_secret_access_key=secret_key, - ) + if access_key!="": + self.iam = boto3.resource( + 'iam', + config=my_config, + aws_access_key_id=access_key, + aws_secret_access_key=secret_key, + ) + else: + self.iam = boto3.resource( + 'iam', + config=my_config, + ) return self.iam diff --git a/aws-lambda/1.0.0/api.yaml b/aws-lambda/1.0.0/api.yaml index 816f7dbe..4d2548bd 100644 --- a/aws-lambda/1.0.0/api.yaml +++ b/aws-lambda/1.0.0/api.yaml @@ -16,13 +16,13 @@ authentication: - name: access_key description: The access key to use example: "*****" - required: true + required: false schema: type: string - name: secret_key description: The secret key to use example: "*****" - required: true + required: false schema: type: string - name: region diff --git a/aws-lambda/1.0.0/src/app.py b/aws-lambda/1.0.0/src/app.py index 8395aa11..0d8b72e4 100644 --- a/aws-lambda/1.0.0/src/app.py +++ b/aws-lambda/1.0.0/src/app.py @@ -31,13 +31,19 @@ def auth_lambda(self, access_key, secret_key, region): 'mode': 'standard' }, ) - - return boto3.client( - 'lambda', - config=my_config, - aws_access_key_id=access_key, - aws_secret_access_key=secret_key, - ) + + if access_key!="": + return boto3.client( + 'lambda', + config=my_config, + aws_access_key_id=access_key, + aws_secret_access_key=secret_key, + ) + else: + return boto3.client( + 'lambda', + config=my_config, + ) def list_functions(self, access_key, secret_key, region): diff --git a/aws-s3/1.0.0/api.yaml b/aws-s3/1.0.0/api.yaml index a65de9c9..911dafb3 100644 --- a/aws-s3/1.0.0/api.yaml +++ b/aws-s3/1.0.0/api.yaml @@ -17,13 +17,13 @@ authentication: - name: access_key description: The access key to use example: "*****" - required: true + required: false schema: type: string - name: secret_key description: The secret key to use example: "*****" - required: true + required: false schema: type: string - name: region diff --git a/aws-s3/1.0.0/src/app.py b/aws-s3/1.0.0/src/app.py index d28854ec..0d4c7e79 100644 --- a/aws-s3/1.0.0/src/app.py +++ b/aws-s3/1.0.0/src/app.py @@ -32,12 +32,18 @@ def auth_s3(self, access_key, secret_key, region): }, ) - self.s3 = boto3.resource( - 's3', - config=my_config, - aws_access_key_id=access_key, - aws_secret_access_key=secret_key, - ) + if access_key!="": + self.s3 = boto3.resource( + 's3', + config=my_config, + aws_access_key_id=access_key, + aws_secret_access_key=secret_key, + ) + else: + self.s3 = boto3.resource( + 's3', + config=my_config, + ) return self.s3 From 117c8971c7aa5a4548cc4e2b40fb226470ceffa4 Mon Sep 17 00:00:00 2001 From: Mesut Gungor Date: Thu, 9 Mar 2023 13:48:54 +0100 Subject: [PATCH 2/4] Enable using AWS services with ec2role --- aws-securityhub/1.0.0/api.yaml | 4 ++-- aws-securityhub/1.0.0/src/app.py | 18 ++++++++++++------ aws-ses/1.0.0/api.yaml | 4 ++-- aws-ses/1.0.0/src/app.py | 18 ++++++++++++------ aws-waf/1.0.0/api.yaml | 4 ++-- aws-waf/1.0.0/src/app.py | 5 ++++- 6 files changed, 34 insertions(+), 19 deletions(-) diff --git a/aws-securityhub/1.0.0/api.yaml b/aws-securityhub/1.0.0/api.yaml index 01419fa2..22895d5d 100644 --- a/aws-securityhub/1.0.0/api.yaml +++ b/aws-securityhub/1.0.0/api.yaml @@ -17,13 +17,13 @@ authentication: - name: access_key description: The access key to use example: "*****" - required: true + required: false schema: type: string - name: secret_key description: The secret key to use example: "*****" - required: true + required: false schema: type: string - name: region diff --git a/aws-securityhub/1.0.0/src/app.py b/aws-securityhub/1.0.0/src/app.py index bd0a35c4..735a40c4 100644 --- a/aws-securityhub/1.0.0/src/app.py +++ b/aws-securityhub/1.0.0/src/app.py @@ -32,12 +32,18 @@ def auth(self, access_key, secret_key, region): }, ) - return boto3.client( - 'securityhub', - config=my_config, - aws_access_key_id=access_key, - aws_secret_access_key=secret_key, - ) + if access_key!="": + return boto3.client( + 'securityhub', + config=my_config, + aws_access_key_id=access_key, + aws_secret_access_key=secret_key, + ) + else: + return boto3.client( + 'securityhub', + config=my_config, + ) # Write your data inside this function def enable_security_hub(self, access_key, secret_key, region): diff --git a/aws-ses/1.0.0/api.yaml b/aws-ses/1.0.0/api.yaml index cbfe7fcb..1f3cbded 100644 --- a/aws-ses/1.0.0/api.yaml +++ b/aws-ses/1.0.0/api.yaml @@ -15,13 +15,13 @@ authentication: - name: access_key description: The access key to use example: "*****" - required: true + required: false schema: type: string - name: secret_key description: The secret key to use example: "*****" - required: true + required: false schema: type: string - name: region diff --git a/aws-ses/1.0.0/src/app.py b/aws-ses/1.0.0/src/app.py index 6fd1dbd5..fa5da465 100644 --- a/aws-ses/1.0.0/src/app.py +++ b/aws-ses/1.0.0/src/app.py @@ -32,12 +32,18 @@ def auth_ses(self, access_key, secret_key, region): }, ) - self.ses = boto3.client( - 'ses', - config = my_config, - aws_access_key_id = access_key, - aws_secret_access_key = secret_key, - ) + if access_key!="": + self.dynamodb = boto3.resource( + 'ses', + config=my_config, + aws_access_key_id=access_key, + aws_secret_access_key=secret_key, + ) + else: + self.dynamodb = boto3.resource( + 'ses', + config=my_config, + ) return self.ses diff --git a/aws-waf/1.0.0/api.yaml b/aws-waf/1.0.0/api.yaml index 12c93316..16564d35 100644 --- a/aws-waf/1.0.0/api.yaml +++ b/aws-waf/1.0.0/api.yaml @@ -15,13 +15,13 @@ authentication: - name: access_key description: The access key to use example: "*****" - required: true + required: false schema: type: string - name: secret_key description: The secret key to use example: "*****" - required: true + required: false schema: type: string - name: region diff --git a/aws-waf/1.0.0/src/app.py b/aws-waf/1.0.0/src/app.py index fcaeb0bc..e8095e85 100644 --- a/aws-waf/1.0.0/src/app.py +++ b/aws-waf/1.0.0/src/app.py @@ -32,8 +32,11 @@ def auth(self, access_key, secret_key, region): 'mode': 'standard' }, ) + if access_key!="": + return boto3.client('wafv2', config=my_config, aws_access_key_id=access_key, aws_secret_access_key=secret_key) + else: + return boto3.client('wafv2', config=my_config) - return boto3.client('wafv2', config=my_config, aws_access_key_id=access_key, aws_secret_access_key=secret_key) # Write your data inside this function def block_ip_waf(self, access_key, secret_key, region, ipset_name, ip): From 291a859e4b01bfca104aa06f39978597522ec16b Mon Sep 17 00:00:00 2001 From: Mesut Gungor Date: Wed, 15 Mar 2023 13:20:37 +0100 Subject: [PATCH 3/4] get nacls added --- aws-ec2/1.0.0/api.yaml | 8 ++++++++ aws-ec2/1.0.0/src/app.py | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/aws-ec2/1.0.0/api.yaml b/aws-ec2/1.0.0/api.yaml index 6918110b..980d17b7 100644 --- a/aws-ec2/1.0.0/api.yaml +++ b/aws-ec2/1.0.0/api.yaml @@ -63,6 +63,14 @@ actions: returns: schema: type: string + + - name: get_nacls + description: Gets the rules for an ACLs + returns: + schema: + type: string + + - name: get_rules description: Gets the rules for an ACL ID parameters: diff --git a/aws-ec2/1.0.0/src/app.py b/aws-ec2/1.0.0/src/app.py index 49dbe3cf..dba83013 100644 --- a/aws-ec2/1.0.0/src/app.py +++ b/aws-ec2/1.0.0/src/app.py @@ -62,6 +62,12 @@ def get_rules(self, access_key, secret_key, region, NetworkAclId): network_acl = self.ec2.NetworkAcl(NetworkAclId) return network_acl.entries + # Write your data inside this function + def get_nacls(self, access_key, secret_key, region): + self.ec2 = self.auth_ec2(access_key, secret_key, region) + + network_acls = self.ec2.NetworkAcl() + return network_acls.Associations # Write your data inside this function def block_ip(self, access_key, secret_key, region, NetworkAclId, ip, direction): From 9e3a925cef27e8db94b69075766725f7aff887e0 Mon Sep 17 00:00:00 2001 From: Mesut Gungor Date: Tue, 21 Mar 2023 16:19:03 +0100 Subject: [PATCH 4/4] reverted ec2 --- aws-ec2/1.0.0/api.yaml | 7 ------- aws-ec2/1.0.0/src/app.py | 6 ------ 2 files changed, 13 deletions(-) diff --git a/aws-ec2/1.0.0/api.yaml b/aws-ec2/1.0.0/api.yaml index 980d17b7..b9362124 100644 --- a/aws-ec2/1.0.0/api.yaml +++ b/aws-ec2/1.0.0/api.yaml @@ -64,13 +64,6 @@ actions: schema: type: string - - name: get_nacls - description: Gets the rules for an ACLs - returns: - schema: - type: string - - - name: get_rules description: Gets the rules for an ACL ID parameters: diff --git a/aws-ec2/1.0.0/src/app.py b/aws-ec2/1.0.0/src/app.py index dba83013..49dbe3cf 100644 --- a/aws-ec2/1.0.0/src/app.py +++ b/aws-ec2/1.0.0/src/app.py @@ -62,12 +62,6 @@ def get_rules(self, access_key, secret_key, region, NetworkAclId): network_acl = self.ec2.NetworkAcl(NetworkAclId) return network_acl.entries - # Write your data inside this function - def get_nacls(self, access_key, secret_key, region): - self.ec2 = self.auth_ec2(access_key, secret_key, region) - - network_acls = self.ec2.NetworkAcl() - return network_acls.Associations # Write your data inside this function def block_ip(self, access_key, secret_key, region, NetworkAclId, ip, direction):