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

Process Credentials Provider #192

Merged
merged 5 commits into from
Aug 14, 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
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ packageTargets.append(contentsOf: [
dependencies: ["AwsCommonRuntimeKit"],
path: "Test/AwsCommonRuntimeKitTests",
resources: [
.copy("Resources")
.process("Resources")
]
),
.executableTarget(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,50 @@ extension CredentialsProvider.Source {
}
}

/// The process credentials provider sources credentials from running a command or process.
/// The command to run is sourced from a profile in the AWS config file, using the standard
/// profile selection rules. The profile key the command is read from is "credential_process."
/// E.g.:
/// [default]
/// credential_process=/opt/amazon/bin/my-credential-fetcher --argsA=abc
/// On successfully running the command, the output should be a json data with the following
/// format:
/// {
/// "Version": 1,
/// "AccessKeyId": "accesskey",
/// "SecretAccessKey": "secretAccessKey"
/// "SessionToken": "....",
/// "Expiration": "2019-05-29T00:21:43Z"
/// }
/// Version here identifies the command output format version.
///
/// - Parameters:
/// - fileBasedConfiguration: The file based configuration to read the configuration from.
/// - profileFileNameOverride: (Optional) Override of what profile to use to source credentials from ('default' by default)
/// - shutdownCallback: (Optional) shutdown callback
/// - Returns: `CredentialsProvider`
/// - Throws: CommonRuntimeError.crtError
public static func `process`(fileBasedConfiguration: FileBasedConfiguration,
profileFileNameOverride: String? = nil,
shutdownCallback: ShutdownCallback? = nil) -> Self {
Self {
let shutdownCallbackCore = ShutdownCallbackCore(shutdownCallback)
var processOptionsC = aws_credentials_provider_process_options()
processOptionsC.shutdown_options = shutdownCallbackCore.getRetainedCredentialProviderShutdownOptions()
processOptionsC.config_profile_collection_cached = fileBasedConfiguration.rawValue
guard let provider: UnsafeMutablePointer<aws_credentials_provider> = withByteCursorFromStrings(
profileFileNameOverride, { profileCursor in
processOptionsC.profile_to_use = profileCursor
return aws_credentials_provider_new_process(allocator.rawValue, &processOptionsC)
})
else {
shutdownCallbackCore.release()
throw CommonRunTimeError.crtError(CRTError.makeFromLastError())
}
return provider
}
}

/// Creates a credentials provider that sources credentials from ec2 instance metadata.
///
/// - Parameters:
Expand Down
4 changes: 3 additions & 1 deletion Test/AwsCommonRuntimeKitTests/Resources/example_profile.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[default]
aws_access_key_id = default_access_key_id
aws_secret_access_key = default_secret_access_key
credential_process = echo '{"Version": 1, "AccessKeyId": "AccessKey123", "SecretAccessKey": "SecretAccessKey123", "SessionToken": "SessionToken123","Expiration":"2020-02-25T06:03:31Z"}'
waahm7 marked this conversation as resolved.
Show resolved Hide resolved
s3 =
max_concurrent_requests = 20
[profile crt_user]
aws_access_key_id = example_access_key_id
aws_secret_access_key = example_secret_access_key
aws_secret_access_key = example_secret_access_key

15 changes: 15 additions & 0 deletions Test/AwsCommonRuntimeKitTests/auth/CredentialsProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,21 @@ class CredentialsProviderTests: XCBaseTestCase {
wait(for: [shutdownWasCalled], timeout: 15)
}

func testCreateCredentialsProviderProcess() async throws {
do {
let provider = try CredentialsProvider(source: .process(
fileBasedConfiguration: FileBasedConfiguration(
configFilePath: Bundle.module.path(forResource: "example_profile", ofType: "txt")!),
shutdownCallback: getShutdownCallback()))
let credentials = try await provider.getCredentials()
XCTAssertNotNil(credentials)
XCTAssertEqual("AccessKey123", credentials.getAccessKey())
XCTAssertEqual("SecretAccessKey123", credentials.getSecret())
XCTAssertEqual("SessionToken123", credentials.getSessionToken())
}
wait(for: [shutdownWasCalled], timeout: 15)
}

func testCreateCredentialsProviderSSO() async throws {
do {
let provider = try CredentialsProvider(source: .sso(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class FileBasedConfigurationTests: XCBaseTestCase {
let fileBasedConfiguration = try FileBasedConfiguration(configFilePath: profilePath, credentialsFilePath: configPath)
XCTAssertNotNil(fileBasedConfiguration)
let defaultSection = fileBasedConfiguration.getSection(name: "default", sectionType: .profile)!
XCTAssertEqual(defaultSection.propertyCount, 3)
XCTAssertEqual(defaultSection.propertyCount, 4)
let property = defaultSection.getProperty(name: "aws_access_key_id")!
XCTAssertEqual("accessKey", property.value)

Expand Down
2 changes: 1 addition & 1 deletion aws-common-runtime/aws-c-common
Submodule aws-c-common updated 69 files
+3 −3 .github/workflows/ci.yml
+1 −1 .github/workflows/stale_issue.yml
+1 −1 CMakeLists.txt
+74 −41 cmake/AwsCheckHeaders.cmake
+2 −2 cmake/AwsTestHarness.cmake
+2 −0 include/aws/common/allocator.h
+19 −1 include/aws/common/array_list.h
+13 −21 include/aws/common/array_list.inl
+5 −2 include/aws/common/assert.h
+3 −0 include/aws/common/atomics.h
+16 −11 include/aws/common/atomics_msvc.inl
+3 −0 include/aws/common/byte_buf.h
+2 −0 include/aws/common/byte_order.h
+3 −0 include/aws/common/cache.h
+3 −0 include/aws/common/clock.h
+3 −0 include/aws/common/command_line_parser.h
+2 −0 include/aws/common/common.h
+4 −0 include/aws/common/condition_variable.h
+4 −0 include/aws/common/cpuid.h
+3 −0 include/aws/common/date_time.h
+3 −0 include/aws/common/device_random.h
+2 −0 include/aws/common/encoding.h
+3 −0 include/aws/common/environment.h
+5 −0 include/aws/common/error.h
+2 −0 include/aws/common/fifo_cache.h
+3 −0 include/aws/common/file.h
+3 −0 include/aws/common/hash_table.h
+3 −0 include/aws/common/json.h
+2 −0 include/aws/common/lifo_cache.h
+3 −0 include/aws/common/linked_hash_table.h
+3 −0 include/aws/common/linked_list.h
+1 −1 include/aws/common/linked_list.inl
+3 −0 include/aws/common/log_channel.h
+3 −0 include/aws/common/log_formatter.h
+3 −0 include/aws/common/log_writer.h
+14 −0 include/aws/common/logging.h
+2 −0 include/aws/common/lru_cache.h
+22 −0 include/aws/common/macros.h
+3 −0 include/aws/common/math.h
+7 −5 include/aws/common/math.msvc.inl
+3 −0 include/aws/common/mutex.h
+1 −1 include/aws/common/predicates.h
+3 −0 include/aws/common/priority_queue.h
+1 −1 include/aws/common/private/xml_parser_impl.h
+3 −0 include/aws/common/process.h
+8 −0 include/aws/common/promise.h
+3 −0 include/aws/common/ref_count.h
+3 −5 include/aws/common/ring_buffer.h
+3 −0 include/aws/common/rw_lock.h
+3 −0 include/aws/common/statistics.h
+6 −1 include/aws/common/string.h
+3 −0 include/aws/common/system_info.h
+3 −0 include/aws/common/task_scheduler.h
+3 −0 include/aws/common/thread.h
+3 −0 include/aws/common/thread_scheduler.h
+2 −0 include/aws/common/time.h
+3 −0 include/aws/common/uri.h
+3 −0 include/aws/common/uuid.h
+19 −31 include/aws/common/xml_parser.h
+2 −0 include/aws/common/zero.h
+20 −20 include/aws/testing/aws_test_harness.h
+15 −0 source/arch/intel/cpuid.c
+8 −0 source/array_list.c
+3 −0 source/common.c
+5 −2 source/promise.c
+71 −122 source/xml_parser.c
+1 −0 tests/cpuid_test.c
+101 −136 tests/xml_parser_test.c
+0 −1 verification/cbmc/proofs/prepare.py
2 changes: 1 addition & 1 deletion aws-common-runtime/aws-c-http
2 changes: 1 addition & 1 deletion aws-common-runtime/aws-c-io
Submodule aws-c-io updated 52 files
+7 −6 .builder/actions/pkcs11_test_setup.py
+82 −0 .github/ISSUE_TEMPLATE/bug-report.yml
+5 −0 .github/ISSUE_TEMPLATE/config.yml
+23 −0 .github/ISSUE_TEMPLATE/documentation.yml
+47 −0 .github/ISSUE_TEMPLATE/feature-request.yml
+1 −1 .github/workflows/ci.yml
+17 −0 .github/workflows/closed-issue-message.yml
+1 −1 .github/workflows/proof-alarm.yml
+46 −0 .github/workflows/stale_issue.yml
+1 −1 CMakeLists.txt
+0 −1 builder.json
+3 −2 codebuild/linux-integration-tests.yml
+117 −0 include/aws/io/async_stream.h
+3 −0 include/aws/io/channel.h
+3 −0 include/aws/io/channel_bootstrap.h
+3 −0 include/aws/io/event_loop.h
+627 −0 include/aws/io/future.h
+3 −0 include/aws/io/host_resolver.h
+3 −0 include/aws/io/io.h
+3 −0 include/aws/io/logging.h
+3 −0 include/aws/io/message_pool.h
+3 −0 include/aws/io/pipe.h
+3 −0 include/aws/io/pkcs11.h
+5 −0 include/aws/io/retry_strategy.h
+3 −0 include/aws/io/shared_library.h
+9 −0 include/aws/io/socket.h
+3 −0 include/aws/io/socket_channel_handler.h
+3 −0 include/aws/io/statistics.h
+3 −0 include/aws/io/stream.h
+5 −2 include/aws/io/tls_channel_handler.h
+264 −0 include/aws/testing/async_stream_tester.h
+227 −0 include/aws/testing/stream_tester.h
+153 −0 source/async_stream.c
+9 −0 source/bsd/kqueue_event_loop.c
+11 −3 source/exponential_backoff_retry_strategy.c
+543 −0 source/future.c
+9 −0 source/linux/epoll_event_loop.c
+10 −0 source/posix/socket.c
+28 −13 source/s2n/s2n_tls_channel_handler.c
+1 −1 source/stream.c
+2 −0 source/tls_channel_handler.c
+10 −0 source/windows/iocp/socket.c
+54 −25 tests/CMakeLists.txt
+168 −0 tests/async_stream_test.c
+2 −14 tests/byo_crypto_test.c
+57 −0 tests/exponential_backoff_retry_test.c
+739 −0 tests/future_test.c
+22 −0 tests/future_test.h
+2 −13 tests/socket_handler_test.c
+3 −18 tests/socket_test.c
+69 −25 tests/stream_test.c
+12 −29 tests/tls_handler_test.c
2 changes: 1 addition & 1 deletion aws-common-runtime/s2n
Submodule s2n updated 275 files