Skip to content

Commit c49ea89

Browse files
committed
chore: disable API and Dashboard by default
1 parent 1fd0673 commit c49ea89

File tree

3 files changed

+81
-3
lines changed

3 files changed

+81
-3
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,37 @@ GoUP! is a minimal, tweakable web server written in Go. You can use it to serve
2323
- API for dynamic configuration changes
2424
- Docker/Podman support for easy deployment
2525

26+
27+
## API & Dashboard
28+
29+
GoUp includes a built-in REST API and a Web Dashboard for management.
30+
**By default, these are disabled for security reasons.**
31+
32+
To enable them, edit your global configuration file (`~/.config/goup/conf.global.json`) and configure the `account` section to secure them.
33+
34+
### Authentication
35+
36+
Security is mandatory when enabling the API/Dashboard. GoUp uses:
37+
- **Basic Auth** for the Dashboard.
38+
- **Token Auth** for the API.
39+
40+
Configuration example:
41+
42+
```json
43+
{
44+
"account": {
45+
"username": "admin",
46+
"password_hash": "$2a$12$R9h/cIPz0gi.URNNXMnmueKz3hJ...", // BCrypt hash
47+
"api_token": "your-secret-token-here"
48+
},
49+
"enable_api": true,
50+
"api_port": 6007,
51+
"dashboard_port": 6008
52+
}
53+
```
54+
55+
> **Note:** You can generate a BCrypt hash using online tools or `htpasswd -Bnm user password`.
56+
2657
## Compression
2758

2859
GoUp handles compression automatically with a dual-layer strategy:
@@ -142,6 +173,14 @@ goup start --tui
142173
goup restart // Not implemented yet, use <Ctrl+C> to stop the server and start it again
143174
```
144175

176+
- **Generate Password Hash:**
177+
178+
```bash
179+
goup gen-pass
180+
# Or providing the password as argument
181+
goup gen-pass mysecretpassword
182+
```
183+
145184
## Configuration
146185

147186
### Site Configuration Structure

internal/cli/cli.go

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"github.com/mirkobrombin/goup/internal/plugin"
1111
"github.com/mirkobrombin/goup/internal/server"
1212
"github.com/spf13/cobra"
13+
"golang.org/x/crypto/bcrypt"
14+
"golang.org/x/term"
1315
)
1416

1517
var tuiMode bool
@@ -33,14 +35,17 @@ func Execute() {
3335

3436
func init() {
3537
rootCmd.AddCommand(generateCmd)
38+
rootCmd.AddCommand(genPassCmd)
3639
rootCmd.AddCommand(startCmd)
3740
rootCmd.AddCommand(validateCmd)
3841
rootCmd.AddCommand(listCmd)
3942
rootCmd.AddCommand(pluginsCmd)
4043

4144
startCmd.Flags().BoolVarP(&tuiMode, "tui", "t", false, "Enable TUI mode")
4245
startCmd.Flags().BoolVarP(&benchMode, "bench", "b", false, "Enable benchmark mode")
43-
startCmd.Flags().StringVarP(&configPath, "config", "c", "", "Path to specific configuration file")
46+
47+
// Global flags
48+
rootCmd.PersistentFlags().StringVarP(&configPath, "config", "c", "", "Path to specific configuration file")
4449
}
4550

4651
var generateCmd = &cobra.Command{
@@ -242,3 +247,37 @@ var pluginsCmd = &cobra.Command{
242247
}
243248
},
244249
}
250+
251+
// genPassCmd generates a Bcrypt password hash.
252+
var genPassCmd = &cobra.Command{
253+
Use: "gen-pass [password]",
254+
Short: "Generate a Bcrypt hash for a password",
255+
Long: `Generate a Bcrypt hash for a password. If no password is provided as an argument, you will be prompted to enter one securely.`,
256+
Args: cobra.MaximumNArgs(1),
257+
Run: genPass,
258+
}
259+
260+
func genPass(cmd *cobra.Command, args []string) {
261+
var password []byte
262+
var err error
263+
264+
if len(args) > 0 {
265+
password = []byte(args[0])
266+
} else {
267+
fmt.Print("Enter Password: ")
268+
password, err = term.ReadPassword(int(os.Stdin.Fd()))
269+
fmt.Println() // Add newline after silent input
270+
if err != nil {
271+
fmt.Printf("Error reading password: %v\n", err)
272+
os.Exit(1)
273+
}
274+
}
275+
276+
hash, err := bcrypt.GenerateFromPassword(password, bcrypt.DefaultCost)
277+
if err != nil {
278+
fmt.Printf("Error generating hash: %v\n", err)
279+
os.Exit(1)
280+
}
281+
282+
fmt.Println(string(hash))
283+
}

internal/config/global_config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ func LoadGlobalConfig() error {
4040
configFile := filepath.Join(configDir, globalConfName)
4141
if _, err := os.Stat(configFile); os.IsNotExist(err) {
4242
GlobalConf = &GlobalConfig{
43-
EnableAPI: true,
43+
EnableAPI: false,
4444
APIPort: 6007,
45-
DashboardPort: 6008,
45+
DashboardPort: 0, // Disabled by default
4646
EnabledPlugins: []string{},
4747
}
4848
return nil

0 commit comments

Comments
 (0)