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

feat(ec2): peer cidr ip validation #3642

Merged
merged 7 commits into from
Aug 22, 2019
Merged

feat(ec2): peer cidr ip validation #3642

merged 7 commits into from
Aug 22, 2019

Conversation

nmussy
Copy link
Contributor

@nmussy nmussy commented Aug 13, 2019

Fixes #3639


Please read the contribution guidelines and follow the pull-request checklist.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@@ -112,6 +122,16 @@ class CidrIPv6 implements IPeer {
public readonly uniqueId: string;

constructor(private readonly cidrIpv6: string) {
const cidrMatch = cidrIpv6.match(/^([\da-f]{0,4}:){2,7}([\da-f]{0,4})?(\/\d+)?$/);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used some fairly loose RegExps, especially for IPv6. The stricter ones tend to become a little crazy

@NGL321 NGL321 requested a review from rix0rrr August 13, 2019 22:24
}

if (!cidrMatch[2]) {
throw new Error(`CIDR mask is missing in IPv4: "${cidrIp}". Did you mean "${cidrIp}/xx"?`);
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel it makes more sense to replace /xx with /32 in the error message. If people wrote a single IP address, that's probably what they meant, and if they didn't it's clear enough where to substitute values to make it do what they want.

I considered automatically adding /32 to the IP address, but we should probably make a separate class for single IP addresses.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we should probably make a separate class for single IP addresses.

I like that idea. We could also deprecate ipv4/v6 and explicitly name them ipv4Cidr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Otherwise, done

@@ -77,6 +77,16 @@ class CidrIPv4 implements IPeer {
public readonly uniqueId: string;

constructor(private readonly cidrIp: string) {
const cidrMatch = cidrIp.match(/^(\d{1,3}\.){3}\d{1,3}(\/\d+)?$/);
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess to be safe this needs a if (!cdk.Token.isUnresolved(cidrIp)) { ... } block around the checks, same for the IPv6 version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}

if (!cidrMatch[3]) {
throw new Error(`CIDR mask is missing in IPv6: "${cidrIpv6}". Did you mean "${cidrIpv6}/xx"?`);
Copy link
Contributor

Choose a reason for hiding this comment

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

/128 I suppose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@mergify
Copy link
Contributor

mergify bot commented Aug 19, 2019

Pull Request Checklist

  • Testing
  • Unit test added (prefer to add a new test rather than modify existing tests)
  • CLI change? Re-run/add CLI integration tests
  • Documentation
  • Inline docs: make sure all public APIs are documented (copy & paste from official AWS docs)
  • README: update module README
  • Design: for significant features, follow the design process
  • Title uses the format type(scope): text
  • Type: fix, feat, refactor go into CHANGELOG, chore is hidden
  • Scope: name of the module without the aws- or cdk- prefix or postfix (e.g. s3 instead of aws-s3-deployment)
  • Style: use all lower-case, do not end with a period
  • Description
  • Rationale: describe rationale of change and approach taken
  • Issues: Indicate issues fixed via: fixes #xxx or closes #xxx
  • Breaking?: last paragraph: BREAKING CHANGE: <describe what changed + link for details>
  • Sensitive Modules (requires 2 PR approvers)
  • IAM document library (in @aws-cdk/aws-iam)
  • EC2 security groups and ACLs (in @aws-cdk/aws-ec2)
  • Grant APIs (if not based on official documentation with a reference)

1 similar comment
@mergify
Copy link
Contributor

mergify bot commented Aug 19, 2019

Pull Request Checklist

  • Testing
  • Unit test added (prefer to add a new test rather than modify existing tests)
  • CLI change? Re-run/add CLI integration tests
  • Documentation
  • Inline docs: make sure all public APIs are documented (copy & paste from official AWS docs)
  • README: update module README
  • Design: for significant features, follow the design process
  • Title uses the format type(scope): text
  • Type: fix, feat, refactor go into CHANGELOG, chore is hidden
  • Scope: name of the module without the aws- or cdk- prefix or postfix (e.g. s3 instead of aws-s3-deployment)
  • Style: use all lower-case, do not end with a period
  • Description
  • Rationale: describe rationale of change and approach taken
  • Issues: Indicate issues fixed via: fixes #xxx or closes #xxx
  • Breaking?: last paragraph: BREAKING CHANGE: <describe what changed + link for details>
  • Sensitive Modules (requires 2 PR approvers)
  • IAM document library (in @aws-cdk/aws-iam)
  • EC2 security groups and ACLs (in @aws-cdk/aws-ec2)
  • Grant APIs (if not based on official documentation with a reference)

@mergify mergify bot dismissed rix0rrr’s stale review August 22, 2019 08:34

Pull request has been modified.

@mergify
Copy link
Contributor

mergify bot commented Aug 22, 2019

Thank you for contributing! Your pull request is now being automatically merged.

@rix0rrr rix0rrr merged commit b67b0f3 into aws:master Aug 22, 2019
@nmussy nmussy deleted the 3639 branch August 22, 2019 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EC2: Security Group Peer CIDR validation
2 participants