Compare commits

...

3 Commits

Author SHA1 Message Date
Stavros
97830a309b chore: bump version 2025-02-02 19:36:12 +02:00
Stavros
fe594d2755 fix: do not crash when docker is not connected 2025-02-02 19:34:02 +02:00
Stavros
b3aac26644 chore: update gitignore 2025-02-02 14:28:12 +02:00
5 changed files with 40 additions and 19 deletions

8
.gitignore vendored
View File

@@ -12,4 +12,10 @@ users.txt
# secret test file
secret.txt
secret_oauth.txt
secret_oauth.txt
# vscode
.vscode
# apple stuff
.DS_Store

View File

@@ -107,7 +107,10 @@ func (api *API) SetupRoutes() {
log.Debug().Msg("Authenticated")
appAllowed, appAllowedErr := api.Auth.ResourceAllowed(userContext, host)
if handleApiError(c, "Failed to check if resource is allowed", appAllowedErr) {
log.Debug().Bool("appAllowed", appAllowed).Msg("Checking if user is allowed")
if api.handleError(c, "Failed to check if resource is allowed", appAllowedErr) {
return
}
@@ -117,7 +120,7 @@ func (api *API) SetupRoutes() {
Username: userContext.Username,
Resource: strings.Split(host, ".")[0],
})
if handleApiError(c, "Failed to build query", queryErr) {
if api.handleError(c, "Failed to build query", queryErr) {
return
}
c.Redirect(http.StatusTemporaryRedirect, fmt.Sprintf("%s/unauthorized?%s", api.Config.AppURL, queries.Encode()))
@@ -299,7 +302,7 @@ func (api *API) SetupRoutes() {
tailscaleQuery, tailscaleQueryErr := query.Values(types.TailscaleQuery{
Code: (1000 + rand.IntN(9000)), // doesn't need to be secure, just there to avoid caching
})
if handleApiError(c, "Failed to build query", tailscaleQueryErr) {
if api.handleError(c, "Failed to build query", tailscaleQueryErr) {
return
}
c.JSON(200, gin.H{
@@ -322,7 +325,7 @@ func (api *API) SetupRoutes() {
bindErr := c.BindUri(&providerName)
if handleApiError(c, "Failed to bind URI", bindErr) {
if api.handleError(c, "Failed to bind URI", bindErr) {
return
}
@@ -351,7 +354,7 @@ func (api *API) SetupRoutes() {
log.Debug().Msg("Got token")
if handleApiError(c, "Failed to exchange token", tokenErr) {
if api.handleError(c, "Failed to exchange token", tokenErr) {
return
}
@@ -359,7 +362,7 @@ func (api *API) SetupRoutes() {
log.Debug().Str("email", email).Msg("Got email")
if handleApiError(c, "Failed to get user", emailErr) {
if api.handleError(c, "Failed to get user", emailErr) {
return
}
@@ -368,7 +371,7 @@ func (api *API) SetupRoutes() {
unauthorizedQuery, unauthorizedQueryErr := query.Values(types.UnauthorizedQuery{
Username: email,
})
if handleApiError(c, "Failed to build query", unauthorizedQueryErr) {
if api.handleError(c, "Failed to build query", unauthorizedQueryErr) {
return
}
c.Redirect(http.StatusPermanentRedirect, fmt.Sprintf("%s/unauthorized?%s", api.Config.AppURL, unauthorizedQuery.Encode()))
@@ -400,7 +403,7 @@ func (api *API) SetupRoutes() {
log.Debug().Msg("Got redirect query")
if handleApiError(c, "Failed to build query", redirectQueryErr) {
if api.handleError(c, "Failed to build query", redirectQueryErr) {
return
}
@@ -413,6 +416,15 @@ func (api *API) Run() {
api.Router.Run(fmt.Sprintf("%s:%d", api.Config.Address, api.Config.Port))
}
func (api *API) handleError(c *gin.Context, msg string, err error) bool {
if err != nil {
log.Error().Err(err).Msg(msg)
c.Redirect(http.StatusPermanentRedirect, fmt.Sprintf("%s/error", api.Config.AppURL))
return true
}
return false
}
func zerolog() gin.HandlerFunc {
return func(c *gin.Context) {
tStart := time.Now()
@@ -436,12 +448,3 @@ func zerolog() gin.HandlerFunc {
}
}
}
func handleApiError(c *gin.Context, msg string, err error) bool {
if err != nil {
log.Error().Err(err).Msg(msg)
c.Redirect(http.StatusPermanentRedirect, "/error")
return true
}
return false
}

View File

@@ -1 +1 @@
v2.1.0
v2.1.1

View File

@@ -97,6 +97,13 @@ func (auth *Auth) UserAuthConfigured() bool {
}
func (auth *Auth) ResourceAllowed(context types.UserContext, host string) (bool, error) {
isConnected := auth.Docker.DockerConnected()
if !isConnected {
log.Debug().Msg("Docker not connected, allowing access")
return true, nil
}
appId := strings.Split(host, ".")[0]
containers, containersErr := auth.Docker.GetContainers()

View File

@@ -49,3 +49,8 @@ func (docker *Docker) InspectContainer(containerId string) (types.ContainerJSON,
return inspect, nil
}
func (docker *Docker) DockerConnected() bool {
_, err := docker.Client.Ping(docker.Context)
return err == nil
}