Skip to content

Commit 32a77d9

Browse files
author
Vieltojarvi
committed
fixing permissions
1 parent 909813c commit 32a77d9

File tree

3 files changed

+7
-55
lines changed

3 files changed

+7
-55
lines changed

packages/cli/src/seed-policy-generation/generate_seed_policy_template.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,10 @@ export const generateSeedPolicyTemplate = async (
2727
'Please add an auth resource to your sandbox and rerun this command',
2828
});
2929
}
30-
// /const userPoolId = clientConfig.auth?.user_pool_id;
3130

3231
const stsResponse = await stsClient.send(new GetCallerIdentityCommand({}));
3332
const arn = `arn:aws:cognito-idp:${clientConfig.auth.aws_region}:${stsResponse.Account}:userpool/${clientConfig.auth.user_pool_id}`;
34-
/*const userpoolOutput = await cognitoIdProvider.send(
35-
new DescribeUserPoolCommand({ UserPoolId: userPoolId })
36-
);
37-
const userpoolArn = userpoolOutput.UserPool?.Arn;
38-
// so long as there is an auth resource we should always be able to get an Arn for the userpool
39-
if (!userpoolArn) {
40-
throw new AmplifyFault('MissingUserpoolArnFault', {
41-
message:
42-
'Either the userpool is missing or the userpool exists but it is missing an arn',
43-
resolution: 'Ensure your userpool exists and has an arn',
44-
});
45-
}*/
33+
4634
const cognitoGrant = new PolicyStatement({
4735
effect: Effect.ALLOW,
4836
actions: ['cognito-idp:AdminCreateUser', 'cognito-idp:AdminAddUserToGroup'],

packages/integration-tests/src/test-project-setup/seed_test_project.ts

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ import { TestProjectCreator } from './test_project_creator.js';
44
import { AmplifyClient } from '@aws-sdk/client-amplify';
55
import { e2eToolingClientConfig } from '../e2e_tooling_client_config.js';
66
import { CognitoIdentityProviderClient } from '@aws-sdk/client-cognito-identity-provider';
7-
import {
8-
AttachRolePolicyCommand,
9-
CreatePolicyCommand,
10-
IAMClient,
11-
} from '@aws-sdk/client-iam';
127
import fsp from 'fs/promises';
138
import assert from 'node:assert';
149
import { createEmptyAmplifyProject } from './create_empty_amplify_project.js';
@@ -26,8 +21,6 @@ import { AUTH_TYPE, createAuthLink } from 'aws-appsync-auth-link';
2621
import { AmplifyAuthCredentialsFactory } from '../amplify_auth_credentials_factory.js';
2722
import { execa, execaSync } from 'execa';
2823
import { AssumeRoleCommand, STSClient } from '@aws-sdk/client-sts';
29-
import { shortUuid } from '../short_uuid.js';
30-
import { ManagedPolicy } from 'aws-cdk-lib/aws-iam';
3124
import { SemVer } from 'semver';
3225

3326
// TODO: this is a work around - in theory this should be fixed
@@ -60,9 +53,6 @@ export class SeedTestProjectCreator implements TestProjectCreator {
6053
private readonly cognitoIdentityProviderClient: CognitoIdentityProviderClient = new CognitoIdentityProviderClient(
6154
e2eToolingClientConfig
6255
),
63-
private readonly iamClient: IAMClient = new IAMClient(
64-
e2eToolingClientConfig
65-
),
6656
private readonly stsClient: STSClient = new STSClient(
6757
e2eToolingClientConfig
6858
)
@@ -79,7 +69,6 @@ export class SeedTestProjectCreator implements TestProjectCreator {
7969
this.cfnClient,
8070
this.amplifyClient,
8171
this.cognitoIdentityProviderClient,
82-
this.iamClient,
8372
this.stsClient
8473
);
8574
await fsp.cp(
@@ -110,7 +99,6 @@ class SeedTestProject extends TestProjectBase {
11099
cfnClient: CloudFormationClient,
111100
amplifyClient: AmplifyClient,
112101
private readonly cognitoIdentityProviderClient: CognitoIdentityProviderClient,
113-
private readonly iamClient: IAMClient,
114102
private readonly stsClient: STSClient
115103
) {
116104
super(
@@ -128,7 +116,6 @@ class SeedTestProject extends TestProjectBase {
128116
) {
129117
await super.deploy(backendIdentifier, environment);
130118

131-
console.log('Executing seed policy command');
132119
const command = execaSync('npx', ['which', 'ampx'], {
133120
cwd: this.projectDirPath,
134121
}).stdout.trim();
@@ -140,9 +127,7 @@ class SeedTestProject extends TestProjectBase {
140127
env: environment,
141128
}
142129
);
143-
//await this.attachToRole(seedPolicyProcess.stdout, backendIdentifier);
144130

145-
console.log(seedPolicyProcess.stdout);
146131
const clientConfig = await generateClientConfig(backendIdentifier, '1.3');
147132
if (!clientConfig.custom) {
148133
throw new Error('Client config missing custom section');
@@ -156,9 +141,7 @@ class SeedTestProject extends TestProjectBase {
156141
Policy: seedPolicyProcess.stdout,
157142
PolicyArns: [
158143
{
159-
arn: ManagedPolicy.fromAwsManagedPolicyName(
160-
'service-role/AmplifyBackendDeployFullAccess'
161-
).managedPolicyArn,
144+
arn: 'arn:aws:iam::aws:policy/service-role/AmplifyBackendDeployFullAccess',
162145
},
163146
],
164147
})
@@ -169,7 +152,6 @@ class SeedTestProject extends TestProjectBase {
169152
assert.ok(seedCredentials.Credentials.SessionToken);
170153
assert.ok(seedCredentials.Credentials.SecretAccessKey);
171154

172-
console.log('executing seed command');
173155
await ampxCli(['sandbox', 'seed'], this.projectDirPath, {
174156
env: {
175157
AWS_ACCESS_KEY_ID: seedCredentials.Credentials!.AccessKeyId,
@@ -237,25 +219,4 @@ class SeedTestProject extends TestProjectBase {
237219
`Todo list item for ${testUsername}`
238220
);
239221
}
240-
241-
async attachToRole(policyString: string, backendId: BackendIdentifier) {
242-
const policy = await this.iamClient.send(
243-
new CreatePolicyCommand({
244-
PolicyName: `seedPolicy_${shortUuid()}`,
245-
PolicyDocument: policyString,
246-
})
247-
);
248-
249-
const clientConfig = await generateClientConfig(backendId, '1.3');
250-
if (!clientConfig.custom) {
251-
throw new Error('Client config missing custom section');
252-
}
253-
254-
await this.iamClient.send(
255-
new AttachRolePolicyCommand({
256-
RoleName: clientConfig.custom.seedRoleName as string,
257-
PolicyArn: policy.Policy?.Arn,
258-
})
259-
);
260-
}
261222
}

packages/integration-tests/src/test-projects/seed-test-project/amplify/backend.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defineBackend } from '@aws-amplify/backend';
22
import { auth } from './auth/resource.js';
33
import { data } from './data/resource.js';
4-
import { AccountPrincipal, Role } from 'aws-cdk-lib/aws-iam';
4+
import { AccountPrincipal, ManagedPolicy, Role } from 'aws-cdk-lib/aws-iam';
55
import { RemovalPolicy } from 'aws-cdk-lib';
66

77
/**
@@ -14,10 +14,13 @@ const backend = defineBackend({
1414

1515
const seedRoleStack = backend.createStack('seed-policy');
1616

17-
// need AmplifyBackendDeployFullAccess to be able to generate configs, would rather not add these permissions directly to the seed policy
17+
// this role has AdminAccess because the policies this role can assume are subset of the policies it initially has - it never directly uses AdminAccess
1818
const seedRole = new Role(seedRoleStack, 'SeedRole', {
1919
assumedBy: new AccountPrincipal(seedRoleStack.account),
2020
path: '/',
21+
managedPolicies: [
22+
ManagedPolicy.fromAwsManagedPolicyName('AdministratorAccess'),
23+
],
2124
});
2225
seedRole.applyRemovalPolicy(RemovalPolicy.DESTROY);
2326

0 commit comments

Comments
 (0)