Skip to content

Agent Mesh

fix: restore writable persistent storage after non-root Docker migration

Antonio Ojea4f66c956ddb1
diff --git a/Dockerfile.sam-control-plane b/Dockerfile.sam-control-plane
index 16758e39..3e50494b 100644
--- a/Dockerfile.sam-control-plane
+++ b/Dockerfile.sam-control-plane
@@ -5,9 +5,14 @@ COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -buildvcs=false -o sam-control-plane ./cmd/sam-control-plane
+# Pre-create the sqlite data dir owned by the nonroot UID so that a fresh
+# named/anonymous volume mounted over it inherits writable ownership instead
+# of defaulting to root.
+RUN mkdir -p /data-seed && chown 65532:65532 /data-seed
# Stage 2: Final
FROM gcr.io/distroless/static:nonroot
COPY --from=builder --chown=nonroot:nonroot /app/sam-control-plane /
+COPY --from=builder --chown=nonroot:nonroot /data-seed /data
USER nonroot:nonroot
ENTRYPOINT ["/sam-control-plane"]
diff --git a/Dockerfile.sam-node b/Dockerfile.sam-node
index afacd439..dfda2faf 100644
--- a/Dockerfile.sam-node
+++ b/Dockerfile.sam-node
@@ -5,9 +5,14 @@ COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -buildvcs=false -o sam-node ./cmd/sam-node
+# Pre-create the default data dir owned by the nonroot UID so that a fresh
+# named/anonymous volume mounted over it inherits writable ownership instead
+# of defaulting to root.
+RUN mkdir -p /data-seed && chown 65532:65532 /data-seed
# Stage 2: Final
FROM gcr.io/distroless/static:nonroot
COPY --from=builder --chown=nonroot:nonroot /app/sam-node /
+COPY --from=builder --chown=nonroot:nonroot /data-seed /data
USER nonroot:nonroot
ENTRYPOINT ["/sam-node"]
diff --git a/Dockerfile.sam-router b/Dockerfile.sam-router
index 5cb50c78..f34f55b7 100644
--- a/Dockerfile.sam-router
+++ b/Dockerfile.sam-router
@@ -5,9 +5,14 @@ COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -buildvcs=false -o sam-router ./cmd/sam-router
+# Pre-create the keys/data dir owned by the nonroot UID so that a fresh
+# named/anonymous volume mounted over it inherits writable ownership instead
+# of defaulting to root.
+RUN mkdir -p /data-seed && chown 65532:65532 /data-seed
# Stage 2: Final
FROM gcr.io/distroless/static:nonroot
COPY --from=builder --chown=nonroot:nonroot /app/sam-router /
+COPY --from=builder --chown=nonroot:nonroot /data-seed /data
USER nonroot:nonroot
ENTRYPOINT ["/sam-router"]
diff --git a/mobile/mobile_e2e.sh b/mobile/mobile_e2e.sh
index 39e41017..72b7d42d 100755
--- a/mobile/mobile_e2e.sh
+++ b/mobile/mobile_e2e.sh
@@ -66,6 +66,9 @@ adb reverse tcp:18080 tcp:18080
# 4. Start the Control Plane and Router containers
rm -rf /tmp/control-plane-data /tmp/router-data
mkdir -p /tmp/control-plane-data /tmp/router-data
+# sam-control-plane/sam-router run as the nonroot (65532) container user, so
+# host bind mounts must be writable by that UID.
+chmod 777 /tmp/control-plane-data /tmp/router-data
docker run --name sam-control-plane \
--network sam-net \
@@ -128,6 +131,7 @@ curl -s -X POST \
# 5. Enroll and Start the External Node on Host inside Docker
rm -rf /tmp/host-node-data
mkdir -p /tmp/host-node-data
+chmod 777 /tmp/host-node-data
HOST_JWT=$(curl -s -X POST -d "grant_type=client_credentials&client_id=test-client&client_secret=test-secret" http://127.0.0.1:18080/token | jq -r .access_token)
diff --git a/site/content/docs/development/testnet-validation.md b/site/content/docs/development/testnet-validation.md
index 53e995f0..09199e11 100644
--- a/site/content/docs/development/testnet-validation.md
+++ b/site/content/docs/development/testnet-validation.md
@@ -20,6 +20,7 @@ Before starting, ensure you have:
```
And run via:
```bash
+ chmod 777 ~/.config/sam-mesh
docker run --name sam-node \
-v ~/.config/sam-mesh:/data \
-p 5001:5001/udp -p 5002:5002 -p 8080:8080 \
diff --git a/site/content/docs/quickstart.md b/site/content/docs/quickstart.md
index 1fcebf3d..4930490a 100644
--- a/site/content/docs/quickstart.md
+++ b/site/content/docs/quickstart.md
@@ -53,7 +53,7 @@ sam-node join https://bananas.sam-mesh.dev
#### Using Docker
```bash
-mkdir -p $(pwd)/sam-data
+mkdir -p $(pwd)/sam-data && chmod 777 $(pwd)/sam-data
docker run -it \
-v $(pwd)/sam-data:/data \
ghcr.io/google/sam-node:latest \
@@ -73,6 +73,7 @@ sam-node join --bootstrap-token <your-token> https://bananas.sam-mesh.dev
#### Using Docker
```bash
+mkdir -p $(pwd)/sam-data && chmod 777 $(pwd)/sam-data
docker run -it \
-v $(pwd)/sam-data:/data \
ghcr.io/google/sam-node:latest \
@@ -101,6 +102,7 @@ PeerID: 12D3KooW...
### Using Docker
Map the required ports (`5001/udp`, `5002/tcp` for libp2p, and `8080/tcp` for the local API):
```bash
+mkdir -p $(pwd)/sam-data && chmod 777 $(pwd)/sam-data
docker run -d \
--name sam-node \
-v $(pwd)/sam-data:/data \
diff --git a/tests/e2e/auth_flows.bats b/tests/e2e/auth_flows.bats
index 5fca57e1..fae083da 100644
--- a/tests/e2e/auth_flows.bats
+++ b/tests/e2e/auth_flows.bats
@@ -49,9 +49,9 @@ teardown() {
docker run --name "${node_name}-join" \
--network "${MESH_NETWORK}" \
$(mesh_get_add_hosts) \
- -v "${data_vol}:/root/.config/sam-mesh" \
+ -v "${data_vol}:/data" \
"sam-node:local" \
- join "http://sam-control-plane:8080" > "/tmp/${node_name}-join.out" 2>&1 &
+ join --data-dir /data "http://sam-control-plane:8080" > "/tmp/${node_name}-join.out" 2>&1 &
local join_pid=$!
MESH_CONTAINERS+=("${node_name}-join")
@@ -93,9 +93,10 @@ teardown() {
--name "${node_name}" \
--network "${MESH_NETWORK}" \
$(mesh_get_add_hosts) \
- -v "${data_vol}:/root/.config/sam-mesh" \
+ -v "${data_vol}:/data" \
"sam-node:local" \
run \
+ --data-dir /data \
--hub "http://sam-hub:9090"
MESH_CONTAINERS+=("${node_name}")
@@ -190,18 +191,19 @@ teardown() {
docker run --name "${node_name}-join" \
--network "${MESH_NETWORK}" \
$(mesh_get_add_hosts) \
- -v "${data_vol}:/root/.config/sam-mesh" \
+ -v "${data_vol}:/data" \
"sam-node:local" \
- join --bootstrap-token "${node_token}" "http://sam-control-plane:8080"
+ join --data-dir /data --bootstrap-token "${node_token}" "http://sam-control-plane:8080"
# 3. Start the node container with stored identity
docker run -d \
--name "${node_name}" \
--network "${MESH_NETWORK}" \
$(mesh_get_add_hosts) \
- -v "${data_vol}:/root/.config/sam-mesh" \
+ -v "${data_vol}:/data" \
"sam-node:local" \
run \
+ --data-dir /data \
--hub "http://sam-control-plane:8080"
MESH_CONTAINERS+=("${node_name}")