martysweet / cfn-lint

A CloudFormation JSON and YAML Validator
MIT License
163 stars 38 forks source link

Raise a critical error when S3Bucket name have upper case. #49

Open tchia04 opened 7 years ago

tchia04 commented 7 years ago

This template will fail with the message "Bucket name should not contain uppercase characters "

However cfn-lint is not able to catch this. $ cfn-lint validate s3bucket_parameter.yaml 0 infos 0 warn 0 crit Template valid!

Tonys-Mac-mini:~/cloudformation $  cat s3bucket_parameter.yaml
---
  AWSTemplateFormatVersion: "2010-09-09"
  Parameters:
    BucketName:
      Description: "Name of MyS3Bucket"
      Type: "String"
#      Default: "mys3bucketacloudgurutraining"
  Resources:
    S3Bucket:
      Type: "AWS::S3::Bucket"
      Properties:
        BucketName:
          Ref: "BucketName"
    S3Bucket2:
      Type: "AWS::S3::Bucket"
      Properties:
        BucketName: "Publicreadbucket220170703"
  Outputs:
    S3BucketName:
      Value:
        Ref: "S3Bucket"
      Description: "Name of S3 bucket"
    S3BucketName2:
      Value:
        Ref: "S3Bucket2"
      Description: "Name of S3 bucket"
martysweet commented 7 years ago

Thanks, this makes sense as S3 Buckets are a common resource to use.

I think a custom attribute checker would be needed to allow this functionality to be expanded to different types. Probably another JSON file which specifies the type name, in this case AWS::S3::Bucket.BucketName with the validation rules and messages to test/show. Then a small bit of code which uses this JSON to run the validations at validate time.

For reference, the limitation of buckets is at: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket.html#cfn-s3-bucket-name

akdor1154 commented 6 years ago

I was wondering about a JS file instead of a JSON file, that way we could just write arbitrary validation functions. (this one is also something I've been wondering about).