api_op_AssumeRole.go (26226B)
1 // Code generated by smithy-go-codegen DO NOT EDIT. 2 3 package sts 4 5 import ( 6 "context" 7 8 v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" 9 "github.com/aws/aws-sdk-go-v2/service/sts/types" 10 "github.com/aws/smithy-go/middleware" 11 ) 12 13 // Returns a set of temporary security credentials that you can use to access 14 // Amazon Web Services resources. These temporary credentials consist of an access 15 // key ID, a secret access key, and a security token. Typically, you use AssumeRole 16 // within your account or for cross-account access. For a comparison of AssumeRole 17 // with other API operations that produce temporary credentials, see [Requesting Temporary Security Credentials]and [Compare STS credentials] in the 18 // IAM User Guide. 19 // 20 // # Permissions 21 // 22 // The temporary security credentials created by AssumeRole can be used to make 23 // API calls to any Amazon Web Services service with the following exception: You 24 // cannot call the Amazon Web Services STS GetFederationToken or GetSessionToken 25 // API operations. 26 // 27 // (Optional) You can pass inline or managed session policies to this operation. 28 // You can pass a single JSON policy document to use as an inline session policy. 29 // You can also specify up to 10 managed policy Amazon Resource Names (ARNs) to use 30 // as managed session policies. The plaintext that you use for both inline and 31 // managed session policies can't exceed 2,048 characters. Passing policies to this 32 // operation returns new temporary credentials. The resulting session's permissions 33 // are the intersection of the role's identity-based policy and the session 34 // policies. You can use the role's temporary credentials in subsequent Amazon Web 35 // Services API calls to access resources in the account that owns the role. You 36 // cannot use session policies to grant more permissions than those allowed by the 37 // identity-based policy of the role that is being assumed. For more information, 38 // see [Session Policies]in the IAM User Guide. 39 // 40 // When you create a role, you create two policies: a role trust policy that 41 // specifies who can assume the role, and a permissions policy that specifies what 42 // can be done with the role. You specify the trusted principal that is allowed to 43 // assume the role in the role trust policy. 44 // 45 // To assume a role from a different account, your Amazon Web Services account 46 // must be trusted by the role. The trust relationship is defined in the role's 47 // trust policy when the role is created. That trust policy states which accounts 48 // are allowed to delegate that access to users in the account. 49 // 50 // A user who wants to access a role in a different account must also have 51 // permissions that are delegated from the account administrator. The administrator 52 // must attach a policy that allows the user to call AssumeRole for the ARN of the 53 // role in the other account. 54 // 55 // To allow a user to assume a role in the same account, you can do either of the 56 // following: 57 // 58 // - Attach a policy to the user that allows the user to call AssumeRole (as long 59 // as the role's trust policy trusts the account). 60 // 61 // - Add the user as a principal directly in the role's trust policy. 62 // 63 // You can do either because the role’s trust policy acts as an IAM resource-based 64 // policy. When a resource-based policy grants access to a principal in the same 65 // account, no additional identity-based policy is required. For more information 66 // about trust policies and resource-based policies, see [IAM Policies]in the IAM User Guide. 67 // 68 // # Tags 69 // 70 // (Optional) You can pass tag key-value pairs to your session. These tags are 71 // called session tags. For more information about session tags, see [Passing Session Tags in STS]in the IAM 72 // User Guide. 73 // 74 // An administrator must grant you the permissions necessary to pass session tags. 75 // The administrator can also create granular permissions to allow you to pass only 76 // specific session tags. For more information, see [Tutorial: Using Tags for Attribute-Based Access Control]in the IAM User Guide. 77 // 78 // You can set the session tags as transitive. Transitive tags persist during role 79 // chaining. For more information, see [Chaining Roles with Session Tags]in the IAM User Guide. 80 // 81 // # Using MFA with AssumeRole 82 // 83 // (Optional) You can include multi-factor authentication (MFA) information when 84 // you call AssumeRole . This is useful for cross-account scenarios to ensure that 85 // the user that assumes the role has been authenticated with an Amazon Web 86 // Services MFA device. In that scenario, the trust policy of the role being 87 // assumed includes a condition that tests for MFA authentication. If the caller 88 // does not include valid MFA information, the request to assume the role is 89 // denied. The condition in a trust policy that tests for MFA authentication might 90 // look like the following example. 91 // 92 // "Condition": {"Bool": {"aws:MultiFactorAuthPresent": true}} 93 // 94 // For more information, see [Configuring MFA-Protected API Access] in the IAM User Guide guide. 95 // 96 // To use MFA with AssumeRole , you pass values for the SerialNumber and TokenCode 97 // parameters. The SerialNumber value identifies the user's hardware or virtual 98 // MFA device. The TokenCode is the time-based one-time password (TOTP) that the 99 // MFA device produces. 100 // 101 // [Configuring MFA-Protected API Access]: https://docs.aws.amazon.com/IAM/latest/UserGuide/MFAProtectedAPI.html 102 // [Session Policies]: https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session 103 // [Passing Session Tags in STS]: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html 104 // [Chaining Roles with Session Tags]: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html#id_session-tags_role-chaining 105 // [IAM Policies]: https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html 106 // [Requesting Temporary Security Credentials]: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_request.html 107 // [Compare STS credentials]: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_sts-comparison.html 108 // [Tutorial: Using Tags for Attribute-Based Access Control]: https://docs.aws.amazon.com/IAM/latest/UserGuide/tutorial_attribute-based-access-control.html 109 func (c *Client) AssumeRole(ctx context.Context, params *AssumeRoleInput, optFns ...func(*Options)) (*AssumeRoleOutput, error) { 110 if params == nil { 111 params = &AssumeRoleInput{} 112 } 113 114 result, metadata, err := c.invokeOperation(ctx, "AssumeRole", params, optFns, c.addOperationAssumeRoleMiddlewares) 115 if err != nil { 116 return nil, err 117 } 118 119 out := result.(*AssumeRoleOutput) 120 out.ResultMetadata = metadata 121 return out, nil 122 } 123 124 type AssumeRoleInput struct { 125 126 // The Amazon Resource Name (ARN) of the role to assume. 127 // 128 // This member is required. 129 RoleArn *string 130 131 // An identifier for the assumed role session. 132 // 133 // Use the role session name to uniquely identify a session when the same role is 134 // assumed by different principals or for different reasons. In cross-account 135 // scenarios, the role session name is visible to, and can be logged by the account 136 // that owns the role. The role session name is also used in the ARN of the assumed 137 // role principal. This means that subsequent cross-account API requests that use 138 // the temporary security credentials will expose the role session name to the 139 // external account in their CloudTrail logs. 140 // 141 // For security purposes, administrators can view this field in [CloudTrail logs] to help identify 142 // who performed an action in Amazon Web Services. Your administrator might require 143 // that you specify your user name as the session name when you assume the role. 144 // For more information, see [sts:RoleSessionName]sts:RoleSessionName . 145 // 146 // The regex used to validate this parameter is a string of characters consisting 147 // of upper- and lower-case alphanumeric characters with no spaces. You can also 148 // include underscores or any of the following characters: +=,.@- 149 // 150 // [CloudTrail logs]: https://docs.aws.amazon.com/IAM/latest/UserGuide/cloudtrail-integration.html#cloudtrail-integration_signin-tempcreds 151 // [sts:RoleSessionName]: https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_iam-condition-keys.html#ck_rolesessionname 152 // 153 // This member is required. 154 RoleSessionName *string 155 156 // The duration, in seconds, of the role session. The value specified can range 157 // from 900 seconds (15 minutes) up to the maximum session duration set for the 158 // role. The maximum session duration setting can have a value from 1 hour to 12 159 // hours. If you specify a value higher than this setting or the administrator 160 // setting (whichever is lower), the operation fails. For example, if you specify a 161 // session duration of 12 hours, but your administrator set the maximum session 162 // duration to 6 hours, your operation fails. 163 // 164 // Role chaining limits your Amazon Web Services CLI or Amazon Web Services API 165 // role session to a maximum of one hour. When you use the AssumeRole API 166 // operation to assume a role, you can specify the duration of your role session 167 // with the DurationSeconds parameter. You can specify a parameter value of up to 168 // 43200 seconds (12 hours), depending on the maximum session duration setting for 169 // your role. However, if you assume a role using role chaining and provide a 170 // DurationSeconds parameter value greater than one hour, the operation fails. To 171 // learn how to view the maximum value for your role, see [Update the maximum session duration for a role]. 172 // 173 // By default, the value is set to 3600 seconds. 174 // 175 // The DurationSeconds parameter is separate from the duration of a console 176 // session that you might request using the returned credentials. The request to 177 // the federation endpoint for a console sign-in token takes a SessionDuration 178 // parameter that specifies the maximum length of the console session. For more 179 // information, see [Creating a URL that Enables Federated Users to Access the Amazon Web Services Management Console]in the IAM User Guide. 180 // 181 // [Update the maximum session duration for a role]: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_update-role-settings.html#id_roles_update-session-duration 182 // [Creating a URL that Enables Federated Users to Access the Amazon Web Services Management Console]: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_enable-console-custom-url.html 183 DurationSeconds *int32 184 185 // A unique identifier that might be required when you assume a role in another 186 // account. If the administrator of the account to which the role belongs provided 187 // you with an external ID, then provide that value in the ExternalId parameter. 188 // This value can be any string, such as a passphrase or account number. A 189 // cross-account role is usually set up to trust everyone in an account. Therefore, 190 // the administrator of the trusting account might send an external ID to the 191 // administrator of the trusted account. That way, only someone with the ID can 192 // assume the role, rather than everyone in the account. For more information about 193 // the external ID, see [How to Use an External ID When Granting Access to Your Amazon Web Services Resources to a Third Party]in the IAM User Guide. 194 // 195 // The regex used to validate this parameter is a string of characters consisting 196 // of upper- and lower-case alphanumeric characters with no spaces. You can also 197 // include underscores or any of the following characters: +=,.@:\/- 198 // 199 // [How to Use an External ID When Granting Access to Your Amazon Web Services Resources to a Third Party]: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-user_externalid.html 200 ExternalId *string 201 202 // An IAM policy in JSON format that you want to use as an inline session policy. 203 // 204 // This parameter is optional. Passing policies to this operation returns new 205 // temporary credentials. The resulting session's permissions are the intersection 206 // of the role's identity-based policy and the session policies. You can use the 207 // role's temporary credentials in subsequent Amazon Web Services API calls to 208 // access resources in the account that owns the role. You cannot use session 209 // policies to grant more permissions than those allowed by the identity-based 210 // policy of the role that is being assumed. For more information, see [Session Policies]in the IAM 211 // User Guide. 212 // 213 // The plaintext that you use for both inline and managed session policies can't 214 // exceed 2,048 characters. The JSON policy characters can be any ASCII character 215 // from the space character to the end of the valid character list (\u0020 through 216 // \u00FF). It can also include the tab (\u0009), linefeed (\u000A), and carriage 217 // return (\u000D) characters. 218 // 219 // An Amazon Web Services conversion compresses the passed inline session policy, 220 // managed policy ARNs, and session tags into a packed binary format that has a 221 // separate limit. Your request can fail for this limit even if your plaintext 222 // meets the other requirements. The PackedPolicySize response element indicates 223 // by percentage how close the policies and tags for your request are to the upper 224 // size limit. 225 // 226 // For more information about role session permissions, see [Session policies]. 227 // 228 // [Session Policies]: https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session 229 // [Session policies]: https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session 230 Policy *string 231 232 // The Amazon Resource Names (ARNs) of the IAM managed policies that you want to 233 // use as managed session policies. The policies must exist in the same account as 234 // the role. 235 // 236 // This parameter is optional. You can provide up to 10 managed policy ARNs. 237 // However, the plaintext that you use for both inline and managed session policies 238 // can't exceed 2,048 characters. For more information about ARNs, see [Amazon Resource Names (ARNs) and Amazon Web Services Service Namespaces]in the 239 // Amazon Web Services General Reference. 240 // 241 // An Amazon Web Services conversion compresses the passed inline session policy, 242 // managed policy ARNs, and session tags into a packed binary format that has a 243 // separate limit. Your request can fail for this limit even if your plaintext 244 // meets the other requirements. The PackedPolicySize response element indicates 245 // by percentage how close the policies and tags for your request are to the upper 246 // size limit. 247 // 248 // Passing policies to this operation returns new temporary credentials. The 249 // resulting session's permissions are the intersection of the role's 250 // identity-based policy and the session policies. You can use the role's temporary 251 // credentials in subsequent Amazon Web Services API calls to access resources in 252 // the account that owns the role. You cannot use session policies to grant more 253 // permissions than those allowed by the identity-based policy of the role that is 254 // being assumed. For more information, see [Session Policies]in the IAM User Guide. 255 // 256 // [Session Policies]: https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session 257 // [Amazon Resource Names (ARNs) and Amazon Web Services Service Namespaces]: https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html 258 PolicyArns []types.PolicyDescriptorType 259 260 // A list of previously acquired trusted context assertions in the format of a 261 // JSON array. The trusted context assertion is signed and encrypted by Amazon Web 262 // Services STS. 263 // 264 // The following is an example of a ProvidedContext value that includes a single 265 // trusted context assertion and the ARN of the context provider from which the 266 // trusted context assertion was generated. 267 // 268 // [{"ProviderArn":"arn:aws:iam::aws:contextProvider/IdentityCenter","ContextAssertion":"trusted-context-assertion"}] 269 ProvidedContexts []types.ProvidedContext 270 271 // The identification number of the MFA device that is associated with the user 272 // who is making the AssumeRole call. Specify this value if the trust policy of 273 // the role being assumed includes a condition that requires MFA authentication. 274 // The value is either the serial number for a hardware device (such as 275 // GAHT12345678 ) or an Amazon Resource Name (ARN) for a virtual device (such as 276 // arn:aws:iam::123456789012:mfa/user ). 277 // 278 // The regex used to validate this parameter is a string of characters consisting 279 // of upper- and lower-case alphanumeric characters with no spaces. You can also 280 // include underscores or any of the following characters: +=/:,.@- 281 SerialNumber *string 282 283 // The source identity specified by the principal that is calling the AssumeRole 284 // operation. The source identity value persists across [chained role]sessions. 285 // 286 // You can require users to specify a source identity when they assume a role. You 287 // do this by using the [sts:SourceIdentity]sts:SourceIdentity condition key in a role trust policy. 288 // You can use source identity information in CloudTrail logs to determine who took 289 // actions with a role. You can use the aws:SourceIdentity condition key to 290 // further control access to Amazon Web Services resources based on the value of 291 // source identity. For more information about using source identity, see [Monitor and control actions taken with assumed roles]in the 292 // IAM User Guide. 293 // 294 // The regex used to validate this parameter is a string of characters consisting 295 // of upper- and lower-case alphanumeric characters with no spaces. You can also 296 // include underscores or any of the following characters: +=,.@-. You cannot use a 297 // value that begins with the text aws: . This prefix is reserved for Amazon Web 298 // Services internal use. 299 // 300 // [chained role]: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html#iam-term-role-chaining 301 // [Monitor and control actions taken with assumed roles]: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_control-access_monitor.html 302 // [sts:SourceIdentity]: https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-sourceidentity 303 SourceIdentity *string 304 305 // A list of session tags that you want to pass. Each session tag consists of a 306 // key name and an associated value. For more information about session tags, see [Tagging Amazon Web Services STS Sessions] 307 // in the IAM User Guide. 308 // 309 // This parameter is optional. You can pass up to 50 session tags. The plaintext 310 // session tag keys can’t exceed 128 characters, and the values can’t exceed 256 311 // characters. For these and additional limits, see [IAM and STS Character Limits]in the IAM User Guide. 312 // 313 // An Amazon Web Services conversion compresses the passed inline session policy, 314 // managed policy ARNs, and session tags into a packed binary format that has a 315 // separate limit. Your request can fail for this limit even if your plaintext 316 // meets the other requirements. The PackedPolicySize response element indicates 317 // by percentage how close the policies and tags for your request are to the upper 318 // size limit. 319 // 320 // You can pass a session tag with the same key as a tag that is already attached 321 // to the role. When you do, session tags override a role tag with the same key. 322 // 323 // Tag key–value pairs are not case sensitive, but case is preserved. This means 324 // that you cannot have separate Department and department tag keys. Assume that 325 // the role has the Department = Marketing tag and you pass the department = 326 // engineering session tag. Department and department are not saved as separate 327 // tags, and the session tag passed in the request takes precedence over the role 328 // tag. 329 // 330 // Additionally, if you used temporary credentials to perform this operation, the 331 // new session inherits any transitive session tags from the calling session. If 332 // you pass a session tag with the same key as an inherited tag, the operation 333 // fails. To view the inherited tags for a session, see the CloudTrail logs. For 334 // more information, see [Viewing Session Tags in CloudTrail]in the IAM User Guide. 335 // 336 // [Tagging Amazon Web Services STS Sessions]: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html 337 // [IAM and STS Character Limits]: https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_iam-limits.html#reference_iam-limits-entity-length 338 // [Viewing Session Tags in CloudTrail]: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html#id_session-tags_ctlogs 339 Tags []types.Tag 340 341 // The value provided by the MFA device, if the trust policy of the role being 342 // assumed requires MFA. (In other words, if the policy includes a condition that 343 // tests for MFA). If the role being assumed requires MFA and if the TokenCode 344 // value is missing or expired, the AssumeRole call returns an "access denied" 345 // error. 346 // 347 // The format for this parameter, as described by its regex pattern, is a sequence 348 // of six numeric digits. 349 TokenCode *string 350 351 // A list of keys for session tags that you want to set as transitive. If you set 352 // a tag key as transitive, the corresponding key and value passes to subsequent 353 // sessions in a role chain. For more information, see [Chaining Roles with Session Tags]in the IAM User Guide. 354 // 355 // This parameter is optional. The transitive status of a session tag does not 356 // impact its packed binary size. 357 // 358 // If you choose not to specify a transitive tag key, then no tags are passed from 359 // this session to any subsequent sessions. 360 // 361 // [Chaining Roles with Session Tags]: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html#id_session-tags_role-chaining 362 TransitiveTagKeys []string 363 364 noSmithyDocumentSerde 365 } 366 367 // Contains the response to a successful AssumeRole request, including temporary Amazon Web 368 // Services credentials that can be used to make Amazon Web Services requests. 369 type AssumeRoleOutput struct { 370 371 // The Amazon Resource Name (ARN) and the assumed role ID, which are identifiers 372 // that you can use to refer to the resulting temporary security credentials. For 373 // example, you can reference these credentials as a principal in a resource-based 374 // policy by using the ARN or assumed role ID. The ARN and ID include the 375 // RoleSessionName that you specified when you called AssumeRole . 376 AssumedRoleUser *types.AssumedRoleUser 377 378 // The temporary security credentials, which include an access key ID, a secret 379 // access key, and a security (or session) token. 380 // 381 // The size of the security token that STS API operations return is not fixed. We 382 // strongly recommend that you make no assumptions about the maximum size. 383 Credentials *types.Credentials 384 385 // A percentage value that indicates the packed size of the session policies and 386 // session tags combined passed in the request. The request fails if the packed 387 // size is greater than 100 percent, which means the policies and tags exceeded the 388 // allowed space. 389 PackedPolicySize *int32 390 391 // The source identity specified by the principal that is calling the AssumeRole 392 // operation. 393 // 394 // You can require users to specify a source identity when they assume a role. You 395 // do this by using the sts:SourceIdentity condition key in a role trust policy. 396 // You can use source identity information in CloudTrail logs to determine who took 397 // actions with a role. You can use the aws:SourceIdentity condition key to 398 // further control access to Amazon Web Services resources based on the value of 399 // source identity. For more information about using source identity, see [Monitor and control actions taken with assumed roles]in the 400 // IAM User Guide. 401 // 402 // The regex used to validate this parameter is a string of characters consisting 403 // of upper- and lower-case alphanumeric characters with no spaces. You can also 404 // include underscores or any of the following characters: =,.@- 405 // 406 // [Monitor and control actions taken with assumed roles]: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_control-access_monitor.html 407 SourceIdentity *string 408 409 // Metadata pertaining to the operation's result. 410 ResultMetadata middleware.Metadata 411 412 noSmithyDocumentSerde 413 } 414 415 func (c *Client) addOperationAssumeRoleMiddlewares(stack *middleware.Stack, options Options) (err error) { 416 err = stack.Serialize.Add(&awsAwsquery_serializeOpAssumeRole{}, middleware.After) 417 if err != nil { 418 return err 419 } 420 err = stack.Deserialize.Add(&awsAwsquery_deserializeOpAssumeRole{}, middleware.After) 421 if err != nil { 422 return err 423 } 424 425 if err = addComputeContentLength(stack); err != nil { 426 return err 427 } 428 if err = addResolveEndpointMiddleware(stack, options); err != nil { 429 return err 430 } 431 if err = addComputePayloadSHA256(stack); err != nil { 432 return err 433 } 434 if err = addRecordResponseTiming(stack, options); err != nil { 435 return err 436 } 437 if err = addCredentialSource(stack, options); err != nil { 438 return err 439 } 440 if err = addOpAssumeRoleValidationMiddleware(stack); err != nil { 441 return err 442 } 443 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 444 return err 445 } 446 if err = addResponseErrorMiddleware(stack); err != nil { 447 return err 448 } 449 if err = addRequestResponseLogging(stack, options); err != nil { 450 return err 451 } 452 if err = addDisableHTTPSMiddleware(stack, options); err != nil { 453 return err 454 } 455 if err = addInterceptors(stack, options); err != nil { 456 return err 457 } 458 return nil 459 } 460 461 // PresignAssumeRole is used to generate a presigned HTTP Request which contains 462 // presigned URL, signed headers and HTTP method used. 463 func (c *PresignClient) PresignAssumeRole(ctx context.Context, params *AssumeRoleInput, optFns ...func(*PresignOptions)) (*v4.PresignedHTTPRequest, error) { 464 if params == nil { 465 params = &AssumeRoleInput{} 466 } 467 options := c.options.copy() 468 for _, fn := range optFns { 469 fn(&options) 470 } 471 clientOptFns := append(options.ClientOptions, withNopHTTPClientAPIOption) 472 473 result, _, err := c.client.invokeOperation(ctx, "AssumeRole", params, clientOptFns, 474 c.client.addOperationAssumeRoleMiddlewares, 475 presignConverter(options).convertToPresignMiddleware, 476 ) 477 if err != nil { 478 return nil, err 479 } 480 481 out := result.(*v4.PresignedHTTPRequest) 482 return out, nil 483 }