Skip to content

Conversation

@geunwoonoh
Copy link
Collaborator

Summary

Integrates new features from main branch (Tunneling, Auth Manager, Logger refactoring, Ping/Pong) into the refactored architecture.

Changes

  • Integrate Tunneling feature using Handler pattern (TunnelHandler)
  • Add Auth Manager / MFA sudo approval workflow
  • Remove lumberjack from Logger, use systemd journald
  • Add WebSocket ping/pong heartbeat support

Test plan

  • go build -v ./... succeeds
  • go test -v ./... -p 1 all tests pass
  • Manual testing of Tunnel functionality
  • Manual testing of Auth Manager sudo approval

Detailed Changes

1. Tunneling Feature (PR #156 Integration)

New files:

  • pkg/executor/handlers/tunnel/tunnel.go - TunnelHandler implementation
  • pkg/executor/handlers/tunnel/types.go - Data type definitions
  • pkg/runner/tunnel_client.go - smux multiplexing tunnel client
  • pkg/runner/tunnel_worker.go - Tunnel worker subprocess
  • pkg/runner/tunnel_linux.go - Linux privilege demotion
  • pkg/runner/tunnel_darwin.go - macOS implementation
  • pkg/tunnel/conn.go - WebSocket adapter
  • pkg/tunnel/pool.go - Buffer pool
  • cmd/alpamon/command/tunnel/tunnel.go - CLI command

Modified files:

  • pkg/executor/factory.go - Register TunnelHandler
  • pkg/executor/handlers/common/types.go - Add OpenTunnel, CloseTunnel types
  • pkg/executor/handlers/common/args.go - Add TargetPort field
  • internal/protocol/command.go - Add TargetPort mapping
  • pkg/config/config.go - Add smux configuration

2. Auth Manager / MFA Feature (PR #101 Integration)

New files:

  • pkg/runner/auth_manager.go - Sudo approval request management (Unix socket)
  • pkg/runner/control_client.go - Control WebSocket client

Modified files:

  • cmd/alpamon/command/root.go - ControlClient, AuthManager initialization and shutdown
  • pkg/runner/pty.go - Add/remove PID mapping for PTY sessions

3. Logger Refactoring (PR #160 Integration)

Modified files:

  • pkg/logger/logger.go - Remove lumberjack, output to stdout/stderr
  • cmd/alpamon/command/root.go - Remove lumberjack-related code

4. Ping/Pong Handler (PR #158 Integration)

Modified files:

  • pkg/runner/client.go - Add SendPongResponse(), handle ping queries

5. Miscellaneous

  • .github/workflows/release.yml - PackageCloud channel separation
  • configs/alpamon.service - systemd service configuration update
  • go.mod, go.sum - Add smux dependency

Architecture Compliance

Compliance with refactoring architecture :

Item Status Notes
Handler Pattern Implemented as TunnelHandler
Factory Pattern Registered in factory.go
Pool Usage Commands executed through Pool
Context Propagation ctx parameter in all handlers
Circular Dependencies None

Security Considerations

  • Unix socket permissions 0600 (root only)
  • Tunnel connections localhost only (127.0.0.1)
  • Authentication header ID/Key based
  • TLS configuration option available

Concurrency Safety

Component Protection Method
AuthManager sync.RWMutex
ControlClient sync.Mutex
activeTunnels sync.RWMutex
terminals sync.RWMutex

Related Issues/PRs

hyunwoo hwang and others added 30 commits August 5, 2025 14:40
…nt-via-mfa-authentication' of https://github.com/alpacax/alpamon into 99-sudo-privilege-verification-and-centralized-management-via-mfa-authentication
…tion-and-centralized-management-via-mfa-authentication
- Add alpamon-pam as recommended dependency in .goreleaser.yaml
  - Debian/Ubuntu: recommends alpamon-pam
  - CentOS/RHEL: recommends alpamon-pam
- Update README.md with PAM module documentation
  - Add installation instructions with/without PAM module
  - Document PAM configuration steps for /etc/pam.d/sudo and /etc/sudo.conf
  - Add note about Alpamon service requirement for PAM authentication
…tion-and-centralized-management-via-mfa-authentication
Convert Korean comment in Dockerfile to English for better maintainability.

Changes:
- Dockerfiles/ubuntu/22.04/Dockerfile: Convert GOARCH architecture comment
Add AuthManager for centralized sudo privilege verification:
- Unix domain socket server (/var/run/alpamon/auth.sock)
- Handle check_user requests from pam_alpamon.so
- Handle sudo_approval requests from alpacon_approval.so
- Distinguish Alpacon users (pidToSessionMap) vs local users (localSudoRequests)
- Retry logic with exponential backoff for WebSocket communication
- Response routing back to PAM/sudo plugin via Unix socket

Security improvements:
- Root-only socket permissions (0600)
- 30-second timeout to prevent DoS
- Request ID based mapping for concurrent requests
- Proper cleanup on timeout and connection errors

Integration:
- WebSocket communication with alpacon-server
- Coordinate with PtyClient session management
- Support both authenticated and local user approval flows
…atting

Replace Msg(fmt.Sprintf(...)) with Msgf(...) to fix staticcheck SA1006 linting error.
This resolves the golangci-lint failure in CI while maintaining the same functionality.
Use Str() instead of Err(fmt.Errorf()) to fix staticcheck SA1006 error.
The result variable is already a string, so we use structured logging with Str().
- Fix critical mutex double unlock bug in HandleSudoApprovalResponse
  - Previously unlocked mutex inside loop, causing panic on second unlock
  - Now unlocks once after checking both alpacon and local requests

- Improve connection lifecycle management in handleSudoRequest
  - Remove defer close() to prevent double-close with manual cleanup
  - Explicitly close connections after check_user requests
  - Document that sudo_approval connections are managed by response handlers

- Add default case for unknown request types with proper cleanup
- Improve timeout handling with explicit service shutdown cleanup
- Rename is_alpcon_user to is_alpacon_user for consistency
  - SudoApprovalRequest, SudoApprovalResponse structs
  - MFAResponse, IsAlpconResponse structs
…tion-and-centralized-management-via-mfa-authentication
- Remove hardcoded sudo group addition in adduser
- Sudo privilege is now controlled by alpacon-server via gids
- Add ControlClient to handle control WebSocket connection
- Refactor client.go to separate control logic into control_client.go
- Support sudo_approval request/response via control channel
jisung-02 and others added 25 commits December 22, 2025 17:25
- Rename variables to camelCase (unix_conn -> unixConn, sudo_approval_req -> sudoApprovalReq)
- Add BaseRequest struct for type-safe request parsing
- Extract createSendOperation method from sendSudoRequestWithRetry
- Add completion channels for proper timeout handling
- Close connection after sendSudoApprovalResponse in cleanupTimeoutRequest
- Call RemovePIDSessionMapping when PtyClient disconnects
- Remove lumberjack dependency for log rotation
- Output logs to stderr for systemd/journald to capture
- Update systemd service to use journald (StandardOutput/Error=journal)
- Add log viewing instructions to README
…tion-and-centralized-management-via-mfa-authentication
…nd-centralized-management-via-mfa-authentication

feat: implement MFA-based sudo approval system
…tdout

refactor(logger): remove lumberjack, use systemd journald for logging
feat: Support for Websh based TCP-tunneling
Add support for deploying packages to different
PackageCloud repositories based on release tag patterns:
- stable (alpamon): vX.Y.Z tags
- latest (alpamon-latest): vX.Y.Z-rc.N tags
- dev (alpamon-dev): vX.Y.Z-dev, -beta.N, -alpha.N tags
Also enable automatic GitHub pre-release detection in goreleaser.
…ls-stable-dev-latest

Resolve "Separate PackageCloud Channels (stable, dev, latest)"
…actoring-integrate-main-branch-changes-into-refactored-architecture
Add TunnelHandler to handle the following commands:
opentunnel, closetunnel
Define types and structs related to TunnelHandler.
Add fields related to tunneling functionality
in conjunction with TunnelHandler.
…ation

Update RegisterAll() to include TunnelHandler registration.
@geunwoonoh geunwoonoh self-assigned this Dec 29, 2025
@geunwoonoh geunwoonoh merged commit 4cf6ff7 into 131-alpamon-agent-refactoring Dec 29, 2025
2 checks passed
@geunwoonoh geunwoonoh deleted the 162-alpamon-agent-refactoring-integrate-main-branch-changes-into-refactored-architecture branch December 29, 2025 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants