gardesk/garcard / 3da8c0d

Browse files

Add sprint 07 lifecycle validation assets

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
3da8c0d6785a5e71b5405791faf5314af528398f
Parents
79b89e8
Tree
501d685

3 changed files

StatusFile+-
M README.md 9 0
A examples/sprint-07-validation.md 45 0
A examples/validate-sprint-07.sh 137 0
README.mdmodified
@@ -12,6 +12,12 @@
1212
 2. `cargo run -p garcardctl -- status`
1313
 3. `cargo run -p garcard -- prompt --mode secret --message "Validation prompt"`
1414
 
15
+## Lifecycle Commands
16
+1. `cargo run -q -p garcardctl -- diagnose`
17
+2. `cargo run -q -p garcardctl -- temp-list`
18
+3. `cargo run -q -p garcardctl -- temp-revoke <authorization-id>`
19
+4. `cargo run -q -p garcardctl -- temp-revoke-all`
20
+
1521
 ## User Service
1622
 1. Install unit file:
1723
    - `install -Dm644 garcard.service ~/.config/systemd/user/garcard.service`
@@ -52,10 +58,13 @@ gartk prompt path with a persistent in-process modal session and falls back to
5258
 5. `examples/validate-sprint-03-integration.sh`
5359
 6. `examples/validate-sprint-04.sh`
5460
 7. `examples/validate-sprint-04-runtime.sh`
61
+8. `examples/sprint-07-validation.md`
62
+9. `examples/validate-sprint-07.sh`
5563
 
5664
 ## Troubleshooting
5765
 1. `Authorization requires authentication but no agent is available`
5866
    - ensure daemon is running: `cargo run -q -p garcardctl -- ping`
67
+   - inspect authority and subject health: `cargo run -q -p garcardctl -- diagnose`
5968
    - restart daemon after polkit restart: `cargo run -q -p garcardctl -- quit` then relaunch
6069
 2. `failed to connect to garcard daemon ...`
6170
    - check socket path from `garcardctl status`
examples/sprint-07-validation.mdadded
@@ -0,0 +1,45 @@
1
+# Sprint 07 Validation Checklist
2
+
3
+Run these checks from an active desktop user session.
4
+
5
+## Automated Baseline
6
+1. `cargo test --workspace`
7
+2. `./examples/validate-sprint-07.sh`
8
+
9
+Expected:
10
+1. Tests pass.
11
+2. `status`, `auth-summary`, `diagnose`, and temp-authorization commands all respond.
12
+
13
+## Fresh Login / Session Restart
14
+1. Log out and back in.
15
+2. Start daemon: `cargo run -q -p garcard -- daemon`
16
+3. Run:
17
+   - `cargo run -q -p garcardctl -- status`
18
+   - `cargo run -q -p garcardctl -- diagnose`
19
+
20
+Expected:
21
+1. `status.subject_kind` should normally be `unix-session`.
22
+2. `diagnose.authority_connected` should be `true` when polkit is reachable.
23
+
24
+## Polkit Restart Recovery
25
+1. Run: `GARCARD_SPRINT07_POLKIT_RESTART_CMD='sudo systemctl restart polkit' ./examples/validate-sprint-07.sh`
26
+2. If sudo is unavailable, restart polkit manually and rerun:
27
+   - `garcardctl diagnose`
28
+   - `garcardctl temp-list`
29
+
30
+Expected:
31
+1. Daemon can be restarted cleanly after polkit restart.
32
+2. Diagnostics and temp-authorization controls recover without socket cleanup.
33
+
34
+## Repeated Authorization + Revocation Cycles
35
+1. Run: `GARCARD_SPRINT07_BACKEND=polkit GARCARD_SPRINT07_RUN_PKCHECK=1 ./examples/validate-sprint-07.sh`
36
+2. During prompts, exercise both denied and successful authentication outcomes.
37
+3. After successful auth, verify:
38
+   - `garcardctl temp-list`
39
+   - `garcardctl temp-revoke-all`
40
+   - `garcardctl temp-list`
41
+
42
+Expected:
43
+1. Repeated cycles do not wedge auth state.
44
+2. Temporary authorizations are introspectable and revocable in-session.
45
+3. `diagnose.hints` includes useful remediation guidance for denied/no-agent paths.
examples/validate-sprint-07.shadded
@@ -0,0 +1,137 @@
1
+#!/usr/bin/env bash
2
+set -euo pipefail
3
+
4
+SOCKET_PATH="${GARCARD_SPRINT07_SOCKET:-${PWD}/target/garcard-sprint07.sock}"
5
+BACKEND="${GARCARD_SPRINT07_BACKEND:-polkit}"
6
+ACTION_ID="${GARCARD_SPRINT07_ACTION_ID:-com.mesonbuild.install.run}"
7
+AUTH_CYCLES="${GARCARD_SPRINT07_AUTH_CYCLES:-3}"
8
+LOG_FILE="${GARCARD_SPRINT07_LOG:-${PWD}/target/garcard-sprint07.log}"
9
+RUN_PKCHECK="${GARCARD_SPRINT07_RUN_PKCHECK:-1}"
10
+POLKIT_RESTART_CMD="${GARCARD_SPRINT07_POLKIT_RESTART_CMD:-}"
11
+
12
+if command -v garcard >/dev/null 2>&1; then
13
+  DAEMON_CMD=(garcard daemon)
14
+else
15
+  DAEMON_CMD=(cargo run -q -p garcard -- daemon)
16
+fi
17
+
18
+if command -v garcardctl >/dev/null 2>&1; then
19
+  CTL_CMD=(garcardctl)
20
+else
21
+  CTL_CMD=(cargo run -q -p garcardctl --)
22
+fi
23
+
24
+DAEMON_PID=0
25
+
26
+run_ctl() {
27
+  GARCARD_SOCKET="${SOCKET_PATH}" "${CTL_CMD[@]}" "$@"
28
+}
29
+
30
+wait_for_daemon() {
31
+  local tries=120
32
+  while (( tries > 0 )); do
33
+    if run_ctl ping >/dev/null 2>&1; then
34
+      return 0
35
+    fi
36
+    sleep 0.2
37
+    tries=$((tries - 1))
38
+  done
39
+  echo "daemon did not become ready in time"
40
+  return 1
41
+}
42
+
43
+start_daemon() {
44
+  GARCARD_SOCKET="${SOCKET_PATH}" \
45
+    GARCARD_AGENT_BACKEND="${BACKEND}" \
46
+    "${DAEMON_CMD[@]}" >>"${LOG_FILE}" 2>&1 &
47
+  DAEMON_PID=$!
48
+  wait_for_daemon
49
+}
50
+
51
+stop_daemon() {
52
+  if [[ "${DAEMON_PID}" -gt 0 ]] && kill -0 "${DAEMON_PID}" 2>/dev/null; then
53
+    run_ctl quit >/dev/null 2>&1 || true
54
+    wait "${DAEMON_PID}" 2>/dev/null || true
55
+  fi
56
+  DAEMON_PID=0
57
+}
58
+
59
+cleanup() {
60
+  stop_daemon
61
+  rm -f "${SOCKET_PATH}"
62
+}
63
+trap cleanup EXIT
64
+
65
+mkdir -p "$(dirname "${SOCKET_PATH}")"
66
+mkdir -p "$(dirname "${LOG_FILE}")"
67
+rm -f "${SOCKET_PATH}" "${LOG_FILE}"
68
+
69
+echo "Sprint 07 lifecycle validation"
70
+echo "  socket: ${SOCKET_PATH}"
71
+echo "  backend: ${BACKEND}"
72
+echo "  action: ${ACTION_ID}"
73
+echo "  log: ${LOG_FILE}"
74
+
75
+start_daemon
76
+
77
+echo "[1/5] Baseline lifecycle and diagnostics surface"
78
+run_ctl status
79
+run_ctl auth-summary
80
+run_ctl diagnose
81
+run_ctl temp-list || true
82
+
83
+echo "[2/5] Repeated auth + revocation loop (${AUTH_CYCLES} iterations)"
84
+if [[ "${RUN_PKCHECK}" == "1" ]] && command -v pkcheck >/dev/null 2>&1; then
85
+  pkcheck --revoke-temp || true
86
+  for i in $(seq 1 "${AUTH_CYCLES}"); do
87
+    echo "  cycle ${i}: trigger auth"
88
+    set +e
89
+    pkcheck --allow-user-interaction --process "$$" --action-id "${ACTION_ID}"
90
+    rc=$?
91
+    set -e
92
+    echo "  cycle ${i}: pkcheck rc=${rc}"
93
+    run_ctl auth-summary || true
94
+    run_ctl temp-list || true
95
+    run_ctl temp-revoke-all || true
96
+    run_ctl temp-list || true
97
+  done
98
+else
99
+  echo "  skipped (set GARCARD_SPRINT07_RUN_PKCHECK=1 and install pkcheck)"
100
+fi
101
+
102
+echo "[3/5] Daemon restart resilience"
103
+run_ctl quit >/dev/null
104
+wait "${DAEMON_PID}" 2>/dev/null || true
105
+DAEMON_PID=0
106
+start_daemon
107
+run_ctl status
108
+run_ctl diagnose
109
+
110
+echo "[4/5] Optional polkit restart check"
111
+if [[ -n "${POLKIT_RESTART_CMD}" ]]; then
112
+  echo "  running: ${POLKIT_RESTART_CMD}"
113
+  set +e
114
+  bash -lc "${POLKIT_RESTART_CMD}"
115
+  restart_rc=$?
116
+  set -e
117
+  echo "  restart command rc=${restart_rc}"
118
+  if [[ "${restart_rc}" -eq 0 ]]; then
119
+    run_ctl quit >/dev/null
120
+    wait "${DAEMON_PID}" 2>/dev/null || true
121
+    DAEMON_PID=0
122
+    start_daemon
123
+    run_ctl diagnose
124
+    run_ctl temp-list || true
125
+  fi
126
+else
127
+  echo "  skipped (set GARCARD_SPRINT07_POLKIT_RESTART_CMD, e.g. 'sudo systemctl restart polkit')"
128
+fi
129
+
130
+echo "[5/5] Final summary snapshot"
131
+run_ctl temp-revoke-all || true
132
+run_ctl status
133
+run_ctl auth-summary
134
+run_ctl diagnose
135
+
136
+echo "Validation complete. Log output:"
137
+echo "  ${LOG_FILE}"