Skip to content

Commit f04041c

Browse files
committed
store/keychain(ci): linux default keychain collection
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
1 parent 47441b7 commit f04041c

6 files changed

Lines changed: 253 additions & 21 deletions

File tree

.github/workflows/keychain.yml

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,77 @@ on:
99
paths:
1010
- 'store/**'
1111
jobs:
12-
tests:
13-
name: KeychainTests
12+
linux-keychain:
13+
permissions:
14+
id-token: write
15+
contents: read
16+
name: LinuxKeychainTests
17+
runs-on: ubuntu-24.04
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
subtest:
22+
- fedora-43-gnome-keyring
23+
# - fedora-43-kdewallet
24+
- ubuntu-24-gnome-keyring
25+
# - ubuntu-24-kdewallet
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v4
29+
- name: Hub login
30+
uses: docker/login-action@v3
31+
with:
32+
username: ${{ vars.DOCKERBUILDBOT_USERNAME }}
33+
password: ${{ secrets.DOCKERBUILDBOT_WRITE_PAT }}
34+
- name: Set up Docker Buildx
35+
id: buildx
36+
uses: docker/setup-buildx-action@v3
37+
with:
38+
driver: cloud
39+
endpoint: "docker/secrets-engine"
40+
install: true
41+
- name: Test
42+
run: DOCKER_TARGET=${{ matrix.subtest }} make keychain-linux-unit-tests
43+
# tests-windows:
44+
# permissions:
45+
# id-token: write
46+
# contents: read
47+
# name: WindowsKeychainTests
48+
# runs-on: ${{ matrix.os }}
49+
# strategy:
50+
# fail-fast: false
51+
# matrix:
52+
# os:
53+
# - windows-2022
54+
# - windows-2025
55+
# steps:
56+
# - name: Checkout
57+
# uses: actions/checkout@v4
58+
# - name: Setup Go
59+
# uses: actions/setup-go@v5
60+
# with:
61+
# go-version-file: ./store/go.mod
62+
# - name: Test keychain
63+
# run: make keychain-unit-tests
64+
tests-macos:
65+
permissions:
66+
id-token: write
67+
contents: read
68+
name: MacOSKeychainTests
1469
runs-on: ${{ matrix.os }}
1570
strategy:
1671
fail-fast: false
1772
matrix:
1873
os:
19-
- ubuntu-24.04
20-
- ubuntu-22.04
2174
- macOS-15
2275
- macOS-14
2376
- macOS-13
24-
- windows-2022
25-
- windows-2025
2677
steps:
2778
- name: Checkout
2879
uses: actions/checkout@v4
2980
- name: Setup Go
3081
uses: actions/setup-go@v5
3182
with:
3283
go-version-file: ./store/go.mod
33-
- name: Install deps (ubuntu)
34-
if: startsWith(matrix.os, 'ubuntu-')
35-
run: |
36-
sudo apt-get update
37-
sudo apt-get install -y dbus-x11 gnome-keyring
3884
- name: Test keychain
3985
run: make keychain-unit-tests

Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ DOCKER_BUILD_ARGS := --build-arg GO_VERSION \
2828
--build-arg GOLANGCI_LINT_VERSION \
2929
--build-arg NRI_PLUGIN_BINARY \
3030
--build-arg BUF_VERSION \
31-
--build-arg GIT_TAG
31+
--build-arg GIT_TAG \
32+
--build-arg MAIN_MODULE_PATH
3233

3334
GO_TEST := go test
3435
ifneq ($(shell sh -c "which gotestsum 2> /dev/null"),)
@@ -54,8 +55,11 @@ clean: ## remove built binaries and packages
5455
unit-tests:
5556
CGO_ENABLED=0 go test -v -tags="gen" $$(go list ./... | grep -v /store/)
5657

58+
keychain-linux-unit-tests:
59+
@docker buildx build $(DOCKER_BUILD_ARGS) --target=$(DOCKER_TARGET) --file store/Dockerfile .
60+
5761
keychain-unit-tests:
58-
$(MAKE) -C store/ unit-tests
62+
CGO_ENABLED=1 go test -v $$(go list ./store/keychain/...)
5963

6064
nri-plugin:
6165
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -trimpath -ldflags "-s -w ${GO_LDFLAGS}" -o ./dist/$(NRI_PLUGIN_BINARY)$(EXTENSION) ./cmd/nri-plugin
@@ -81,4 +85,4 @@ help: ## Show this help
8185
@echo Please specify a build target. The choices are:
8286
@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "$(INFO_COLOR)%-30s$(NO_COLOR) %s\n", $$1, $$2}'
8387

84-
.PHONY: run bin format lint unit-tests cross x-package clean help generate docker-mcp
88+
.PHONY: run bin format lint unit-tests cross x-package clean help generate docker-mcp keychain-linux-unit-tests keychain-unit-tests

store/Dockerfile

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
ARG GO_VERSION=latest
2+
3+
FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION}-alpine AS go-base
4+
5+
FROM --platform=${BUILDPLATFORM} fedora:43 AS fedora43
6+
RUN dnf install -y gnome-keyring kf6-kwallet dbus-daemon
7+
COPY --from=go-base /usr/local/go /usr/local/go
8+
ENV PATH="/usr/local/go/bin:${PATH}"
9+
RUN useradd -ms /bin/bash user
10+
USER user
11+
WORKDIR /app
12+
RUN --mount=type=bind,target=.
13+
14+
FROM --platform=${BUILDPLATFORM} ubuntu:24.04 AS ubuntu24
15+
RUN apt update && apt install -y --no-install-recommends libglib2.0-bin dbus gnome-keyring kwalletmanager
16+
COPY --from=go-base /usr/local/go /usr/local/go
17+
ENV PATH="/usr/local/go/bin:${PATH}"
18+
RUN useradd -ms /bin/bash user
19+
USER user
20+
WORKDIR /app
21+
RUN --mount=type=bind,target=.
22+
23+
FROM fedora43 AS fedora-43-gnome-keyring
24+
ENV CGO_ENABLED=0
25+
USER user
26+
WORKDIR /app
27+
RUN --mount=type=bind,target=. \
28+
--mount=type=cache,target=/go/pkg/mod \
29+
--mount=type=cache,target=/root/.cache/go-build \
30+
/app/store/scripts/gnome-keyring \
31+
go test -v ./store/keychain/...
32+
33+
FROM fedora43 AS fedora-43-kdewallet
34+
ENV CGO_ENABLED=0
35+
USER user
36+
WORKDIR /app
37+
RUN --mount=type=bind,target=. \
38+
--mount=type=cache,target=/go/pkg/mod \
39+
--mount=type=cache,target=/root/.cache/go-build \
40+
/app/store/scripts/kdewallet \
41+
go test -v ./store/keychain/...
42+
43+
FROM ubuntu24 AS ubuntu-24-gnome-keyring
44+
ENV CGO_ENABLED=0
45+
USER user
46+
WORKDIR /app
47+
RUN --mount=type=bind,target=. \
48+
--mount=type=cache,target=/go/pkg/mod \
49+
--mount=type=cache,target=/root/.cache/go-build \
50+
/app/store/scripts/gnome-keyring \
51+
go test -v ./store/keychain/...
52+
53+
FROM ubuntu24 AS ubuntu-24-kdewallet
54+
ENV CGO_ENABLED=0
55+
USER user
56+
WORKDIR /app
57+
RUN --mount=type=bind,target=. \
58+
--mount=type=cache,target=/go/pkg/mod \
59+
--mount=type=cache,target=/root/.cache/go-build \
60+
/app/store/scripts/kdewallet \
61+
go test -v ./store/keychain/...

store/Makefile

Lines changed: 0 additions & 7 deletions
This file was deleted.

store/scripts/gnome-keyring

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/sh
2+
3+
set -eux pipefail
4+
5+
if test -z $(command -v gnome-keyring-daemon); then
6+
echo "gnome-keyring-daemon is not installed"
7+
exit 1
8+
fi
9+
10+
if test -z $(command -v busctl); then
11+
echo "busctl is not installed"
12+
exit 1
13+
fi
14+
15+
if test -z $(command -v dbus-daemon); then
16+
echo "dbus-daemon is not installed"
17+
exit 1
18+
fi
19+
20+
mkdir -p ~/.local/share/keyrings
21+
touch ~/.local/share/keyrings/login.keyring
22+
23+
# Start D-Bus session (dbus must be installed)
24+
export DBUS_SESSION_BUS_ADDRESS=$(dbus-daemon --session --print-address --fork)
25+
26+
# create fake passwordless 'login' keyring
27+
echo '[keyring]
28+
display-name=login
29+
ctime=1750965549
30+
mtime=0
31+
lock-on-idle=false
32+
lock-after=false' > ~/.local/share/keyrings/login.keyring
33+
34+
gnome-keyring-daemon --start --components=secrets
35+
36+
if [[ $(busctl --user status org.freedesktop.secrets | grep -E 'Exe') != *gnome-keyring-daemon* ]]; then
37+
echo "dbus org.freedesktop.secrets is not using gnome-keyring-daemon"
38+
exit 1
39+
fi

store/scripts/kdewallet

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/sh
2+
3+
set -eux pipefail
4+
5+
kwalletd=$(command -v kwalletd5 || command -v kwalletd6)
6+
7+
if test -z "$kwalletd"; then
8+
echo "kwalletd5 or kwalletd6 is not installed"
9+
exit 1
10+
fi
11+
12+
if test -z $(command -v busctl); then
13+
echo "busctl is not installed"
14+
exit 1
15+
fi
16+
17+
if test -z $(command -v dbus-daemon); then
18+
echo "dbus-daemon is not installed"
19+
exit 1
20+
fi
21+
22+
mkdir -p ~/.local/share/dbus-1/services
23+
touch ~/.local/share/dbus-1/services/org.freedesktop.secrets.service
24+
25+
echo "[D-BUS Service]
26+
Name=org.freedesktop.secrets
27+
Exec=${kwalletd}" > ~/.local/share/dbus-1/services/org.freedesktop.secrets.service
28+
29+
30+
mkdir -p ~/.local/share/kwalletd
31+
mkdir ~/.config
32+
33+
echo -e "[Wallet]\nFirst Use=false\nDefault Wallet=kwallet" > ~/.config/kwalletrc
34+
echo -e "[Wallet]\nVersion=1" > ~/.local/share/kwalletd/kwallet.kwl
35+
36+
export QT_QPA_PLATFORM=minimal
37+
38+
# Start D-Bus session (dbus must be installed)
39+
export DBUS_SESSION_BUS_ADDRESS=$(dbus-daemon --session --print-address --fork)
40+
41+
"$kwalletd" &
42+
43+
# Wait up to 5 seconds for org.freedesktop.secrets to appear on D-Bus
44+
timeout=5000
45+
interval=100
46+
elapsed=0
47+
48+
while ! gdbus call --session \
49+
--dest org.freedesktop.DBus \
50+
--object-path /org/freedesktop/DBus \
51+
--method org.freedesktop.DBus.GetNameOwner \
52+
org.freedesktop.secrets >/dev/null 2>&1; do
53+
54+
sleep 0.1
55+
elapsed=$((elapsed + interval))
56+
if (( elapsed >= timeout )); then
57+
echo "❌ Timeout waiting for kwalletd to register org.freedesktop.secrets"
58+
exit 1
59+
fi
60+
done
61+
62+
owner=$(gdbus call --session \
63+
--dest org.freedesktop.DBus \
64+
--object-path /org/freedesktop/DBus \
65+
--method org.freedesktop.DBus.GetNameOwner \
66+
org.freedesktop.secrets | awk -F"'" '{print $2}')
67+
68+
if test -v $owner; then
69+
echo "there is no owner of the org.freedesktop.secrets API"
70+
exit 1
71+
fi
72+
73+
pid=$(gdbus call --session \
74+
--dest org.freedesktop.DBus \
75+
--object-path /org/freedesktop/DBus \
76+
--method org.freedesktop.DBus.GetConnectionUnixProcessID \
77+
"$owner" | awk '{print $2}' | tr -d ',)')
78+
79+
if test -v $pid; then
80+
echo "there is no registered org.freedesktop.secrets daemon"
81+
exit 1
82+
fi
83+
84+
exe=$(readlink -f /proc/$pid/exe)
85+
86+
if [[ "$exe" != "/usr/bin/ksecretd" ]]; then
87+
echo "dbus org.freedesktop.secrets is not using ${kwalletd}"
88+
exit 1
89+
fi

0 commit comments

Comments
 (0)