aws_iam/model/
types.rs

1/*!
2Provides the structures and enumerations that define the IAM Rust model.
3
4# Mapping from AWS Names
5
6A JSON policy document includes these elements:
7
8* Optional policy-wide information at the top of the document
9* One or more individual statements
10
11Each statement includes information about a single permission. If a policy includes multiple
12statements, AWS applies a logical OR across the statements when evaluating them. If multiple
13policies apply to a request, AWS applies a logical OR across all of those policies when
14evaluating them. The information in a statement is contained within a series of elements.
15
16* **Version** – Specify the version of the policy language that you want to use. As a best
17  practice, use the latest 2012-10-17 version.
18* **Statement** – Use this main policy element as a container for the following elements. You
19  can include more than one statement in a policy.
20* **Sid** (Optional) – Include an optional statement ID to differentiate between your statements.
21* **Effect** – Use Allow or Deny to indicate whether the policy allows or denies access.
22* **Principal** (Required in only some circumstances) – If you create a resource-based policy,
23  you must indicate the account, user, role, or federated user to which you would like to allow
24  or deny access. If you are creating an IAM permissions policy to attach to a user or role, you
25  cannot include this element. The principal is implied as that user or role.
26* **Action** – Include a list of actions that the policy allows or denies.
27* **Resource** (Required in only some circumstances) – If you create an IAM permissions policy,
28  you must specify a list of resources to which the actions apply. If you create a resource-based
29  policy, this element is optional. If you do not include this element, then the resource to which
30  the action applies is the resource to which the policy is attached.
31* **Condition** (Optional) – Specify the circumstances under which the policy grants permission.
32
33From [Overview of JSON Policies](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#access_policies-json).
34*/
35
36use crate::model::containers::*;
37use crate::model::qstring::QString;
38use serde::{Deserialize, Serialize};
39use std::collections::HashMap;
40
41// ------------------------------------------------------------------------------------------------
42// Public Types
43// ------------------------------------------------------------------------------------------------
44
45///
46/// An IAM policy resource.
47///
48#[derive(Debug, Serialize, Deserialize)]
49#[serde(rename_all = "PascalCase")]
50pub struct Policy {
51    #[serde(skip_serializing_if = "Option::is_none")]
52    /// The IAM version of the policy grammar used in this resource
53    pub version: Option<Version>,
54    #[serde(skip_serializing_if = "Option::is_none")]
55    /// The identifier of this policy, if any
56    pub id: Option<String>,
57    /// One or more policy statements
58    pub statement: OneOrAll<Statement>,
59}
60
61///
62/// The Version policy element is used within a policy and defines the version of
63/// the policy language.
64///
65/// If you do not include a Version element, the value defaults to 2008-10-17,
66/// but newer features, such as policy variables, will not work with your policy.
67/// For example, variables such as ${aws:username} aren't recognized as variables
68/// and are instead treated as literal strings in the policy.
69///
70/// From [IAM JSON Policy Elements: Version](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_version.html).
71///
72#[derive(Debug, Clone, Serialize, Deserialize)]
73pub enum Version {
74    #[serde(rename = "2012-10-17")]
75    /// This is the current version of the policy language, and you should always
76    /// include a Version element and set it to 2012-10-17. Otherwise, you cannot
77    /// use features such as policy variables that were introduced with this version.
78    V2012,
79
80    #[serde(rename = "2008-10-17")]
81    /// This was an earlier version of the policy language. You might see this
82    /// version on older existing policies. Do not use this version for any new
83    /// policies or when you update any existing policies.
84    V2008,
85}
86
87///
88/// The Statement element is the main element for a policy. This element is required. It can
89/// include multiple elements (see the subsequent sections in this page). The Statement element
90/// contains an array of individual statements. Each individual statement is a JSON block
91/// enclosed in braces `{ }`.
92///
93/// From [IAM JSON Policy Elements: Statement](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_statement.html).
94///
95#[derive(Debug, Clone, Serialize, Deserialize)]
96#[serde(rename_all = "PascalCase")]
97pub struct Statement {
98    ///
99    /// The Sid (statement ID) is an optional identifier that you provide for the policy statement.
100    /// You can assign a Sid value to each statement in a statement array. In services that let
101    /// you specify an ID element, such as SQS and SNS, the Sid value is just a sub-ID of the
102    /// policy document's ID. In IAM, the Sid value must be unique within a JSON policy
103    ///
104    /// In IAM, the Sid is not exposed in the IAM API. You can't retrieve a particular statement
105    /// based on this ID.
106    ///
107    /// From [IAM JSON Policy Elements: Sid](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_sid.html).
108    ///
109    #[serde(skip_serializing_if = "Option::is_none")]
110    pub sid: Option<String>,
111    ///
112    /// The principals, or not-principals to match as part of this statement.
113    ///
114    #[serde(skip_serializing_if = "Option::is_none")]
115    #[serde(flatten)]
116    pub principal: Option<Principal>,
117    ///
118    /// The effect, outcome, if this statement is matched.
119    ///
120    pub effect: Effect,
121    ///
122    /// The actions, or not-actions to match as part of this statement.
123    ///
124    #[serde(flatten)]
125    pub action: Action,
126    ///
127    /// The resources, or not-resources to match as part of this statement.
128    ///
129    #[serde(flatten)]
130    pub resource: Resource,
131    ///
132    /// Any condition(s) attached to this statement.
133    ///
134    #[serde(skip_serializing_if = "Option::is_none")]
135    pub condition: Option<HashMap<ConditionOperator, HashMap<QString, OneOrAll<ConditionValue>>>>,
136}
137
138///
139/// The Effect element is required and specifies whether the statement results in an allow or an
140/// explicit deny. Valid values for Effect are Allow and Deny.
141///
142/// From [IAM JSON Policy Elements: Effect](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_effect.html).
143///
144#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
145pub enum Effect {
146    /// The result of successful evaluation of this policy is to allow access.
147    Allow,
148    /// The result of successful evaluation of this policy is to deny access.
149    Deny,
150}
151
152///
153/// The Action element describes the specific action or actions that will be allowed or denied.
154/// Statements must include either an Action or NotAction element. Each AWS service has its own
155/// set of actions that describe tasks that you can perform with that service.
156///
157/// You specify a value using a service namespace as an action prefix (`iam`, `ec2`, `sqs`,
158/// `sns`, `s3`, etc.) followed by the name of the action to allow or deny. The name must match
159/// an action that is supported by the service. The prefix and the action name are case
160/// insensitive. For example, `iam:ListAccessKeys` is the same as `IAM:listaccesskeys`.
161///
162/// From [IAM JSON Policy Elements: Action](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_action.html)
163/// and [IAM JSON Policy Elements: NotAction](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_notaction.html).
164///
165#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
166pub enum Action {
167    /// Asserts that the action in the request **must** match one of the specified ones.
168    Action(OneOrAny<QString>),
169    /// Asserts that the action in the request **must not** match one of the specified ones.
170    NotAction(OneOrAny<QString>),
171}
172
173///
174/// Use the Principal element to specify the IAM user, federated user, IAM role, AWS account,
175/// AWS service, or other principal entity that is allowed or denied access to a resource. You
176/// cannot use the Principal element in an IAM identity-based policy. You can use it in the
177/// trust policies for IAM roles and in resource-based policies. Resource-based policies are
178/// policies that you embed directly in an IAM resource.
179///
180/// From [AWS JSON Policy Elements: Principal](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_principal.html)
181/// and [AWS JSON Policy Elements: NotPrincipal](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_notprincipal.html).
182///
183#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
184pub enum Principal {
185    /// Asserts that the principal in the request **must** match one of the specified ones.
186    Principal(HashMap<PrincipalType, OneOrAny>),
187    /// Asserts that the principal in the request **must not** match one of the specified ones.
188    NotPrincipal(HashMap<PrincipalType, OneOrAny>),
189}
190
191///
192/// This describes the way in which the condition ARNs should be understood.
193///
194#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
195pub enum PrincipalType {
196    /// Anyone, everyone, or anonymous users.
197    #[serde(rename = "*")]
198    Everyone,
199    /// When you use an AWS account identifier as the principal in a policy, you delegate
200    /// authority to the account. Within that account, the permissions in the policy statement
201    /// can be granted to all identities. This includes IAM users and roles in that account.
202    /// When you specify an AWS account, you can use the account ARN
203    /// (`arn:aws:iam::AWS-account-ID:root`), or a shortened form that consists of the `AWS:`
204    /// prefix followed by the account ID.
205    AWS,
206    /// Federated users either using web identity federation or using a SAML identity provider.
207    Federated,
208    /// IAM roles that can be assumed by an AWS service are called service roles. Service roles
209    /// must include a trust policy. Trust policies are resource-based policies that are attached
210    /// to a role that define which principals can assume the role. Some service roles have
211    /// predefined trust policies. However, in some cases, you must specify the service principal
212    /// in the trust policy. A service principal is an identifier that is used to grant
213    /// permissions to a service.
214    Service,
215    /// The canonical user ID is an identifier for your account. Because this identifier is
216    /// used by Amazon S3, only this service provides IAM users with access to the canonical
217    /// user ID. You can also view the canonical user ID for your account from the AWS
218    /// Management Console while signed in as the AWS account root user.
219    CanonicalUser,
220}
221
222///
223/// The Resource element specifies the object or objects that the statement covers. Statements
224/// must include either a Resource or a NotResource element. You specify a resource using an ARN.
225///
226/// From [IAM JSON Policy Elements: Resource](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_resource.html)
227/// and [IAM JSON Policy Elements: NotResource](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_notresource.html).
228///
229#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
230pub enum Resource {
231    /// Asserts that the resource in the request **must** match one of the specified ones.
232    Resource(OneOrAny),
233    /// Asserts that the resource in the request **must not** match one of the specified ones.
234    NotResource(OneOrAny),
235}
236
237///
238/// You can use the Condition element of a policy to test multiple keys or multiple
239/// values for a single key in a request. You can use condition keys to test the
240/// values of the matching keys in the request. For example, you can use a condition
241/// key to control access to specific attributes of a DynamoDB table or to an Amazon
242/// EC2 instance based on tags.
243///
244/// From [Creating a Condition with Multiple Keys or Values](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_multi-value-conditions.html).
245///
246#[derive(Debug, Clone, PartialEq, Eq, Hash)]
247pub enum ConditionOperatorQuantifier {
248    /// The condition **must** hold true for **all** values provided.
249    ForAllValues,
250    /// The condition **must** hold true for **at least** one value provided.
251    ForAnyValue,
252}
253
254///
255/// Pulls apart the string form of an operator used by IAM. It identifies the
256/// quantifiers which are used as string prefixes and recognizes the _if exist_
257/// suffix as well.
258///
259#[derive(Debug, Clone, PartialEq, Eq, Hash)]
260pub struct ConditionOperator {
261    /// Used to test multiple keys or multiple values for a single key in a request.
262    pub quantifier: Option<ConditionOperatorQuantifier>,
263    /// The condition operator you choose to use.
264    pub operator: GlobalConditionOperator,
265    /// You use this to say "If the policy key is present in the context of the
266    /// request, process the key as specified in the policy. If the key is not
267    /// present, evaluate the condition element as true." Other condition elements
268    /// in the statement can still result in a nonmatch, but not a missing key
269    /// when checked with ...`IfExists`.
270    pub if_exists: bool,
271}
272
273///
274/// Use condition operators in the `Condition` element to match the condition
275/// key and value in the policy against values in the request context.
276///
277/// The condition operator that you can use in a policy depends on the condition
278/// key you choose. You can choose a global condition key or a service-specific
279/// condition key.
280///
281/// From [IAM JSON Policy Elements: Condition Operators](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition_operators.html).
282///
283#[derive(Debug, Clone, PartialEq, Eq, Hash)]
284pub enum GlobalConditionOperator {
285    // ----- String Condition Operators
286    /// Exact matching, case sensitive
287    StringEquals,
288    /// Negated matching
289    StringNotEquals,
290    /// Exact matching, ignoring case
291    StringEqualsIgnoreCase,
292    /// Negated matching, ignoring case
293    StringNotEqualsIgnoreCase,
294    /// Case-sensitive matching. The values can include a multi-character
295    /// match wildcard (*) or a single-character match wildcard (?) anywhere
296    /// in the string.
297    StringLike,
298    /// Negated case-sensitive matching. The values can include a multi-character
299    /// match wildcard (*) or a single-character match wildcard (?) anywhere
300    /// in the string.
301    StringNotLike,
302    // ----- Numeric Condition Operators
303    /// Matching
304    NumericEquals,
305    /// Negated matching
306    NumericNotEquals,
307    /// "Less than" matching
308    NumericLessThan,
309    /// "Less than or equals" matching
310    NumericLessThanEquals,
311    /// "Greater than" matching
312    NumericGreaterThan,
313    /// "Greater than or equals" matching
314    NumericGreaterThanEquals,
315    // ----- Date Condition Operators
316    /// Matching a specific date
317    DateEquals,
318    /// Negated matching
319    DateNotEquals,
320    /// Matching before a specific date and time
321    DateLessThan,
322    /// Matching at or before a specific date and time
323    DateLessThanEquals,
324    /// Matching after a specific a date and time
325    DateGreaterThan,
326    /// Matching at or after a specific date and time
327    DateGreaterThanEquals,
328    // ----- Boolean Condition Operators
329    /// Boolean matching
330    Bool,
331    // ----- Binary Condition Operators
332    /// The BinaryEquals condition operator let you construct Condition
333    /// elements that test key values that are in binary format. It compares
334    /// the value of the specified key byte for byte against a base-64
335    /// encoded representation of the binary value in the policy.
336    BinaryEquals,
337    // ----- IP Address Condition Operators
338    /// The specified IP address or range
339    IpAddress,
340    /// ll IP addresses except the specified IP address or range
341    NotIpAddress,
342    // ----- ARN Condition Operators
343    /// Case-sensitive matching of the ARN. Each of the six colon-delimited
344    /// components of the ARN is checked separately and each can include a
345    /// multi-character match wildcard (*) or a single-character match
346    /// wildcard (?).
347    ArnEquals,
348    /// Case-sensitive matching of the ARN. Each of the six colon-delimited
349    /// components of the ARN is checked separately and each can include a
350    /// multi-character match wildcard (*) or a single-character match
351    /// wildcard (?).
352    ArnLike,
353    /// Negated matching for ARN.
354    ArnNotEquals,
355    /// Negated matching for ARN.
356    ArnNotLike,
357    // ------ Check Existence of Condition Keys
358    /// Use a Null condition operator to check if a condition key is
359    /// present at the time of authorization. In the policy statement, use
360    /// either true (the key doesn't exist — it is null) or false (the key
361    /// exists and its value is not null).
362    Null,
363    // ----- Custom Condition Operator
364    /// The name of a custom condition
365    Other(QString),
366}
367
368///
369/// The value to test an operator against.
370///
371#[derive(Debug, Clone, Serialize, Deserialize)]
372#[serde(untagged)]
373pub enum ConditionValue {
374    /// A String (or QString) value.
375    String(String),
376    /// A signed 64-bit integer value.
377    Integer(i64),
378    /// A 64-bit float value.
379    Float(f64),
380    /// A boolean value.
381    Bool(bool),
382}