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

wip - aws.ecr - log warning on access denied instead of raising #3618

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 20 additions & 1 deletion c7n/resources/ecr.py
Expand Up @@ -16,7 +16,7 @@
import json

from c7n.actions import RemovePolicyBase, Action
from c7n.exceptions import PolicyValidationError
from c7n.exceptions import PolicyValidationError, ClientError
from c7n.filters import CrossAccountAccessFilter, Filter, ValueFilter
from c7n.manager import resources
from c7n.query import QueryResourceManager
Expand Down Expand Up @@ -104,11 +104,18 @@ def process(self, resources, event=None):
client = local_session(self.manager.session_factory).client('ecr')

def _augment(r):
if 'Policy' in r:
return r
try:
r['Policy'] = client.get_repository_policy(
repositoryName=r['repositoryName'])['policyText']
except client.exceptions.RepositoryPolicyNotFoundException:
return None
except ClientError as e:
if e.response['Error']['Code'] == 'AccessDeniedException':
self.log.warning('Access Denied on GetRepositoryPolicy for repository: %s' %
r['repositoryName'])
return None
return r

self.log.debug("fetching policy for %d repos" % len(resources))
Expand Down Expand Up @@ -212,6 +219,11 @@ def process(self, resources, event=None):
'lifecyclePolicyText', ''))
except client.exceptions.LifecyclePolicyNotFoundException:
r[self.policy_annotation] = {}
except ClientError as e:
if e.response['Error']['Code'] == 'AccessDeniedException':
self.log.warning('Access Denied on GetLifecyclePolicy for repository: %s' %
r['repositoryName'])
r[self.policy_annotation] = {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some changes got pushed to this that now unconditionally and without logging swallow all other exceptions ...


state = self.data.get('state', False)
matchers = []
Expand Down Expand Up @@ -319,6 +331,13 @@ def process_resource(self, client, resource):
repositoryName=resource['repositoryName'])['policyText']
except client.exceptions.RepositoryPolicyNotFoundException:
return
except ClientError as e:
if e.response['Error']['Code'] == 'AccessDeniedException':
self.log.warning('Access Denied on GetRepositoryPolicy for repository: %s' %
resource['repositoryName'])
return None
else:
raise

p = json.loads(resource['Policy'])
statements, found = self.process_policy(
Expand Down