src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

api_op_GetFederationToken.go (18365B)


      1 // Code generated by smithy-go-codegen DO NOT EDIT.
      2 
      3 package sts
      4 
      5 import (
      6 	"context"
      7 	"fmt"
      8 	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
      9 	"github.com/aws/aws-sdk-go-v2/service/sts/types"
     10 	"github.com/aws/smithy-go/middleware"
     11 	smithyhttp "github.com/aws/smithy-go/transport/http"
     12 )
     13 
     14 // Returns a set of temporary security credentials (consisting of an access key
     15 // ID, a secret access key, and a security token) for a user. A typical use is in a
     16 // proxy application that gets temporary security credentials on behalf of
     17 // distributed applications inside a corporate network. You must call the
     18 // GetFederationToken operation using the long-term security credentials of an IAM
     19 // user. As a result, this call is appropriate in contexts where those credentials
     20 // can be safeguarded, usually in a server-based application. For a comparison of
     21 // GetFederationToken with the other API operations that produce temporary
     22 // credentials, see Requesting Temporary Security Credentials (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_request.html)
     23 // and Comparing the Amazon Web Services STS API operations (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_request.html#stsapi_comparison)
     24 // in the IAM User Guide. Although it is possible to call GetFederationToken using
     25 // the security credentials of an Amazon Web Services account root user rather than
     26 // an IAM user that you create for the purpose of a proxy application, we do not
     27 // recommend it. For more information, see Safeguard your root user credentials
     28 // and don't use them for everyday tasks (https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#lock-away-credentials)
     29 // in the IAM User Guide. You can create a mobile-based or browser-based app that
     30 // can authenticate users using a web identity provider like Login with Amazon,
     31 // Facebook, Google, or an OpenID Connect-compatible identity provider. In this
     32 // case, we recommend that you use Amazon Cognito (http://aws.amazon.com/cognito/)
     33 // or AssumeRoleWithWebIdentity . For more information, see Federation Through a
     34 // Web-based Identity Provider (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_request.html#api_assumerolewithwebidentity)
     35 // in the IAM User Guide. Session duration The temporary credentials are valid for
     36 // the specified duration, from 900 seconds (15 minutes) up to a maximum of 129,600
     37 // seconds (36 hours). The default session duration is 43,200 seconds (12 hours).
     38 // Temporary credentials obtained by using the root user credentials have a maximum
     39 // duration of 3,600 seconds (1 hour). Permissions You can use the temporary
     40 // credentials created by GetFederationToken in any Amazon Web Services service
     41 // with the following exceptions:
     42 //   - You cannot call any IAM operations using the CLI or the Amazon Web Services
     43 //     API. This limitation does not apply to console sessions.
     44 //   - You cannot call any STS operations except GetCallerIdentity .
     45 //
     46 // You can use temporary credentials for single sign-on (SSO) to the console. You
     47 // must pass an inline or managed session policy (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session)
     48 // to this operation. You can pass a single JSON policy document to use as an
     49 // inline session policy. You can also specify up to 10 managed policy Amazon
     50 // Resource Names (ARNs) to use as managed session policies. The plaintext that you
     51 // use for both inline and managed session policies can't exceed 2,048 characters.
     52 // Though the session policy parameters are optional, if you do not pass a policy,
     53 // then the resulting federated user session has no permissions. When you pass
     54 // session policies, the session permissions are the intersection of the IAM user
     55 // policies and the session policies that you pass. This gives you a way to further
     56 // restrict the permissions for a federated user. You cannot use session policies
     57 // to grant more permissions than those that are defined in the permissions policy
     58 // of the IAM user. For more information, see Session Policies (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session)
     59 // in the IAM User Guide. For information about using GetFederationToken to create
     60 // temporary security credentials, see GetFederationToken—Federation Through a
     61 // Custom Identity Broker (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_request.html#api_getfederationtoken)
     62 // . You can use the credentials to access a resource that has a resource-based
     63 // policy. If that policy specifically references the federated user session in the
     64 // Principal element of the policy, the session has the permissions allowed by the
     65 // policy. These permissions are granted in addition to the permissions granted by
     66 // the session policies. Tags (Optional) You can pass tag key-value pairs to your
     67 // session. These are called session tags. For more information about session tags,
     68 // see Passing Session Tags in STS (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html)
     69 // in the IAM User Guide. You can create a mobile-based or browser-based app that
     70 // can authenticate users using a web identity provider like Login with Amazon,
     71 // Facebook, Google, or an OpenID Connect-compatible identity provider. In this
     72 // case, we recommend that you use Amazon Cognito (http://aws.amazon.com/cognito/)
     73 // or AssumeRoleWithWebIdentity . For more information, see Federation Through a
     74 // Web-based Identity Provider (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_request.html#api_assumerolewithwebidentity)
     75 // in the IAM User Guide. An administrator must grant you the permissions necessary
     76 // to pass session tags. The administrator can also create granular permissions to
     77 // allow you to pass only specific session tags. For more information, see
     78 // Tutorial: Using Tags for Attribute-Based Access Control (https://docs.aws.amazon.com/IAM/latest/UserGuide/tutorial_attribute-based-access-control.html)
     79 // in the IAM User Guide. Tag key–value pairs are not case sensitive, but case is
     80 // preserved. This means that you cannot have separate Department and department
     81 // tag keys. Assume that the user that you are federating has the Department =
     82 // Marketing tag and you pass the department = engineering session tag. Department
     83 // and department are not saved as separate tags, and the session tag passed in
     84 // the request takes precedence over the user tag.
     85 func (c *Client) GetFederationToken(ctx context.Context, params *GetFederationTokenInput, optFns ...func(*Options)) (*GetFederationTokenOutput, error) {
     86 	if params == nil {
     87 		params = &GetFederationTokenInput{}
     88 	}
     89 
     90 	result, metadata, err := c.invokeOperation(ctx, "GetFederationToken", params, optFns, c.addOperationGetFederationTokenMiddlewares)
     91 	if err != nil {
     92 		return nil, err
     93 	}
     94 
     95 	out := result.(*GetFederationTokenOutput)
     96 	out.ResultMetadata = metadata
     97 	return out, nil
     98 }
     99 
    100 type GetFederationTokenInput struct {
    101 
    102 	// The name of the federated user. The name is used as an identifier for the
    103 	// temporary security credentials (such as Bob ). For example, you can reference
    104 	// the federated user name in a resource-based policy, such as in an Amazon S3
    105 	// bucket policy. The regex used to validate this parameter is a string of
    106 	// characters consisting of upper- and lower-case alphanumeric characters with no
    107 	// spaces. You can also include underscores or any of the following characters:
    108 	// =,.@-
    109 	//
    110 	// This member is required.
    111 	Name *string
    112 
    113 	// The duration, in seconds, that the session should last. Acceptable durations
    114 	// for federation sessions range from 900 seconds (15 minutes) to 129,600 seconds
    115 	// (36 hours), with 43,200 seconds (12 hours) as the default. Sessions obtained
    116 	// using root user credentials are restricted to a maximum of 3,600 seconds (one
    117 	// hour). If the specified duration is longer than one hour, the session obtained
    118 	// by using root user credentials defaults to one hour.
    119 	DurationSeconds *int32
    120 
    121 	// An IAM policy in JSON format that you want to use as an inline session policy.
    122 	// You must pass an inline or managed session policy (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session)
    123 	// to this operation. You can pass a single JSON policy document to use as an
    124 	// inline session policy. You can also specify up to 10 managed policy Amazon
    125 	// Resource Names (ARNs) to use as managed session policies. This parameter is
    126 	// optional. However, if you do not pass any session policies, then the resulting
    127 	// federated user session has no permissions. When you pass session policies, the
    128 	// session permissions are the intersection of the IAM user policies and the
    129 	// session policies that you pass. This gives you a way to further restrict the
    130 	// permissions for a federated user. You cannot use session policies to grant more
    131 	// permissions than those that are defined in the permissions policy of the IAM
    132 	// user. For more information, see Session Policies (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session)
    133 	// in the IAM User Guide. The resulting credentials can be used to access a
    134 	// resource that has a resource-based policy. If that policy specifically
    135 	// references the federated user session in the Principal element of the policy,
    136 	// the session has the permissions allowed by the policy. These permissions are
    137 	// granted in addition to the permissions that are granted by the session policies.
    138 	// The plaintext that you use for both inline and managed session policies can't
    139 	// exceed 2,048 characters. The JSON policy characters can be any ASCII character
    140 	// from the space character to the end of the valid character list (\u0020 through
    141 	// \u00FF). It can also include the tab (\u0009), linefeed (\u000A), and carriage
    142 	// return (\u000D) characters. An Amazon Web Services conversion compresses the
    143 	// passed inline session policy, managed policy ARNs, and session tags into a
    144 	// packed binary format that has a separate limit. Your request can fail for this
    145 	// limit even if your plaintext meets the other requirements. The PackedPolicySize
    146 	// response element indicates by percentage how close the policies and tags for
    147 	// your request are to the upper size limit.
    148 	Policy *string
    149 
    150 	// The Amazon Resource Names (ARNs) of the IAM managed policies that you want to
    151 	// use as a managed session policy. The policies must exist in the same account as
    152 	// the IAM user that is requesting federated access. You must pass an inline or
    153 	// managed session policy (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session)
    154 	// to this operation. You can pass a single JSON policy document to use as an
    155 	// inline session policy. You can also specify up to 10 managed policy Amazon
    156 	// Resource Names (ARNs) to use as managed session policies. The plaintext that you
    157 	// use for both inline and managed session policies can't exceed 2,048 characters.
    158 	// You can provide up to 10 managed policy ARNs. For more information about ARNs,
    159 	// see Amazon Resource Names (ARNs) and Amazon Web Services Service Namespaces (https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html)
    160 	// in the Amazon Web Services General Reference. This parameter is optional.
    161 	// However, if you do not pass any session policies, then the resulting federated
    162 	// user session has no permissions. When you pass session policies, the session
    163 	// permissions are the intersection of the IAM user policies and the session
    164 	// policies that you pass. This gives you a way to further restrict the permissions
    165 	// for a federated user. You cannot use session policies to grant more permissions
    166 	// than those that are defined in the permissions policy of the IAM user. For more
    167 	// information, see Session Policies (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session)
    168 	// in the IAM User Guide. The resulting credentials can be used to access a
    169 	// resource that has a resource-based policy. If that policy specifically
    170 	// references the federated user session in the Principal element of the policy,
    171 	// the session has the permissions allowed by the policy. These permissions are
    172 	// granted in addition to the permissions that are granted by the session policies.
    173 	// An Amazon Web Services conversion compresses the passed inline session policy,
    174 	// managed policy ARNs, and session tags into a packed binary format that has a
    175 	// separate limit. Your request can fail for this limit even if your plaintext
    176 	// meets the other requirements. The PackedPolicySize response element indicates
    177 	// by percentage how close the policies and tags for your request are to the upper
    178 	// size limit.
    179 	PolicyArns []types.PolicyDescriptorType
    180 
    181 	// A list of session tags. Each session tag consists of a key name and an
    182 	// associated value. For more information about session tags, see Passing Session
    183 	// Tags in STS (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html)
    184 	// in the IAM User Guide. This parameter is optional. You can pass up to 50 session
    185 	// tags. The plaintext session tag keys can’t exceed 128 characters and the values
    186 	// can’t exceed 256 characters. For these and additional limits, see IAM and STS
    187 	// Character Limits (https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_iam-limits.html#reference_iam-limits-entity-length)
    188 	// in the IAM User Guide. An Amazon Web Services conversion compresses the passed
    189 	// inline session policy, managed policy ARNs, and session tags into a packed
    190 	// binary format that has a separate limit. Your request can fail for this limit
    191 	// even if your plaintext meets the other requirements. The PackedPolicySize
    192 	// response element indicates by percentage how close the policies and tags for
    193 	// your request are to the upper size limit. You can pass a session tag with the
    194 	// same key as a tag that is already attached to the user you are federating. When
    195 	// you do, session tags override a user tag with the same key. Tag key–value pairs
    196 	// are not case sensitive, but case is preserved. This means that you cannot have
    197 	// separate Department and department tag keys. Assume that the role has the
    198 	// Department = Marketing tag and you pass the department = engineering session
    199 	// tag. Department and department are not saved as separate tags, and the session
    200 	// tag passed in the request takes precedence over the role tag.
    201 	Tags []types.Tag
    202 
    203 	noSmithyDocumentSerde
    204 }
    205 
    206 // Contains the response to a successful GetFederationToken request, including
    207 // temporary Amazon Web Services credentials that can be used to make Amazon Web
    208 // Services requests.
    209 type GetFederationTokenOutput struct {
    210 
    211 	// The temporary security credentials, which include an access key ID, a secret
    212 	// access key, and a security (or session) token. The size of the security token
    213 	// that STS API operations return is not fixed. We strongly recommend that you make
    214 	// no assumptions about the maximum size.
    215 	Credentials *types.Credentials
    216 
    217 	// Identifiers for the federated user associated with the credentials (such as
    218 	// arn:aws:sts::123456789012:federated-user/Bob or 123456789012:Bob ). You can use
    219 	// the federated user's ARN in your resource-based policies, such as an Amazon S3
    220 	// bucket policy.
    221 	FederatedUser *types.FederatedUser
    222 
    223 	// A percentage value that indicates the packed size of the session policies and
    224 	// session tags combined passed in the request. The request fails if the packed
    225 	// size is greater than 100 percent, which means the policies and tags exceeded the
    226 	// allowed space.
    227 	PackedPolicySize *int32
    228 
    229 	// Metadata pertaining to the operation's result.
    230 	ResultMetadata middleware.Metadata
    231 
    232 	noSmithyDocumentSerde
    233 }
    234 
    235 func (c *Client) addOperationGetFederationTokenMiddlewares(stack *middleware.Stack, options Options) (err error) {
    236 	if err := stack.Serialize.Add(&setOperationInputMiddleware{}, middleware.After); err != nil {
    237 		return err
    238 	}
    239 	err = stack.Serialize.Add(&awsAwsquery_serializeOpGetFederationToken{}, middleware.After)
    240 	if err != nil {
    241 		return err
    242 	}
    243 	err = stack.Deserialize.Add(&awsAwsquery_deserializeOpGetFederationToken{}, middleware.After)
    244 	if err != nil {
    245 		return err
    246 	}
    247 	if err := addProtocolFinalizerMiddlewares(stack, options, "GetFederationToken"); err != nil {
    248 		return fmt.Errorf("add protocol finalizers: %v", err)
    249 	}
    250 
    251 	if err = addlegacyEndpointContextSetter(stack, options); err != nil {
    252 		return err
    253 	}
    254 	if err = addSetLoggerMiddleware(stack, options); err != nil {
    255 		return err
    256 	}
    257 	if err = addClientRequestID(stack); err != nil {
    258 		return err
    259 	}
    260 	if err = addComputeContentLength(stack); err != nil {
    261 		return err
    262 	}
    263 	if err = addResolveEndpointMiddleware(stack, options); err != nil {
    264 		return err
    265 	}
    266 	if err = addComputePayloadSHA256(stack); err != nil {
    267 		return err
    268 	}
    269 	if err = addRetry(stack, options); err != nil {
    270 		return err
    271 	}
    272 	if err = addRawResponseToMetadata(stack); err != nil {
    273 		return err
    274 	}
    275 	if err = addRecordResponseTiming(stack); err != nil {
    276 		return err
    277 	}
    278 	if err = addClientUserAgent(stack, options); err != nil {
    279 		return err
    280 	}
    281 	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
    282 		return err
    283 	}
    284 	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
    285 		return err
    286 	}
    287 	if err = addSetLegacyContextSigningOptionsMiddleware(stack); err != nil {
    288 		return err
    289 	}
    290 	if err = addOpGetFederationTokenValidationMiddleware(stack); err != nil {
    291 		return err
    292 	}
    293 	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opGetFederationToken(options.Region), middleware.Before); err != nil {
    294 		return err
    295 	}
    296 	if err = addRecursionDetection(stack); err != nil {
    297 		return err
    298 	}
    299 	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
    300 		return err
    301 	}
    302 	if err = addResponseErrorMiddleware(stack); err != nil {
    303 		return err
    304 	}
    305 	if err = addRequestResponseLogging(stack, options); err != nil {
    306 		return err
    307 	}
    308 	if err = addDisableHTTPSMiddleware(stack, options); err != nil {
    309 		return err
    310 	}
    311 	return nil
    312 }
    313 
    314 func newServiceMetadataMiddleware_opGetFederationToken(region string) *awsmiddleware.RegisterServiceMetadata {
    315 	return &awsmiddleware.RegisterServiceMetadata{
    316 		Region:        region,
    317 		ServiceID:     ServiceID,
    318 		OperationName: "GetFederationToken",
    319 	}
    320 }