{"id":4889,"date":"2022-04-26T11:47:41","date_gmt":"2022-04-26T11:47:41","guid":{"rendered":"https:\/\/petabytz.com\/?p=4889"},"modified":"2026-02-19T10:19:06","modified_gmt":"2026-02-19T10:19:06","slug":"securing-passwords-in-aws-quick-starts-using-aws-secrets-manager","status":"publish","type":"post","link":"https:\/\/petabytz.com\/blogs\/securing-passwords-in-aws-quick-starts-using-aws-secrets-manager\/","title":{"rendered":"Securing passwords in AWS Quick Starts using AWS Secrets Manager"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"4889\" class=\"elementor elementor-4889\" data-elementor-post-type=\"post\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-7c50398 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"7c50398\" data-element_type=\"section\" data-e-type=\"section\" data-settings=\"{&quot;ekit_has_onepagescroll_dot&quot;:&quot;yes&quot;}\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-b0a419e\" data-id=\"b0a419e\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-d5185a8 elementor-widget elementor-widget-heading\" data-id=\"d5185a8\" data-element_type=\"widget\" data-e-type=\"widget\" data-settings=\"{&quot;ekit_we_effect_on&quot;:&quot;none&quot;}\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h1 class=\"elementor-heading-title elementor-size-default\">Securing passwords in AWS Quick Starts using AWS Secrets Manager<\/h1>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-7260394 elementor-widget elementor-widget-text-editor\" data-id=\"7260394\" data-element_type=\"widget\" data-e-type=\"widget\" data-settings=\"{&quot;ekit_we_effect_on&quot;:&quot;none&quot;}\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<div class=\"wpb_text_column\"><p id=\"793f\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\">A secure password is more than eight characters long and is complex \u2014 including lowercase letters, uppercase letters, numbers, and special characters. Complex passwords tend to be hard to remember, which is partly what makes them more secure. Complex passwords can also be hard to come up with. For these reasons, prompting a human for a password might not be suitable during an automated deployment.<\/p><p id=\"cf9d\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\">Secrets Manager can generate a Secure password and store it for use, which negates the need for human interaction in an automation workflow.<\/p><p id=\"3980\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\">The following code block demonstrates how this is done through AWS CloudFormation by using the AWS:: SecretsManager:: Secret resource type.<\/p><p id=\"d9cf\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\">RestoreModeSecrets:<\/p><p id=\"8e1c\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\">Type: AWS::SecretsManager::Secret<\/p><p id=\"8412\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\">Properties:<\/p><p id=\"77fe\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\">Name: !Sub \u2018RestoreModeSecrets-${AWS::StackName}\u2019<\/p><p id=\"1552\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\">Description: Restore Mode Password for AD Quick Start<\/p><p id=\"f382\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\">GenerateSecretString:<\/p><p id=\"8afa\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\">SecretStringTemplate: \u2018{\u201cusername\u201d: \u201cAdministrator\u201d}\u2019 GenerateStringKey: \u201cpassword\u201d<\/p><p id=\"240f\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\">PasswordLength: 30<\/p><p id=\"c876\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\">By default, Secrets Manager will create a 32-character password that includes uppercase letters, lowercase letters, numbers, and special characters. You can also use several properties with the<code class=\"nb tb tc td te b\">GenerateSecretString<\/code>property type to customize the password as needed. The<code class=\"nb tb tc td te b\">SecretStringTemplate<\/code>in this case is setting the user name for this secret. The<code class=\"nb tb tc td te b\">GenerateStringKey<\/code>is specifying the key for which you want to generate the random string.<\/p><p id=\"39f3\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\">I prompt for the password through AWS CloudFormation parameters. Admin credentials are prompted for by using a code block that is similar to the following SQL Service parameter example.<\/p><p id=\"77df\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">SQLServiceAccount:<\/code><\/p><p id=\"537a\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">AllowedPattern: '[a-zA-Z0-9]*'<\/code><\/p><p id=\"2b18\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">Default: sqlsa<\/code><\/p><p id=\"0b40\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">Description: User name for the SQL Server Service Account.<\/code><\/p><p id=\"f6f4\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">MaxLength: '25'<\/code><\/p><p id=\"5086\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">MinLength: '5'<\/code><\/p><p id=\"b437\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">Type: String<\/code><\/p><p id=\"bbe2\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">SQLServiceAccountPassword:<\/code><\/p><p id=\"2612\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">Description: Password for the SQL Service account.<\/code><\/p><p id=\"9781\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">MaxLength: '32'<\/code><\/p><p id=\"9ec4\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">MinLength: '8'<\/code><\/p><p id=\"5401\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">NoEcho: 'true'<\/code><\/p><p id=\"f36f\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">Type: String<\/code><\/p><p id=\"9d02\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">In the SQLServiceAccountPasswordparameter, I use theNoEchoproperty type, which ensures that the password doesn\u2019t appear in clear text while the template is launched.<\/code><\/p><p id=\"70cb\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">SQLSecrets:<\/code><\/p><p id=\"2323\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">Type: AWS::SecretsManager::Secret<\/code><\/p><p id=\"2be5\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">Properties:<\/code><\/p><p id=\"a4b8\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">Name: !Sub 'AWSQuickStart\/${AWS::StackName}\/SQLSecrets'<\/code><\/p><p id=\"940f\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">Description: MS SQL Credentials for Quick Start<\/code><\/p><p id=\"1a2b\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">SecretString: !Sub '{ \"username\" : \"${SQLServiceAccount}\", \"password\" : \"${SQLServiceAccountPassword}\" }'<\/code><\/p><h2 id=\"6370\" class=\"nk nl ct ba az dw nm nn no np nq nr ns nt nu nv nw\"><code class=\"nb tb tc td te b\">Retrieving secrets<\/code><\/h2><p id=\"756f\" class=\"lv lw ct ba lx b ly nx ma ny mc nz me oa mg ob mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">You can retrieve secrets from Secrets Manager by using Windows PowerShell and Python within a script. And you can retrieve secrets from Secrets Manager for use within AWS CloudFormation.<\/code><\/p><p id=\"80f2\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">The following sample code, retrieves a password.<\/code><\/p><p id=\"e526\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">import boto3<\/code><\/p><p id=\"c193\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">from botocore.exceptions import ClientError<\/code><\/p><p id=\"c193\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">from botocore.exceptions import ClientError<\/code><\/p><p id=\"5371\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">def get_secret():<\/code><\/p><p id=\"67a2\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">secret_name = \"MySecretName\"<\/code><\/p><p id=\"d813\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">region_name = \"us-west-2\"<\/code><\/p><p id=\"0764\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">session = boto3.session.Session()<\/code><\/p><p id=\"b982\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">client = session.client(<\/code><\/p><p id=\"ccbc\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">service_name='secretsmanager',<\/code><\/p><p id=\"f0ed\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">region_name=region_name,<\/code><\/p><p id=\"7f46\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">)<\/code><\/p><p id=\"0679\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">try:<\/code><\/p><p id=\"51c6\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">get_secret_value_response = client.get_secret_value( SecretId=secret_name<\/code><\/p><p id=\"99c5\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">)<\/code><\/p><p id=\"e0a1\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">except ClientError as e:<\/code><\/p><p id=\"1473\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">if e.response['Error']['Code'] == 'ResourceNotFoundException': print(\"The requested secret \" + secret_name + \" was not found\") elif e.response['Error']['Code'] == 'InvalidRequestException': print(\"The request was invalid due to:\", e)<\/code><\/p><p id=\"0b56\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">elif e.response['Error']['Code'] == 'InvalidParameterException':<\/code><\/p><p id=\"1410\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">print(\"The request had invalid params:\", e)<\/code><\/p><p id=\"4cda\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">else:<\/code><\/p><p id=\"40ac\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\"># Secrets Manager decrypts the secret value using the associated KMSCMK<\/code><\/p><p id=\"f11e\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\"># Depending on whether the secret was a string or binary, only one of these fields will be populated if 'SecretString' in get_secret_value_response:<\/code><\/p><p id=\"a162\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">text_secret_data = get_secret_value_response['SecretString']<\/code><\/p><p id=\"987c\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">else:<\/code><\/p><p id=\"7dee\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">binary_secret_data = get_secret_value_response['SecretBinary']<\/code><\/p><p id=\"516e\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\"># Your code goes here.<\/code><\/p><p data-selectable-paragraph=\"\">Another way to pass secrets in AWS CloudFormation is by using dynamic references in the stack template.<\/p><p id=\"5f67\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">MyRDSInstance:<\/code><\/p><p id=\"0775\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">Type: 'AWS::RDS::DBInstance'<\/code><\/p><p id=\"e591\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">Properties:<\/code><\/p><p id=\"6654\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">DBName: MyRDSInstance<\/code><\/p><p id=\"fc37\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">AllocatedStorage: '20'<\/code><\/p><p id=\"343d\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">DBInstanceClass: db.t2.micro<\/code><\/p><p id=\"c211\" class=\"lv lw ct ba lx b ly lz ma mb mc md me mf mg mh mi\" data-selectable-paragraph=\"\"><code class=\"nb tb tc td te b\">Engine: mysql MasterUsername:'{{resolve:secretsmanager:MyRDSSecret:SecretString:username}' MasterUserPassword:'{{resolve:secretsmanager:MyRDSSecret:SecretString:password}}'<\/code><\/p><\/div>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Securing passwords in AWS Quick Starts using AWS Secrets Manager A secure password is more than eight characters long and is complex \u2014 including lowercase letters, uppercase letters, numbers, and special characters. Complex passwords tend to be hard to remember, which is partly what makes them more secure. Complex passwords can also be hard to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[25,1],"tags":[],"class_list":["post-4889","post","type-post","status-publish","format-standard","hentry","category-blogs","category-uncategorized"],"acf":[],"_links":{"self":[{"href":"https:\/\/petabytz.com\/blogs\/wp-json\/wp\/v2\/posts\/4889","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/petabytz.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/petabytz.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/petabytz.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/petabytz.com\/blogs\/wp-json\/wp\/v2\/comments?post=4889"}],"version-history":[{"count":3,"href":"https:\/\/petabytz.com\/blogs\/wp-json\/wp\/v2\/posts\/4889\/revisions"}],"predecessor-version":[{"id":14729,"href":"https:\/\/petabytz.com\/blogs\/wp-json\/wp\/v2\/posts\/4889\/revisions\/14729"}],"wp:attachment":[{"href":"https:\/\/petabytz.com\/blogs\/wp-json\/wp\/v2\/media?parent=4889"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/petabytz.com\/blogs\/wp-json\/wp\/v2\/categories?post=4889"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/petabytz.com\/blogs\/wp-json\/wp\/v2\/tags?post=4889"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}