1 | import { AwsSecurityCredentials } from './awsrequestsigner';
|
2 | import { BaseExternalAccountClient, BaseExternalAccountClientOptions, ExternalAccountSupplierContext } from './baseexternalclient';
|
3 | import { AuthClientOptions } from './authclient';
|
4 | import { SnakeToCamelObject } from '../util';
|
5 | /**
|
6 | * AWS credentials JSON interface. This is used for AWS workloads.
|
7 | */
|
8 | export interface AwsClientOptions extends BaseExternalAccountClientOptions {
|
9 | /**
|
10 | * Object containing options to retrieve AWS security credentials. A valid credential
|
11 | * source or a aws security credentials supplier should be specified.
|
12 | */
|
13 | credential_source?: {
|
14 | /**
|
15 | * AWS environment ID. Currently only 'AWS1' is supported.
|
16 | */
|
17 | environment_id: string;
|
18 | /**
|
19 | * The EC2 metadata URL to retrieve the current AWS region from. If this is
|
20 | * not provided, the region should be present in the AWS_REGION or AWS_DEFAULT_REGION
|
21 | * environment variables.
|
22 | */
|
23 | region_url?: string;
|
24 | /**
|
25 | * The EC2 metadata URL to retrieve AWS security credentials. If this is not provided,
|
26 | * the credentials should be present in the AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY,
|
27 | * and AWS_SESSION_TOKEN environment variables.
|
28 | */
|
29 | url?: string;
|
30 | /**
|
31 | * The regional GetCallerIdentity action URL, used to determine the account
|
32 | * ID and its roles.
|
33 | */
|
34 | regional_cred_verification_url: string;
|
35 | /**
|
36 | * The imdsv2 session token url is used to fetch session token from AWS
|
37 | * which is later sent through headers for metadata requests. If the
|
38 | * field is missing, then session token won't be fetched and sent with
|
39 | * the metadata requests.
|
40 | * The session token is required for IMDSv2 but optional for IMDSv1
|
41 | */
|
42 | imdsv2_session_token_url?: string;
|
43 | };
|
44 | /**
|
45 | * The AWS security credentials supplier to call to retrieve the AWS region
|
46 | * and AWS security credentials. Either this or a valid credential source
|
47 | * must be specified.
|
48 | */
|
49 | aws_security_credentials_supplier?: AwsSecurityCredentialsSupplier;
|
50 | }
|
51 | /**
|
52 | * Supplier interface for AWS security credentials. This can be implemented to
|
53 | * return an AWS region and AWS security credentials. These credentials can
|
54 | * then be exchanged for a GCP token by an {@link AwsClient}.
|
55 | */
|
56 | export interface AwsSecurityCredentialsSupplier {
|
57 | /**
|
58 | * Gets the active AWS region.
|
59 | * @param context {@link ExternalAccountSupplierContext} from the calling
|
60 | * {@link AwsClient}, contains the requested audience and subject token type
|
61 | * for the external account identity as well as the transport from the
|
62 | * calling client to use for requests.
|
63 | * @return A promise that resolves with the AWS region string.
|
64 | */
|
65 | getAwsRegion: (context: ExternalAccountSupplierContext) => Promise<string>;
|
66 | /**
|
67 | * Gets valid AWS security credentials for the requested external account
|
68 | * identity. Note that these are not cached by the calling {@link AwsClient},
|
69 | * so caching should be including in the implementation.
|
70 | * @param context {@link ExternalAccountSupplierContext} from the calling
|
71 | * {@link AwsClient}, contains the requested audience and subject token type
|
72 | * for the external account identity as well as the transport from the
|
73 | * calling client to use for requests.
|
74 | * @return A promise that resolves with the requested {@link AwsSecurityCredentials}.
|
75 | */
|
76 | getAwsSecurityCredentials: (context: ExternalAccountSupplierContext) => Promise<AwsSecurityCredentials>;
|
77 | }
|
78 | /**
|
79 | * AWS external account client. This is used for AWS workloads, where
|
80 | * AWS STS GetCallerIdentity serialized signed requests are exchanged for
|
81 | * GCP access token.
|
82 | */
|
83 | export declare class AwsClient extends BaseExternalAccountClient {
|
84 | #private;
|
85 | private readonly environmentId?;
|
86 | private readonly awsSecurityCredentialsSupplier;
|
87 | private readonly regionalCredVerificationUrl;
|
88 | private awsRequestSigner;
|
89 | private region;
|
90 | /**
|
91 | * @deprecated AWS client no validates the EC2 metadata address.
|
92 | **/
|
93 | static AWS_EC2_METADATA_IPV4_ADDRESS: string;
|
94 | /**
|
95 | * @deprecated AWS client no validates the EC2 metadata address.
|
96 | **/
|
97 | static AWS_EC2_METADATA_IPV6_ADDRESS: string;
|
98 | /**
|
99 | * Instantiates an AwsClient instance using the provided JSON
|
100 | * object loaded from an external account credentials file.
|
101 | * An error is thrown if the credential is not a valid AWS credential.
|
102 | * @param options The external account options object typically loaded
|
103 | * from the external account JSON credential file.
|
104 | * @param additionalOptions **DEPRECATED, all options are available in the
|
105 | * `options` parameter.** Optional additional behavior customization options.
|
106 | * These currently customize expiration threshold time and whether to retry
|
107 | * on 401/403 API request errors.
|
108 | */
|
109 | constructor(options: AwsClientOptions | SnakeToCamelObject<AwsClientOptions>, additionalOptions?: AuthClientOptions);
|
110 | private validateEnvironmentId;
|
111 | /**
|
112 | * Triggered when an external subject token is needed to be exchanged for a
|
113 | * GCP access token via GCP STS endpoint. This will call the
|
114 | * { AwsSecurityCredentialsSupplier} to retrieve an AWS region and AWS
|
115 | * Security Credentials, then use them to create a signed AWS STS request that
|
116 | * can be exchanged for a GCP access token.
|
117 | * with the external subject token.
A promise that resolves |
118 | */
|
119 | retrieveSubjectToken(): Promise<string>;
|
120 | }
|