Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable IMDSV1 #215

Merged
merged 5 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -215,21 +215,20 @@ extension CredentialsProvider.Source {
}

/// Creates a credentials provider that sources credentials from ec2 instance metadata.
/// It will use IMDSv2 to fetch the credentials.
///
/// - Parameters:
/// - bootstrap: Connection bootstrap to use for any network connections made while sourcing credentials.
/// - imdsVersion: (Optional) Which version of the imds query protocol to use.
/// - shutdownCallback: (Optional) shutdown callback
/// - Returns: `CredentialsProvider`
/// - Throws: CommonRuntimeError.crtError
public static func `imds`(bootstrap: ClientBootstrap,
imdsVersion: IMDSProtocolVersion = IMDSProtocolVersion.version2,
shutdownCallback: ShutdownCallback? = nil) -> Self {
Self {
let shutdownCallbackCore = ShutdownCallbackCore(shutdownCallback)
var imdsOptions = aws_credentials_provider_imds_options()
imdsOptions.bootstrap = bootstrap.rawValue
imdsOptions.imds_version = imdsVersion.rawValue
imdsOptions.ec2_metadata_v1_disabled = true
imdsOptions.shutdown_options = shutdownCallbackCore.getRetainedCredentialProviderShutdownOptions()
guard let provider = aws_credentials_provider_new_imds(allocator.rawValue,
&imdsOptions)
Expand Down
9 changes: 7 additions & 2 deletions Source/AwsCommonRuntimeKit/auth/imds/IMDSClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,22 @@ import AwsCAuth
// swiftlint:disable type_body_length
public class IMDSClient {
let rawValue: OpaquePointer

/// Creates an IMDSClient that always uses IMDSv2
/// - Parameters:
/// - bootstrap: Connection bootstrap to use for any network connections
/// - retryStrategy: RetryStrategy to use with the client
/// - shutdownCallback: (Optional) shutdown callback
public init(bootstrap: ClientBootstrap,
retryStrategy: RetryStrategy,
protocolVersion: IMDSProtocolVersion = IMDSProtocolVersion.version2,
shutdownCallback: ShutdownCallback? = nil) throws {
let shutdownCallbackCore = ShutdownCallbackCore(shutdownCallback)
let shutdownOptions = shutdownCallbackCore.getRetainedIMDSClientShutdownOptions()
var imdsOptions = aws_imds_client_options()
imdsOptions.shutdown_options = shutdownOptions
imdsOptions.bootstrap = bootstrap.rawValue
imdsOptions.retry_strategy = retryStrategy.rawValue
imdsOptions.imds_version = protocolVersion.rawValue
imdsOptions.ec2_metadata_v1_disabled = true
guard let rawValue = aws_imds_client_new(allocator.rawValue, &imdsOptions) else {
shutdownCallbackCore.release()
throw CommonRunTimeError.crtError(CRTError.makeFromLastError())
Expand Down
18 changes: 0 additions & 18 deletions Source/AwsCommonRuntimeKit/auth/imds/IMDSProtocolVersion.swift

This file was deleted.