diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index c08e5e2..54c0e17 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -16,7 +16,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: 1.19.1 + go-version: 1.24.4 - name: Get coverage tool run: | diff --git a/README.md b/README.md index 40fb1d6..3f1a6fe 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,7 @@ Once done, just go to and login as "admin" with . | HOST | Url to OnLogs host from protocol to domain name. | | if `AGENT=true` | ONLOGS_TOKEN | Token that will use an agent to authorize and connect to HOST | Generates with OnLogs interface | if `AGENT=true` | MAX_LOGS_SIZE | Maximum allowed total logs size before cleanup triggers. Accepts human-readable formats like 5GB, 500MB, 1.5GB etc. When exceeded, 10% of logs (by count) will be removed proportionally across containers starting from oldest | 10GB | - +| DISABLE_AUTH | Option to completely disable built in authentication in the application. When this option is set to `true` the app will behave like if the Administrator is logged in. The option to manage users will be removed. | false | - ### Docket socket URL By default the app will connect using the raw unix socket. But this can be overriden via the ENV variable `DOCKER_HOST`. That way you can specify fully qualified URL to the socket or URL of an docker socket proxy. diff --git a/application/backend/.env example b/application/backend/.env example index 4ad1c5b..13a76ed 100644 --- a/application/backend/.env example +++ b/application/backend/.env example @@ -2,6 +2,6 @@ PASSWORD=fsadfsadfad ENV_NAME = local PORT=2874 ONLOGS_PATH_PREFIX='' - +DISABLE_AUTH=false # HOST=onlogs.coposter.me # AGENT=true \ No newline at end of file diff --git a/application/backend/app/routes/routes.go b/application/backend/app/routes/routes.go index e675d44..dcce55a 100644 --- a/application/backend/app/routes/routes.go +++ b/application/backend/app/routes/routes.go @@ -43,6 +43,10 @@ func enableCors(w *http.ResponseWriter) { } func verifyAdminUser(w *http.ResponseWriter, req *http.Request) bool { + if os.Getenv("DISABLE_AUTH") == "true" { + return true + } + username, err := util.GetUserFromJWT(*req) if username != os.Getenv("ADMIN_USERNAME") { (*w).WriteHeader(http.StatusForbidden) @@ -59,6 +63,10 @@ func verifyAdminUser(w *http.ResponseWriter, req *http.Request) bool { } func verifyUser(w *http.ResponseWriter, req *http.Request) bool { + if os.Getenv("DISABLE_AUTH") == "true" { + return true + } + _, err := util.GetUserFromJWT(*req) if err != nil { (*w).WriteHeader(http.StatusUnauthorized) @@ -91,19 +99,30 @@ func (h *RouteController)Frontend(w http.ResponseWriter, req *http.Request) { if err != nil { dir = http.Dir("dist") file, err = dir.Open("index.html") + fileName = "index.html" } if err != nil { return } defer file.Close() + stat, _ := file.Stat() + content, _ := io.ReadAll(file) + + if fileName == "index.html" { + var disableAuth []byte + if os.Getenv("DISABLE_AUTH") == "true" { + disableAuth = []byte("true") + } else { + disableAuth = []byte("false") + } + + content = bytes.Replace(content, []byte("$DISABLE_AUTH$"), disableAuth, 1) + } + w.Header().Set("Cache-Control", "no-store") w.Header().Set("Content-Type", mime.TypeByExtension(filepath.Ext(fileName))) - - stat, _ := file.Stat() - content := make([]byte, stat.Size()) - io.ReadFull(file, content) - http.ServeContent(w, req, requestedPath, stat.ModTime(), bytes.NewReader(content)) + http.ServeContent(w, req, fileName, stat.ModTime(), bytes.NewReader(content)) } func (h *RouteController)CheckCookie(w http.ResponseWriter, req *http.Request) { diff --git a/application/backend/app/routes/routes_test.go b/application/backend/app/routes/routes_test.go index 7605e3b..0bd36a6 100644 --- a/application/backend/app/routes/routes_test.go +++ b/application/backend/app/routes/routes_test.go @@ -16,8 +16,8 @@ import ( "github.com/devforth/OnLogs/app/userdb" "github.com/devforth/OnLogs/app/util" "github.com/devforth/OnLogs/app/vars" - "github.com/joho/godotenv" "github.com/docker/docker/client" + "github.com/joho/godotenv" "github.com/syndtr/goleveldb/leveldb" ) @@ -33,11 +33,11 @@ func initTestConfig() *RouteController { DockerClient: dockerService, } - // Initialize the "Controller" with its dependencies - routerCtrl := &RouteController{ - DockerService: dockerService, + // Initialize the "Controller" with its dependencies + routerCtrl := &RouteController{ + DockerService: dockerService, DaemonService: daemonService, - } + } return routerCtrl } @@ -93,7 +93,7 @@ func TestCheckCookie(t *testing.T) { func TestGetHosts(t *testing.T) { err := godotenv.Load("../../.env") if err != nil { - os.Setenv("DOCKER_HOST", "tcp://localhost:2375") + os.Setenv("DOCKER_HOST", "unix:///var/run/docker.sock") } ctrl := initTestConfig() diff --git a/application/frontend/index.html b/application/frontend/index.html index 1739d85..a46b8a3 100644 --- a/application/frontend/index.html +++ b/application/frontend/index.html @@ -26,6 +26,10 @@ OnLogs + +
diff --git a/application/frontend/src/lib/ClientPanel/ClientPanel.svelte b/application/frontend/src/lib/ClientPanel/ClientPanel.svelte index 71188b9..2949291 100644 --- a/application/frontend/src/lib/ClientPanel/ClientPanel.svelte +++ b/application/frontend/src/lib/ClientPanel/ClientPanel.svelte @@ -14,6 +14,8 @@ let localTheme = ""; let api = new fetchApi(); + const showUserMenu = window.DISABLE_AUTH ?? true; + //store management function toggleUserMenu() { userMenuOpen.update((v) => !v); @@ -69,6 +71,7 @@ ($activeMenuOption === 'view' && 'active')}" /> + {#if showUserMenu}
  • + {/if}