By Implementation

Service Control PoliciesConfig RulesAuto Remediation RulesConformance PacksAmazon GuardDutyAmazon InspectorAWS Security HubAWS Network FirewallRoute53 Resolver SecurityAmazon MacieS3 Bucket PoliciesCloudWatch Alarms and Event RulesAWS WAFAWS Secrets ManagerAWS Systems ManagerSecurity Groups & NACLsAWS KMSIAM Policies

By Service Protected

Configuration Packages

Strategy Guides

Other

IAM Security Controls

Set IAM Password Policy

Configuration to set an IAM password policy in an AWS account. Options include: Require uppercase, lowercase, numbers, symbols in passwords, allow users to change their password, enable password expiration, prevent password reuse, and requiring administrator reset for expired passwords.

Important: If you have used the CloudFormation template of this configuration item prior to June 25th, you might run into an issue when you run an UPDATE operation on the CloudFormation stack. Please update the stack with this current version (or use the Lambda code to update the Lambda function that was created by your stack).

AWS Documentation
Items
3
Size
3.3 KB
AWSTemplateFormatVersion: "2010-09-09"
Description: ""
Resources:
  IamPasswordPolicy:
    Type: "Custom::PasswordPolicy"
    Properties:
      HardExpiry: false
      AllowUsersToChangePassword: true
      MaxPasswordAge: 90
      MinimumPasswordLength: 14
      PasswordReusePrevention: 6
      RequireLowercaseCharacters: true
      RequireNumbers: true
      RequireSymbols: true
      RequireUppercaseCharacters: true
      ServiceToken:
        Fn::GetAtt:
          - "IamPasswordPolicyLambda"
          - "Arn"
  IamPasswordPolicyLambdaRole:
    Type: "AWS::IAM::Role"
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: "Allow"
            Principal:
              Service: "lambda.amazonaws.com"
            Action:
              - "sts:AssumeRole"
      Path: "/"
      ManagedPolicyArns:
        - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
      Policies:
        - PolicyName: "iam"
          PolicyDocument:
            Statement:
              - Effect: "Allow"
                Action:
                  - "iam:UpdateAccountPasswordPolicy"
                  - "iam:DeleteAccountPasswordPolicy"
                Resource: "*"
  IamPasswordPolicyLambda:
    Type: "AWS::Lambda::Function"
    Properties:
      Code:
        ZipFile: "'use strict';\nconst AWS = require('aws-sdk');\nconst response = require('cfn-response');\nconst iam = new AWS.IAM({apiVersion: '2010-05-08'});\nexports.handler = (event, context, cb) => {\nconsole.log(`Invoke: ${JSON.stringify(event)}`);\nconst done = (err) => {\n  if (err) {\n    console.log(`Error: ${JSON.stringify(err)}`);\n    response.send(event, context, response.FAILED, {}, event.PhysicalResourceId);\n  } else {\n    response.send(event, context, response.SUCCESS, {}, event.PhysicalResourceId );\n  }\n};\nif (event.RequestType === 'Delete') {\n  iam.deleteAccountPasswordPolicy({}, done);\n} else if (event.RequestType === 'Create' || event.RequestType === 'Update') {\n  let params = {\n    AllowUsersToChangePassword: event.ResourceProperties.AllowUsersToChangePassword === 'true',\n    HardExpiry: event.ResourceProperties.HardExpiry === 'true',\n    MinimumPasswordLength: parseInt(event.ResourceProperties.MinimumPasswordLength, 10),\n    RequireLowercaseCharacters: event.ResourceProperties.RequireLowercaseCharacters === 'true',\n    RequireNumbers: event.ResourceProperties.RequireNumbers === 'true',\n    RequireSymbols: event.ResourceProperties.RequireSymbols === 'true',\n    RequireUppercaseCharacters: event.ResourceProperties.RequireUppercaseCharacters === 'true',\n  };\n  if (parseInt(event.ResourceProperties.MaxPasswordAge, 10) > 0) {\n    params.MaxPasswordAge = parseInt(event.ResourceProperties.MaxPasswordAge, 10);\n  }\n  if (parseInt(event.ResourceProperties.PasswordReusePrevention, 10) > 0) {\n    params.PasswordReusePrevention = parseInt(event.ResourceProperties.PasswordReusePrevention, 10);\n  }\n  iam.updateAccountPasswordPolicy(params, done);\n} else {\n  cb(new Error(`unsupported RequestType: ${event.RequestType}`));\n}\n};"
      Handler: "index.handler"
      MemorySize: 128
      Role:
        Fn::GetAtt:
          - "IamPasswordPolicyLambdaRole"
          - "Arn"
      Runtime: "nodejs12.x"
      Timeout: 60
Parameters: {}
Metadata: {}
Conditions: {}

Actions



Customize Template

* Required field