api_op_AssumeRoleWithSAML.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. // Code generated by smithy-go-codegen DO NOT EDIT.
  2. package sts
  3. import (
  4. "context"
  5. awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
  6. "github.com/aws/aws-sdk-go-v2/service/sts/types"
  7. "github.com/aws/smithy-go/middleware"
  8. smithyhttp "github.com/aws/smithy-go/transport/http"
  9. )
  10. // Returns a set of temporary security credentials for users who have been
  11. // authenticated via a SAML authentication response. This operation provides a
  12. // mechanism for tying an enterprise identity store or directory to role-based
  13. // Amazon Web Services access without user-specific credentials or configuration.
  14. // For a comparison of AssumeRoleWithSAML with the other API operations that
  15. // produce temporary credentials, see Requesting Temporary Security Credentials
  16. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_request.html)
  17. // and Comparing the Amazon Web Services STS API operations
  18. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_request.html#stsapi_comparison)
  19. // in the IAM User Guide. The temporary security credentials returned by this
  20. // operation consist of an access key ID, a secret access key, and a security
  21. // token. Applications can use these temporary security credentials to sign calls
  22. // to Amazon Web Services services. Session Duration By default, the temporary
  23. // security credentials created by AssumeRoleWithSAML last for one hour. However,
  24. // you can use the optional DurationSeconds parameter to specify the duration of
  25. // your session. Your role session lasts for the duration that you specify, or
  26. // until the time specified in the SAML authentication response's
  27. // SessionNotOnOrAfter value, whichever is shorter. You can provide a
  28. // DurationSeconds value from 900 seconds (15 minutes) up to the maximum session
  29. // duration setting for the role. This setting can have a value from 1 hour to 12
  30. // hours. To learn how to view the maximum value for your role, see View the
  31. // Maximum Session Duration Setting for a Role
  32. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use.html#id_roles_use_view-role-max-session)
  33. // in the IAM User Guide. The maximum session duration limit applies when you use
  34. // the AssumeRole* API operations or the assume-role* CLI commands. However the
  35. // limit does not apply when you use those operations to create a console URL. For
  36. // more information, see Using IAM Roles
  37. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use.html) in the IAM
  38. // User Guide. Role chaining
  39. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_terms-and-concepts.html#iam-term-role-chaining)
  40. // limits your CLI or Amazon Web Services API role session to a maximum of one
  41. // hour. When you use the AssumeRole API operation to assume a role, you can
  42. // specify the duration of your role session with the DurationSeconds parameter.
  43. // You can specify a parameter value of up to 43200 seconds (12 hours), depending
  44. // on the maximum session duration setting for your role. However, if you assume a
  45. // role using role chaining and provide a DurationSeconds parameter value greater
  46. // than one hour, the operation fails. Permissions The temporary security
  47. // credentials created by AssumeRoleWithSAML can be used to make API calls to any
  48. // Amazon Web Services service with the following exception: you cannot call the
  49. // STS GetFederationToken or GetSessionToken API operations. (Optional) You can
  50. // pass inline or managed session policies
  51. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session)
  52. // to this operation. You can pass a single JSON policy document to use as an
  53. // inline session policy. You can also specify up to 10 managed policy Amazon
  54. // Resource Names (ARNs) to use as managed session policies. The plaintext that you
  55. // use for both inline and managed session policies can't exceed 2,048 characters.
  56. // Passing policies to this operation returns new temporary credentials. The
  57. // resulting session's permissions are the intersection of the role's
  58. // identity-based policy and the session policies. You can use the role's temporary
  59. // credentials in subsequent Amazon Web Services API calls to access resources in
  60. // the account that owns the role. You cannot use session policies to grant more
  61. // permissions than those allowed by the identity-based policy of the role that is
  62. // being assumed. For more information, see Session Policies
  63. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session)
  64. // in the IAM User Guide. Calling AssumeRoleWithSAML does not require the use of
  65. // Amazon Web Services security credentials. The identity of the caller is
  66. // validated by using keys in the metadata document that is uploaded for the SAML
  67. // provider entity for your identity provider. Calling AssumeRoleWithSAML can
  68. // result in an entry in your CloudTrail logs. The entry includes the value in the
  69. // NameID element of the SAML assertion. We recommend that you use a NameIDType
  70. // that is not associated with any personally identifiable information (PII). For
  71. // example, you could instead use the persistent identifier
  72. // (urn:oasis:names:tc:SAML:2.0:nameid-format:persistent). Tags (Optional) You can
  73. // configure your IdP to pass attributes into your SAML assertion as session tags.
  74. // Each session tag consists of a key name and an associated value. For more
  75. // information about session tags, see Passing Session Tags in STS
  76. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html) in the
  77. // IAM User Guide. You can pass up to 50 session tags. The plaintext session tag
  78. // keys can’t exceed 128 characters and the values can’t exceed 256 characters. For
  79. // these and additional limits, see IAM and STS Character Limits
  80. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_iam-limits.html#reference_iam-limits-entity-length)
  81. // in the IAM User Guide. An Amazon Web Services conversion compresses the passed
  82. // inline session policy, managed policy ARNs, and session tags into a packed
  83. // binary format that has a separate limit. Your request can fail for this limit
  84. // even if your plaintext meets the other requirements. The PackedPolicySize
  85. // response element indicates by percentage how close the policies and tags for
  86. // your request are to the upper size limit. You can pass a session tag with the
  87. // same key as a tag that is attached to the role. When you do, session tags
  88. // override the role's tags with the same key. An administrator must grant you the
  89. // permissions necessary to pass session tags. The administrator can also create
  90. // granular permissions to allow you to pass only specific session tags. For more
  91. // information, see Tutorial: Using Tags for Attribute-Based Access Control
  92. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/tutorial_attribute-based-access-control.html)
  93. // in the IAM User Guide. You can set the session tags as transitive. Transitive
  94. // tags persist during role chaining. For more information, see Chaining Roles with
  95. // Session Tags
  96. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html#id_session-tags_role-chaining)
  97. // in the IAM User Guide. SAML Configuration Before your application can call
  98. // AssumeRoleWithSAML, you must configure your SAML identity provider (IdP) to
  99. // issue the claims required by Amazon Web Services. Additionally, you must use
  100. // Identity and Access Management (IAM) to create a SAML provider entity in your
  101. // Amazon Web Services account that represents your identity provider. You must
  102. // also create an IAM role that specifies this SAML provider in its trust policy.
  103. // For more information, see the following resources:
  104. //
  105. // * About SAML 2.0-based
  106. // Federation
  107. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_saml.html)
  108. // in the IAM User Guide.
  109. //
  110. // * Creating SAML Identity Providers
  111. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_create_saml.html)
  112. // in the IAM User Guide.
  113. //
  114. // * Configuring a Relying Party and Claims
  115. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_create_saml_relying-party.html)
  116. // in the IAM User Guide.
  117. //
  118. // * Creating a Role for SAML 2.0 Federation
  119. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-idp_saml.html)
  120. // in the IAM User Guide.
  121. func (c *Client) AssumeRoleWithSAML(ctx context.Context, params *AssumeRoleWithSAMLInput, optFns ...func(*Options)) (*AssumeRoleWithSAMLOutput, error) {
  122. if params == nil {
  123. params = &AssumeRoleWithSAMLInput{}
  124. }
  125. result, metadata, err := c.invokeOperation(ctx, "AssumeRoleWithSAML", params, optFns, c.addOperationAssumeRoleWithSAMLMiddlewares)
  126. if err != nil {
  127. return nil, err
  128. }
  129. out := result.(*AssumeRoleWithSAMLOutput)
  130. out.ResultMetadata = metadata
  131. return out, nil
  132. }
  133. type AssumeRoleWithSAMLInput struct {
  134. // The Amazon Resource Name (ARN) of the SAML provider in IAM that describes the
  135. // IdP.
  136. //
  137. // This member is required.
  138. PrincipalArn *string
  139. // The Amazon Resource Name (ARN) of the role that the caller is assuming.
  140. //
  141. // This member is required.
  142. RoleArn *string
  143. // The base64 encoded SAML authentication response provided by the IdP. For more
  144. // information, see Configuring a Relying Party and Adding Claims
  145. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/create-role-saml-IdP-tasks.html)
  146. // in the IAM User Guide.
  147. //
  148. // This member is required.
  149. SAMLAssertion *string
  150. // The duration, in seconds, of the role session. Your role session lasts for the
  151. // duration that you specify for the DurationSeconds parameter, or until the time
  152. // specified in the SAML authentication response's SessionNotOnOrAfter value,
  153. // whichever is shorter. You can provide a DurationSeconds value from 900 seconds
  154. // (15 minutes) up to the maximum session duration setting for the role. This
  155. // setting can have a value from 1 hour to 12 hours. If you specify a value higher
  156. // than this setting, the operation fails. For example, if you specify a session
  157. // duration of 12 hours, but your administrator set the maximum session duration to
  158. // 6 hours, your operation fails. To learn how to view the maximum value for your
  159. // role, see View the Maximum Session Duration Setting for a Role
  160. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use.html#id_roles_use_view-role-max-session)
  161. // in the IAM User Guide. By default, the value is set to 3600 seconds. The
  162. // DurationSeconds parameter is separate from the duration of a console session
  163. // that you might request using the returned credentials. The request to the
  164. // federation endpoint for a console sign-in token takes a SessionDuration
  165. // parameter that specifies the maximum length of the console session. For more
  166. // information, see Creating a URL that Enables Federated Users to Access the
  167. // Amazon Web Services Management Console
  168. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_enable-console-custom-url.html)
  169. // in the IAM User Guide.
  170. DurationSeconds *int32
  171. // An IAM policy in JSON format that you want to use as an inline session policy.
  172. // This parameter is optional. Passing policies to this operation returns new
  173. // temporary credentials. The resulting session's permissions are the intersection
  174. // of the role's identity-based policy and the session policies. You can use the
  175. // role's temporary credentials in subsequent Amazon Web Services API calls to
  176. // access resources in the account that owns the role. You cannot use session
  177. // policies to grant more permissions than those allowed by the identity-based
  178. // policy of the role that is being assumed. For more information, see Session
  179. // Policies
  180. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session)
  181. // in the IAM User Guide. The plaintext that you use for both inline and managed
  182. // session policies can't exceed 2,048 characters. The JSON policy characters can
  183. // be any ASCII character from the space character to the end of the valid
  184. // character list (\u0020 through \u00FF). It can also include the tab (\u0009),
  185. // linefeed (\u000A), and carriage return (\u000D) characters. An Amazon Web
  186. // Services conversion compresses the passed inline session policy, managed policy
  187. // ARNs, and session tags into a packed binary format that has a separate limit.
  188. // Your request can fail for this limit even if your plaintext meets the other
  189. // requirements. The PackedPolicySize response element indicates by percentage how
  190. // close the policies and tags for your request are to the upper size limit.
  191. Policy *string
  192. // The Amazon Resource Names (ARNs) of the IAM managed policies that you want to
  193. // use as managed session policies. The policies must exist in the same account as
  194. // the role. This parameter is optional. You can provide up to 10 managed policy
  195. // ARNs. However, the plaintext that you use for both inline and managed session
  196. // policies can't exceed 2,048 characters. For more information about ARNs, see
  197. // Amazon Resource Names (ARNs) and Amazon Web Services Service Namespaces
  198. // (https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html) in
  199. // the Amazon Web Services General Reference. An Amazon Web Services conversion
  200. // compresses the passed inline session policy, managed policy ARNs, and session
  201. // tags into a packed binary format that has a separate limit. Your request can
  202. // fail for this limit even if your plaintext meets the other requirements. The
  203. // PackedPolicySize response element indicates by percentage how close the policies
  204. // and tags for your request are to the upper size limit. Passing policies to this
  205. // operation returns new temporary credentials. The resulting session's permissions
  206. // are the intersection of the role's identity-based policy and the session
  207. // policies. You can use the role's temporary credentials in subsequent Amazon Web
  208. // Services API calls to access resources in the account that owns the role. You
  209. // cannot use session policies to grant more permissions than those allowed by the
  210. // identity-based policy of the role that is being assumed. For more information,
  211. // see Session Policies
  212. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session)
  213. // in the IAM User Guide.
  214. PolicyArns []types.PolicyDescriptorType
  215. noSmithyDocumentSerde
  216. }
  217. // Contains the response to a successful AssumeRoleWithSAML request, including
  218. // temporary Amazon Web Services credentials that can be used to make Amazon Web
  219. // Services requests.
  220. type AssumeRoleWithSAMLOutput struct {
  221. // The identifiers for the temporary security credentials that the operation
  222. // returns.
  223. AssumedRoleUser *types.AssumedRoleUser
  224. // The value of the Recipient attribute of the SubjectConfirmationData element of
  225. // the SAML assertion.
  226. Audience *string
  227. // The temporary security credentials, which include an access key ID, a secret
  228. // access key, and a security (or session) token. The size of the security token
  229. // that STS API operations return is not fixed. We strongly recommend that you make
  230. // no assumptions about the maximum size.
  231. Credentials *types.Credentials
  232. // The value of the Issuer element of the SAML assertion.
  233. Issuer *string
  234. // A hash value based on the concatenation of the following:
  235. //
  236. // * The Issuer response
  237. // value.
  238. //
  239. // * The Amazon Web Services account ID.
  240. //
  241. // * The friendly name (the last
  242. // part of the ARN) of the SAML provider in IAM.
  243. //
  244. // The combination of NameQualifier
  245. // and Subject can be used to uniquely identify a federated user. The following
  246. // pseudocode shows how the hash value is calculated: BASE64 ( SHA1 (
  247. // "https://example.com/saml" + "123456789012" + "/MySAMLIdP" ) )
  248. NameQualifier *string
  249. // A percentage value that indicates the packed size of the session policies and
  250. // session tags combined passed in the request. The request fails if the packed
  251. // size is greater than 100 percent, which means the policies and tags exceeded the
  252. // allowed space.
  253. PackedPolicySize *int32
  254. // The value in the SourceIdentity attribute in the SAML assertion. You can require
  255. // users to set a source identity value when they assume a role. You do this by
  256. // using the sts:SourceIdentity condition key in a role trust policy. That way,
  257. // actions that are taken with the role are associated with that user. After the
  258. // source identity is set, the value cannot be changed. It is present in the
  259. // request for all actions that are taken by the role and persists across chained
  260. // role
  261. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_terms-and-concepts#iam-term-role-chaining)
  262. // sessions. You can configure your SAML identity provider to use an attribute
  263. // associated with your users, like user name or email, as the source identity when
  264. // calling AssumeRoleWithSAML. You do this by adding an attribute to the SAML
  265. // assertion. For more information about using source identity, see Monitor and
  266. // control actions taken with assumed roles
  267. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_control-access_monitor.html)
  268. // in the IAM User Guide. The regex used to validate this parameter is a string of
  269. // characters consisting of upper- and lower-case alphanumeric characters with no
  270. // spaces. You can also include underscores or any of the following characters:
  271. // =,.@-
  272. SourceIdentity *string
  273. // The value of the NameID element in the Subject element of the SAML assertion.
  274. Subject *string
  275. // The format of the name ID, as defined by the Format attribute in the NameID
  276. // element of the SAML assertion. Typical examples of the format are transient or
  277. // persistent. If the format includes the prefix
  278. // urn:oasis:names:tc:SAML:2.0:nameid-format, that prefix is removed. For example,
  279. // urn:oasis:names:tc:SAML:2.0:nameid-format:transient is returned as transient. If
  280. // the format includes any other prefix, the format is returned with no
  281. // modifications.
  282. SubjectType *string
  283. // Metadata pertaining to the operation's result.
  284. ResultMetadata middleware.Metadata
  285. noSmithyDocumentSerde
  286. }
  287. func (c *Client) addOperationAssumeRoleWithSAMLMiddlewares(stack *middleware.Stack, options Options) (err error) {
  288. err = stack.Serialize.Add(&awsAwsquery_serializeOpAssumeRoleWithSAML{}, middleware.After)
  289. if err != nil {
  290. return err
  291. }
  292. err = stack.Deserialize.Add(&awsAwsquery_deserializeOpAssumeRoleWithSAML{}, middleware.After)
  293. if err != nil {
  294. return err
  295. }
  296. if err = addSetLoggerMiddleware(stack, options); err != nil {
  297. return err
  298. }
  299. if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
  300. return err
  301. }
  302. if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
  303. return err
  304. }
  305. if err = addResolveEndpointMiddleware(stack, options); err != nil {
  306. return err
  307. }
  308. if err = addRetryMiddlewares(stack, options); err != nil {
  309. return err
  310. }
  311. if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
  312. return err
  313. }
  314. if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
  315. return err
  316. }
  317. if err = addClientUserAgent(stack); err != nil {
  318. return err
  319. }
  320. if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
  321. return err
  322. }
  323. if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
  324. return err
  325. }
  326. if err = addOpAssumeRoleWithSAMLValidationMiddleware(stack); err != nil {
  327. return err
  328. }
  329. if err = stack.Initialize.Add(newServiceMetadataMiddleware_opAssumeRoleWithSAML(options.Region), middleware.Before); err != nil {
  330. return err
  331. }
  332. if err = addRequestIDRetrieverMiddleware(stack); err != nil {
  333. return err
  334. }
  335. if err = addResponseErrorMiddleware(stack); err != nil {
  336. return err
  337. }
  338. if err = addRequestResponseLogging(stack, options); err != nil {
  339. return err
  340. }
  341. return nil
  342. }
  343. func newServiceMetadataMiddleware_opAssumeRoleWithSAML(region string) *awsmiddleware.RegisterServiceMetadata {
  344. return &awsmiddleware.RegisterServiceMetadata{
  345. Region: region,
  346. ServiceID: ServiceID,
  347. SigningName: "sts",
  348. OperationName: "AssumeRoleWithSAML",
  349. }
  350. }