Skip to content

Commit

Permalink
Merge pull request #1522 from saez0pub/fix/gcp_audit
Browse files Browse the repository at this point in the history
Fix(gcp): update cloudsql api and edge case configurations
  • Loading branch information
liyun-li authored Jun 5, 2023
2 parents d6cf479 + b1d9602 commit acf7bda
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ScoutSuite/providers/gcp/facade/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ async def is_api_enabled(self, project_id, service):
elif service == 'CloudStorage':
endpoint = 'storage-component'
elif service == 'CloudSQL':
endpoint = 'sql-component'
endpoint = 'sqladmin'
elif service == 'ComputeEngine':
endpoint = 'compute'
elif service == 'Functions':
Expand Down
8 changes: 7 additions & 1 deletion ScoutSuite/providers/gcp/facade/gke.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ async def get_clusters(self, project_id):
async def _get_and_set_private_google_access_enabled(self, cluster, project_id):
try:
region = self._get_cluster_region(cluster)
subnetwork = await self._gce_facade.get_subnetwork(project_id, region, cluster['subnetwork'])
subnetwork_project_id = self._get_cluster_subnetwork_project(cluster)
subnetwork = await self._gce_facade.get_subnetwork(subnetwork_project_id, region, cluster['subnetwork'])
if subnetwork:
cluster['privateIpGoogleAccess'] = subnetwork.get('privateIpGoogleAccess')
else:
Expand All @@ -42,3 +43,8 @@ def _get_cluster_region(self, cluster):
region_regex = re.compile("^([\\w]+-[\\w]+)")
result = region_regex.search(cluster['location'])
return result.group(1)

# Subnetwork can be in different project
# networkConfig.subnetwork is like projects/{project}/regions/{region}/subnetworks/{subnetworkname}
def _get_cluster_subnetwork_project(self, cluster):
return cluster['networkConfig']['subnetwork'].split('/')[1]
4 changes: 2 additions & 2 deletions ScoutSuite/providers/gcp/resources/functions/functions_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ def _parse_function(self, raw_function):
function_dict['max_instances'] = raw_function['maxInstances']
function_dict['docker_registry'] = raw_function['dockerRegistry']
function_dict['url'] = raw_function.get('httpsTrigger', {}).get('url')
function_dict['security_level'] = raw_function.get('httpsTrigger', {}).get('securityLevel')
function_dict['security_level'] = 'SECURE_ALWAYS' if function_dict['url'] is None else raw_function.get('httpsTrigger', {}).get('securityLevel')
function_dict['ingress_settings'] = raw_function['ingressSettings']

function_dict['bindings'] = raw_function['bindings']

function_dict['environment_variables'] = raw_function['environmentVariables']
function_dict['environment_variables'] = raw_function.get('environmentVariables', {})
function_dict['environment_variables_secrets'] = get_environment_secrets(function_dict['environment_variables'])

function_dict['labels'] = raw_function['labels']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def _parse_function(self, raw_function):
function_dict['service_account'] = raw_function.get('serviceConfig', {}).get('serviceAccountEmail')
function_dict['bindings'] = raw_function['bindings']

function_dict['environment_variables'] = raw_function.get('serviceConfig', {}).get('environmentVariables')
function_dict['environment_variables'] = raw_function.get('serviceConfig', {}).get('environmentVariables', {})
function_dict['environment_variables_secrets'] = get_environment_secrets(function_dict['environment_variables'])

function_dict['labels'] = raw_function['labels']
Expand Down

0 comments on commit acf7bda

Please sign in to comment.