package main
import (
"fmt"
"net/http"
)
func main() {
// Making an HTTPS GET request to the endpoint
url := "https://git.home.lab"
resp, err := http.Get(url)
if err != nil {
fmt.Printf("Error making GET request: %v\n", err)
return
}
defer resp.Body.Close()
// Print the response status to confirm the request was successful
fmt.Printf("Request succeeded with status code: %d\n", resp.StatusCode)
}
The standard librasy supports the SSL_CERT_FILE and SSL_CERT_DIR environment variables to specify the location of the CA certificate file or directory.
If the SSL_CERT_FILE is set, the http.Get function will use the CA certificate file to verify the server's certificate.
If the SSL_CERT_DIR is set, the http.Get function will use the CA certificate files in the directory to verify the server's certificate.
Test using the SSL_CERT_FILE environment variable
Request without the env var set
flamarion@wandb-local:~/go-http-client$ go run main2.go
Error making GET request: Get "https://git.home.lab": tls: failed to verify certificate: x509: certificate signed by unknown authority
Request with the env var set
flamarion@wandb-local:~/go-http-client$ export SSL_CERT_FILE=$(realpath root-ca.crt)
flamarion@wandb-local:~/go-http-client$ go run main2.go
Request succeeded with status code: 200
Test using the SSL_CERT_DIR environment variable
Request without the env var set
flamarion@wandb-local:~/go-http-client$ go run main2.go
Error making GET request: Get "https://git.home.lab": tls: failed to verify certificate: x509: certificate signed by unknown authority
Request with the env var set
flamarion@wandb-local:~/go-http-client$ mkdir certs
flamarion@wandb-local:~/go-http-client$ mv root-ca.crt intermediate-ca.crt certs/
flamarion@wandb-local:~/go-http-client$ export SSL_CERT_DIR=./certs
flamarion@wandb-local:~/go-http-client$ go run main2.go
Request succeeded with status code: 200
Making docker container using the same base images used by operator to validate the requests
# Build the manager binary
FROM golang:1.20 AS manager-builder
ARG TARGETOS
ARG TARGETARCH
WORKDIR /workspace
COPY main.go main.go
# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
FROM gcr.io/distroless/static-debian11
COPY --from=manager-builder /workspace/manager .
ENTRYPOINT ["/manager"]
flamarion@wandb-local:~/go-http-client$ docker run --rm manager:v0.1
Error making GET request: Get "https://git.home.lab": tls: failed to verify certificate: x509: certificate signed by unknown authority
Run the container with the SSL_CERT_FILE env var set
flamarion@wandb-local:~/go-http-client$ docker run --rm -e SSL_CERT_FILE=/certs/root-ca.crt -v ./certs/root-ca.crt:/certs/root-ca.crt manager:v0.1
Request succeeded with status code: 200
Run the container with the SSL_CERT_DIR env var set
flamarion@wandb-local:~/go-http-client$ docker run --rm -e SSL_CERT_DIR=/certs -v ./certs:/certs manager:v0.1
Request succeeded with status code: 200
Go http client to test the requests
The standard librasy supports the
SSL_CERT_FILE
andSSL_CERT_DIR
environment variables to specify the location of the CA certificate file or directory. If theSSL_CERT_FILE
is set, thehttp.Get
function will use the CA certificate file to verify the server's certificate. If theSSL_CERT_DIR
is set, thehttp.Get
function will use the CA certificate files in the directory to verify the server's certificate.Test using the
SSL_CERT_FILE
environment variableRequest without the env var set
Request with the env var set
Test using the
SSL_CERT_DIR
environment variableRequest without the env var set
Request with the env var set
Making docker container using the same base images used by operator to validate the requests
Build the container
Run the container without the env var set
Run the container with the
SSL_CERT_FILE
env var setRun the container with the
SSL_CERT_DIR
env var set------- helm tests ----
Content of
values.yaml
Upgrade the deployment
Check the deployment