Skip to content

Commit 8aaaac4

Browse files
committed
feat: use HTTPS endpoints for metalctl
we need to put the CA data into an env var to later access metal-api. So we run cert generation on before calling the requested make target if certs are not generated yet. Signed-off-by: Benjamin Ritter <benjamin.ritter@x-cellent.com>
1 parent e314aae commit 8aaaac4

4 files changed

Lines changed: 50 additions & 26 deletions

File tree

Makefile

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1+
# runs at parse time on every invocation: ensure certs exist, then (re)generate .env
2+
$(shell [ -f files/certs/ca.pem ] || ./scripts/gen-certs.sh)
3+
$(shell ./env.sh 1>&2)
4+
-include .env
5+
16
.DEFAULT_GOAL := up
27
.EXPORT_ALL_VARIABLES:
38

4-
-include .env
9+
# disable built-in implicit rules (e.g. the "%: %.sh" rule that silently turns a
10+
# stray/misspelled prerequisite into a junk executable instead of erroring out)
11+
MAKEFLAGS += --no-builtin-rules
12+
.SUFFIXES:
513

614
# Commands
715
YQ=docker run --rm -i -v $(shell pwd):/workdir mikefarah/yq:4
816

917
KINDCONFIG := $(or $(KINDCONFIG),control-plane/kind.yaml)
1018
KUBECONFIG := $(shell pwd)/.kubeconfig
1119

12-
METALCTL_HMAC := $(or $(METALCTL_HMAC),metal-admin)
13-
METALCTL_API_URL := $(or $(METALCTL_API_URL),http://api.172.42.0.42.nip.io:8080/metal)
14-
METAL_APIV2_URL := $(or $(METAL_APIV2_URL),http://v2.172.42.0.42.nip.io:8080)
15-
1620
MKE2FS_CONFIG := $(shell pwd)/mke2fs.conf
1721
# Default values
1822
CONTAINERLAB=$(shell which containerlab)
@@ -80,7 +84,7 @@ COMPOSE_ARGS += $(if $(MINI_LAB_HELM_CHARTS),-f compose.dev/helm-charts.yaml)
8084
endif
8185

8286
.PHONY: up
83-
up: env gen-certs verify-deployment-image control-plane-bake partition-bake
87+
up: gen-certs verify-deployment-image control-plane-bake partition-bake
8488
@chmod 600 files/ssh/id_ed25519
8589
docker compose $(COMPOSE_ARGS) up --pull=always --abort-on-container-failure --remove-orphans --force-recreate control-plane partition
8690
@$(MAKE) --no-print-directory start-machines
@@ -98,23 +102,12 @@ restart: down up
98102
.PHONY: down
99103
down: cleanup
100104

101-
.PHONY: gen-certs
102-
gen-certs:
103-
@if ! [ -f "files/certs/ca.pem" ]; then \
104-
echo "certificate generation required, running cfssl container"; \
105-
docker run --rm \
106-
--user $$(id -u):$$(id -g) \
107-
--entrypoint bash \
108-
-v ${PWD}:/work \
109-
cfssl/cfssl /work/scripts/roll_certs.sh; fi
110-
111105
.PHONY: roll-certs
112106
roll-certs:
113-
rm files/certs/ca.pem
114-
$(MAKE) gen-certs
107+
./scripts/gen-certs.sh
115108

116109
.PHONY: control-plane
117-
control-plane: control-plane-bake env
110+
control-plane: control-plane-bake
118111
docker compose $(COMPOSE_ARGS) up --remove-orphans --force-recreate control-plane
119112

120113
.PHONY: create-proxy-registries
@@ -152,7 +145,7 @@ endif
152145
./scripts/deactivate_offloading.sh; fi
153146

154147
.PHONY: verify-deployment-image
155-
verify-deployment-image: env
148+
verify-deployment-image:
156149
@if which cosign 1> /dev/null 2> /dev/null; then \
157150
echo -e "\033[0;32mcosign is installed, verifying deployment base image\033[0m" && \
158151
. ./.env && cosign verify --key files/cosign.pub ghcr.io/metal-stack/metal-deployment-base:$$DEPLOYMENT_BASE_IMAGE_TAG; \
@@ -178,9 +171,14 @@ external_network:
178171
sudo ip -6 route add 2001:db8:0:113::/64 via 2001:db8:0:1::1 dev mini_lab_ext; \
179172
fi
180173

181-
.PHONY: env
182-
env:
183-
@./env.sh
174+
files/certs/ca.pem:
175+
@./scripts/gen-certs.sh
176+
177+
.env: files/certs/ca.pem
178+
@./env.sh 1>&2
179+
180+
.PHONY: gen-certs # keep as a convenience alias
181+
gen-certs: files/certs/ca.pem
184182

185183
.PHONY: cleanup
186184
cleanup: cleanup-control-plane cleanup-partition
@@ -202,7 +200,7 @@ cleanup-partition:
202200
docker network rm --force mini_lab_ext
203201

204202
.PHONY: _privatenet
205-
_privatenet: env
203+
_privatenet:
206204
docker compose run $(DOCKER_COMPOSE_RUN_ARG) metalctl network list --name user-private-network | grep user-private-network || docker compose run $(DOCKER_COMPOSE_RUN_ARG) metalctl network allocate --partition mini-lab --project 00000000-0000-0000-0000-000000000001 --name user-private-network
207205

208206
.PHONY: update-userdata
@@ -245,7 +243,7 @@ public-ipv6:
245243
@docker compose run $(DOCKER_COMPOSE_RUN_ARG) metalctl network ip create --name test --network internet-mini-lab --project 00000000-0000-0000-0000-000000000001 --addressfamily IPv6 -o template --template "{{ .ipaddress }}"
246244

247245
.PHONY: ls
248-
ls: env
246+
ls:
249247
docker compose run $(DOCKER_COMPOSE_RUN_ARG) metalctl machine ls
250248

251249
## SWITCH MANAGEMENT ##
@@ -351,7 +349,7 @@ console-machine04:
351349
@$(MAKE) --no-print-directory _console VM=machine04
352350

353351
.PHONY: _password
354-
_password: env
352+
_password:
355353
docker compose run $(DOCKER_COMPOSE_RUN_ARG) metalctl machine consolepassword $(MACHINE_UUID)
356354

357355
.PHONY: password-machine01
@@ -440,6 +438,7 @@ dev-env:
440438
@echo "export METALCTL_HMAC=${METALCTL_HMAC}"
441439
@echo "export METAL_APIV2_URL=${METAL_APIV2_URL}"
442440
@echo "export KUBECONFIG=$(KUBECONFIG)"
441+
@echo "export METALCTL_CERTIFICATE_AUTHORITY_DATA=$(METALCTL_CERTIFICATE_AUTHORITY_DATA)"
443442

444443
build-dell-sonic:
445444
if [ ! -f "sonic-vs.img" ]; then \

compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ services:
5353
environment:
5454
- METALCTL_HMAC=${METALCTL_HMAC}
5555
- METALCTL_API_URL=${METALCTL_API_URL}
56+
- METALCTL_CERTIFICATE_AUTHORITY_DATA=${METALCTL_CERTIFICATE_AUTHORITY_DATA}
5657
- METALCTL_HMAC_AUTH_TYPE=${METALCTL_HMAC_AUTH_TYPE:-Metal-Admin}
5758
volumes:
5859
- ./files/ssh:/root/.ssh:ro

env.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,10 @@ CI=${CI:=false}
2525
DOCKER_HUB_USER=${DOCKER_HUB_USER:=}
2626
DOCKER_HUB_TOKEN=${DOCKER_HUB_TOKEN:=}
2727
KIND_EXPERIMENTAL_DOCKER_NETWORK=${MINI_LAB_INTERNAL_NETWORK:=mini_lab_internal}
28+
29+
METALCTL_HMAC=${METALCTL_HMAC:=metal-admin}
30+
METALCTL_API_URL=${METALCTL_API_URL:=https://api.172.42.0.42.nip.io/metal}
31+
METALCTL_CERTIFICATE_AUTHORITY_DATA=${METALCTL_CERTIFICATE_AUTHORITY_DATA:=$(cat files/certs/ca.pem | base64 -w0)}
32+
33+
METAL_APIV2_URL=${METAL_APIV2_URL:=http://v2.172.42.0.42.nip.io}
2834
EOF

scripts/gen-certs.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
3+
# Generates the mini-lab TLS certificates by running the cfssl container, which
4+
# in turn executes scripts/roll_certs.sh inside it. All output goes to stderr so
5+
# this can be called safely from $(shell ...) / recipes that capture stdout.
6+
7+
set -eo pipefail
8+
9+
# resolve the repo root (parent of this script's dir) so we work from any cwd
10+
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
11+
12+
echo "certificate generation required, running cfssl container" >&2
13+
14+
docker run --rm \
15+
--user "$(id -u):$(id -g)" \
16+
--entrypoint bash \
17+
-v "${repo_root}:/work" \
18+
cfssl/cfssl /work/scripts/roll_certs.sh 1>&2

0 commit comments

Comments
 (0)