Skip to content
Open
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
6 changes: 3 additions & 3 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ let package = Package(
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.20.1"),
.package(url: "https://github.com/apple/swift-system.git", from: "1.4.0"),
.package(url: "https://github.com/swiftlang/swift-docc-plugin", from: "1.1.0"),
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.36.0"),
],
targets: [
.target(
Expand Down Expand Up @@ -228,6 +229,8 @@ let package = Package(
"ContainerizationError",
.product(name: "Collections", package: "swift-collections"),
.product(name: "Logging", package: "swift-log"),
.product(name: "NIOSSL", package: "swift-nio-ssl"),

]
),
.testTarget(
Expand Down
4 changes: 2 additions & 2 deletions Sources/Containerization/Image/ImageStore/ImageStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ extension ImageStore {
) async throws -> Image {

let matcher = createPlatformMatcher(for: platform)
let client = try RegistryClient(reference: reference, insecure: insecure, auth: auth)
let client = try RegistryClient(reference: reference, insecure: insecure, auth: auth, tlsConfiguration: TLSUtils.makeEnvironmentAwareTLSConfiguration())

let ref = try Reference.parse(reference)
let name = ref.path
Expand Down Expand Up @@ -248,7 +248,7 @@ extension ImageStore {
guard let tag = ref.tag ?? ref.digest else {
throw ContainerizationError(.invalidArgument, message: "Invalid tag/digest for image reference \(reference)")
}
let client = try RegistryClient(reference: reference, insecure: insecure, auth: auth)
let client = try RegistryClient(reference: reference, insecure: insecure, auth: auth, tlsConfiguration: TLSUtils.makeEnvironmentAwareTLSConfiguration())
let operation = ExportOperation(name: name, tag: tag, contentStore: self.contentStore, client: client, progress: progress)
try await operation.export(index: img.descriptor, platforms: matcher)
}
Expand Down
39 changes: 39 additions & 0 deletions Sources/ContainerizationExtras/TLSUtils.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//===----------------------------------------------------------------------===//
// Copyright © 2025 Apple Inc. and the Containerization project authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//===----------------------------------------------------------------------===//

import Foundation
import NIO
import NIOSSL

public enum TLSUtils {

public static func makeEnvironmentAwareTLSConfiguration() -> TLSConfiguration {
var tlsConfig = TLSConfiguration.makeClientConfiguration()

// Check standard SSL environment variables in priority order
let customCAPath =
ProcessInfo.processInfo.environment["SSL_CERT_FILE"]
?? ProcessInfo.processInfo.environment["CURL_CA_BUNDLE"]
?? ProcessInfo.processInfo.environment["REQUESTS_CA_BUNDLE"]

if let caPath = customCAPath {
tlsConfig.trustRoots = .file(caPath)
}
// else: use .default

return tlsConfig
}
}
13 changes: 10 additions & 3 deletions Sources/ContainerizationOCI/Client/RegistryClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Foundation
import Logging
import NIO
import NIOHTTP1
import NIOSSL

#if os(macOS)
import Network
Expand Down Expand Up @@ -66,7 +67,8 @@ public final class RegistryClient: ContentClient {
reference: String,
insecure: Bool = false,
auth: Authentication? = nil,
logger: Logger? = nil
logger: Logger? = nil,
tlsConfiguration: TLSConfiguration? = nil,
) throws {
let ref = try Reference.parse(reference)
guard let domain = ref.resolvedDomain else {
Expand All @@ -86,7 +88,8 @@ public final class RegistryClient: ContentClient {
scheme: scheme,
port: port,
authentication: auth,
retryOptions: Self.defaultRetryOptions
retryOptions: Self.defaultRetryOptions,
tlsConfiguration: tlsConfiguration,
)
}

Expand All @@ -98,7 +101,8 @@ public final class RegistryClient: ContentClient {
clientID: String? = nil,
retryOptions: RetryOptions? = nil,
bufferSize: Int = Int(4.mib()),
logger: Logger? = nil
logger: Logger? = nil,
tlsConfiguration: TLSConfiguration? = nil,
) {
var components = URLComponents()
components.scheme = scheme
Expand All @@ -118,6 +122,9 @@ public final class RegistryClient: ContentClient {
let proxyPort = proxyURL.port ?? (proxyURL.scheme == "https" ? 443 : 80)
httpConfiguration.proxy = HTTPClient.Configuration.Proxy.server(host: proxyHost, port: proxyPort)
}
if tlsConfiguration != nil {
httpConfiguration.tlsConfiguration = tlsConfiguration
}

if let logger {
self.client = HTTPClient(eventLoopGroupProvider: .singleton, configuration: httpConfiguration, backgroundActivityLogger: logger)
Expand Down
4 changes: 3 additions & 1 deletion Sources/cctl/LoginCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import ArgumentParser
import Containerization
import ContainerizationError
import ContainerizationExtras
import ContainerizationOCI
import Foundation

Expand Down Expand Up @@ -74,7 +75,8 @@ extension Application {
shouldRetry: ({ response in
response.status.code >= 500
})
)
),
tlsConfiguration: TLSUtils.makeEnvironmentAwareTLSConfiguration(),
)
try await client.ping()
try keychain.save(domain: server, username: username, password: password)
Expand Down
6 changes: 3 additions & 3 deletions vminitd/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.