UNPKG

6.07 kBTypeScriptView Raw
1import { BaseExternalAccountClient, BaseExternalAccountClientOptions } from './baseexternalclient';
2import { AuthClientOptions } from './authclient';
3/**
4 * Defines the credential source portion of the configuration for PluggableAuthClient.
5 *
6 * <p>Command is the only required field. If timeout_millis is not specified, the library will
7 * default to a 30-second timeout.
8 *
9 * <pre>
10 * Sample credential source for Pluggable Auth Client:
11 * {
12 * ...
13 * "credential_source": {
14 * "executable": {
15 * "command": "/path/to/get/credentials.sh --arg1=value1 --arg2=value2",
16 * "timeout_millis": 5000,
17 * "output_file": "/path/to/generated/cached/credentials"
18 * }
19 * }
20 * }
21 * </pre>
22 */
23export interface PluggableAuthClientOptions extends BaseExternalAccountClientOptions {
24 credential_source: {
25 executable: {
26 /**
27 * The command used to retrieve the 3rd party token.
28 */
29 command: string;
30 /**
31 * The timeout for executable to run in milliseconds. If none is provided it
32 * will be set to the default timeout of 30 seconds.
33 */
34 timeout_millis?: number;
35 /**
36 * An optional output file location that will be checked for a cached response
37 * from a previous run of the executable.
38 */
39 output_file?: string;
40 };
41 };
42}
43/**
44 * Error thrown from the executable run by PluggableAuthClient.
45 */
46export declare class ExecutableError extends Error {
47 /**
48 * The exit code returned by the executable.
49 */
50 readonly code: string;
51 constructor(message: string, code: string);
52}
53/**
54 * PluggableAuthClient enables the exchange of workload identity pool external credentials for
55 * Google access tokens by retrieving 3rd party tokens through a user supplied executable. These
56 * scripts/executables are completely independent of the Google Cloud Auth libraries. These
57 * credentials plug into ADC and will call the specified executable to retrieve the 3rd party token
58 * to be exchanged for a Google access token.
59 *
60 * <p>To use these credentials, the GOOGLE_EXTERNAL_ACCOUNT_ALLOW_EXECUTABLES environment variable
61 * must be set to '1'. This is for security reasons.
62 *
63 * <p>Both OIDC and SAML are supported. The executable must adhere to a specific response format
64 * defined below.
65 *
66 * <p>The executable must print out the 3rd party token to STDOUT in JSON format. When an
67 * output_file is specified in the credential configuration, the executable must also handle writing the
68 * JSON response to this file.
69 *
70 * <pre>
71 * OIDC response sample:
72 * {
73 * "version": 1,
74 * "success": true,
75 * "token_type": "urn:ietf:params:oauth:token-type:id_token",
76 * "id_token": "HEADER.PAYLOAD.SIGNATURE",
77 * "expiration_time": 1620433341
78 * }
79 *
80 * SAML2 response sample:
81 * {
82 * "version": 1,
83 * "success": true,
84 * "token_type": "urn:ietf:params:oauth:token-type:saml2",
85 * "saml_response": "...",
86 * "expiration_time": 1620433341
87 * }
88 *
89 * Error response sample:
90 * {
91 * "version": 1,
92 * "success": false,
93 * "code": "401",
94 * "message": "Error message."
95 * }
96 * </pre>
97 *
98 * <p>The "expiration_time" field in the JSON response is only required for successful
99 * responses when an output file was specified in the credential configuration
100 *
101 * <p>The auth libraries will populate certain environment variables that will be accessible by the
102 * executable, such as: GOOGLE_EXTERNAL_ACCOUNT_AUDIENCE, GOOGLE_EXTERNAL_ACCOUNT_TOKEN_TYPE,
103 * GOOGLE_EXTERNAL_ACCOUNT_INTERACTIVE, GOOGLE_EXTERNAL_ACCOUNT_IMPERSONATED_EMAIL, and
104 * GOOGLE_EXTERNAL_ACCOUNT_OUTPUT_FILE.
105 *
106 * <p>Please see this repositories README for a complete executable request/response specification.
107 */
108export declare class PluggableAuthClient extends BaseExternalAccountClient {
109 /**
110 * The command used to retrieve the third party token.
111 */
112 private readonly command;
113 /**
114 * The timeout in milliseconds for running executable,
115 * set to default if none provided.
116 */
117 private readonly timeoutMillis;
118 /**
119 * The path to file to check for cached executable response.
120 */
121 private readonly outputFile?;
122 /**
123 * Executable and output file handler.
124 */
125 private readonly handler;
126 /**
127 * Instantiates a PluggableAuthClient instance using the provided JSON
128 * object loaded from an external account credentials file.
129 * An error is thrown if the credential is not a valid pluggable auth credential.
130 * @param options The external account options object typically loaded from
131 * the external account JSON credential file.
132 * @param additionalOptions **DEPRECATED, all options are available in the
133 * `options` parameter.** Optional additional behavior customization options.
134 * These currently customize expiration threshold time and whether to retry
135 * on 401/403 API request errors.
136 */
137 constructor(options: PluggableAuthClientOptions, additionalOptions?: AuthClientOptions);
138 /**
139 * Triggered when an external subject token is needed to be exchanged for a
140 * GCP access token via GCP STS endpoint.
141 * This uses the `options.credential_source` object to figure out how
142 * to retrieve the token using the current environment. In this case,
143 * this calls a user provided executable which returns the subject token.
144 * The logic is summarized as:
145 * 1. Validated that the executable is allowed to run. The
146 * GOOGLE_EXTERNAL_ACCOUNT_ALLOW_EXECUTABLES environment must be set to
147 * 1 for security reasons.
148 * 2. If an output file is specified by the user, check the file location
149 * for a response. If the file exists and contains a valid response,
150 * return the subject token from the file.
151 * 3. Call the provided executable and return response.
152 * @return A promise that resolves with the external subject token.
153 */
154 retrieveSubjectToken(): Promise<string>;
155}