UNPKG

13.3 kBTypeScriptView Raw
1import { IConstruct } from '@aws-cdk/core';
2import { IPrincipal, ServicePrincipalOpts } from './principals';
3/**
4 * Represents a statement in an IAM policy document.
5 */
6export declare class PolicyStatement {
7 /**
8 * Creates a new PolicyStatement based on the object provided.
9 * This will accept an object created from the `.toJSON()` call
10 * @param obj the PolicyStatement in object form.
11 */
12 static fromJson(obj: any): PolicyStatement;
13 /**
14 * Statement ID for this statement
15 */
16 sid?: string;
17 /**
18 * Whether to allow or deny the actions in this statement
19 */
20 effect: Effect;
21 private readonly _action;
22 private readonly _notAction;
23 private readonly _principal;
24 private readonly _notPrincipal;
25 private readonly _resource;
26 private readonly _notResource;
27 private readonly _condition;
28 private principalConditionsJson?;
29 private readonly _principals;
30 private readonly _notPrincipals;
31 constructor(props?: PolicyStatementProps);
32 /**
33 * Specify allowed actions into the "Action" section of the policy statement.
34 *
35 * @see https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_action.html
36 *
37 * @param actions actions that will be allowed.
38 */
39 addActions(...actions: string[]): void;
40 /**
41 * Explicitly allow all actions except the specified list of actions into the "NotAction" section
42 * of the policy document.
43 *
44 * @see https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_notaction.html
45 *
46 * @param notActions actions that will be denied. All other actions will be permitted.
47 */
48 addNotActions(...notActions: string[]): void;
49 /**
50 * Indicates if this permission has a "Principal" section.
51 */
52 get hasPrincipal(): boolean;
53 /**
54 * Adds principals to the "Principal" section of a policy statement.
55 *
56 * @see https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_principal.html
57 *
58 * @param principals IAM principals that will be added
59 */
60 addPrincipals(...principals: IPrincipal[]): void;
61 /**
62 * Specify principals that is not allowed or denied access to the "NotPrincipal" section of
63 * a policy statement.
64 *
65 * @see https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_notprincipal.html
66 *
67 * @param notPrincipals IAM principals that will be denied access
68 */
69 addNotPrincipals(...notPrincipals: IPrincipal[]): void;
70 private validatePolicyPrincipal;
71 /**
72 * Specify AWS account ID as the principal entity to the "Principal" section of a policy statement.
73 */
74 addAwsAccountPrincipal(accountId: string): void;
75 /**
76 * Specify a principal using the ARN identifier of the principal.
77 * You cannot specify IAM groups and instance profiles as principals.
78 *
79 * @param arn ARN identifier of AWS account, IAM user, or IAM role (i.e. arn:aws:iam::123456789012:user/user-name)
80 */
81 addArnPrincipal(arn: string): void;
82 /**
83 * Adds a service principal to this policy statement.
84 *
85 * @param service the service name for which a service principal is requested (e.g: `s3.amazonaws.com`).
86 * @param opts options for adding the service principal (such as specifying a principal in a different region)
87 */
88 addServicePrincipal(service: string, opts?: ServicePrincipalOpts): void;
89 /**
90 * Adds a federated identity provider such as Amazon Cognito to this policy statement.
91 *
92 * @param federated federated identity provider (i.e. 'cognito-identity.amazonaws.com')
93 * @param conditions The conditions under which the policy is in effect.
94 * See [the IAM documentation](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition.html).
95 */
96 addFederatedPrincipal(federated: any, conditions: Conditions): void;
97 /**
98 * Adds an AWS account root user principal to this policy statement
99 */
100 addAccountRootPrincipal(): void;
101 /**
102 * Adds a canonical user ID principal to this policy document
103 *
104 * @param canonicalUserId unique identifier assigned by AWS for every account
105 */
106 addCanonicalUserPrincipal(canonicalUserId: string): void;
107 /**
108 * Adds all identities in all accounts ("*") to this policy statement
109 */
110 addAnyPrincipal(): void;
111 /**
112 * Specify resources that this policy statement applies into the "Resource" section of
113 * this policy statement.
114 *
115 * @see https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_resource.html
116 *
117 * @param arns Amazon Resource Names (ARNs) of the resources that this policy statement applies to
118 */
119 addResources(...arns: string[]): void;
120 /**
121 * Specify resources that this policy statement will not apply to in the "NotResource" section
122 * of this policy statement. All resources except the specified list will be matched.
123 *
124 * @see https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_notresource.html
125 *
126 * @param arns Amazon Resource Names (ARNs) of the resources that this policy statement does not apply to
127 */
128 addNotResources(...arns: string[]): void;
129 /**
130 * Adds a ``"*"`` resource to this statement.
131 */
132 addAllResources(): void;
133 /**
134 * Indicates if this permission has at least one resource associated with it.
135 */
136 get hasResource(): boolean;
137 /**
138 * Add a condition to the Policy
139 *
140 * If multiple calls are made to add a condition with the same operator and field, only
141 * the last one wins. For example:
142 *
143 * ```ts
144 * declare const stmt: iam.PolicyStatement;
145 *
146 * stmt.addCondition('StringEquals', { 'aws:SomeField': '1' });
147 * stmt.addCondition('StringEquals', { 'aws:SomeField': '2' });
148 * ```
149 *
150 * Will end up with the single condition `StringEquals: { 'aws:SomeField': '2' }`.
151 *
152 * If you meant to add a condition to say that the field can be *either* `1` or `2`, write
153 * this:
154 *
155 * ```ts
156 * declare const stmt: iam.PolicyStatement;
157 *
158 * stmt.addCondition('StringEquals', { 'aws:SomeField': ['1', '2'] });
159 * ```
160 */
161 addCondition(key: string, value: Condition): void;
162 /**
163 * Add multiple conditions to the Policy
164 *
165 * See the `addCondition` function for a caveat on calling this method multiple times.
166 */
167 addConditions(conditions: Conditions): void;
168 /**
169 * Add a condition that limits to a given account
170 *
171 * This method can only be called once: subsequent calls will overwrite earlier calls.
172 */
173 addAccountCondition(accountId: string): void;
174 /**
175 * Create a new `PolicyStatement` with the same exact properties
176 * as this one, except for the overrides
177 */
178 copy(overrides?: PolicyStatementProps): PolicyStatement;
179 /**
180 * JSON-ify the policy statement
181 *
182 * Used when JSON.stringify() is called
183 */
184 toStatementJson(): any;
185 /**
186 * String representation of this policy statement
187 */
188 toString(): string;
189 /**
190 * JSON-ify the statement
191 *
192 * Used when JSON.stringify() is called
193 */
194 toJSON(): any;
195 /**
196 * Add a principal's conditions
197 *
198 * For convenience, principals have been modeled as both a principal
199 * and a set of conditions. This makes it possible to have a single
200 * object represent e.g. an "SNS Topic" (SNS service principal + aws:SourcArn
201 * condition) or an Organization member (* + aws:OrgId condition).
202 *
203 * However, when using multiple principals in the same policy statement,
204 * they must all have the same conditions or the OR samentics
205 * implied by a list of principals cannot be guaranteed (user needs to
206 * add multiple statements in that case).
207 */
208 private addPrincipalConditions;
209 /**
210 * Validate that the policy statement satisfies base requirements for a policy.
211 *
212 * @returns An array of validation error messages, or an empty array if the statement is valid.
213 */
214 validateForAnyPolicy(): string[];
215 /**
216 * Validate that the policy statement satisfies all requirements for a resource-based policy.
217 *
218 * @returns An array of validation error messages, or an empty array if the statement is valid.
219 */
220 validateForResourcePolicy(): string[];
221 /**
222 * Validate that the policy statement satisfies all requirements for an identity-based policy.
223 *
224 * @returns An array of validation error messages, or an empty array if the statement is valid.
225 */
226 validateForIdentityPolicy(): string[];
227 /**
228 * The Actions added to this statement
229 */
230 get actions(): string[];
231 /**
232 * The NotActions added to this statement
233 */
234 get notActions(): string[];
235 /**
236 * The Principals added to this statement
237 */
238 get principals(): IPrincipal[];
239 /**
240 * The NotPrincipals added to this statement
241 */
242 get notPrincipals(): IPrincipal[];
243 /**
244 * The Resources added to this statement
245 */
246 get resources(): string[];
247 /**
248 * The NotResources added to this statement
249 */
250 get notResources(): string[];
251 /**
252 * The conditions added to this statement
253 */
254 get conditions(): any;
255 /**
256 * Estimate the size of this policy statement
257 *
258 * By necessity, this will not be accurate. We'll do our best to overestimate
259 * so we won't have nasty surprises.
260 *
261 * @internal
262 */
263 _estimateSize(options: EstimateSizeOptions): number;
264}
265/**
266 * The Effect element of an IAM policy
267 *
268 * @see https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_effect.html
269 */
270export declare enum Effect {
271 /**
272 * Allows access to a resource in an IAM policy statement. By default, access to resources are denied.
273 */
274 ALLOW = "Allow",
275 /**
276 * Explicitly deny access to a resource. By default, all requests are denied implicitly.
277 *
278 * @see https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_evaluation-logic.html
279 */
280 DENY = "Deny"
281}
282/**
283 * Condition for when an IAM policy is in effect. Maps from the keys in a request's context to
284 * a string value or array of string values. See the Conditions interface for more details.
285 */
286export declare type Condition = any;
287/**
288 * Conditions for when an IAM Policy is in effect, specified in the following structure:
289 *
290 * `{ "Operator": { "keyInRequestContext": "value" } }`
291 *
292 * The value can be either a single string value or an array of string values.
293 *
294 * For more information, including which operators are supported, see [the IAM
295 * documentation](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition.html).
296 */
297export declare type Conditions = Record<string, Condition>;
298/**
299 * Interface for creating a policy statement
300 */
301export interface PolicyStatementProps {
302 /**
303 * The Sid (statement ID) is an optional identifier that you provide for the
304 * policy statement. You can assign a Sid value to each statement in a
305 * statement array. In services that let you specify an ID element, such as
306 * SQS and SNS, the Sid value is just a sub-ID of the policy document's ID. In
307 * IAM, the Sid value must be unique within a JSON policy.
308 *
309 * @default - no sid
310 */
311 readonly sid?: string;
312 /**
313 * List of actions to add to the statement
314 *
315 * @default - no actions
316 */
317 readonly actions?: string[];
318 /**
319 * List of not actions to add to the statement
320 *
321 * @default - no not-actions
322 */
323 readonly notActions?: string[];
324 /**
325 * List of principals to add to the statement
326 *
327 * @default - no principals
328 */
329 readonly principals?: IPrincipal[];
330 /**
331 * List of not principals to add to the statement
332 *
333 * @default - no not principals
334 */
335 readonly notPrincipals?: IPrincipal[];
336 /**
337 * Resource ARNs to add to the statement
338 *
339 * @default - no resources
340 */
341 readonly resources?: string[];
342 /**
343 * NotResource ARNs to add to the statement
344 *
345 * @default - no not-resources
346 */
347 readonly notResources?: string[];
348 /**
349 * Conditions to add to the statement
350 *
351 * @default - no condition
352 */
353 readonly conditions?: {
354 [key: string]: any;
355 };
356 /**
357 * Whether to allow or deny the actions in this statement
358 *
359 * @default Effect.ALLOW
360 */
361 readonly effect?: Effect;
362}
363/**
364 * Options for _estimateSize
365 *
366 * These can optionally come from context, but it's too expensive to look
367 * them up every time so we bundle them into a struct first.
368 *
369 * @internal
370 */
371export interface EstimateSizeOptions {
372 /**
373 * Estimated size of an unresolved ARN
374 */
375 readonly arnEstimate: number;
376 /**
377 * Estimated size of an unresolved action
378 */
379 readonly actionEstimate: number;
380}
381/**
382 * Derive the size estimation options from context
383 *
384 * @internal
385 */
386export declare function deriveEstimateSizeOptions(scope: IConstruct): EstimateSizeOptions;
387
\No newline at end of file