Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving AWS Config security pattern #172

Merged
merged 6 commits into from
May 15, 2024

Conversation

aliaksei-ivanou
Copy link
Contributor

@aliaksei-ivanou aliaksei-ivanou commented May 10, 2024

Issue #, if available:

Description of changes:

  1. Adding pre-deployment checks to prevent the stack deployment failure because AWS Config recorder or a delivery channel already exist in the target account and region:
    a. Check if AWS Config recorder is already enabled in the target account and region.
    b. Check if a delivery channel is already configured in the target account and region.
  2. Send SNS notifications when AWS Config rules compliance status changes.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link
Contributor

@shapirov103 shapirov103 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gret work, a few comments.

console.log(err, err.stack);
} else {
if (data.ConfigurationRecorders?.length === 0) {
console.log("AWS Config is not enabled in this region.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you specify the region as opposed to "this"?

const awsConfig = new AWS.ConfigService();
awsConfig.describeConfigurationRecorders({}, (err, data) => {
if (err) {
console.log(err, err.stack);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use logger from blueprints for error messages and info messages, otherwise there is no control to suppress and elevate these.

const logger = blueprints.utils.logger;

applies elsewhere

});
// Check if AWS Config is already enabled in the region
const awsConfig = new AWS.ConfigService();
awsConfig.describeConfigurationRecorders({}, (err, data) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is getting a bit hard to maintain if you use this callback style (callback hell). Let's use async/await and this style of SDK invocation:

import { DescribeConfigurationRecordersCommand } from "@aws-sdk/client-config-service";

const command = new DescribeConfigurationRecordersCommand(input);
const response = await client.send(command);

You can use try/catch with this. You will need to move this code away from the constructor as constructor can have async.

It is a minor change, example here but it will improve readability and maintenance.

@aliaksei-ivanou
Copy link
Contributor Author

@shapirov103 addressed


const logger = blueprints.utils.logger;

(async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aliaksei-ivanou let's move it to a method like async buildConfigStack and remove => and such.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

Copy link
Contributor

@shapirov103 shapirov103 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, great work!

@shapirov103 shapirov103 merged commit 2dc0888 into aws-samples:main May 15, 2024
2 checks passed
@aliaksei-ivanou aliaksei-ivanou deleted the config-improvement branch May 15, 2024 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants