nomoss 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/README.md +5 -15
- package/ROADMAP.md +2 -0
- package/docs/README.md +1 -1
- package/docs/application/aws-resource-coverage.md +26 -0
- package/docs/application/aws-resource-lifecycle-management.md +13 -23
- package/docs/application/cli-workflow.md +1 -1
- package/docs/application/engine-design.md +2 -2
- package/docs/application/generation-architecture.md +10 -45
- package/docs/application/resource-command-policy-stage.md +2 -2
- package/docs/application/resource-graph.md +1 -1
- package/docs/application/resource-lifecycle-tracker.md +1 -9
- package/docs/application/resource-mapping.md +4 -9
- package/docs/application/resource-operations.md +4 -2
- package/docs/application/tracing.md +2 -6
- package/docs/development/code-documentation.md +2 -0
- package/docs/development/effect-native-development.md +44 -0
- package/docs/development/linting.md +1 -1
- package/docs/development/review-code.md +22 -6
- package/docs/development/review-remediation-spec.md +28 -37
- package/docs/development/spec-writing.md +1 -1
- package/docs/development/testing.md +23 -9
- package/docs/operations/observability-sop.md +11 -17
- package/docs/operations/releasing.md +3 -1
- package/examples/README.md +3 -26
- package/examples/commands.ts +2 -36
- package/examples/queue/application.ts +8 -2
- package/examples/state-machine/application.ts +3 -1
- package/package.json +40 -46
- package/providers/aws/README.md +21 -0
- package/providers/aws/awsEnvironment.ts +114 -0
- package/providers/aws/generated/managementRegistry.ts +136 -0
- package/{src/providers/aws/resources/generated/native/apigatewayv2/api/index.ts → providers/aws/generated/resources/apigatewayv2/api.ts} +13 -50
- package/{src/providers/aws/resources/generated/native/apigatewayv2/integration/index.ts → providers/aws/generated/resources/apigatewayv2/integration.ts} +13 -37
- package/{src/providers/aws/resources/generated/native/apigatewayv2/route/index.ts → providers/aws/generated/resources/apigatewayv2/route.ts} +23 -40
- package/{src/providers/aws/resources/generated/native/apigatewayv2/stage/index.ts → providers/aws/generated/resources/apigatewayv2/stage.ts} +13 -38
- package/providers/aws/generated/resources/iam/accesskey.ts +184 -0
- package/{src/providers/aws/resources/generated/native/iam/group/index.ts → providers/aws/generated/resources/iam/group.ts} +13 -38
- package/{src/providers/aws/resources/generated/native/iam/grouppolicy/index.ts → providers/aws/generated/resources/iam/grouppolicy.ts} +29 -59
- package/{src/providers/aws/resources/generated/native/iam/instanceprofile/index.ts → providers/aws/generated/resources/iam/instanceprofile.ts} +13 -41
- package/{src/providers/aws/resources/generated/native/iam/managedpolicy/index.ts → providers/aws/generated/resources/iam/managedpolicy.ts} +13 -95
- package/providers/aws/generated/resources/iam/oidcprovider.ts +314 -0
- package/{src/providers/aws/resources/generated/native/iam/policy/index.ts → providers/aws/generated/resources/iam/policy.ts} +13 -28
- package/{src/providers/aws/resources/generated/native/iam/role/index.ts → providers/aws/generated/resources/iam/role.ts} +13 -47
- package/{src/providers/aws/resources/generated/native/iam/rolepolicy/index.ts → providers/aws/generated/resources/iam/rolepolicy.ts} +29 -59
- package/providers/aws/generated/resources/iam/samlprovider.ts +463 -0
- package/providers/aws/generated/resources/iam/servercertificate.ts +465 -0
- package/providers/aws/generated/resources/iam/servicelinkedrole.ts +187 -0
- package/{src/providers/aws/resources/generated/native/iam/user/index.ts → providers/aws/generated/resources/iam/user.ts} +13 -38
- package/{src/providers/aws/resources/generated/native/iam/userpolicy/index.ts → providers/aws/generated/resources/iam/userpolicy.ts} +29 -59
- package/{src/providers/aws/resources/generated/native/iam/usertogroupaddition/index.ts → providers/aws/generated/resources/iam/usertogroupaddition.ts} +13 -27
- package/providers/aws/generated/resources/iam/virtualmfadevice.ts +298 -0
- package/{src/providers/aws/resources/generated/native/kms/key/index.ts → providers/aws/generated/resources/kms/key.ts} +13 -41
- package/{src/providers/aws/resources/generated/native/lambda/function/index.ts → providers/aws/generated/resources/lambda/function.ts} +13 -63
- package/{src/providers/aws/resources/generated/native/lambda/permission/index.ts → providers/aws/generated/resources/lambda/permission.ts} +13 -55
- package/{src/providers/aws/resources/generated/native/s3/bucket/index.ts → providers/aws/generated/resources/s3/bucket.ts} +14 -104
- package/{src/providers/aws/resources/generated/native/sns/topic/index.ts → providers/aws/generated/resources/sns/topic.ts} +14 -29
- package/{src/providers/aws/resources/generated/native/sqs/queue/index.ts → providers/aws/generated/resources/sqs/queue.ts} +14 -38
- package/{src/providers/aws/resources/generated/native/stepfunctions/statemachine/index.ts → providers/aws/generated/resources/stepfunctions/statemachine.ts} +15 -58
- package/providers/aws/management/mappings/iam/group.ts +63 -0
- package/providers/aws/management/mappings/iam/iamIdentity.ts +41 -0
- package/providers/aws/management/mappings/iam/iamLifecycleSettings.ts +8 -0
- package/providers/aws/management/mappings/iam/inlinePolicies.ts +159 -0
- package/providers/aws/management/mappings/iam/instanceProfile.ts +77 -0
- package/providers/aws/management/mappings/iam/oidcProvider.ts +94 -0
- package/providers/aws/management/mappings/iam/role.ts +74 -0
- package/providers/aws/management/mappings/iam/samlProvider.ts +98 -0
- package/providers/aws/management/mappings/iam/serverCertificate.ts +72 -0
- package/providers/aws/management/mappings/iam/user.ts +61 -0
- package/providers/aws/management/mappings/iam/userToGroupAddition.ts +75 -0
- package/providers/aws/management/operations/iam/accessKey.ts +206 -0
- package/providers/aws/management/operations/iam/managedPolicy.ts +491 -0
- package/providers/aws/management/operations/iam/policy.ts +476 -0
- package/providers/aws/management/operations/iam/serviceLinkedRole.ts +172 -0
- package/providers/aws/management/operations/iam/virtualMfaDevice.ts +253 -0
- package/providers/aws/management/resourceAssociationConfiguration.ts +112 -0
- package/providers/aws/management/resourceAssociationRegistration.ts +349 -0
- package/providers/aws/management/resourceAssociations.ts +168 -0
- package/{src/providers → providers}/aws/management/resourceConfiguration.ts +24 -26
- package/providers/aws/management/resourceLifecycleRegistration.ts +540 -0
- package/providers/aws/management/resourceManagementModule.ts +31 -0
- package/providers/aws/management/resourceManagementRegistry.ts +62 -0
- package/providers/aws/management/resourceMapping.ts +84 -0
- package/providers/aws/management/resourceOperation.ts +134 -0
- package/providers/aws/management/resourceTagOperations.ts +108 -0
- package/providers/aws/management/resourceTiming.ts +4 -0
- package/providers/aws/runtime.ts +52 -0
- package/src/core/resource/resourceCommandPolicy.ts +20 -0
- package/src/core/resource/resourceLifecycle.ts +644 -0
- package/src/core/resource/resourceStabilization.ts +120 -0
- package/src/core/resource/resourceVersions.ts +102 -0
- package/src/core/stack/planner.ts +9 -0
- package/src/core/stack/resourceStackLifecycle.ts +36 -3
- package/src/core/state/resourceState.ts +6 -4
- package/src/core/state/stateStore.ts +57 -10
- package/src/providers/file/resourcePolicy.ts +13 -12
- package/src/providers/providerRuntimeLayer.ts +5 -2
- package/src/providers/resourceCommandPolicyLayer.ts +117 -37
- package/src/providers/stripe/management/resourcePolicy.ts +22 -11
- package/examples/http-echo/application.ts +0 -87
- package/src/providers/aws/client/awsClient.ts +0 -418
- package/src/providers/aws/client/awsClientConfig.ts +0 -133
- package/src/providers/aws/client/awsClientModel.ts +0 -119
- package/src/providers/aws/client/awsHttpOperation.ts +0 -153
- package/src/providers/aws/client/awsQueryOperation.ts +0 -149
- package/src/providers/aws/client/awsRequestSigner.ts +0 -115
- package/src/providers/aws/client/awsResponseDecoder.ts +0 -135
- package/src/providers/aws/client/awsRetryPolicy.ts +0 -62
- package/src/providers/aws/client/generated/apiGatewayV2.ts +0 -3025
- package/src/providers/aws/client/generated/cloudControl.ts +0 -5746
- package/src/providers/aws/client/generated/iam.ts +0 -10892
- package/src/providers/aws/client/generated/lambda.ts +0 -5403
- package/src/providers/aws/client/generated/sqs.ts +0 -3769
- package/src/providers/aws/client/generated/stepFunctions.ts +0 -1726
- package/src/providers/aws/client/openapi/cloudControl/CancelResourceRequest.json +0 -579
- package/src/providers/aws/client/openapi/cloudControl/CreateResource.json +0 -1019
- package/src/providers/aws/client/openapi/cloudControl/DeleteResource.json +0 -1018
- package/src/providers/aws/client/openapi/cloudControl/GetResource.json +0 -883
- package/src/providers/aws/client/openapi/cloudControl/GetResourceRequestStatus.json +0 -655
- package/src/providers/aws/client/openapi/cloudControl/ListResourceRequests.json +0 -566
- package/src/providers/aws/client/openapi/cloudControl/ListResources.json +0 -913
- package/src/providers/aws/client/openapi/cloudControl/UpdateResource.json +0 -1027
- package/src/providers/aws/cloudControl/client.ts +0 -69
- package/src/providers/aws/cloudControl/requestTracker.ts +0 -138
- package/src/providers/aws/cloudControl/resourceCommandPolicyLayer.ts +0 -63
- package/src/providers/aws/cloudControl/resourceLifecycle.ts +0 -479
- package/src/providers/aws/cloudControl/resources/generated/certificatemanager/certificate/index.ts +0 -179
- package/src/providers/aws/cloudControl/resources/generated/kms/key/index.ts +0 -362
- package/src/providers/aws/cloudControl/resources/generated/s3/bucket/index.ts +0 -2364
- package/src/providers/aws/cloudControl/resources/generated/sns/topic/index.ts +0 -326
- package/src/providers/aws/cloudControl/resources/generated/sqs/queue/index.ts +0 -307
- package/src/providers/aws/cloudControl/resources/generated/sqs/queueinlinepolicy/index.ts +0 -108
- package/src/providers/aws/cloudControl/runtime.ts +0 -127
- package/src/providers/aws/management/resourceMapping.ts +0 -343
- package/src/providers/aws/management/resourceOperation.ts +0 -57
- package/src/providers/aws/management/resourcePolicy.ts +0 -549
- package/src/providers/aws/management/resourceRegistration.ts +0 -294
- package/src/providers/aws/resources/apiGatewayV2/httpApi.ts +0 -327
- package/src/providers/aws/resources/generated/native/resourceCommands.ts +0 -152
- package/src/providers/aws/resources/iam/grant.ts +0 -150
- package/src/providers/aws/resources/iam/grantCommands.ts +0 -283
- package/src/providers/aws/resources/iam/policyDocument.ts +0 -30
- package/src/providers/aws/resources/iam/policyStatement.ts +0 -59
- package/src/providers/aws/resources/iam/role.ts +0 -426
- package/src/providers/aws/resources/iam/roleDeclaration.ts +0 -105
- package/src/providers/aws/resources/lambda/function.ts +0 -403
- package/src/providers/aws/resources/lambda/functionDeclaration.ts +0 -234
- package/src/providers/aws/resources/lambda/permission.ts +0 -363
- package/src/providers/aws/resources/stepFunctions/stateMachine.ts +0 -95
- package/src/providers/aws/runtime.ts +0 -70
|
@@ -1,426 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Array as Arr,
|
|
3
|
-
Data,
|
|
4
|
-
Effect,
|
|
5
|
-
Exit,
|
|
6
|
-
Layer,
|
|
7
|
-
Match,
|
|
8
|
-
Option,
|
|
9
|
-
pipe,
|
|
10
|
-
Schedule,
|
|
11
|
-
Schema,
|
|
12
|
-
Struct,
|
|
13
|
-
Tuple,
|
|
14
|
-
} from "effect";
|
|
15
|
-
import { Digest } from "effect/crypto";
|
|
16
|
-
import {
|
|
17
|
-
type ResourceCommand,
|
|
18
|
-
ResourceCommandResult,
|
|
19
|
-
ResourceCommandUnsupported,
|
|
20
|
-
ResourceObservation,
|
|
21
|
-
} from "../../../../core/resource/lifecycle.js";
|
|
22
|
-
import {
|
|
23
|
-
ResourceModel,
|
|
24
|
-
type ResourceNode,
|
|
25
|
-
resourceGeneration,
|
|
26
|
-
resourceModelLayer,
|
|
27
|
-
} from "../../../../core/resource/model.js";
|
|
28
|
-
import {
|
|
29
|
-
ResourceCommandExecutionFailed,
|
|
30
|
-
ResourceCommandStackName,
|
|
31
|
-
} from "../../../../core/resource/resourceCommandPolicy.js";
|
|
32
|
-
import { providerCommandPolicyTag } from "../../../resourceCommandPolicyLayer.js";
|
|
33
|
-
import type { AwsServiceError } from "../../client/awsClientModel.js";
|
|
34
|
-
import { makeIAMClient, type Role } from "../../client/generated/iam.js";
|
|
35
|
-
import {
|
|
36
|
-
AWSRoleRequestSchema,
|
|
37
|
-
AWSRoleResourceSchema,
|
|
38
|
-
} from "../generated/native/iam/role/index.js";
|
|
39
|
-
import { encodeIamPolicy } from "./policyDocument.js";
|
|
40
|
-
|
|
41
|
-
const Identity = Schema.Struct({
|
|
42
|
-
RoleName: Schema.String,
|
|
43
|
-
RoleId: Schema.String,
|
|
44
|
-
Arn: Schema.String,
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
type RoleRequest = typeof AWSRoleRequestSchema.Type;
|
|
48
|
-
|
|
49
|
-
class IamRoleIdentityChanged extends Data.TaggedError(
|
|
50
|
-
"IamRoleIdentityChanged",
|
|
51
|
-
)<{
|
|
52
|
-
readonly roleName: string;
|
|
53
|
-
}> {
|
|
54
|
-
override get message() {
|
|
55
|
-
return `IAM role "${this.roleName}" has a different RoleId than the saved role`;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const isMissingRole = (error: { readonly _tag: string }) =>
|
|
60
|
-
error._tag === "AwsServiceError" &&
|
|
61
|
-
"code" in error &&
|
|
62
|
-
error.code === "NoSuchEntity";
|
|
63
|
-
|
|
64
|
-
const missingIsSuccess = (failure: AwsServiceError) =>
|
|
65
|
-
Match.value(failure.code).pipe(
|
|
66
|
-
Match.when("NoSuchEntity", () => Effect.void),
|
|
67
|
-
Match.orElse(() => Effect.fail(failure)),
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
const sameJson = Schema.toEquivalence(Schema.Json);
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* The roleCommands Layer manages role trust and permissions. Configuration
|
|
74
|
-
* changes detach only policies and tags recorded in the last request, so an
|
|
75
|
-
* IAM role read does not grant ownership over unrelated assignments.
|
|
76
|
-
*
|
|
77
|
-
* @see ../../../../../refs/aws-api-models/models/iam/service/2010-05-08/iam-2010-05-08.json (CreateRole, AttachRolePolicy, PutRolePolicy, GetRole and DeleteRole)
|
|
78
|
-
*/
|
|
79
|
-
export const roleCommands = Layer.effect(
|
|
80
|
-
providerCommandPolicyTag(AWSRoleResourceSchema),
|
|
81
|
-
Effect.gen(function* () {
|
|
82
|
-
const iam = yield* makeIAMClient;
|
|
83
|
-
const model = yield* ResourceModel;
|
|
84
|
-
const digest = yield* Digest.Digest;
|
|
85
|
-
|
|
86
|
-
const readRole = (RoleName: string) =>
|
|
87
|
-
iam.getRole({ RoleName }).pipe(
|
|
88
|
-
Effect.map(({ Role }) => Option.some(Role)),
|
|
89
|
-
Effect.catchIf(isMissingRole, () =>
|
|
90
|
-
Effect.succeed(Option.none<Role>()),
|
|
91
|
-
),
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
const confirmRole = (RoleName: string) =>
|
|
95
|
-
readRole(RoleName).pipe(
|
|
96
|
-
Effect.repeat({
|
|
97
|
-
while: Option.isNone,
|
|
98
|
-
schedule: Schedule.spaced("1 second"),
|
|
99
|
-
}),
|
|
100
|
-
Effect.timeout("30 seconds"),
|
|
101
|
-
Effect.flatMap(Effect.fromOption),
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* The roleName helper generates the same name for the same declaration
|
|
106
|
-
* across retries. A user-supplied name remains the requested IAM name.
|
|
107
|
-
*
|
|
108
|
-
* @see ../../../../../docs/application/resource-operations.md (resource identity and creation retries)
|
|
109
|
-
*/
|
|
110
|
-
const roleName = Effect.fn("IamRole.roleName")(function* (
|
|
111
|
-
node: ResourceNode,
|
|
112
|
-
request: RoleRequest,
|
|
113
|
-
) {
|
|
114
|
-
return yield* Effect.fromOption(
|
|
115
|
-
Option.fromUndefinedOr(request.RoleName),
|
|
116
|
-
).pipe(
|
|
117
|
-
Effect.catch(() =>
|
|
118
|
-
ResourceCommandStackName.pipe(
|
|
119
|
-
Effect.flatMap(Effect.fromOption),
|
|
120
|
-
Effect.map((stack) =>
|
|
121
|
-
Tuple.make(stack, node.key.logicalId, resourceGeneration(node)),
|
|
122
|
-
),
|
|
123
|
-
Effect.flatMap(
|
|
124
|
-
Schema.encodeEffect(Schema.fromJsonString(Schema.Json)),
|
|
125
|
-
),
|
|
126
|
-
Effect.flatMap((seed) =>
|
|
127
|
-
digest.digestHex(Digest.sha256, new TextEncoder().encode(seed)),
|
|
128
|
-
),
|
|
129
|
-
Effect.map((hash) => `nomoss-${hash.substring(0, 56)}`),
|
|
130
|
-
),
|
|
131
|
-
),
|
|
132
|
-
);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* The applyPolicies operation updates the role's declared assignments.
|
|
137
|
-
* Names present only in the previous request are removed explicitly.
|
|
138
|
-
*
|
|
139
|
-
* @see ../../../../../refs/aws-api-models/models/iam/service/2010-05-08/iam-2010-05-08.json (AttachRolePolicy and PutRolePolicy)
|
|
140
|
-
*/
|
|
141
|
-
const applyPolicies = Effect.fn("IamRole.applyPolicies")(function* (
|
|
142
|
-
RoleName: string,
|
|
143
|
-
desired: Pick<RoleRequest, "ManagedPolicyArns" | "Policies">,
|
|
144
|
-
previous: Pick<RoleRequest, "ManagedPolicyArns" | "Policies">,
|
|
145
|
-
) {
|
|
146
|
-
const wanted = desired.ManagedPolicyArns ?? [];
|
|
147
|
-
const saved = previous.ManagedPolicyArns ?? [];
|
|
148
|
-
|
|
149
|
-
yield* Effect.forEach(
|
|
150
|
-
Arr.difference(saved, wanted),
|
|
151
|
-
(PolicyArn) =>
|
|
152
|
-
iam
|
|
153
|
-
.detachRolePolicy({ RoleName, PolicyArn })
|
|
154
|
-
.pipe(Effect.catchTag("AwsServiceError", missingIsSuccess)),
|
|
155
|
-
{ discard: true },
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
yield* Effect.forEach(
|
|
159
|
-
Arr.difference(wanted, saved),
|
|
160
|
-
(PolicyArn) => iam.attachRolePolicy({ RoleName, PolicyArn }),
|
|
161
|
-
{ discard: true },
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
const inline = desired.Policies ?? [];
|
|
165
|
-
const priorInline = previous.Policies ?? [];
|
|
166
|
-
const wantedNames = Arr.map(inline, (policy) => policy.PolicyName);
|
|
167
|
-
|
|
168
|
-
const removed = Arr.filter(
|
|
169
|
-
priorInline,
|
|
170
|
-
({ PolicyName }) => !Arr.contains(wantedNames, PolicyName),
|
|
171
|
-
);
|
|
172
|
-
|
|
173
|
-
const changed = Arr.filter(
|
|
174
|
-
inline,
|
|
175
|
-
(policy) => !Arr.some(priorInline, (saved) => sameJson(saved, policy)),
|
|
176
|
-
);
|
|
177
|
-
|
|
178
|
-
yield* Effect.forEach(
|
|
179
|
-
changed,
|
|
180
|
-
({ PolicyName, PolicyDocument }) =>
|
|
181
|
-
encodeIamPolicy(PolicyDocument).pipe(
|
|
182
|
-
Effect.flatMap((document) =>
|
|
183
|
-
iam.putRolePolicy({
|
|
184
|
-
RoleName,
|
|
185
|
-
PolicyName,
|
|
186
|
-
PolicyDocument: document,
|
|
187
|
-
}),
|
|
188
|
-
),
|
|
189
|
-
),
|
|
190
|
-
{ discard: true },
|
|
191
|
-
);
|
|
192
|
-
|
|
193
|
-
yield* Effect.forEach(
|
|
194
|
-
removed,
|
|
195
|
-
({ PolicyName }) =>
|
|
196
|
-
iam
|
|
197
|
-
.deleteRolePolicy({ RoleName, PolicyName })
|
|
198
|
-
.pipe(Effect.catchTag("AwsServiceError", missingIsSuccess)),
|
|
199
|
-
{ discard: true },
|
|
200
|
-
);
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
const removeRole = Effect.fn("IamRole.removeRole")(function* (
|
|
204
|
-
RoleName: string,
|
|
205
|
-
assigned: Pick<RoleRequest, "ManagedPolicyArns" | "Policies">,
|
|
206
|
-
) {
|
|
207
|
-
yield* applyPolicies(RoleName, {}, assigned);
|
|
208
|
-
|
|
209
|
-
yield* iam
|
|
210
|
-
.deleteRole({ RoleName })
|
|
211
|
-
.pipe(Effect.catchTag("AwsServiceError", missingIsSuccess));
|
|
212
|
-
|
|
213
|
-
yield* readRole(RoleName).pipe(
|
|
214
|
-
Effect.repeat({
|
|
215
|
-
while: Option.isSome,
|
|
216
|
-
schedule: Schedule.spaced("1 second"),
|
|
217
|
-
}),
|
|
218
|
-
Effect.timeout("30 seconds"),
|
|
219
|
-
);
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
const create = Effect.fn("IamRole.create")(function* (node: ResourceNode) {
|
|
223
|
-
const desired = yield* model.decodeProps(node, AWSRoleRequestSchema);
|
|
224
|
-
const RoleName = yield* roleName(node, desired);
|
|
225
|
-
const AssumeRolePolicyDocument = yield* encodeIamPolicy(
|
|
226
|
-
desired.AssumeRolePolicyDocument,
|
|
227
|
-
);
|
|
228
|
-
|
|
229
|
-
const fields = Struct.pick(desired, [
|
|
230
|
-
"Description",
|
|
231
|
-
"MaxSessionDuration",
|
|
232
|
-
"Path",
|
|
233
|
-
"PermissionsBoundary",
|
|
234
|
-
"Tags",
|
|
235
|
-
]);
|
|
236
|
-
|
|
237
|
-
// Role creation retains the role after successful configuration and
|
|
238
|
-
// removes it after failure or interruption. Effect.acquireUseRelease
|
|
239
|
-
// protects acquisition and cleanup as documented in
|
|
240
|
-
// node_modules/effect/src/Effect.ts, "acquireUseRelease".
|
|
241
|
-
const applied = yield* Effect.acquireUseRelease(
|
|
242
|
-
iam.createRole({ ...fields, RoleName, AssumeRolePolicyDocument }),
|
|
243
|
-
Effect.fnUntraced(function* ({ Role }) {
|
|
244
|
-
yield* confirmRole(RoleName);
|
|
245
|
-
yield* applyPolicies(RoleName, desired, {});
|
|
246
|
-
|
|
247
|
-
return yield* model.withOutputs(node, Role);
|
|
248
|
-
}),
|
|
249
|
-
(_, exit) =>
|
|
250
|
-
Exit.match(exit, {
|
|
251
|
-
onSuccess: () => Effect.void,
|
|
252
|
-
onFailure: () => removeRole(RoleName, desired),
|
|
253
|
-
}),
|
|
254
|
-
);
|
|
255
|
-
|
|
256
|
-
return ResourceCommandResult.Created({ node: applied });
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* The checkRole operation verifies the immutable RoleId before changing
|
|
261
|
-
* an existing role. A new IAM role can have the same name as a deleted
|
|
262
|
-
* role and still belong to someone else.
|
|
263
|
-
*
|
|
264
|
-
* @see ../../../../../refs/aws-api-models/models/iam/service/2010-05-08/iam-2010-05-08.json (Role)
|
|
265
|
-
*/
|
|
266
|
-
const checkRole = Effect.fn("IamRole.checkRole")(function* (
|
|
267
|
-
node: ResourceNode,
|
|
268
|
-
) {
|
|
269
|
-
const saved = yield* model.decodeOutputs(node, Identity);
|
|
270
|
-
|
|
271
|
-
return yield* readRole(saved.RoleName).pipe(
|
|
272
|
-
Effect.filterOrFail(
|
|
273
|
-
(role) =>
|
|
274
|
-
!Option.exists(role, ({ RoleId }) => saved.RoleId !== RoleId),
|
|
275
|
-
() => new IamRoleIdentityChanged({ roleName: saved.RoleName }),
|
|
276
|
-
),
|
|
277
|
-
);
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
const update = Effect.fn("IamRole.update")(function* (
|
|
281
|
-
node: ResourceNode,
|
|
282
|
-
current: ResourceNode,
|
|
283
|
-
) {
|
|
284
|
-
const saved = yield* model.decodeOutputs(current, Identity);
|
|
285
|
-
const previous = yield* model.decodeProps(current, AWSRoleRequestSchema);
|
|
286
|
-
const desired = yield* model.decodeProps(node, AWSRoleRequestSchema);
|
|
287
|
-
|
|
288
|
-
yield* checkRole(current).pipe(Effect.flatMap(Effect.fromOption));
|
|
289
|
-
|
|
290
|
-
const { RoleName } = saved;
|
|
291
|
-
const Description = desired.Description ?? "";
|
|
292
|
-
const MaxSessionDuration = desired.MaxSessionDuration ?? 3600;
|
|
293
|
-
const configurationChanged =
|
|
294
|
-
desired.Description !== previous.Description ||
|
|
295
|
-
desired.MaxSessionDuration !== previous.MaxSessionDuration;
|
|
296
|
-
|
|
297
|
-
yield* iam
|
|
298
|
-
.updateRole({ RoleName, Description, MaxSessionDuration })
|
|
299
|
-
.pipe(Effect.when(Effect.succeed(configurationChanged)));
|
|
300
|
-
|
|
301
|
-
const trustChanged = !sameJson(
|
|
302
|
-
desired.AssumeRolePolicyDocument,
|
|
303
|
-
previous.AssumeRolePolicyDocument,
|
|
304
|
-
);
|
|
305
|
-
|
|
306
|
-
yield* encodeIamPolicy(desired.AssumeRolePolicyDocument).pipe(
|
|
307
|
-
Effect.flatMap((PolicyDocument) =>
|
|
308
|
-
iam.updateAssumeRolePolicy({ RoleName, PolicyDocument }),
|
|
309
|
-
),
|
|
310
|
-
Effect.when(Effect.succeed(trustChanged)),
|
|
311
|
-
);
|
|
312
|
-
|
|
313
|
-
const permissionsChanged =
|
|
314
|
-
desired.PermissionsBoundary !== previous.PermissionsBoundary;
|
|
315
|
-
|
|
316
|
-
yield* Option.match(Option.fromUndefinedOr(desired.PermissionsBoundary), {
|
|
317
|
-
onNone: () => iam.deleteRolePermissionsBoundary({ RoleName }),
|
|
318
|
-
onSome: (PermissionsBoundary) =>
|
|
319
|
-
iam.putRolePermissionsBoundary({ RoleName, PermissionsBoundary }),
|
|
320
|
-
}).pipe(Effect.when(Effect.succeed(permissionsChanged)));
|
|
321
|
-
|
|
322
|
-
const tags = desired.Tags ?? [];
|
|
323
|
-
const savedTags = previous.Tags ?? [];
|
|
324
|
-
|
|
325
|
-
const keys = Arr.map(tags, (tag) => tag.Key);
|
|
326
|
-
const TagKeys = Arr.difference(
|
|
327
|
-
Arr.map(savedTags, (tag) => tag.Key),
|
|
328
|
-
keys,
|
|
329
|
-
);
|
|
330
|
-
|
|
331
|
-
const Tags = Arr.filter(
|
|
332
|
-
tags,
|
|
333
|
-
({ Key, Value }) =>
|
|
334
|
-
!Arr.some(
|
|
335
|
-
savedTags,
|
|
336
|
-
(saved) => Key === saved.Key && Value === saved.Value,
|
|
337
|
-
),
|
|
338
|
-
);
|
|
339
|
-
|
|
340
|
-
yield* iam
|
|
341
|
-
.untagRole({ RoleName, TagKeys })
|
|
342
|
-
.pipe(
|
|
343
|
-
Effect.when(Effect.succeed(Arr.isReadonlyArrayNonEmpty(TagKeys))),
|
|
344
|
-
);
|
|
345
|
-
|
|
346
|
-
yield* iam
|
|
347
|
-
.tagRole({ RoleName, Tags })
|
|
348
|
-
.pipe(Effect.when(Effect.succeed(Arr.isReadonlyArrayNonEmpty(Tags))));
|
|
349
|
-
|
|
350
|
-
yield* applyPolicies(RoleName, desired, previous);
|
|
351
|
-
|
|
352
|
-
const observed = yield* confirmRole(RoleName);
|
|
353
|
-
|
|
354
|
-
const applied = yield* model.withObservedOutputs(
|
|
355
|
-
{ ...node, outputs: current.outputs },
|
|
356
|
-
observed,
|
|
357
|
-
);
|
|
358
|
-
|
|
359
|
-
return ResourceCommandResult.Updated({ node: applied });
|
|
360
|
-
});
|
|
361
|
-
|
|
362
|
-
const read = Effect.fn("IamRole.read")(function* (node: ResourceNode) {
|
|
363
|
-
const role = yield* checkRole(node);
|
|
364
|
-
|
|
365
|
-
const present = yield* pipe(
|
|
366
|
-
role,
|
|
367
|
-
Option.map((observed) =>
|
|
368
|
-
model
|
|
369
|
-
.withObservedOutputs(node, observed)
|
|
370
|
-
.pipe(
|
|
371
|
-
Effect.map((node) =>
|
|
372
|
-
ResourceObservation.Present({ node, observed }),
|
|
373
|
-
),
|
|
374
|
-
),
|
|
375
|
-
),
|
|
376
|
-
Effect.transposeOption,
|
|
377
|
-
);
|
|
378
|
-
|
|
379
|
-
const observation = Option.match(present, {
|
|
380
|
-
onNone: () => ResourceObservation.Missing({ node }),
|
|
381
|
-
onSome: (value) => value,
|
|
382
|
-
});
|
|
383
|
-
|
|
384
|
-
return ResourceCommandResult.Observed({ observation });
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
const destroy = Effect.fn("IamRole.destroy")(function* (
|
|
388
|
-
node: ResourceNode,
|
|
389
|
-
) {
|
|
390
|
-
const { RoleName } = yield* model.decodeOutputs(node, Identity);
|
|
391
|
-
const assigned = yield* model.decodeProps(node, AWSRoleRequestSchema);
|
|
392
|
-
const role = yield* checkRole(node);
|
|
393
|
-
|
|
394
|
-
yield* removeRole(RoleName, assigned).pipe(
|
|
395
|
-
Effect.when(Effect.succeed(Option.isSome(role))),
|
|
396
|
-
);
|
|
397
|
-
|
|
398
|
-
return ResourceCommandResult.Destroyed({ node });
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
const execute = Effect.fn("IamRole.execute")((command: ResourceCommand) => {
|
|
402
|
-
const action = Match.value(command).pipe(
|
|
403
|
-
Match.tag("Apply", ({ decision }) => decision),
|
|
404
|
-
Match.orElse((direct) => direct),
|
|
405
|
-
);
|
|
406
|
-
|
|
407
|
-
return Match.value(action).pipe(
|
|
408
|
-
Match.tag("Create", ({ node }) => create(node)),
|
|
409
|
-
Match.tag("Read", ({ node }) => read(node)),
|
|
410
|
-
Match.when(
|
|
411
|
-
{ _tag: "Update", current: Match.defined },
|
|
412
|
-
({ node, current }) => update(node, current),
|
|
413
|
-
),
|
|
414
|
-
Match.tag("Delete", "Destroy", ({ node }) => destroy(node)),
|
|
415
|
-
Match.orElse(() =>
|
|
416
|
-
Effect.fail(new ResourceCommandUnsupported({ command })),
|
|
417
|
-
),
|
|
418
|
-
Effect.mapError(
|
|
419
|
-
(cause) => new ResourceCommandExecutionFailed({ command, cause }),
|
|
420
|
-
),
|
|
421
|
-
);
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
return { execute };
|
|
425
|
-
}),
|
|
426
|
-
).pipe(Layer.provide(resourceModelLayer));
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
2
|
-
import type { ResourceKey } from "../../../../core/resource/model.js";
|
|
3
|
-
import { ResourceGraphBuilder } from "../../../../core/resource/resourceGraphBuilder.js";
|
|
4
|
-
import type { ResourceOutputBinding } from "../../../../core/resource/resourceOutputBinding.js";
|
|
5
|
-
import {
|
|
6
|
-
AWSRoleOutputsSchema,
|
|
7
|
-
type AWSRoleProps,
|
|
8
|
-
AWSRolePropsSchema,
|
|
9
|
-
AWSRoleRequestSchema,
|
|
10
|
-
AWSRoleResourceTypeSchema,
|
|
11
|
-
AWSRoleResource as GeneratedRole,
|
|
12
|
-
} from "../generated/native/iam/role/index.js";
|
|
13
|
-
import { type PolicyStatement, RoleGrant } from "./grant.js";
|
|
14
|
-
|
|
15
|
-
export * from "../generated/native/iam/role/index.js";
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* The AWSRoleResource class adds identity permissions to the generated IAM
|
|
19
|
-
* role declaration. Each named statement has its own lifecycle.
|
|
20
|
-
*/
|
|
21
|
-
export class AWSRoleResource<
|
|
22
|
-
Props = AWSRoleProps,
|
|
23
|
-
> extends GeneratedRole<Props> {
|
|
24
|
-
/**
|
|
25
|
-
* The addToPolicy method declares a named IAM statement on this role.
|
|
26
|
-
* Its grant can be used to order a workload that needs the permission.
|
|
27
|
-
*/
|
|
28
|
-
addToPolicy(name: string, statement: PolicyStatement) {
|
|
29
|
-
return Schema.decodeEffect(Schema.NonEmptyString)(name).pipe(
|
|
30
|
-
Effect.flatMap((name) =>
|
|
31
|
-
RoleGrant(`${this.key.logicalId}/${name}`, this, statement),
|
|
32
|
-
),
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* The grantPassRole method gives the grantee permission to pass this
|
|
38
|
-
* role to an AWS service. The grant resolves this role's ARN at apply
|
|
39
|
-
* time and removing the grant revokes the permission it owns.
|
|
40
|
-
*
|
|
41
|
-
* @see ../../../../../refs/aws-api-models/models/lambda/service/2015-03-31/lambda-2015-03-31.json (CreateFunction and CreateFunctionRequest.Role)
|
|
42
|
-
* @see ../../../../../docs/application/resource-graph.md (Relationships and request values)
|
|
43
|
-
*/
|
|
44
|
-
grantPassRole(grantee: AWSRoleResource) {
|
|
45
|
-
return grantee.addToPolicy(
|
|
46
|
-
`PassRole/${encodeURIComponent(this.key.logicalId)}`,
|
|
47
|
-
{ actions: ["iam:PassRole"], resources: [this] },
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* The grantAssumeRole method adds permission for the grantee to call
|
|
53
|
-
* STS AssumeRole for this role. Configure this role's trust policy to
|
|
54
|
-
* allow the grantee before it calls STS.
|
|
55
|
-
*
|
|
56
|
-
* @see ../../../../../refs/aws-api-models/models/sts/service/2011-06-15/sts-2011-06-15.json (AssumeRole)
|
|
57
|
-
*/
|
|
58
|
-
grantAssumeRole(grantee: AWSRoleResource) {
|
|
59
|
-
return grantee.addToPolicy(
|
|
60
|
-
`AssumeRole/${encodeURIComponent(this.key.logicalId)}`,
|
|
61
|
-
{ actions: ["sts:AssumeRole"], resources: [this] },
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* The createAWSRoleDeclaration function constructs the IAM role entity from
|
|
68
|
-
* validated properties. Pass the declaration's binding to expose applied
|
|
69
|
-
* provider outputs.
|
|
70
|
-
*/
|
|
71
|
-
export const createAWSRoleDeclaration = <Props>(
|
|
72
|
-
key: ResourceKey,
|
|
73
|
-
props: Props,
|
|
74
|
-
binding?: ResourceOutputBinding,
|
|
75
|
-
) => new AWSRoleResource(key, props, binding);
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* The AWSRole function registers a role through the generated Registry
|
|
79
|
-
* schemas and returns a role whose policy methods use the same stack graph.
|
|
80
|
-
*/
|
|
81
|
-
export const AWSRole = Effect.fn("AWSRole")(function* (input: {
|
|
82
|
-
readonly logicalId: string;
|
|
83
|
-
readonly props: AWSRoleProps;
|
|
84
|
-
}) {
|
|
85
|
-
const graph = yield* ResourceGraphBuilder;
|
|
86
|
-
|
|
87
|
-
const key = { logicalId: input.logicalId };
|
|
88
|
-
const props = yield* Schema.decodeEffect(AWSRolePropsSchema)(input.props);
|
|
89
|
-
|
|
90
|
-
const declaration = yield* graph.resource(key);
|
|
91
|
-
yield* declaration.registerEntity(AWSRoleResourceTypeSchema, {
|
|
92
|
-
propsSchema: AWSRolePropsSchema,
|
|
93
|
-
requestSchema: AWSRoleRequestSchema,
|
|
94
|
-
outputsSchema: AWSRoleOutputsSchema,
|
|
95
|
-
props,
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
const role: AWSRoleResource = createAWSRoleDeclaration(
|
|
99
|
-
key,
|
|
100
|
-
props,
|
|
101
|
-
declaration.outputs,
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
return role;
|
|
105
|
-
});
|