Skip to content

Commit 6c3b789

Browse files
feat: simplify Gitea installation with local credential storage
- Removed Vault integration and environment-based secret management for simpler local setup - Updated to store database credentials directly in .env file instead of secret manager - Modified installation documentation to reflect local credential storage approach - Added note about future Vault integration coming in ~6 months - Simplified code by removing unused imports and dependencies (environment, secrets, zap) - Updated log messages to reflect
1 parent d481f3c commit 6c3b789

2 files changed

Lines changed: 17 additions & 59 deletions

File tree

cmd/create/gitea.go

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@ package create
66
import (
77
"fmt"
88

9-
"github.com/CodeMonkeyCybersecurity/eos/pkg/environment"
109
eos "github.com/CodeMonkeyCybersecurity/eos/pkg/eos_cli"
1110
"github.com/CodeMonkeyCybersecurity/eos/pkg/eos_io"
1211
"github.com/CodeMonkeyCybersecurity/eos/pkg/gitea"
13-
"github.com/CodeMonkeyCybersecurity/eos/pkg/secrets"
1412
"github.com/spf13/cobra"
1513
"github.com/uptrace/opentelemetry-go-extra/otelzap"
16-
"go.uber.org/zap"
1714
)
1815

1916
// CreateGiteaCmd represents the Gitea installation command
@@ -26,7 +23,7 @@ Gitea is a lightweight self-hosted Git service with a web interface.
2623
2724
This command will:
2825
- Create installation directory at /opt/gitea
29-
- Generate secure database credentials
26+
- Generate secure database credentials in .env file
3027
- Create docker-compose.yml configuration
3128
- Deploy Gitea and PostgreSQL containers
3229
- Expose Gitea on port 8167 (HTTP) and 2222 (SSH)
@@ -35,31 +32,16 @@ Example:
3532
eos create gitea
3633
3734
After installation, access Gitea at http://localhost:8167 and complete
38-
the initial setup wizard.`,
35+
the initial setup wizard.
36+
37+
NOTE: Database credentials are stored in /opt/gitea/.env
38+
(Vault integration coming in ~6 months)`,
3939
RunE: eos.Wrap(func(rc *eos_io.RuntimeContext, cmd *cobra.Command, args []string) error {
4040
logger := otelzap.Ctx(rc.Ctx)
4141
logger.Info("Starting Gitea installation")
4242

43-
// ASSESS: Discover environment
44-
logger.Info("Discovering environment configuration")
45-
envConfig, err := environment.DiscoverEnvironment(rc)
46-
if err != nil {
47-
return fmt.Errorf("failed to discover environment: %w", err)
48-
}
49-
50-
logger.Info("Environment discovered",
51-
zap.String("environment", envConfig.Environment),
52-
zap.String("datacenter", envConfig.Datacenter))
53-
54-
// Initialize secret manager
55-
logger.Info("Initializing secret manager")
56-
secretManager, err := secrets.NewManager(rc, envConfig)
57-
if err != nil {
58-
return fmt.Errorf("failed to initialize secret manager: %w", err)
59-
}
60-
6143
// Create installation configuration
62-
config := gitea.DefaultInstallConfig(secretManager)
44+
config := gitea.DefaultInstallConfig()
6345

6446
// INTERVENE: Delegate to pkg/gitea for business logic
6547
if err := gitea.Install(rc, config); err != nil {

pkg/gitea/install.go

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/CodeMonkeyCybersecurity/eos/pkg/container"
1212
"github.com/CodeMonkeyCybersecurity/eos/pkg/crypto"
1313
"github.com/CodeMonkeyCybersecurity/eos/pkg/eos_io"
14-
"github.com/CodeMonkeyCybersecurity/eos/pkg/secrets"
1514
"github.com/CodeMonkeyCybersecurity/eos/pkg/shared"
1615
"github.com/uptrace/opentelemetry-go-extra/otelzap"
1716
"go.uber.org/zap"
@@ -27,18 +26,14 @@ type InstallConfig struct {
2726

2827
// SSHPort is the SSH port for Git operations (default: 2222)
2928
SSHPort int
30-
31-
// SecretManager is the initialized secret manager for credential storage
32-
SecretManager *secrets.Manager
3329
}
3430

3531
// DefaultInstallConfig returns the default installation configuration
36-
func DefaultInstallConfig(secretManager *secrets.Manager) *InstallConfig {
32+
func DefaultInstallConfig() *InstallConfig {
3733
return &InstallConfig{
38-
InstallDir: GiteaDir,
39-
Port: GiteaPort,
40-
SSHPort: GiteaSSHPort,
41-
SecretManager: secretManager,
34+
InstallDir: GiteaDir,
35+
Port: GiteaPort,
36+
SSHPort: GiteaSSHPort,
4237
}
4338
}
4439

@@ -105,33 +100,13 @@ func interveneInstall(rc *eos_io.RuntimeContext, config *InstallConfig) error {
105100
}
106101
}
107102

108-
// Step 3: Generate or retrieve database password
109-
logger.Info("Managing secrets for Gitea")
110-
requiredSecrets := map[string]secrets.SecretType{
111-
"db_password": secrets.SecretTypePassword,
112-
}
113-
serviceSecrets, err := config.SecretManager.EnsureServiceSecrets(rc.Ctx, "gitea", requiredSecrets)
103+
// Step 3: Generate database password
104+
logger.Info("Generating database password")
105+
dbPassword, err := crypto.GeneratePassword(32)
114106
if err != nil {
115-
// Fallback: generate password locally if secret manager fails
116-
logger.Warn("Failed to manage secrets via secret manager, generating locally", zap.Error(err))
117-
password, genErr := crypto.GeneratePassword(32)
118-
if genErr != nil {
119-
return fmt.Errorf("failed to generate password: %w", genErr)
120-
}
121-
serviceSecrets = &secrets.ServiceSecrets{
122-
Secrets: map[string]interface{}{
123-
"db_password": password,
124-
},
125-
Backend: "local",
126-
}
127-
}
128-
129-
dbPassword, ok := serviceSecrets.Secrets["db_password"].(string)
130-
if !ok {
131-
return fmt.Errorf("database password is not a string")
107+
return fmt.Errorf("failed to generate database password: %w", err)
132108
}
133-
logger.Info("Secrets managed",
134-
zap.String("backend", serviceSecrets.Backend))
109+
logger.Debug("Database password generated")
135110

136111
// Step 4: Create docker-compose.yml
137112
composeFilePath := filepath.Join(config.InstallDir, GiteaComposeFile)
@@ -189,7 +164,8 @@ func evaluateInstallation(rc *eos_io.RuntimeContext, config *InstallConfig) erro
189164
zap.String("installation_directory", config.InstallDir),
190165
zap.String("compose_file", filepath.Join(config.InstallDir, GiteaComposeFile)),
191166
zap.String("data_directory", filepath.Join(config.InstallDir, "data")),
192-
zap.String("database_password_location", "Retrieve via: eos read credentials --service gitea"))
167+
zap.String("env_file", filepath.Join(config.InstallDir, ".env")),
168+
zap.String("database_password_note", "Database password stored in .env file"))
193169

194170
logger.Info("Next steps",
195171
zap.String("step_1", fmt.Sprintf("Navigate to http://%s:%d", shared.GetInternalHostname(), config.Port)),

0 commit comments

Comments
 (0)