Keen documentation
Open Keen ↗

Administering Keen

AWS

Chapter 14 of 40

AWS

AWS posture reads each account's IAM users and administrators, root user, password policy, CloudTrail logging, S3 Block Public Access, security groups and RDS exposure, and Security Hub findings, with read-only access, and records CloudTrail console sign-ins and IAM changes. Results appear on the Amazon Web Services vendor's Cloud posture tab (see Cloud vendor posture).

Keen reaches each account by assuming a read-only role in it, with an external ID, and confirms through STS that the credentials answer for that account before reading anything. With one account, Keen's own identity can hold the read actions and no role is needed.

Checks

CheckActionMet when
MFA for console usersposture.identity.mfaEvery IAM user with a console password has an MFA device.
MFA for administratorsposture.identity.admin_mfaEvery console user with administrator rights has an MFA device.
Administratorsposture.identity.adminsReported for information: the users and roles holding AdministratorAccess, directly or through a group, or any policy that allows * on *. Service-linked roles are left out.
Unused usersposture.identity.inactiveNo IAM user has gone unused, by console or access key, for KEEN_CLOUD_INACTIVE_DAYS.
Access key ageposture.credentials.key_ageNo active access key is older than KEEN_CLOUD_KEY_AGE_DAYS.
Root userposture.aws.rootThe root user has MFA and neither access keys nor signing certificates.
Password policyposture.aws.password_policyAn account password policy requires at least 14 characters and prevents reuse of the last 24 passwords.
CloudTrail loggingposture.logging.audit_trailA multi-region trail, such as an organisation trail, is logging.
S3 Block Public Accessposture.storage.public_accessAll four account-level Block Public Access settings are on.
SSH and RDP open to the internetposture.network.admin_portsNo security group attached to a network interface lets TCP port 22 or 3389 in from 0.0.0.0/0 or ::/0.
Databases open to the internetposture.network.databasesNo publicly accessible RDS instance has a security group that admits the internet on its database port.
Security Hub findingsposture.findingsSecurity Hub holds no active critical or high finding in the New or Notified workflow state for the account.

Administrators come from the account's authorisation snapshot; Keen does not work out effective permissions through service control policies, permission boundaries or resource policies. People who sign in through IAM Identity Center appear as AWSReservedSSO_ roles. AWS regenerates the credential report at most every four hours, so a user's last use can be up to four hours old. A member account may see its organisation's trail without being allowed its status; CloudTrail logging then reads Not established, unless another multi-region trail in the account is logging. The network checks read every region enabled in the account, up to 40, or the regions in KEEN_AWS_REGIONS; security group rules that admit a prefix list or another security group are left out. Security Hub findings come from KEEN_AWS_REGION, so choose your Security Hub aggregation region there to cover every region; Keen counts up to 5,000 findings and says at least beyond that. An account without Security Hub reads Not established.

The vendor page lists each account's IAM users, with their console access, access keys, MFA and last use, and the root user.

CloudTrail activity

Keen reads CloudTrail's event history, which holds the last 90 days of management events in each region and needs no trail. It records console sign-ins and role switches, successful or failed, with whether MFA was used, and password changes, from the regions AWS records sign-ins in (us-east-1, us-east-2, us-west-2, eu-north-1 and ap-southeast-2), and every IAM call that changes something, such as creating a user or attaching a policy, from us-east-1, where AWS records IAM (us-gov-west-1 and cn-north-1 in those partitions). Read-only IAM calls are left out. CloudTrail delivers events within about 15 minutes, so each read stops 20 minutes before the present, and it answers two event history requests a second, so a busy account can take a few minutes per read.

1. Create the read-only role in each account

Choose an external ID: a random value that only Keen and your role trust policies know, for example from openssl rand -hex 24. Save this permissions policy as keen-posture.json:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "KeenPostureReadOnly",
      "Effect": "Allow",
      "Action": [
        "iam:GetAccountSummary",
        "iam:GenerateCredentialReport",
        "iam:GetCredentialReport",
        "iam:GetAccountAuthorizationDetails",
        "iam:GetAccountPasswordPolicy",
        "iam:ListAccountAliases",
        "cloudtrail:DescribeTrails",
        "cloudtrail:GetTrailStatus",
        "cloudtrail:LookupEvents",
        "s3:GetAccountPublicAccessBlock",
        "ec2:DescribeRegions",
        "ec2:DescribeSecurityGroups",
        "ec2:DescribeNetworkInterfaces",
        "rds:DescribeDBInstances",
        "securityhub:GetFindings"
      ],
      "Resource": "*"
    }
  ]
}

Save this trust policy as keen-trust.json, naming the IAM user Keen signs in as (step 2) and your external ID. If Keen runs with an instance profile or task role, name that role's ARN instead.

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": { "AWS": "arn:aws:iam::111122223333:user/keen-posture" },
      "Action": "sts:AssumeRole",
      "Condition": { "StringEquals": { "sts:ExternalId": "YOUR-EXTERNAL-ID" } }
    }
  ]
}

Then create the role in each account Keen should read, signed in to that account:

aws iam create-role --role-name KeenPostureReadOnly \
  --assume-role-policy-document file://keen-trust.json
aws iam put-role-policy --role-name KeenPostureReadOnly \
  --policy-name KeenPosture --policy-document file://keen-posture.json

In an AWS organisation, a CloudFormation StackSet can create the same role in every member account. Running put-role-policy again replaces the policy. With a single account, attach keen-posture.json to Keen's own IAM user from step 2 and skip the role.

2. Give Keen its own credentials

Create a dedicated IAM user, in a security or management account, that can only assume the posture roles. Save this policy as keen-assume.json:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "sts:AssumeRole",
      "Resource": "arn:aws:iam::*:role/KeenPostureReadOnly"
    }
  ]
}
aws iam create-user --user-name keen-posture
aws iam put-user-policy --user-name keen-posture \
  --policy-name KeenAssumePostureRoles --policy-document file://keen-assume.json
aws iam create-access-key --user-name keen-posture

The last command prints the access key ID and secret access key once. Store them as Keen's posture credentials and nowhere else. Rotate them by creating a second key, updating Keen and deleting the first.

3. Configure Keen

SettingPurpose
KEEN_AWS_ENABLEDTurns AWS posture on.
AWS_POSTURE_ACCESS_KEY_ID, AWS_POSTURE_SECRET_ACCESS_KEYThe keys from step 2. Leave both blank to use the host's role chain, such as an instance profile or task role. These names leave AWS_ACCESS_KEY_ID to CloudWatch Logs collection.
AWS_POSTURE_SESSION_TOKENOnly for temporary keys.
AWS_POSTURE_EXTERNAL_IDThe external ID from step 1.
KEEN_AWS_ROLE_ARNSThe role in each account, separated by commas, such as arn:aws:iam::444455556666:role/KeenPostureReadOnly; up to 100. Leave it blank to read only the account Keen's credentials belong to.
KEEN_AWS_REGIONThe region for STS, CloudTrail trails, S3 Control and Security Hub; us-east-1 by default. Use a China or GovCloud region in those partitions.
KEEN_AWS_REGIONSThe regions the network checks read, separated by commas; blank reads every region enabled in the account.

4. Verify

Recreate the API, worker and beat containers and choose Admin → Ingest runners → Run AWS, then open the Amazon Web Services vendor's Cloud posture tab. Each account appears under its account alias, or its ID. A check that reads Not established names its reason: not allowed means the role or its policy is missing an action, and not set up, or the credentials were not accepted covers wrong keys, an external ID that does not match the trust policy, a role in a different account from its ARN, and an account without Security Hub.