Skip to content

Conversation

@nfebe
Copy link
Contributor

@nfebe nfebe commented Feb 3, 2026

No description provided.

nfebe added 2 commits February 1, 2026 21:37
Add setup flow endpoints for the installer UI to configure:
- System validation checks
- Domain configuration
- CORS/UI origin settings
- Initial user creation

Note: Dynamic CORS middleware included but may be removed
if installer UI is served from same origin.

Signed-off-by: nfebe <fenn25.fn@gmail.com>
- Add duplicate domain+path validation in addDomain API endpoint
- Add nginx warning tolerance (ssl_stapling warnings no longer fail)
- Add location deduplication in config generator to prevent duplicate
  location "/" errors
- Add vhost backup/restore on proxy setup failure instead of deletion
- Add WriteVirtualHost and GetVirtualHost to NginxManager interface

Fixes issue where adding domains would fail due to ssl_stapling warnings
and corrupt vhost config by deleting it on failure.
@sourceant
Copy link

sourceant bot commented Feb 3, 2026

Code Review Summary

This pull request introduces a significant new feature: a comprehensive initial setup flow for the agent. This feature streamlines first-time configuration, including Docker environment validation, instance IP detection, domain/SSL setup, CORS configuration, and initial user creation. Beyond the new setup, the PR substantially enhances the robustness of the Nginx proxy management by implementing atomic configuration updates with rollback capabilities and intelligent handling of duplicate domain paths. Key dependencies have also been updated, improving overall stability.

🚀 Key Improvements

  • Initial Setup Flow: A structured and guided initial setup experience for the agent, including critical environment validations and configuration steps.
  • 🔒 Enhanced Nginx Configuration Reliability: Nginx config changes are now atomic, with automatic rollback to the previous valid configuration if a new one fails validation.
  • 🛡️ Improved Security Configuration: Dynamic CORS management and mandatory username/password policies for initial admin user creation contribute to a more secure default state.
  • Duplicate Domain/Path Handling: The proxy configuration now correctly deduplicates location blocks for the same domain and path prefix, preventing potential Nginx errors.
  • ⬆️ Dependency Updates: go.mod and go.sum reflect important updates to github.com/docker/docker and golang.org/x/crypto, among others, ensuring the project uses more recent and potentially more secure/performant libraries.

💡 Minor Suggestions

  • Review internal/proxy/orchestrator_test.go to refactor testableOrchestrator to test the actual Orchestrator more directly with mocked dependencies, reducing logic duplication in tests.
  • Consider adding more comprehensive documentation for the new setup package's public API and internal design decisions.

@sourceant
Copy link

sourceant bot commented Feb 3, 2026

🔍 Code Review

💡 1. **internal/nginx/manager.go** (Lines 230-236) - BUG

The modification to TestConfig to explicitly check for [emerg] or [error] in Nginx output, while allowing warnings, is a robust improvement. This prevents Nginx from being reloaded with potentially problematic configurations while still allowing non-critical warnings (like ssl_stapling issues) to pass.

Suggested Code:

		outputStr := string(output)		if isNginxConfigValid(outputStr) {			log.Printf("nginx config test passed with warnings: %s", outputStr)			return nil		}		return fmt.Errorf("nginx config test failed: %s - %w", outputStr, err)

Current Code:

		return fmt.Errorf("nginx config test failed: %s - %w", string(output), err)
💡 2. **internal/nginx/manager.go** (Lines 443-447) - BUG

The addition of seenPaths to deduplicate location blocks within groupDomainsByHost is a critical fix. Without this, multiple domain configurations for the same domain and path prefix could lead to redundant location blocks in Nginx, which might cause unpredictable routing or Nginx configuration errors. The added logging for skipped duplicates is also helpful for debugging.

Suggested Code:

		seenPaths := make(map[string]bool)
		hasSSL := false

Current Code:

		hasSSL := false
💡 3. **internal/proxy/orchestrator.go** (Lines 108-115) - REFACTOR

This change significantly improves the robustness of proxy setup. By backing up the previous Nginx configuration and restoring it if the new configuration fails the TestConfig, the system ensures atomicity and prevents leaving Nginx in an invalid or broken state. This greatly enhances stability and fault tolerance.

Suggested Code:

		if hadPreviousConfig {
			if restoreErr := o.nginx.WriteVirtualHost(deployment.Name, previousConfig); restoreErr != nil {
				log.Printf("warning: failed to restore previous vhost config: %v", restoreErr)
			}
		} else {
			_ = o.nginx.DeleteVirtualHost(deployment.Name)
		}

Current Code:

		_ = o.nginx.DeleteVirtualHost(deployment.Name)

Verdict: APPROVE

Posted as a comment because posting a review failed.

@nfebe nfebe closed this Feb 3, 2026
@nfebe nfebe deleted the fix/domain-add-duplicate-migration branch February 3, 2026 19:42
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.

1 participant