Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Docker rootless #451

Merged
merged 18 commits into from
Aug 27, 2024
Merged
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
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ OPTIONS:=" arm64 no-secty app-sample zero-trust " # Must have spaces around word
# This tool now only supports compose V2, aka "docker compose" as it has replaced to old docker-compose tool.
DOCKER_COMPOSE=docker compose

# Resolve user ID for rootless docker port mapping
export USERID:=$(shell id -u)

# Set default rootful docker socket path
export DOCKER_SOCKET_PATH=/var/run/docker.sock

ifeq (arm64, $(filter arm64,$(ARGS)))
ARM64=-arm64
ARM64_OPTION=arm64
Expand All @@ -52,6 +58,9 @@ endef
.PHONY: $(OPTIONS)

portainer:
@if [ -e /run/user/${USERID}/docker.sock ]; then \
export DOCKER_SOCKET_PATH=/run/user/${USERID}/docker.sock; \
fi
${DOCKER_COMPOSE} -p portainer -f docker-compose-portainer.yml up -d

portainer-down:
Expand Down
32 changes: 27 additions & 5 deletions compose-builder/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ BUS=
NANOMQ=
REGISTRY=

# Resolve user ID for rootless docker port mapping
export USERID:=$(shell id -u)

# Set default rootful docker socket path
export DOCKER_SOCKET_PATH=/var/run/docker.sock

# Get total system memory in megabytes for vault config
export TOTAL_SYSTEM_MEMORY:=$(shell grep MemTotal /proc/meminfo | awk '{print $$2}')m

BROKER_YAML=add-mqtt-broker-mosquitto.yml
TAF_BROKER_YAML=add-taf-mqtt-broker-mosquitto.yml

Expand Down Expand Up @@ -132,11 +141,19 @@ ifeq (keeper, $(filter keeper,$(ARGS)))
endif
endif

# When in delay-start mode, we have to make sure support serivces be delayed-start-compliant: i.e. the runtime-token configuration be added etc..
ifeq (delayed-start, $(filter delayed-start,$(ARGS)))
ext_file_sup_notif:= $(shell ZERO_TRUST="$(MAKE_ZERO_TRUST)" GEN_EXT_DIR="$(GEN_EXT_DIR)" ./gen_runtime_token_config_compose_ext.sh support-notifications)
ext_file_sup_sch:= $(shell ZERO_TRUST="$(MAKE_ZERO_TRUST)" GEN_EXT_DIR="$(GEN_EXT_DIR)" ./gen_runtime_token_config_compose_ext.sh support-scheduler)
COMPOSE_FILES:=$(COMPOSE_FILES) -f $(ext_file_sup_notif) -f $(ext_file_sup_sch)
# When in delay-start mode, ensure support services are delay-start-compliant by adding runtime-token configuration
ifeq (delayed-start,$(filter delayed-start,$(ARGS)))
# Ensure Docker is running rootless, as security-spire-agent runs only in Docker rootless mode
ifneq (,$(wildcard /run/user/$(USERID)/docker.sock))
export DOCKER_SOCKET_PATH := /run/user/$(USERID)/docker.sock
endif

# Generate runtime token config for support services
ext_file_sup_notif := $(shell ZERO_TRUST="$(MAKE_ZERO_TRUST)" GEN_EXT_DIR="$(GEN_EXT_DIR)" ./gen_runtime_token_config_compose_ext.sh support-notifications)
ext_file_sup_sch := $(shell ZERO_TRUST="$(MAKE_ZERO_TRUST)" GEN_EXT_DIR="$(GEN_EXT_DIR)" ./gen_runtime_token_config_compose_ext.sh support-scheduler)

# Add generated config files to COMPOSE_FILES
COMPOSE_FILES += -f $(ext_file_sup_notif) -f $(ext_file_sup_sch)
endif

# Add Device Services
Expand Down Expand Up @@ -1060,6 +1077,11 @@ help:
echo "See README.md in this folder"

portainer:
@if [ ! -e /run/user/${USERID}/docker.sock ]; then \
echo "Error: Docker socket not found at /run/user/${USERID}/docker.sock"; \
echo "Please ensure Docker is running rootless."; \
exit 1; \
fi
make -C ${RELEASE_FOLDER} portainer

portainer-down:
Expand Down
2 changes: 1 addition & 1 deletion compose-builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ Usage: make <target> where target is:
#### Portainer

```
portainer Runs Portainer independent of the EdgeX services
portainer Runs Portainer independent of the EdgeX services.
portainer-down Stops Portainer independent of the EdgeX services
```
#### Build
Expand Down
2 changes: 1 addition & 1 deletion compose-builder/add-delayed-start-services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ services:
- spire-ca:/srv/spiffe/ca
- spire-agent:/srv/spiffe/agent
- /tmp/edgex/secrets/spiffe:/tmp/edgex/secrets/spiffe:z
- /var/run/docker.sock:/var/run/docker.sock
- ${DOCKER_SOCKET_PATH}:/var/run/docker.sock
depends_on:
- security-spire-server
pid: host
Expand Down
22 changes: 19 additions & 3 deletions compose-builder/add-security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,34 @@ services:
- edgex-network
ports:
- "127.0.0.1:8200:8200"
cap_add:
- "IPC_LOCK"
deploy:
resources:
limits:
memory: "${TOTAL_SYSTEM_MEMORY}"
memswap_limit: "${TOTAL_SYSTEM_MEMORY}"
tmpfs:
- /vault/config
entrypoint: ["/edgex-init/vault_wait_install.sh"]
entrypoint: [ "/edgex-init/vault_wait_install.sh" ]
env_file:
- common-sec-stage-gate.env
command: server
environment:
VAULT_ADDR: http://edgex-vault:8200
VAULT_CONFIG_DIR: /vault/config
VAULT_UI: "true"
SKIP_SETCAP: "true"
VAULT_LOCAL_CONFIG: |
listener "tcp" {
address = "edgex-vault:8200"
tls_disable = "1"
cluster_address = "edgex-vault:8201"
}
backend "file" {
path = "/vault/file"
}
default_lease_ttl = "168h"
max_lease_ttl = "720h"
disable_mlock = true
volumes:
- edgex-init:/edgex-init:ro
- vault-file:/vault/file
Expand Down
9 changes: 7 additions & 2 deletions docker-compose-arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1293,19 +1293,22 @@ services:
bind:
create_host_path: true
vault:
cap_add:
- IPC_LOCK
command:
- server
container_name: edgex-vault
depends_on:
security-bootstrapper:
condition: service_started
required: true
deploy:
resources:
limits:
memory: "34032716873728"
entrypoint:
- /edgex-init/vault_wait_install.sh
environment:
PROXY_SETUP_HOST: edgex-security-proxy-setup
SKIP_SETCAP: "true"
STAGEGATE_BOOTSTRAPPER_HOST: edgex-security-bootstrapper
STAGEGATE_BOOTSTRAPPER_STARTPORT: "54321"
STAGEGATE_DATABASE_HOST: edgex-redis
Expand All @@ -1321,9 +1324,11 @@ services:
STAGEGATE_WAITFOR_TIMEOUT: 60s
VAULT_ADDR: http://edgex-vault:8200
VAULT_CONFIG_DIR: /vault/config
VAULT_LOCAL_CONFIG: "listener \"tcp\" { \n address = \"edgex-vault:8200\" \n tls_disable = \"1\" \n cluster_address = \"edgex-vault:8201\" \n} \nbackend \"file\" {\n path = \"/vault/file\"\n}\ndefault_lease_ttl = \"168h\" \nmax_lease_ttl = \"720h\"\ndisable_mlock = true\n"
VAULT_UI: "true"
hostname: edgex-vault
image: hashicorp/vault:1.14
memswap_limit: "34032716873728"
networks:
edgex-network: null
ports:
Expand Down
2 changes: 1 addition & 1 deletion docker-compose-portainer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ services:
restart: always
command: -H unix:///var/run/docker.sock
volumes:
- /var/run/docker.sock:/var/run/docker.sock:z
- ${DOCKER_SOCKET_PATH}:/var/run/docker.sock
- portainer_data:/data

9 changes: 7 additions & 2 deletions docker-compose-with-app-sample-arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1370,19 +1370,22 @@ services:
bind:
create_host_path: true
vault:
cap_add:
- IPC_LOCK
command:
- server
container_name: edgex-vault
depends_on:
security-bootstrapper:
condition: service_started
required: true
deploy:
resources:
limits:
memory: "34032716873728"
entrypoint:
- /edgex-init/vault_wait_install.sh
environment:
PROXY_SETUP_HOST: edgex-security-proxy-setup
SKIP_SETCAP: "true"
STAGEGATE_BOOTSTRAPPER_HOST: edgex-security-bootstrapper
STAGEGATE_BOOTSTRAPPER_STARTPORT: "54321"
STAGEGATE_DATABASE_HOST: edgex-redis
Expand All @@ -1398,9 +1401,11 @@ services:
STAGEGATE_WAITFOR_TIMEOUT: 60s
VAULT_ADDR: http://edgex-vault:8200
VAULT_CONFIG_DIR: /vault/config
VAULT_LOCAL_CONFIG: "listener \"tcp\" { \n address = \"edgex-vault:8200\" \n tls_disable = \"1\" \n cluster_address = \"edgex-vault:8201\" \n} \nbackend \"file\" {\n path = \"/vault/file\"\n}\ndefault_lease_ttl = \"168h\" \nmax_lease_ttl = \"720h\"\ndisable_mlock = true\n"
VAULT_UI: "true"
hostname: edgex-vault
image: hashicorp/vault:1.14
memswap_limit: "34032716873728"
networks:
edgex-network: null
ports:
Expand Down
9 changes: 7 additions & 2 deletions docker-compose-with-app-sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1370,19 +1370,22 @@ services:
bind:
create_host_path: true
vault:
cap_add:
- IPC_LOCK
command:
- server
container_name: edgex-vault
depends_on:
security-bootstrapper:
condition: service_started
required: true
deploy:
resources:
limits:
memory: "34032716873728"
entrypoint:
- /edgex-init/vault_wait_install.sh
environment:
PROXY_SETUP_HOST: edgex-security-proxy-setup
SKIP_SETCAP: "true"
STAGEGATE_BOOTSTRAPPER_HOST: edgex-security-bootstrapper
STAGEGATE_BOOTSTRAPPER_STARTPORT: "54321"
STAGEGATE_DATABASE_HOST: edgex-redis
Expand All @@ -1398,9 +1401,11 @@ services:
STAGEGATE_WAITFOR_TIMEOUT: 60s
VAULT_ADDR: http://edgex-vault:8200
VAULT_CONFIG_DIR: /vault/config
VAULT_LOCAL_CONFIG: "listener \"tcp\" { \n address = \"edgex-vault:8200\" \n tls_disable = \"1\" \n cluster_address = \"edgex-vault:8201\" \n} \nbackend \"file\" {\n path = \"/vault/file\"\n}\ndefault_lease_ttl = \"168h\" \nmax_lease_ttl = \"720h\"\ndisable_mlock = true\n"
VAULT_UI: "true"
hostname: edgex-vault
image: hashicorp/vault:1.14
memswap_limit: "34032716873728"
networks:
edgex-network: null
ports:
Expand Down
9 changes: 7 additions & 2 deletions docker-compose-zero-trust-arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1124,19 +1124,22 @@ services:
selinux: z
create_host_path: true
vault:
cap_add:
- IPC_LOCK
command:
- server
container_name: edgex-vault
depends_on:
security-bootstrapper:
condition: service_started
required: true
deploy:
resources:
limits:
memory: "34032716873728"
entrypoint:
- /edgex-init/vault_wait_install.sh
environment:
PROXY_SETUP_HOST: edgex-security-proxy-setup
SKIP_SETCAP: "true"
STAGEGATE_BOOTSTRAPPER_HOST: edgex-security-bootstrapper
STAGEGATE_BOOTSTRAPPER_STARTPORT: "54321"
STAGEGATE_DATABASE_HOST: edgex-redis
Expand All @@ -1152,9 +1155,11 @@ services:
STAGEGATE_WAITFOR_TIMEOUT: 60s
VAULT_ADDR: http://edgex-vault:8200
VAULT_CONFIG_DIR: /vault/config
VAULT_LOCAL_CONFIG: "listener \"tcp\" { \n address = \"edgex-vault:8200\" \n tls_disable = \"1\" \n cluster_address = \"edgex-vault:8201\" \n} \nbackend \"file\" {\n path = \"/vault/file\"\n}\ndefault_lease_ttl = \"168h\" \nmax_lease_ttl = \"720h\"\ndisable_mlock = true\n"
VAULT_UI: "true"
hostname: edgex-vault
image: hashicorp/vault:1.14
memswap_limit: "34032716873728"
networks:
edgex-network: null
ports:
Expand Down
9 changes: 7 additions & 2 deletions docker-compose-zero-trust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1124,19 +1124,22 @@ services:
selinux: z
create_host_path: true
vault:
cap_add:
- IPC_LOCK
command:
- server
container_name: edgex-vault
depends_on:
security-bootstrapper:
condition: service_started
required: true
deploy:
resources:
limits:
memory: "34032716873728"
entrypoint:
- /edgex-init/vault_wait_install.sh
environment:
PROXY_SETUP_HOST: edgex-security-proxy-setup
SKIP_SETCAP: "true"
STAGEGATE_BOOTSTRAPPER_HOST: edgex-security-bootstrapper
STAGEGATE_BOOTSTRAPPER_STARTPORT: "54321"
STAGEGATE_DATABASE_HOST: edgex-redis
Expand All @@ -1152,9 +1155,11 @@ services:
STAGEGATE_WAITFOR_TIMEOUT: 60s
VAULT_ADDR: http://edgex-vault:8200
VAULT_CONFIG_DIR: /vault/config
VAULT_LOCAL_CONFIG: "listener \"tcp\" { \n address = \"edgex-vault:8200\" \n tls_disable = \"1\" \n cluster_address = \"edgex-vault:8201\" \n} \nbackend \"file\" {\n path = \"/vault/file\"\n}\ndefault_lease_ttl = \"168h\" \nmax_lease_ttl = \"720h\"\ndisable_mlock = true\n"
VAULT_UI: "true"
hostname: edgex-vault
image: hashicorp/vault:1.14
memswap_limit: "34032716873728"
networks:
edgex-network: null
ports:
Expand Down
9 changes: 7 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1293,19 +1293,22 @@ services:
bind:
create_host_path: true
vault:
cap_add:
- IPC_LOCK
command:
- server
container_name: edgex-vault
depends_on:
security-bootstrapper:
condition: service_started
required: true
deploy:
resources:
limits:
memory: "34032716873728"
entrypoint:
- /edgex-init/vault_wait_install.sh
environment:
PROXY_SETUP_HOST: edgex-security-proxy-setup
SKIP_SETCAP: "true"
STAGEGATE_BOOTSTRAPPER_HOST: edgex-security-bootstrapper
STAGEGATE_BOOTSTRAPPER_STARTPORT: "54321"
STAGEGATE_DATABASE_HOST: edgex-redis
Expand All @@ -1321,9 +1324,11 @@ services:
STAGEGATE_WAITFOR_TIMEOUT: 60s
VAULT_ADDR: http://edgex-vault:8200
VAULT_CONFIG_DIR: /vault/config
VAULT_LOCAL_CONFIG: "listener \"tcp\" { \n address = \"edgex-vault:8200\" \n tls_disable = \"1\" \n cluster_address = \"edgex-vault:8201\" \n} \nbackend \"file\" {\n path = \"/vault/file\"\n}\ndefault_lease_ttl = \"168h\" \nmax_lease_ttl = \"720h\"\ndisable_mlock = true\n"
VAULT_UI: "true"
hostname: edgex-vault
image: hashicorp/vault:1.14
memswap_limit: "34032716873728"
networks:
edgex-network: null
ports:
Expand Down
9 changes: 7 additions & 2 deletions taf/docker-compose-taf-arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2331,19 +2331,22 @@ services:
bind:
create_host_path: true
vault:
cap_add:
- IPC_LOCK
command:
- server
container_name: edgex-vault
depends_on:
security-bootstrapper:
condition: service_started
required: true
deploy:
resources:
limits:
memory: "34032716873728"
entrypoint:
- /edgex-init/vault_wait_install.sh
environment:
PROXY_SETUP_HOST: edgex-security-proxy-setup
SKIP_SETCAP: "true"
STAGEGATE_BOOTSTRAPPER_HOST: edgex-security-bootstrapper
STAGEGATE_BOOTSTRAPPER_STARTPORT: "54321"
STAGEGATE_DATABASE_HOST: edgex-redis
Expand All @@ -2359,9 +2362,11 @@ services:
STAGEGATE_WAITFOR_TIMEOUT: 60s
VAULT_ADDR: http://edgex-vault:8200
VAULT_CONFIG_DIR: /vault/config
VAULT_LOCAL_CONFIG: "listener \"tcp\" { \n address = \"edgex-vault:8200\" \n tls_disable = \"1\" \n cluster_address = \"edgex-vault:8201\" \n} \nbackend \"file\" {\n path = \"/vault/file\"\n}\ndefault_lease_ttl = \"168h\" \nmax_lease_ttl = \"720h\"\ndisable_mlock = true\n"
VAULT_UI: "true"
hostname: edgex-vault
image: hashicorp/vault:1.14
memswap_limit: "34032716873728"
networks:
edgex-network: null
ports:
Expand Down
Loading