Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Inspec 1
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
slevenick authored and Stuart Paterson committed Apr 6, 2020
1 parent 421150a commit b9b5a36
Show file tree
Hide file tree
Showing 112 changed files with 6,343 additions and 2,032 deletions.
62 changes: 39 additions & 23 deletions docs/resources/google_compute_address.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
---
title: About the google_compute_address Resource
title: About the google_compute_address resource
platform: gcp
---

# google\_compute\_address

Use the `google_compute_address` InSpec audit resource to test properties of a single GCP compute address.

<br>

## Syntax

A `google_compute_address` resource block declares the tests for a single GCP compute address by project, region and name.

describe google_compute_address(project: 'chef-inspec-gcp', location: 'europe-west2', name: 'compute-address') do
it { should exist }
its('name') { should eq 'compute-address' }
its('region') { should match 'europe-west2' }
end

<br>
A `google_compute_address` is used to test a Google Address resource

## Examples

The following examples show how to use this InSpec audit resource.
```
describe google_compute_address(project: 'chef-gcp-inspec', location: 'europe-west2', name: 'inspec-gcp-global-address') do
it { should exist }
its('address') { should eq '10.2.0.3' }
its('address_type') { should eq 'INTERNAL' }
its('user_count') { should eq 0 }
end
describe google_compute_address(project: 'chef-gcp-inspec', location: 'europe-west2', name: 'nonexistent') do
it { should_not exist }
end
```

### Test that a GCP compute address IP exists

Expand All @@ -49,15 +44,36 @@ The following examples show how to use this InSpec audit resource.
its('user_resource_name') { should eq "gcp_ext_vm_name" }
end

<br>

## Properties
Properties that can be accessed from the `google_compute_address` resource:


* `address`: The static external IP address represented by this resource. Only IPv4 is supported. An address may only be specified for INTERNAL address types. The IP address must be inside the specified subnetwork, if any.

* `address_type`: The type of address to reserve, either INTERNAL or EXTERNAL. If unspecified, defaults to EXTERNAL.

* `creation_timestamp`: Creation timestamp in RFC3339 text format.

* `description`: An optional description of this resource.

* `id`: The unique identifier for the resource.

* `name`: Name of the resource. The name must be 1-63 characters long, and comply with RFC1035. Specifically, the name must be 1-63 characters long and match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?` which means the first character must be a lowercase letter, and all following characters must be a dash, lowercase letter, or digit, except the last character, which cannot be a dash.

* `purpose`: The purpose of this resource, which can be one of the following values: - GCE_ENDPOINT for addresses that are used by VM instances, alias IP ranges, internal load balancers, and similar resources. This should only be set when using an Internal address.

* `network_tier`: The networking tier used for configuring this address. This field can take the following values: PREMIUM or STANDARD. If this field is not specified, it is assumed to be PREMIUM.

* `subnetwork`: The URL of the subnetwork in which to reserve the address. If an IP address is specified, it must be within the subnetwork's IP range. This field can only be used with INTERNAL type with GCE_ENDPOINT/DNS_RESOLVER purposes.

* `users`: The URLs of the resources that are using this address.

* `address`, `creation_timestamp`, `description`, `id`, `kind`, `name`, `region`, `status`, `users`
* `status`: The status of the address, which can be one of RESERVING, RESERVED, or IN_USE. An address that is RESERVING is currently in the process of being reserved. A RESERVED address is currently reserved and available to use. An IN_USE address is currently being used by another resource and is not available.

<br>
* `region`: URL of the region where the regional address resides. This field is not applicable to global addresses.


## GCP Permissions

Ensure the [Compute Engine API](https://console.cloud.google.com/apis/library/compute.googleapis.com/) is enabled for the project where the resource is located.
Ensure the [Compute Engine API](https://console.cloud.google.com/apis/library/compute.googleapis.com/) is enabled for the current project.
40 changes: 40 additions & 0 deletions docs/resources/google_compute_addresses.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: About the google_compute_addresses resource
platform: gcp
---

## Syntax
A `google_compute_addresses` is used to test a Google Address resource

## Examples
```
describe google_compute_addresses(project: 'chef-gcp-inspec', location: 'europe-west2') do
its('addresses') { should include '10.2.0.3' }
its('names') { should include 'inspec-gcp-global-address' }
end
```

## Properties
Properties that can be accessed from the `google_compute_addresses` resource:

See [google_compute_address.md](google_compute_address.md) for more detailed information
* `addresses`: an array of `google_compute_address` address
* `address_types`: an array of `google_compute_address` address_type
* `creation_timestamps`: an array of `google_compute_address` creation_timestamp
* `descriptions`: an array of `google_compute_address` description
* `ids`: an array of `google_compute_address` id
* `names`: an array of `google_compute_address` name
* `purposes`: an array of `google_compute_address` purpose
* `network_tiers`: an array of `google_compute_address` network_tier
* `subnetworks`: an array of `google_compute_address` subnetwork
* `users`: an array of `google_compute_address` users
* `statuses`: an array of `google_compute_address` status
* `regions`: an array of `google_compute_address` region

## Filter Criteria
This resource supports all of the above properties as filter criteria, which can be used
with `where` as a block or a method.

## GCP Permissions

Ensure the [Compute Engine API](https://console.cloud.google.com/apis/library/compute.googleapis.com/) is enabled for the current project.
76 changes: 52 additions & 24 deletions docs/resources/google_compute_firewall.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
---
title: About the google_compute_firewall Resource
title: About the google_compute_firewall resource
platform: gcp
---

# google\_compute\_firewall

Use the `google_compute_firewall` InSpec audit resource to test properties of a single GCP compute compute firewall.

<br>

## Syntax

A `google_compute_firewall` resource block declares the tests for a single GCP compute firewall by project and name.

describe google_compute_firewall(project: 'chef-inspec-gcp', name: 'firewall-rule') do
it { should exist }
its('name') { should eq 'firewall-rule' }
end

<br>
A `google_compute_firewall` is used to test a Google Firewall resource

## Examples

The following examples show how to use this InSpec audit resource.
```
describe google_compute_firewall(project: 'chef-gcp-inspec', name: 'inspec-gcp-firewall') do
its('direction') { should cmp 'INGRESS' }
its('log_config_enabled?') { should be true }
its('source_tags') { should include 'some-tag' }
end
```

### Test that a GCP compute firewall allows SSH access on port 22

Expand Down Expand Up @@ -76,19 +67,56 @@ The following examples show how to use this InSpec audit resource.
it { should allow_target_tags_only ["allow-gcp-other-tag"] }
end

<br>

## Properties
Properties that can be accessed from the `google_compute_firewall` resource:


* `allowed`: The list of ALLOW rules specified by this firewall. Each rule specifies a protocol and port-range tuple that describes a permitted connection.

* `ip_protocol`: The IP protocol to which this rule applies. The protocol type is required when creating a firewall rule. This value can either be one of the following well known protocol strings (tcp, udp, icmp, esp, ah, sctp), or the IP protocol number.

* `ports`: An optional list of ports to which this rule applies. This field is only applicable for UDP or TCP protocol. Each entry must be either an integer or a range. If not specified, this rule applies to connections through any port. Example inputs include: ["22"], ["80","443"], and ["12345-12349"].

* `creation_timestamp`: Creation timestamp in RFC3339 text format.

* `denied`: The list of DENY rules specified by this firewall. Each rule specifies a protocol and port-range tuple that describes a denied connection.

* `ip_protocol`: The IP protocol to which this rule applies. The protocol type is required when creating a firewall rule. This value can either be one of the following well known protocol strings (tcp, udp, icmp, esp, ah, sctp), or the IP protocol number.

* `ports`: An optional list of ports to which this rule applies. This field is only applicable for UDP or TCP protocol. Each entry must be either an integer or a range. If not specified, this rule applies to connections through any port. Example inputs include: ["22"], ["80","443"], and ["12345-12349"].

* `description`: An optional description of this resource. Provide this property when you create the resource.

* `destination_ranges`: If destination ranges are specified, the firewall will apply only to traffic that has destination IP address in these ranges. These ranges must be expressed in CIDR format. Only IPv4 is supported.

* `direction`: Direction of traffic to which this firewall applies; default is INGRESS. Note: For INGRESS traffic, it is NOT supported to specify destinationRanges; For EGRESS traffic, it is NOT supported to specify sourceRanges OR sourceTags.

* `disabled`: Denotes whether the firewall rule is disabled, i.e not applied to the network it is associated with. When set to true, the firewall rule is not enforced and the network behaves as if it did not exist. If this is unspecified, the firewall rule will be enabled.

* `log_config`: This field denotes whether to enable logging for a particular firewall rule. If logging is enabled, logs will be exported to Stackdriver.

* `enable_logging`: This field denotes whether to enable logging for a particular firewall rule. If logging is enabled, logs will be exported to Stackdriver.

* `id`: The unique identifier for the resource.

* `name`: Name of the resource. Provided by the client when the resource is created. The name must be 1-63 characters long, and comply with RFC1035. Specifically, the name must be 1-63 characters long and match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?` which means the first character must be a lowercase letter, and all following characters must be a dash, lowercase letter, or digit, except the last character, which cannot be a dash.

* `network`: URL of the network resource for this firewall rule. If not specified when creating a firewall rule, the default network is used: global/networks/default If you choose to specify this property, you can specify the network as a full or partial URL. For example, the following are all valid URLs: https://www.googleapis.com/compute/v1/projects/myproject/global/ networks/my-network projects/myproject/global/networks/my-network global/networks/default

* `priority`: Priority for this rule. This is an integer between 0 and 65535, both inclusive. When not specified, the value assumed is 1000. Relative priorities determine precedence of conflicting rules. Lower value of priority implies higher precedence (eg, a rule with priority 0 has higher precedence than a rule with priority 1). DENY rules take precedence over ALLOW rules having equal priority.

* `source_ranges`: If source ranges are specified, the firewall will apply only to traffic that has source IP address in these ranges. These ranges must be expressed in CIDR format. One or both of sourceRanges and sourceTags may be set. If both properties are set, the firewall will apply to traffic that has source IP address within sourceRanges OR the source IP that belongs to a tag listed in the sourceTags property. The connection does not need to match both properties for the firewall to apply. Only IPv4 is supported.

* `allowed`, `creation_timestamp`, `description`, `direction`, `id`, `kind`, `name`, `network`, `priority`, `source_ranges`, `target_tags`
* `source_service_accounts`: If source service accounts are specified, the firewall will apply only to traffic originating from an instance with a service account in this list. Source service accounts cannot be used to control traffic to an instance's external IP address because service accounts are associated with an instance, not an IP address. sourceRanges can be set at the same time as sourceServiceAccounts. If both are set, the firewall will apply to traffic that has source IP address within sourceRanges OR the source IP belongs to an instance with service account listed in sourceServiceAccount. The connection does not need to match both properties for the firewall to apply. sourceServiceAccounts cannot be used at the same time as sourceTags or targetTags.

In addition, the following helpers are available:
* `source_tags`: If source tags are specified, the firewall will apply only to traffic with source IP that belongs to a tag listed in source tags. Source tags cannot be used to control traffic to an instance's external IP address. Because tags are associated with an instance, not an IP address. One or both of sourceRanges and sourceTags may be set. If both properties are set, the firewall will apply to traffic that has source IP address within sourceRanges OR the source IP that belongs to a tag listed in the sourceTags property. The connection does not need to match both properties for the firewall to apply.

* `allowed_http?`, `allowed_ssh?`, `allow_port_protocol`, `allow_source_tags`, `allow_source_tags_only`, `allow_target_tags`, `allow_target_tags_only`, `allow_ip_ranges`, `allow_ip_ranges_only`
* `target_service_accounts`: A list of service accounts indicating sets of instances located in the network that may make network connections as specified in allowed[]. targetServiceAccounts cannot be used at the same time as targetTags or sourceTags. If neither targetServiceAccounts nor targetTags are specified, the firewall rule applies to all instances on the specified network.

<br>
* `target_tags`: A list of instance tags indicating sets of instances located in the network that may make network connections as specified in allowed[]. If no targetTags are specified, the firewall rule applies to all instances on the specified network.


## GCP Permissions

Ensure the [Compute Engine API](https://console.cloud.google.com/apis/library/compute.googleapis.com/) is enabled for the project where the resource is located.
Ensure the [Compute Engine API](https://console.cloud.google.com/apis/library/compute.googleapis.com/) is enabled for the current project.
96 changes: 33 additions & 63 deletions docs/resources/google_compute_firewalls.md
Original file line number Diff line number Diff line change
@@ -1,76 +1,46 @@
---
title: About the google_compute_firewalls Resource
title: About the google_compute_firewalls resource
platform: gcp
---

# google\_compute\_firewalls

Use the `google_compute_firewalls` InSpec audit resource to test properties of all, or a filtered group of, GCP compute firewalls for a project.

<br>

## Syntax

A `google_compute_firewalls` resource block collects GCP firewalls by project then tests that group.

describe google_compute_firewalls(project: 'chef-inspec-gcp') do
it { should exist }
end

Use this InSpec resource to enumerate IDs then test in-depth using `google_compute_firewall`.

google_compute_firewalls(project: 'chef-inspec-gcp').firewall_names.each do |firewall_name|
describe google_compute_firewall(project: 'chef-inspec-gcp', name: firewall_name) do
it { should exist }
its('kind') { should eq "compute#firewall" }
end
end

<br>
A `google_compute_firewalls` is used to test a Google Firewall resource

## Examples

The following examples show how to use this InSpec audit resource.

### Test that there are no more than a specified number of firewalls available for the project

describe google_compute_firewalls(project: 'chef-inspec-gcp') do
its('count') { should be <= 100}
end

### Test that an expected firewall is available for the project

describe google_compute_firewalls(project: 'chef-inspec-gcp') do
its('firewall_names') { should include "my-app-firewall-rule" }
end

### Test that a particular named rule does not exist

describe google_compute_firewalls(project: 'chef-inspec-gcp') do
its('firewall_names') { should_not include "default-allow-ssh" }
end

### Test there are no firewalls for the "INGRESS" direction

describe google_compute_firewalls(project: 'chef-inspec-gcp').where(firewall_direction: 'INGRESS') do
it { should_not exist }
end

<br>

## Filter Criteria

This resource supports the following filter criteria: `firewall_id`; `firewall_name`; and `firewall_direction`. Any of these may be used with `where`, as a block or as a method.
```
describe google_compute_firewalls(project: 'chef-gcp-inspec') do
its('count') { should be >= 1 }
its('firewall_names') { should include 'inspec-gcp-firewall' }
its('firewall_directions') { should include 'INGRESS' }
end
```

## Properties
Properties that can be accessed from the `google_compute_firewalls` resource:

See [google_compute_firewall.md](google_compute_firewall.md) for more detailed information
* `alloweds`: an array of `google_compute_firewall` allowed
* `creation_timestamps`: an array of `google_compute_firewall` creation_timestamp
* `denieds`: an array of `google_compute_firewall` denied
* `descriptions`: an array of `google_compute_firewall` description
* `destination_ranges`: an array of `google_compute_firewall` destination_ranges
* `firewall_directions`: an array of `google_compute_firewall` direction
* `disableds`: an array of `google_compute_firewall` disabled
* `log_configs`: an array of `google_compute_firewall` log_config
* `firewall_ids`: an array of `google_compute_firewall` id
* `firewall_names`: an array of `google_compute_firewall` name
* `networks`: an array of `google_compute_firewall` network
* `priorities`: an array of `google_compute_firewall` priority
* `source_ranges`: an array of `google_compute_firewall` source_ranges
* `source_service_accounts`: an array of `google_compute_firewall` source_service_accounts
* `source_tags`: an array of `google_compute_firewall` source_tags
* `target_service_accounts`: an array of `google_compute_firewall` target_service_accounts
* `target_tags`: an array of `google_compute_firewall` target_tags

* `firewall_ids` - an array of google_compute_firewall identifier integers
* `firewall_names` - an array of google_compute_firewall name strings
* `firewall_directions`- an array of google_compute_firewall directions containing strings e.g. "INGRESS" or "EGRESS"

<br>

## Filter Criteria
This resource supports all of the above properties as filter criteria, which can be used
with `where` as a block or a method.

## GCP Permissions

Ensure the [Compute Engine API](https://console.cloud.google.com/apis/library/compute.googleapis.com/) is enabled for the project where the resource is located.
Ensure the [Compute Engine API](https://console.cloud.google.com/apis/library/compute.googleapis.com/) is enabled for the current project.
Loading

0 comments on commit b9b5a36

Please sign in to comment.