Closed ucoruh closed 2 months ago
Have you tried https = false
here with localhost:9000
?
explicit BaseUrl(std::string host, bool https = true,
std::string region = {});
No, I didn't notice this parameter before. I have removed all the certificates and related operations, and this parameter helped us disable HTTPS. Thank you for the tip.
The following code works well:
#include <miniocpp/client.h>
#include <iostream>
int main() {
// MinIO connection setup
minio::s3::BaseUrl base_url("http://localhost:9000",false);
minio::creds::StaticProvider provider("admin", "adminadmin");
minio::s3::Client client(base_url, &provider);
// Debug modunu açma
//client.Debug(true);
// Sertifika doğrulama kontrolünü devre dışı bırakma (SSL kullanılmadığı için)
//client.IgnoreCertCheck(true);
// Bucket'ları listelemeye çalışma
minio::s3::ListBucketsResponse listResp = client.ListBuckets();
// İstek başarılı oldu mu kontrol et
if (!listResp) {
std::cerr << "Failed to connect to MinIO server: " << listResp.Error().String() << std::endl;
return 1;
}
std::cout << "Buckets found on the server:" << std::endl;
for (const auto& bucket : listResp.buckets) {
std::cout << " - " << bucket.name << std::endl;
}
return 0;
}
Issue Description
When using the
minio-cpp
SDK in a C++ application, we encountered an issue where the SDK, which relies oncurlpp
for HTTP requests, fails to connect to a MinIO server if TLS (SSL) is not configured. The problem arises becausecurlpp
forces the connection to use TLS, and without a proper certificate setup, the connection either fails silently or provides uninformative error messages.Root Cause:
The
curlpp
library enforces TLS by default, causing the connection to fail when attempting to connect to a MinIO server over HTTP without SSL. This results in issues where no meaningful error message is returned, making debugging difficult. When attempting to connect without SSL,curlpp
still expects SSL-related configurations, leading to connection failures.Solution
Steps Taken:
Generate Self-Signed Certificates:
Docker Setup with Self-Signed Certificates:
docker-compose.yml
Testing with
awscurl
:awscurl
tool to test the connection with AWS Signature Version 4, ensuring that the self-signed certificates were correctly handled.C++ Application Configuration:
Step-by-Step Guide
1. Generate and Install Self-Signed Certificates
Open Command Prompt as Administrator:
This ensures that you have the necessary permissions to generate the files in the desired directory.
Navigate to the MinIO Directory:
Generate the Private Key:
Generate the Self-Signed Certificate:
Verify the Generated Files:
Ensure you have two files in
C:\Tools\minio
:private.key
: The private key for SSL.public.crt
: The public certificate for SSL.2. Add the Self-Signed Certificate to Trusted Certificates
Windows:
Install the Certificate:
public.crt
file.Add the Certificate to the Python Certificate Store:
public.crt
content to thecacert.pem
file located atC:\Python\Python312\Lib\site-packages\certifi\cacert.pem
.3. Testing the Setup
Install
awscurl
:Make Requests Using
awscurl
:Example Code
Here’s an example of how the code was adapted to work with the configured SSL setup:
Conclusion
By generating self-signed certificates, configuring Docker for SSL, and updating the C++ application to correctly handle SSL connections, we were able to overcome the limitations imposed by
curlpp
when using theminio-cpp
SDK. This solution ensures that the connection works seamlessly with SSL, providing better security and error handling during development.