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

aws_route53_record_set does not work #976

Open
mwiczynski-cartera opened this issue Oct 20, 2023 · 0 comments
Open

aws_route53_record_set does not work #976

mwiczynski-cartera opened this issue Oct 20, 2023 · 0 comments

Comments

@mwiczynski-cartera
Copy link

mwiczynski-cartera commented Oct 20, 2023

aws_route53_record_set should check if a record exists. It does not. It will report true if any record exists in the zone.
It also cannot verify if the value for the record is correct.

Describe the problem

Say you have a zone home.com and a record like foo.home.com. It points to an aws load balancer: 123.us-west-2.elb.amazonaws.com

Both these tests will pass, 2nd one should not.

describe aws_route53_record_set(hosted_zone_id: 'zone-id', start_record_name: 'foo.home.com') do
  it { should exist }
end

describe aws_route53_record_set(hosted_zone_id: 'zone-id', start_record_name: 'bar.home.com') do
  it { should exist }
end

Testing for correct value in resource_records fails to work at all

describe aws_route53_record_set(hosted_zone_id: 'zone-id', start_record_name: 'foo.home.com') do
  its('resource_records.first.value') { should include '123.us-west-2.elb.amazonaws.com' }
end

Some suggestions how to fix this:

Change

resp = @aws.route53_client.list_resource_record_sets({ hosted_zone_id: opts[:hosted_zone_id], start_record_name: opts[:name] })

to

      resp = @aws.route53_client.list_resource_record_sets({ hosted_zone_id: opts[:hosted_zone_id], start_record_name: opts[:start_record_name], max_items: 1 })

There is a mistake in the code, opts[:name] does not exist, should be opts[:start_record_name]

By adding max_items: 1 you limit results returned which is more efficient than returning 100 records by default.

The api docs https://docs.aws.amazon.com/sdk-for-ruby/v2/api/Aws/Route53/Client.html#list_resource_record_sets-instance_method say

If you specify Name but not Type

    The results begin with the first resource record set in the list whose name is greater than or equal to Name.

This means you need to check the value of name in result, not just if response from AWS api call is empty or not.

https://github.com/inspec/inspec-aws/blob/ed08c422c0a8116e621986b192eba4194f1ba346/libraries/aws_route53_record_set.rb#L37C7-L37C7
should be something like:

    [email protected]? && [email protected]? && ( @res[:name] == @start_record_name || @res[:name] == @start_record_name + '.' )
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

No branches or pull requests

1 participant