Code Monkey home page Code Monkey logo

turbot / steampipe-plugin-azure Goto Github PK

View Code? Open in Web Editor NEW
33.0 11.0 14.0 4.12 MB

Use SQL to instantly query Azure resources across regions and subscriptions. Open source CLI. No DB required.

Home Page: https://hub.steampipe.io/plugins/turbot/azure

License: Apache License 2.0

JavaScript 1.05% Makefile 0.01% HCL 15.46% Go 83.34% PLSQL 0.15%
azure azure-devops steampipe steampipe-plugin postgresql postgresql-fdw azure-cli azure-client sql hacktoberfest

steampipe-plugin-azure's People

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

steampipe-plugin-azure's Issues

The Azure query for Key Vault runs to infinite loop.

While executing this query, it runs in to loop. There are only 3 no of key-vaults in the subscription.

> select
  name,
  id,
  soft_delete_enabled,
  soft_delete_retention_in_days
from
  azure_key_vault

⠏ Loading results: 275
⠸ Loading results: 553
⠇ Loading results: 646
⠋ Loading results: 646
⠹ Loading results: 646
⠼ Loading results: 646
⠦ Loading results: 646
Error: pq: rpc error: code = Unavailable desc = transport is closing ( This comes after I stopped the service with steampipe service stop --force)
Connected again to execute the same query

abc % steampipe query
Welcome to Steampipe v0.2.2
For more information, type .help

select
name,
id,
soft_delete_enabled,
soft_delete_retention_in_days
from
azure_key_vault
⠙ Loading results: 275

Add Azure monitor table

Describe the new table

Need to query the Azure Monitor table to verify the CIS section 5 (Logging and Monitoring)

References

Section 5

We need to achieve some of the steps as per CIS recommendation

5.1 Configuring Diagnostic Settings
5.1.1 Ensure that a 'Diagnostics Setting' exists (Automated)
5.1.2 Ensure Diagnostic Setting captures appropriate categories (Automated)
5.1.3 Ensure the storage container storing the activity logs is not publicly accessible (Automated)
5.1.4 Ensure the storage account containing the container with activity logs is encrypted with BYOK (Use Your Own Key) (Automated)
5.1.5 Ensure that logging for Azure KeyVault is 'Enabled' (Automated)
5.2.1 Ensure that Activity Log Alert exists for Create Policy Assignment (Automated)
5.2.2 Ensure that Activity Log Alert exists for Delete Policy Assignment (Automated)
5.2.3 Ensure that Activity Log Alert exists for Create or Update Network Security Group (Automated)
5.2.4 Ensure that Activity Log Alert exists for Delete Network Security Group (Automated)
5.2.5 Ensure that Activity Log Alert exists for Create or Update Network Security Group Rule (Automated)
5.2.6 Ensure that activity log alert exists for the Delete Network Security Group Rule (Automated)
5.2.7 Ensure that Activity Log Alert exists for Create or Update Security Solution (Automated)
5.2.8 Ensure that Activity Log Alert exists for Delete Security Solution (Automated)
5.2.9 Ensure that Activity Log Alert exists for Create or Update or Delete SQL Server Firewall Rule (Automated)
5.3 Ensure that Diagnostic Logs are enabled for all services which support it. (Automated)

Add Kubernetes table

Describe the new table

Need to query the Kubernetes table to query if the instances are enabled with RBAC.

References

Section 8

We need to achieve some of the steps as per CIS recommendation
8.5 Enable role-based access control (RBAC) within Azure Kubernetes Services (Automated), steps 2 & 3

Ensure that the endpoint protection for all Virtual Machines is installed

Is your feature request related to a problem? Please describe.
This is to achieve some of the CIS steps 7.6

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
At this point in time, there is no API mechanism available.

Add Security Center table

Describe the new table

Need to query the Security Center table to verify the CIS section 2 (Security Center)

References

Section 2

2.1 Ensure that Azure Defender is set to On for Servers (Manual)
2.2 Ensure that Azure Defender is set to On for App Service (Manual)
2.3 Ensure that Azure Defender is set to On for Azure SQL database servers (Manual)
2.4 Ensure that Azure Defender is set to On for SQL servers on machines (Manual)
2.5 Ensure that Azure Defender is set to On for Storage (Manual)
2.6 Ensure that Azure Defender is set to On for Kubernetes (Manual)
2.7 Ensure that Azure Defender is set to On for Container Registries (Manual)
2.8 Ensure that Azure Defender is set to On for Key Vault (Manual)
2.9 Ensure that Windows Defender ATP (WDATP) integration with Security Center is selected (Manual)
2.10 Ensure that Microsoft Cloud App Security (MCAS) integration with Security Center is selected (Manual)
2.11 Ensure that 'Automatic provisioning of monitoring agent' is set to 'On' (Automated)
2.12 Ensure any of the ASC Default policy setting is not set to "Disabled" (Manual)
2.13 Ensure 'Additional email addresses' is configured with a security contact email (Automated)
2.14 Ensure that 'Notify about alerts with the following severity' is set to 'High' (Automated)
2.15 Ensure that 'All users with the following roles' is set to 'Owner' (Automated)

Add Azure > AppService to check if configured to Azure Active Directory.

Register with Azure Active Directory is enabled on App Service, this can an extension to azure_app_service_web_app table.

az webapp identity show --resource-group <RESOURCE_GROUP_NAME> --name
<APP_NAME> --query principalId
The output should return unique Principal ID.
If no output for the above command then Register with Azure Active Directory is not set.

Ensure that the latest OS Patches for all Virtual Machines are applied

Is your feature request related to a problem? Please describe.
This is to achieve some of the CIS steps 7.5

Describe the solution you'd like

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Please note that at this point of time, there is no API/CLI mechanism available to
programmatically conduct security assessment for this recommendation.

unfriendly error after changing azure password

After chaing my azure password, steampipe fails with an unfriendly error:

select * from azure_ad_group
Error: pq: rpc error: code = Unknown desc = Invoking Azure CLI failed with the following error: UnexpectedError: The command failed with an unexpected error. Here is the traceback:
Get Token request returned http error: 400 and server response: {"error":"invalid_grant","error_description":"AADSTS50173: The provided grant has expired due to it being revoked, a fresh auth token is needed. The user might have changed or reset their password. The grant was issued on '2020-08-26T13:52:10.1898142Z' and the TokensValidFrom date (before which tokens are not valid) for this user is '2021-01-26T21:20:37.0000000Z'.\r\nTrace ID: 62ae314d-d6be-4854-ab2d-1e19ac971300\r\nCorrelation ID: 5d919732-f206-4ed5-b6f9-1d6798276b37\r\nTimestamp: 2021-01-26 23:28:38Z","error_codes":[50173],"timestamp":"2021-01-26 23:28:38Z","trace_id":"62ae314d-d6be-4854-ab2d-1e19ac971300","correlation_id":"5d919732-f206-4ed5-b6f9-1d6798276b37","error_uri":"https://login.microsoftonline.com/error?code=50173"}
Traceback (most recent call last):
  File "/usr/local/Cellar/azure-cli/2.12.1/libexec/lib/python3.8/site-packages/knack/cli.py", line 215, in invoke
    cmd_result = self.invocation.execute(args)
  File "/usr/local/Cellar/azure-cli/2.12.1/libexec/lib/python3.8/site-packages/azure/cli/core/commands/__init__.py", line 654, in execute
    raise ex
  File "/usr/local/Cellar/azure-cli/2.12.1/libexec/lib/python3.8/site-packages/azure/cli/core/commands/__init__.py", line 718, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
  File "/usr/local/Cellar/azure-cli/2.12.1/libexec/lib/python3.8/site-packages/azure/cli/core/commands/__init__.py", line 711, in _run_job
    six.reraise(*sys.exc_info())
  File "/usr/local/Cellar/azure-cli/2.12.1/libexec/lib/python3.8/site-packages/six.py", line 703, in reraise
    raise value
  File "/usr/local/Cellar/azure-cli/2.12.1/libexec/lib/python3.8/site-packages/azure/cli/core/commands/__init__.py", line 688, in _run_job
    result = cmd_copy(params)
  File "/usr/local/Cellar/azure-cli/2.12.1/libexec/lib/python3.8/site-packages/azure/cli/core/commands/__init__.py", line 325, in __call__
    return self.handler(*args, **kwargs)
  File "/usr/local/Cellar/azure-cli/2.12.1/libexec/lib/python3.8/site-packages/azure/cli/core/__init__.py", line 784, in default_command_handler
    return op(**command_args)
  File "/usr/local/Cellar/azure-cli/2.12.1/libexec/lib/python3.8/site-packages/azure/cli/command_modules/profile/custom.py", line 75, in get_access_token
    creds, subscription, tenant = profile.get_raw_token(subscription=subscription, resource=resource, tenant=tenant)
  File "/usr/local/Cellar/azure-cli/2.12.1/libexec/lib/python3.8/site-packages/azure/cli/core/_profile.py", line 649, in get_raw_token
    creds = self._creds_cache.retrieve_token_for_user(username_or_sp_id,
  File "/usr/local/Cellar/azure-cli/2.12.1/libexec/lib/python3.8/site-packages/azure/cli/core/_profile.py", line 1019, in retrieve_token_for_user
    token_entry = context.acquire_token(resource, username, _CLIENT_ID)
  File "/usr/local/Cellar/azure-cli/2.12.1/libexec/lib/python3.8/site-packages/adal/authentication_context.py", line 145, in acquire_token
    return self._acquire_token(token_func)
  File "/usr/local/Cellar/azure-cli/2.12.1/libexec/lib/python3.8/site-packages/adal/authentication_context.py", line 128, in _acquire_token
    return token_func(self)
  File "/usr/local/Cellar/azure-cli/2.12.1/libexec/lib/python3.8/site-packages/adal/authentication_context.py", line 143, in token_func
    return token_request.get_token_from_cache_with_refresh(user_id)
  File "/usr/local/Cellar/azure-cli/2.12.1/libexec/lib/python3.8/site-packages/adal/token_request.py", line 347, in get_token_from_cache_with_refresh
    return self._find_token_from_cache()
  File "/usr/local/Cellar/azure-cli/2.12.1/libexec/lib/python3.8/site-packages/adal/token_request.py", line 127, in _find_token_from_cache
    return self._cache_driver.find(cache_query)
  File "/usr/local/Cellar/azure-cli/2.12.1/libexec/lib/python3.8/site-packages/adal/cache_driver.py", line 198, in find
    return self._refresh_entry_if_necessary(entry,
  File "/usr/local/Cellar/azure-cli/2.12.1/libexec/lib/python3.8/site-packages/adal/cache_driver.py", line 177, in _refresh_entry_if_necessary
    return self._refresh_expired_entry(entry)
  File "/usr/local/Cellar/azure-cli/2.12.1/libexec/lib/python3.8/site-packages/adal/cache_driver.py", line 153, in _refresh_expired_entry
    token_response = self._refresh_function(entry, None)
  File "/usr/local/Cellar/azure-cli/2.12.1/libexec/lib/python3.8/site-packages/adal/token_request.py", line 137, in _get_token_with_token_response
    return self._get_token_with_refresh_token(refresh_token, resource, None)
  File "/usr/local/Cellar/azure-cli/2.12.1/libexec/lib/python3.8/site-packages/adal/token_request.py", line 339, in _get_token_with_refresh_token
    return self._oauth_get_token(oauth_parameters)
  File "/usr/local/Cellar/azure-cli/2.12.1/libexec/lib/python3.8/site-packages/adal/token_request.py", line 112, in _oauth_get_token
    return client.get_token(oauth_parameters)
  File "/usr/local/Cellar/azure-cli/2.12.1/libexec/lib/python3.8/site-packages/adal/oauth2_client.py", line 289, in get_token
    raise AdalError(return_error_string, error_response)
adal.adal_error.AdalError: Get Token request returned http error: 400 and server response: {"error":"invalid_grant","error_description":"AADSTS50173: The provided grant has expired due to it being revoked, a fresh auth token is needed. The user might have changed or reset their password. The grant was issued on '2020-08-26T13:52:10.1898142Z' and the TokensValidFrom date (before which tokens are not valid) for this user is '2021-01-26T21:20:37.0000000Z'.\r\nTrace ID: 62ae314d-d6be-4854-ab2d-1e19ac971300\r\nCorrelation ID: 5d919732-f206-4ed5-b6f9-1d6798276b37\r\nTimestamp: 2021-01-26 23:28:38Z","error_codes":[50173],"timestamp":"2021-01-26 23:28:38Z","trace_id":"62ae314d-d6be-4854-ab2d-1e19ac971300","correlation_id":"5d919732-f206-4ed5-b6f9-1d6798276b37","error_uri":"https://login.microsoftonline.com/error?code=50173"}
To open an issue, please run: 'az feedback'
> 

We should throw a more informative error, similar to the az cli:

$ az vm list
ValidationError: The credential data used by CLI has been expired because you might have changed or reset the password. Please clear browser's cookies and run 'az login'

Add Azure Active Directory table support.

This is to add most of the Azure IAM CIS requirements.

E.x.

  • CIS v 1.3.0 : 1.22 Ensure Security Defaults is enabled on Azure Active Directory (Automated) : This is to check the Directory Properties whether enabled with defaults or not.
  • Whether a maximum of 3 owners should be designated for subscription or not.

azure_storage_account > virtual_network_rules does not work

Even if we have data available as mentioned in the screen the query below does not show any data.

select virtual_network_rules from azure_storage_account where name = 'anothertesting'

We can extend azure_storage_account to add additional data in virtual_network_rules field to include the data for Firewalls and virtual networks
image

image

Add support to query NSG flow log retention period from azure_network_watcher.

Currently this query returns only the id of the
select jsonb_pretty(flow_logs) from azure_network_security_group where name = 'myabc-nsg'
[ {
"id": "/subscriptions/xxxxxxxxxxxxxxxxxx1b097a0469dd/resourceGroups/NetworkWatcherRG/providers/Microsoft.Network/networkWatchers/NetworkWatcher_westus/flowLogs/myabc-nsg-flowlog
}
]
However
If we can pull more info from the Flow logs settings from Network Watcher will be good, this will also address the retention period.

API reference - https://docs.microsoft.com/en-us/rest/api/network-watcher/flowlogs/get

image

Ref Azure CIS 1.3.0 : 6.4

v0.3.0

v0.3.0 [2021-03-11]

What's new?

Bug fixes

  • Removed use of deprecated ItemFromKey function from all tables

Add Storage Account > logging enablement check for Blob, Table & Queue service.

Already there is logging support available for Storage Account, however enabling the logging in storage account level does not ensure the logging in Blob, Table & Queue service in it.

Requirement is whether, logging is enabled for read, write, and delete requests for above services.

Ref:
Azure CIS 1.3.0 > 3.3,3.10,3.11

Add further extension to the Azure VM table to support security feature query

Is your feature request related to a problem? Please describe.
Would like to have following details associated with the vm table such as --

How to know of the Vm is associated with any endpoint protection e.g. az vm show -g MyResourceGroup -n MyVm -d
Also provide support for the vm extension such as : az vm extension list -g MyResourceGroup --vm-name MyVm
Describe the solution you'd like
A clear and concise description of what you want to happen.

This is to achieve some of the CIS steps ( such as 7.4, 7.5, 7.6)

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Add table for azure policies

Is there a way to query the FRIENDLY names of azure policies? So far, I've only been able to obtain the definition IDs which are completely useless when given to our app teams for compliance reporting. Is there a better way? So far, I have this query:

policyresources
| where properties['policyDefinitionAction'] != "deny"
| where properties['complianceState'] == "NonCompliant"
| where properties['resourceGroup'] != ""
| project properties['resourceId'], resourceGroup, properties['policyDefinitionName'], properties['policyDefinitionReferenceId'], properties['complianceState']
| order by 'resourceId' asc

Add support to query Key Vault > Key & Secret expiry details.

Its recommended that every Keys in KV must have expiry date. By default, keys never expire. It is thus recommended that keys be rotated in the key vault and set an explicit expiration time for all keys. This ensures that the keys cannot be used beyond their assigned lifetimes.

The existing table does not support to query the same.

Ref : Azure CIS 1.3.0 : 8.1. 8.2

Add PostgreSql server table

Describe the new table

Need to query the PostgreSql table to query and verify the CIS section 4.3 (PostgreSQL Database Server)

References

Section 4

We need to achieve some of the steps as per CIS recommendation
4.3.1 Ensure 'Enforce SSL connection' is set to 'ENABLED' for PostgreSQL Database Server (Automated)
4.3.2 Ensure 'Enforce SSL connection' is set to 'ENABLED' for MySQL Database Server (Automated)
4.3.3 Ensure server parameter 'log_checkpoints' is set to 'ON' for PostgreSQL Database Server (Automated)
4.3.4 Ensure server parameter 'log_connections' is set to 'ON' for PostgreSQL Database Server (Automated)
4.3.5 Ensure server parameter 'log_disconnections' is set to 'ON' for PostgreSQL Database Server (Automated)
4.3.6 Ensure server parameter 'connection_throttling' is set to 'ON' for PostgreSQL Database Server (Automated)
4.3.7 Ensure server parameter 'log_retention_days' is greater than 3 days for PostgreSQL Database Server (Automated)
4.3.8 Ensure 'Allow access to Azure services' for PostgreSQL Database Server is disabled (Manual)
4.4 Ensure that Azure Active Directory Admin is configured (Automated)
4.5 Ensure SQL server's TDE protector is encrypted with Customer-managed key (Automated)

Add table azure_postgresql_server

References
https://docs.microsoft.com/en-us/rest/api/postgresql/servers

This will unblock the following CIS recommendations

Section 4

4.3.1 Ensure 'Enforce SSL connection' is set to 'ENABLED' for PostgreSQL Database Server (Automated)
4.3.3 Ensure server parameter 'log_checkpoints' is set to 'ON' for PostgreSQL Database Server (Automated)
4.3.4 Ensure server parameter 'log_connections' is set to 'ON' for PostgreSQL Database Server (Automated)
4.3.5 Ensure server parameter 'log_disconnections' is set to 'ON' for PostgreSQL Database Server (Automated)
4.3.6 Ensure server parameter 'connection_throttling' is set to 'ON' for PostgreSQL Database Server (Automated)
4.3.7 Ensure server parameter 'log_retention_days' is greater than 3 days for PostgreSQL Database Server (Automated)
4.3.8 Ensure 'Allow access to Azure services' for PostgreSQL Database Server is disabled (Manual)

Remove deprecated ItemFromKey from GET call

List of tables

  • azure_ad_service_principal
  • azure_ad_user
  • azure_ad_user
  • azure_cosmosdb_account
  • azure_cosmosdb_mongo_database
  • azure_cosmosdb_sql_database
  • azure_management_lock
  • azure_provider
  • azure_resource_group
  • azure_role_assignment
  • azure_role_definition
  • azure_storage_account
  • azure_storage_queue
  • azure_subnet

Update azure_storage_account table to include blob service logging details

Is your feature request related to a problem? Please describe.
Need to verify one CIS recommendations for which the table should contain the logging details for blob service.
https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob-service-properties

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Bug: Tables failing with error `Error: pq: rpc error: code = Internal desc = get hydrate function getAdGroup failed with panic interface conversion: interface {} is nil, not *graphrbac.ADGroup`

Azure tables that were using ItemFromKey forget API call in table schema are breaking.

> select * from azure_ad_group where object_id = '66e4618f-1eda-45d6-914c-6613a1ac2cfd';
Error: pq: rpc error: code = Internal desc = get hydrate function getAdGroup failed with panic interface conversion: interface {} is nil, not *graphrbac.ADGroup
> select * from azure_ad_user where object_id = '1cbf1ad0-993a-47f4-a927-64cf4a2ecb5f';
Error: pq: rpc error: code = Internal desc = get hydrate function getAdUser failed with panic interface conversion: interface {} is nil, not *graphrbac.User

Tables impacted

  • azure_ad_user
  • azure_ad_service_principal
  • azure_ad_user
  • azure_cosmosdb_account
  • azure_cosmosdb_mongo_database
  • azure_cosmosdb_sql_database
  • azure_management_lock
  • azure_provider
  • azure_resource_group
  • azure_role_assignment
  • azure_role_definition
  • azure_storage_account
  • azure_storage_queue
  • azure_subnet

Add power_state, private_ips, public_ips to azure_compute_virtual_machine and remove managed_disk_storage_account_type, os_disk_size_gb

Remove managed_disk_storage_account_type, os_disk_size_gb from azure_compute_virtual_machine. These fields are unreliable as they are null if the vm is not running. The azure_compute_disk has this information.

Add power_state, private_ips, public_ips to azure_compute_virtual_machine. These are common fields related to a vm that are difficult to obtain in the current table structure.

Update table azure_sql_server to return null instead of empty object, if not configured

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

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.