AWSTemplateFormatVersion: "2010-09-09" Description: > SpikeCatcher member account IAM role. Deploy this in each AWS member account (via StackSet from your payer account) to allow SpikeCatcher to scan resources for cost optimization recommendations. # Security notes: read-only, explicit allow-list (no wildcards, no ReadOnlyAccess), trusts only the payer account's # SpikeCatcherReadOnlyRole by ARN. Cannot read S3 objects, secrets, log contents or database contents, and cannot # change anything. This template forwards no events. See the install template for the full data-scope statement and # https://spikecatcher.com/security Parameters: PayerAccountId: Type: String Description: Your AWS payer account ID (where the SpikeCatcherReadOnlyRole is deployed). RoleName: Type: String Default: "SpikeCatcherReadOnlyRole" Description: Must match the role name used in your payer account. EnableLambdaChecks: Type: String Default: 'false' AllowedValues: ['false', 'true'] Description: > Optional. Set to 'true' to let SpikeCatcher list Lambda functions in this account for arm64 and Compute Optimizer recommendations. AWS has no Lambda list permission that hides environment variables, so enabling this lets SpikeCatcher read them. Leave 'false' unless you want those recommendations. Conditions: LambdaChecksEnabled: !Equals [!Ref EnableLambdaChecks, 'true'] Resources: SpikeCatcherMemberRole: Type: AWS::IAM::Role Properties: RoleName: !Ref RoleName AssumeRolePolicyDocument: Version: "2012-10-17" Statement: - Effect: Allow Principal: AWS: !Sub "arn:aws:iam::${PayerAccountId}:role/${RoleName}" Action: sts:AssumeRole Tags: - Key: spikecatcher:template-version Value: '66' # Explicit allow-list (no broader than the payer role) instead of the AWS-managed ReadOnlyAccess # policy, which also grants s3:GetObject, ssm:Get* and lambda:Get* (object contents, parameters, environment # variables). Nothing here reads object contents, secret values, parameters or Lambda configuration. Policies: - PolicyName: SpikeCatcherMemberReadOnly PolicyDocument: Version: '2012-10-17' Statement: # Billing and usage data (Cost Explorer). Core of anomaly detection. Explicit actions only. - Sid: CostExplorerRead Effect: Allow Action: - ce:GetCostAndUsage - ce:GetCostAndUsageWithResources - ce:GetCostForecast - ce:GetDimensionValues - ce:GetReservationUtilization - ce:GetReservationPurchaseRecommendation - ce:GetRightsizingRecommendation - ce:GetSavingsPlansPurchaseRecommendation - ce:GetSavingsPlansUtilization - ce:GetTags - ce:ListCostAllocationTags Resource: '*' # Savings Plan and Reserved Instance coverage and utilization, to find unused commitments. - Sid: CommitmentsRead Effect: Allow Action: - ce:GetSavingsPlansCoverage - ce:GetReservationCoverage - ce:GetSavingsPlansUtilizationDetails - ce:ListSavingsPlansPurchaseRecommendationGeneration - redshift:DescribeReservedNodes - es:DescribeReservedElasticsearchInstances - es:DescribeReservedInstances Resource: '*' # Metrics only (CPU, network, ...) to find idle resources. No log access. - Sid: CloudWatchReadMetrics Effect: Allow Action: - cloudwatch:GetMetricStatistics - cloudwatch:ListMetrics Resource: '*' # Lists enabled regions so every region is covered. - Sid: DescribeRegions Effect: Allow Action: - ec2:DescribeRegions Resource: '*' # Describe/List calls on resource configuration (type, size, state). cloudtrail:DescribeTrails and GetEventSelectors read trail settings only, to find duplicate trails that cost money. They do not read log contents. - Sid: ResourceDescribe Effect: Allow Action: - ec2:DescribeInstances - ec2:DescribeInstanceTypes - ec2:DescribeVolumes - ec2:DescribeAddresses - ec2:DescribeNatGateways - ec2:DescribeReservedInstances - ec2:DescribeSnapshots - rds:DescribeDBInstances - rds:DescribeDBClusters - rds:DescribeReservedDBInstances - elasticache:DescribeCacheClusters - elasticache:DescribeReplicationGroups - elasticache:DescribeReservedCacheNodes - savingsplans:DescribeSavingsPlans - savingsplans:DescribeSavingsPlanRates - es:ListDomainNames - es:DescribeElasticsearchDomain - es:DescribeDomain - rds:DescribeDBSnapshots - cloudtrail:DescribeTrails - cloudtrail:GetEventSelectors - ecs:DescribeServices - ecs:DescribeClusters - ecs:ListServices - ecs:ListClusters Resource: '*' # Bucket-level settings (lifecycle, tiering, versioning, location) to find storage savings. Cannot read or list objects. - Sid: S3OptimizationRead Effect: Allow Action: - s3:ListAllMyBuckets - s3:GetBucketLocation - s3:GetLifecycleConfiguration - s3:GetIntelligentTieringConfiguration - s3:GetBucketVersioning Resource: '*' # IAM credential report: one CSV of users, key ages, last use and MFA status, used for security hygiene findings. It contains no passwords, secret keys or key IDs. - Sid: IamHygieneRead Effect: Allow Action: - iam:GenerateCredentialReport - iam:GetCredentialReport Resource: '*' - !If - LambdaChecksEnabled - Sid: LambdaOptimizationRead Effect: Allow Action: - lambda:ListFunctions - lambda:ListProvisionedConcurrencyConfigs Resource: '*' - !Ref AWS::NoValue Outputs: RoleArn: Value: !GetAtt SpikeCatcherMemberRole.Arn