Giter VIP home page Giter VIP logo

inspec-azure's Introduction

InSpec for Azure

  • Project State: Maintained

For more information on project states and SLAs, see this documentation.

Build Status

This InSpec resource pack uses the Azure REST API and provides the required resources to write tests for resources in Azure.

Table of Contents

Prerequisites

  • Ruby
  • Bundler installed

Authentication

Azure CLI Authentication:

-The Azure CLI provides a command-line interface for interacting with Azure services. To enable authentication, you will need to install the Azure CLI.- https://learn.microsoft.com/en-us/cli/azure/install-azure-cli

  az login --tenant AZURE_TENANT_ID

a. Use the az login --tenant AZURE_TENANT_ID command to log in with a specific Azure tenant: If you have a specific Azure tenant ID, you can provide it as a parameter to the az login command. If you don't specify the tenant ID, the CLI will provide a list of available tenants.

b. If the CLI can open your default browser: If the CLI can open your default browser, it will initiate the authorization code flow and open the Azure sign-in page in the browser for authentication.

c. If no web browser is available or fails to open: In case a web browser is not available or fails to open, the CLI will initiate the device code flow. It will provide you with a code and instruct you to open a browser page at https://aka.ms/devicelogin. You need to enter the code displayed in your terminal on that page for authentication.

d. Storing retrieved credentials: The documentation suggests storing the retrieved credentials, such as tenant_id and subscription_id, in environment variables prefaced with AZURE_. It provides an example of using a .envrc file or creating environment variables using the preferred method.

AZURE_TENANT_ID=<your-azure-tenant-id-here>
AZURE_SUBSCRIPTION_ID=<your-azure-subscription-id-here>

Azure Service Principal Account Authentication:

Service Principal

Your Azure Service Principal Account must have a minimum of reader role of the Azure roles to any subscription that you'd like to use this resource pack.

You must have the following pieces of information:

  • TENANT_ID
  • CLIENT_ID
  • CLIENT_SECRET
  • SUBSCRIPTION_ID

To create your account Service Principal Account:

  1. Log in to the Azure portal.
  2. Click Azure Active Directory.
  3. Click APP registrations.
  4. Click New application registration.
  5. Enter name and select Web from the Application Type drop-down.
  6. Save your application.
  7. Note your Application ID. This is your client_id.
  8. Click Certificates & secrets.
  9. Click New client secret.
  10. Create a new password. This value is your client_secret above.
  11. Go to your subscription (click All Services then subscriptions).
  12. Choose your subscription from that list.
  13. Note your Subscription ID.
  14. Click Access control (IAM).
  15. Click Add.
  16. Select the reader role.
  17. Select the application you created and click save.

These must be stored in an environment variables prefaced with AZURE_. If you use Dotenv, then you can save these values in your own .envrc file. Either source it or run direnv allow. If you do not use Dotenv, then you can create environment variables in the way that you prefer.

Use the Resources

Since this is an InSpec resource pack, it only defines InSpec resources. To use these resources in your controls, you should create your profile:

Create a new profile

inspec init profile --platform azure my-profile

Example inspec.yml:

name: my-profile
title: My own Azure profile
version: 0.1.0
inspec_version: '>= 4.23.15'
depends:
  - name: inspec-azure
    url: https://github.com/inspec/inspec-azure/archive/x.tar.gz
supports:
  - platform: azure

(For available inspec-azure versions, see this list of inspec-azure versions.)

Resource Documentation

List of generic resources:

With the generic resources:

  • Azure cloud resources pack, which does not include a static InSpec resource and can be tested.
  • Azure resources from different resource providers and resource groups can be tested at the same time.
  • Server-side filtering can be used for more efficient tests.

List of static resources

Singular Resource Plural Resource
azure_active_directory_domain_service azure_active_directory_domain_services
azure_active_directory_object azure_active_directory_objects
azure_aks_cluster azure_aks_clusters
azure_api_management azure_api_management
azure_application_gateway azure_application_gateways
azure_bastion_hosts_resource azure_bastion_hosts_resources
azure_blob_service azure_blob_services
azure_cdn_profile azure_cdn_profiles
azure_container_group azure_container_groups
azure_container_registry azure_container_registries
azure_cosmosdb_database_account No Plural Resource
azure_data_factory azure_data_factories
azure_data_factory_dataset azure_data_factory_datasets
azure_data_factory_linked_service azure_data_factory_linked_services
azure_data_factory_pipeline azure_data_factory_pipelines
azure_data_factory_pipeline_run_resource azure_data_factory_pipeline_run_resources
azure_data_lake_storage_gen2_filesystem azure_data_lake_storage_gen2_filesystems
azure_data_lake_storage_gen2_path azure_data_lake_storage_gen2_paths
azure_db_migration_service azure_db_migration_services
azure_ddos_protection_resource azure_ddos_protection_resources
azure_dns_zones_resource azure_dns_zones_resources
azure_event_hub_authorization_rule No Plural Resource
azure_event_hub_event_hub No Plural Resource
azure_event_hub_namespace No Plural Resource
azure_express_route_circuit azure_express_route_circuits
No Singular Resource azure_express_route_providers
azure_graph_user azure_graph_users
azure_hdinsight_cluster No Plural Resource
azure_hpc_asc_operation No Plural Resource
azure_hpc_cache azure_hpc_caches
azure_hpc_storage_target azure_hpc_storage_targets
azure_iothub No Plural Resource
azure_iothub_event_hub_consumer_group azure_iothub_event_hub_consumer_groups
azure_key_vault azure_key_vaults
azure_key_vault_key azure_key_vault_keys
azure_key_vault_secret azure_key_vault_secrets
azure_load_balancer azure_load_balancers
azure_lock azure_locks
azure_managed_application azure_managed_applications
azure_management_group azure_management_groups
azure_mariadb_server azure_mariadb_servers
azure_microsoft_defender_pricing azure_microsoft_defender_pricings
azure_microsoft_defender_security_contact No Plural Resource
azure_microsoft_defender_setting azure_microsoft_defender_settings
azure_migrate_assessment azure_migrate_assessments
azure_migrate_assessment_group azure_migrate_assessment_groups
azure_migrate_project No Plural Resource
azure_migrate_project_database azure_migrate_project_databases
azure_migrate_project_database_instance azure_migrate_project_database_instances
azure_migrate_project_event azure_migrate_project_events
azure_migrate_project_machine azure_migrate_project_machines
azure_migrate_assessment_project azure_migrate_assessment_projects
azure_migrate_project_solution azure_migrate_project_solutions
azure_monitor_activity_log_alert azure_monitor_activity_log_alerts
azure_monitor_log_profile azure_monitor_log_profiles
azure_mysql_database azure_mysql_databases
azure_mysql_server azure_mysql_servers
azure_mysql_server_configuration azure_mysql_server_configurations
azure_network_interface azure_network_interfaces
azure_network_security_group azure_network_security_groups
azure_network_watcher azure_network_watchers
No Singular Resource azure_policy_assignments
azure_policy_definition azure_policy_definitions
azure_policy_exemption azure_policy_exemptions
azure_policy_insights_query_result azure_policy_insights_query_results
azure_postgresql_database azure_postgresql_databases
azure_postgresql_server azure_postgresql_servers
azure_power_bi_app azure_power_bi_apps
azure_power_bi_app_dashboard azure_power_bi_app_dashboards
azure_power_bi_app_dashboard_tile azure_power_bi_app_dashboard_tiles
azure_power_bi_app_report azure_power_bi_app_reports
No Singular Resource azure_power_bi_capacities
azure_power_bi_capacity_refreshable azure_power_bi_capacity_refreshables
azure_power_bi_capacity_workload azure_power_bi_capacity_workloads
azure_power_bi_dataflow azure_power_bi_dataflows
No Singular Resource azure_power_bi_dataflow_storage_accounts
azure_power_bi_dataset azure_power_bi_datasets
No Singular Resource azure_power_bi_dataset_datasources
azure_power_bi_embedded_capacity azure_power_bi_embedded_capacities
azure_power_bi_gateway azure_power_bi_gateways
No Singular Resource azure_power_bi_generic_resources
azure_public_ip No Plural Resource
azure_redis_cache azure_redis_caches
azure_resource_group azure_resource_groups
azure_resource_health_availability_status azure_resource_health_availability_statuses
azure_resource_health_emerging_issue azure_resource_health_emerging_issues
No Singular Resource azure_resource_health_events
azure_role_definition azure_role_definitions
azure_security_center_policy azure_security_center_policies
azure_service_bus_namespace azure_service_bus_namespaces
No Singular Resource azure_service_bus_regions
azure_service_bus_subscription azure_service_bus_subscriptions
azure_service_bus_subscription_rule azure_service_bus_subscription_rules
azure_service_bus_topic azure_service_bus_topics
azure_service_fabric_mesh_application azure_service_fabric_mesh_applications
azure_service_fabric_mesh_network azure_service_fabric_mesh_networks
azure_service_fabric_mesh_replica azure_service_fabric_mesh_replicas
azure_service_fabric_mesh_service azure_service_fabric_mesh_services
azure_service_fabric_mesh_volume azure_service_fabric_mesh_volumes
azure_snapshot azure_snapshots
azure_sql_database azure_sql_databases
azure_sql_database_server_vulnerability_assessment azure_sql_database_server_vulnerability_assessments
azure_sql_managed_instance azure_sql_managed_instances
azure_sql_server azure_sql_servers
azure_sql_virtual_machine azure_sql_virtual_machines
azure_sql_virtual_machine_group azure_sql_virtual_machine_groups
azure_sql_virtual_machine_group_availability_listener azure_sql_virtual_machine_group_availability_listeners
azure_storage_account_blob_container azure_storage_account_blob_containers
azure_storage_account azure_storage_accounts
azure_streaming_analytics_function azure_streaming_analytics_functions
azure_subnet azure_subnets
azure_subscription azure_subscriptions
azure_synapse_notebook azure_synapse_notebooks
azure_synapse_workspace azure_synapse_workspaces
azure_virtual_machine azure_virtual_machines
azure_virtual_machine_disk azure_virtual_machine_disks
azure_virtual_network azure_virtual_networks
azure_virtual_network_gateway azure_virtual_network_gateways
azure_virtual_network_gateway_connection azure_virtual_network_gateway_connections
azure_virtual_network_peering azure_virtual_network_peerings
azure_virtual_wan azure_virtual_wans
azure_web_app_function azure_web_app_functions
azure_webapp azure_webapps

Please refer to the specific resource pages for more details and different use cases.

Examples

Ensure that all resources have specified names within the subscription regardless of type and resource Group

azure_generic_resources(substring_of_name: 'NAME').ids.each do |id|
  describe azure_generic_resource(resource_id: id) do
    its('location') { should eq 'eastus' }
  end
end

Ensure all resources has a specified tag defined regardless of the value

azure_generic_resources(tag_name: 'NAME').ids.each do |id|
  describe azure_generic_resource(resource_id: id) do
    its('location') { should eq 'eastus' }
  end
end

Verify Properties of an Azure Virtual Machine

describe azure_virtual_machine(resource_group: 'RESOURCE_GROUP', name: 'NAME-WEB-01') do
  it { should exist }
  it { should have_monitoring_agent_installed }
  it { should_not have_endpoint_protection_installed([]) }
  it { should have_only_approved_extensions(['MicrosoftMonitoringAgent']) }
  its('type') { should eq 'Microsoft.Compute/virtualMachines' }
  its('installed_extensions_types') { should include('MicrosoftMonitoringAgent') }
  its('installed_extensions_names') { should include('LogAnalytics') }
end

Verify Properties of a Network Security Group

describe azure_network_security_group(resource_group: 'RESOURCE_GROUP', name: 'NAME-SERVER') do
  it { should exist }
  its('type') { should eq 'Microsoft.Network/networkSecurityGroups' }
  its('security_rules') { should_not be_empty }
  its('default_security_rules') { should_not be_empty }
  it { should_not allow_rdp_from_internet }
  it { should_not allow_ssh_from_internet }
  it { should allow(source_ip_range: '0.0.0.0', destination_port: '22', direction: 'inbound') }
  it { should allow_in(service_tag: 'Internet', port: %w{1433-1434 1521 4300-4350 5000-6000}) }
end

Parameters Applicable To All Resources

The generic resources and their derivations support the following parameters unless stated otherwise on their specific resource page.

api_version

As an Azure resource provider enables new features, it releases a new version of the REST API. They are generally in the format of 2020-01-01. InSpec Azure resources can be forced to use a specific version of the API to eliminate the behavioral changes between the tests using different API versions. The latest version is used unless a specific version is provided.

User-Provided API Version

describe azure_virtual_machine(resource_group: 'RESOURCE_GROUP', name: 'NAME', api_version: '2020-01-01') do
  its('api_version_used_for_query_state') { should eq 'user_provided' }
  its('api_version_used_for_query') { should eq '2020-01-01' }
end

Pre-defined Default Api Version

DEFAULT api version can be used, if it is supported by the resource provider.

describe azure_generic_resource(resource_provider: 'Microsoft.Compute/virtualMachines', name: 'NAME', api_version: 'DEFAULT') do
  its('api_version_used_for_query_state') { should eq 'DEFAULT' }
end

Latest API Version

LATEST version is determined by this resource pack within the supported API versions. If the latest version is a preview, than an older, but a stable version might be used. Explicitly forcing to use the LATEST version.

describe azure_virtual_networks(api_version: 'LATEST') do
  its('api_version_used_for_query_state') { should eq 'LATEST' }
end

LATEST version is used unless provided (Implicit).

describe azure_network_security_groups(resource_group: 'RESOURCE_GROUP') do
  its('api_version_used_for_query_state') { should eq 'LATEST' }
end

LATEST version is used if the provided is invalid.

describe azure_network_security_groups(resource_group: 'RESOURCE_GROUP', api_version: 'invalid_api_version') do
  its('api_version_used_for_query_state') { should eq 'LATEST' }
end

endpoint

Microsoft Azure cloud services are available through a global and three national networks of the datacenter as described here. The preferred data center can be defined via endpoint parameter. Azure Global Cloud is used if not provided.

  • azure_cloud (default)
  • azure_china_cloud
  • azure_us_government_L4
  • azure_us_government_L5
  • azure_german_cloud
describe azure_virtual_machines(endpoint: 'azure_german_cloud') do
  it { should exist }
end

It can be defined as an environment variable or a resource parameter (has priority).

The pre-defined environment variables for each cloud deployment can be found here.

http_client parameters

The behavior of the HTTP client can be defined with the following parameters:

  • azure_retry_limit: Maximum number of retries (default - 2, Integer).
  • azure_retry_backoff: Pause in seconds between retries (default - 0, Integer).
  • azure_retry_backoff_factor: The amount to multiply each successive retries interval amount by (default - 1, Integer).

They can be defined as environment variables or resource parameters (has priority).


WARNING The following resources are using their azure_ counterparts under the hood, and they will be deprecated in the InSpec Azure version 2. Their API versions are fixed (see below) for full backward compatibility. It is strongly advised to start using the resources with azure_ prefix for an up-to-date testing experience.

Legacy Resource Name Fixed API version Replaced by
azurerm_ad_user, azurerm_ad_users v1.0 azure_graph_user, azure_graph_users
azurerm_aks_cluster, azurerm_aks_clusters 2018-03-31 azure_aks_cluster, azure_aks_cluster
azurerm_api_management, azurerm_api_managements 2019-12-01 azure_api_management, azure_api_managements
azurerm_application_gateway, azurerm_application_gateways 2019-12-01 azure_application_gateway, azure_application_gateways
azurerm_cosmosdb_database_account 2015-04-08 azure_cosmosdb_database_account
azurerm_event_hub_authorization_rule 2017-04-01 azure_event_hub_authorization_rule
azurerm_event_hub_event_hub 2017-04-01 azure_event_hub_event_hub
azurerm_event_hub_namespace 2017-04-01 azure_event_hub_namespace
azurerm_hdinsight_cluster 2015-03-01-preview azure_hdinsight_cluster
azurerm_iothub 2018-04-01 azure_iothub
azurerm_iothub_event_hub_consumer_group, azurerm_iothub_event_hub_consumer_groups 2018-04-01 azure_iothub_event_hub_consumer_group, azure_iothub_event_hub_consumer_groups
azurerm_key_vault, azurerm_key_vaults 2016-10-01 azure_key_vault, azure_key_vaults
azurerm_key_vault_key, azurerm_key_vault_keys 2016-10-01 azure_key_vault_key, azure_key_vault_keys
azurerm_key_vault_secret, azurerm_key_vault_secrets 2016-10-01 azure_key_vault_secret, azure_key_vault_secrets
azurerm_load_balancer, azurerm_load_balancers 2018-11-01 azure_load_balancer, azure_load_balancers
azurerm_locks 2016-09-01 azure_locks
azurerm_management_group, azurerm_management_groups 2018-03-01-preview azure_management_group, azure_management_groups
azurerm_mariadb_server, azurerm_mariadb_servers 2018-06-01-preview azure_mariadb_server, azure_mariadb_servers
azurerm_monitor_activity_log_alert, azurerm_monitor_activity_log_alerts 2017-04-01 azure_monitor_activity_log_alert, azure_monitor_activity_log_alerts
azurerm_monitor_log_profile, azurerm_monitor_log_profiles 2016-03-01 azure_monitor_log_profile, azure_monitor_log_profiles
azurerm_mysql_database, azurerm_mysql_databases 2017-12-01 azure_mysql_database, azure_mysql_databases
azurerm_mysql_server, azurerm_mysql_servers 2017-12-01 azure_mysql_server, azure_mysql_servers
azurerm_network_interface, azurerm_network_interfaces 2018-11-01 azure_network_interface, azure_network_interfaces
azurerm_network_security_group, azurerm_network_security_groups 2018-02-01 azure_network_security_group, azure_network_security_groups
azurerm_network_watcher, azurerm_network_watchers 2018-02-01 azure_network_watcher, azure_network_watchers
azurerm_postgresql_database, azurerm_postgresql_databases 2017-12-01 azure_postgresql_database, azure_postgresql_databases
azurerm_postgresql_server, azurerm_postgresql_servers 2017-12-01 azure_postgresql_server, azure_postgresql_servers
azurerm_public_ip 2020-05-01 azure_public_ip
azurerm_resource_groups 2018-02-01 azure_resource_groups
azurerm_role_definition, azurerm_role_definitions 2015-07-01 azure_role_definition, azure_role_definitions
azurerm_security_center_policy, azurerm_security_center_policies 2015-06-01-Preview azure_security_center_policy, azure_security_center_policies
azurerm_sql_database, azurerm_sql_databases 2017-10-01-preview azure_sql_database, azure_sql_databases
azurerm_sql_server, azurerm_sql_servers 2018-06-01-preview azure_sql_server, azure_sql_servers
azurerm_storage_account, azurerm_storage_accounts 2017-06-01 azure_storage_account, azure_storage_accounts
azurerm_storage_account_blob_container, azurerm_storage_account_blob_containers 2018-07-01 azure_storage_account_blob_container, azure_storage_account_blob_containers
azurerm_subnet, azurerm_subnets 2018-02-01 azure_subnet, azure_subnets
azurerm_subscription 2019-10-01 azure_subscription
azurerm_virtual_machine, azurerm_virtual_machines 2017-12-01 azure_virtual_machine, azure_virtual_machines
azurerm_virtual_machine_disk, azurerm_virtual_machine_disks 2017-03-30 azure_virtual_machine_disk, azure_virtual_machine_disks
azurerm_virtual_network, azurerm_virtual_networks 2018-02-01 azure_virtual_network, azure_virtual_networks
azurerm_webapp, azurerm_webapps 2016-08-01 azure_webapp, azure_webapps

Development

If you would like to contribute to this project, please see Contributing Rules.

For a detailed walk-through of resource creation, see the Resource Creation Guide.

Developing a Static Resource

The static resource is an InSpec Azure resource that is used to interrogate a specific Azure resource, such as, azure_virtual_machine, azure_key_vaults. As opposed to the generic resources, they might have some static properties created by processing the dynamic properties of a resource, such as azure_virtual_machine.admin_username.

The easiest way to start by checking the existing static resources. They have detailed information on leveraging the backend class within their comments.

The common parameters are:

  • resource_provider: Such as Microsoft.Compute/virtualMachines. It has to be hardcoded in the code by the resource author via the specific_resource_constraint method, and it should be the first parameter defined in the resource. This method includes user-supplied input validation.
  • display_name: A generic one will be created unless defined.
  • required_parameters: Define mandatory parameters. The resource_group and resource name in the singular resources are default mandatory in the base class.
  • allowed_parameters: Define optional parameters. The resource_group is optional in plural resources, but this can be made mandatory in the static resource.
  • resource_uri: Azure REST API URI of a resource. This parameter should be used when a resource does not reside in a resource group. It requires add_subscription_id to be set to either true or false. See azure_policy_definition and azure_policy_definitions.
  • add_subscription_id: It indicates whether the subscription ID should be included in the resource_uri or not.

Singular Resources

The singular resource is used to test a specific resource of a specific type and should include all of the properties available, such as azure_virtual_machine.

  • In most cases, resource_group and resource name should be required from the users, and a single API call would be enough for creating methods on the resource. See azure_virtual_machine for a standard singular resource and how to create static methods from resource properties.
  • If it is beneficial to accept the resource name with a more specific keyword, such as server_name, see azure_mysql_server.
  • If a resource exists in another resource, such as a subnet on a virtual network, see azure_subnet.
  • If it is necessary to make an additional API call within a static method, the create_additional_properties should be used. See azure_key_vault.

Plural Resources

A plural resource is used to test the collection of resources of a specific type, such as, azure_virtual_machines. This allows for tests to be written based on the group of resources.

  • A standard plural resource does not require a parameter, except optional resource_group. See azure_mysql_servers.
  • All plural resources use FilterTable to be able to provide filtering within returned resources. The filter criteria must be defined table_schema Hash variable.
  • If the properties of the resource are to be manipulated before populating the FilterTable, a populate_table method has to be defined. See azure_virtual_machines.
  • If the resources exist in another resource, such as subnets of a virtual network, a resource_path has to be created. For that, the identifiers of the parent resource, resource_group and virtual network name vnet, must be required from the users. See azure_subnets.

Setting the Environment Variables

The following instructions helps you get your development environment setup to run integration tests.

Copy .envrc-example to .envrc and fill in the fields with the values from your account.

export AZURE_SUBSCRIPTION_ID=<subscription id>
export AZURE_CLIENT_ID=<client id>
export AZURE_TENANT_ID=<tenant id>
export AZURE_CLIENT_SECRET=<client secret>

For PowerShell, set the following environment variables.

$env:AZURE_SUBSCRIPTION_ID="<subscription id>"
$env:AZURE_CLIENT_ID="<client id>"
$env:AZURE_CLIENT_SECRET="<client secret>"
$env:AZURE_TENANT_ID="<tenant id>"

in order to run tests along with mock train URI

export RAKE_ENV=test

Setup Azure CLI

  • Follow the instructions for your platform here
    • macOS: brew update && brew install azure-cli
  • Login with the azure-cli
    • rake azure:login
  • Verify azure-cli is logged in:
    • az account show

Starting an Environment

First, ensure your system has Terraform installed.

This environment may be used to run your profile against or to run integration tests on it. We are using Terraform workspaces to allow teams to have unique environments without affecting each other.

Direnv

Direnv is used to initialize an environment variable WORKSPACE to your username. We recommend using direnv and allowing it to run in your environment. However, if you prefer to not use direnv you may also source .envrc.

Rake Commands

Creating a new environment:

rake azure:login
rake tf:apply

Updating a running environment (For example, when you change the .tf file):

rake tf:apply

Checking if your state has diverged from your plan:

rake tf:plan

Destroying your environment:

rake tf:destroy

To run Rubocop and Syntax, check for Ruby and InSpec:

rake test:lint

To run unit tests:

rake test:unit

To run integration tests:

rake test:integration

Please note that Graph API resource requires specific privileges granted to your service principal.

Please refer to the Microsoft Documentation for information on how to grant these permissions to your application.

To run a control called azure_virtual_machine only:

rake test:integration[azurerm_virtual_machine]

Note that in zsh you need to escape the [, ] characters.

You may run selected multiple controls only:

rake test:integration[azure_aks_cluster,azure_virtual_machine]

To run lint and unit tests:

rake

Optional Components

The creation of the following resources can be skipped if there are any resource constraints.

  • Network Watcher
rake tf:apply[network_watcher]
  • HDinsight Interactive Query Cluster
rake tf:apply[hdinsight_cluster]
  • Public IP
rake tf:apply[public_ip]
  • API Management
rake tf:apply[api_management]
  • Management Group
rake tf:apply[management_group]

A combination of the above can be provided.

rake tf:apply[management_group,public_ip,network_watcher]

inspec-azure's People

Contributors

chef-ci avatar chris-rock avatar clintoncwolfe avatar dependabot-preview[bot] avatar dependabot[bot] avatar dkumaras avatar dmccown avatar dwizzle204 avatar gsreynolds avatar ianmadd avatar jasonwbarnett avatar jayashrig158 avatar jnikles1 avatar joemccsap avatar miah avatar mikaelkrief avatar nirbhay1997 avatar ppradhan9 avatar pwelch avatar rmoles avatar russellseymour avatar sa-progress avatar samir-progress avatar sathish-progress avatar skelleyton avatar soumyo13 avatar tduffield avatar thelunaticscripter avatar trevorbramble avatar voojoe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

inspec-azure's Issues

Cannot determine the return for a filter

After having created a new resource for data disks I have tried to use it with a control such as:

  describe azure_vm_datadisks(host: 'AutomateServer-VM', resource_group: 'rjs-automate-09').where { (disk == 1 and size >= 10) } do
    it { should be true }
  end

However there is an error from Inspec when trying to use this:

 ×  azure-vm-datadisks-1.0: Ensure that the machine has 1 data disk of greater than or equal to 10gb (
     expected true
          got #<#<Class:0x007fa8c6a50db8>:70181433717000> => azure_vm_datadisks with disk == 1 size >= 10
     )
     ×  azure_vm_datadisks with disk == 1 size >= 10 should equal true

     expected true
          got #<#<Class:0x007fa8c6a50db8>:70181433717000> => azure_vm_datadisks with disk == 1 size >= 10

I am not sure where the #<#<Class... is coming from and I do not know how to inspect the result for the test.

I have created a FilterTable for this and connected it to the parameters for the hashtable for the data disks. https://github.com/chef/inspec-azure/blob/russellseymour/data-disks/libraries/azure_vm_datadisks.rb#L33-L44

env variables azure_backend.rb library issue, if credential file not present

I run into this issue passing Azure SPN credential via environment variables. I don't have any credential file into ~/.azure folder as did set up the following env variables:

export AZURE_SUBSCRIPTION_ID="<value>" 
export AZURE_CLIENT_ID="<value>" 
export AZURE_CLIENT_SECRET="<value>" 
export AZURE_TENANT_ID="<value>"

I am on Ubuntu 16.04, Inspec 1.26.0, Ruby 2.4.1p111.

Error:

Please report a bug if this causes problems.
/home/vagrant/.azure/credentials was not found or not accessible
libraries/azure_backend.rb:59:in `spn': undefined method `sections' for nil:NilClass (NoMethodError)
	from libraries/azure_backend.rb:43:in `connection'
	from libraries/azure_backend.rb:217:in `initialize'
	from libraries/azure_backend.rb:121:in `new'
	from libraries/azure_backend.rb:121:in `initialize'
	from libraries/azure_resource_group.rb:35:in `new'
	from libraries/azure_resource_group.rb:35:in `initialize'
	from /usr/local/lib/ruby/gems/2.4.0/gems/inspec-1.26.0/lib/inspec/plugins/resource.rb:47:in `initialize'
	from /usr/local/lib/ruby/gems/2.4.0/gems/inspec-1.26.0/lib/inspec/resource.rb:48:in `new'
	from /usr/local/lib/ruby/gems/2.4.0/gems/inspec-1.26.0/lib/inspec/resource.rb:48:in `block (3 levels) in create_dsl'
	from startup-compliance/controls/resource_groups.rb:12:in `block in load_with_context'
	from /usr/local/lib/ruby/gems/2.4.0/gems/inspec-1.26.0/lib/inspec/rule.rb:50:in `instance_eval'
	from /usr/local/lib/ruby/gems/2.4.0/gems/inspec-1.26.0/lib/inspec/rule.rb:50:in `initialize'
	from /usr/local/lib/ruby/gems/2.4.0/gems/inspec-1.26.0/lib/inspec/control_eval_context.rb:71:in `new'
	from /usr/local/lib/ruby/gems/2.4.0/gems/inspec-1.26.0/lib/inspec/control_eval_context.rb:71:in `block (2 levels) in create'
	from startup-compliance/controls/resource_groups.rb:7:in `load_with_context'
	from /usr/local/lib/ruby/gems/2.4.0/gems/inspec-1.26.0/lib/inspec/profile_context.rb:146:in `instance_eval'
	from /usr/local/lib/ruby/gems/2.4.0/gems/inspec-1.26.0/lib/inspec/profile_context.rb:146:in `load_with_context'
	from /usr/local/lib/ruby/gems/2.4.0/gems/inspec-1.26.0/lib/inspec/profile_context.rb:130:in `load_control_file'
	from /usr/local/lib/ruby/gems/2.4.0/gems/inspec-1.26.0/lib/inspec/profile.rb:151:in `block in collect_tests'
	from /usr/local/lib/ruby/gems/2.4.0/gems/inspec-1.26.0/lib/inspec/profile.rb:148:in `each'
	from /usr/local/lib/ruby/gems/2.4.0/gems/inspec-1.26.0/lib/inspec/profile.rb:148:in `collect_tests'
	from /usr/local/lib/ruby/gems/2.4.0/gems/inspec-1.26.0/lib/inspec/runner.rb:90:in `block in load'
	from /usr/local/lib/ruby/gems/2.4.0/gems/inspec-1.26.0/lib/inspec/runner.rb:79:in `each'
	from /usr/local/lib/ruby/gems/2.4.0/gems/inspec-1.26.0/lib/inspec/runner.rb:79:in `load'
	from /usr/local/lib/ruby/gems/2.4.0/gems/inspec-1.26.0/lib/inspec/runner.rb:100:in `run'
	from /usr/local/lib/ruby/gems/2.4.0/gems/inspec-1.26.0/lib/inspec/base_cli.rb:83:in `run_tests'
	from /usr/local/lib/ruby/gems/2.4.0/gems/inspec-1.26.0/lib/inspec/cli.rb:159:in `exec'
	from /home/vagrant/.gem/ruby/2.4.0/gems/thor-0.19.4/lib/thor/command.rb:27:in `run'
	from /home/vagrant/.gem/ruby/2.4.0/gems/thor-0.19.4/lib/thor/invocation.rb:126:in `invoke_command'
	from /home/vagrant/.gem/ruby/2.4.0/gems/thor-0.19.4/lib/thor.rb:369:in `dispatch'
	from /home/vagrant/.gem/ruby/2.4.0/gems/thor-0.19.4/lib/thor/base.rb:444:in `start'
	from /usr/local/lib/ruby/gems/2.4.0/gems/inspec-1.26.0/bin/inspec:12:in `<top (required)>'
	from /home/vagrant/.gem/ruby/2.4.0/bin/inspec:22:in `load'
	from /home/vagrant/.gem/ruby/2.4.0/bin/inspec:22:in `<main>'

What am I doing wrong?

Add a suffix to the domain name when the Public IP Address is created in Terraform

Each domain name that is assigned to a Public IP Address in Azure must be unique within the region.

The current string is linux-external-1 which is a fairly common string and can lead to clashes when the address is provisioned.

To resolve this a suffix should be added to the end of the domain name, e.g. linux-external-1-xxxx.

README implies Terraform is required

As this project moves from a development project to a user-facing repository of resources, we need to make sure the README makes sense to multiple audiences. One confusing point to me was the matter of Terraform and Direnv; if I were a user with an existing Azure infra I wanted to test, would I need to setup Terraform, manage workspaces, remote state, etc?

Rename the azure_rg resource

The azure_rg resource could possibly be less than obvious as to what it does.

It is responsible for checking that the correct resources are in Azure after deployment. It is not necessarily to do with Resource Groups.

The two options for the name are:

  1. azure_resources
  2. azure_resource_group

Specify the subscription to be used by index

The resource pack allows a subscription to be selected from the credentials file using the AZURE_SUBSCRIPTION_ID.

This is to allow an index to be specified instead of the actual ID. This will be AZURE_SUBSCRIPTION_INDEX.

Add integration tests

As there are no controls provided by this resource pack, the integration tests can be used to ensure that all the libraries are working correctly.

Fix how internal libraries are loaded

require_relative is being used to load files that are required by the Helpers class. However when used in an Inspec test this is resolving to the current project and not the files within the Azure resource pack.

Document adding new services

We should document what we learned from connecting our resource pack to the Graph API for contributors that wish to connect to other services, such as key vault.

Test output does not contain name of the test

When running the following for example:

  describe azure_vm(host: 'Linux-Internal-VM', resource_group: 'Inspec-Azure') do
    its('sku') { should eq '16.04.0-LTS' }
    its('publisher') { should eq 'Canonical' }
    its('offer') { should eq 'UbuntuServer' }
    its('size') { should eq 'Standard_DS2_v2' }
    its('location') { should eq 'westeurope' }
    its('boot_diagnostics?') { should be false }
    its('nic_count') { should eq 1 }
    its('username') { should eq 'azure' }
    its('password_authentication?') { should be true }
    its('ssh_key_count') { should eq 0 }
    its('os_type') { should eq 'Linux' }  
  end

The output is:

 azure_vm sku
     ✔  should eq "16.04.0-LTS"
     ✔  should eq "Canonical"
     ✔  should eq "UbuntuServer"
     ✔  should eq "Standard_DS2_v2"
     ✔  should eq "westeurope"
     ✔  should equal false
     ✔  should eq 1
     ✔  should eq "azure"
     ✔  should equal true
     ✔  should eq 0
     ✔  should eq "Linux"

Although each of the tests are passing, there is no indication as to what it was. For example, what does this mean?

✔ should eq 1

By elimination it is checking that the username is azure but this was when interpreted with the tests as well. The name of what is being tested should be displayed as well.

Incomplete README on how to get started using this lib

I have set up my inspec profile as you recommended:

name: acceptance-tests
...
depends:
  - name: azure
    url: https://github.com/chef/inspec-azure/archive/master.tar.gz

However when I execute the tests inspec exec . I get the error below:

/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- ms_rest_azure (LoadError)
  from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
  from /var/lib/gems/2.3.0/gems/inspec-1.33.1/lib/inspec/dsl_shared.rb:14:in `require'
  from libraries/azure_backend.rb:1:in `load_with_context'
  ...
  from /usr/local/bin/inspec:23:in `load'
  from /usr/local/bin/inspec:23:in `<main>'

That's because Inspec can't find the required file ms_rest_azure on your azure_backend.rb. Indeed, I searched your git repo and there's no file with that name.

It seems you include some dependencies on your Gemfile, but what am I supposed to do? On your readme you only mention adding the depends/url to the inspec profile... what am I missing?

Add resources for checking the VM

Update the azure_vm resource so that the following checks can be performed:

  • vm size
  • location
  • boot diagnostics enabled?
  • nic count
  • username

`client': uninitialized constant Azure::Resources (NameError) -- After recent changes

Hello Dear,

I was able to use the resource pack and could connect to azure vm's and tests there resources before recent updates & new commits.

However the moment I pulled the new code, my profile is failing with below errors. I have tried setting up credentials file at ~/.azure/credentials, also have tried adding required credentials as environment variables in my mac. Not sure what's going wrong it keep's throwing below error:
Is there a problem with recent check-ins ?

WARN: Unresolved specs during Gem::Specification.reset:
rake (>= 0)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
libraries/azure_backend.rb:63:in client': uninitialized constant Azure::Resources (NameError) from libraries/azure_backend.rb:201:in initialize'
from libraries/azure_generic_resource.rb:16:in initialize' from /Users/tushard/.rvm/gems/ruby-2.4.1/gems/inspec-1.43.8/lib/inspec/plugins/resource.rb:47:in initialize'
from /Users/tushard/.rvm/gems/ruby-2.4.1/gems/inspec-1.43.8/lib/inspec/resource.rb:47:in new' from /Users/tushard/.rvm/gems/ruby-2.4.1/gems/inspec-1.43.8/lib/inspec/resource.rb:47:in block (3 levels) in create_dsl'
from inspec-azure-vm/controls/resources-check.rb:5:in block in load_with_context' from /Users/tushard/.rvm/gems/ruby-2.4.1/gems/inspec-1.43.8/lib/inspec/rule.rb:49:in instance_eval'
from /Users/tushard/.rvm/gems/ruby-2.4.1/gems/inspec-1.43.8/lib/inspec/rule.rb:49:in initialize' from /Users/tushard/.rvm/gems/ruby-2.4.1/gems/inspec-1.43.8/lib/inspec/control_eval_context.rb:73:in new'
from /Users/tushard/.rvm/gems/ruby-2.4.1/gems/inspec-1.43.8/lib/inspec/control_eval_context.rb:73:in block (2 levels) in create' from inspec-azure-vm/controls/resources-check.rb:1:in load_with_context'
from /Users/tushard/.rvm/gems/ruby-2.4.1/gems/inspec-1.43.8/lib/inspec/profile_context.rb:148:in instance_eval' from /Users/tushard/.rvm/gems/ruby-2.4.1/gems/inspec-1.43.8/lib/inspec/profile_context.rb:148:in load_with_context'
from /Users/tushard/.rvm/gems/ruby-2.4.1/gems/inspec-1.43.8/lib/inspec/profile_context.rb:132:in load_control_file' from /Users/tushard/.rvm/gems/ruby-2.4.1/gems/inspec-1.43.8/lib/inspec/profile.rb:160:in block in collect_tests'
from /Users/tushard/.rvm/gems/ruby-2.4.1/gems/inspec-1.43.8/lib/inspec/profile.rb:157:in each' from /Users/tushard/.rvm/gems/ruby-2.4.1/gems/inspec-1.43.8/lib/inspec/profile.rb:157:in collect_tests'
from /Users/tushard/.rvm/gems/ruby-2.4.1/gems/inspec-1.43.8/lib/inspec/runner.rb:89:in block in load' from /Users/tushard/.rvm/gems/ruby-2.4.1/gems/inspec-1.43.8/lib/inspec/runner.rb:78:in each'
from /Users/tushard/.rvm/gems/ruby-2.4.1/gems/inspec-1.43.8/lib/inspec/runner.rb:78:in load' from /Users/tushard/.rvm/gems/ruby-2.4.1/gems/inspec-1.43.8/lib/inspec/runner.rb:99:in run'
from /Users/tushard/.rvm/gems/ruby-2.4.1/gems/inspec-1.43.8/lib/inspec/base_cli.rb:83:in run_tests' from /Users/tushard/.rvm/gems/ruby-2.4.1/gems/inspec-1.43.8/lib/inspec/cli.rb:159:in exec'
from /Users/tushard/.rvm/gems/ruby-2.4.1/gems/thor-0.20.0/lib/thor/command.rb:27:in run' from /Users/tushard/.rvm/gems/ruby-2.4.1/gems/thor-0.20.0/lib/thor/invocation.rb:126:in invoke_command'
from /Users/tushard/.rvm/gems/ruby-2.4.1/gems/thor-0.20.0/lib/thor.rb:387:in dispatch' from /Users/tushard/.rvm/gems/ruby-2.4.1/gems/thor-0.20.0/lib/thor/base.rb:466:in start'
from /Users/tushard/.rvm/gems/ruby-2.4.1/gems/inspec-1.43.8/bin/inspec:12:in <top (required)>' from /Users/tushard/.rvm/gems/ruby-2.4.1/bin/inspec:23:in load'
from /Users/tushard/.rvm/gems/ruby-2.4.1/bin/inspec:23:in <main>' from /Users/tushard/.rvm/gems/ruby-2.4.1/bin/ruby_executable_hooks:15:in eval'
from /Users/tushard/.rvm/gems/ruby-2.4.1/bin/ruby_executable_hooks:15:in `

'

No Graph API access prevents terraform from running

Description of Issue

If you attempt to start a Terraform environment without having permissions to the Graph API your Terraform task will fail with an error "Insufficient Permissions". We should make Graph an optional configuration item so someone is not blocked if they don't have permissions while developing new resources.

At the moment we have optional features in Terraform:

  • msi_vm
  • network_watcher

What would be a good interface to allow someone to opt into additional components depending on what they are testing without needing a huge rake command.

If we were to follow the existing pattern we would have something like:

$ rake network_watcher graph tf:apply test:integration

Proposals

Consolidated rake task

$ rake with[network_watcher,graph,msi_vm,etc] # modifies .envrc
$ source .envrc # or direnv allow
$ rake tf:apply
$ rake test:integration
$ rake with[] # modifies .envrc to remove all optional components
$ source .envrc # or direnv allow

This task could modify your .envrc file to add any optional components to your configuration. We could then output something on other rake tasks to output which optional components you are using. As well as noting that tests will be skipped for any optional components you aren't using.

By default all optional components would be disabled.

Other ideas

Are there other ideas that would be a better user experience and provide clarity around what components you have enabled/disabled?

Remove Azure resource class helpers

Helper methods have been created for the certain Azure classes.

However as more are being added, these will become too numerous to manage effectively.

So methods will exist that will return the client for each class so it can be used directly

azure_generic_resource gives unreliable results

🎛 I believe this resource is evaluating properties of the resource group and returning a false positive when your trying to evaluate a resource within that group.

is this a 🐛 bug report

Briefly describe the issue and the expected behavior

🌍 InSpec and Platform Version

inspec version 2.1.83 on OSX 10.13.4

🤔 Replication Case

control 'foobar' do
  title 'foobar'
  describe azure_generic_resource(group_name: '<existing resource group>, name: 'foobar') do
    it { should exist }
    its('location') { should cmp 'eastus' }
    its('provisioning_state') { should cmp 'Succeeded' }

    its('properties.addressSpace.addressPrefixes') { should cmp '10.6.8.0/22' }
    its('properties.dhcpOptions.dnsServers') { should cmp ["10.6.8.4", "168.63.129.16"] }
    it { should have_tags }
    its ('Environment_tag') { should cmp 'prod'}
    its ('ManagedBy_tag') { should cmp 'Terraform'}
    its ('Project_tag') { should cmp 'infra'}
  end
end

foobar: foobar (2 failed)
✔ azure_generic_resource should exist
✔ azure_generic_resource should have tags
✔ azure_generic_resource location should cmp == "eastus"
✔ azure_generic_resource provisioning_state should cmp == "Succeeded"
× azure_generic_resource properties.addressSpace.addressPrefixes
undefined method addressSpace' for []:Array × azure_generic_resource properties.dhcpOptions.dnsServers undefined method dhcpOptions' for []:Array
✔ azure_generic_resource Environment_tag should cmp == "prod"
✔ azure_generic_resource ManagedBy_tag should cmp == "Terraform"
✔ azure_generic_resource Project_tag should cmp == "infra"

Since the resource foobar doesn't exist in the resource group, all of those tests should fail, but only the two referencing the specific properties fail.

The documentation here: https://www.inspec.io/docs/reference/resources/azure_generic_resource/ at says that the tag and location tests should at least be usable but both return as successful even when the resource doesn't exist.

💁 Possible Solutions

I currently don't know of a solution other then to no use those tests, but in that case this becomes a lot more restrictive, and prone to false positives, and the documentation should be updated to reflect this.

💻 Stacktrace

Add resources to check security policies

  • Check that a policy is active
  • Check that resources adhere to the policy (in the case of somebody turning off the policy, making a change, then turning it back on again)

Document supported connection strategies

We need some documentation on the different ways we handle the needed Azure properties in order to connect. I'd like to see documentation for the following methods:

  1. Credentials file
  2. Environment variables
  3. MSI Port

Opt in to using network watcher

When we spin up a test environment we automatically get a network watcher in Azure, but due to Azure limitations we may only have one per a resource group per subscription. Let's figure out a way to make that something you need to opt in to start up so we can work concurrently.

azure_generic_resource resource: Should have better handling when item not found

Description

When using azure_generic_resource with a name: that does not exist, the user is presented with a least one false positive and several Ruby undefined_method error messages.

Example control:

control 'azure_vm_example' do
  title 'Ensure the example VM matches expectations'
  impact 1.0

  describe azure_generic_resource(group_name: 'Inspec-Azure', name: 'NOT-VALID') do
    # Ensure the VM is located in the correct region
    its('location') { should cmp 'westeurope' }

    # Ensure the VM has tags
    it { should_not have_tags }

    # Ensure the VM has the correct image
    its('properties.storageProfile.imageReference.publisher') { should cmp 'MicrosoftWindowsServer' }
    its('properties.storageProfile.imageReference.offer') { should cmp 'WindowsServer' }
    its('properties.storageProfile.imageReference.sku') { should cmp '2016-Datacenter' }

    # Ensure the VM has the correct size
    its('properties.hardwareProfile.vmSize') { should cmp 'Standard_DS2_v2' }

    # Ensure the VM has the correct authentication information
    its('properties.osProfile.computerName') { should eq 'win-internal-1' }
    its('properties.osProfile.adminUsername') { should eq 'azure' }
    its('properties.osProfile.windowsConfiguration.provisionVMAgent') { should be true }
    its('properties.osProfile.windowsConfiguration.enableAutomaticUpdates') { should be false }
  end
end

Example Output:


Profile: Azure Example Profile (profile-azure)
Version: 1.0.0
Target:  azure://REDACTED
�[38;5;9m  ×  azure_vm_example: Ensure the example VM matches expectations (9 failed)�[0m
�[38;5;9m     ×  azure_generic_resource should not have tags
     expected #has_tags? to return false, got true�[0m
�[38;5;41m     ✔  azure_generic_resource location should cmp == "westeurope"�[0m
�[38;5;9m     ×  azure_generic_resource properties.storageProfile.imageReference.publisher 
     undefined method `storageProfile' for []:Array�[0m
�[38;5;9m     ×  azure_generic_resource properties.storageProfile.imageReference.offer 
     undefined method `storageProfile' for []:Array�[0m
�[38;5;9m     ×  azure_generic_resource properties.storageProfile.imageReference.sku 
     undefined method `storageProfile' for []:Array�[0m
�[38;5;9m     ×  azure_generic_resource properties.hardwareProfile.vmSize 
     undefined method `hardwareProfile' for []:Array�[0m
�[38;5;9m     ×  azure_generic_resource properties.osProfile.computerName 
     undefined method `osProfile' for []:Array�[0m
�[38;5;9m     ×  azure_generic_resource properties.osProfile.adminUsername 
     undefined method `osProfile' for []:Array�[0m
�[38;5;9m     ×  azure_generic_resource properties.osProfile.windowsConfiguration.provisionVMAgent 
     undefined method `osProfile' for []:Array�[0m
�[38;5;9m     ×  azure_generic_resource properties.osProfile.windowsConfiguration.enableAutomaticUpdates 
     undefined method `osProfile' for []:Array�[0m


Profile Summary: 0 successful controls, �[38;5;9m1 control failure�[0m, 0 controls skipped
Test Summary: �[38;5;41m1 successful�[0m, �[38;5;9m9 failures�[0m, 0 skipped

InSpec and Platform Version

Platform: Arch Linux
InSpec: 2.0.4

Possible Solutions

Ensure that location fails and add better handling for when resource is not found.

How to update inspec-azure/libraries/support/azure/authentication.rb to add AzureGov Endpoints

Description

Error during execution is 'The subscription '12345678-1234-1234-1234-123456789012' could not be found.

Train and Platform Version

os RHEL7.5
inspec 2.2.20
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]

Replication Case

execute test

inspec exec ./test/integration/default -t azure:// -l=debug --diagnose

inspec profile check

  tag "Default Value": "Generic Resource Test at Azure Gov \n\n\n"
  describe azure_generic_resource(group_name: ENV.fetch('AZURE_RG'), name: 'vm') do
    its('location') { should eq 'usgovvirginia' }
  end

Possible Solutions

according to tcpdump, inspec performs lookups for azure instead of azuregov, verified ip addresses to which connection is made is the same address provided by dns resolution, assumption is made inspec is connecting to azure endpoints instead of azuregov

Stacktrace

https://gist.github.com/yarick/983adc75570948cd30cc4d40c028ee57

<script src="https://gist.github.com/yarick/983adc75570948cd30cc4d40c028ee57.js"></script>

inspec exec ./test/integration/default -t azure:// -l=debug --diagnose
InSpec version: 2.2.20
Train version: 1.4.15
Command line configuration:
{"target"=>"azure://", "log_level"=>"debug", "diagnose"=>true}
JSON configuration file:
{}
Merged configuration:
{"reporter"=>{"cli"=>{"stdout"=>true}},
"show_progress"=>false,
"color"=>true,
"create_lockfile"=>true,
"backend_cache"=>true,
"type"=>:exec,
"target"=>"azure://",
"log_level"=>"debug",
"diagnose"=>true}

[2018-06-26T11:18:33-04:00] DEBUG: Option backend_cache is enabled
[2018-06-26T11:18:33-04:00] DEBUG: Resolve ./test/integration/default into cache /root/.inspec/cache
[2018-06-26T11:18:33-04:00] DEBUG: Dependency does not exist in the cache ./test/integration/default
[2018-06-26T11:18:33-04:00] DEBUG: Starting run with targets: ["Inspec::Profile"]
[2018-06-26T11:18:33-04:00] DEBUG: Using existing lockfile ./test/integration/default/inspec.lock
[2018-06-26T11:18:33-04:00] DEBUG: Loading ./test/integration/default/controls/M-2.12.rb into #Inspec::ProfileContext:0x0000000003bb93f8
[DEPRECATED] use a specific azure resources instead of 'azure_generic_resource'. See inspec/inspec#3131
[2018-06-26T11:18:34-04:00] DEBUG: Registering rule M-2.12

Profile: AZURE Inspec Demo based on CIS_Microsoft_Azure_Foundations_Benchmark (azure-inspec-demo)
Version: 0.2
Target: azure://12345678-1234-1234-1234-123456789012

× M-2.12: 2.12 Ensure that 'JIT Network Access' is set to 'On' (Scored) (2 failed)
× azure_generic_resource
The subscription '12345678-1234-1234-1234-123456789012' could not be found.
× azure_resource_group
The subscription '12345678-1234-1234-1234-123456789012' could not be found.

Profile Summary: 0 successful controls, 1 control failure, 0 controls skipped
Test Summary: 0 successful, 2 failures, 0 skipped

Peg Azure SDKs to version 0.14

Microsoft have added some breaking changes to the Azure SDKs 0.15 which means this plugin will not work with that version.

As a quick workaround the SDKs should be pinned to version 0.14 to allow it to keep working in the short term.

Azure Government Endpoints are not working

Description

Error during execution is 'The subscription '12345678-1234-1234-1234-123456789012' could not be found.

Train and Platform Version

os RHEL7.5
inspec 2.2.20
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]

Replication Case

execute test

inspec exec ./test/integration/default -t azure:// -l=debug --diagnose

inspec profile check

  tag "Default Value": "Generic Resource Test at Azure Gov \n\n\n"
  describe azure_generic_resource(group_name: ENV.fetch('AZURE_RG'), name: 'vm') do
    its('location') { should eq 'usgovvirginia' }
  end

Possible Solutions

according to tcpdump, inspec performs lookups for azure instead of azuregov, verified ip addresses to which connection is made is the same address provided by dns resolution, assumption is made inspec is connecting to azure endpoints instead of azuregov

Stacktrace

https://gist.github.com/yarick/983adc75570948cd30cc4d40c028ee57

<script src="https://gist.github.com/yarick/983adc75570948cd30cc4d40c028ee57.js"></script>

inspec exec ./test/integration/default -t azure:// -l=debug --diagnose
InSpec version: 2.2.20
Train version: 1.4.15
Command line configuration:
{"target"=>"azure://", "log_level"=>"debug", "diagnose"=>true}
JSON configuration file:
{}
Merged configuration:
{"reporter"=>{"cli"=>{"stdout"=>true}},
"show_progress"=>false,
"color"=>true,
"create_lockfile"=>true,
"backend_cache"=>true,
"type"=>:exec,
"target"=>"azure://",
"log_level"=>"debug",
"diagnose"=>true}

[2018-06-26T11:18:33-04:00] DEBUG: Option backend_cache is enabled
[2018-06-26T11:18:33-04:00] DEBUG: Resolve ./test/integration/default into cache /root/.inspec/cache
[2018-06-26T11:18:33-04:00] DEBUG: Dependency does not exist in the cache ./test/integration/default
[2018-06-26T11:18:33-04:00] DEBUG: Starting run with targets: ["Inspec::Profile"]
[2018-06-26T11:18:33-04:00] DEBUG: Using existing lockfile ./test/integration/default/inspec.lock
[2018-06-26T11:18:33-04:00] DEBUG: Loading ./test/integration/default/controls/M-2.12.rb into #Inspec::ProfileContext:0x0000000003bb93f8
[DEPRECATED] use a specific azure resources instead of 'azure_generic_resource'. See inspec/inspec#3131
[2018-06-26T11:18:34-04:00] DEBUG: Registering rule M-2.12

Profile: AZURE Inspec Demo based on CIS_Microsoft_Azure_Foundations_Benchmark (azure-inspec-demo)
Version: 0.2
Target: azure://12345678-1234-1234-1234-123456789012

× M-2.12: 2.12 Ensure that 'JIT Network Access' is set to 'On' (Scored) (2 failed)
× azure_generic_resource
The subscription '12345678-1234-1234-1234-123456789012' could not be found.
× azure_resource_group
The subscription '12345678-1234-1234-1234-123456789012' could not be found.

Profile Summary: 0 successful controls, 1 control failure, 0 controls skipped
Test Summary: 0 successful, 2 failures, 0 skipped

Add cache support to Graph module

🎛 Description

Choose one: 🙋 feature request

Update Graph module to use cache. At the moment it will re-issue requests for the same information.

Add Powershell Env Vars for Windows to Docs

Add Powershell environment variables for Windows to the documentation:

to set environment variables:
$env:AZURE_SUBSCRIPTION_ID="43706c4e-b31d-425e-b5f5-e64e6bf63ac4"
$env:AZURE_CLIENT_ID="ecee433c-083a-4293-a579-3eea4286190a"
$env:AZURE_CLIENT_SECRET="MYCLIENTSECRETHERE="
$env:AZURE_TENANT_ID="9c117323-1f20-444d-82a9-9ee430723ba3"

bundle exec inspec exec C:\projects\user\inspec_azure_testing\v2\profile\ -t azure://ID

Test on Windows VM

Update plugin so that it works with latest versions of Azure SDK

Update the plugin so that it knows how to work with the latest Azure SDK versions.

At the moment (as of 2017-10-26) there appears to be a bug with 0.15 version of the SDK that means that it will only look for environment variables for credentials. Microsoft are aware of this.

Resources need to be prefixed `azurerm`

Currently resources are mixed between azure and azurerm prefixes. Standardize on azurerm and alias azure with a deprecation warning.
Be sure to update integration tests and documentation.

  • azure_monitor_activity_log_alert
  • azure_monitor_activity_log_alerts
  • azure_monitor_log_profile
  • azure_monitor_log_profiles
  • azure_network_security_group
  • azure_network_security_groups
  • azure_network_watcher
  • azure_network_watchers
  • azure_resource_groups
  • azure_security_center_policies
  • azure_security_center_policy

Do we need `has_disks?` for azure_virtual_machine?

To have a method name like has_disks? feels not optimal.

describe azure_virtual_machine(name: 'MyVM', resource_group: 'MyResourceGroup') do
  its('has_disks?') { should be true }
end

Is there any reason why we cannot use:

describe azure_virtual_machine(name: 'MyVM', resource_group: 'MyResourceGroup') do
  its('count') { should cmp >= 0 }
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.