Skip to content

Commit 2908b0f

Browse files
authored
Revert "feat(core) Enable account level SCP mgmt (#691)" (#707)
This reverts commit 2007c88.
1 parent 2007c88 commit 2908b0f

File tree

4 files changed

+0
-91
lines changed

4 files changed

+0
-91
lines changed

reference-artifacts/SAMPLE_CONFIGS/sample_snippets.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -705,17 +705,6 @@
705705

706706
---
707707

708-
- Add SCP on a per account basis - add this to either workload or mandatory accounts sections
709-
710-
```
711-
"scps": [
712-
"SCP 1",
713-
"SCP 2"
714-
]
715-
```
716-
717-
---
718-
719708
- Future description
720709

721710
```

src/core/runtime/src/add-scp-step.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,6 @@ export const handler = async (input: AddScpInput) => {
103103
acceleratorPrefix,
104104
});
105105

106-
await scps.attachOrDetachPoliciesToAccounts({
107-
existingPolicies,
108-
configurationAccounts: accounts,
109-
accountConfigs: config.getAccountConfigs(),
110-
acceleratorPrefix,
111-
});
112-
113106
return {
114107
status: 'SUCCESS',
115108
};

src/lib/common-config/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,6 @@ export const MandatoryAccountConfigType = t.interface({
592592
'populate-all-elbs-in-param-store': fromNullable(t.boolean, false),
593593
'ssm-automation': fromNullable(t.array(SsmShareAutomation), []),
594594
'aws-config': fromNullable(t.array(AwsConfigAccountConfig), []),
595-
scps: optional(t.array(t.string)),
596595
});
597596

598597
export type MandatoryAccountConfig = t.TypeOf<typeof MandatoryAccountConfigType>;

src/lib/common/src/scp/index.ts

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import { stringType } from 'aws-sdk/clients/iam';
55
import { PolicySummary } from 'aws-sdk/clients/organizations';
66
import { OrganizationalUnit } from '@aws-accelerator/common-outputs/src/organizations';
77
import { additionalReplacements, replaceDefaults } from './../util/common';
8-
import { AccountConfig } from '@aws-accelerator/common-config/src';
9-
import { Account } from '@aws-accelerator/common-outputs/src/accounts';
108

119
export const FULL_AWS_ACCESS_POLICY_NAME = 'FullAWSAccess';
1210

@@ -268,76 +266,6 @@ export class ServiceControlPolicy {
268266
}
269267
}
270268

271-
/**
272-
* Attach new or detach removed policies based on the account configuration.
273-
*/
274-
async attachOrDetachPoliciesToAccounts(props: {
275-
existingPolicies: PolicySummary[];
276-
configurationAccounts: Account[];
277-
accountConfigs: [string, AccountConfig][];
278-
acceleratorPrefix: string;
279-
}) {
280-
const { existingPolicies, configurationAccounts, accountConfigs, acceleratorPrefix } = props;
281-
282-
for (const [accountKey, accountConfig] of accountConfigs) {
283-
const Account = configurationAccounts.find(Account => Account.key === accountKey);
284-
/**
285-
* Check if scps key is set on account. If not, ignore as SCPs are being managed in the outside the installer.
286-
*/
287-
if (accountConfig.scps == null) {
288-
continue;
289-
}
290-
291-
// Attach Accelerator SCPs to Accounts
292-
if (!Account) {
293-
console.warn(`Cannot find Account configuration with key "${accountKey}"`);
294-
continue;
295-
}
296-
297-
const accountPolicyNames = accountConfig.scps.map(policyName =>
298-
ServiceControlPolicy.policyNameToAcceleratorPolicyName({ acceleratorPrefix, policyName }),
299-
);
300-
301-
if (accountPolicyNames.length > 4) {
302-
console.warn(`Maximum allowed SCP per Account is 5. Limit exceeded for Account ${accountKey}`);
303-
continue;
304-
}
305-
306-
// Find targets for this policy
307-
const policyTargets = await this.org.listPoliciesForTarget({
308-
Filter: 'SERVICE_CONTROL_POLICY',
309-
TargetId: Account.id,
310-
});
311-
312-
// Detach removed policies
313-
for (const policyTarget of policyTargets) {
314-
const policyTargetName = policyTarget.Name!;
315-
if (!accountPolicyNames.includes(policyTargetName) && policyTargetName !== FULL_AWS_ACCESS_POLICY_NAME) {
316-
console.log(`Detaching ${policyTargetName} from Account ${accountKey}`);
317-
await this.org.detachPolicy(policyTarget.Id!, Account.id);
318-
}
319-
}
320-
321-
// Attach new policies
322-
for (const accountPolicyName of accountPolicyNames) {
323-
const policy = existingPolicies.find(p => p.Name === accountPolicyName);
324-
if (!policy) {
325-
console.warn(`Cannot find policy with name "${accountPolicyName}"`);
326-
continue;
327-
}
328-
329-
const policyTarget = policyTargets.find(x => x.Name === accountPolicyName);
330-
if (policyTarget) {
331-
console.log(`Skipping attachment of ${accountPolicyName} to already attached Account ${accountKey}`);
332-
continue;
333-
}
334-
335-
console.log(`Attaching ${accountPolicyName} to Account ${accountKey}`);
336-
await this.org.attachPolicy(policy.Id!, Account.id);
337-
}
338-
}
339-
}
340-
341269
static createQuarantineScpContent(props: { acceleratorPrefix: string; organizationAdminRole: string }) {
342270
return JSON.stringify({
343271
Version: '2012-10-17',

0 commit comments

Comments
 (0)