Skip to content

Commit 1cc60b2

Browse files
authored
ignore attach/detach scps to nested OUs (#942)
* ignore attach/detach scps to nested OUs * Fitler out nested ous from SCP detach/attach Co-authored-by: hickeydh-aws <hickeydh@amazon.com>
1 parent 5773ba5 commit 1cc60b2

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,12 @@ export const handler = async (input: AddScpInput) => {
9393

9494
// Find roots to attach FullAWSAccess
9595
const rootIds = await scps.organizationRoots();
96+
const rootOus = organizationalUnits.filter(ou => {
97+
return !ou.ouPath.includes('/');
98+
});
9699

97100
// Find Accelerator accounts and OUs to attach FullAWSAccess
98-
const acceleratorOuIds = organizationalUnits.map(ou => ou.ouId);
101+
const acceleratorOuIds = rootOus.map(ou => ou.ouId);
99102
const acceleratorAccountIds = accounts.map(a => a.id);
100103
const acceleratorTargetIds = [...rootIds, ...acceleratorOuIds, ...acceleratorAccountIds];
101104
const acceleratorTargetOuIds = [...rootIds, ...acceleratorOuIds];

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,16 @@ export const handler = async (input: ScheduledEvent) => {
110110
if (ignoredOus.length > 0) {
111111
if (targetId.startsWith('ou-')) {
112112
const destinationOrg = await organizations.getOrganizationalUnitWithPath(targetId);
113+
console.log(JSON.stringify(destinationOrg, null, 2));
113114
const destinationRootOrg = destinationOrg.Name!;
114115
if (ignoredOus.includes(destinationRootOrg)) {
115116
console.log(`${eventName} is on ignored-ou from ROOT, no need to reattach`);
116117
return 'IGNORE';
117118
}
119+
if (destinationOrg.Path.includes('/')) {
120+
console.log(`${destinationOrg.Path} is a nested OU under ${destinationOrg.Name}. Ignoring`);
121+
return 'IGNORE';
122+
}
118123
} else {
119124
const accountObject = accounts.find(acc => acc.accountId === targetId);
120125
if (ignoredOus.includes(accountObject?.organizationalUnit!)) {

0 commit comments

Comments
 (0)