Use the azurerm_ad_user InSpec audit resource to test properties of an Azure Active Directory user within a Tenant.
This resource interacts with version 1.6 of the Azure Graph API. For more information see the official Azure documentation.
At the moment, there doesn’t appear to be a way to select the version of the Azure API docs. If you notice a newer version being referenced in the official documentation please open an issue or submit a pull request using the updated version.
This resource is available in the inspec-azure resource pack. To use it, add the following to your inspec.yml in your top-level profile:
depends:
- name: inspec-azure
git: https://github.com/inspec/inspec-azure.git
You’ll also need to setup your Azure credentials; see the resource pack README.
This resource first became available in 1.1.0 of the inspec-azure resource pack.
The user_id must be given as a parameter.
describe azurerm_ad_user(user_id: 'someUserId') do
it { should exist }
end
If an Active Directory user account is referenced with a valid ID
describe azurerm_ad_user(user_id: 'someValidId')
it { should exist }
end
If an Active Directory user account is referenced with an invalid ID
describe azurerm_ad_user(user_id: 'someInvalidId')
it { should_not exist }
end
user_iduser_id is a required parameter.
describe azurerm_ad_user(user_id: 'MyUserId') do
...
end
object_idaccount_enabledcitycountrydepartmentdisplayNamefacsimile_telephone_numbergiven_namejob_titlemailmail_nicknamemobilepassword_policiespassword_profilepostal_codestatestreet_addresssurnametelephone_numberusage_locationuser_principal_nameuser_typeThe user’s object ID.
Whether the account is enabled.
The user’s city.
The user’s country.
The user’s department.
The display name of the user.
the user’s facsimile (fax) number.
the given name for the user.
the user’s job title.
the primary email address of the user.
The mail alias for the user.
The user’s mobile (cell) phone number.
The password policies for the user.
The password profile for the user.
The user’s postal (ZIP) code.
The user’s state.
The user’s street address.
The user’s surname (family name or last name).
The user’s telephone number.
A two letter country code (ISO standard 3166). Required for users that will be assigned licenses due to legal requirement to check for availability of services in countries. Examples include: “US”, “JP”, and “GB”.
The principal name of the user.
A string value that can be used to classify user types in your directory, such as ‘Member’ and ‘Guest’.
There are additional attributes that may be accessed that we have not documented. Please take a look at the Azure documentation. Any attribute in the response may be accessed with the key names separated by dots (.). Given the example response in their documentation:
...
"preferredLanguage": "en-US",
"provisionedPlans": [
{
"capabilityStatus": "Enabled",
"provisioningStatus": "Success",
"service": "exchange"
},
...
We may access provisioningStatus with:
its('provisionedPlants.first.provisioningStatus') { should eq "Success" }
The API may not always return keys that do not have any associated data. There may be cases where the deeply nested property may not have the desired attribute along your call chain. If you find yourself writing tests against properties that may be nil, fork this resource pack and add an accessor to the resource. Within that accessor you’ll be able to guard against nil keys. Pull requests are always welcome.
This InSpec audit resource has the following special matchers. For a full list of available matchers, please visit our Universal Matchers page.
describe azurerm_ad_user(user_id: 'someUserId') do
it { should exist }
end
The Client/Active Directory Application you have configured InSpec Azure to use (AZURE_CLIENT_ID) must have permissions to read User data from the Azure Graph RBAC API.
Please refer to the Microsoft Documentation for information on how to grant these permissions to your application.
Note: An Azure Admin must grant your application these permissions.
© Chef Software, Inc.
Licensed under the Creative Commons Attribution 3.0 Unported License.
The Chef™ Mark and Chef Logo are either registered trademarks/service marks or trademarks/servicemarks of Chef, in the United States and other countries and are used with Chef Inc's permission.
We are not affiliated with, endorsed or sponsored by Chef Inc.
https://docs.chef.io/inspec/resources/azurerm_ad_user/