You may pass filter criteria to `where` to narrow down the result set.
### has\_attached\_policies
True or false. Filters the users to include only those that have at least one IAM managed policy attached to the user.
# Don't attach policies to users
describe aws_iam_users.where(has_attached_policies: true) do
it { should_not exist }
end
### has\_console\_password
True or false. Filters the users to include only those that have a console password (that is, they are able to login to the AWS web UI using a password).
# No console passwords for anyone
describe aws_iam_users.where(has_console_password: true) do
it { should_not exist }
end
### has\_inline\_policies
True or false. Filters the users to include only those that have at least one IAM policy directly embedded in the user record.
# Embedding policies is usually hard to manage
describe aws_iam_users.where(has_inline_policies: true) do
it { should_not exist }
end
### has\_mfa\_enabled
True or false. Filters the users to include only those that have some kind of Mult-Factor Authentication enabled (virtual or hardware).
# Require MFA for everyone
describe aws_iam_users.where(has_mfa_enabled: false) do
it { should_not exist }
end
### password\_ever\_used
True or false. Filters the users to include only those that have used their password at least once.
# Someone should have used their password
describe aws_iam_users.where(password_ever_used: true) do
it { should exist }
end
### password\_last\_used_days\_ago
Integer. Filters the users to include only those who used their password a certain number of days ago. '0' means today.
# Bob should login every day
describe aws_iam_users.where(password_ever_used: true, password_last_used_days_ago:0) do
its('usernames') { should include 'bob' }
end
# This filter is often more useful in block mode, using a greater-than
# Here, audit users who have not logged in in the last 30 days
True or false. Filters the users to include only those that have used _never_ their password.
# No zombie accounts!
describe aws_iam_users.where(password_never_used: true) do
it { should_not exist }
end
### username
String. Filters the users to include only those whose username matches the value you provide.
# Block mode example (recommended)
# Service users should not have a password
describe aws_iam_users.where { username.start_with?('service') } do
it { should_not have_console_password }
end
# Method call example. This is a poor use of aws_iam_users (plural);
# if you want to audit an individual user whose username you know, use
# aws_iam_user (singular)
# Verify Bob exists
describe aws_iam_users.where(username: 'bob') do
it { should exist }
end
## Properties
Properties are used with the `its` test to obtain information about the matched users. Properties always return arrays, though they may be empty.
### attached\_policy\_arns
Array of strings. Each entry is the ARN of an IAM managed policy that is attached to at least one matched user. The list is de-duplicated, so if you have five users that are all attached to the same policy, `attached_policy_arns` will return only one ARN, not five.
# Service users should be attached to a custom service policy
describe aws_iam_users.where { username.start_with?('service') } do
its('attached_policy_arns') { should include 'arn:aws:iam::123456789012:policy/MyServicePolicy' }
end
### attached\_policy\_names
Array of strings. Each entry is the friendly name of an IAM managed policy that is attached to at least one matched user. The list is de-duplicated, so if you have five users that are all attached to the same policy, `attached_policy_names` will return only one name, not five.
# Service users should be attached to a custom service policy
# and not include Admin policy!
describe aws_iam_users.where { username.start_with?('service') } do
its('attached_policy_names') { should include 'MyServicePolicy' }
its('attached_policy_names') { should_not include 'AdministratorAccess' }
end
### inline\_policy\_names
Array of strings. Each entry is the name of an embedded policy that is embedded in at least one matched user. Keep in mind that each user has a copy of a policy (which can then be modified). This means that two users can have an embedded policy with the same name, but very different contents. The list is de-duplicated, so if you have five users that have an inline policy with the same name, `inline_policy_names` will return only one name, not five.
# Service users should have a bespoke policy
describe aws_iam_users.where { username.start_with?('service') } do
its('inline_policy_names') { should include 'some-bespoke-policy' }
end
### usernames
Array of strings. Each entry is the name of a user that matched. There will be exactly as many usernames here as there were users that matched, though it is possible to have non-unique usernames.
# 42 Users, including Bob, should have a password.
describe aws_iam_users.where(has_console_password: true) do