Skip to content

Commit f37be60

Browse files
authored
Revert "Fix for Issue# 1060: Cannot enforce an AWS Backup Policy (#1106)" (#1119)
This reverts commit 055c6a8.
1 parent 6642b61 commit f37be60

File tree

4 files changed

+21
-51
lines changed

4 files changed

+21
-51
lines changed

reference-artifacts/SCPs/ASEA-Guardrails-Part0-CoreOUs.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,9 @@
102102
"Action": [
103103
"acm:DeleteCert*",
104104
"acm:ExportCert*",
105-
"acm:AddTagsToCert*",
106105
"acm:RemoveTagsFromCert*",
107106
"elasticloadbalancing:DeleteLoadBal*",
108-
"elasticloadbalancing:DeleteTargetG*",
109-
"elasticloadbalancing:AddTags",
110-
"elasticloadbalancing:RemoveTags"
107+
"elasticloadbalancing:DeleteTargetG*"
111108
],
112109
"Resource": "*",
113110
"Condition": {

reference-artifacts/SCPs/ASEA-Guardrails-Part0-WkldOUs.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,9 @@
102102
"Action": [
103103
"acm:DeleteCert*",
104104
"acm:ExportCert*",
105-
"acm:AddTagsToCert*",
106105
"acm:RemoveTagsFromCert*",
107106
"elasticloadbalancing:DeleteLoadBal*",
108-
"elasticloadbalancing:DeleteTargetG*",
109-
"elasticloadbalancing:AddTags",
110-
"elasticloadbalancing:RemoveTags"
107+
"elasticloadbalancing:DeleteTargetG*"
111108
],
112109
"Resource": "*",
113110
"Condition": {

reference-artifacts/SCPs/ASEA-Guardrails-Part1.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
"ec2:DeleteSecurityGroup",
99
"ec2:RevokeSecurityGroup*",
1010
"ec2:AuthorizeSecurityGroup*",
11-
"ec2:CreateSecurityGroup",
12-
"ec2:DeleteTags"
11+
"ec2:CreateSecurityGroup"
1312
],
1413
"Resource": "*",
1514
"Condition": {
@@ -222,8 +221,7 @@
222221
"ec2:DeleteSubnet",
223222
"ec2:DeleteRoute",
224223
"ec2:DetachInternetGateway",
225-
"ec2:DisassociateRouteTable",
226-
"ec2:DeleteTags"
224+
"ec2:DisassociateRouteTable"
227225
],
228226
"Resource": "*",
229227
"Condition": {

src/deployments/runtime/src/ou-validation-events/policy-changes.ts

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,12 @@ export const handler = async (input: ScheduledEvent) => {
8383
return 'INVALID_REQUEST';
8484
}
8585

86-
// describe policy
87-
const policyResponse = await organizations.describePolicy(policyId);
88-
const policy = policyResponse.Policy;
89-
if (!policy) {
90-
console.error(`Invalid PolicyId provided ${policyId}`);
91-
return false;
92-
}
93-
94-
if (!isServiceControlPolicy(policy)) {
95-
console.log('The policy is NOT of type SERVICE_CONTROL_POLICY; No operation required');
96-
return 'NO_OPERATION_REQUIRED';
97-
}
98-
99-
if (isControlTowerSCP(policy)) {
100-
console.log('Policy Changes Performed by Control Tower; No operation required');
86+
if (await isControlTowerSCP(policyId)) {
87+
console.log('Policy Changes Performed by Control Tower, No operation required');
10188
return 'NO_OPERATION_REQUIRED';
10289
}
10390
const eventName = requestDetail.eventName;
104-
if (!['DeletePolicy', 'AttachPolicy'].includes(eventName) && !isAcceleratorScp(policy, scpNames)) {
91+
if (!['DeletePolicy', 'AttachPolicy'].includes(eventName) && !(await isAcceleratorScp(policyId, scpNames))) {
10592
console.log(`SCP ${policyId} is not managed by Accelerator`);
10693
return 'SUCCESS';
10794
}
@@ -168,15 +155,15 @@ export const handler = async (input: ScheduledEvent) => {
168155
);
169156
console.log(`SCP Names for Target are :: ${acclScpNames}`);
170157
if (eventName === 'AttachPolicy') {
171-
if (isAcceleratorScp(policy, acclScpNames)) {
158+
if (await isAcceleratorScp(policyId, acclScpNames)) {
172159
console.log('Accelerator Managed policy is attached');
173160
return 'IGNORE';
174161
}
175162
// Detach target from policy
176163
console.log(`Detaching target "${targetId}" from policy "${policyId}"`);
177164
await organizations.detachPolicy(policyId, targetId);
178165
} else {
179-
if (!isAcceleratorScp(policy, acclScpNames)) {
166+
if (!(await isAcceleratorScp(policyId, acclScpNames))) {
180167
console.log('Non Accelerator Managed policy is detached');
181168
return 'IGNORE';
182169
}
@@ -249,44 +236,35 @@ export const handler = async (input: ScheduledEvent) => {
249236
return 'SUCCESS';
250237
};
251238

252-
function isAcceleratorScp(policy: any, scpNames: string[]): boolean {
239+
async function isAcceleratorScp(policyId: string, scpNames: string[]): Promise<boolean> {
240+
const policyResponse = await organizations.describePolicy(policyId);
241+
const policy = policyResponse.Policy;
242+
if (!policy) {
243+
console.error(`Invalid PolicyId provided ${policyId}`);
244+
return false;
245+
}
253246
const policyName = policy.PolicySummary?.Name;
254247
if (!policyName) {
255-
console.error(`isAcceleratorScp - Invalid policy name`);
256248
return false;
257249
}
258-
if (policyName !== FULL_AWS_ACCESS_POLICY_NAME && !scpNames.includes(policyName!)) {
250+
if (policyName !== FULL_AWS_ACCESS_POLICY_NAME && !scpNames.includes(policy.PolicySummary?.Name!)) {
259251
console.error(`Policy is not handled through Accelerator`);
260252
return false;
261253
}
262254
return true;
263255
}
264256

265-
function isControlTowerSCP(policy: any): boolean {
257+
async function isControlTowerSCP(policyId: string): Promise<boolean> {
258+
const policyResponse = await organizations.describePolicy(policyId);
259+
const policy = policyResponse.Policy;
260+
266261
const policyName = policy?.PolicySummary?.Name;
267262
if (policyName?.startsWith('aws-guardrails-')) {
268263
return true;
269264
}
270265
return false;
271266
}
272267

273-
/**
274-
* Checks if the policy type is SERVICE_CONTROL_POLICY.
275-
* @see https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/organizations.html#Organizations.Client.describe_policy
276-
*/
277-
function isServiceControlPolicy(policy: any): boolean {
278-
const policyType: string = policy?.PolicySummary?.Type;
279-
if (!policyType) {
280-
console.error(`isServiceControlPolicy - Invalid policy type`);
281-
return false;
282-
}
283-
console.log(`isServiceControlPolicy - Policy type : ${policyType}`);
284-
if (policyType === 'SERVICE_CONTROL_POLICY') {
285-
return true;
286-
}
287-
return false;
288-
}
289-
290268
async function loadAccountsAndOrganizationsFromConfig(
291269
config: AcceleratorConfig,
292270
): Promise<{ organizationalUnits: OrganizationalUnit[]; accounts: ConfigurationAccount[] }> {

0 commit comments

Comments
 (0)