Skip to content

Commit acf7bda

Browse files
authored
Merge pull request #1522 from saez0pub/fix/gcp_audit
Fix(gcp): update cloudsql api and edge case configurations
2 parents d6cf479 + b1d9602 commit acf7bda

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

ScoutSuite/providers/gcp/facade/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ async def is_api_enabled(self, project_id, service):
210210
elif service == 'CloudStorage':
211211
endpoint = 'storage-component'
212212
elif service == 'CloudSQL':
213-
endpoint = 'sql-component'
213+
endpoint = 'sqladmin'
214214
elif service == 'ComputeEngine':
215215
endpoint = 'compute'
216216
elif service == 'Functions':

ScoutSuite/providers/gcp/facade/gke.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ async def get_clusters(self, project_id):
2727
async def _get_and_set_private_google_access_enabled(self, cluster, project_id):
2828
try:
2929
region = self._get_cluster_region(cluster)
30-
subnetwork = await self._gce_facade.get_subnetwork(project_id, region, cluster['subnetwork'])
30+
subnetwork_project_id = self._get_cluster_subnetwork_project(cluster)
31+
subnetwork = await self._gce_facade.get_subnetwork(subnetwork_project_id, region, cluster['subnetwork'])
3132
if subnetwork:
3233
cluster['privateIpGoogleAccess'] = subnetwork.get('privateIpGoogleAccess')
3334
else:
@@ -42,3 +43,8 @@ def _get_cluster_region(self, cluster):
4243
region_regex = re.compile("^([\\w]+-[\\w]+)")
4344
result = region_regex.search(cluster['location'])
4445
return result.group(1)
46+
47+
# Subnetwork can be in different project
48+
# networkConfig.subnetwork is like projects/{project}/regions/{region}/subnetworks/{subnetworkname}
49+
def _get_cluster_subnetwork_project(self, cluster):
50+
return cluster['networkConfig']['subnetwork'].split('/')[1]

ScoutSuite/providers/gcp/resources/functions/functions_v1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ def _parse_function(self, raw_function):
3131
function_dict['max_instances'] = raw_function['maxInstances']
3232
function_dict['docker_registry'] = raw_function['dockerRegistry']
3333
function_dict['url'] = raw_function.get('httpsTrigger', {}).get('url')
34-
function_dict['security_level'] = raw_function.get('httpsTrigger', {}).get('securityLevel')
34+
function_dict['security_level'] = 'SECURE_ALWAYS' if function_dict['url'] is None else raw_function.get('httpsTrigger', {}).get('securityLevel')
3535
function_dict['ingress_settings'] = raw_function['ingressSettings']
3636

3737
function_dict['bindings'] = raw_function['bindings']
3838

39-
function_dict['environment_variables'] = raw_function['environmentVariables']
39+
function_dict['environment_variables'] = raw_function.get('environmentVariables', {})
4040
function_dict['environment_variables_secrets'] = get_environment_secrets(function_dict['environment_variables'])
4141

4242
function_dict['labels'] = raw_function['labels']

ScoutSuite/providers/gcp/resources/functions/functions_v2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def _parse_function(self, raw_function):
3535
function_dict['service_account'] = raw_function.get('serviceConfig', {}).get('serviceAccountEmail')
3636
function_dict['bindings'] = raw_function['bindings']
3737

38-
function_dict['environment_variables'] = raw_function.get('serviceConfig', {}).get('environmentVariables')
38+
function_dict['environment_variables'] = raw_function.get('serviceConfig', {}).get('environmentVariables', {})
3939
function_dict['environment_variables_secrets'] = get_environment_secrets(function_dict['environment_variables'])
4040

4141
function_dict['labels'] = raw_function['labels']

0 commit comments

Comments
 (0)