Compare commits

...

8 Commits

Author SHA1 Message Date
Stavros
ada3531565 chore: use correct timezone in discohook 2025-03-10 21:25:49 +02:00
Stavros
939ed26fd0 chore: update discohook date 2025-03-10 21:22:01 +02:00
Stavros
da0641c115 chore: migrate to new domain 2025-03-10 21:21:31 +02:00
Stavros
753b95baff docs: change warning to note in contributing 2025-03-10 18:50:43 +02:00
Stavros
9dd9829058 docs: update contributing 2025-03-10 18:47:54 +02:00
Stavros
ec67ea3807 refactor: detect if using browser or headless client for better responses 2025-03-10 17:02:23 +02:00
Stavros
3649d0d84e fix: allow oauth resource when oauth whitelist is empty 2025-03-10 16:22:32 +02:00
Stavros
c0ffe3faf4 refactor: release multiple semver tags 2025-03-10 16:02:48 +02:00
10 changed files with 75 additions and 56 deletions

View File

@@ -125,9 +125,8 @@ jobs:
with:
images: ghcr.io/${{ github.repository_owner }}/tinyauth
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}
type=semver,pattern={{major}}.{{minor}}
- name: Create manifest list and push

View File

@@ -1,6 +1,6 @@
# Contributing
Contributing is relatively easy.
Contributing is relatively easy, you just need to follow the steps carefully and you will be up and running with a development server in less than 5 minutes.
## Requirements
@@ -8,6 +8,7 @@ Contributing is relatively easy.
- Golang v1.23.2 and above
- Git
- Docker
- Make (not required but it will make your life easier)
## Cloning the repository
@@ -20,48 +21,42 @@ cd tinyauth
## Install requirements
Now it's time to install the requirements, firstly the Go ones:
To install the requirements simply run:
```sh
go mod download
make requirements
```
And now the site ones:
```sh
cd site
bun i
```
It will download all the node packages required by the frontend as well as all the go requirements.
## Developing locally
In order to develop the app locally you need to build the frontend and copy it to the assets folder in order for Go to embed it and host it. In order to build the frontend run:
In order to develop the app you need to firstly compile the frontend and then the go app. To avoid running the same commands over and over again you can just run:
```sh
cd site
bun run build
cd ..
make run
```
Copy it to the assets folder:
This is the equivalent of `go run main.go`, if you would like to build a binary run:
```sh
rm -rf internal/assets/dist
cp -r site/dist internal/assets/dist
make build
```
Finally either run the app with:
To avoid rebuilding the frontend every time you can run:
```sh
go run main.go
make run-no-web
```
Or build it with:
And:
```sh
go build
make build-no-web
```
For these commands to succeed you must have built the frontend at least once.
> [!WARNING]
> Make sure you have set the environment variables when running outside of docker else the app will fail.
@@ -70,8 +65,8 @@ go build
My recommended development method is docker so I can test that both my image works and that the app responds correctly to traefik. In my setup I have set these two DNS records in my DNS server:
```
*.dev.local -> 127.0.0.1
dev.local -> 127.0.0.1
*.dev.example.com -> 127.0.0.1
dev.example.com -> 127.0.0.1
```
Then I can just make sure the domains are correct in the example docker compose file and do:
@@ -79,3 +74,6 @@ Then I can just make sure the domains are correct in the example docker compose
```sh
docker compose -f docker-compose.dev.yml up --build
```
> [!NOTE]
> I would recommend copying the example `docker-compose.dev.yml` into a `docker-compose.test.yml` file, so as you don't accidentally commit any sensitive information.

View File

@@ -2,6 +2,11 @@
web:
cd site; bun run build
# Requirements
requirements:
cd site; bun install
go mod tidy
# Copy site assets
assets: web
rm -rf internal/assets/dist
@@ -12,6 +17,10 @@ assets: web
run: assets
go run main.go
# Run development binary without compiling the frontend
run-skip-web:
go run main.go
# Test
test:
go test ./...
@@ -20,6 +29,6 @@ test:
build: assets
go build -o tinyauth
# Build no site
# Build the binary without compiling the frontend
build-skip-web:
go build -o tinyauth

View File

@@ -28,11 +28,11 @@ I just made a Discord server for Tinyauth! It is not only for Tinyauth but gener
## Getting Started
You can easily get started with tinyauth by following the guide on the [documentation](https://tinyauth.doesmycode.work/docs/getting-started.html). There is also an available [docker compose file](./docker-compose.example.yml) that has traefik, nginx and tinyauth to demonstrate its capabilities.
You can easily get started with tinyauth by following the guide on the [documentation](https://tinyauth.app/docs/getting-started.html). There is also an available [docker compose file](./docker-compose.example.yml) that has traefik, nginx and tinyauth to demonstrate its capabilities.
## Documentation
You can find documentation and guides on all available configuration of tinyauth [here](https://tinyauth.doesmycode.work).
You can find documentation and guides on all available configuration of tinyauth [here](https://tinyauth.app).
## Contributing

View File

@@ -3,8 +3,8 @@
"embeds": [
{
"title": "Welcome to Tinyauth Discord!",
"description": "Tinyauth is a simple authentication middleware that adds simple username/password login or OAuth with Google, Github and any generic OAuth provider to all of your docker apps.\n\n**Information**\n\n• Github: <https://github.com/steveiliop56/tinyauth>\n• Website: <https://tinyauth.doesmycode.work>",
"url": "https://tinyauth.doesmycode.work",
"description": "Tinyauth is a simple authentication middleware that adds simple username/password login or OAuth with Google, Github and any generic OAuth provider to all of your docker apps.\n\n**Information**\n\n• Github: <https://github.com/steveiliop56/tinyauth>\n• Website: <https://tinyauth.app>",
"url": "https://tinyauth.app",
"color": 7002085,
"author": {
"name": "Tinyauth"
@@ -12,11 +12,11 @@
"footer": {
"text": "Updated at"
},
"timestamp": "2025-02-06T22:00:00.000Z",
"timestamp": "2025-03-10T19:00:00.000Z",
"thumbnail": {
"url": "https://github.com/steveiliop56/tinyauth/blob/main/site/public/logo.png?raw=true"
}
}
],
"attachments": []
}
}

View File

@@ -8,12 +8,12 @@ services:
volumes:
- /var/run/docker.sock:/var/run/docker.sock
nginx:
container_name: nginx
image: nginx:latest
whoami:
container_name: whoami
image: traefik/whoami:latest
labels:
traefik.enable: true
traefik.http.routers.nginx.rule: Host(`nginx.dev.local`)
traefik.http.routers.nginx.rule: Host(`whoami.dev.example.com`)
traefik.http.services.nginx.loadbalancer.server.port: 80
traefik.http.routers.nginx.middlewares: tinyauth
@@ -24,11 +24,11 @@ services:
dockerfile: Dockerfile
environment:
- SECRET=some-random-32-chars-string
- APP_URL=http://tinyauth.dev.local
- APP_URL=http://tinyauth.dev.example.com
- USERS=user:$$2a$$10$$UdLYoJ5lgPsC0RKqYH/jMua7zIn0g9kPqWmhYayJYLaZQ/FTmH2/u # user:password
labels:
traefik.enable: true
traefik.http.routers.tinyauth.rule: Host(`tinyauth.dev.local`)
traefik.http.routers.tinyauth.rule: Host(`tinyauth.dev.example.com`)
traefik.http.services.tinyauth.loadbalancer.server.port: 3000
traefik.http.middlewares.tinyauth.forwardauth.address: http://tinyauth:3000/api/auth/traefik
traefik.http.middlewares.tinyauth.forwardauth.authResponseHeaders: Remote-User

View File

@@ -8,12 +8,12 @@ services:
volumes:
- /var/run/docker.sock:/var/run/docker.sock
nginx:
container_name: nginx
image: nginx:latest
whoami:
container_name: whoami
image: traefik/whoami:latest
labels:
traefik.enable: true
traefik.http.routers.nginx.rule: Host(`nginx.example.com`)
traefik.http.routers.nginx.rule: Host(`whoami.example.com`)
traefik.http.services.nginx.loadbalancer.server.port: 80
traefik.http.routers.nginx.middlewares: tinyauth

2
go.mod
View File

@@ -7,6 +7,7 @@ require (
github.com/gin-gonic/gin v1.10.0
github.com/go-playground/validator/v10 v10.24.0
github.com/google/go-querystring v1.1.0
github.com/mdp/qrterminal/v3 v3.2.0
github.com/rs/zerolog v1.33.0
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
@@ -15,7 +16,6 @@ require (
require (
github.com/containerd/log v0.1.0 // indirect
github.com/mdp/qrterminal/v3 v3.2.0 // indirect
github.com/moby/term v0.5.2 // indirect
github.com/morikuni/aec v1.0.0 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect

View File

@@ -131,18 +131,24 @@ func (api *API) SetupRoutes() {
return
}
log.Debug().Interface("proxy", proxy.Proxy).Msg("Got proxy")
// Check if the request is coming from a browser (tools like curl/bruno use */* and they don't include the text/html)
isBrowser := strings.Contains(c.Request.Header.Get("Accept"), "text/html")
// Check if using basic auth
_, _, basicAuth := c.Request.BasicAuth()
if isBrowser {
log.Debug().Msg("Request is most likely coming from a browser")
} else {
log.Debug().Msg("Request is most likely not coming from a browser")
}
log.Debug().Interface("proxy", proxy.Proxy).Msg("Got proxy")
// Check if auth is enabled
authEnabled, authEnabledErr := api.Auth.AuthEnabled(c)
// Handle error
if authEnabledErr != nil {
// Return 500 if nginx is the proxy or if the request is using basic auth
if proxy.Proxy == "nginx" || basicAuth {
// Return 500 if nginx is the proxy or if the request is not coming from a browser
if proxy.Proxy == "nginx" || !isBrowser {
log.Error().Err(authEnabledErr).Msg("Failed to check if auth is enabled")
c.JSON(500, gin.H{
"status": 500,
@@ -186,8 +192,8 @@ func (api *API) SetupRoutes() {
// Check if there was an error
if appAllowedErr != nil {
// Return 500 if nginx is the proxy or if the request is using basic auth
if proxy.Proxy == "nginx" || basicAuth {
// Return 500 if nginx is the proxy or if the request is not coming from a browser
if proxy.Proxy == "nginx" || !isBrowser {
log.Error().Err(appAllowedErr).Msg("Failed to check if app is allowed")
c.JSON(500, gin.H{
"status": 500,
@@ -208,9 +214,11 @@ func (api *API) SetupRoutes() {
if !appAllowed {
log.Warn().Str("username", userContext.Username).Str("host", host).Msg("User not allowed")
// Return 401 if nginx is the proxy or if the request is using an Authorization header
if proxy.Proxy == "nginx" || basicAuth {
c.Header("WWW-Authenticate", "Basic realm=\"tinyauth\"")
// Set WWW-Authenticate header
c.Header("WWW-Authenticate", "Basic realm=\"tinyauth\"")
// Return 401 if nginx is the proxy or if the request is not coming from a browser
if proxy.Proxy == "nginx" || !isBrowser {
c.JSON(401, gin.H{
"status": 401,
"message": "Unauthorized",
@@ -252,9 +260,11 @@ func (api *API) SetupRoutes() {
// The user is not logged in
log.Debug().Msg("Unauthorized")
// Return 401 if nginx is the proxy or if the request is using an Authorization header
if proxy.Proxy == "nginx" || basicAuth {
c.Header("WWW-Authenticate", "Basic realm=\"tinyauth\"")
// Set www-authenticate header
c.Header("WWW-Authenticate", "Basic realm=\"tinyauth\"")
// Return 401 if nginx is the proxy or if the request is not coming from a browser
if proxy.Proxy == "nginx" || !isBrowser {
c.JSON(401, gin.H{
"status": 401,
"message": "Unauthorized",

View File

@@ -162,7 +162,10 @@ func (auth *Auth) ResourceAllowed(c *gin.Context, context types.UserContext) (bo
// Check if resource is allowed
allowed, allowedErr := auth.Docker.ContainerAction(appId, func(labels types.TinyauthLabels) (bool, error) {
// If the container has an oauth whitelist, check if the user is in it
if context.OAuth && len(labels.OAuthWhitelist) != 0 {
if context.OAuth {
if len(labels.OAuthWhitelist) == 0 {
return true, nil
}
log.Debug().Msg("Checking OAuth whitelist")
if slices.Contains(labels.OAuthWhitelist, context.Username) {
return true, nil