# Copyright 2018 Capital One Services, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from c7n.manager import resources
from c7n.filters import iamaccess
from c7n.query import QueryResourceManager
from c7n.tags import RemoveTag, Tag, TagActionFilter, TagDelayedAction
from c7n.utils import local_session
[docs]@resources.register('secrets-manager')
class SecretsManager(QueryResourceManager):
permissions = ('secretsmanager:ListSecretVersionIds',)
[docs] class resource_type(object):
service = 'secretsmanager'
enum_spec = ('list_secrets', 'SecretList', None)
detail_spec = ('describe_secret', 'SecretId', 'ARN', None)
arn = id = 'ARN'
name = 'Name'
dimension = None
filter_name = None
SecretsManager.filter_registry.register('marked-for-op', TagActionFilter)
[docs]@SecretsManager.filter_registry.register('cross-account')
class CrossAccountAccessFilter(iamaccess.CrossAccountAccessFilter):
policy_annotation = "c7n:AccessPolicy"
permissions = ("secretsmanager:GetResourcePolicy",)
[docs] def process(self, resources, event=None):
self.client = local_session(self.manager.session_factory).client('secretsmanager')
return super(CrossAccountAccessFilter, self).process(resources)
[docs] def get_resource_policy(self, r):
if self.policy_annotation in r:
return r[self.policy_annotation]
r[self.policy_annotation] = p = self.client.get_resource_policy(
SecretId=r['Name']).get('ResourcePolicy', None)
return p
[docs]@SecretsManager.action_registry.register('mark-for-op')
class MarkSecretForOp(TagDelayedAction):
"""Action to mark a Secret resource for deferred action :example:
.. code-block:: yaml
policies:
- name: mark-secret-for-delete
resource: secrets-manager
actions:
- type: mark-for-op
op: tag
days: 1
"""