Skip to content

Commit 3a242b6

Browse files
authored
refactor: use openconnect delegation mechanism (#3)
* feat: Add tasks for OpenConnect CLI delegation refactor - Introduced a comprehensive task list for refactoring OpenConnect CLI, organized by phases and user stories. - Established foundational tasks for setup and core entity definitions. - Defined user stories focusing on VPN connection, state tracking, disconnection, status querying, and error handling. - Emphasized TDD approach with tasks for writing failing tests before implementation. - Included checkpoints for each phase to ensure progress and functionality. * feat: MVP -> Implement unit tests for VPN connection management and refactor CLI integration - Added unit tests for `CliConnector`, `ConnectionEvent`, and `OutputParser` to ensure proper functionality and state transitions. - Removed FFI-related files and infrastructure, transitioning to a pure Rust implementation. - Refactored `run_vpn_on`, `run_vpn_off`, and `run_vpn_status` functions to utilize the new `CliConnector` for managing VPN connections. - Implemented state management for VPN connections, including error handling and event logging. - Updated main function to support asynchronous execution with Tokio. * feat(cli): enhance setup command with colored output and lazy mode option - Updated setup command to use colored output for better visibility. - Added lazy mode configuration option to automatically connect to VPN when running 'akon' without arguments. - Improved user prompts and messages for clarity. feat(vpn): improve VPN connection handling and error suggestions - Enhanced VPN connection logic to check for existing connections and handle reconnections gracefully. - Added actionable suggestions for various VPN errors to assist users in troubleshooting. - Improved output formatting for connection status and error messages. test(vpn): add integration tests for VPN disconnect functionality - Implemented comprehensive integration tests for VPN disconnect logic, state management, and error handling. - Verified state file format, missing fields, and invalid JSON scenarios. - Ensured proper cleanup of state files after disconnecting. fix(tests): update VPN status tests for accurate exit codes - Adjusted VPN status tests to check for correct exit codes when not connected. - Improved assertions to validate output messages for disconnected status. * feat(cli): prevent duplicate authenticating events - Added a flag to track if the authenticating event has been sent - Modified event handling to ensure only the first authenticating event is sent * feat: update version numbers and improve installation process - Bump version to 1.0.0 in Cargo.toml for both akon and akon-core - Simplify installation instructions in README.md to use 'make install' - Remove redundant setup-sudo.sh script, integrating its functionality into the Makefile - Add version information to CLI command output
1 parent 61299f5 commit 3a242b6

39 files changed

+8174
-733
lines changed

Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ resolver = "2"
44

55
[package]
66
name = "akon"
7-
version = "0.1.0"
7+
version = "1.0.0"
88
edition = "2021"
99

1010
[lints.rust]
@@ -24,6 +24,11 @@ nix.workspace = true
2424
serde_json.workspace = true
2525
libc.workspace = true
2626
serde.workspace = true
27+
tokio.workspace = true
28+
# Additional dependencies
29+
which = "6.0"
30+
chrono = "0.4"
31+
colored = "2.1"
2732
# Local crate
2833
akon-core = { path = "akon-core" }
2934

@@ -40,7 +45,7 @@ clap = { version = "4.0", features = ["derive"] }
4045
tracing = "0.1"
4146
tracing-journald = "0.3"
4247
tracing-subscriber = "0.3"
43-
tokio = { version = "1.0", features = ["full"] }
48+
tokio = { version = "1.35", features = ["process", "io-util", "time", "macros", "rt-multi-thread", "full"] }
4449

4550
# Security and crypto
4651
totp-lite = "2.0"

Makefile

Lines changed: 36 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,46 @@
1-
.PHONY: install-deps build install install-dev run-vpn-on run-vpn-off run-vpn-status test clean logs help uninstall
1+
.PHONY: all install install-dev
22

3-
# Default target
4-
all: build
5-
6-
# Install system dependencies required for the project
7-
install-deps:
8-
sudo dnf install -y openconnect-devel dbus-devel pkgconf-pkg-config libcap
9-
10-
# Build the project in release mode
11-
build:
3+
# Default target - build release binary
4+
all:
125
cargo build --release
136

14-
# Build in debug mode
15-
build-debug:
16-
cargo build
17-
18-
# Build in dev mode
19-
build-dev:
20-
cargo build
21-
@echo "✓ Built successfully"
22-
23-
# Install release version with network capabilities (one-time setup)
24-
# After this, you can run 'akon vpn on' without sudo
25-
install: build
26-
@echo "Installing akon with network capabilities..."
7+
# Install release version with passwordless sudo setup
8+
# This configures everything needed to run akon without password prompts
9+
install: all
10+
@echo "Installing akon..."
2711
sudo install -m 755 target/release/akon /usr/local/bin/akon
28-
sudo setcap cap_net_admin,cap_net_raw,cap_setuid,cap_setgid+eip /usr/local/bin/akon
2912
@echo "✓ Installed to /usr/local/bin/akon"
30-
@echo "✓ Network capabilities set (CAP_NET_ADMIN, CAP_NET_RAW, CAP_SETUID, CAP_SETGID)"
3113
@echo ""
32-
@echo "You can now run without sudo:"
33-
@echo " akon vpn on"
14+
@echo "Configuring passwordless sudo for openconnect..."
15+
@if ! command -v openconnect &> /dev/null; then \
16+
echo "ERROR: openconnect is not installed"; \
17+
echo "Please install it first:"; \
18+
echo " Ubuntu/Debian: sudo apt install openconnect"; \
19+
echo " RHEL/Fedora: sudo dnf install openconnect"; \
20+
exit 1; \
21+
fi
22+
@OPENCONNECT_PATH=$$(which openconnect); \
23+
SUDOERS_FILE="/etc/sudoers.d/akon"; \
24+
echo "# Allow $$USER to run openconnect without password for akon VPN" | sudo tee $$SUDOERS_FILE > /dev/null; \
25+
echo "$$USER ALL=(root) NOPASSWD: $$OPENCONNECT_PATH" | sudo tee -a $$SUDOERS_FILE > /dev/null; \
26+
sudo chmod 0440 $$SUDOERS_FILE; \
27+
if sudo visudo -c -f $$SUDOERS_FILE 2>&1 | grep -q "parsed OK"; then \
28+
echo "✓ Passwordless sudo configured for openconnect"; \
29+
else \
30+
echo "ERROR: Invalid sudoers configuration"; \
31+
sudo rm -f $$SUDOERS_FILE; \
32+
exit 1; \
33+
fi
34+
@echo ""
35+
@echo "Installation complete! You can now run:"
36+
@echo " akon setup"
3437

35-
# Install development version with network capabilities
36-
install-dev: build-debug
37-
@echo "Installing debug akon with network capabilities..."
38+
# Install development version for debugging
39+
install-dev:
40+
cargo build
41+
@echo "Installing debug akon..."
3842
sudo install -m 755 target/debug/akon /usr/local/bin/akon-dev
39-
sudo setcap cap_net_admin,cap_net_raw,cap_setuid,cap_setgid+eip /usr/local/bin/akon-dev
4043
@echo "✓ Installed to /usr/local/bin/akon-dev"
41-
@echo "✓ Network capabilities set (CAP_NET_ADMIN, CAP_NET_RAW, CAP_SETUID, CAP_SETGID)"
4244
@echo ""
43-
@echo "You can now run without sudo:"
44-
@echo " akon-dev vpn on"
45-
46-
# Uninstall akon binaries
47-
uninstall:
48-
sudo rm -f /usr/local/bin/akon /usr/local/bin/akon-dev
49-
@echo "✓ Uninstalled akon"
50-
51-
# Kill any existing akon processes
52-
kill-akon:
53-
-pkill -f akon || true
54-
55-
# Run VPN connection - RELEASE MODE (after 'make install')
56-
# This assumes you've run 'make install' and the binary has capabilities
57-
run-vpn-on: install
58-
@echo "Connecting to VPN..."
59-
RUST_LOG=info akon vpn on
60-
61-
# Run VPN connection - DEBUG MODE (for development)
62-
# This uses the locally built binary with capabilities set temporarily
63-
run-vpn-on-debug: build-dev
64-
@echo "Setting temporary capabilities on debug binary..."
65-
@sudo setcap cap_net_admin+eip target/debug/akon || true
66-
@echo "Connecting to VPN (debug mode)..."
67-
RUST_LOG=debug ./target/debug/akon vpn on
68-
69-
# Disconnect VPN (debug)
70-
run-vpn-off-debug:
71-
cargo run -- vpn off
72-
73-
# Disconnect VPN
74-
run-vpn-off:
75-
cargo run --release -- vpn off
76-
77-
# Check VPN status (debug)
78-
run-vpn-status-debug:
79-
cargo run -- vpn status
80-
81-
# Check VPN status
82-
run-vpn-status:
83-
cargo run --release -- vpn status
84-
85-
# Run tests
86-
test:
87-
cargo test
88-
89-
# Clean build artifacts
90-
clean:
91-
cargo clean
92-
93-
# Show recent logs from journalctl
94-
logs:
95-
sudo journalctl --since "5 minutes ago" | grep -E "akon|openconnect"
96-
97-
# Show segfault/crash logs
98-
crash-logs:
99-
sudo journalctl --since "10 minutes ago" | grep -E "segfault|SEGV|core dump"
100-
101-
# Analyze core dump (if available)
102-
coredump:
103-
@echo "Recent core dumps:"
104-
@coredumpctl list | grep akon | head -5
105-
@echo ""
106-
@echo "To debug the latest crash, run:"
107-
@echo " coredumpctl debug"
108-
109-
# Show help
110-
help:
111-
@echo "Available targets:"
112-
@echo " make install-deps - Install system dependencies"
113-
@echo " make build - Build in release mode"
114-
@echo " make build-debug - Build in debug mode"
115-
@echo " make build-dev - Build in dev mode"
116-
@echo " make run-vpn-on - Connect VPN (release, with logs)"
117-
@echo " make run-vpn-on-debug - Connect VPN (debug, with logs)"
118-
@echo " make run-vpn-off - Disconnect VPN (release)"
119-
@echo " make run-vpn-off-debug - Disconnect VPN (debug)"
120-
@echo " make run-vpn-status - Check VPN status (release)"
121-
@echo " make run-vpn-status-debug - Check VPN status (debug)"
122-
@echo " make test - Run tests"
123-
@echo " make logs - Show recent logs"
124-
@echo " make crash-logs - Show crash/segfault logs"
125-
@echo " make coredump - Analyze core dumps"
126-
@echo " make clean - Clean build artifacts"
45+
@echo "You can now run:"
46+
@echo " akon-dev setup"

0 commit comments

Comments
 (0)