feat(mosaic-portainer): add PORTAINER_INSECURE flag for self-signed TLS
Self-signed Portainer instances (e.g. internal LAN at 10.1.1.43:9443) caused all wrapper calls to fail silently with HTTP 000. Setting PORTAINER_INSECURE=1 passes -k to curl, bypassing certificate verification and unblocking API calls to such instances. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -13,6 +13,14 @@ export PORTAINER_URL="https://portainer.example.com:9443"
|
|||||||
export PORTAINER_API_KEY="your-api-key-here"
|
export PORTAINER_API_KEY="your-api-key-here"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If your Portainer instance uses a self-signed TLS certificate (e.g. internal LAN), set:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export PORTAINER_INSECURE=1
|
||||||
|
```
|
||||||
|
|
||||||
|
This passes `-k` to all curl calls, bypassing certificate verification. Do not set this against public/production instances.
|
||||||
|
|
||||||
You can add these to your shell profile (`~/.bashrc`, `~/.zshrc`) or use a `.env` file.
|
You can add these to your shell profile (`~/.bashrc`, `~/.zshrc`) or use a `.env` file.
|
||||||
|
|
||||||
### Creating an API Key
|
### Creating an API Key
|
||||||
|
|||||||
@@ -46,8 +46,14 @@ fi
|
|||||||
# Remove trailing slash from URL
|
# Remove trailing slash from URL
|
||||||
PORTAINER_URL="${PORTAINER_URL%/}"
|
PORTAINER_URL="${PORTAINER_URL%/}"
|
||||||
|
|
||||||
|
# TLS options
|
||||||
|
CURL_OPTS=()
|
||||||
|
if [ "${PORTAINER_INSECURE:-0}" = "1" ]; then
|
||||||
|
CURL_OPTS+=(-k)
|
||||||
|
fi
|
||||||
|
|
||||||
# Fetch endpoints
|
# Fetch endpoints
|
||||||
response=$(curl -s -w "\n%{http_code}" \
|
response=$(curl -s "${CURL_OPTS[@]}" -w "\n%{http_code}" \
|
||||||
-H "X-API-Key: ${PORTAINER_API_KEY}" \
|
-H "X-API-Key: ${PORTAINER_API_KEY}" \
|
||||||
"${PORTAINER_URL}/api/endpoints")
|
"${PORTAINER_URL}/api/endpoints")
|
||||||
|
|
||||||
|
|||||||
@@ -52,8 +52,14 @@ fi
|
|||||||
# Remove trailing slash from URL
|
# Remove trailing slash from URL
|
||||||
PORTAINER_URL="${PORTAINER_URL%/}"
|
PORTAINER_URL="${PORTAINER_URL%/}"
|
||||||
|
|
||||||
|
# TLS options
|
||||||
|
CURL_OPTS=()
|
||||||
|
if [ "${PORTAINER_INSECURE:-0}" = "1" ]; then
|
||||||
|
CURL_OPTS+=(-k)
|
||||||
|
fi
|
||||||
|
|
||||||
# Fetch stacks
|
# Fetch stacks
|
||||||
response=$(curl -s -w "\n%{http_code}" \
|
response=$(curl -s "${CURL_OPTS[@]}" -w "\n%{http_code}" \
|
||||||
-H "X-API-Key: ${PORTAINER_API_KEY}" \
|
-H "X-API-Key: ${PORTAINER_API_KEY}" \
|
||||||
"${PORTAINER_URL}/api/stacks")
|
"${PORTAINER_URL}/api/stacks")
|
||||||
|
|
||||||
|
|||||||
@@ -64,12 +64,18 @@ fi
|
|||||||
# Remove trailing slash from URL
|
# Remove trailing slash from URL
|
||||||
PORTAINER_URL="${PORTAINER_URL%/}"
|
PORTAINER_URL="${PORTAINER_URL%/}"
|
||||||
|
|
||||||
|
# TLS options
|
||||||
|
CURL_OPTS=()
|
||||||
|
if [ "${PORTAINER_INSECURE:-0}" = "1" ]; then
|
||||||
|
CURL_OPTS+=(-k)
|
||||||
|
fi
|
||||||
|
|
||||||
# Function to make API requests
|
# Function to make API requests
|
||||||
api_request() {
|
api_request() {
|
||||||
local method="$1"
|
local method="$1"
|
||||||
local endpoint="$2"
|
local endpoint="$2"
|
||||||
|
|
||||||
curl -s -w "\n%{http_code}" -X "$method" \
|
curl -s "${CURL_OPTS[@]}" -w "\n%{http_code}" -X "$method" \
|
||||||
-H "X-API-Key: ${PORTAINER_API_KEY}" \
|
-H "X-API-Key: ${PORTAINER_API_KEY}" \
|
||||||
"${PORTAINER_URL}${endpoint}"
|
"${PORTAINER_URL}${endpoint}"
|
||||||
}
|
}
|
||||||
@@ -165,7 +171,7 @@ fi
|
|||||||
# Note: Docker API returns raw log stream, not JSON
|
# Note: Docker API returns raw log stream, not JSON
|
||||||
if [[ "$FOLLOW" == "true" ]]; then
|
if [[ "$FOLLOW" == "true" ]]; then
|
||||||
# Stream logs
|
# Stream logs
|
||||||
curl -s -N \
|
curl -s "${CURL_OPTS[@]}" -N \
|
||||||
-H "X-API-Key: ${PORTAINER_API_KEY}" \
|
-H "X-API-Key: ${PORTAINER_API_KEY}" \
|
||||||
"${PORTAINER_URL}/api/endpoints/${ENDPOINT_ID}/docker/containers/${CONTAINER_ID}/logs?${params}" | \
|
"${PORTAINER_URL}/api/endpoints/${ENDPOINT_ID}/docker/containers/${CONTAINER_ID}/logs?${params}" | \
|
||||||
# Docker log format has 8-byte header per line, strip it
|
# Docker log format has 8-byte header per line, strip it
|
||||||
@@ -175,7 +181,7 @@ if [[ "$FOLLOW" == "true" ]]; then
|
|||||||
done
|
done
|
||||||
else
|
else
|
||||||
# Get logs (non-streaming)
|
# Get logs (non-streaming)
|
||||||
curl -s \
|
curl -s "${CURL_OPTS[@]}" \
|
||||||
-H "X-API-Key: ${PORTAINER_API_KEY}" \
|
-H "X-API-Key: ${PORTAINER_API_KEY}" \
|
||||||
"${PORTAINER_URL}/api/endpoints/${ENDPOINT_ID}/docker/containers/${CONTAINER_ID}/logs?${params}" | \
|
"${PORTAINER_URL}/api/endpoints/${ENDPOINT_ID}/docker/containers/${CONTAINER_ID}/logs?${params}" | \
|
||||||
# Docker log format has 8-byte header per line, attempt to strip it
|
# Docker log format has 8-byte header per line, attempt to strip it
|
||||||
|
|||||||
@@ -63,13 +63,19 @@ fi
|
|||||||
# Remove trailing slash from URL
|
# Remove trailing slash from URL
|
||||||
PORTAINER_URL="${PORTAINER_URL%/}"
|
PORTAINER_URL="${PORTAINER_URL%/}"
|
||||||
|
|
||||||
|
# TLS options
|
||||||
|
CURL_OPTS=()
|
||||||
|
if [ "${PORTAINER_INSECURE:-0}" = "1" ]; then
|
||||||
|
CURL_OPTS+=(-k)
|
||||||
|
fi
|
||||||
|
|
||||||
# Function to make API requests
|
# Function to make API requests
|
||||||
api_request() {
|
api_request() {
|
||||||
local method="$1"
|
local method="$1"
|
||||||
local endpoint="$2"
|
local endpoint="$2"
|
||||||
local data="${3:-}"
|
local data="${3:-}"
|
||||||
|
|
||||||
local args=(-s -w "\n%{http_code}" -X "$method" -H "X-API-Key: ${PORTAINER_API_KEY}")
|
local args=(-s "${CURL_OPTS[@]}" -w "\n%{http_code}" -X "$method" -H "X-API-Key: ${PORTAINER_API_KEY}")
|
||||||
|
|
||||||
if [[ -n "$data" ]]; then
|
if [[ -n "$data" ]]; then
|
||||||
args+=(-H "Content-Type: application/json" -d "$data")
|
args+=(-H "Content-Type: application/json" -d "$data")
|
||||||
|
|||||||
@@ -54,12 +54,18 @@ fi
|
|||||||
# Remove trailing slash from URL
|
# Remove trailing slash from URL
|
||||||
PORTAINER_URL="${PORTAINER_URL%/}"
|
PORTAINER_URL="${PORTAINER_URL%/}"
|
||||||
|
|
||||||
|
# TLS options
|
||||||
|
CURL_OPTS=()
|
||||||
|
if [ "${PORTAINER_INSECURE:-0}" = "1" ]; then
|
||||||
|
CURL_OPTS+=(-k)
|
||||||
|
fi
|
||||||
|
|
||||||
# Function to make API requests
|
# Function to make API requests
|
||||||
api_request() {
|
api_request() {
|
||||||
local method="$1"
|
local method="$1"
|
||||||
local endpoint="$2"
|
local endpoint="$2"
|
||||||
|
|
||||||
curl -s -w "\n%{http_code}" -X "$method" \
|
curl -s "${CURL_OPTS[@]}" -w "\n%{http_code}" -X "$method" \
|
||||||
-H "X-API-Key: ${PORTAINER_API_KEY}" \
|
-H "X-API-Key: ${PORTAINER_API_KEY}" \
|
||||||
"${PORTAINER_URL}${endpoint}"
|
"${PORTAINER_URL}${endpoint}"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,12 +57,18 @@ fi
|
|||||||
# Remove trailing slash from URL
|
# Remove trailing slash from URL
|
||||||
PORTAINER_URL="${PORTAINER_URL%/}"
|
PORTAINER_URL="${PORTAINER_URL%/}"
|
||||||
|
|
||||||
|
# TLS options
|
||||||
|
CURL_OPTS=()
|
||||||
|
if [ "${PORTAINER_INSECURE:-0}" = "1" ]; then
|
||||||
|
CURL_OPTS+=(-k)
|
||||||
|
fi
|
||||||
|
|
||||||
# Function to make API requests
|
# Function to make API requests
|
||||||
api_request() {
|
api_request() {
|
||||||
local method="$1"
|
local method="$1"
|
||||||
local endpoint="$2"
|
local endpoint="$2"
|
||||||
|
|
||||||
curl -s -w "\n%{http_code}" -X "$method" \
|
curl -s "${CURL_OPTS[@]}" -w "\n%{http_code}" -X "$method" \
|
||||||
-H "X-API-Key: ${PORTAINER_API_KEY}" \
|
-H "X-API-Key: ${PORTAINER_API_KEY}" \
|
||||||
"${PORTAINER_URL}${endpoint}"
|
"${PORTAINER_URL}${endpoint}"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,12 +54,18 @@ fi
|
|||||||
# Remove trailing slash from URL
|
# Remove trailing slash from URL
|
||||||
PORTAINER_URL="${PORTAINER_URL%/}"
|
PORTAINER_URL="${PORTAINER_URL%/}"
|
||||||
|
|
||||||
|
# TLS options
|
||||||
|
CURL_OPTS=()
|
||||||
|
if [ "${PORTAINER_INSECURE:-0}" = "1" ]; then
|
||||||
|
CURL_OPTS+=(-k)
|
||||||
|
fi
|
||||||
|
|
||||||
# Function to make API requests
|
# Function to make API requests
|
||||||
api_request() {
|
api_request() {
|
||||||
local method="$1"
|
local method="$1"
|
||||||
local endpoint="$2"
|
local endpoint="$2"
|
||||||
|
|
||||||
curl -s -w "\n%{http_code}" -X "$method" \
|
curl -s "${CURL_OPTS[@]}" -w "\n%{http_code}" -X "$method" \
|
||||||
-H "X-API-Key: ${PORTAINER_API_KEY}" \
|
-H "X-API-Key: ${PORTAINER_API_KEY}" \
|
||||||
"${PORTAINER_URL}${endpoint}"
|
"${PORTAINER_URL}${endpoint}"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user