Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Settings Page Returns Page Not Found #337

Closed
WalterSchirmacher opened this issue May 4, 2024 · 15 comments
Closed

Settings Page Returns Page Not Found #337

WalterSchirmacher opened this issue May 4, 2024 · 15 comments

Comments

@WalterSchirmacher
Copy link

WalterSchirmacher commented May 4, 2024

When clicking on the Settings link, a "Page Not Found" page appears instead of the expected settings page.

Configuration

{
	email [email protected]

	order authenticate before respond
	order authorize before basicauth

	security {
		credentials myuname-icloud {
			username myuname
			password {env.icloudpass}
		}

		messaging email provider icloud-smtp-server {
			address smtp.mail.me.com:587
			protocol smtp
			credentials myusername-icloud
			sender myusernameicloud.com "Example Portal"
			bcc [email protected]
		}

		local identity store localdb {
			realm local
			path /etc/caddy/users.json
		}

		authentication portal myportal {
			crypto default token lifetime 86400
			crypto key sign-verify {env.JWT_SHARED_KEY}
			enable identity store localdb
			cookie domain mydomain.url
			cookie lifetime 86400

				ui {
						"My Identity" "/whoami" icon "las la-user"
					}
			}

			transform user {
				match origin local
				require mfa
			}

			transform user {
				match email [email protected]
				ui link "My Portal Settings" /settings icon "las la-cog"
			}

			transform user {
				match email [email protected]
				ui link "Portal Settings" /settings icon "las la-cog"
			}
		}

		authorization policy mypolicy {
			set auth url https://auth.example.com
			crypto key verify {env.JWT_SHARED_KEY}
			allow roles authp/admin authp/user
			validate bearer header
			inject headers with claims
		}
	}
}

(myHost) {
	tls {
		dns myhost {
			api_key {env.MYHOST_API_KEY}
			api_secret_key {env.MYHOST_API_PASSWORD}
		}
	}
}

www.mywebsite.com {
	redir https://mywebsite.com{uri}
	import myHost
}

mywebsite.com {
	encode gzip zstd
	root * /data/exampleuser/ExampleDrive/MyWebsite
	file_server {
		hide .git
	}
	import myHost

	log {
		output file /var/log/access.log
	}
}

*.mywebsite.com {
	encode gzip zstd
	import myHost

	log {
		output file /var/log/access.log
	}

	@test host test.mywebsite.com
	handle @test {
		authorize with mypolicy 
		reverse_proxy 192.168.0.160:8000 {
			header_up Host {http.reverse_proxy.upstream.hostport}
		}
	}

	#Authorize
	@theauth host auth.mywebsite.com
	handle @theauth {
		authenticate with myportal
	}

	#Fallback for unhandled domains
	handle {
		abort
	}
}

Version Information

Provide output of caddy list-modules --versions | grep -E "(auth|security)" below:

http.authentication.hashes.bcrypt v2.7.6
http.authentication.hashes.scrypt v2.7.6
http.authentication.providers.http_basic v2.7.6
http.handlers.authentication v2.7.6
tls.client_auth.leaf v2.7.6
http.authentication.providers.authorizer v1.1.29
http.handlers.authenticator v1.1.29
security v1.1.29

Expected behavior

The settings page would appear and be functional.

Screenshot 2024-05-04 125607

@greenpau
Copy link
Owner

greenpau commented May 5, 2024

@WalterSchirmacher , please server the portal from “/auth/*” path. The settings are available via “/auth/profile”

@greenpau
Copy link
Owner

greenpau commented May 5, 2024

@WalterSchirmacher , serve it from “auth.mywebsite.com/auth/“

@WalterSchirmacher
Copy link
Author

WalterSchirmacher commented May 6, 2024 via email

@greenpau
Copy link
Owner

greenpau commented May 6, 2024

@WalterSchirmacher , there are no more "settings". It is "/auth/profile".

@WalterSchirmacher
Copy link
Author

I tried /auth/profile and still get page not found. I also tried /profile with the same result.

@greenpau
Copy link
Owner

greenpau commented May 8, 2024

@WalterSchirmacher , please share the snippet how you are serving “authenticate with” directive.

@WalterSchirmacher
Copy link
Author

Here are the relevant parts:

{
authentication portal myportal {
crypto default token lifetime 86400
crypto key sign-verify {env.JWT_SHARED_KEY}
enable identity store localdb
cookie domain mydomain.url
cookie lifetime 86400

			ui {
					"My Identity" "/whoami" icon "las la-user"
				}
		}

		transform user {
			match origin local
			require mfa
		}

		transform user {
			match email [email protected]
			ui link "My Portal Settings" /settings icon "las la-cog"
			ui link "My Portal Settings" /profile icon "las la-cog"
			ui link "My Portal Settings" /auth/profile icon "las la-cog"
			ui link "My Portal Settings" /auth/settings icon "las la-cog"
		}

		transform user {
			match email [email protected]
			ui link "Portal Settings" /settings icon "las la-cog"
			ui link "My Portal Settings" /profile icon "las la-cog"
			ui link "My Portal Settings" /auth/profile icon "las la-cog"
			ui link "My Portal Settings" /auth/settings icon "las la-cog"
		}
	}

	authorization policy mypolicy {
		set auth url https://auth.example.com
		crypto key verify {env.JWT_SHARED_KEY}
		allow roles authp/admin authp/user
		validate bearer header
		inject headers with claims
	}

}

*.mywebsite.com {
encode gzip zstd
import myHost

log {
	output file /var/log/access.log
}

@test host test.mywebsite.com
handle @test {
	authorize with mypolicy 
	reverse_proxy 192.168.0.160:8000 {
		header_up Host {http.reverse_proxy.upstream.hostport}
	}
}

#Authorize
@theauth host auth.mywebsite.com
handle @theauth {
	authenticate with myportal
}

#Fallback for unhandled domains
handle {
	abort
}

}

@greenpau
Copy link
Owner

greenpau commented May 9, 2024

@WalterSchirmacher , the issue is here

@theauth host auth.mywebsite.com
handle @theauth {
authenticate with myportal
}

you are serving it from “/“, you need to have a redirect from “/“ to “/auth/“ and handle the path “/auth*”

@alyssondiasmec
Copy link

I am with the same error, following routes are not accessible:

  • /auth/settings
  • /auth/profile

This is my Caddyfile:

{
    debug
    https_port 443

    order authenticate before respond
    order authorize before basicauth

    security {
        local identity store localdb {
            realm local
            path /etc/caddy/users.json
        }

        authentication portal myportal {
            crypto default token lifetime 2592000
            enable identity store localdb

            transform user {
                match origin local
                action add role authp/user
                ui link "Portal Settings 1" /auth/profile icon "las la-cog"
                ui link "Portal Settings 2" /auth/settings icon "las la-cog"
            }
            
        }
        authorization policy mypolicy {
            with api key auth portal myportal realm local
            acl default allow
        }
    }
}

(internal_config) {
    handle /auth* {
        authenticate with myportal
    }
}

:80 {
    # import internal_config
    redir https://caddy_edge{uri}
}

https://localhost:443, {$HOST_DOMAIN_ADDRESS} {
    import internal_config
}

@alyssondiasmec
Copy link

@WalterSchirmacher , the issue is here

@theauth host auth.mywebsite.com handle @theauth { authenticate with myportal }

you are serving it from “/“, you need to have a redirect from “/“ to “/auth/“ and handle the path “/auth*”

I tried to do this, however with no success.

I might be forgetting something.

@ooiuri
Copy link

ooiuri commented May 9, 2024

@WalterSchirmacher , the issue is here
@theauth host auth.mywebsite.com handle @theauth { authenticate with myportal }
you are serving it from “/“, you need to have a redirect from “/“ to “/auth/“ and handle the path “/auth*”

I tried to do this, however with no success.

I might be forgetting something.

I was also facing the same issue with a very similar configuration and for me worked on putting the '/' at the end of the url, like:

mydomain.com/auth/profile/

for some reason:

mydomain.com/auth/profile would give me a 404 not found

@alyssondiasmec
Copy link

@WalterSchirmacher , the issue is here
@theauth host auth.mywebsite.com handle @theauth { authenticate with myportal }
you are serving it from “/“, you need to have a redirect from “/“ to “/auth/“ and handle the path “/auth*”

I tried to do this, however with no success.
I might be forgetting something.

I was also facing the same issue with a very similar configuration and for me worked on putting the '/' at the end of the url, like:

mydomain.com/auth/profile/

for some reason:

mydomain.com/auth/profile would give me a 404 not found

Thanks @ooiuri. That was it!

Solved for my side.

@WalterSchirmacher
Copy link
Author

Thank you @ooiuri - that was it for me as well.

Combining @greenpau change to /auth/profile (instead of settings) and adding the final / was the solution.

mydomain.com/auth/profile/ works.

@greenpau
Copy link
Owner

@WalterSchirmacher , please share your final config.

@tribor
Copy link

tribor commented May 23, 2024

                        transform user {
                                match origin local
                                action add role authp/user
-				ui link "My Portal Settings" /settings icon "las la-cog"
+                               ui link "User Dashboard" /auth/profile/ icon "las la-cog"
                        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants