1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489
|
#ifndef AWS_AUTH_IMDS_CLIENT_H
#define AWS_AUTH_IMDS_CLIENT_H
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/auth/auth.h>
#include <aws/auth/credentials.h>
#include <aws/common/array_list.h>
#include <aws/common/date_time.h>
#include <aws/http/connection_manager.h>
#include <aws/io/retry_strategy.h>
AWS_PUSH_SANE_WARNING_LEVEL
typedef void(aws_imds_client_shutdown_completed_fn)(void *user_data);
/**
* Optional callback and user data to be invoked when an imds client has fully shut down
*/
struct aws_imds_client_shutdown_options {
aws_imds_client_shutdown_completed_fn *shutdown_callback;
void *shutdown_user_data;
};
/**
* Configuration options when creating an imds client
*/
struct aws_imds_client_options {
/*
* Completion callback to be invoked when the client has fully shut down
*/
struct aws_imds_client_shutdown_options shutdown_options;
/*
* Client bootstrap to use when this client makes network connections
*/
struct aws_client_bootstrap *bootstrap;
/*
* Retry strategy instance that governs how failed requests are retried
*/
struct aws_retry_strategy *retry_strategy;
/*
* What version of the imds protocol to use
*
* Defaults to IMDS_PROTOCOL_V2
*/
enum aws_imds_protocol_version imds_version;
/*
* If true, fallback from v2 to v1 will be disabled for all cases
*/
bool ec2_metadata_v1_disabled;
/*
* Table holding all cross-system functional dependencies for an imds client.
*
* For mocking the http layer in tests, leave NULL otherwise
*/
struct aws_auth_http_system_vtable *function_table;
};
/*
* Standard callback for instance metadata queries
*/
typedef void(
aws_imds_client_on_get_resource_callback_fn)(const struct aws_byte_buf *resource, int error_code, void *user_data);
/**
* https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-categories.html
*/
struct aws_imds_iam_profile {
struct aws_date_time last_updated;
struct aws_byte_cursor instance_profile_arn;
struct aws_byte_cursor instance_profile_id;
};
/**
* Block of per-instance EC2-specific data
*
* https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html
*/
struct aws_imds_instance_info {
/* an array of aws_byte_cursor */
struct aws_array_list marketplace_product_codes;
struct aws_byte_cursor availability_zone;
struct aws_byte_cursor private_ip;
struct aws_byte_cursor version;
struct aws_byte_cursor instance_id;
/* an array of aws_byte_cursor */
struct aws_array_list billing_products;
struct aws_byte_cursor instance_type;
struct aws_byte_cursor account_id;
struct aws_byte_cursor image_id;
struct aws_date_time pending_time;
struct aws_byte_cursor architecture;
struct aws_byte_cursor kernel_id;
struct aws_byte_cursor ramdisk_id;
struct aws_byte_cursor region;
};
/* the item typed stored in array is pointer to aws_byte_cursor */
typedef void(
aws_imds_client_on_get_array_callback_fn)(const struct aws_array_list *array, int error_code, void *user_data);
typedef void(aws_imds_client_on_get_credentials_callback_fn)(
const struct aws_credentials *credentials,
int error_code,
void *user_data);
typedef void(aws_imds_client_on_get_iam_profile_callback_fn)(
const struct aws_imds_iam_profile *iam_profile_info,
int error_code,
void *user_data);
typedef void(aws_imds_client_on_get_instance_info_callback_fn)(
const struct aws_imds_instance_info *instance_info,
int error_code,
void *user_data);
/**
* AWS EC2 Metadata Client is used to retrieve AWS EC2 Instance Metadata info.
*/
struct aws_imds_client;
AWS_EXTERN_C_BEGIN
/**
* Creates a new imds client
*
* @param allocator memory allocator to use for creation and queries
* @param options configuration options for the imds client
*
* @return a newly-constructed imds client, or NULL on failure
*/
AWS_AUTH_API
struct aws_imds_client *aws_imds_client_new(
struct aws_allocator *allocator,
const struct aws_imds_client_options *options);
/**
* Increments the ref count on the client
*
* @param client imds client to acquire a reference to
*/
AWS_AUTH_API
void aws_imds_client_acquire(struct aws_imds_client *client);
/**
* Decrements the ref count on the client
*
* @param client imds client to release a reference to
*/
AWS_AUTH_API
void aws_imds_client_release(struct aws_imds_client *client);
/**
* Queries a generic resource (string) from the ec2 instance metadata document
*
* @param client imds client to use for the query
* @param resource_path path of the resource to query
* @param callback callback function to invoke on query success or failure
* @param user_data opaque data to invoke the completion callback with
* @return AWS_OP_SUCCESS if the query was successfully started, AWS_OP_ERR otherwise
*/
AWS_AUTH_API
int aws_imds_client_get_resource_async(
struct aws_imds_client *client,
struct aws_byte_cursor resource_path,
aws_imds_client_on_get_resource_callback_fn callback,
void *user_data);
/**
* Gets the ami id of the ec2 instance from the instance metadata document
*
* @param client imds client to use for the query
* @param callback callback function to invoke on query success or failure
* @param user_data opaque data to invoke the completion callback with
* @return AWS_OP_SUCCESS if the query was successfully started, AWS_OP_ERR otherwise
*/
AWS_AUTH_API
int aws_imds_client_get_ami_id(
struct aws_imds_client *client,
aws_imds_client_on_get_resource_callback_fn callback,
void *user_data);
/**
* Gets the ami launch index of the ec2 instance from the instance metadata document
*
* @param client imds client to use for the query
* @param callback callback function to invoke on query success or failure
* @param user_data opaque data to invoke the completion callback with
* @return AWS_OP_SUCCESS if the query was successfully started, AWS_OP_ERR otherwise
*/
AWS_AUTH_API
int aws_imds_client_get_ami_launch_index(
struct aws_imds_client *client,
aws_imds_client_on_get_resource_callback_fn callback,
void *user_data);
/**
* Gets the ami manifest path of the ec2 instance from the instance metadata document
*
* @param client imds client to use for the query
* @param callback callback function to invoke on query success or failure
* @param user_data opaque data to invoke the completion callback with
* @return AWS_OP_SUCCESS if the query was successfully started, AWS_OP_ERR otherwise
*/
AWS_AUTH_API
int aws_imds_client_get_ami_manifest_path(
struct aws_imds_client *client,
aws_imds_client_on_get_resource_callback_fn callback,
void *user_data);
/**
* Gets the list of ancestor ami ids of the ec2 instance from the instance metadata document
*
* @param client imds client to use for the query
* @param callback callback function to invoke on query success or failure
* @param user_data opaque data to invoke the completion callback with
* @return AWS_OP_SUCCESS if the query was successfully started, AWS_OP_ERR otherwise
*/
AWS_AUTH_API
int aws_imds_client_get_ancestor_ami_ids(
struct aws_imds_client *client,
aws_imds_client_on_get_array_callback_fn callback,
void *user_data);
/**
* Gets the instance-action of the ec2 instance from the instance metadata document
*
* @param client imds client to use for the query
* @param callback callback function to invoke on query success or failure
* @param user_data opaque data to invoke the completion callback with
* @return AWS_OP_SUCCESS if the query was successfully started, AWS_OP_ERR otherwise
*/
AWS_AUTH_API
int aws_imds_client_get_instance_action(
struct aws_imds_client *client,
aws_imds_client_on_get_resource_callback_fn callback,
void *user_data);
/**
* Gets the instance id of the ec2 instance from the instance metadata document
*
* @param client imds client to use for the query
* @param callback callback function to invoke on query success or failure
* @param user_data opaque data to invoke the completion callback with
* @return AWS_OP_SUCCESS if the query was successfully started, AWS_OP_ERR otherwise
*/
AWS_AUTH_API
int aws_imds_client_get_instance_id(
struct aws_imds_client *client,
aws_imds_client_on_get_resource_callback_fn callback,
void *user_data);
/**
* Gets the instance type of the ec2 instance from the instance metadata document
*
* @param client imds client to use for the query
* @param callback callback function to invoke on query success or failure
* @param user_data opaque data to invoke the completion callback with
* @return AWS_OP_SUCCESS if the query was successfully started, AWS_OP_ERR otherwise
*/
AWS_AUTH_API
int aws_imds_client_get_instance_type(
struct aws_imds_client *client,
aws_imds_client_on_get_resource_callback_fn callback,
void *user_data);
/**
* Gets the mac address of the ec2 instance from the instance metadata document
*
* @param client imds client to use for the query
* @param callback callback function to invoke on query success or failure
* @param user_data opaque data to invoke the completion callback with
* @return AWS_OP_SUCCESS if the query was successfully started, AWS_OP_ERR otherwise
*/
AWS_AUTH_API
int aws_imds_client_get_mac_address(
struct aws_imds_client *client,
aws_imds_client_on_get_resource_callback_fn callback,
void *user_data);
/**
* Gets the private ip address of the ec2 instance from the instance metadata document
*
* @param client imds client to use for the query
* @param callback callback function to invoke on query success or failure
* @param user_data opaque data to invoke the completion callback with
* @return AWS_OP_SUCCESS if the query was successfully started, AWS_OP_ERR otherwise
*/
AWS_AUTH_API
int aws_imds_client_get_private_ip_address(
struct aws_imds_client *client,
aws_imds_client_on_get_resource_callback_fn callback,
void *user_data);
/**
* Gets the availability zone of the ec2 instance from the instance metadata document
*
* @param client imds client to use for the query
* @param callback callback function to invoke on query success or failure
* @param user_data opaque data to invoke the completion callback with
* @return AWS_OP_SUCCESS if the query was successfully started, AWS_OP_ERR otherwise
*/
AWS_AUTH_API
int aws_imds_client_get_availability_zone(
struct aws_imds_client *client,
aws_imds_client_on_get_resource_callback_fn callback,
void *user_data);
/**
* Gets the product codes of the ec2 instance from the instance metadata document
*
* @param client imds client to use for the query
* @param callback callback function to invoke on query success or failure
* @param user_data opaque data to invoke the completion callback with
* @return AWS_OP_SUCCESS if the query was successfully started, AWS_OP_ERR otherwise
*/
AWS_AUTH_API
int aws_imds_client_get_product_codes(
struct aws_imds_client *client,
aws_imds_client_on_get_resource_callback_fn callback,
void *user_data);
/**
* Gets the public key of the ec2 instance from the instance metadata document
*
* @param client imds client to use for the query
* @param callback callback function to invoke on query success or failure
* @param user_data opaque data to invoke the completion callback with
* @return AWS_OP_SUCCESS if the query was successfully started, AWS_OP_ERR otherwise
*/
AWS_AUTH_API
int aws_imds_client_get_public_key(
struct aws_imds_client *client,
aws_imds_client_on_get_resource_callback_fn callback,
void *user_data);
/**
* Gets the ramdisk id of the ec2 instance from the instance metadata document
*
* @param client imds client to use for the query
* @param callback callback function to invoke on query success or failure
* @param user_data opaque data to invoke the completion callback with
* @return AWS_OP_SUCCESS if the query was successfully started, AWS_OP_ERR otherwise
*/
AWS_AUTH_API
int aws_imds_client_get_ramdisk_id(
struct aws_imds_client *client,
aws_imds_client_on_get_resource_callback_fn callback,
void *user_data);
/**
* Gets the reservation id of the ec2 instance from the instance metadata document
*
* @param client imds client to use for the query
* @param callback callback function to invoke on query success or failure
* @param user_data opaque data to invoke the completion callback with
* @return AWS_OP_SUCCESS if the query was successfully started, AWS_OP_ERR otherwise
*/
AWS_AUTH_API
int aws_imds_client_get_reservation_id(
struct aws_imds_client *client,
aws_imds_client_on_get_resource_callback_fn callback,
void *user_data);
/**
* Gets the list of the security groups of the ec2 instance from the instance metadata document
*
* @param client imds client to use for the query
* @param callback callback function to invoke on query success or failure
* @param user_data opaque data to invoke the completion callback with
* @return AWS_OP_SUCCESS if the query was successfully started, AWS_OP_ERR otherwise
*/
AWS_AUTH_API
int aws_imds_client_get_security_groups(
struct aws_imds_client *client,
aws_imds_client_on_get_array_callback_fn callback,
void *user_data);
/**
* Gets the list of block device mappings of the ec2 instance from the instance metadata document
*
* @param client imds client to use for the query
* @param callback callback function to invoke on query success or failure
* @param user_data opaque data to invoke the completion callback with
* @return AWS_OP_SUCCESS if the query was successfully started, AWS_OP_ERR otherwise
*/
AWS_AUTH_API
int aws_imds_client_get_block_device_mapping(
struct aws_imds_client *client,
aws_imds_client_on_get_array_callback_fn callback,
void *user_data);
/**
* Gets the attached iam role of the ec2 instance from the instance metadata document
*
* @param client imds client to use for the query
* @param callback callback function to invoke on query success or failure
* @param user_data opaque data to invoke the completion callback with
* @return AWS_OP_SUCCESS if the query was successfully started, AWS_OP_ERR otherwise
*/
AWS_AUTH_API
int aws_imds_client_get_attached_iam_role(
struct aws_imds_client *client,
aws_imds_client_on_get_resource_callback_fn callback,
void *user_data);
/**
* Gets temporary credentials based on the attached iam role of the ec2 instance
*
* @param client imds client to use for the query
* @param iam_role_name iam role name to get temporary credentials through
* @param callback callback function to invoke on query success or failure
* @param user_data opaque data to invoke the completion callback with
* @return AWS_OP_SUCCESS if the query was successfully started, AWS_OP_ERR otherwise
*/
AWS_AUTH_API
int aws_imds_client_get_credentials(
struct aws_imds_client *client,
struct aws_byte_cursor iam_role_name,
aws_imds_client_on_get_credentials_callback_fn callback,
void *user_data);
/**
* Gets the iam profile information of the ec2 instance from the instance metadata document
*
* @param client imds client to use for the query
* @param callback callback function to invoke on query success or failure
* @param user_data opaque data to invoke the completion callback with
* @return AWS_OP_SUCCESS if the query was successfully started, AWS_OP_ERR otherwise
*/
AWS_AUTH_API
int aws_imds_client_get_iam_profile(
struct aws_imds_client *client,
aws_imds_client_on_get_iam_profile_callback_fn callback,
void *user_data);
/**
* Gets the user data of the ec2 instance from the instance metadata document
*
* @param client imds client to use for the query
* @param callback callback function to invoke on query success or failure
* @param user_data opaque data to invoke the completion callback with
* @return AWS_OP_SUCCESS if the query was successfully started, AWS_OP_ERR otherwise
*/
AWS_AUTH_API
int aws_imds_client_get_user_data(
struct aws_imds_client *client,
aws_imds_client_on_get_resource_callback_fn callback,
void *user_data);
/**
* Gets the signature of the ec2 instance from the instance metadata document
*
* @param client imds client to use for the query
* @param callback callback function to invoke on query success or failure
* @param user_data opaque data to invoke the completion callback with
* @return AWS_OP_SUCCESS if the query was successfully started, AWS_OP_ERR otherwise
*/
AWS_AUTH_API
int aws_imds_client_get_instance_signature(
struct aws_imds_client *client,
aws_imds_client_on_get_resource_callback_fn callback,
void *user_data);
/**
* Gets the instance information data block of the ec2 instance from the instance metadata document
*
* @param client imds client to use for the query
* @param callback callback function to invoke on query success or failure
* @param user_data opaque data to invoke the completion callback with
* @return AWS_OP_SUCCESS if the query was successfully started, AWS_OP_ERR otherwise
*/
AWS_AUTH_API
int aws_imds_client_get_instance_info(
struct aws_imds_client *client,
aws_imds_client_on_get_instance_info_callback_fn callback,
void *user_data);
AWS_EXTERN_C_END
AWS_POP_SANE_WARNING_LEVEL
#endif /* AWS_AUTH_IMDS_CLIENT_H */
|