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

soumyo/aws_rds_db_proxy #771

Merged
merged 26 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a849c39
all singular and plural resources
soumyo13 Nov 21, 2021
e06e960
all singular and plural resource
soumyo13 Nov 21, 2021
c8b9e6b
added tf
Nov 24, 2021
3dffe17
added tf
Nov 24, 2021
3bfd866
added resourcce and test
Nov 24, 2021
40a16c4
Merge remote-tracking branch 'origin/soumyo/aws_rds_db_proxy' into so…
Nov 24, 2021
dc46103
Delete aws_rds_db_proxy_target_group.md
Nirbhay1997 Nov 24, 2021
d3efb45
Delete aws_rds_db_proxy_target_groups.md
Nirbhay1997 Nov 24, 2021
d99bc0c
Delete aws_rds_db_proxy_target_group.rb
Nirbhay1997 Nov 24, 2021
65f9398
Delete aws_rds_db_proxy_target_groups.rb
Nirbhay1997 Nov 24, 2021
4590990
Delete aws_s3_bucket_policy.rb
Nirbhay1997 Nov 24, 2021
3df8119
Delete aws_rds_db_proxy_target_group.rb
Nirbhay1997 Nov 24, 2021
f17fb4d
Delete aws_rds_db_proxy_target_groups.rb
Nirbhay1997 Nov 24, 2021
cd9eded
Delete aws_s3_bucket_policy_test.rb
Nirbhay1997 Nov 24, 2021
eb5f05a
Delete aws_rds_db_proxy_target_groups_test.rb
Nirbhay1997 Nov 24, 2021
6b2a4e5
Delete aws_rds_db_proxy_target_group_test.rb
Nirbhay1997 Nov 24, 2021
c0f5151
Delete aws_s3_bucket_policy.rb
Nirbhay1997 Nov 24, 2021
3b92d42
Delete aws_s3_bucket_policy.md
Nirbhay1997 Nov 24, 2021
b8d1b67
Update libraries/aws_backend.rb
Nirbhay1997 Nov 24, 2021
3373f2a
updated docs and tf
Nov 25, 2021
03ab341
Delete aws_rds_db_proxies.rb
soumyo13 Nov 25, 2021
969743d
Delete aws_rds_db_proxies_test.rb
soumyo13 Nov 25, 2021
ec08d1c
updated docs and tf
Nov 25, 2021
f889566
updated docs and tf
Nov 25, 2021
721e74b
Docs edits
IanMadd Nov 29, 2021
fd004c5
resolved conflicts
Dec 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions docs/resources/aws_rds_db_proxies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
title: About the aws_rds_db_proxies Resource
platform: aws
---

# aws_rds_db_proxies

Use the `aws_rds_db_proxies` InSpec audit resource to test properties of the plural resource of AWS RDS DBProxy.

The AWS::RDS::DBProxy resource creates or updates a DB proxy.

## Syntax

Ensure that the db proxy exists.

describe aws_rds_db_proxies(db_proxy_name: 'DB_PROXY_NAME') do
it { should exist }
end

## Parameters

`db_proxy_name` _(required)_

The identifier for the proxy. This name must be unique for all proxies owned by your AWS account in the specified AWS Region.

For additional information, see the [AWS documentation on AWS RDS DBProxy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-rds-dbproxy.html).

## Properties

| Property | Description | Fields |
| --- | --- | --- |
| db_proxy_names | The identifier for the proxy. This name must be unique for all proxies owned by your AWS account in the specified AWS Region. | db_proxy_name |
| db_proxy_arns | The Amazon Resource Name (ARN) for the proxy. | db_proxy_arn |
| statuses | The current status of this proxy. |
| engine_families | The engine family applies to MySQL and PostgreSQL for both RDS and Aurora. | engine_family |
| vpc_ids | The VPC id. | vpc_id |
| vpc_security_group_ids | Provides a list of VPC security groups that the proxy belongs to. | vpc_security_group_ids |
| vpc_subnet_ids | The EC2 subnet IDs for the proxy. | vpc_subnet_ids |
| auths | One or more data structures specifying the authorization mechanism to connect to the associated RDS DB instance or Aurora DB cluster. | auths |
| role_arns | The Amazon Resource Name (ARN) for the IAM role that the proxy uses to access Amazon Secrets Manager. | role_arn |
| endpoints | The endpoint that you can use to connect to the proxy. You include the endpoint value in the connection string for a database client application. | endpoint |
| require_tls | Indicates whether Transport Layer Security (TLS) encryption is required for connections to the proxy. |
| idle_client_timeouts | The number of seconds a connection to the proxy can have no activity before the proxy drops the client connection. | idle_client_timeout |
| debug_loggings | Whether the proxy includes detailed information about SQL statements in its logs. | debug_logging |
| created_dates | The date and time when the proxy was first created. | created_date |
| updated_dates | The date and time when the proxy was last updated. | updated_date |

## Examples

### Ensure a db proxy name is available.
describe aws_rds_db_proxies(db_proxy_name: 'DB_PROXY_NAME') do
its('db_proxy_names') { should include 'DB_PROXY_NAME' }
end

### Ensure a db proxy arn is available.
describe aws_rds_db_proxies(db_proxy_name: 'DB_PROXY_NAME') do
its('db_proxy_arns') { should include 'DB_PROXY_ARN' }
end

### Ensure a status is `available`.
describe aws_rds_db_proxies(db_proxy_name: 'DB_PROXY_NAME') do
its('statuses') { should include 'available' }
end

## Matchers

This InSpec audit resource has the following special matchers. For a full list of available matchers, please visit our [Universal Matchers page](https://www.inspec.io/docs/reference/matchers/).

The controls will pass if the `describe` method returns at least one result.

### exist

Use `should` to test that the entity exists.

describe aws_rds_db_proxies(db_proxy_name: 'DB_PROXY_NAME') do
it { should exist }
end

Use `should_not` to test the entity does not exist.

describe aws_rds_db_proxies(db_proxy_name: 'DB_PROXY_NAME') do
it { should_not exist }
end

### be_available

Use `should` to check if the entity is available.

describe aws_rds_db_proxies(db_proxy_name: 'DB_PROXY_NAME') do
it { should be_available }
end

## AWS Permissions

Your [Principal](https://docs.aws.amazon.com/IAM/latest/UserGuide/intro-structure.html#intro-structure-principal) will need the `RDS:Client:DescribeDBProxiesResponse` action with `Effect` set to `Allow`.
99 changes: 99 additions & 0 deletions docs/resources/aws_rds_db_proxy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
title: About the aws_rds_db_proxy Resource
platform: aws
---

# aws_rds_db_proxy

Use the `aws_rds_db_proxy` InSpec audit resource to test properties of the singular resource of AWS RDS DBProxy.

The AWS::RDS::DBProxy resource creates or updates a DB proxy.

## Syntax

Ensure that the db proxy exists.

describe aws_rds_db_proxy(db_proxy_name: 'DB_PROXY_NAME') do
it { should exist }
end

## Parameters

`db_proxy_name` _(required)_

The identifier for the proxy. This name must be unique for all proxies owned by your AWS account in the specified AWS Region.

For additional information, see the [AWS documentation on AWS RDS DBProxy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-rds-dbproxy.html).

## Properties

| Property | Description |
| --- | --- |
| db_proxy_name | The identifier for the proxy. This name must be unique for all proxies owned by your AWS account in the specified AWS Region. |
| db_proxy_arn | The Amazon Resource Name (ARN) for the proxy. |
| status | The current status of this proxy. |
| engine_family | The engine family applies to MySQL and PostgreSQL for both RDS and Aurora. |
| vpc_id | The VPC id. |
| vpc_security_group_ids | Provides a list of VPC security groups that the proxy belongs to. |
| vpc_subnet_ids | The EC2 subnet IDs for the proxy. |
| auth_descriptions | A user-specified description about the authentication used by a proxy to log in as a specific database user. |
| auth_user_names | The name of the database user to which the proxy connects. |
| auth_schemes | The type of authentication that the proxy uses for connections from the proxy to the underlying database. |
| auth_secret_arns | The Amazon Resource Name (ARN) representing the secret that the proxy uses to authenticate to the RDS DB instance or Aurora DB cluster. These secrets are stored within Amazon Secrets Manager. |
| auth_iam_auths | Whether to require or disallow AWS Identity and Access Management (IAM) authentication for connections to the proxy. |
| role_arn | The Amazon Resource Name (ARN) for the IAM role that the proxy uses to access Amazon Secrets Manager. |
| endpoint | The endpoint that you can use to connect to the proxy. You include the endpoint value in the connection string for a database client application. |
| require_tls | Indicates whether Transport Layer Security (TLS) encryption is required for connections to the proxy. |
| idle_client_timeout | The number of seconds a connection to the proxy can have no activity before the proxy drops the client connection. |
| debug_logging | Whether the proxy includes detailed information about SQL statements in its logs. |
| created_date | The date and time when the proxy was first created. |
| updated_date | The date and time when the proxy was last updated. |

## Examples

### Ensure a db proxy name is available.
describe aws_rds_db_proxy(db_proxy_name: 'DB_PROXY_NAME') do
its('db_proxy_name') { should eq 'DB_PROXY_NAME' }
end

### Ensure a db proxy arn is available.
describe aws_rds_db_proxy(db_proxy_name: 'DB_PROXY_NAME') do
its('db_proxy_arn') { should eq 'DB_PROXY_ARN' }
end

### Ensure a status is `available`.
describe aws_rds_db_proxy(db_proxy_name: 'DB_PROXY_NAME') do
its('status') { should eq 'available' }
end

## Matchers

This InSpec audit resource has the following special matchers. For a full list of available matchers, please visit our [Universal Matchers page](https://www.inspec.io/docs/reference/matchers/).

The controls will pass if the `describe` method returns at least one result.

### exist

Use `should` to test that the entity exists.

describe aws_rds_db_proxy(db_proxy_name: 'DB_PROXY_NAME') do
it { should exist }
end

Use `should_not` to test the entity does not exist.

describe aws_rds_db_proxy(db_proxy_name: 'DB_PROXY_NAME') do
it { should_not exist }
end

### be_available

Use `should` to check if the entity is available.

describe aws_rds_db_proxy(db_proxy_name: 'DB_PROXY_NAME') do
it { should be_available }
end

## AWS Permissions

Your [Principal](https://docs.aws.amazon.com/IAM/latest/UserGuide/intro-structure.html#intro-structure-principal) will need the `RDS:Client:DescribeDBProxiesResponse` action with `Effect` set to `Allow`.
Empty file.
4 changes: 4 additions & 0 deletions libraries/aws_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ def simpledb_client
def emr_client
aws_client(Aws::EMR::Client)
end

def s3_client
aws_client(Aws::S3::Client)
end
Nirbhay1997 marked this conversation as resolved.
Show resolved Hide resolved
end

# Base class for AWS resources
Expand Down
68 changes: 68 additions & 0 deletions libraries/aws_rds_db_proxies.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# frozen_string_literal: true

require 'aws_backend'

class AWSRDSProxies < AwsResourceBase
name 'aws_rds_db_proxies'
desc 'Returns information about DB proxies.'

example "
describe aws_rds_db_proxies(db_proxy_name: 'DB_PROXY_NAME') do
it { should exist }
end
"

attr_reader :table

FilterTable.create
.register_column(:db_proxy_names, field: :db_proxy_name)
.register_column(:db_proxy_arns, field: :db_proxy_arn)
.register_column(:statuses, field: :status)
.register_column(:engine_families, field: :engine_family)
.register_column(:vpc_ids, field: :vpc_id)
.register_column(:vpc_security_group_ids, field: :vpc_security_group_ids)
.register_column(:vpc_subnet_ids, field: :vpc_subnet_ids)
.register_column(:auths, field: :auth)
.register_column(:role_arns, field: :role_arn)
.register_column(:endpoints, field: :endpoint)
.register_column(:require_tls, field: :require_tls)
.register_column(:idle_client_timeouts, field: :idle_client_timeout)
.register_column(:debug_loggings, field: :debug_logging)
.register_column(:created_dates, field: :created_date)
.register_column(:updated_dates, field: :updated_date)
.install_filter_methods_on_resource(self, :table)

def initialize(opts = {})
super(opts)
validate_parameters(required: %i(db_proxy_name))
@query_params = {}
raise ArgumentError, "#{@__resource_name__}: db_proxy_name must be provided" unless opts[:db_proxy_name] && !opts[:db_proxy_name].empty?
@query_params[:db_proxy_name] = opts[:db_proxy_name]
@table = fetch_data
end

def fetch_data
catch_aws_errors do
@table = @aws.rds_client.describe_db_proxies(@query_params).map do |table|
table.db_proxies.map { |table_name| {
db_proxy_name: table_name.db_proxy_name,
db_proxy_arn: table_name.db_proxy_arn,
status: table_name.status,
engine_family: table_name.engine_family,
vpc_id: table_name.vpc_id,
vpc_security_group_ids: table_name.vpc_security_group_ids,
vpc_subnet_ids: table_name.vpc_subnet_ids,
auth: table_name.auth,
role_arn: table_name.role_arn,
endpoint: table_name.endpoint,
require_tls: table_name.require_tls,
idle_client_timeout: table_name.idle_client_timeout,
debug_logging: table_name.debug_logging,
created_date: table_name.created_date,
updated_date: table_name.updated_date,
}
}
end.flatten
end
end
end
59 changes: 59 additions & 0 deletions libraries/aws_rds_db_proxy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# frozen_string_literal: true

require 'aws_backend'

class AWSRDSProxy < AwsResourceBase
name 'aws_rds_db_proxy'
desc 'Returns information about DB proxies.'

example "
describe aws_rds_db_proxy(db_proxy_name: 'DB_PROXY_NAME') do
it { should exist }
end
"

def initialize(opts = {})
super(opts)
validate_parameters(required: %i(db_proxy_name))
raise ArgumentError, "#{@__resource_name__}: db_proxy_name must be provided" unless opts[:db_proxy_name] && !opts[:db_proxy_name].empty?
@display_name = opts[:db_proxy_name]
catch_aws_errors do
resp = @aws.rds_client.describe_db_proxies({ db_proxy_name: opts[:db_proxy_name] })
@res = resp.db_proxies[0].to_h
create_resource_methods(@res)
end
end

def db_proxy_name
return nil unless exists?
@res[:db_proxy_name]
end

def exists?
!@res.nil? && !@res.empty?
end

def to_s
"DB Proxy Name: #{@display_name}"
end

def auth_descriptions
auth.map(&:description)
end

def auth_user_names
auth.map(&:user_name)
end

def auth_schemes
auth.map(&:auth_scheme)
end

def auth_secret_arns
auth.map(&:secret_arn)
end

def auth_iam_auths
auth.map(&:iam_auth)
end
end
Loading